mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-24 03:35:59 +08:00
refactor shadowoscks framework
This commit is contained in:
@@ -136,4 +136,7 @@ app.express.listen config.web.listen, ->
|
||||
if fs.existsSync config.web.listen
|
||||
fs.chmodSync config.web.listen, 0o770
|
||||
|
||||
app.pluggable.selectHook(null, 'app.started').forEach (hook) ->
|
||||
hook.action()
|
||||
|
||||
app.logger.log "RootPanel start at #{config.web.listen}"
|
||||
|
||||
@@ -5,10 +5,6 @@ exports.plugins = {}
|
||||
|
||||
exports.hooks =
|
||||
app:
|
||||
# action: function
|
||||
models_created: _.extend [],
|
||||
global_event: true
|
||||
|
||||
# action: function
|
||||
started: _.extend [],
|
||||
global_event: true
|
||||
|
||||
@@ -67,4 +67,5 @@ app.express.get '/public/monitor', requireAuthenticate, (req, res) ->
|
||||
exports.render 'monitor', req, result, (html) ->
|
||||
res.send html
|
||||
|
||||
monitor.run()
|
||||
if config.plugins.linux.monitor_cycle
|
||||
monitor.run()
|
||||
|
||||
@@ -26,6 +26,7 @@ exports.registerHook 'view.pay.display_payment_details',
|
||||
callback exports.t(req) 'view.payment_details',
|
||||
order_id: deposit_log.payload.order_id
|
||||
|
||||
app.express.get '/', (req, res) ->
|
||||
exports.render 'index', req, {}, (html) ->
|
||||
res.send html
|
||||
unless config.plugins.rpvhost.index_page == false
|
||||
app.express.get '/', (req, res) ->
|
||||
exports.render 'index', req, {}, (html) ->
|
||||
res.send html
|
||||
|
||||
@@ -6,7 +6,12 @@ describe 'plugin/rpvhost', ->
|
||||
|
||||
describe 'router', ->
|
||||
it 'GET /', (done) ->
|
||||
if config.plugins.rpvhost and config.plugins.rpvhost.index_page != false
|
||||
expect_code = 200
|
||||
else
|
||||
expect_code = 302
|
||||
|
||||
agent.get '/'
|
||||
.redirects 0
|
||||
.expect 200
|
||||
.expect expect_code
|
||||
.end done
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
markdown = require('markdown').markdown
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
|
||||
service = require './service'
|
||||
{renderAccount, requireInService, requireAuthenticate} = require '../../core/middleware'
|
||||
|
||||
mAccount = require '../../core/model/account'
|
||||
|
||||
module.exports = exports = express.Router()
|
||||
|
||||
exports.use requireInService 'shadowsocks'
|
||||
|
||||
exports.post '/reset_password', (req, res) ->
|
||||
password = mAccount.randomString 10
|
||||
|
||||
mAccount.update _id: req.account._id,
|
||||
$set:
|
||||
'attribute.plugin.shadowsocks.password': password
|
||||
, ->
|
||||
req.account.attribute.plugin.shadowsocks.password = password
|
||||
|
||||
service.restart req.account, ->
|
||||
service.restartAccount req.account, ->
|
||||
res.json {}
|
||||
|
||||
wiki_router = express.Router()
|
||||
|
||||
wiki_router.use renderAccount, requireAuthenticate, (req, res) ->
|
||||
url = req.url.substr 1
|
||||
|
||||
unless url
|
||||
url = 'README.md'
|
||||
|
||||
filename = path.resolve path.join __dirname, 'WIKI', url
|
||||
baseDir = path.resolve path.join __dirname, 'WIKI'
|
||||
|
||||
unless filename[0 .. baseDir.length-1] == baseDir
|
||||
return res.json 404
|
||||
|
||||
fs.readFile filename, (err, data) ->
|
||||
if err
|
||||
return res.status(404).send err.toString()
|
||||
|
||||
res.render 'wiki',
|
||||
title: url
|
||||
content: markdown.toHTML data.toString()
|
||||
|
||||
app.view_hook.menu_bar.push
|
||||
href: '/wiki/'
|
||||
html: '使用帮助'
|
||||
|
||||
app.use '/wiki', wiki_router
|
||||
@@ -1,20 +1,36 @@
|
||||
service = require './service'
|
||||
action = require './action'
|
||||
{pluggable, config} = app
|
||||
|
||||
module.exports =
|
||||
name: 'shadowsocks'
|
||||
type: 'service'
|
||||
exports = module.exports = class ShadowSocksPlugin extends pluggable.Plugin
|
||||
@NAME: 'shadowsocks'
|
||||
@type: 'service'
|
||||
@dependencies: ['supervisor', 'linux']
|
||||
|
||||
action: action
|
||||
service: service
|
||||
shadowsocks = require './shadowsocks'
|
||||
|
||||
layout:
|
||||
style: '/style/layout.css'
|
||||
exports.registerHook 'plugin.wiki.pages',
|
||||
t_category: 'shadowsocks'
|
||||
t_title: 'README.md'
|
||||
language: 'zh_CN'
|
||||
content_markdown: fs.readFileSync("#{__dirname}/wiki/README.md").toString()
|
||||
|
||||
panel:
|
||||
widget: service.widget
|
||||
script: '/script/panel.js'
|
||||
style: '/style/panel.css'
|
||||
exports.registerHook 'view.panel.scripts',
|
||||
path: '/plugin/shadowsocks/script/panel.js'
|
||||
|
||||
service.monitoring()
|
||||
setInterval service.monitoring, config.plugins.shadowsocks.monitor_cycle
|
||||
exports.registerHook 'view.panel.styles',
|
||||
path: '/plugin/shadowsocks/style/panel.css'
|
||||
|
||||
if config.plugins.shadowsocks.green_style
|
||||
exports.registerHook 'view.layout.styles',
|
||||
path: '/plugin/shadowsocks/style/layout.css'
|
||||
|
||||
exports.registerHook 'view.panel.widgets',
|
||||
generator: (req, callback) ->
|
||||
exports.render 'widget', req, {}, callback
|
||||
|
||||
exports.registerServiceHook 'enable',
|
||||
filter: (req, callback) ->
|
||||
|
||||
exports.registerServiceHook 'disable',
|
||||
filter: (req, callback) ->
|
||||
|
||||
app.express.use '/plugin/shadowsocks', require './router'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
{
|
||||
"name": "ShadowSocks",
|
||||
"description": "ShadowSocks 是一种轻量级的代理"
|
||||
"": "ShadowSocks"
|
||||
}
|
||||
|
||||
19
plugin/shadowsocks/router.coffee
Normal file
19
plugin/shadowsocks/router.coffee
Normal file
@@ -0,0 +1,19 @@
|
||||
{markdown, fs, path, express} = app.libs
|
||||
{renderAccount, requireInService, requireAuthenticate} = require '../../core/middleware'
|
||||
|
||||
module.exports = exports = express.Router()
|
||||
|
||||
exports.use requireInService 'shadowsocks'
|
||||
|
||||
exports.post '/reset_password', (req, res) ->
|
||||
password = mAccount.randomString 10
|
||||
|
||||
mAccount.update _id: req.account._id,
|
||||
$set:
|
||||
'attribute.plugin.shadowsocks.password': password
|
||||
, ->
|
||||
req.account.attribute.plugin.shadowsocks.password = password
|
||||
|
||||
service.restart req.account, ->
|
||||
service.restartAccount req.account, ->
|
||||
res.json {}
|
||||
0
plugin/shadowsocks/shadowsocks.coffee
Normal file
0
plugin/shadowsocks/shadowsocks.coffee
Normal file
@@ -8,7 +8,7 @@ exports = module.exports = class SupervisorPlugin extends pluggable.Plugin
|
||||
supervisor = require './supervisor'
|
||||
|
||||
exports.registerHook 'view.panel.scripts',
|
||||
path: '/plugin/linux/script/panel.css'
|
||||
path: '/plugin/linux/script/panel.js'
|
||||
|
||||
exports.registerHook 'view.panel.widgets',
|
||||
generator: (req, callback) ->
|
||||
|
||||
@@ -40,7 +40,7 @@ module.exports =
|
||||
|
||||
test:
|
||||
t_name: 'plans.test.name'
|
||||
t_description: 'plans.test.name.description'
|
||||
t_description: 'plans.test.description'
|
||||
|
||||
billing_by_usage:
|
||||
auto_leave: 7 * 24 * 3600 * 1000
|
||||
|
||||
@@ -29,7 +29,7 @@ module.exports =
|
||||
plans:
|
||||
all:
|
||||
t_name: 'plans.all.name'
|
||||
t_description: 'plans.all.name.description'
|
||||
t_description: 'plans.all.description'
|
||||
|
||||
billing_by_time:
|
||||
unit: 24 * 3600 * 1000
|
||||
@@ -69,6 +69,7 @@ module.exports =
|
||||
coinbase_api_key: 'coinbase-simple-api-key'
|
||||
|
||||
rpvhost:
|
||||
index_page: true
|
||||
taobao_item_id: '38370649858'
|
||||
|
||||
linux:
|
||||
|
||||
76
sample/shadowsocks.config.coffee
Normal file
76
sample/shadowsocks.config.coffee
Normal file
@@ -0,0 +1,76 @@
|
||||
module.exports =
|
||||
web:
|
||||
t_name: 'plugins.rpvhost.site_name'
|
||||
url: 'http://greenshadow.net'
|
||||
listen: '/home/rpadmin/rootpanel.sock'
|
||||
google_analytics_id: ''
|
||||
|
||||
account:
|
||||
cookie_time: 30 * 24 * 3600 * 1000
|
||||
|
||||
i18n:
|
||||
available_language: ['zh_CN', 'en']
|
||||
default_language: 'zh_CN'
|
||||
default_timezone: 'Asia/Shanghai'
|
||||
|
||||
plugin:
|
||||
available_extensions: ['bitcoin', 'wiki', 'rpvhost']
|
||||
available_services: ['linux', 'supervisor', 'shadowsocks']
|
||||
|
||||
billing:
|
||||
currency: 'CNY'
|
||||
|
||||
force_freeze:
|
||||
when_balance_below: 0
|
||||
when_arrears_above: 0
|
||||
|
||||
billing_cycle: 10 * 60 * 1000
|
||||
|
||||
plans:
|
||||
all:
|
||||
t_name: 'plugins.rpvhost.plans.shadowsocks.name'
|
||||
t_description: 'plugins.rpvhost.plans.shadowsocks.description'
|
||||
|
||||
billing_by_usage:
|
||||
auto_leave: 14 * 24 * 3600 * 1000
|
||||
|
||||
services: ['shadowsocks']
|
||||
|
||||
mongodb:
|
||||
user: 'rpadmin'
|
||||
password: 'password'
|
||||
host: 'localhost'
|
||||
name: 'RootPanel'
|
||||
|
||||
redis:
|
||||
host: '127.0.0.1'
|
||||
port: 6379
|
||||
password: 'password'
|
||||
prefix: 'RP'
|
||||
|
||||
email:
|
||||
send_from: 'robot@rpvhost.net'
|
||||
|
||||
account:
|
||||
service: 'Postmark'
|
||||
auth:
|
||||
user: 'postmark-api-token'
|
||||
pass: 'postmark-api-token'
|
||||
|
||||
plugins:
|
||||
linux:
|
||||
monitor_cycle: null
|
||||
|
||||
bitcoin:
|
||||
coinbase_api_key: 'coinbase-simple-api-key'
|
||||
|
||||
rpvhost:
|
||||
index_page: false
|
||||
taobao_item_id: '41040606505'
|
||||
|
||||
shadowsocks:
|
||||
green_style: true
|
||||
|
||||
billing_bucket: 100 * 1024 * 1024
|
||||
monitor_cycle: 5 * 60 * 1000
|
||||
price_bucket: 0.06
|
||||
@@ -1,6 +1,6 @@
|
||||
process.env.NODE_ENV = 'test'
|
||||
|
||||
config = require '../config'
|
||||
global.config = require '../config'
|
||||
|
||||
global._ = require 'underscore'
|
||||
global.fs = require 'fs'
|
||||
|
||||
Reference in New Issue
Block a user