pull/632/head
Mr Chen 6 months ago
parent c77d409317
commit 3ae8f0253e
  1. 3
      class/core/crontab_api.py
  2. 33
      data/sql/default.sql
  3. 17
      web/admin/crontab/__init__.py
  4. 2
      web/admin/plugins/__init__.py
  5. 6
      web/admin/setting/setting.py
  6. 2
      web/admin/site/__init__.py
  7. 1
      web/thisdb/__init__.py
  8. 39
      web/thisdb/tasks.py
  9. 9
      web/utils/crontab.py
  10. 2
      web/utils/firewall.py
  11. 19
      web/utils/plugin.py

@ -500,8 +500,7 @@ class crontab_api:
# 取任务构造Month # 取任务构造Month
def month(self, param): def month(self, param):
cuonConfig = "{0} {1} {2} * * ".format( cuonConfig = "{0} {1} {2} * * ".format(param['minute'], param['hour'], param['where1'])
param['minute'], param['hour'], param['where1'])
return cuonConfig return cuonConfig
# 取执行脚本 # 取执行脚本

@ -6,7 +6,7 @@ CREATE TABLE IF NOT EXISTS `backup` (
`pid` INTEGER, `pid` INTEGER,
`filename` TEXT, `filename` TEXT,
`size` INTEGER, `size` INTEGER,
`addtime` TEXT `add_time` TEXT
); );
CREATE TABLE IF NOT EXISTS `binding` ( CREATE TABLE IF NOT EXISTS `binding` (
@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS `binding` (
`domain` TEXT, `domain` TEXT,
`path` TEXT, `path` TEXT,
`port` INTEGER, `port` INTEGER,
`addtime` TEXT `add_time` TEXT
); );
@ -27,7 +27,6 @@ CREATE TABLE IF NOT EXISTS `crontab` (
`where_hour` INTEGER, `where_hour` INTEGER,
`where_minute` INTEGER, `where_minute` INTEGER,
`echo` TEXT, `echo` TEXT,
`addtime` TEXT,
`status` INTEGER DEFAULT '1', `status` INTEGER DEFAULT '1',
`save` INTEGER DEFAULT '3', `save` INTEGER DEFAULT '3',
`backup_to` TEXT DEFAULT 'off', `backup_to` TEXT DEFAULT 'off',
@ -35,6 +34,7 @@ CREATE TABLE IF NOT EXISTS `crontab` (
`sbody` TEXT, `sbody` TEXT,
'stype' TEXT, 'stype' TEXT,
`urladdress` TEXT `urladdress` TEXT
`add_time` TEXT
); );
CREATE TABLE IF NOT EXISTS `firewall` ( CREATE TABLE IF NOT EXISTS `firewall` (
@ -42,12 +42,12 @@ CREATE TABLE IF NOT EXISTS `firewall` (
`port` TEXT, `port` TEXT,
`protocol` TEXT DEFAULT 'tcp', `protocol` TEXT DEFAULT 'tcp',
`ps` TEXT, `ps` TEXT,
`addtime` TEXT `add_time` TEXT
); );
ALTER TABLE `firewall` ADD COLUMN `protocol` TEXT DEFAULT 'tcp'; 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'), (1, '80', 'tcp','网站默认端口', '0000-00-00 00:00:00'),
(2, '443', 'tcp/udp', 'HTTPS', '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, `type` TEXT,
`log` TEXT, `log` TEXT,
`uid` INTEGER DEFAULT '1', `uid` INTEGER DEFAULT '1',
`addtime` TEXT `add_time` TEXT
); );
ALTER TABLE `logs` ADD COLUMN `uid` INTEGER DEFAULT '1'; ALTER TABLE `logs` ADD COLUMN `uid` INTEGER DEFAULT '1';
@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS `sites` (
`edate` TEXT, `edate` TEXT,
`ssl_effective_date` TEXT, `ssl_effective_date` TEXT,
`ssl_expiration_date` TEXT, `ssl_expiration_date` TEXT,
`addtime` TEXT `add_time` TEXT
); );
ALTER TABLE `sites` ADD COLUMN `ssl_effective_date` TEXT DEFAULT ''; ALTER TABLE `sites` ADD COLUMN `ssl_effective_date` TEXT DEFAULT '';
@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS `domain` (
`pid` INTEGER, `pid` INTEGER,
`name` TEXT, `name` TEXT,
`port` INTEGER, `port` INTEGER,
`addtime` TEXT `add_time` TEXT
); );
CREATE TABLE IF NOT EXISTS `users` ( CREATE TABLE IF NOT EXISTS `users` (
@ -110,11 +110,11 @@ CREATE TABLE IF NOT EXISTS `tasks` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT, `id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT, `name` TEXT,
`type` TEXT, `type` TEXT,
`status` TEXT,
`addtime` TEXT,
`start` INTEGER, `start` INTEGER,
`end` INTEGER, `end` INTEGER,
`execstr` TEXT `cmd` TEXT,
`status` INTEGER,
`add_time` INTEGER
); );
CREATE TABLE IF NOT EXISTS `temp_login` ( CREATE TABLE IF NOT EXISTS `temp_login` (
@ -126,7 +126,7 @@ CREATE TABLE IF NOT EXISTS `temp_login` (
`login_addr` REAL, `login_addr` REAL,
`logout_time` INTEGER, `logout_time` INTEGER,
`expire` INTEGER, `expire` INTEGER,
`addtime` INTEGER `add_time` INTEGER
); );
CREATE TABLE IF NOT EXISTS `panel` ( CREATE TABLE IF NOT EXISTS `panel` (
@ -136,5 +136,12 @@ CREATE TABLE IF NOT EXISTS `panel` (
`username` TEXT, `username` TEXT,
`password` TEXT, `password` TEXT,
`click` INTEGER, `click` INTEGER,
`addtime` INTEGER `add_time` INTEGER
);
CREATE TABLE IF NOT EXISTS `option` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT,
`type` TEXT,
`value` TEXT
); );

@ -31,4 +31,19 @@ def list():
clist = Crontab.query.paginate(page=int(page), per_page=size) clist = Crontab.query.paginate(page=int(page), per_page=size)
# print(clist) # print(clist)
return [] 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 []

@ -14,7 +14,7 @@ import json
from flask import Blueprint, render_template from flask import Blueprint, render_template
from flask import request 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.user_login_check import panel_login_required
from admin import model from admin import model

@ -18,9 +18,11 @@ from flask import request
from admin import model from admin import model
from admin.user_login_check import panel_login_required from admin.user_login_check import panel_login_required
import core.mw as mw import core.mw as mw
import utils.config as utils_config import utils.config as utils_config
# 默认页面 # 默认页面
blueprint = Blueprint('setting', __name__, url_prefix='/setting', template_folder='../../templates') blueprint = Blueprint('setting', __name__, url_prefix='/setting', template_folder='../../templates')
@blueprint.route('/index', endpoint='index') @blueprint.route('/index', endpoint='index')
@ -218,12 +220,12 @@ def set_port():
msg = mw.getInfo('放行端口[{1}]成功', (port,)) msg = mw.getInfo('放行端口[{1}]成功', (port,))
mw.writeLog("防火墙管理", msg) mw.writeLog("防火墙管理", msg)
addtime = time.strftime('%Y-%m-%d %X', time.localtime()) 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().addAcceptPort(port)
# firewall_api.firewall_api().firewallReload() # firewall_api.firewall_api().firewallReload()
mw.restartMw() mw.restartMw()
return mw.returnJson(True, '端口保存成功!') return mw.returnData(True, '端口保存成功!')

@ -16,7 +16,7 @@ from flask import request
from admin.model import Sites from admin.model import Sites
from admin.user_login_check import panel_login_required 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 utils.site as site
import core.mw as mw import core.mw as mw

@ -12,3 +12,4 @@ from .init import *
from .option import * from .option import *
from .user import * from .user import *
from .sites import * from .sites import *
from .tasks import *

@ -0,0 +1,39 @@
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
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

@ -0,0 +1,9 @@
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------

@ -230,7 +230,7 @@ class Firewall(object):
if model.getFirewallCountByPort(port) > 0: if model.getFirewallCountByPort(port) > 0:
return mw.returnData(False, '您要放行的端口已存在,无需重复放行!') return mw.returnData(False, '您要放行的端口已存在,无需重复放行!')
model.addFirewall(port,ps=ps,protocol=protocol) model.addFirewall(port, ps=ps,protocol=protocol)
self.addAcceptPortCmd(port, protocol=protocol) self.addAcceptPortCmd(port, protocol=protocol)
self.reload() self.reload()

@ -18,8 +18,9 @@ from admin import model
import core.mw as mw import core.mw as mw
import admin.model.option as option import admin.model.option as option
import thisdb
class pa_thread(threading.Thread): class pg_thread(threading.Thread):
def __init__(self, func, args, name=''): def __init__(self, func, args, name=''):
threading.Thread.__init__(self) threading.Thread.__init__(self)
@ -34,7 +35,7 @@ class pa_thread(threading.Thread):
except Exception: except Exception:
return None return None
class MwPlugin(object): class plugin(object):
def_plugin_type = [ def_plugin_type = [
{ {
@ -88,11 +89,11 @@ class MwPlugin(object):
@classmethod @classmethod
def instance(cls, *args, **kwargs): def instance(cls, *args, **kwargs):
if not hasattr(MwPlugin, "_instance"): if not hasattr(plugin, "_instance"):
with MwPlugin._instance_lock: with plugin._instance_lock:
if not hasattr(MwPlugin, "_instance"): if not hasattr(plugin, "_instance"):
MwPlugin._instance = MwPlugin(*args, **kwargs) plugin._instance = plugin(*args, **kwargs)
return MwPlugin._instance return plugin._instance
"""插件类初始化""" """插件类初始化"""
def __init__(self): def __init__(self):
@ -260,7 +261,7 @@ class MwPlugin(object):
self.hookInstall(info_data) self.hookInstall(info_data)
title = '{0}[{1}-{2}]'.format(msg_head,name,version) 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) mw.debugLog(exec_bash)
@ -494,7 +495,7 @@ class MwPlugin(object):
threads = [] threads = []
ntmp_list = range(len(info)) ntmp_list = range(len(info))
for i in ntmp_list: for i in ntmp_list:
t = pa_thread(self.checkStatusThreads,(info[i], i)) t = pg_thread(self.checkStatusThreads,(info[i], i))
threads.append(t) threads.append(t)
for i in ntmp_list: for i in ntmp_list:
Loading…
Cancel
Save