mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-28 19:45:45 +08:00
finish /plugin/ssh/update_passwd/
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
## Plugin API
|
||||
|
||||
### POST /plugin/action/
|
||||
|
||||
Request:
|
||||
|
||||
{
|
||||
"plugin": "ssh",
|
||||
"action": "update_passwd"
|
||||
}
|
||||
|
||||
Response.
|
||||
@@ -18,7 +18,7 @@ module.exports =
|
||||
]
|
||||
|
||||
plugin:
|
||||
availablePlugin: ['shadowsocks']
|
||||
availablePlugin: ['ssh']
|
||||
|
||||
plans:
|
||||
all:
|
||||
|
||||
@@ -47,7 +47,7 @@ exports.runWebServer = ->
|
||||
api.bind app
|
||||
|
||||
plugin = require './plugin'
|
||||
plugin.loadPlugins()
|
||||
plugin.loadPlugins app
|
||||
|
||||
app.listen config.web.port
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@ config = require './config'
|
||||
exports.get = (name) ->
|
||||
return require path.join(__dirname, "../plugin/#{name}")
|
||||
|
||||
exports.loadPlugins = ->
|
||||
exports.loadPlugins = (app) ->
|
||||
for name in config.plugin.availablePlugin
|
||||
i18n.loadPlugin path.join(__dirname, "../plugin/#{name}/locale"), name
|
||||
|
||||
p = exports.get name
|
||||
|
||||
app.use ('/plugin/' + name), p.action
|
||||
|
||||
16
plugin/ssh/API.md
Normal file
16
plugin/ssh/API.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## SSH Plugin API
|
||||
|
||||
### POST /plugin/ssh/update_passwd/
|
||||
|
||||
Request:
|
||||
|
||||
{
|
||||
"passwd": "123123"
|
||||
}
|
||||
|
||||
No Response.
|
||||
|
||||
Exception:
|
||||
|
||||
* invalid_passwd
|
||||
* not_in_service
|
||||
@@ -1,13 +1,24 @@
|
||||
child_process = require 'child_process'
|
||||
express = require 'express'
|
||||
|
||||
module.exports =
|
||||
update_passwd:
|
||||
mode: 'passwd'
|
||||
callback: ->
|
||||
mAccount = require '../../core/model/account'
|
||||
|
||||
killall:
|
||||
mode: 'alert'
|
||||
callback: ->
|
||||
module.exports = exports = express.Router()
|
||||
|
||||
reset_permission:
|
||||
mode: 'alert'
|
||||
callback: ->
|
||||
exports.use (req, res) ->
|
||||
mAccount.authenticate req.token, (account) ->
|
||||
unless account
|
||||
return res.json 400, error: 'auth_failed'
|
||||
|
||||
unless 'ssh' in account.attribute.service
|
||||
return res.json 400, error: 'not_in_service'
|
||||
|
||||
req.account = account
|
||||
|
||||
exports.post '/update_passwd/', (req, res) ->
|
||||
unless req.body.passwd or not /^[A-Za-z0-9\-_]+$/.test req.body.passwd
|
||||
return res.json 400, error: 'invalid_passwd'
|
||||
|
||||
child_process.exec "echo '#{req.account.username}:{#{req.body.passwd}}' | sudo chpasswd", (err, stdout, stderr) ->
|
||||
throw err if err
|
||||
res.json {}
|
||||
|
||||
Reference in New Issue
Block a user