mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-13 07:01:20 +08:00
linux plugin framework
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
service = require './service'
|
||||
monitor = require './monitor'
|
||||
{pluggable, config} = app
|
||||
|
||||
{pluggable} = app
|
||||
linux = require './linux'
|
||||
|
||||
app.view_hook.menu_bar.push
|
||||
href: '/public/monitor/'
|
||||
html: '服务器状态'
|
||||
|
||||
module.exports =
|
||||
module.exports = pluggable.createHelpers exports =
|
||||
name: 'linux'
|
||||
type: 'service'
|
||||
|
||||
service: service
|
||||
exports.registerHook 'view.layout.menu_bar',
|
||||
href: '/public/monitor/'
|
||||
body: '服务器状态'
|
||||
|
||||
panel:
|
||||
widget: service.widget
|
||||
style:'/style/panel.css'
|
||||
exports.registerHook 'account.username_filter',
|
||||
filter: (username, callback) ->
|
||||
linux.getPasswdMap (passwd_map) ->
|
||||
callback username in _.values passwd_map
|
||||
|
||||
pluggable.account.username_filter.push (account, callback) ->
|
||||
monitor.loadPasswd (passwd_cache) ->
|
||||
if req.body.username in _.values(passwd_cache)
|
||||
return callback false
|
||||
exports.registerHook 'view.panel.styles',
|
||||
path: '/plugin/linux/style/panel.css'
|
||||
|
||||
callback true
|
||||
exports.registerHook 'view.panel.widgets',
|
||||
generator: (req, callback) ->
|
||||
|
||||
monitor.run()
|
||||
exports.registerServiceHook 'enable',
|
||||
action: (req, callback) ->
|
||||
|
||||
exports.registerServiceHook 'disable',
|
||||
action: (req, callback) ->
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
fs = require 'fs'
|
||||
_ = require 'underscore'
|
||||
|
||||
{cache} = app
|
||||
|
||||
exports.getPasswdMap = (callback) ->
|
||||
cache.try 'linux.getPasswdMap',
|
||||
command: cache.SETEX 120
|
||||
is_json: true
|
||||
, (callback) ->
|
||||
fs.readFile '/etc/passwd', (err, content) ->
|
||||
result = {}
|
||||
|
||||
for line in _.compact(content.toString().split '\n')
|
||||
[username, password, uid] = line.split ':'
|
||||
result[uid] = username
|
||||
|
||||
callback result
|
||||
, (passwd_map) ->
|
||||
callback passwd_map
|
||||
|
||||
@@ -56,26 +56,6 @@ exports.loadMemoryInfo = (callback) ->
|
||||
swap_used_per: swap_used_per
|
||||
swap_free_per: swap_free_per
|
||||
|
||||
exports.loadPasswd = (callback) ->
|
||||
app.redis.get 'rp:passwd_cache', (err, result) ->
|
||||
if result
|
||||
passwd_cache = JSON.parse result
|
||||
callback passwd_cache
|
||||
else
|
||||
fs.readFile '/etc/passwd', (err, content) ->
|
||||
throw err if err
|
||||
content = content.toString().split '\n'
|
||||
|
||||
passwd_cache = {}
|
||||
|
||||
for line in content
|
||||
if line
|
||||
[username, password, uid] = line.split ':'
|
||||
passwd_cache[uid] = username
|
||||
|
||||
app.redis.setex 'rp:passwd_cache', 120, JSON.stringify(passwd_cache), ->
|
||||
callback passwd_cache
|
||||
|
||||
exports.getProcessList = (callback) ->
|
||||
app.redis.get 'rp:process_list', (err, plist) ->
|
||||
if plist
|
||||
|
||||
Reference in New Issue
Block a user