def setFileAccessApi(self): if public.isAppleSystem(): return public.returnJson(True, '开发机不设置!') filename = request.form.get('filename', '').encode('utf-8') user = request.form.get('user', '').encode('utf-8') access = request.form.get('access', '755') sall = '-R' try: if not self.checkDir(filename): return public.returnJson(False, '请不要花样作死') if not os.path.exists(filename): return public.returnJson(False, '指定文件不存在!') os.system('chmod ' + sall + ' ' + access + " '" + filename + "'") os.system('chown ' + sall + ' ' + user + ':' + user + " '" + filename + "'") msg = public.getInfo( '设置[{1}]权限为[{2}]所有者为[{3}]', (filename, access, user,)) public.writeLog('文件管理', msg) return public.returnJson(True, '设置成功!') except: return public.returnJson(False, '设置失败!')
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 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 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 getMinData(conn, sec): time_diff = 0 if public.isAppleSystem(): time_diff = 3 * 60 pre = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() - sec - time_diff)) sql = "select count(id) from search_hash where create_time > '" + pre + "'" data = conn.query(sql) return data[0][0]
def initdStatus(): if not app_debug: if public.isAppleSystem(): return "Apple Computer does not support" initd_bin = getInitDFile() if os.path.exists(initd_bin): return 'ok' return 'fail'
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 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 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 removeForCrond(self, echo): 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 conf = public.readFile(file) rep = ".+" + str(echo) + ".+\n" conf = re.sub(rep, "", conf) if not public.writeFile(file, conf): return False self.crondReload() return True
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 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, '文件写入失败,请检查是否开启系统加固功能!')
# coding: utf-8 import time import random import os import json import re import sys sys.path.append(os.getcwd() + "/class/core") import public app_debug = False if public.isAppleSystem(): app_debug = True def getPluginName(): return 'simdht' def getPluginDir(): return public.getPluginDir() + '/' + getPluginName() sys.path.append(getPluginDir() + "/class") import mysql def getServerDir(): return public.getServerDir() + '/' + getPluginName()
def getPathFilePsk(): if public.isAppleSystem(): return getServerDir() + '/ipsec.secrets' return '/etc/ipsec.secrets'
def getPathFile(): if public.isAppleSystem(): return getServerDir() + '/chap-secrets' return '/etc/ppp/chap-secrets'