mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-01 10:43:02 +08:00
55 lines
1.6 KiB
CoffeeScript
55 lines
1.6 KiB
CoffeeScript
_ = require 'underscore'
|
|
child_process = require 'child_process'
|
|
jade = require 'jade'
|
|
path = require 'path'
|
|
async = require 'async'
|
|
tmp = require 'tmp'
|
|
fs = require 'fs'
|
|
|
|
mAccount = require '../../core/model/account'
|
|
|
|
module.exports =
|
|
enable: (account, callback) ->
|
|
mAccount.update _id: account._id,
|
|
$set:
|
|
'attribute.plugin.phpfpm.is_enable': false
|
|
, ->
|
|
callback()
|
|
|
|
delete: (account, callback) ->
|
|
if account.attribute.plugin.phpfpm.is_enable
|
|
this.switch account, callback
|
|
else
|
|
callback()
|
|
|
|
switch: (account, is_enable, callback) ->
|
|
callbackback = ->
|
|
child_process.exec 'sudo service php5-fpm restart', (err) ->
|
|
throw err if err
|
|
callback()
|
|
|
|
if is_enable
|
|
tmp.file
|
|
mode: 0o750
|
|
, (err, filepath, fd) ->
|
|
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/fpm-pool.conf')).toString(),
|
|
account: account
|
|
fs.writeSync fd, config_content, 0, 'utf8'
|
|
fs.closeSync fd
|
|
|
|
child_process.exec "sudo cp #{filepath} /etc/php5/fpm/pool.d/#{account.username}.conf", (err) ->
|
|
throw err if err
|
|
callbackback()
|
|
else
|
|
child_process.exec "sudo rm /etc/php5/fpm/pool.d/#{account.username}.conf", ->
|
|
callbackback()
|
|
|
|
widget: (account, callback) ->
|
|
jade.renderFile path.join(__dirname, 'view/widget.jade'), {account: account}, (err, html) ->
|
|
throw err if err
|
|
callback html
|
|
|
|
preview: (callback) ->
|
|
jade.renderFile path.join(__dirname, 'view/preview.jade'), {}, (err, html) ->
|
|
callback html
|