def initdUinstall(): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" if mw.isAppleSystem(): mw.execShell('chkconfig --del ' + getPluginName()) initd_bin = getInitDFile() os.remove(initd_bin) mw.execShell('systemctl disable mongod') return 'ok'
def getSshInfoApi(self): file = '/etc/ssh/sshd_config' conf = mw.readFile(file) rep = "#*Port\s+([0-9]+)\s*\n" port = re.search(rep, conf).groups(0)[0] isPing = True try: if mw.isAppleSystem(): isPing = True else: file = '/etc/sysctl.conf' conf = mw.readFile(file) rep = "#*net\.ipv4\.icmp_echo_ignore_all\s*=\s*([0-9]+)" tmp = re.search(rep, conf).groups(0)[0] if tmp == '1': isPing = False except: isPing = True import system_api panelsys = system_api.system_api() version = panelsys.getSystemVersion() if os.path.exists('/usr/bin/apt-get'): if os.path.exists('/etc/init.d/sshd'): cmd = "service sshd status | grep -P '(dead|stop)'|grep -v grep" status = mw.execShell(cmd) else: cmd = "service ssh status | grep -P '(dead|stop)'|grep -v grep" status = mw.execShell(cmd) else: if version.find(' 7.') != -1: cmd = "systemctl status sshd.service | grep 'dead'|grep -v grep" status = mw.execShell(cmd) else: cmd = "/etc/init.d/sshd status | grep -e 'stopped' -e '已停'|grep -v grep" status = mw.execShell(cmd) if len(status[0]) > 3: status = False else: status = True data = {} data['port'] = port data['status'] = status data['ping'] = isPing if mw.isAppleSystem(): data['firewall_status'] = False else: data['firewall_status'] = self.getFwStatus() return mw.getJson(data)
def initdInstall(): import shutil if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" if mw.isAppleSystem(): source_bin = initDreplace() initd_bin = getInitDFile() shutil.copyfile(source_bin, initd_bin) mw.execShell('chmod +x ' + initd_bin) mw.execShell('chkconfig --add ' + getPluginName()) mw.execShell('systemctl enable mongod') return 'ok'
def getRunUser(): if mw.isAppleSystem(): user = mw.execShell( "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() return user else: return 'root'
def rootDir(): path = '/root' if mw.isAppleSystem(): user = mw.execShell( "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() path = '/Users/' + user return path
def uninstallApi(self): rundir = mw.getRunDir() name = request.form.get('name', '') version = request.form.get('version', '') if name.strip() == '': return mw.returnJson(False, "缺少插件名称!", ()) if version.strip() == '': return mw.returnJson(False, "缺少版本信息!", ()) infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json' if not os.path.exists(infoJsonPos): return mw.returnJson(False, "配置文件不存在!", ()) pluginInfo = json.loads(mw.readFile(infoJsonPos)) execstr = "cd " + os.getcwd() + "/plugins/" + \ name + " && /bin/bash " + pluginInfo["shell"] \ + " uninstall " + version data = mw.execShell(execstr) if mw.isAppleSystem(): print(execstr) print(data[0], data[1]) return mw.returnJson(True, '卸载执行成功!')
def initdUinstall(): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" mw.execShell('systemctl disable ' + getPluginName()) return 'ok'
def runInfo(): import pymongo client = pymongo.MongoClient(host='127.0.0.1', port=27017) db = client.admin serverStatus = db.command('serverStatus') listDbs = client.list_database_names() showDbList = [] for x in range(len(listDbs)): mongd = client[listDbs[x]] stats = mongd.command({"dbstats": 1}) showDbList.append(stats) # print(showDbList) # print(serverStatus) # for key, value in serverStatus.items(): # print(key, value) result = {} result["version"] = serverStatus['version'] result["uptime"] = serverStatus['uptime'] result['db_path'] = '/var/lib/mongo' if mw.isAppleSystem(): result['db_path'] = getServerDir() + "/data" result["connections"] = serverStatus['connections']['current'] result["collections"] = serverStatus['catalogStats']['collections'] result["dbs"] = showDbList return mw.getJson(result)
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 mw.isAppleSystem(): mw.execShell("sed -i .bak '/^\(" + username + "\)/d' " + path) else: mw.execShell("sed -i '/^\(" + username + "\)/d' " + path) # print 'echo "' + username + " l2tpd " + password + " *\" >>" # + path ret = mw.execShell("echo \"" + username + " l2tpd " + password + " *\" >>" + path) if ret[1] == '': return mw.returnJson(True, '修改成功!') return mw.returnJson(False, '修改失败')
def getHomeDir(): if mw.isAppleSystem(): user = mw.execShell( "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() return '/Users/' + user else: return '/root'
def initdStatus(): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" if mw.isAppleSystem(): initd_bin = getInitDFile() if os.path.exists(initd_bin): return 'ok' return 'fail' shell_cmd = 'systemctl status mongod | grep loaded | grep "enabled;"' data = mw.execShell(shell_cmd) if data[0] == '': return 'fail' return 'ok'
def contentReplace(content, version): service_path = mw.getServerDir() content = content.replace('{$ROOT_PATH}', mw.getRootDir()) content = content.replace('{$SERVER_PATH}', service_path) content = content.replace('{$PHP_VERSION}', version) content = content.replace('{$LOCAL_IP}', mw.getLocalIp()) if mw.isAppleSystem(): # user = mw.execShell( # "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() content = content.replace('{$PHP_USER}', 'nobody') content = content.replace('{$PHP_GROUP}', 'nobody') rep = 'listen.owner\s*=\s*(.+)\r?\n' val = ';listen.owner = nobody\n' content = re.sub(rep, val, content) rep = 'listen.group\s*=\s*(.+)\r?\n' val = ';listen.group = nobody\n' content = re.sub(rep, val, content) rep = 'user\s*=\s*(.+)\r?\n' val = ';user = nobody\n' content = re.sub(rep, val, content) rep = r'[^\.]group\s*=\s*(.+)\r?\n' val = ';group = nobody\n' content = re.sub(rep, val, content) else: content = content.replace('{$PHP_USER}', 'www') content = content.replace('{$PHP_GROUP}', 'www') return content
def setFwApi(self): if mw.isAppleSystem(): return mw.returnJson(True, '开发机不能设置!') status = request.form.get('status', '1') if status == '1': if self.__isUfw: mw.execShell('/usr/sbin/ufw stop') return if self.__isFirewalld: mw.execShell('systemctl stop firewalld.service') mw.execShell('systemctl disable firewalld.service') elif self.__isMac: pass else: mw.execShell('/etc/init.d/iptables save') mw.execShell('/etc/init.d/iptables stop') else: if self.__isUfw: mw.execShell('/usr/sbin/ufw start') return if self.__isFirewalld: mw.execShell('systemctl start firewalld.service') mw.execShell('systemctl enable firewalld.service') elif self.__isMac: pass else: mw.execShell('/etc/init.d/iptables save') mw.execShell('/etc/init.d/iptables restart') return mw.returnJson(True, '设置成功!')
def __init__(self): if os.path.exists('/usr/sbin/firewalld'): self.__isFirewalld = True if os.path.exists('/usr/sbin/ufw'): self.__isUfw = True if mw.isAppleSystem(): self.__isMac = True
def setFileAccessApi(self): if mw.isAppleSystem(): return mw.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 mw.returnJson(False, '请不要花样作死') if not os.path.exists(filename): return mw.returnJson(False, '指定文件不存在!') os.system('chmod ' + sall + ' ' + access + " '" + filename + "'") os.system('chown ' + sall + ' ' + user + ':' + user + " '" + filename + "'") msg = mw.getInfo('设置[{1}]权限为[{2}]所有者为[{3}]', ( filename, access, user, )) mw.writeLog('文件管理', msg) return mw.returnJson(True, '设置成功!') except: return mw.returnJson(False, '设置失败!')
def syncDateApi(self): if mw.isAppleSystem(): return mw.returnJson(True, '开发系统不必同步时间!') data = mw.execShell('ntpdate -s time.nist.gov') if data[0] == '': return mw.returnJson(True, '同步成功!') return mw.returnJson(False, '同步失败:' + data[0])
def start(): if mw.isAppleSystem(): return "Apple Computer does not support" data = mw.execShell('service jenkins start') if data[1] == '': return 'ok' return 'fail'
def stop(): if mw.isAppleSystem(): return "Apple Computer does not support" data = mw.execShell('service ss5 stop') if data[1] == '': return 'ok' return data[1]
def restart(): if mw.isAppleSystem(): return "Apple Computer does not support" data = mw.execShell('service xl2tpd restart') if data[0] == '': return 'ok' return data[1]
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 initdUinstall(version): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" mw.execShell('chkconfig --del ' + getPluginName()) initd_bin = getInitDFile(version) os.remove(initd_bin) return 'ok'
def getMinData(conn, sec): time_diff = 0 if mw.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 getHomePage(): try: port = getPort() ip = '127.0.0.1' if not mw.isAppleSystem(): ip = mw.getLocalIp() url = 'http://' + ip + ':' + port + '/index.php' return mw.returnJson(True, 'OK', url) except Exception as e: return mw.returnJson(False, '插件未启动!')
def status(): if not app_debug: if mw.isAppleSystem(): return "stop" data = mw.execShell('sudo sysctl -n net.ipv4.tcp_congestion_control') r = data[0].strip() if r == 'bbr': return 'start' return 'stop'
def start(): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" mw.execShell('echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf') cmd = 'echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf' mw.execShell(cmd) mw.execShell('sysctl -p') return '执行成功!重启系统生效'
def reload(): if mw.isAppleSystem(): return "Apple Computer does not support" # data = mw.execShell('systemctl reload rsyncd.service') # if data[1] == '': # return 'ok' # return 'fail' stop() start() return 'ok'
def initdStatus(): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" _initd_csvn = '/etc/init.d/csvn' _initd_csvn_httpd = '/etc/init.d/csvn-httpd' if os.path.exists(_initd_csvn) and os.path.exists(_initd_csvn_httpd): return 'ok' return 'fail'
def initdUinstall(): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" _csvn = getServerDir() + '/bin/csvn' _csvn_httpd = getServerDir() + '/bin/csvn-httpd' ret_csvn = mw.execShell(_csvn + ' remove') ret_csvn_httpd = mw.execShell(_csvn_httpd + ' remove') return 'ok'
def stop(): if not app_debug: if mw.isAppleSystem(): return "Apple Computer does not support" cmd1 = "sed -i '/net\.core\.default_qdisc/d' /etc/sysctl.conf" mw.execShell(cmd1) cmd2 = "sed -i '/net\.ipv4\.tcp_congestion_control/d' /etc/sysctl.conf" mw.execShell(cmd2) mw.execShell("sysctl -p") return '执行成功!重启系统生效'
def reload(): if mw.isAppleSystem(): file = initDreplace() data = mw.execShell(file + ' reload') if data[1] == '': return 'ok' return 'fail' data = mw.execShell('systemctl reload mongod') if data[1] == '': return 'ok' return 'fail'