diff --git a/class/core/crontab_api.py b/class/core/crontab_api.py index c9f7d682d..ba77196a2 100755 --- a/class/core/crontab_api.py +++ b/class/core/crontab_api.py @@ -500,8 +500,7 @@ class crontab_api: # 取任务构造Month def month(self, param): - cuonConfig = "{0} {1} {2} * * ".format( - param['minute'], param['hour'], param['where1']) + cuonConfig = "{0} {1} {2} * * ".format(param['minute'], param['hour'], param['where1']) return cuonConfig # 取执行脚本 diff --git a/data/sql/default.sql b/data/sql/default.sql index daa5e4521..1acdaa795 100755 --- a/data/sql/default.sql +++ b/data/sql/default.sql @@ -6,7 +6,7 @@ CREATE TABLE IF NOT EXISTS `backup` ( `pid` INTEGER, `filename` TEXT, `size` INTEGER, - `addtime` TEXT + `add_time` TEXT ); CREATE TABLE IF NOT EXISTS `binding` ( @@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS `binding` ( `domain` TEXT, `path` TEXT, `port` INTEGER, - `addtime` TEXT + `add_time` TEXT ); @@ -27,7 +27,6 @@ CREATE TABLE IF NOT EXISTS `crontab` ( `where_hour` INTEGER, `where_minute` INTEGER, `echo` TEXT, - `addtime` TEXT, `status` INTEGER DEFAULT '1', `save` INTEGER DEFAULT '3', `backup_to` TEXT DEFAULT 'off', @@ -35,6 +34,7 @@ CREATE TABLE IF NOT EXISTS `crontab` ( `sbody` TEXT, 'stype' TEXT, `urladdress` TEXT + `add_time` TEXT ); CREATE TABLE IF NOT EXISTS `firewall` ( @@ -42,12 +42,12 @@ CREATE TABLE IF NOT EXISTS `firewall` ( `port` TEXT, `protocol` TEXT DEFAULT 'tcp', `ps` TEXT, - `addtime` TEXT + `add_time` TEXT ); ALTER TABLE `firewall` ADD COLUMN `protocol` TEXT DEFAULT 'tcp'; -INSERT INTO `firewall` (`id`, `port`, `protocol`, `ps`, `addtime`) VALUES +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'); @@ -58,7 +58,7 @@ CREATE TABLE IF NOT EXISTS `logs` ( `type` TEXT, `log` TEXT, `uid` INTEGER DEFAULT '1', - `addtime` TEXT + `add_time` TEXT ); ALTER TABLE `logs` ADD COLUMN `uid` INTEGER DEFAULT '1'; @@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS `sites` ( `edate` TEXT, `ssl_effective_date` TEXT, `ssl_expiration_date` TEXT, - `addtime` TEXT + `add_time` TEXT ); ALTER TABLE `sites` ADD COLUMN `ssl_effective_date` TEXT DEFAULT ''; @@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS `domain` ( `pid` INTEGER, `name` TEXT, `port` INTEGER, - `addtime` TEXT + `add_time` TEXT ); CREATE TABLE IF NOT EXISTS `users` ( @@ -110,11 +110,11 @@ CREATE TABLE IF NOT EXISTS `tasks` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT, `type` TEXT, - `status` TEXT, - `addtime` TEXT, `start` INTEGER, `end` INTEGER, - `execstr` TEXT + `cmd` TEXT, + `status` INTEGER, + `add_time` INTEGER ); CREATE TABLE IF NOT EXISTS `temp_login` ( @@ -126,7 +126,7 @@ CREATE TABLE IF NOT EXISTS `temp_login` ( `login_addr` REAL, `logout_time` INTEGER, `expire` INTEGER, - `addtime` INTEGER + `add_time` INTEGER ); CREATE TABLE IF NOT EXISTS `panel` ( @@ -136,5 +136,12 @@ CREATE TABLE IF NOT EXISTS `panel` ( `username` TEXT, `password` TEXT, `click` INTEGER, - `addtime` INTEGER + `add_time` INTEGER +); + +CREATE TABLE IF NOT EXISTS `option` ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `name` TEXT, + `type` TEXT, + `value` TEXT ); diff --git a/web/admin/crontab/__init__.py b/web/admin/crontab/__init__.py index f10762d03..782623ca2 100644 --- a/web/admin/crontab/__init__.py +++ b/web/admin/crontab/__init__.py @@ -31,4 +31,19 @@ def list(): clist = Crontab.query.paginate(page=int(page), per_page=size) # print(clist) - return [] \ No newline at end of file + return [] + + +@blueprint.route('/add', endpoint='add', methods=['GET','POST']) +@panel_login_required +def add(): + page = request.args.get('p', 1) + size = 10 + count = Crontab.query.count() + # print(count) + clist = Crontab.query.paginate(page=int(page), per_page=size) + # print(clist) + + return [] + + diff --git a/web/admin/plugins/__init__.py b/web/admin/plugins/__init__.py index 8e8a1a1e2..77baaf6f1 100644 --- a/web/admin/plugins/__init__.py +++ b/web/admin/plugins/__init__.py @@ -14,7 +14,7 @@ import json from flask import Blueprint, render_template from flask import request -from utils.mwplugin import MwPlugin +from utils.plugin import plugin as MwPlugin from admin.user_login_check import panel_login_required from admin import model diff --git a/web/admin/setting/setting.py b/web/admin/setting/setting.py index 72010d808..f6e663e27 100644 --- a/web/admin/setting/setting.py +++ b/web/admin/setting/setting.py @@ -18,9 +18,11 @@ from flask import request from admin import model from admin.user_login_check import panel_login_required + import core.mw as mw import utils.config as utils_config + # 默认页面 blueprint = Blueprint('setting', __name__, url_prefix='/setting', template_folder='../../templates') @blueprint.route('/index', endpoint='index') @@ -218,12 +220,12 @@ def set_port(): msg = mw.getInfo('放行端口[{1}]成功', (port,)) mw.writeLog("防火墙管理", msg) addtime = time.strftime('%Y-%m-%d %X', time.localtime()) - mw.M('firewall').add('port,ps,addtime', (port, "配置修改", addtime)) + mw.M('firewall').add('port,ps,add_time', (port, "配置修改", add_time)) # firewall_api.firewall_api().addAcceptPort(port) # firewall_api.firewall_api().firewallReload() mw.restartMw() - return mw.returnJson(True, '端口保存成功!') + return mw.returnData(True, '端口保存成功!') \ No newline at end of file diff --git a/web/admin/site/__init__.py b/web/admin/site/__init__.py index 4ec0f7db6..d51580a0c 100644 --- a/web/admin/site/__init__.py +++ b/web/admin/site/__init__.py @@ -16,7 +16,7 @@ from flask import request from admin.model import Sites from admin.user_login_check import panel_login_required -from utils.mwplugin import MwPlugin +from utils.plugin import plugin as MwPlugin import utils.site as site import core.mw as mw diff --git a/web/thisdb/__init__.py b/web/thisdb/__init__.py index fa43ddfe9..9022ba603 100644 --- a/web/thisdb/__init__.py +++ b/web/thisdb/__init__.py @@ -12,3 +12,4 @@ from .init import * from .option import * from .user import * from .sites import * +from .tasks import * diff --git a/web/thisdb/tasks.py b/web/thisdb/tasks.py new file mode 100644 index 000000000..7dcab2a21 --- /dev/null +++ b/web/thisdb/tasks.py @@ -0,0 +1,39 @@ +# coding:utf-8 + +# --------------------------------------------------------------------------------- +# MW-Linux面板 +# --------------------------------------------------------------------------------- +# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. +# --------------------------------------------------------------------------------- +# Author: midoks +# --------------------------------------------------------------------------------- + +import core.mw as mw + +def addTask( + name: str | None = '常用任务', + cmd: str | None = None, + type: str | None = 'execshell', + status: int | None = 0, +): + ''' + 添加后台任务 + :name -> str 类型 + :cmd -> str 日志内容 (必填) + :type -> str 用户ID + ''' + if cmd is None: + return False + + add_time = mw.formatDate() + insert_data = { + 'name':name, + 'type':type, + 'cmd':cmd, + 'start':0, + 'end':0, + 'status':status, + 'add_time':add_time, + } + mw.M('tasks').insert(insert_data) + return True \ No newline at end of file diff --git a/web/utils/crontab.py b/web/utils/crontab.py new file mode 100644 index 000000000..b15af4bdb --- /dev/null +++ b/web/utils/crontab.py @@ -0,0 +1,9 @@ +# coding:utf-8 + +# --------------------------------------------------------------------------------- +# MW-Linux面板 +# --------------------------------------------------------------------------------- +# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. +# --------------------------------------------------------------------------------- +# Author: midoks +# --------------------------------------------------------------------------------- diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 509b17ae6..e100925ad 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -230,7 +230,7 @@ class Firewall(object): if model.getFirewallCountByPort(port) > 0: return mw.returnData(False, '您要放行的端口已存在,无需重复放行!') - model.addFirewall(port,ps=ps,protocol=protocol) + model.addFirewall(port, ps=ps,protocol=protocol) self.addAcceptPortCmd(port, protocol=protocol) self.reload() diff --git a/web/utils/mwplugin.py b/web/utils/plugin.py similarity index 97% rename from web/utils/mwplugin.py rename to web/utils/plugin.py index 6a2ff736b..81eda5a51 100644 --- a/web/utils/mwplugin.py +++ b/web/utils/plugin.py @@ -18,8 +18,9 @@ from admin import model import core.mw as mw import admin.model.option as option +import thisdb -class pa_thread(threading.Thread): +class pg_thread(threading.Thread): def __init__(self, func, args, name=''): threading.Thread.__init__(self) @@ -34,7 +35,7 @@ class pa_thread(threading.Thread): except Exception: return None -class MwPlugin(object): +class plugin(object): def_plugin_type = [ { @@ -88,11 +89,11 @@ class MwPlugin(object): @classmethod def instance(cls, *args, **kwargs): - if not hasattr(MwPlugin, "_instance"): - with MwPlugin._instance_lock: - if not hasattr(MwPlugin, "_instance"): - MwPlugin._instance = MwPlugin(*args, **kwargs) - return MwPlugin._instance + if not hasattr(plugin, "_instance"): + with plugin._instance_lock: + if not hasattr(plugin, "_instance"): + plugin._instance = plugin(*args, **kwargs) + return plugin._instance """插件类初始化""" def __init__(self): @@ -260,7 +261,7 @@ class MwPlugin(object): self.hookInstall(info_data) title = '{0}[{1}-{2}]'.format(msg_head,name,version) - model.addTask(name=title,cmd=exec_bash, status=0) + thisdb.addTask(name=title,cmd=exec_bash, status=0) # 调式日志 mw.debugLog(exec_bash) @@ -494,7 +495,7 @@ class MwPlugin(object): threads = [] ntmp_list = range(len(info)) for i in ntmp_list: - t = pa_thread(self.checkStatusThreads,(info[i], i)) + t = pg_thread(self.checkStatusThreads,(info[i], i)) threads.append(t) for i in ntmp_list: