shadowsocks frame

This commit is contained in:
jysperm
2014-08-16 21:27:28 +08:00
parent fb37e11180
commit 24ef5b7999
6 changed files with 80 additions and 1 deletions

View File

@@ -0,0 +1,16 @@
service = require './service'
{requireInService} = require '../../core/router/middleware'
mAccount = require '../../core/model/account'
module.exports = exports = express.Router()
exports.use requireInService 'shadowsocks'
exports.post '/reset_password', (req, res) ->
mAccount.update _id: req.account._id,
$set:
'attribute.plugin.shadowsocks.password': mAccount.randomSalt()
, ->
service.restart req.account, ->
res.json {}

View File

@@ -0,0 +1,11 @@
service = require './service'
action = require './action'
module.exports =
name: 'shadowsocks'
type: 'service'
service: service
panel:
widget: service.widget

View File

@@ -0,0 +1,44 @@
child_process = require 'child_process'
plugin = require '../../core/plugin'
mAccount = require '../../core/model/account'
generatePort = (callback) ->
port = 10000 + Math.floor Math.random() * 10000
mAccount.findOne
'attribute.plugin.shadowsocks.port': port
, (err, result) ->
if result
generatePort callback
else
callback port
module.exports =
enable: (account, callback) =>
generatePort (port) ->
mAccount.update _id: account._id,
$set:
'attribute.plugin.shadowsocks':
port: port
password: mAccount.randomSalt()
, =>
@restart account, ->
callback()
delete: (account, callback) ->
mAccount.update _id: account._id,
$unset:
'attribute.plugin.shadowsocks': true
, ->
#TODO kill process
callback()
restart: (account, callback) ->
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/config.conf')).toString(), account.attribute.plugin.shadowsocks
plugin.writeConfig "/etc/shadowsocks/#{account.username}.conf", config_content, ->
# kill process
child_process.exec "nohup ss-server -c /etc/shadowsocks/#{account.username}.conf &", ->
callback()

View File

@@ -0,0 +1,8 @@
{
"server": "0.0.0.0",
"server_port": "<%= port %>",
"local_port": 1080,
"password": "<%= password %>",
"timeout": 60,
"method": "aes-256-cfb"
}

View File