pull/109/head
Mr Chen 6 years ago
parent f87f018952
commit 568207e3d2
  1. 60
      plugins/openresty/index.py
  2. 9
      plugins/openresty/js/openresty.js

@ -64,6 +64,17 @@ def getConf():
return path return path
def getOs():
data = {}
data['os'] = public.getOs()
ng_exe_bin = getServerDir() + "/nginx/sbin/nginx"
if checkAuthEq(ng_exe_bin, 'root'):
data['auth'] = True
else:
data['auth'] = False
return public.getJson(data)
def getInitDTpl(): def getInitDTpl():
path = getPluginDir() + "/init.d/nginx.tpl" path = getPluginDir() + "/init.d/nginx.tpl"
return path return path
@ -81,6 +92,21 @@ def makeConf():
shutil.copyfile(source_vhost, dest_vhost) shutil.copyfile(source_vhost, dest_vhost)
def getFileOwner(filename):
import pwd
stat = os.lstat(filename)
uid = stat.st_uid
pw = pwd.getpwuid(uid)
return pw.pw_name
def checkAuthEq(file, owner='root'):
fowner = getFileOwner(file)
if (fowner == owner):
return True
return False
def confReplace(): def confReplace():
service_path = os.path.dirname(os.getcwd()) service_path = os.path.dirname(os.getcwd())
content = public.readFile(getConf()) content = public.readFile(getConf())
@ -88,8 +114,9 @@ def confReplace():
user = 'www' user = 'www'
user_group = 'www' user_group = 'www'
# macosx do
if public.getOs() == 'darwin': if public.getOs() == 'darwin':
# macosx do
user = public.execShell( user = public.execShell(
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
# user = 'root' # user = 'root'
@ -105,22 +132,17 @@ def confReplace():
public.writeFile(getServerDir() + '/nginx/conf/nginx.conf', content) public.writeFile(getServerDir() + '/nginx/conf/nginx.conf', content)
# exe_bin = getServerDir() + "/bin/openresty" # give nginx root permission
# print 'chown -R ' + user + ':' + user_group + ' ' + exe_bin
# print public.execShell('chown -R ' + user + ':' + user_group + ' ' + exe_bin)
# public.execShell('chmod 755 ' + exe_bin)
# public.execShell('chmod u+s ' + exe_bin)
ng_exe_bin = getServerDir() + "/nginx/sbin/nginx" ng_exe_bin = getServerDir() + "/nginx/sbin/nginx"
if not checkAuthEq(ng_exe_bin, 'root'):
# args = getArgs() args = getArgs()
# print args['pwd'] sudoPwd = args['pwd']
# sudoPassword = args['pwd'] cmd_own = 'chown -R ' + 'root:' + user_group + ' ' + ng_exe_bin
# command = 'chown -R ' + 'root:' + user_group + ' ' + ng_exe_bin os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_own))
# print os.system('echo %s|sudo -S %s' % (args['pwd'], command)) cmd_mod = 'chmod 755 ' + ng_exe_bin
# print os.system('echo %s|sudo -S %s' % (sudoPassword, 'chmod 755 ' + ng_exe_bin)) os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_mod))
# print os.system('echo %s|sudo -S %s' % (sudoPassword, 'chmod u+s ' + cmd_s = 'chmod u+s ' + ng_exe_bin
# ng_exe_bin)) os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_s))
def initDreplace(): def initDreplace():
@ -150,7 +172,7 @@ def initDreplace():
def status(): def status():
data = public.execShell( data = public.execShell(
"ps -ef|grep openresty |grep -v grep | grep -v python | awk '{print $2}'") "ps -ef|grep nginx |grep -v grep | grep -v python | awk '{print $2}'")
if data[0] == '': if data[0] == '':
return 'stop' return 'stop'
return 'start' return 'start'
@ -159,7 +181,6 @@ def status():
def start(): def start():
file = initDreplace() file = initDreplace()
data = public.execShell(file + ' start') data = public.execShell(file + ' start')
print data
if data[1] == '': if data[1] == '':
return 'ok' return 'ok'
return 'fail' return 'fail'
@ -168,7 +189,6 @@ def start():
def stop(): def stop():
file = initDreplace() file = initDreplace()
data = public.execShell(file + ' stop') data = public.execShell(file + ' stop')
print data
clearTemp() clearTemp()
if data[1] == '': if data[1] == '':
return 'ok' return 'ok'
@ -269,7 +289,7 @@ if __name__ == "__main__":
elif func == 'conf': elif func == 'conf':
print getConf() print getConf()
elif func == 'get_os': elif func == 'get_os':
print public.getOs() print getOs()
elif func == 'run_info': elif func == 'run_info':
print runInfo() print runInfo()
elif func == 'error_log': elif func == 'error_log':

@ -63,22 +63,23 @@ function orPluginOpService(a, b, v) {
} }
layer.confirm( msgTpl('您真的要{1}{2}{3}服务吗?', [d,a,v]), {icon:3,closeBtn: 2}, function() { layer.confirm( msgTpl('您真的要{1}{2}{3}服务吗?', [d,a,v]), {icon:3,closeBtn: 2}, function() {
orPost('get_os',{},function(data){ orPost('get_os',{},function(data){
if (data.data == 'darwin'){ var rdata = $.parseJSON(data.data);
if (rdata['os'] == 'darwin' && !rdata['auth']){
layer.prompt({title: '检查到权限不足,需要输入密码!', formType: 1},function(pwd, index){ layer.prompt({title: '检查到权限不足,需要输入密码!', formType: 1},function(pwd, index){
layer.close(index); layer.close(index);
var data = {'pwd':pwd}; var data = {'pwd':pwd};
c += '&args='+JSON.stringify(data); c += '&args='+JSON.stringify(data);
orPluginOpServiceOp(a,c,d,a,v); orPluginOpServiceOp(a,b,c,d,a,v);
}); });
} else { } else {
orPluginOpServiceOp(a,c,d,a,v); orPluginOpServiceOp(a,b,c,d,a,v);
} }
}); });
}) })
} }
function orPluginOpServiceOp(a,c,d,a,v){ function orPluginOpServiceOp(a,b,c,d,a,v){
var e = layer.msg(msgTpl('正在{1}{2}{3}服务,请稍候...',[d,a,v]), {icon: 16,time: 0}); var e = layer.msg(msgTpl('正在{1}{2}{3}服务,请稍候...',[d,a,v]), {icon: 16,time: 0});
$.post("/plugins/run", c, function(g) { $.post("/plugins/run", c, function(g) {
layer.close(e); layer.close(e);

Loading…
Cancel
Save