Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/socket5/index.py

208 lines
4.5 KiB

4 years ago
# coding:utf-8
import sys
import io
import os
import time
import shutil
sys.path.append(os.getcwd() + "/class/core")
import mw
app_debug = False
if mw.isAppleSystem():
app_debug = True
def getPluginName():
4 years ago
return 'socket5'
4 years ago
def getPluginDir():
return mw.getPluginDir() + '/' + getPluginName()
def getServerDir():
return mw.getServerDir() + '/' + getPluginName()
4 years ago
def getInitDFile():
if app_debug:
return '/tmp/' + getPluginName()
return '/etc/init.d/ss5'
4 years ago
def initDreplace():
return getPluginDir() + '/init.d/ss5'
4 years ago
def getArgs():
args = sys.argv[2:]
tmp = {}
args_len = len(args)
if args_len == 1:
t = args[0].strip('{').strip('}')
t = t.split(':')
tmp[t[0]] = t[1]
elif args_len > 1:
for i in range(len(args)):
t = args[i].split(':')
tmp[t[0]] = t[1]
return tmp
def checkArgs(data, ck=[]):
for i in range(len(ck)):
if not ck[i] in data:
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
return (True, mw.returnJson(True, 'ok'))
def status():
4 years ago
cmd = "ps -ef|grep ss5 |grep -v grep | grep -v python | awk '{print $2}'"
4 years ago
data = mw.execShell(cmd)
if data[0] == '':
return 'stop'
return 'start'
def initConf():
4 years ago
ss5_conf = getServerDir() + '/ss5.conf'
if not os.path.exists(ss5_conf):
4 years ago
tmp = getPluginDir() + '/tmp/ss5.conf'
if not os.path.exists(tmp):
mw.execShell('cp -rf ' + tmp + ' /etc/opt/ss5')
mw.execShell('cp -rf ' + tmp + ' ' + getServerDir())
4 years ago
4 years ago
init_file = '/etc/init.d/ss5'
if os.path.exists(init_file):
4 years ago
mw.execShell('chmod +x ' + init_file)
4 years ago
4 years ago
ss5_pwd = getServerDir() + '/ss5.passwd'
if not os.path.exists(ss5_pwd):
4 years ago
tmp = getPluginDir() + '/tmp/ss5.passwd'
4 years ago
if not os.path.exists(tmp):
mw.execShell('cp -rf ' + tmp + ' /etc/opt/ss5')
mw.execShell('cp -rf ' + tmp + ' ' + getServerDir())
4 years ago
def start():
initConf()
if mw.isAppleSystem():
return "Apple Computer does not support"
4 years ago
data = mw.execShell('service ss5 start')
4 years ago
if data[1] == '':
4 years ago
return 'ok'
return data[1]
def stop():
if mw.isAppleSystem():
return "Apple Computer does not support"
4 years ago
data = mw.execShell('service ss5 stop')
4 years ago
if data[1] == '':
4 years ago
return 'ok'
return data[1]
def restart():
if mw.isAppleSystem():
return "Apple Computer does not support"
4 years ago
data = mw.execShell('service ss5 restart')
4 years ago
if data[1] == '':
4 years ago
return 'ok'
return data[1]
def reload():
4 years ago
data = mw.execShell('service ss5 reload')
4 years ago
if data[1] == '':
4 years ago
return 'ok'
return data[1]
def getPathFile():
if mw.isAppleSystem():
4 years ago
return getServerDir() + '/ss5.conf'
return '/etc/opt/ss5/ss5.conf'
4 years ago
4 years ago
def getPathFilePwd():
4 years ago
if mw.isAppleSystem():
4 years ago
return getServerDir() + '/ss5.passwd'
return '/etc/opt/ss5/ss5.passwd'
4 years ago
4 years ago
def getPathFilePort():
return '/etc/sysconfig/ss5'
4 years ago
def initdStatus():
if not app_debug:
if mw.isAppleSystem():
return "Apple Computer does not support"
initd_bin = getInitDFile()
if os.path.exists(initd_bin):
return 'ok'
return 'fail'
def initdInstall():
import shutil
if not app_debug:
if mw.isAppleSystem():
return "Apple Computer does not support"
source_bin = initDreplace()
initd_bin = getInitDFile()
shutil.copyfile(source_bin, initd_bin)
mw.execShell('chmod +x ' + initd_bin)
mw.execShell('chkconfig --add ' + getPluginName())
return 'ok'
def initdUinstall():
if not app_debug:
if mw.isAppleSystem():
return "Apple Computer does not support"
mw.execShell('chkconfig --del ' + getPluginName())
initd_bin = getInitDFile()
os.remove(initd_bin)
return 'ok'
4 years ago
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
print status()
elif func == 'start':
print start()
elif func == 'stop':
print stop()
elif func == 'restart':
print restart()
elif func == 'reload':
print reload()
elif func == 'conf':
print getPathFile()
4 years ago
elif func == 'conf_pwd':
4 years ago
print getPathFilePwd()
4 years ago
elif func == 'conf_port':
print getPathFilePort()
4 years ago
elif func == 'initd_status':
print initdStatus()
elif func == 'initd_install':
print initdInstall()
elif func == 'initd_uninstall':
print initdUinstall()
4 years ago
else:
print 'error'