Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xhprof|安全入口|面板端口命令修复 #637

Merged
merged 22 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions panel_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def mwcli(mw_input=0):
'(3) 启动面板服务',
'(4) 重载面板服务',
'(5) 修改面板端口',
'(6) 关闭安全入口',
'(10) 查看面板默认信息',
'(11) 修改面板密码',
'(12) 修改面板用户名',
Expand Down Expand Up @@ -98,7 +99,8 @@ def mwcli(mw_input=0):
mw_input = 0

nums = [
1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15,
1, 2, 3, 4, 5, 6,
10, 11, 12, 13, 14, 15,
20, 21, 22, 23, 24, 25, 26, 27, 28,
100, 101,
200, 201
Expand Down Expand Up @@ -128,6 +130,9 @@ def mwcli(mw_input=0):
else:
mw.echoInfo("端口范围在0-65536之间")
return
elif mw_input == 6:
thisdb.setOption('admin_path', '')
mw.echoInfo("关闭安全入口成功!")
elif mw_input == 10:
os.system(INIT_CMD + " default")
elif mw_input == 11:
Expand Down Expand Up @@ -220,7 +225,6 @@ def mwcli(mw_input=0):
if not run_cmd:
mw.echoInfo("未检测到防火墙!")
elif mw_input == 28:
from utils.firewall import Firewall as MwFirewall
MwFirewall.instance().aIF()
mw.echoInfo("执行自动识别防火墙端口到面板成功!")
elif mw_input == 100:
Expand Down Expand Up @@ -283,7 +287,10 @@ def show_panel_pwd():

def show_panel_adminpath():
admin_path = thisdb.getOption('admin_path')
print('/'+admin_path)
if admin_path == '':
print('/login')
else:
print('/'+admin_path)


def set_panel_username(username=None):
Expand Down
60 changes: 32 additions & 28 deletions plugins/php/conf/app_start.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

if (isset($_GET['mw_opcache_reset']) && $_GET['mw_opcache_reset'] == 'ok'){
opcache_reset();
if (isset($_GET['mw_opcache_reset']) && $_GET['mw_opcache_reset'] == 'ok') {
if (function_exists('opcache_reset')) {
opcache_reset();
}
}

define('XHProf_Name', 'mdd');
Expand All @@ -11,43 +13,45 @@
*/

function app_xhprof_start() {
$root = '{$ROOT_PATH}';
$lib = $root . '/server/xhprof/xhprof_lib/utils/xhprof_lib.php';
if (file_exists($lib)) {
include_once $lib;
include_once $root . '/server/xhprof/xhprof_lib/utils/xhprof_runs.php';
xhprof_enable();
}
$root = '{$ROOT_PATH}';
$lib = $root . '/server/xhprof/xhprof_lib/utils/xhprof_lib.php';
if (file_exists($lib)) {
include_once $lib;
include_once $root . '/server/xhprof/xhprof_lib/utils/xhprof_runs.php';
xhprof_enable();
}
}

function app_xhprof_end() {

$root = '{$ROOT_PATH}';
$lib = $root . '/server/xhprof';
if (!file_exists($lib)) {
return;
}
$root = '{$ROOT_PATH}';
$lib = $root . '/server/xhprof';
if (! file_exists($lib)) {
return;
}

//保存xhprof数据
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
//保存xhprof数据
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();

$run_id = $xhprof_runs->save_run($xhprof_data, 'xhprof_foo');
$run_id = $xhprof_runs->save_run($xhprof_data, 'xhprof_foo');

$profiler_url = sprintf('http://{$LOCAL_IP}:5858/index.php?run=%s&source=xhprof_foo', $run_id);
echo "<script language='javascript'>window.open('{$profiler_url}')</script>";
// echo '<a href="' . $profiler_url . '" target="_blank">Profiler output</a>';
$profiler_url = sprintf('http://{$LOCAL_IP}:5858/index.php?run=%s&source=xhprof_foo', $run_id);
// echo "<script language='javascript'>window.open('{$profiler_url}')</script>";

$style_css = 'position:fixed;bottom: 0px;right: 0px;z-index: 100000000;color: red;background-color: black;padding: 0px;margin: 0px;';
echo '<a href="' . $profiler_url . '" target="_blank" style="' . $style_css . '">XHProf分析结果</a>';

}

if (extension_loaded('xhprof')
&& isset($_GET[XHProf_Name]) && $_GET[XHProf_Name] == 'ok' &&
(!in_array($_SERVER['SCRIPT_NAME'], array('/xhprof_html/callgraph.php',
'/xhprof_html/index.php')))) {
app_xhprof_start();
include_once $_SERVER['SCRIPT_FILENAME'];
app_xhprof_end();
exit;
&& isset($_GET[XHProf_Name]) && $_GET[XHProf_Name] == 'ok' &&
(! in_array($_SERVER['SCRIPT_NAME'], ['/xhprof_html/callgraph.php',
'/xhprof_html/index.php']))) {
app_xhprof_start();
register_shutdown_function('app_xhprof_end');
include_once $_SERVER['SCRIPT_FILENAME'];
exit;
}

?>
32 changes: 20 additions & 12 deletions plugins/xhprof/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import time
import re
import json

web_dir = os.getcwd() + "/web"
if os.path.exists(web_dir):
Expand Down Expand Up @@ -72,8 +73,7 @@ def getHomePage():
return mw.returnJson(False, '插件未启动!')


def getPhpVer(expect=56):
import json
def getPhpVer(expect=74):
v = MwSites.instance().getPhpVersion()
for i in range(len(v)):
t = int(v[i]['version'])
Expand All @@ -100,6 +100,7 @@ def contentReplace(content):
content = content.replace('{$ROOT_PATH}', mw.getFatherDir())
content = content.replace('{$SERVER_PATH}', service_path)
content = content.replace('{$PHP_VER}', php_ver)
content = content.replace('{$LOCAL_IP}', mw.getLocalIp())
return content


Expand All @@ -118,8 +119,22 @@ def status():
return 'start'
return 'stop'

def getConfAppStart():
pstart = mw.getServerDir() + '/php/app_start.php'
return pstart


def phpPrependFile():
app_start = getConfAppStart()
tpl = mw.getPluginDir() + '/php/conf/app_start.php'
content = mw.readFile(tpl)
content = contentReplace(content)
mw.writeFile(app_start, content)
return True

def start():
phpPrependFile()

file_tpl = getPluginDir() + '/conf/xhprof.conf'
file_run = getConf()

Expand Down Expand Up @@ -160,12 +175,11 @@ def setPhpVer():
file_tpl = getPluginDir() + '/conf/xhprof.conf'
file_run = getConf()

centent = mw.readFile(file_tpl)
centent = contentReplacePHP(centent, args['phpver'])
mw.writeFile(file_run, centent)
content = mw.readFile(file_tpl)
content = contentReplacePHP(content, args['phpver'])
mw.writeFile(file_run, content)

mw.restartWeb()

return 'ok'


Expand Down Expand Up @@ -204,13 +218,7 @@ def setXhPort():
return mw.returnJson(True, '修改成功!')


def getConfAppStart():
pstart = mw.getServerDir() + '/php/app_start.php'
return pstart


def installPreInspection():

path = mw.getServerDir() + '/php'
if not os.path.exists(path):
return "先安装一个可用的PHP版本!"
Expand Down
4 changes: 1 addition & 3 deletions scripts/init.d/mw.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ mw_install_app()
}

mw_close_admin_path(){
if [ -f $mw_path/data/admin_path.pl ]; then
rm -rf $mw_path/data/admin_path.pl
fi
cd ${PANEL_DIR} && python3 panel_tools.py cli 6
}

mw_force_kill()
Expand Down
2 changes: 1 addition & 1 deletion web/admin/dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


blueprint = Blueprint('dashboard', __name__, url_prefix='/', template_folder='../../templates')
@blueprint.route('/')
@blueprint.route('/', endpoint='index', methods=['GET'])
@panel_login_required
def index():
name = thisdb.getOption('template', default='default')
Expand Down
4 changes: 2 additions & 2 deletions web/admin/dashboard/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def login():
session['login'] = False
session['overdue'] = 0

db_path = thisdb.getOption('admin_path')
if db_path == '':
admin_path = thisdb.getOption('admin_path')
if admin_path == '':
return render_template('%s/login.html' % name)
else:
unauthorized_status = thisdb.getOption('unauthorized_status')
Expand Down
6 changes: 3 additions & 3 deletions web/static/app/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,11 @@ function onlineEditFile(k, f, callback) {
"Ctrl-H": "replaceAll",
"Ctrl-S": function() {
$("#textBody").text(code_mirror.getValue());
onlineEditFile(2, f,callback);
onlineEditFile(2, f, callback);
},
"Cmd-S":function() {
$("#textBody").text(code_mirror.getValue());
onlineEditFile(2, f,callback);
onlineEditFile(2, f, callback);
},
},
mode: d,
Expand All @@ -758,7 +758,7 @@ function onlineEditFile(k, f, callback) {
},
yes:function(){
$("#textBody").text(code_mirror.getValue());
onlineEditFile(1, f,callback);
onlineEditFile(1, f, callback);
}
});
},'json');
Expand Down
Loading