def modUser(): args = getArgs() data = checkArgs(args, ['username', 'password']) if not data[0]: return data[1] path = getPathFile() username = args['username'] password = args['password'] # sed -i "/^\<${user}\>/d" /etc/ppp/chap-secrets # echo "${user} l2tpd ${pass} *" >> /etc/ppp/chap-secrets if public.isAppleSystem(): public.execShell("sed -i .bak '/^\(" + username + "\)/d' " + path) else: public.execShell("sed -i '/^\(" + username + "\)/d' " + path) # print 'echo "' + username + " l2tpd " + password + " *\" >>" # + path ret = public.execShell("echo \"" + username + " l2tpd " + password + " *\" >>" + path) if ret[1] == '': return public.returnJson(True, '修改成功!') return public.returnJson(False, '修改失败')
def initDreplace(): ddir = getServerDir() + '/workers' if not os.path.exists(ddir): sdir = getPluginDir() + '/workers' public.execShell('cp -rf ' + sdir + ' ' + getServerDir()) cfg = getServerDir() + '/db.cfg' if not os.path.exists(cfg): cfg_tpl = getPluginDir() + '/workers/db.cfg' content = public.readFile(cfg_tpl) public.writeFile(cfg, content) file_tpl = getInitDTpl() service_path = os.path.dirname(os.getcwd()) initD_path = getServerDir() + '/init.d' if not os.path.exists(initD_path): os.mkdir(initD_path) file_bin = initD_path + '/' + getPluginName() # initd replace content = public.readFile(file_tpl) content = content.replace('{$SERVER_PATH}', service_path) public.writeFile(file_bin, content) public.execShell('chmod +x ' + file_bin) return file_bin
def initdUinstall(): if not app_debug: if public.isAppleSystem(): return "Apple Computer does not support" initd_bin = getInitDFile() os.remove(initd_bin) public.execShell('chkconfig --del ' + getPluginName()) return 'ok'
def initConf(): l2tp_cs = getServerDir() + '/chap-secrets' if not os.path.exists(l2tp_cs): public.execShell('cp -rf ' + getPluginDir() + '/tmp/chap-secrets' + ' ' + getServerDir()) l2tp_is = getServerDir() + '/ipsec.secrets' if not os.path.exists(l2tp_is): public.execShell('cp -rf ' + getPluginDir() + '/tmp/ipsec.secrets' + ' ' + getServerDir())
def initdInstall(): import shutil if not app_debug: if public.isAppleSystem(): return "Apple Computer does not support" mysql_bin = initDreplace() initd_bin = getInitDFile() shutil.copyfile(mysql_bin, initd_bin) public.execShell('chmod +x ' + initd_bin) public.execShell('chkconfig --add ' + getPluginName()) return 'ok'
def start(): cmd = "ps -ef | grep qbittorrent-nox |grep -v grep |awk '{print $2}'" ret = public.execShell(cmd) if ret[0] == '': public.execShell('qbittorrent-nox -d') file = initDreplace() data = public.execShell(file + ' start') if data[1] == '': return 'ok' return data[1]
def start(): file = initDreplace() data = public.execShell(file + ' start') if data[1] == '': return 'ok' return data[1]
def deleteDirApi(self): path = request.form.get('path', '').encode('utf-8') if not os.path.exists(path): return public.returnJson(False, '指定文件不存在!') # 检查是否为.user.ini if path.find('.user.ini'): os.system("chattr -i '" + path + "'") try: if os.path.exists('data/recycle_bin.pl'): if self.mvRecycleBin(path): return public.returnJson(True, '已将文件移动到回收站!') public.execShell('rm -rf ' + path) public.writeLog('文件管理', '删除文件成功!', (path,)) return public.returnJson(True, '删除文件成功!') except: return public.returnJson(False, '删除文件失败!')
def stop(): file = initDreplace() data = public.execShell(file + ' stop') # cmd = "ps -ef | grep qbittorrent-nox |grep -v grep |awk '{print $2}' | xargs kill" # public.execShell(cmd) if data[1] == '': return 'ok' return data[1]
def restart(): if public.isAppleSystem(): return "Apple Computer does not support" data = public.execShell('service xl2tpd restart') if data[0] == '': return 'ok' return data[1]
def setFileAccept(self, filename): auth = 'www:www' if public.getOs() == 'darwin': user = public.execShell( "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() auth = user + ':staff' os.system('chown -R ' + auth + ' ' + filename) os.system('chmod -R 755 ' + filename)
def addUser(): if public.isAppleSystem(): return public.returnJson(False, "Apple Computer does not support") args = getArgs() data = checkArgs(args, ['username']) if not data[0]: return data[1] ret = public.execShell('echo ' + args['username'] + '|l2tp -a') if ret[1] == '': return public.returnJson(True, '添加成功!:' + ret[0]) return public.returnJson(False, '添加失败:' + ret[0])
def writeShell(self, config): u_file = '/var/spool/cron/crontabs/root' if not os.path.exists(u_file): file = '/var/spool/cron/root' if public.isAppleSystem(): file = '/etc/crontab' else: file = u_file if not os.path.exists(file): public.writeFile(file, '') conf = public.readFile(file) conf += config + "\n" if public.writeFile(file, conf): if not os.path.exists(u_file): public.execShell("chmod 600 '" + file + "' && chown root.root " + file) else: public.execShell("chmod 600 '" + file + "' && chown root.crontab " + file) return True return public.returnJson(False, '文件写入失败,请检查是否开启系统加固功能!')
def crondReload(self): if public.isAppleSystem(): if os.path.exists('/etc/crontab'): pass # public.execShell('/usr/sbin/cron restart') else: if os.path.exists('/etc/init.d/crond'): public.execShell('/etc/init.d/crond reload') elif os.path.exists('/etc/init.d/cron'): public.execShell('service cron restart') else: public.execShell("systemctl reload crond")
def initInitD(): script = public.getRunDir() + '/scripts/init.d/mw.tpl' script_bin = public.getRunDir() + '/scripts/init.d/mw' # if os.path.exists(script_bin): # return content = public.readFile(script) content = content.replace("{$SERVER_PATH}", public.getRunDir()) public.writeFile(script_bin, content) public.execShell('chmod +x ' + script_bin) if not public.isAppleSystem(): initd_bin = '/etc/init.d/mw' if not os.path.exists(initd_bin): import shutil shutil.copyfile(script_bin, initd_bin) public.execShell('chmod +x ' + initd_bin) #加入自启动 public.execShell('chkconfig --add mw')
def reload(): data = public.execShell('service xl2tpd reload') if data[0] == '': return 'ok' return data[1]
def status(): cmd = "ps -ef|grep xl2tpd |grep -v grep | grep -v python | awk '{print $2}'" data = public.execShell(cmd) if data[0] == '': return 'stop' return 'start'
def getShell(self, param): # try: stype = param['stype'] if stype == 'toFile': shell = param.sFile else: head = "#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n" log = '.log' wheres = { 'path': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py path " + param['sname'] + " " + str(param['save']), 'site': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py site " + param['sname'] + " " + str(param['save']), 'database': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py database " + param['sname'] + " " + str(param['save']), 'logs': head + "python " + public.getServerDir() + "/mdserver-web/scripts/logs_backup.py " + param['sname'] + log + " " + str(param['save']), 'rememory': head + "/bin/bash " + public.getServerDir() + '/mdserver-web/scripts/rememory.sh' } if param['backup_to'] != 'localhost': cfile = public.getServerDir( ) + "/mdserver-web/plugin/" + param['backup_to'] + "/" + param[ 'backup_to'] + "_main.py" if not os.path.exists(cfile): cfile = public.getServerDir() + "/mdserver-web/script/backup_" + \ param['backup_to'] + ".py" wheres = { 'path': head + "python " + cfile + " path " + param['sname'] + " " + str(param['save']), 'site': head + "python " + cfile + " site " + param['sname'] + " " + str(param['save']), 'database': head + "python " + cfile + " database " + param['sname'] + " " + str(param['save']), 'logs': head + "python " + public.getServerDir() + "/mdserver-web/scripts/logs_backup.py " + param['sname'] + log + " " + str(param['save']), 'rememory': head + "/bin/bash " + public.getServerDir() + '/mdserver-web/scripts/rememory.sh' } try: shell = wheres[stype] except: if stype == 'toUrl': shell = head + "curl -sS --connect-timeout 10 -m 60 '" + \ param['urladdress'] + "'" else: shell = head + param['sbody'].replace("\r\n", "\n") shell += ''' echo "----------------------------------------------------------------------------" endDate=`date +"%Y-%m-%d %H:%M:%S"` echo "★[$endDate] Successful" echo "----------------------------------------------------------------------------" ''' cronPath = public.getServerDir() + '/cron' if not os.path.exists(cronPath): public.execShell('mkdir -p ' + cronPath) if not 'echo' in param: cronName = public.md5(public.md5(str(time.time()) + '_mw')) else: cronName = param['echo'] file = cronPath + '/' + cronName public.writeFile(file, self.checkScript(shell)) public.execShell('chmod 750 ' + file) return cronName
def status(): data = public.execShell( "ps -ef|grep qbittorrent_worker | grep -v grep | awk '{print $2}'") if data[0] == '': return 'stop' return 'start'
def getDirSize(self, path): if public.getOs() == 'darwin': tmp = public.execShell('du -sh ' + path) else: tmp = public.execShell('du -sbh ' + path) return tmp
def reload(): file = initDreplace() data = public.execShell(file + ' reload') if data[1] == '': return 'ok' return 'fail'
def status(): data = public.execShell( "ps -ef|grep \"simdht_worker.py\" | grep -v grep | awk '{print $2}'") if data[0] == '': return 'stop' return 'start'