mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-24 03:35:59 +08:00
shadowsocks frame
This commit is contained in:
16
plugin/shadowsocks/action.coffee
Normal file
16
plugin/shadowsocks/action.coffee
Normal 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 {}
|
||||
11
plugin/shadowsocks/index.coffee
Normal file
11
plugin/shadowsocks/index.coffee
Normal file
@@ -0,0 +1,11 @@
|
||||
service = require './service'
|
||||
action = require './action'
|
||||
|
||||
module.exports =
|
||||
name: 'shadowsocks'
|
||||
type: 'service'
|
||||
|
||||
service: service
|
||||
|
||||
panel:
|
||||
widget: service.widget
|
||||
44
plugin/shadowsocks/service.coffee
Normal file
44
plugin/shadowsocks/service.coffee
Normal 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()
|
||||
8
plugin/shadowsocks/template/config.conf
Normal file
8
plugin/shadowsocks/template/config.conf
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"server": "0.0.0.0",
|
||||
"server_port": "<%= port %>",
|
||||
"local_port": 1080,
|
||||
"password": "<%= password %>",
|
||||
"timeout": 60,
|
||||
"method": "aes-256-cfb"
|
||||
}
|
||||
0
plugin/shadowsocks/view/widget.jade
Normal file
0
plugin/shadowsocks/view/widget.jade
Normal file
Reference in New Issue
Block a user