2024-10-31 14:10:08 -04:00
|
|
|
# coding:utf-8
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------
|
|
|
|
|
# MW-Linux面板
|
|
|
|
|
# ---------------------------------------------------------------------------------
|
|
|
|
|
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
|
|
|
|
|
# ---------------------------------------------------------------------------------
|
|
|
|
|
# Author: midoks <midoks@163.com>
|
|
|
|
|
# ---------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------
|
|
|
|
|
# 配置文件
|
|
|
|
|
# ---------------------------------------------------------------------------------
|
|
|
|
|
|
2026-04-05 03:19:19 -04:00
|
|
|
|
2025-06-12 01:17:44 -04:00
|
|
|
|
2024-10-31 14:10:08 -04:00
|
|
|
import time
|
|
|
|
|
import sys
|
|
|
|
|
import random
|
|
|
|
|
import os
|
|
|
|
|
|
2024-11-28 07:16:58 -05:00
|
|
|
# 初始化db
|
|
|
|
|
from admin import setup
|
|
|
|
|
setup.init()
|
2024-10-31 14:10:08 -04:00
|
|
|
|
|
|
|
|
import core.mw as mw
|
|
|
|
|
import utils.system as system
|
2024-11-26 02:47:22 -05:00
|
|
|
import thisdb
|
2024-11-01 14:19:58 -04:00
|
|
|
|
2024-10-31 14:10:08 -04:00
|
|
|
cpu_info = system.getCpuInfo()
|
|
|
|
|
workers = cpu_info[1]
|
2024-11-28 05:13:31 -05:00
|
|
|
# workers = 1
|
2024-10-31 14:10:08 -04:00
|
|
|
|
|
|
|
|
panel_dir = mw.getPanelDir()
|
|
|
|
|
log_dir = mw.getMWLogs()
|
|
|
|
|
if not os.path.exists(log_dir):
|
|
|
|
|
os.mkdir(log_dir)
|
|
|
|
|
|
2024-11-26 12:19:40 -05:00
|
|
|
data_dir = panel_dir+'/data'
|
|
|
|
|
if not os.path.exists(data_dir):
|
|
|
|
|
os.mkdir(data_dir)
|
|
|
|
|
|
2024-10-31 14:10:08 -04:00
|
|
|
# default port
|
2024-11-11 12:00:06 -05:00
|
|
|
panel_port = '7200'
|
2024-11-30 10:01:21 -05:00
|
|
|
from utils.firewall import Firewall as MwFirewall
|
2024-11-01 14:19:58 -04:00
|
|
|
default_port_file = panel_dir+'/data/port.pl'
|
|
|
|
|
if os.path.exists(default_port_file):
|
2024-11-11 12:00:06 -05:00
|
|
|
panel_port = mw.readFile(default_port_file)
|
|
|
|
|
panel_port.strip()
|
2024-11-30 10:02:08 -05:00
|
|
|
MwFirewall.instance().addAcceptPort(panel_port,'PANEL端口', 'port')
|
2024-11-11 12:00:06 -05:00
|
|
|
else:
|
2024-11-26 17:05:54 -05:00
|
|
|
panel_port = str(random.randint(10000, 65530))
|
2024-11-30 09:41:39 -05:00
|
|
|
MwFirewall.instance().addPanelPort(panel_port)
|
2024-11-26 17:05:54 -05:00
|
|
|
mw.writeFile(default_port_file, panel_port)
|
2024-10-31 14:10:08 -04:00
|
|
|
|
|
|
|
|
bind = []
|
2024-11-01 14:19:58 -04:00
|
|
|
default_ipv6_file = panel_dir+'/data/ipv6.pl'
|
|
|
|
|
if os.path.exists(default_ipv6_file):
|
2024-11-11 12:00:06 -05:00
|
|
|
bind.append('[0:0:0:0:0:0:0:0]:%s' % panel_port)
|
2024-10-31 14:10:08 -04:00
|
|
|
else:
|
2024-11-11 12:00:06 -05:00
|
|
|
bind.append('0.0.0.0:%s' % panel_port)
|
2024-10-31 14:10:08 -04:00
|
|
|
|
2024-11-26 02:47:22 -05:00
|
|
|
panel_ssl_data = thisdb.getOptionByJson('panel_ssl', default={'open':False})
|
|
|
|
|
if panel_ssl_data['open']:
|
|
|
|
|
choose = panel_ssl_data['choose']
|
|
|
|
|
if mw.inArray(['local','nginx'],choose):
|
|
|
|
|
panel_cert = panel_dir+'/ssl/'+choose+'/cert.pem'
|
|
|
|
|
panel_private = panel_dir+'/ssl/'+choose+'/private.pem'
|
|
|
|
|
if os.path.exists(panel_cert) and os.path.exists(panel_private):
|
|
|
|
|
certfile = panel_cert
|
|
|
|
|
keyfile = panel_private
|
2024-11-24 13:40:09 -05:00
|
|
|
ciphers = 'TLSv1 TLSv1.1 TLSv1.2 TLSv1.3'
|
|
|
|
|
ssl_version = 2
|
2026-04-08 10:58:17 -04:00
|
|
|
http2 = True
|
2024-11-24 13:40:09 -05:00
|
|
|
|
2024-10-31 14:10:08 -04:00
|
|
|
if workers > 2:
|
2024-11-28 05:13:31 -05:00
|
|
|
workers = 2
|
2024-10-31 14:10:08 -04:00
|
|
|
|
2024-11-28 05:05:23 -05:00
|
|
|
threads = workers * 2
|
2024-10-31 14:10:08 -04:00
|
|
|
backlog = 512
|
|
|
|
|
reload = False
|
2024-11-26 16:50:15 -05:00
|
|
|
daemon = True
|
2024-11-28 05:13:31 -05:00
|
|
|
# # worker_class = 'geventwebsocket.gunicorn.workers.GeventWebSocketWorker'
|
2026-04-05 03:19:19 -04:00
|
|
|
worker_class = 'gthread'
|
2024-11-01 14:19:58 -04:00
|
|
|
timeout = 600
|
2024-10-31 14:10:08 -04:00
|
|
|
keepalive = 60
|
2024-11-28 05:44:17 -05:00
|
|
|
preload_app = False
|
2024-10-31 14:10:08 -04:00
|
|
|
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'
|
2024-11-11 12:00:06 -05:00
|
|
|
pidfile = log_dir + '/panel.pid'
|