修复日志页面卡顿我呢提
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* 日志 datatable 接口鉴权
|
||||
*/
|
||||
if (!function_exists('cloak_datatable_require_auth')) {
|
||||
function cloak_datatable_require_auth()
|
||||
{
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
if (empty($_SESSION['password']) || $_SESSION['password'] != LOGIN_PASSWORD) {
|
||||
unset($_SESSION['password']);
|
||||
unset($_SESSION['check_result']);
|
||||
http_response_code(404);
|
||||
die('404 Not Found');
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-121
@@ -4,8 +4,10 @@ require_once(dirname(__DIR__) . "/cong.php");
|
||||
require_once(dirname(__DIR__) . "/lib/DbHelper.php");
|
||||
require_once(dirname(__DIR__) . "/lib/Cloak/PipelineTimer.php");
|
||||
require_once(dirname(__DIR__) . "/lib/Cloak/VisitorLogSchema.php");
|
||||
require_once(dirname(__DIR__) . "/lib/Cloak/VisitorApiAudit.php");
|
||||
session_start();
|
||||
require_once(dirname(__DIR__) . "/lib/Cloak/VisitorLogListHelper.php");
|
||||
require_once(dirname(__DIR__) . "/datatable/auth.php");
|
||||
|
||||
cloak_datatable_require_auth();
|
||||
|
||||
$reasons = array(
|
||||
"blank_referrer" => "过滤无来源的访问",
|
||||
@@ -45,20 +47,9 @@ $reasons = array(
|
||||
"time_of_day" => "不可访问的日期",
|
||||
);
|
||||
|
||||
if(empty($_SESSION['password']) || $_SESSION['password'] != LOGIN_PASSWORD) {
|
||||
unset($_SESSION['password']);
|
||||
unset($_SESSION['check_result']);
|
||||
die("404 Not Found");
|
||||
}
|
||||
$servername = "localhost";
|
||||
$username = DB_USERNAME;
|
||||
$password = DB_PASSWORD;
|
||||
$dbname = DB_NAME;
|
||||
|
||||
// Create connection
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
$jsonResult = array();
|
||||
// Check connection
|
||||
$conn = new mysqli('localhost', DB_USERNAME, DB_PASSWORD, DB_NAME);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
$error = "Connection failed: " . $conn->connect_error;
|
||||
$handle = fopen(dirname(__FILE__) . "/err.txt", "a+");
|
||||
@@ -71,123 +62,40 @@ if ($conn->connect_error) {
|
||||
$jsonResult["data"] = array();
|
||||
} else {
|
||||
VisitorLogSchema::ensureColumns($conn);
|
||||
if(isset($_GET['clear']) && $_GET['clear'] == "true") { //清除日志数据表
|
||||
$sql = "TRUNCATE `visitor_logs`";
|
||||
|
||||
// 执行查询并输出结果
|
||||
$result = mysqli_query($conn, $sql);
|
||||
VisitorLogSchema::ensureIndexes($conn);
|
||||
|
||||
if(isset($_GET['clear']) && $_GET['clear'] == "true") {
|
||||
$conn->query("TRUNCATE `visitor_logs`");
|
||||
$jsonResult["code"] = 0;
|
||||
$jsonResult["msg"] = "success";
|
||||
$jsonResult["count"] = 0;
|
||||
$jsonResult["data"] = array();
|
||||
} else { // 默认分页数据
|
||||
// 获取当前页码(默认为第1页)
|
||||
$pageNumber = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
|
||||
// 设置每页显示的记录条数
|
||||
$recordsPerPage = isset($_GET['limit']) ? (int) $_GET['limit'] : 50;
|
||||
|
||||
// 计算起始位置
|
||||
} else {
|
||||
$pageNumber = isset($_GET['page']) ? max(1, (int) $_GET['page']) : 1;
|
||||
$recordsPerPage = isset($_GET['limit']) ? max(1, min(200, (int) $_GET['limit'])) : 50;
|
||||
$startPosition = ($pageNumber - 1) * $recordsPerPage;
|
||||
$map = array();
|
||||
$where = 1;
|
||||
|
||||
if(!empty($_GET['visit_date'])) {
|
||||
$map[] = "DATE_FORMAT(`visit_date`, '%Y-%m-%d') LIKE '" . cloak_db_escape($conn, $_GET['visit_date']) . "'";
|
||||
$where = VisitorLogListHelper::buildWhere($conn, $_GET);
|
||||
|
||||
$sql = VisitorLogListHelper::listSelectSql($where, $startPosition, $recordsPerPage, true);
|
||||
$result = $conn->query($sql);
|
||||
$jsonData = array();
|
||||
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$jsonData[] = VisitorLogListHelper::formatListRow($row, $countries, $reasons);
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
|
||||
$where .= cloak_visitor_log_apply_result_filter($conn, $_GET['result'] ?? '');
|
||||
|
||||
if(!empty($_GET['country'])) {
|
||||
$map[] = "country LIKE '" . cloak_db_escape($conn, $_GET['country']) . "'";
|
||||
}
|
||||
|
||||
if(!empty($_GET['IP'])) {
|
||||
$map[] = "IP LIKE '" . cloak_db_escape($conn, $_GET['IP']) . "'";
|
||||
}
|
||||
|
||||
if(!empty($_GET['domain'])) {
|
||||
$map[] = "domain LIKE '%" . cloak_db_escape($conn, $_GET['domain']) . "%'";
|
||||
}
|
||||
|
||||
if(!empty($_GET['spage'])) {
|
||||
$map[] = "page LIKE '%" . cloak_db_escape($conn, $_GET['spage']) . "%'";
|
||||
}
|
||||
|
||||
if(!empty($map)) {
|
||||
$where .= " AND " . join(" AND ", $map);
|
||||
}
|
||||
// SQL语句
|
||||
$sql = "SELECT `id`, `campagin_id`, `visit_md5_code`, `domain`, `visit_date`, `IP`, `country`, `result`, `reason`, `fp_url`, `referer`, `vtimes`, `client`, `browser`, `page`, `language`, `user_agent`, `http_referer`, `accept_language_raw`, `judge_timing`, `fp_hdata`, `api_by_request`, `api_by_response`, `api_risk_request`, `api_risk_response`, `device`, `add_time` FROM `visitor_logs` WHERE {$where} ORDER BY `id` DESC LIMIT {$startPosition}, {$recordsPerPage}";
|
||||
|
||||
// 执行查询并输出结果
|
||||
$result = mysqli_query($conn, $sql);
|
||||
$jsonData = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
//echo "<p>{$row["columnName"]}</p>"; // 根据需要修改列名
|
||||
if($row['vtimes'] == 0) {
|
||||
$row['vtimes'] = 1; // 还未统计访问次数
|
||||
$sqlVtimes = mysqli_query($conn, "SELECT count(*) as `total` FROM `visitor_logs` WHERE `IP` = '" . cloak_db_escape($conn, $row["IP"]) . "' AND `domain` = '" . cloak_db_escape($conn, $row["domain"]) . "' AND id < " . (int)$row['id']);
|
||||
$vtimesRow = mysqli_fetch_assoc($sqlVtimes);
|
||||
$vtimes = $vtimesRow["total"]; // 如果之前此IP有访问记录
|
||||
if($vtimes > 0) {
|
||||
$row['vtimes'] += $vtimes; // 访问次数叠加
|
||||
}
|
||||
|
||||
// 更新访问次数
|
||||
$updateSql = "UPDATE `visitor_logs` SET `vtimes`=" . (int)$row['vtimes'] . " WHERE id = " . $row['id'];
|
||||
mysqli_query($conn, $updateSql);
|
||||
}
|
||||
|
||||
if(!empty($row['country'])) {
|
||||
$row['country'] = isset($countries[$row['country']])?$countries[$row['country']]:"无";
|
||||
} else {
|
||||
$row['country'] = "无";
|
||||
}
|
||||
if(isset($reasons[$row['reason']])) {
|
||||
$row['reason'] = $reasons[$row['reason']];
|
||||
}
|
||||
if ($row['result'] === 'wait') {
|
||||
$row['result'] = '检测中';
|
||||
}
|
||||
$row['judge_timing_text'] = cloak_visitor_log_format_timing($row['judge_timing'] ?? '');
|
||||
$row['fp_hdata_text'] = cloak_visitor_log_format_fp_hdata($row['fp_hdata'] ?? '');
|
||||
if (!empty($row['fp_hdata'])) {
|
||||
$explain = cloak_visitor_log_fp_risk_explain(
|
||||
$row['fp_hdata'],
|
||||
$row['reason'] ?? '',
|
||||
$row['result'] ?? '',
|
||||
$row['domain'] ?? ''
|
||||
);
|
||||
$row['fp_hdata_explain_summary'] = $explain['summary'];
|
||||
$row['fp_hdata_explain_html'] = $explain['html'];
|
||||
$row['fp_hdata_explain'] = $explain['data'];
|
||||
} else {
|
||||
$row['fp_hdata_explain_summary'] = '';
|
||||
$row['fp_hdata_explain_html'] = '';
|
||||
$row['fp_hdata_explain'] = null;
|
||||
}
|
||||
$row['api_by_request_text'] = VisitorApiAudit::displayText($row['api_by_request'] ?? '');
|
||||
$row['api_by_response_text'] = VisitorApiAudit::displayText($row['api_by_response'] ?? '');
|
||||
$row['api_risk_request_text'] = VisitorApiAudit::displayText($row['api_risk_request'] ?? '');
|
||||
$row['api_risk_response_text']= VisitorApiAudit::displayText($row['api_risk_response'] ?? '');
|
||||
$jsonData[] = $row;
|
||||
}
|
||||
|
||||
$sqlCount = mysqli_query($conn, "SELECT count(*) as `total` FROM `visitor_logs` WHERE {$where}");
|
||||
$countRow = mysqli_fetch_assoc($sqlCount);
|
||||
|
||||
$jsonResult["code"] = 0;
|
||||
$jsonResult["msg"] = "";
|
||||
$jsonResult["count"] = $countRow['total'];
|
||||
$jsonResult["count"] = VisitorLogListHelper::countWhere($conn, $where);
|
||||
$jsonResult["data"] = $jsonData;
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭数据库连接
|
||||
mysqli_close($conn);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$conn->close();
|
||||
|
||||
echo json_encode($jsonResult);exit;
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($jsonResult);
|
||||
exit;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* 二次风控判定解析(按需加载,供日志列表点击「判定详情」)
|
||||
*/
|
||||
require_once dirname(__DIR__) . '/cong.php';
|
||||
require_once dirname(__DIR__) . '/lib/DbHelper.php';
|
||||
require_once dirname(__DIR__) . '/datatable/auth.php';
|
||||
|
||||
cloak_datatable_require_auth();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['code' => 1, 'msg' => 'invalid id']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn = new mysqli('localhost', DB_USERNAME, DB_PASSWORD, DB_NAME);
|
||||
if ($conn->connect_error) {
|
||||
echo json_encode(['code' => 1, 'msg' => 'db error']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT `id`, `fp_hdata`, `reason`, `result`, `domain` FROM `visitor_logs` WHERE `id`=" . $id . ' LIMIT 1';
|
||||
$res = $conn->query($sql);
|
||||
$row = $res ? $res->fetch_assoc() : null;
|
||||
if ($res) {
|
||||
$res->free();
|
||||
}
|
||||
$conn->close();
|
||||
|
||||
if (!$row || empty($row['fp_hdata'])) {
|
||||
echo json_encode(['code' => 1, 'msg' => 'no fp_hdata']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $row['result'] ?? '';
|
||||
if ($result === 'wait') {
|
||||
$result = '检测中';
|
||||
}
|
||||
|
||||
$explain = cloak_visitor_log_fp_risk_explain(
|
||||
$row['fp_hdata'],
|
||||
$row['reason'] ?? '',
|
||||
$result,
|
||||
$row['domain'] ?? ''
|
||||
);
|
||||
|
||||
echo json_encode([
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'summary' => $explain['summary'],
|
||||
'html' => $explain['html'],
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
Regular → Executable
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* 日志大字段按需加载(fp_hdata、api_* 等)
|
||||
*/
|
||||
require_once dirname(__DIR__) . '/cong.php';
|
||||
require_once dirname(__DIR__) . '/lib/DbHelper.php';
|
||||
require_once dirname(__DIR__) . '/datatable/auth.php';
|
||||
|
||||
cloak_datatable_require_auth();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
$field = isset($_GET['field']) ? (string) $_GET['field'] : '';
|
||||
|
||||
$allowed = [
|
||||
'fp_hdata' => 'fp_hdata',
|
||||
'api_by_request' => 'api_by_request',
|
||||
'api_by_response' => 'api_by_response',
|
||||
'api_risk_request' => 'api_risk_request',
|
||||
'api_risk_response' => 'api_risk_response',
|
||||
'user_agent' => 'user_agent',
|
||||
'http_referer' => 'http_referer',
|
||||
'accept_language_raw' => 'accept_language_raw',
|
||||
];
|
||||
|
||||
if ($id <= 0 || !isset($allowed[$field])) {
|
||||
echo json_encode(['code' => 1, 'msg' => 'invalid request']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$col = $allowed[$field];
|
||||
$conn = new mysqli('localhost', DB_USERNAME, DB_PASSWORD, DB_NAME);
|
||||
if ($conn->connect_error) {
|
||||
echo json_encode(['code' => 1, 'msg' => 'db error']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = 'SELECT `' . $col . '` AS `blob` FROM `visitor_logs` WHERE `id`=' . $id . ' LIMIT 1';
|
||||
$res = $conn->query($sql);
|
||||
$row = $res ? $res->fetch_assoc() : null;
|
||||
if ($res) {
|
||||
$res->free();
|
||||
}
|
||||
$conn->close();
|
||||
|
||||
$blob = trim((string) ($row['blob'] ?? ''));
|
||||
if ($blob === '') {
|
||||
echo json_encode(['code' => 1, 'msg' => 'empty']);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'field' => $field,
|
||||
'data' => $blob,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
+26
-111
@@ -4,7 +4,7 @@ require_once(dirname(__DIR__) . "/cong.php");
|
||||
require_once(dirname(__DIR__) . "/lib/DbHelper.php");
|
||||
require_once(dirname(__DIR__) . "/lib/Cloak/PipelineTimer.php");
|
||||
require_once(dirname(__DIR__) . "/lib/Cloak/VisitorLogSchema.php");
|
||||
require_once(dirname(__DIR__) . "/lib/Cloak/VisitorApiAudit.php");
|
||||
require_once(dirname(__DIR__) . "/lib/Cloak/VisitorLogListHelper.php");
|
||||
|
||||
$reasons = array(
|
||||
"blank_referrer" => "过滤无来源的访问",
|
||||
@@ -44,15 +44,9 @@ $reasons = array(
|
||||
"time_of_day" => "不可访问的日期",
|
||||
);
|
||||
|
||||
$servername = "localhost";
|
||||
$username = DB_USERNAME;
|
||||
$password = DB_PASSWORD;
|
||||
$dbname = DB_NAME;
|
||||
|
||||
// Create connection
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
$jsonResult = array();
|
||||
// Check connection
|
||||
$conn = new mysqli('localhost', DB_USERNAME, DB_PASSWORD, DB_NAME);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
$error = "Connection failed: " . $conn->connect_error;
|
||||
$handle = fopen(dirname(__FILE__) . "/err.txt", "a+");
|
||||
@@ -65,119 +59,40 @@ if ($conn->connect_error) {
|
||||
$jsonResult["data"] = array();
|
||||
} else {
|
||||
VisitorLogSchema::ensureColumns($conn);
|
||||
if(isset($_GET['clear']) && $_GET['clear'] == "true") { //清除日志数据表
|
||||
$sql = "TRUNCATE `visitor_logs`";
|
||||
|
||||
// 执行查询并输出结果
|
||||
$result = mysqli_query($conn, $sql);
|
||||
VisitorLogSchema::ensureIndexes($conn);
|
||||
|
||||
if(isset($_GET['clear']) && $_GET['clear'] == "true") {
|
||||
$conn->query("TRUNCATE `visitor_logs`");
|
||||
$jsonResult["code"] = 0;
|
||||
$jsonResult["msg"] = "success";
|
||||
$jsonResult["count"] = 0;
|
||||
$jsonResult["data"] = array();
|
||||
} else { // 默认分页数据
|
||||
// 获取当前页码(默认为第1页)
|
||||
$pageNumber = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
|
||||
// 设置每页显示的记录条数
|
||||
$recordsPerPage = isset($_GET['limit']) ? (int) $_GET['limit'] : 50;
|
||||
|
||||
// 计算起始位置
|
||||
} else {
|
||||
$pageNumber = isset($_GET['page']) ? max(1, (int) $_GET['page']) : 1;
|
||||
$recordsPerPage = isset($_GET['limit']) ? max(1, min(200, (int) $_GET['limit'])) : 50;
|
||||
$startPosition = ($pageNumber - 1) * $recordsPerPage;
|
||||
$map = array();
|
||||
$where = 1;
|
||||
|
||||
if(!empty($_GET['visit_date'])) {
|
||||
$map[] = "DATE_FORMAT(`visit_date`, '%Y-%m-%d') LIKE '" . cloak_db_escape($conn, $_GET['visit_date']) . "'";
|
||||
$where = VisitorLogListHelper::buildWhere($conn, $_GET);
|
||||
|
||||
$sql = VisitorLogListHelper::listSelectSql($where, $startPosition, $recordsPerPage, false);
|
||||
$result = $conn->query($sql);
|
||||
$jsonData = array();
|
||||
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$jsonData[] = VisitorLogListHelper::formatListRow($row, $countries, $reasons);
|
||||
}
|
||||
$result->free();
|
||||
}
|
||||
|
||||
$where .= cloak_visitor_log_apply_result_filter($conn, $_GET['result'] ?? '');
|
||||
|
||||
if(!empty($_GET['country'])) {
|
||||
$map[] = "country LIKE '" . cloak_db_escape($conn, $_GET['country']) . "'";
|
||||
}
|
||||
|
||||
if(!empty($_GET['IP'])) {
|
||||
$map[] = "IP LIKE '" . cloak_db_escape($conn, $_GET['IP']) . "'";
|
||||
}
|
||||
|
||||
if(!empty($_GET['domain'])) {
|
||||
$map[] = "domain LIKE '%" . cloak_db_escape($conn, $_GET['domain']) . "%'";
|
||||
}
|
||||
|
||||
if(!empty($_GET['spage'])) {
|
||||
$map[] = "page LIKE '%" . cloak_db_escape($conn, $_GET['spage']) . "%'";
|
||||
}
|
||||
|
||||
if(!empty($map)) {
|
||||
$where .= " AND " . join(" AND ", $map);
|
||||
}
|
||||
// SQL语句
|
||||
$sql = "SELECT `id`, `campagin_id`, `visit_md5_code`, `domain`, `visit_date`, `IP`, `country`, `result`, `reason`, `fp_url`, `referer`, `vtimes`, `client`, `browser`, `page`, `language`, `user_agent`, `http_referer`, `accept_language_raw`, `judge_timing`, `fp_hdata`, `api_by_request`, `api_by_response`, `api_risk_request`, `api_risk_response`, `device`, `add_time` FROM `visitor_logs` WHERE {$where} ORDER BY `id` DESC LIMIT {$startPosition}, {$recordsPerPage}";
|
||||
|
||||
// 执行查询并输出结果
|
||||
$result = mysqli_query($conn, $sql);
|
||||
$jsonData = array();
|
||||
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
//echo "<p>{$row["columnName"]}</p>"; // 根据需要修改列名
|
||||
if($row['vtimes'] == 0) {
|
||||
$row['vtimes'] = 1; // 还未统计访问次数
|
||||
$sqlVtimes = mysqli_query($conn, "SELECT count(*) as `total` FROM `visitor_logs` WHERE `IP` = '" . cloak_db_escape($conn, $row["IP"]) . "' AND `domain` = '" . cloak_db_escape($conn, $row["domain"]) . "' AND id < " . (int)$row['id']);
|
||||
$vtimesRow = mysqli_fetch_assoc($sqlVtimes);
|
||||
$vtimes = $vtimesRow["total"]; // 如果之前此IP有访问记录
|
||||
if($vtimes > 0) {
|
||||
$row['vtimes'] += $vtimes; // 访问次数叠加
|
||||
}
|
||||
|
||||
// 更新访问次数
|
||||
$updateSql = "UPDATE `visitor_logs` SET `vtimes`=" . (int)$row['vtimes'] . " WHERE id = " . $row['id'];
|
||||
mysqli_query($conn, $updateSql);
|
||||
}
|
||||
|
||||
$row['country'] = $countries[$row['country']];
|
||||
if(isset($reasons[$row['reason']])) {
|
||||
$row['reason'] = $reasons[$row['reason']];
|
||||
}
|
||||
if ($row['result'] === 'wait') {
|
||||
$row['result'] = '检测中';
|
||||
}
|
||||
$row['judge_timing_text'] = cloak_visitor_log_format_timing($row['judge_timing'] ?? '');
|
||||
$row['fp_hdata_text'] = cloak_visitor_log_format_fp_hdata($row['fp_hdata'] ?? '');
|
||||
if (!empty($row['fp_hdata'])) {
|
||||
$explain = cloak_visitor_log_fp_risk_explain(
|
||||
$row['fp_hdata'],
|
||||
$row['reason'] ?? '',
|
||||
$row['result'] ?? '',
|
||||
$row['domain'] ?? ''
|
||||
);
|
||||
$row['fp_hdata_explain_summary'] = $explain['summary'];
|
||||
$row['fp_hdata_explain_html'] = $explain['html'];
|
||||
$row['fp_hdata_explain'] = $explain['data'];
|
||||
} else {
|
||||
$row['fp_hdata_explain_summary'] = '';
|
||||
$row['fp_hdata_explain_html'] = '';
|
||||
$row['fp_hdata_explain'] = null;
|
||||
}
|
||||
$row['api_by_request_text'] = VisitorApiAudit::displayText($row['api_by_request'] ?? '');
|
||||
$row['api_by_response_text'] = VisitorApiAudit::displayText($row['api_by_response'] ?? '');
|
||||
$row['api_risk_request_text'] = VisitorApiAudit::displayText($row['api_risk_request'] ?? '');
|
||||
$row['api_risk_response_text']= VisitorApiAudit::displayText($row['api_risk_response'] ?? '');
|
||||
$jsonData[] = $row;
|
||||
}
|
||||
|
||||
$sqlCount = mysqli_query($conn, "SELECT count(*) as `total` FROM `visitor_logs` WHERE {$where}");
|
||||
$countRow = mysqli_fetch_assoc($sqlCount);
|
||||
|
||||
$jsonResult["code"] = 0;
|
||||
$jsonResult["msg"] = "";
|
||||
$jsonResult["count"] = $countRow['total'];
|
||||
$jsonResult["count"] = VisitorLogListHelper::countWhere($conn, $where);
|
||||
$jsonResult["data"] = $jsonData;
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭数据库连接
|
||||
mysqli_close($conn);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$conn->close();
|
||||
|
||||
echo json_encode($jsonResult);exit;
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($jsonResult);
|
||||
exit;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
require_once dirname(__DIR__) . '/cong.php';
|
||||
require_once dirname(__DIR__) . '/lib/bootstrap.php';
|
||||
require_once dirname(__DIR__) . '/lib/Cloak/VisitorSimulationRunner.php';
|
||||
session_start();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
if (empty($_SESSION['password']) || $_SESSION['password'] != LOGIN_PASSWORD) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['ok' => false, 'message' => '未授权'], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$action = $_REQUEST['action'] ?? '';
|
||||
|
||||
if ($action === 'prefill') {
|
||||
$logId = (int) ($_GET['log_id'] ?? 0);
|
||||
echo json_encode(VisitorSimulationRunner::prefillFromLog($logId), JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'configs') {
|
||||
$list = [];
|
||||
foreach (glob(dirname(__DIR__) . '/check_config/*_config.php') as $file) {
|
||||
$name = basename($file, '_config.php');
|
||||
if ($name !== '') {
|
||||
$list[] = $name;
|
||||
}
|
||||
}
|
||||
sort($list);
|
||||
echo json_encode(['ok' => true, 'configs' => $list], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['ok' => false, 'message' => '请使用 POST'], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $_POST;
|
||||
if (empty($payload) && ($raw = file_get_contents('php://input'))) {
|
||||
$decoded = json_decode($raw, true);
|
||||
if (is_array($decoded)) {
|
||||
$payload = $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
if ($action === 'replay') {
|
||||
$logId = (int) ($payload['log_id'] ?? 0);
|
||||
echo json_encode(VisitorSimulationRunner::replayFromLog($logId), JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'run') {
|
||||
echo json_encode(VisitorSimulationRunner::runManual($payload), JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
http_response_code(400);
|
||||
echo json_encode(['ok' => false, 'message' => '未知 action'], JSON_UNESCAPED_UNICODE);
|
||||
Reference in New Issue
Block a user