From 966506bb8db0e995485e2d5ff6dea860aa2c3374 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 1 Nov 2024 02:10:08 +0800 Subject: [PATCH] update --- README.md | 5 + new_cli.sh | 25 +- panel_task.py | 4 - panel_tools.py | 306 ++++++++++++++++++++++ scripts/init.d/mw-task.service.tpl | 2 +- scripts/install_new.sh | 182 +++++++++++++ web/admin/setting/__init__.py | 2 +- web/admin/setting/secondary_verifiy.py | 2 +- web/admin/setting/{main.py => setting.py} | 0 web/admin/setting/temp_login.py | 2 +- web/admin/setting/timezone.py | 2 +- web/setting.py | 72 +++++ 12 files changed, 585 insertions(+), 19 deletions(-) create mode 100755 panel_tools.py create mode 100755 scripts/install_new.sh rename web/admin/setting/{main.py => setting.py} (100%) create mode 100755 web/setting.py diff --git a/README.md b/README.md index 7c2dceaa5..1107bbb41 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,11 @@ curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev curl --insecure -fsSL https://code.midoks.icu/midoks/mdserver-web/raw/branch/dev/scripts/install_dev.sh | bash curl --insecure -fsSL https://code.midoks.icu/midoks/mdserver-web/raw/branch/dev/scripts/update_dev.sh | bash + + + +curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/install_new.sh | bash +curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/install_new.sh | bash ``` ### 捐赠地址 USDT(TRC20) diff --git a/new_cli.sh b/new_cli.sh index 6016aa138..c5dd43844 100755 --- a/new_cli.sh +++ b/new_cli.sh @@ -3,10 +3,11 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/hom DIR=$(cd "$(dirname "$0")"; pwd) MDIR=$(dirname "$DIR") +# echo $DIR PATH=$PATH:$DIR/bin -if [ -f bin/activate ];then - source bin/activate +if [ -f ${DIR}/bin/activate ];then + source ${DIR}/bin/activate if [ "$?" != "0" ];then echo "load local python env fail!" @@ -46,27 +47,31 @@ mw_start(){ mw_start_debug(){ - if [ ! -f $DIR/logs/task.log ];then - echo '' > $DIR/logs/task.log + if [ ! -f $DIR/logs/panel_task.log ];then + echo '' > $DIR/logs/panel_task.log fi - python3 task.py >> $DIR/logs/task.log 2>&1 & + python3 panel_task.py >> $DIR/logs/panel_task.log 2>&1 & port=7200 if [ -f /www/server/mdserver-web/data/port.pl ];then port=$(cat /www/server/mdserver-web/data/port.pl) fi + + if [ -f ${DIR}/data/port.pl ];then + port=$(cat ${DIR}/data/port.pl) + fi # gunicorn -b :${port} -k gevent -w 1 app:app - gunicorn -b :${port} -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app + cd web && gunicorn -b :${port} -w 1 app:app } mw_start_debug2(){ - python3 task.py >> $DIR/logs/task.log 2>&1 & - gunicorn -b :7200 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app + python3 panel_task.py >> $DIR/logs/panel_task.log 2>&1 & + gunicorn -b :7200 -w 1 app:app } mw_start_debug3(){ gunicorn -c setting.py app:app - python3 task.py + python3 panel_task.py } @@ -78,7 +83,7 @@ mw_stop() kill -9 $i > /dev/null 2>&1 done - pids=`ps -ef|grep task.py | grep -v grep |awk '{print $2}'` + pids=`ps -ef|grep panel_task.py | grep -v grep |awk '{print $2}'` arr=($pids) for p in ${arr[@]} do diff --git a/panel_task.py b/panel_task.py index 62e4c003d..b23038993 100755 --- a/panel_task.py +++ b/panel_task.py @@ -19,10 +19,6 @@ import time import threading import psutil -if sys.version_info[0] == 2: - reload(sys) - sys.setdefaultencoding('utf-8') - web_dir = os.getcwd() + "/web" os.chdir(web_dir) diff --git a/panel_tools.py b/panel_tools.py new file mode 100755 index 000000000..ff4fa3d79 --- /dev/null +++ b/panel_tools.py @@ -0,0 +1,306 @@ +# coding=utf-8 + +# --------------------------------------------------------------------------------- +# MW-Linux面板 +# --------------------------------------------------------------------------------- +# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. +# --------------------------------------------------------------------------------- +# Author: midoks +# --------------------------------------------------------------------------------- + +# --------------------------------------------------------------------------------- +# 工具箱 +# --------------------------------------------------------------------------------- + + +import sys +import os +import json +import time +import re + +web_dir = os.getcwd() + "/web" +os.chdir(web_dir) +sys.path.append(web_dir) + +import core.mw as mw +import core.db as db + +# cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' +# info = mw.execShell(cmd) +# p = "/usr/local/lib/" + info[0].strip() + "/site-packages" +# sys.path.append(p) + +INIT_DIR = "/etc/rc.d/init.d" +if mw.isAppleSystem(): + INIT_DIR = mw.getPanelDir() + "/scripts/init.d" + +INIT_CMD = INIT_DIR + "/mw" + + +def mw_input_cmd(msg): + if sys.version_info[0] == 2: + in_val = raw_input(msg) + else: + in_val = input(msg) + return in_val + + +def mwcli(mw_input=0): + raw_tip = "======================================================" + if not mw_input: + print("===============mdserver-web cli tools=================") + print("(1) 重启面板服务") + print("(2) 停止面板服务") + print("(3) 启动面板服务") + print("(4) 重载面板服务") + print("(5) 修改面板端口") + print("(10) 查看面板默认信息") + print("(11) 修改面板密码") + print("(12) 修改面板用户名") + print("(13) 显示面板错误日志") + print("(20) 关闭BasicAuth认证") + print("(21) 解除域名绑定") + print("(22) 解除面板SSL绑定") + print("(23) 开启IPV6支持") + print("(24) 关闭IPV6支持") + print("(25) 开启防火墙SSH端口") + print("(26) 关闭二次验证") + print("(27) 查看防火墙信息") + print("(100) 开启PHP52显示") + print("(101) 关闭PHP52显示") + print("(200) 切换Linux系统软件源") + print("(201) 简单速度测试") + print("(0) 取消") + print(raw_tip) + try: + mw_input = input("请输入命令编号:") + if sys.version_info[0] == 3: + mw_input = int(mw_input) + except: + mw_input = 0 + + nums = [ + 1, 2, 3, 4, 5, 10, 11, 12, 13, + 20, 21, 22, 23, 24, 25, 26, 27, + 100, 101, + 200, 201 + ] + if not mw_input in nums: + print(raw_tip) + print("已取消!") + exit() + + if mw_input == 1: + os.system(INIT_CMD + " restart") + elif mw_input == 2: + os.system(INIT_CMD + " stop") + elif mw_input == 3: + os.system(INIT_CMD + " start") + elif mw_input == 4: + os.system(INIT_CMD + " reload") + elif mw_input == 5: + in_port = mw_input_cmd("请输入新的面板端口:") + in_port_int = int(in_port.strip()) + if in_port_int < 65536 and in_port_int > 0: + import firewall_api + firewall_api.firewall_api().addAcceptPortArgs( + in_port, 'WEB面板[TOOLS修改]', 'port') + mw.writeFile('data/port.pl', in_port) + os.system(INIT_CMD + " restart_panel") + os.system(INIT_CMD + " default") + else: + print("|-端口范围在0-65536之间") + return + elif mw_input == 10: + os.system(INIT_CMD + " default") + elif mw_input == 11: + input_pwd = mw_input_cmd("请输入新的面板密码:") + if len(input_pwd.strip()) < 5: + print("|-错误,密码长度不能小于5位") + return + set_panel_pwd(input_pwd.strip(), True) + elif mw_input == 12: + input_user = mw_input_cmd("请输入新的面板用户名(>=5位):") + set_panel_username(input_user.strip()) + elif mw_input == 13: + os.system('tail -100 ' + mw.getPanelDir() + '/logs/error.log') + elif mw_input == 20: + basic_auth = 'data/basic_auth.json' + if os.path.exists(basic_auth): + os.remove(basic_auth) + os.system(INIT_CMD + " restart") + print("|-关闭basic_auth成功") + elif mw_input == 21: + bind_domain = 'data/bind_domain.pl' + if os.path.exists(bind_domain): + os.remove(bind_domain) + os.system(INIT_CMD + " unbind_domain") + print("|-解除域名绑定成功") + elif mw_input == 22: + ssl_choose = 'ssl/choose.pl' + if os.path.exists(ssl_choose): + os.remove(ssl_choose) + os.system(INIT_CMD + " unbind_ssl") + print("|-解除面板SSL绑定成功") + elif mw_input == 23: + listen_ipv6 = 'data/ipv6.pl' + if not os.path.exists(listen_ipv6): + mw.writeFile(listen_ipv6,'True') + os.system(INIT_CMD + " restart") + print("|-开启IPv6支持了") + else: + print("|-已开启IPv6支持!") + elif mw_input == 24: + listen_ipv6 = 'data/ipv6.pl' + if not os.path.exists(listen_ipv6): + print("|-已关闭IPv6支持!") + else: + os.remove(listen_ipv6) + os.system(INIT_CMD + " restart") + print("|-关闭IPv6支持了") + elif mw_input == 25: + open_ssh_port() + print("|-已开启!") + elif mw_input == 26: + auth_secret = 'data/auth_secret.pl' + if os.path.exists(auth_secret): + os.remove(auth_secret) + print("|-关闭二次验证成功!") + else: + print("|-二次验证已关闭!") + elif mw_input == 27: + cmd = 'which ufw' + run_cmd = False + find_cmd = mw.execShell(cmd) + if find_cmd[0].strip() != '': + run_cmd = True + os.system('ufw status') + + cmd = 'which firewall-cmd' + find_cmd = mw.execShell(cmd) + if find_cmd[0].strip() != '': + run_cmd = True + os.system('firewall-cmd --list-all') + if not run_cmd: + mw.echoInfo("未检测到防火墙!") + elif mw_input == 100: + php_conf = 'plugins/php/info.json' + if os.path.exists(php_conf): + cont = mw.readFile(php_conf) + cont = re.sub("\"53\"", "\"52\",\"53\"", cont) + cont = re.sub("\"5.3.29\"", "\"5.2.17\",\"5.3.29\"", cont) + mw.writeFile(php_conf, cont) + print("|-执行PHP52显示成功!") + elif mw_input == 101: + php_conf = 'plugins/php/info.json' + if os.path.exists(php_conf): + cont = mw.readFile(php_conf) + cont = re.sub("\"52\",", "", cont) + cont = re.sub("\"5.2.17\",", cont) + mw.writeFile(php_conf, cont) + print("|-执行PHP52隐藏成功!") + elif mw_input == 200: + os.system(INIT_CMD + " mirror") + elif mw_input == 201: + os.system('curl -Lso- bench.sh | bash') + + +def open_ssh_port(): + import firewall_api + find_ssh_port_cmd = "cat /etc/ssh/sshd_config | grep '^Port \\d*' | tail -1" + cmd_data = mw.execShell(find_ssh_port_cmd) + ssh_port = cmd_data[0].replace("Port ", '').strip() + if ssh_port == '': + ssh_port = '22' + + print("|-SSH端口: "+ str(ssh_port)) + firewall_api.firewall_api().addAcceptPortArgs(ssh_port, 'SSH远程管理服务', 'port') + return True + + +def set_panel_pwd(password, ncli=False): + # 设置面板密码 + import db + sql = db.Sql() + result = sql.table('users').where('id=?', (1,)).setField( + 'password', mw.md5(password)) + username = sql.table('users').where('id=?', (1,)).getField('username') + if ncli: + print("|-用户名: " + username) + print("|-新密码: " + password) + else: + print(username) + + +def show_panel_pwd(): + # 设置面板密码 + import db + sql = db.Sql() + password = sql.table('users').where('id=?', (1,)).getField('password') + + file_pwd = '' + if os.path.exists('data/default.pl'): + file_pwd = mw.readFile('data/default.pl').strip() + + if mw.md5(file_pwd) == password: + print('password: ' + file_pwd) + return + print("password has been changed!") + + +def set_panel_username(username=None): + # 随机面板用户名 + import db + sql = db.Sql() + if username: + if len(username) < 5: + print("|-错误,用户名长度不能少于5位") + return + if username in ['admin', 'root']: + print("|-错误,不能使用过于简单的用户名") + return + + sql.table('users').where('id=?', (1,)).setField('username', username) + print("|-新用户名: %s" % username) + return + + username = sql.table('users').where('id=?', (1,)).getField('username') + if username == 'admin': + username = mw.getRandomString(8).lower() + sql.table('users').where('id=?', (1,)).setField('username', username) + print('username: ' + username) + + +def getServerIp(): + version = sys.argv[2] + # ip = mw.execShell( + # "curl --insecure -{} -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text".format(version)) + ip = mw.execShell( + "curl --insecure -{} -sS --connect-timeout 5 -m 60 https://ip.cachecha.com/?format=text".format(version)) + print(ip[0]) + + +if __name__ == "__main__": + method = sys.argv[1] + if method == 'panel': + set_panel_pwd(sys.argv[2]) + elif method == 'username': + if len(sys.argv) > 2: + set_panel_username(sys.argv[2]) + else: + set_panel_username() + elif method == 'password': + show_panel_pwd() + elif method == 'getServerIp': + getServerIp() + elif method == "cli": + clinum = 0 + try: + if len(sys.argv) > 2: + clinum = int(sys.argv[2]) if sys.argv[2][:6] else sys.argv[2] + except: + clinum = sys.argv[2] + mwcli(clinum) + else: + print('ERROR: Parameter error') diff --git a/scripts/init.d/mw-task.service.tpl b/scripts/init.d/mw-task.service.tpl index da6b7e33e..405d9138d 100755 --- a/scripts/init.d/mw-task.service.tpl +++ b/scripts/init.d/mw-task.service.tpl @@ -6,7 +6,7 @@ After=network.target Type=simple WorkingDirectory={$SERVER_PATH} EnvironmentFile={$SERVER_PATH}/scripts/init.d/service.sh -ExecStart=python3 task.py +ExecStart=python3 panel_task.py ExecStop=kill -HUP $MAINID ExecReload=kill -HUP $MAINID KillMode=process diff --git a/scripts/install_new.sh b/scripts/install_new.sh new file mode 100755 index 000000000..71ca2fb51 --- /dev/null +++ b/scripts/install_new.sh @@ -0,0 +1,182 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin +export PATH +# LANG=en_US.UTF-8 +is64bit=`getconf LONG_BIT` + +echo -e "您正在安装的是\033[31mmdserver-web测试版\033[0m,非开发测试用途请使用正式版 install.sh !" +echo -e "You are installing\033[31m mdserver-web dev version\033[0m, normally use install.sh for production.\n" +sleep 1 + +LOG_FILE=/var/log/mw-install.log + +{ + +if [ -f /etc/motd ];then + echo "welcome to mdserver-web panel" > /etc/motd +fi + +startTime=`date +%s` + +_os=`uname` +echo "use system: ${_os}" + + +if [ ${_os} == "Darwin" ]; then + OSNAME='macos' +elif grep -Eq "openSUSE" /etc/*-release; then + OSNAME='opensuse' + zypper refresh + zypper install -y wget curl zip unzip unrar rar +elif grep -Eq "FreeBSD" /etc/*-release; then + OSNAME='freebsd' + pkg install -y wget curl zip unzip unrar rar +elif grep -Eqi "EulerOS" /etc/*-release || grep -Eqi "openEuler" /etc/*-release; then + OSNAME='euler' + yum install -y wget curl zip unzip tar crontabs +elif grep -Eqi "CentOS" /etc/issue || grep -Eqi "CentOS" /etc/*-release; then + OSNAME='rhel' + yum install -y wget zip unzip tar +elif grep -Eqi "Fedora" /etc/issue || grep -Eqi "Fedora" /etc/*-release; then + OSNAME='rhel' + yum install -y wget zip unzip tar +elif grep -Eqi "Rocky" /etc/issue || grep -Eqi "Rocky" /etc/*-release; then + OSNAME='rhel' + yum install -y wget zip unzip +elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eqi "AlmaLinux" /etc/*-release; then + OSNAME='rhel' + yum install -y wget zip unzip tar +elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eqi "Amazon Linux" /etc/*-release; then + OSNAME='amazon' + yum install -y wget zip unzip tar +elif grep -Eqi "Ubuntu" /etc/issue || grep -Eqi "Ubuntu" /etc/*-release; then + OSNAME='ubuntu' + apt install -y wget zip unzip tar +elif grep -Eqi "Debian" /etc/issue || grep -Eqi "Debian" /etc/*-release; then + OSNAME='debian' + apt update -y + apt install -y devscripts + apt install -y wget zip unzip tar +else + OSNAME='unknow' +fi + +if [ "$EUID" -ne 0 ] && [ "$OSNAME" != "macos" ];then + echo "Please run as root!" + exit +fi + +# HTTP_PREFIX="https://" +# LOCAL_ADDR=common +# ping -c 1 github.com > /dev/null 2>&1 +# if [ "$?" != "0" ];then +# LOCAL_ADDR=cn +# HTTP_PREFIX="https://mirror.ghproxy.com/" +# fi + +HTTP_PREFIX="https://" +LOCAL_ADDR=common +cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"") +if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then + LOCAL_ADDR=cn + HTTP_PREFIX="https://mirror.ghproxy.com/" +fi + +echo "local:${LOCAL_ADDR}" +echo "OSNAME:${OSNAME}" + +if [ $OSNAME != "macos" ];then + + if id www &> /dev/null ;then + echo "" + else + groupadd www + useradd -g www -s /usr/sbin/nologin www + fi + + mkdir -p /www/server + mkdir -p /www/wwwroot + mkdir -p /www/wwwlogs + mkdir -p /www/backup/database + mkdir -p /www/backup/site + + if [ ! -d /www/server/mdserver-web ];then + + if [ "$LOCAL_ADDR" == "common" ];then + curl --insecure -sSLo /tmp/dev.zip ${HTTP_PREFIX}github.com/midoks/mdserver-web/archive/refs/heads/dev.zip + cd /tmp && unzip /tmp/dev.zip + mv -f /tmp/mdserver-web-dev /www/server/mdserver-web + rm -rf /tmp/dev.zip + rm -rf /tmp/mdserver-web-dev + else + # curl --insecure -sSLo /tmp/dev.zip https://code.midoks.icu/midoks/mdserver-web/archive/dev.zip + wget --no-check-certificate -O /tmp/dev.zip https://code.midoks.icu/midoks/mdserver-web/archive/dev.zip + cd /tmp && unzip /tmp/dev.zip + mv -f /tmp/mdserver-web /www/server/mdserver-web + rm -rf /tmp/dev.zip + rm -rf /tmp/mdserver-web + fi + fi + + # install acme.sh + if [ ! -d /root/.acme.sh ];then + if [ "$LOCAL_ADDR" != "common" ];then + # curl -sSL -o /tmp/acme.tar.gz ${HTTP_PREFIX}github.com/acmesh-official/acme.sh/archive/master.tar.gz + curl --insecure -sSLo /tmp/acme.tar.gz https://gitee.com/neilpang/acme.sh/repository/archive/master.tar.gz + tar xvzf /tmp/acme.tar.gz -C /tmp + cd /tmp/acme.sh-master + bash acme.sh install + fi + + if [ ! -d /root/.acme.sh ];then + curl https://get.acme.sh | sh + fi + fi +fi + +echo "use system version: ${OSNAME}" + +if [ "${OSNAME}" == "macos" ];then + curl --insecure -fsSL https://code.midoks.icu/midoks/mdserver-web/raw/branch/master/scripts/install/macos.sh | bash +else + cd /www/server/mdserver-web && bash scripts/install/${OSNAME}.sh +fi + +if [ "${OSNAME}" == "macos" ];then + echo "macos end" + exit 0 +fi + +cd /www/server/mdserver-web && bash cli_new.sh start +isStart=`ps -ef|grep 'gunicorn -c setting.py app:app' |grep -v grep|awk '{print $2}'` +n=0 +while [ ! -f /etc/rc.d/init.d/mw ]; +do + echo -e ".\c" + sleep 1 + let n+=1 + if [ $n -gt 20 ];then + echo -e "start mw fail" + exit 1 + fi +done + +cd /www/server/mdserver-web && bash /etc/rc.d/init.d/mw stop +cd /www/server/mdserver-web && bash /etc/rc.d/init.d/mw start +cd /www/server/mdserver-web && bash /etc/rc.d/init.d/mw default + +sleep 2 +if [ ! -e /usr/bin/mw ]; then + if [ -f /etc/rc.d/init.d/mw ];then + ln -s /etc/rc.d/init.d/mw /usr/bin/mw + fi +fi + +endTime=`date +%s` +((outTime=(${endTime}-${startTime})/60)) +echo -e "Time consumed:\033[32m $outTime \033[0mMinute!" + +} 1> >(tee $LOG_FILE) 2>&1 + +echo -e "\nInstall completed. If error occurs, please contact us with the log file mw-install.log ." +echo "安装完毕,如果出现错误,请带上同目录下的安装日志 mw-install.log 联系我们反馈." \ No newline at end of file diff --git a/web/admin/setting/__init__.py b/web/admin/setting/__init__.py index d94faf268..adfb25a3e 100644 --- a/web/admin/setting/__init__.py +++ b/web/admin/setting/__init__.py @@ -8,7 +8,7 @@ # Author: midoks # --------------------------------------------------------------------------------- -from .main import * +from .setting import * from .temp_login import * from .timezone import * from .secondary_verifiy import * diff --git a/web/admin/setting/secondary_verifiy.py b/web/admin/setting/secondary_verifiy.py index 466eb948b..562383706 100644 --- a/web/admin/setting/secondary_verifiy.py +++ b/web/admin/setting/secondary_verifiy.py @@ -24,7 +24,7 @@ from admin.user_login_check import panel_login_required import core.mw as mw import utils.config as utils_config -from .main import blueprint +from .setting import blueprint @blueprint.route('/get_auth_secret', endpoint='get_auth_secret', methods=['POST']) diff --git a/web/admin/setting/main.py b/web/admin/setting/setting.py similarity index 100% rename from web/admin/setting/main.py rename to web/admin/setting/setting.py diff --git a/web/admin/setting/temp_login.py b/web/admin/setting/temp_login.py index f7e9e9a27..51f12a268 100644 --- a/web/admin/setting/temp_login.py +++ b/web/admin/setting/temp_login.py @@ -24,7 +24,7 @@ from admin.user_login_check import panel_login_required import core.mw as mw import utils.config as utils_config -from .main import blueprint +from .setting import blueprint @blueprint.route('/get_temp_login', endpoint='get_temp_login', methods=['POST']) diff --git a/web/admin/setting/timezone.py b/web/admin/setting/timezone.py index c2514d535..246b411c3 100644 --- a/web/admin/setting/timezone.py +++ b/web/admin/setting/timezone.py @@ -21,7 +21,7 @@ from admin.user_login_check import panel_login_required import core.mw as mw import utils.config as utils_config -from .main import blueprint +from .setting import blueprint # 时区相关 @blueprint.route('/get_timezone_list', endpoint='get_timezone_list', methods=['POST']) diff --git a/web/setting.py b/web/setting.py new file mode 100755 index 000000000..1d6961488 --- /dev/null +++ b/web/setting.py @@ -0,0 +1,72 @@ +# coding:utf-8 + +# --------------------------------------------------------------------------------- +# MW-Linux面板 +# --------------------------------------------------------------------------------- +# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. +# --------------------------------------------------------------------------------- +# Author: midoks +# --------------------------------------------------------------------------------- + +# --------------------------------------------------------------------------------- +# 配置文件 +# --------------------------------------------------------------------------------- + + +import time +import sys +import random +import os + + +import core.mw as mw + + +import utils.system as system +cpu_info = system.getCpuInfo() +workers = cpu_info[1] + +panel_dir = mw.getPanelDir() + + +log_dir = mw.getMWLogs() +if not os.path.exists(log_dir): + os.mkdir(log_dir) + +# default port +mw_port = '7200' +if os.path.exists(panel_dir+'/data/port.pl'): + mw_port = mw.readFile(panel_dir+'/data/port.pl') + mw_port.strip() +# else: +# import firewall_api +# import common +# common.initDB() +# mw_port = str(random.randint(10000, 65530)) +# firewall_api.firewall_api().addAcceptPortArgs(mw_port, 'WEB面板', 'port') +# mw.writeFile('data/port.pl', mw_port) + +bind = [] +if os.path.exists('data/ipv6.pl'): + bind.append('[0:0:0:0:0:0:0:0]:%s' % mw_port) +else: + bind.append('0.0.0.0:%s' % mw_port) + +print(mw_port) +if workers > 2: + workers = 2 + +threads = workers * 1 +backlog = 512 +reload = False +daemon = True +# worker_class = 'geventwebsocket.gunicorn.workers.GeventWebSocketWorker' +timeout = 7200 +keepalive = 60 +preload_app = True +capture_output = True +access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"' +loglevel = 'info' +errorlog = log_dir + '/panel_error.log' +accesslog = log_dir + '/panel.log' +pidfile = log_dir + '/mw.pid'