From 0b264c2aac5cf3f89ed6e2ad535e6850b78e55bf Mon Sep 17 00:00:00 2001 From: jysperm Date: Tue, 19 Aug 2014 03:23:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E9=99=A4=E4=BA=86?= =?UTF-8?q?=E6=B5=81=E9=87=8F=E7=BB=9F=E8=AE=A1=E7=9A=84=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- INSTALL.md | 13 +++++++-- core/static/style/ticket.less | 2 +- plugin/shadowsocks/service.coffee | 29 ++++++++++++++++----- plugin/shadowsocks/template/config.conf | 2 +- plugin/shadowsocks/template/supervisor.conf | 4 +++ plugin/shadowsocks/view/widget.jade | 4 +-- 6 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 plugin/shadowsocks/template/supervisor.conf diff --git a/INSTALL.md b/INSTALL.md index 7f5c31b..96eb56a 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -110,14 +110,23 @@ # ShadowSocks - add-apt-repository 'deb http://shadowsocks.org/debian wheezy main' - apt-get install shadowsocks + apt-get install python-pip python-m2crypto supervisor + pip install shadowsocks + + vi /etc/default/supervisor + + ulimit -n 51200 + + service supervisor restart ### Runtime + # Golang apt-get install golang golang-go.tools + # Python apt-get install python python3 python-pip python3-pip python-dev python3-dev pip install django tornado markdown python-memcached web.py mongo uwsgi virtualenv virtualenvwrapper flask gevent jinja2 requests + # Node.js npm install forever coffee-script gulp mocha harp bower -g diff --git a/core/static/style/ticket.less b/core/static/style/ticket.less index 53bdeb2..348fc97 100644 --- a/core/static/style/ticket.less +++ b/core/static/style/ticket.less @@ -7,7 +7,7 @@ margin-right: 10px; } - img { + img.pull-left { width: 58px; height: 58px; } diff --git a/plugin/shadowsocks/service.coffee b/plugin/shadowsocks/service.coffee index 4fd11df..c8805cc 100644 --- a/plugin/shadowsocks/service.coffee +++ b/plugin/shadowsocks/service.coffee @@ -1,6 +1,7 @@ child_process = require 'child_process' path = require 'path' jade = require 'jade' +fs = require 'fs' plugin = require '../../core/plugin' @@ -20,12 +21,18 @@ generatePort = (callback) -> module.exports = enable: (account, callback) -> generatePort (port) -> + password = mAccount.randomSalt()[0...10] + mAccount.update _id: account._id, $set: 'attribute.plugin.shadowsocks': port: port - password: mAccount.randomSalt() + password: password , -> + account.attribute.plugin.shadowsocks = + port: port + password: password + module.exports.restart account, -> callback() @@ -34,16 +41,24 @@ module.exports = $unset: 'attribute.plugin.shadowsocks': true , -> - #TODO kill process - callback() + # TODO delete iptables + + child_process.exec "sudo rm /etc/supervisor/conf.d/#{account.username}.conf", -> + child_process.exec 'sudo supervisorctl reload', -> + 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() + # TODO iptables + + plugin.writeConfig "/etc/shadowsocks/#{account.username}.json", config_content, -> + config_content = _.template (fs.readFileSync path.join(__dirname, 'template/supervisor.conf')).toString(), + account: account + + plugin.writeConfig "/etc/supervisor/conf.d/#{account.username}.conf", config_content, -> + child_process.exec 'sudo supervisorctl reload', -> + callback() widget: (account, callback) -> jade.renderFile path.join(__dirname, 'view/widget.jade'), diff --git a/plugin/shadowsocks/template/config.conf b/plugin/shadowsocks/template/config.conf index c545b33..c8133ce 100644 --- a/plugin/shadowsocks/template/config.conf +++ b/plugin/shadowsocks/template/config.conf @@ -1,6 +1,6 @@ { "server": "0.0.0.0", - "server_port": "<%= port %>", + "server_port": <%= port %>, "local_port": 1080, "password": "<%= password %>", "timeout": 60, diff --git a/plugin/shadowsocks/template/supervisor.conf b/plugin/shadowsocks/template/supervisor.conf new file mode 100644 index 0000000..a150398 --- /dev/null +++ b/plugin/shadowsocks/template/supervisor.conf @@ -0,0 +1,4 @@ +[program:shadowsocks-<%= account.username %>] +command=ssserver -c /etc/shadowsocks/<%= account.username %>.json +autorestart=true +user=nobody diff --git a/plugin/shadowsocks/view/widget.jade b/plugin/shadowsocks/view/widget.jade index 83b20c1..53d7123 100644 --- a/plugin/shadowsocks/view/widget.jade +++ b/plugin/shadowsocks/view/widget.jade @@ -6,10 +6,10 @@ header ShadowSocks .panel-body .input-group(style='margin-bottom: 20px;') span.input-group-addon 端口 - input.form-control(type='text', value='14261', disabled) + input.form-control(type='text', value=account.attribute.plugin.shadowsocks.port, disabled) .input-group span.input-group-addon 密码 - input.form-control(type='test', value='zppeLxbSfyNR2YwL', disabled) + input.form-control(type='text', value=account.attribute.plugin.shadowsocks.password, disabled) span.input-group-btn button.btn.btn-default(type='button') 重置