hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
set_time_limit(120); //暂时设置本脚本执行时间秒
header("Content-type: text/html; charset=utf-8");
include_once '/Common/Logging.php';
 
\Logging\CreateLogging('eventdata.tool.php');
\Logging\LogInfo("_POST: " . print_r($_POST, true));
 
$eventType = $_POST["eventType"];
$pyScriptName = $eventType . ".py";
if (!$eventType || !file_exists($pyScriptName)) {
    echo "不存在该命令脚本! " . $eventType;
    return;
}
 
// 删除不用的参数
// unset($_POST["eventType"]);
unset($_POST["pack_type"]);
unset($_POST["submit"]);
 
$cmd = "python " . $pyScriptName;
$argvs = "";
foreach ($_POST as $key => $value) {
    if ($value) {
        $value = str_replace("\"", "\\\"", $value);
        $value = str_replace(" ", "", $value);
        $argvs .= " " . $key . "=[" . trim($value) . "]";
    }
}
$cmd .= $argvs;
\Logging\LogInfo("cmd: " . $cmd);
$ret = exec($cmd);
// \Logging\LogInfo("ret: " . $ret);
if (!$ret) {
    echo "无返回信息!<br/> cmd: ", $cmd, "<br/>";
} else {
    if (strpos($ret, "Traceback") != false) {
        echo "<hr/>";
        echo "_POST: ", print_r($_POST, true), "<br/><br/>";
        echo "cmd: " . $cmd, "<br/><br/>";
    }
    echo $ret;
}