diff --git a/data/sql/default.sql b/data/sql/default.sql index bc99e4163..ec3bc47d0 100755 --- a/data/sql/default.sql +++ b/data/sql/default.sql @@ -43,14 +43,15 @@ CREATE TABLE IF NOT EXISTS `firewall` ( `port` TEXT, `protocol` TEXT DEFAULT 'tcp', `ps` TEXT, - `add_time` TEXT + `add_time` TEXT, + `update_time` TEXT ); ALTER TABLE `firewall` ADD COLUMN `protocol` TEXT DEFAULT 'tcp'; INSERT INTO `firewall` (`id`, `port`, `protocol`, `ps`, `add_time`) VALUES -(1, '80', 'tcp','网站默认端口', '0000-00-00 00:00:00'), -(2, '443', 'tcp/udp', 'HTTPS', '0000-00-00 00:00:00'); +(1, '80', 'tcp','网站默认端口', '0000-00-00 00:00:00','0000-00-00 00:00:00'), +(2, '443', 'tcp/udp', 'HTTPS', '0000-00-00 00:00:00','0000-00-00 00:00:00'); diff --git a/web/admin/__init__.py b/web/admin/__init__.py index 2c3d468c9..359557fea 100644 --- a/web/admin/__init__.py +++ b/web/admin/__init__.py @@ -100,13 +100,12 @@ setup.init_db_system() app.config['BASIC_AUTH_OPEN'] = False -with app.app_context(): - try: - basic_auth = model.getOptionByJson('basic_auth', default={'open':False}) - if basic_auth['open']: - app.config['BASIC_AUTH_OPEN'] = True - except Exception as e: - pass +try: + basic_auth = model.getOptionByJson('basic_auth', default={'open':False}) + if basic_auth['open']: + app.config['BASIC_AUTH_OPEN'] = True +except Exception as e: + pass @@ -127,6 +126,7 @@ def sendAuthenticated(): @app.before_request def requestCheck(): + config.APP_START_TIME=time.time() # 自定义basic auth认证 if app.config['BASIC_AUTH_OPEN']: basic_auth = model.getOptionByJson('basic_auth', default={'open':False}) @@ -152,6 +152,8 @@ def requestCheck(): def requestAfter(response): response.headers['soft'] = config.APP_NAME response.headers['mw-version'] = config.APP_VERSION + if mw.isDebugMode(): + response.headers['mw-debug-cos'] = time.time() - config.APP_START_TIME return response @@ -163,20 +165,16 @@ def page_unauthorized(error): # 设置模板全局变量 @app.context_processor def inject_global_variables(): - start_t = time.time() - ver = config.APP_VERSION; + app_ver = config.APP_VERSION if mw.isDebugMode(): - ver = ver + str(time.time()) + app_ver = app_ver + str(time.time()) data = utils_config.getGlobalVar() g_config = { - 'version': ver, + 'version': app_ver, 'title' : 'MW面板', 'ip' : '127.0.0.1' } - - end_t = time.time() - print("cos:"+str(end_t-start_t)) return dict(config=g_config, data=data) diff --git a/web/admin/crontab/__init__.py b/web/admin/crontab/__init__.py index 3e8232e40..b1b76ba98 100644 --- a/web/admin/crontab/__init__.py +++ b/web/admin/crontab/__init__.py @@ -23,40 +23,82 @@ blueprint = Blueprint('crontab', __name__, url_prefix='/crontab', template_folde def index(): return render_template('crontab.html') -# 插件列表 -@blueprint.route('/list', endpoint='list', methods=['GET','POST']) +# 计划任务列表 +@blueprint.route('/list', endpoint='list', methods=['POST']) @panel_login_required def list(): page = request.args.get('p', '1').strip() limit = request.args.get('limit', '10').strip() return MwCrontab.instance().getCrontabList(page=int(page),size=int(limit)) -# 插件列表 -@blueprint.route('/logs', endpoint='logs', methods=['GET','POST']) -def logs(self): - sid = request.form.get('id', '') - echo = mw.M('crontab').where("id=?", (sid,)).field('echo').find() - logFile = mw.getServerDir() + '/cron/' + echo['echo'] + '.log' - if not os.path.exists(logFile): - return mw.returnData(False, '当前日志为空!') - log = mw.getLastLine(logFile, 500) - return mw.returnData(True, log) +# 计划任务日志 +@blueprint.route('/logs', endpoint='logs', methods=['POST']) +def logs(): + cron_id = request.form.get('id', '') + return MwCrontab.instance().cronLog(cron_id) -# 获取计划任务 -@blueprint.route('/del', endpoint='del', methods=['GET','POST']) +# 删除计划任务 +@blueprint.route('/del', endpoint='del', methods=['POST']) def crontab_del(): - task_id = request.form.get('id', '') - return MwCrontab.instance().delete(task_id) + cron_id = request.form.get('id', '') + return MwCrontab.instance().delete(cron_id) + +# 删除计划任务日志 +@blueprint.route('/del_logs', endpoint='del_logs', methods=['POST']) +def del_logs(): + cron_id = request.form.get('id', '') + return MwCrontab.instance().delLogs(cron_id) + + +# 设置计划任务状态 +@blueprint.route('/set_cron_status', endpoint='set_cron_status', methods=['POST']) +def set_cron_status(): + cron_id = request.form.get('id', '') + return MwCrontab.instance().setCronStatus(cron_id) + +# 设置计划任务状态 +@blueprint.route('/get_data_list', endpoint='get_data_list', methods=['POST']) +def get_data_list(): + stype = request.form.get('type', '') + return MwCrontab.instance().getDataList(stype) + # 获取计划任务 -@blueprint.route('/get_crond_find', endpoint='get_crond_find', methods=['GET','POST']) +@blueprint.route('/get_crond_find', endpoint='get_crond_find', methods=['POST']) def get_crond_find(): - sid = request.form.get('id', '') - data = MwCrontab.instance().getCrondFind(sid) + cron_id = request.form.get('id', '') + data = MwCrontab.instance().getCrondFind(cron_id) return data +# 修改计划任务 +@blueprint.route('/modify_crond', endpoint='modify_crond', methods=['POST']) +def modify_crond(): + request_data = {} + + request_data['name'] = request.form.get('name', '') + request_data['type'] = request.form.get('type', '') + request_data['week'] = request.form.get('week', '') + request_data['where1'] = request.form.get('where1', '') + request_data['hour'] = request.form.get('hour', '') + request_data['minute'] = request.form.get('minute', '') + request_data['save'] = request.form.get('save', '') + request_data['backup_to'] = request.form.get('backupTo', '') + request_data['stype'] = request.form.get('stype', '') + request_data['sname'] = request.form.get('sname', '') + request_data['sbody'] = request.form.get('sbody', '') + request_data['url_address'] = request.form.get('urladdress', '') + cron_id = request.form.get('id', '') + data = MwCrontab.instance().modifyCrond(cron_id,request_data) + return data + +# 执行计划任务 +@blueprint.route('/start_task', endpoint='start_task', methods=['POST']) +def start_task(): + cron_id = request.form.get('id', '') + return MwCrontab.instance().startTask(cron_id) + # 添加计划任务 -@blueprint.route('/add', endpoint='add', methods=['GET','POST']) +@blueprint.route('/add', endpoint='add', methods=['POST']) @panel_login_required def add(): request_data = {} diff --git a/web/admin/firewall/__init__.py b/web/admin/firewall/__init__.py index a14c0dff7..8cd65a986 100644 --- a/web/admin/firewall/__init__.py +++ b/web/admin/firewall/__init__.py @@ -33,25 +33,7 @@ def index(): def get_list(): p = request.form.get('p', '1').strip() limit = request.form.get('limit', '10').strip() - - count = Firewall.query.filter_by().count() - pagination = Firewall.query.filter_by().paginate(page=int(p), per_page=int(limit)) - - rows = [] - for item in pagination.items: - t = {} - t['id'] = item.id - t['port'] = item.port - t['protocol'] = item.protocol - t['ps'] = item.ps - t['add_time'] = item.add_time - t['update_time'] = item.update_time - rows.append(t) - - data = {} - data['data'] = rows - data['page'] = mw.getPage({'count':count,'tojs':'getLogs','p':p,'row':limit}) - return data + return MwFirewall.instance().getList(p,limit) # 获取站点日志目录 @blueprint.route('/get_www_path', endpoint='get_www_path', methods=['POST']) @@ -64,8 +46,7 @@ def get_www_path(): @blueprint.route('/get_ssh_info', endpoint='get_ssh_info', methods=['POST']) @panel_login_required def get_ssh_info(): - mf = MwFirewall.instance() - return mf.getSshInfo() + return MwFirewall.instance().getSshInfo() # 切换ping开关 @@ -88,8 +69,7 @@ def add_accept_port(): protocol = request.form.get('protocol', '').strip() stype = request.form.get('type', '').strip() - data = mf.addAcceptPort(port, ps, stype, protocol=protocol) - return mw.getJson(data) + return mf.addAcceptPort(port, ps, stype, protocol=protocol) diff --git a/web/config.py b/web/config.py index 1b84db8df..82aa42513 100644 --- a/web/config.py +++ b/web/config.py @@ -60,3 +60,6 @@ SQLITE_PATH = os.path.join(DATA_DIR, APP_SQLITE_NAME + '.db') DEFAULT_SERVER = '127.0.0.1' DEFAULT_SERVER_PORT = 7201 +# APP启动时间 +APP_START_TIME=0 + diff --git a/web/core/mw.py b/web/core/mw.py index e935077c7..8b970cab6 100644 --- a/web/core/mw.py +++ b/web/core/mw.py @@ -97,6 +97,13 @@ def getServerDir(): def getLogsDir(): return getFatherDir() + '/wwwlogs' +def getWwwDir(): + file = getPanelDir() + '/data/site.pl' + if os.path.exists(file): + return readFile(file).strip() + return getFatherDir() + '/wwwroot' + + def getRecycleBinDir(): rb_dir = getFatherDir() + '/recycle_bin' if not os.path.exists(rb_dir): diff --git a/web/static/app/crontab.js b/web/static/app/crontab.js index b8aea37d1..fe21632c4 100755 --- a/web/static/app/crontab.js +++ b/web/static/app/crontab.js @@ -83,7 +83,6 @@ function getBackupName(hook_data, name){ function getCronData(page){ var load = layer.msg(lan.public.the,{icon:16,time:0,shade: [0.3, '#000']}); $.post("/crontab/list?p="+page,'', function(rdata){ - console.log(rdata); layer.close(load); var cbody = ""; if(rdata == ""){ diff --git a/web/static/app/public.js b/web/static/app/public.js index 8516508d4..6188975cf 100755 --- a/web/static/app/public.js +++ b/web/static/app/public.js @@ -259,7 +259,6 @@ function getFormatTime(tm, format) { function changePathCallback(default_dir, callback) { - var c = layer.open({ type: 1, area: "650px", @@ -276,7 +275,7 @@ function changePathCallback(default_dir, callback) { \
\
\ -
计算机
\ +
计算机
\
\
\ \ @@ -387,14 +386,15 @@ function getDiskList(b) { var a = ""; var c = "path=" + b + "&disk=True"; $.post("/files/get_dir", c, function(h) { - if(h.DISK != undefined) { - for(var f = 0; f < h.DISK.length; f++) { - a += "
 " + h.DISK[f].path + "
" - } - $("#changecomlist").html(a) - } - for(var f = 0; f < h.DIR.length; f++) { - var g = h.DIR[f].split(";"); + // console.log(h); + // if(h.dir != undefined) { + // for(var f = 0; f < h.dir.length; f++) { + // a += "
 " + h.dir[f].path + "
"; + // } + // $("#changecomlist").html(a); + // } + for(var f = 0; f < h.dir.length; f++) { + var g = h.dir[f].split(";"); var e = g[0]; if(isChineseChar(e)) { @@ -408,16 +408,16 @@ function getDiskList(b) { } d += "\ - \ + \ " + e + "" + getLocalTime(g[2]) + "\ " + g[3] + "\ " + g[4] + "\ - X\ + X\ "; } - if(h.FILES != null && h.FILES != "") { - for(var f = 0; f < h.FILES.length; f++) { - var g = h.FILES[f].split(";"); + if(h.files != null && h.files != "") { + for(var f = 0; f < h.files.length; f++) { + var g = h.files[f].split(";"); var e = g[0]; if(isChineseChar(e)) { if(e.length > 10) { @@ -441,10 +441,10 @@ function getDiskList(b) { $(".default").hide(); $(".file-list").show(); $("#tbody").html(d); - if(h.PATH.substr(h.PATH.length - 1, 1) != "/") { - h.PATH += "/"; + if(h.path.substr(h.path.length - 1, 1) != "/") { + h.path += "/"; } - $("#PathPlace").find("span").html(h.PATH); + $("#PathPlace").find("span").html(h.path); activeDisk(); return; },'json'); @@ -530,10 +530,11 @@ function activeDisk() { } function backMyComputer() { - $(".default").show(); - $(".file-list").hide(); - $("#PathPlace").find("span").html(""); - activeDisk(); + // $(".default").show(); + // $(".file-list").hide(); + // $("#PathPlace").find("span").html(""); + // activeDisk(); + return; } function backFile() { @@ -1601,13 +1602,6 @@ function activeDisk() { } -function backMyComputer() { - $(".default").show(); - $(".file-list").hide(); - $("#PathPlace").find("span").html(""); - activeDisk(); -} - //检查登陆状态 function check_login(){ $.post('/check_login',{},function(rdata){ diff --git a/web/thisdb/__init__.py b/web/thisdb/__init__.py index 85125f384..8958fa60f 100644 --- a/web/thisdb/__init__.py +++ b/web/thisdb/__init__.py @@ -15,3 +15,4 @@ from .sites import * from .tasks import * from .logs import * from .crontab import * +from .firewall import * diff --git a/web/thisdb/crontab.py b/web/thisdb/crontab.py index 27dad974f..32f755598 100644 --- a/web/thisdb/crontab.py +++ b/web/thisdb/crontab.py @@ -20,6 +20,14 @@ def addCrontab(data): data['update_time'] = now_time return mw.M('crontab').insert(data) +def setCrontabData(cron_id, data): + mw.M('crontab').where('id=?', (cron_id,)).update(data) + return True + +def setCrontabStatus(cron_id, status): + mw.M('crontab').where('id=?', (cron_id,)).update({'status':status}) + return True + def getCrond(id): return mw.M('crontab').where('id=?', (id,)).field(__field).find() @@ -40,4 +48,5 @@ def getCrontabList( data = {} data['count'] = count data['list'] = cron_list - return data \ No newline at end of file + return data + diff --git a/web/thisdb/firewall.py b/web/thisdb/firewall.py new file mode 100644 index 000000000..88c7b0c39 --- /dev/null +++ b/web/thisdb/firewall.py @@ -0,0 +1,55 @@ +# coding:utf-8 + +# --------------------------------------------------------------------------------- +# MW-Linux面板 +# --------------------------------------------------------------------------------- +# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. +# --------------------------------------------------------------------------------- +# Author: midoks +# --------------------------------------------------------------------------------- + +import core.mw as mw + +__FIELD = 'id,port,protocol,ps,add_time,update_time' + +def getFirewallList( + page:int | None = 1, + size:int | None = 10, +): + start = (int(page) - 1) * (int(size)) + limit = str(start) + ',' +str(size) + + firewall_list = mw.M('firewall').field(__FIELD).limit(limit).order('id desc').select() + count = mw.M('firewall').count() + + data = {} + data['count'] = count + data['list'] = firewall_list + return data + +def addFirewall(port, + protocol: str | None = 'tcp', + ps: str | None = '备注' +) -> bool: + ''' + 设置配置的值 + :port -> str 端口 (必填) + :protocol -> str 协议 (可选|tcp,udp,tcp/udp) + :ps -> str 备注 (可选) + ''' + now_time = mw.formatDate() + insert_data = { + 'port':port, + 'protocol':protocol, + 'ps':ps, + 'add_time':now_time, + 'update_time':now_time, + } + mw.M('firewall').insert(insert_data) + return True + + +def getFirewallCountByPort(port): + return mw.M('firewall').where('port=?',(port,)).count() + + diff --git a/web/utils/crontab.py b/web/utils/crontab.py index f9b2d14d5..4a8b6035f 100644 --- a/web/utils/crontab.py +++ b/web/utils/crontab.py @@ -10,6 +10,7 @@ import os import sys +import re import time import json import threading @@ -20,6 +21,7 @@ from admin import model import core.mw as mw import thisdb + class crontab(object): # lock _instance_lock = threading.Lock() @@ -32,6 +34,119 @@ class crontab(object): crontab._instance = crontab(*args, **kwargs) return crontab._instance + def modifyCrond(self,cron_id,data): + if len(data['name']) < 1: + return mw.returnData(False, '任务名称不能为空!') + + is_check_pass, msg = self.cronCheck(data) + if not is_check_pass: + return mw.returnData(is_check_pass, msg) + + info = thisdb.getCrond(cron_id) + + dbdata = {} + dbdata['name'] = data['name'] + dbdata['type'] = data['type'] + dbdata['where1'] = data['where1'] + dbdata['where_hour'] = data['hour'] + dbdata['where_minute'] = data['minute'] + dbdata['save'] = data['save'] + dbdata['backup_to'] = data['backup_to'] + dbdata['sname'] = data['sname'] + dbdata['sbody'] = data['sbody'] + dbdata['stype'] = data['stype'] + dbdata['url_address'] = data['url_address'] + + if not self.removeForCrond(info['echo']): + return mw.returnData(False, '无法写入文件,是否开启了系统加固功能!') + + thisdb.setCrontabData(cron_id, dbdata) + self.syncToCrond(cron_id) + msg = '修改计划任务[' + data['name'] + ']成功' + mw.writeLog('计划任务', msg) + return mw.returnData(True, msg) + + # 取数据列表 + def getDataList(self,stype=''): + + bak_data = [] + if stype == 'site' or stype == 'sites' or stype == 'database' or stype.find('database_') > -1 or stype == 'path': + hookPath = mw.getPanelDataDir() + "/hook_backup.json" + if os.path.exists(hookPath): + t = mw.readFile(hookPath) + bak_data = json.loads(t) + + if stype == 'database' or stype.find('database_') > -1: + sqlite3_name = 'mysql' + path = mw.getServerDir() + '/mysql' + if stype != 'database': + soft_name = stype.replace('database_', '') + path = mw.getServerDir() + '/' + soft_name + + if soft_name == 'postgresql': + sqlite3_name = 'pgsql' + + if soft_name == 'mongodb': + sqlite3_name = 'mongodb' + + db_list = {} + db_list['orderOpt'] = bak_data + + if not os.path.exists(path + '/' + sqlite3_name + '.db'): + db_list['data'] = [] + else: + db_list['data'] = mw.M('databases').dbPos(path, sqlite3_name).field('name,ps').select() + return mw.getJson(db_list) + + if stype == 'path': + db_list = {} + db_list['data'] = [{"name": mw.getWwwDir(), "ps": "www"}] + db_list['orderOpt'] = bak_data + return mw.getJson(db_list) + + data = {} + data['orderOpt'] = bak_data + + default_db = 'sites' + data['data'] = mw.M(default_db).field('name,ps').select() + return mw.getJson(data) + + def setCronStatus(self,cron_id): + data = thisdb.getCrond(cron_id) + + status = 1 + status_msg = '开启' + if data['status'] == status: + status = 0 + status_msg = '关闭' + self.removeForCrond(data['echo']) + else: + data['status'] = 1 + self.syncToCrond(cron_id) + + thisdb.setCrontabStatus(cron_id, status) + + msg = '修改计划任务[' + data['name'] + ']状态为[' + str(status_msg) + ']' + mw.writeLog('计划任务', msg) + return mw.returnJson(True, msg) + + + def cronLog(self, cron_id): + data = thisdb.getCrond(cron_id) + log_file = mw.getServerDir() + '/cron/' + data['echo'] + '.log' + if not os.path.exists(log_file): + return mw.returnData(False, '当前日志为空!') + content = mw.getLastLine(log_file, 500) + return mw.returnData(True, content) + + def startTask(self, cron_id): + data = thisdb.getCrond(cron_id) + cmd_file = mw.getServerDir() + '/cron/' + data['echo'] + os.system('chmod +x ' + cmd_file) + os.system('nohup ' + cmd_file + ' >> ' + cmd_file + '.log 2>&1 &') + return mw.returnData(True, '计划任务【%s】已执行!' % data['name']) + + # 获取指定任务数据 def getCrondFind(self, cron_id): return thisdb.getCrond(cron_id) @@ -78,7 +193,7 @@ class crontab(object): def delete(self, tid): data = thisdb.getCrond(tid) if not self.removeForCrond(data['echo']): - return mw.returnData(False, '无法写入文件,请检查是否开启了系统加固功能!') + return mw.returnData(False, '无法写入文件,是否开启了系统加固功能!') cron_path = mw.getServerDir() + '/cron' cron_file = cron_path + '/' + data['echo'] @@ -94,6 +209,17 @@ class crontab(object): mw.writeLog('计划任务', msg) return mw.returnData(True, msg) + + def delLogs(self,cron_id): + try: + data = thisdb.getCrond(cron_id) + log_file = mw.getServerDir() + '/cron/' + data['echo'] + '.log' + if os.path.exists(log_file): + os.remove(log_file) + return mw.returnData(True, '任务日志已清空!') + except: + return mw.returnData(False, '任务日志清空失败!') + def getCrontabHuman(self, data): rdata = [] for i in range(len(data)): @@ -129,18 +255,23 @@ class crontab(object): if mw.isAppleSystem(): return True - u_file = '/var/spool/cron/crontabs/root' - if not os.path.exists(u_file): - file = '/var/spool/cron/root' - if not os.path.exists(file): - return False - else: - file = u_file + cron_file = [ + '/var/spool/cron/crontabs/root', + '/var/spool/cron/root', + ] - conf = mw.readFile(file) + file = '' + for i in cron_file: + if os.path.exists(file): + file = i + + if file == '': + return False + + content = mw.readFile(file) rep = ".+" + str(echo) + ".+\n" - conf = re.sub(rep, "", conf) - if not mw.writeFile(file, conf): + content = re.sub(rep, "", content) + if not mw.writeFile(file, content): return False self.crondReload() return True @@ -288,7 +419,6 @@ class crontab(object): shell = param.sFile else: head = "#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n" - start_head = ''' SCRIPT_RUN_TIME="0s" MW_ToSeconds() @@ -336,22 +466,16 @@ fi''' % (mw.getPanelDir(),) 'rememory': head + "/bin/bash " + script_dir + '/rememory.sh' } if param['backup_to'] != 'localhost': - cfile = mw.getPluginDir() + "/" + \ - param['backup_to'] + "/index.py" - - wheres['path'] = head + "python3 " + cfile + \ - " path " + param['sname'] + " " + str(param['save']) - wheres['site'] = head + "python3 " + cfile + \ - " site " + param['sname'] + " " + str(param['save']) - wheres['database'] = head + "python3 " + cfile + " " + \ - source_stype + " " + \ - param['sname'] + " " + str(param['save']) + cfile = mw.getPluginDir() + "/" + param['backup_to'] + "/index.py" + + wheres['path'] = head + "python3 " + cfile + " path " + param['sname'] + " " + str(param['save']) + wheres['site'] = head + "python3 " + cfile + " site " + param['sname'] + " " + str(param['save']) + wheres['database'] = head + "python3 " + cfile + " " + source_stype + " " + param['sname'] + " " + str(param['save']) try: shell = wheres[stype] except: if stype == 'toUrl': - shell = head + "curl -sS --connect-timeout 10 -m 60 '" + \ - param['urladdress'] + "'" + shell = head + "curl -sS --connect-timeout 10 -m 60 '" + param['urladdress'] + "'" else: shell = head + param['sbody'].replace("\r\n", "\n") @@ -381,19 +505,19 @@ echo "-------------------------------------------------------------------------- def checkScript(self, shell): keys = ['shutdown', 'init 0', 'mkfs', 'passwd', 'chpasswd', '--stdin', 'mkfs.ext', 'mke2fs'] - for key in keys: - shell = shell.replace(key, '[***]') + for k in keys: + shell = shell.replace(k, '[***]') return shell - - # 将Shell脚本写到文件 - def writeShell(self, config): + def writeShell(self, bash_script): + if mw.isAppleSystem(): + return mw.returnData(True, 'ok') file = '/var/spool/cron/crontabs/root' - current_os = mw.getOs() - if current_os == 'darwin': + sys_os = mw.getOs() + if sys_os == 'darwin': file = '/etc/crontab' - elif current_os.startswith("freebsd"): + elif sys_os.startswith("freebsd"): file = '/var/cron/tabs/root' if not os.path.exists(file): @@ -401,15 +525,16 @@ echo "-------------------------------------------------------------------------- if not os.path.exists(file): mw.writeFile(file, '') - conf = mw.readFile(file) - conf += str(config) + "\n" - if mw.writeFile(file, conf): + + content = mw.readFile(file) + content += str(bash_script) + "\n" + if mw.writeFile(file, content): if not os.path.exists(file): mw.execShell("chmod 600 '" + file +"' && chown root.root " + file) else: mw.execShell("chmod 600 '" + file +"' && chown root.crontab " + file) return mw.returnData(True, 'ok') - return mw.returnData(False, '文件写入失败,请检查是否开启系统加固功能!') + return mw.returnData(False, '文件写入失败,是否开启系统加固功能!') # 重载配置 def crondReload(self): @@ -424,7 +549,22 @@ echo "-------------------------------------------------------------------------- else: mw.execShell("systemctl reload crond") + def syncToCrond(self, cron_id): + info = thisdb.getCrond(cron_id) + if 'status' in info: + if info['status'] == 0: + return False + if 'where_hour' in info: + info['hour'] = info['where_hour'] + info['minute'] = info['where_minute'] + info['week'] = info['where1'] - + cmd, _ = self.getCrondCycle(info) + cron_path = mw.getServerDir() + '/cron' + cron_name = self.getShell(info) + cmd += ' ' + cron_path + '/' + cron_name + ' >> ' + cron_path + '/' + cron_name + '.log 2>&1' + self.writeShell(cmd) + self.crondReload() + return True diff --git a/web/utils/firewall.py b/web/utils/firewall.py index e100925ad..715810947 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -14,9 +14,9 @@ import threading import re import time -from admin import model import core.mw as mw +import thisdb class Firewall(object): @@ -47,6 +47,14 @@ class Firewall(object): elif mw.isAppleSystem(): self.__isMac = True + def getList(self, page=1,size=10): + info = thisdb.getFirewallList(page=page, size=size) + + rdata = {} + rdata['data'] = info['list'] + rdata['page'] = mw.getPage({'count':info['count'],'tojs':'showAccept','p':page,'row':size}) + return rdata + def reload(self): if self.__isUfw: mw.execShell('/usr/sbin/ufw reload') @@ -236,8 +244,7 @@ class Firewall(object): msg = mw.getInfo('放行端口[{1}][{2}]成功', (port, protocol,)) mw.writeLog("防火墙管理", msg) - - return mw.returnData(True, '添加放行(' + port + ')端口成功!') + return mw.returnData(True, msg)