feat: initial commit

This commit is contained in:
root
2026-06-14 14:00:24 +08:00
commit 72d388f642
118 changed files with 39015 additions and 0 deletions
+250
View File
@@ -0,0 +1,250 @@
<?php
// 国家全程与简码
$countries = array(
"XXX"=> "",
"AF" => "Afghanistan",
"AX" => "Aland Islands",
"AL" => "Albania",
"DZ" => "Algeria",
"AS" => "American Samoa",
"AD" => "Andorra",
"AO" => "Angola",
"AI" => "Anguilla",
"AQ" => "Antarctica",
"AG" => "Antigua and Barbuda",
"AR" => "Argentina",
"AM" => "Armenia",
"AW" => "Aruba",
"AU" => "Australia",
"AT" => "Austria",
"AZ" => "Azerbaijan",
"BS" => "Bahamas",
"BH" => "Bahrain",
"BD" => "Bangladesh",
"BB" => "Barbados",
"BY" => "Belarus",
"BE" => "Belgium",
"BZ" => "Belize",
"BJ" => "Benin",
"BM" => "Bermuda",
"BT" => "Bhutan",
"BO" => "Bolivia, Plurinational State of",
"BQ" => "Bonaire, Sint Eustatius and Saba",
"BA" => "Bosnia and Herzegovina",
"BW" => "Botswana",
"BV" => "Bouvet Island",
"BR" => "Brazil",
"IO" => "British Indian Ocean Territory",
"BN" => "Brunei Darussalam",
"BG" => "Bulgaria",
"BF" => "Burkina Faso",
"BI" => "Burundi",
"CV" => "Cabo Verde",
"KH" => "Cambodia",
"CM" => "Cameroon",
"CA" => "Canada",
"KY" => "Cayman Islands",
"CF" => "Central African Republic",
"TD" => "Chad",
"CL" => "Chile",
"CN" => "China",
"CC" => "Cocos (Keeling) Islands",
"CO" => "Colombia",
"KM" => "Comoros",
"CG" => "Congo",
"CD" => "Congo, The Democratic Republic of The",
"CK" => "Cook Islands",
"CR" => "Costa Rica",
"CI" => "Cote D'ivoire",
"HR" => "Croatia",
"CU" => "Cuba",
"CW" => "Curacao",
"CY" => "Cyprus",
"CZ" => "Czech Republic",
"DK" => "Denmark",
"DJ" => "Djibouti",
"DM" => "Dominica",
"DO" => "Dominican Republic",
"EC" => "Ecuador",
"EG" => "Egypt",
"SV" => "El Salvador",
"GQ" => "Equatorial Guinea",
"ER" => "Eritrea",
"EE" => "Estonia",
"ET" => "Ethiopia",
"FK" => "Falkland Islands (Malvinas)",
"FO" => "Faroe Islands",
"FJ" => "Fiji",
"FI" => "Finland",
"FR" => "France",
"GF" => "French Guiana",
"PF" => "French Polynesia",
"TF" => "French Southern Territories",
"GA" => "Gabon",
"GM" => "Gambia",
"GE" => "Georgia",
"DE" => "Germany",
"GH" => "Ghana",
"GI" => "Gibraltar",
"GR" => "Greece",
"GL" => "Greenland",
"GD" => "Grenada",
"GP" => "Guadeloupe",
"GU" => "Guam",
"GT" => "Guatemala",
"GG" => "Guernsey",
"GN" => "Guinea",
"GW" => "Guinea-Bissau",
"GY" => "Guyana",
"HT" => "Haiti",
"VA" => "Holy See",
"HN" => "Honduras",
"HK" => "Hong Kong",
"HU" => "Hungary",
"IS" => "Iceland",
"IN" => "India",
"ID" => "Indonesia",
"IR" => "Iran, Islamic Republic of",
"IQ" => "Iraq",
"IE" => "Ireland",
"IM" => "Isle of Man",
"IL" => "Israel",
"IT" => "Italy",
"JM" => "Jamaica",
"JP" => "Japan",
"JE" => "Jersey",
"JO" => "Jordan",
"KZ" => "Kazakhstan",
"KE" => "Kenya",
"KI" => "Kiribati",
"KP" => "Korea, Democratic People's Republic of",
"KR" => "Korea, Republic of",
"KW" => "Kuwait",
"KG" => "Kyrgyzstan",
"LA" => "Lao People's Democratic Republic",
"LV" => "Latvia",
"LB" => "Lebanon",
"LS" => "Lesotho",
"LR" => "Liberia",
"LY" => "Libya",
"LI" => "Liechtenstein",
"LT" => "Lithuania",
"LU" => "Luxembourg",
"MO" => "Macao",
"MK" => "Macedonia, The Former Yugoslav Republic of",
"MG" => "Madagascar",
"MW" => "Malawi",
"MY" => "Malaysia",
"MV" => "Maldives",
"ML" => "Mali",
"MT" => "Malta",
"MH" => "Marshall Islands",
"MQ" => "Martinique",
"MR" => "Mauritania",
"MU" => "Mauritius",
"YT" => "Mayotte",
"MX" => "Mexico",
"FM" => "Micronesia, Federated States of",
"MD" => "Moldova, Republic of",
"MC" => "Monaco",
"MN" => "Mongolia",
"ME" => "Montenegro",
"MS" => "Montserrat",
"MA" => "Morocco",
"MZ" => "Mozambique",
"MM" => "Myanmar",
"NA" => "Namibia",
"NR" => "Nauru",
"NP" => "Nepal",
"NL" => "Netherlands",
"NC" => "New Caledonia",
"NZ" => "New Zealand",
"NI" => "Nicaragua",
"NE" => "Niger",
"NG" => "Nigeria",
"NU" => "Niue",
"NF" => "Norfolk Island",
"MP" => "Northern Mariana Islands",
"NO" => "Norway",
"OM" => "Oman",
"PK" => "Pakistan",
"PW" => "Palau",
"PS" => "Palestine, State of",
"PA" => "Panama",
"PG" => "Papua New Guinea",
"PY" => "Paraguay",
"PE" => "Peru",
"PH" => "Philippines",
"PN" => "Pitcairn",
"PL" => "Poland",
"PT" => "Portugal",
"PR" => "Puerto Rico",
"QA" => "Qatar",
"RE" => "Reunion",
"RO" => "Romania",
"RU" => "Russian Federation",
"RW" => "Rwanda",
"BL" => "Saint Barthelemy",
"KN" => "Saint Kitts and Nevis",
"LC" => "Saint Lucia",
"MF" => "Saint Martin (French Part)",
"PM" => "Saint Pierre and Miquelon",
"VC" => "Saint Vincent and The Grenadines",
"WS" => "Samoa",
"SM" => "San Marino",
"ST" => "Sao Tome and Principe",
"SA" => "Saudi Arabia",
"SN" => "Senegal",
"RS" => "Serbia",
"SC" => "Seychelles",
"SL" => "Sierra Leone",
"SG" => "Singapore",
"SX" => "Sint Maarten (Dutch Part)",
"SK" => "Slovakia",
"SI" => "Slovenia",
"SB" => "Solomon Islands",
"SO" => "Somalia",
"ZA" => "South Africa",
"GS" => "South Georgia and The South Sandwich Islands",
"SS" => "South Sudan",
"ES" => "Spain",
"LK" => "Sri Lanka",
"SD" => "Sudan",
"SR" => "Suriname",
"SJ" => "Svalbard and Jan Mayen",
"SZ" => "Swaziland",
"SE" => "Sweden",
"CH" => "Switzerland",
"SY" => "Syrian Arab Republic",
"TW" => "Taiwan, Province of China",
"TJ" => "Tajikistan",
"TZ" => "Tanzania, United Republic of",
"TH" => "Thailand",
"TL" => "Timor-Leste",
"TG" => "Togo",
"TK" => "Tokelau",
"TO" => "Tonga",
"TT" => "Trinidad and Tobago",
"TN" => "Tunisia",
"TR" => "Turkey",
"TM" => "Turkmenistan",
"TC" => "Turks and Caicos Islands",
"TV" => "Tuvalu",
"UG" => "Uganda",
"UA" => "Ukraine",
"AE" => "United Arab Emirates",
"GB" => "United Kingdom",
"US" => "United States",
"UM" => "United States Minor Outlying Islands",
"UY" => "Uruguay",
"UZ" => "Uzbekistan",
"VU" => "Vanuatu",
"VE" => "Venezuela, Bolivarian Republic of",
"VN" => "Viet Nam",
"VG" => "Virgin Islands, British",
"VI" => "Virgin Islands, U.S.",
"WF" => "Wallis and Futuna",
"YE" => "Yemen",
"ZM" => "Zambia",
"ZW" => "Zimbabwe",
);
+172
View File
@@ -0,0 +1,172 @@
<?php
require_once(dirname(__DIR__) . "/datatable/countries.php");
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");
session_start();
$reasons = array(
"blank_referrer" => "过滤无来源的访问",
"blacklisted_ptr" => "过滤黑名单主机名的访问者",
"proxy" => " 过滤代理和VPN",
"filter_isps" => "过滤不常见的服务提供商",
"switched_browsers" => "过滤多少分钟内切换浏览器",
"invalid_google_click_id" => "必须是有效的googleID",
"non_touch_device" => "过滤非接触设备",
"spoofed_browser" => "过滤浏览器欺骗设备",
"sticky_filtering" => "启用粘贴过滤",
"whitelisted_browser_ids" => "可访问的用户ID",
"blacklisted_browser_ids" => "不可访问的用户ID",
"whitelisted_urlrules" => "白名单链接参数",
"blacklisted_urlrules" => "黑名单链接参数",
"device_desktop" => "过滤电脑访问",
"device_mobile" => "过滤手机的访问",
"device_tablet" => "过滤平板的访问",
"device_no_accel" => "过滤没有加速度计/陀螺仪的设备",
"device_headless_browser" => "过滤没有浏览器头的访问",
"isp_type" => "过滤指定的ISP类型",
"browser_time_zone" => "可以访问的浏览器时区",
"whitelisted_language_codes" => "允许访问的浏览器语言",
"blacklisted_language_codes" => "不允许访问的浏览器语言",
"agent" => "代理商列表",
"ip_lists" => "IP列表",
"referrer" => "来源用户列表",
"org" => "组织机构列表",
"deadbolt" => "是否限制访问",
"global_db" => "全球IP数据库",
"org_isp" => "组织或者ISP",
"cross_campaign_ip_visits" => "每个IP最多可访问多少个",
"too_many_ip_visits" => "每个IP最多可访问多少次",
"too_many_browser_visits" => "每个浏览器最多可访问多少次",
"whitelisted_safe_page_url" => "仅允许页面地址包含",
"blacklisted_safe_page_url" => "过滤页面地址包含",
"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
if ($conn->connect_error) {
$error = "Connection failed: " . $conn->connect_error;
$handle = fopen(dirname(__FILE__) . "/err.txt", "a+");
fwrite($handle, date("Y-m-d H:i:s") . ' | ' . $error . "\n");
fclose($handle);
$jsonResult["code"] = 1;
$jsonResult["msg"] = $error;
$jsonResult["count"] = 0;
$jsonResult["data"] = array();
} else {
VisitorLogSchema::ensureColumns($conn);
if(isset($_GET['clear']) && $_GET['clear'] == "true") { //清除日志数据表
$sql = "TRUNCATE `visitor_logs`";
// 执行查询并输出结果
$result = mysqli_query($conn, $sql);
$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;
// 计算起始位置
$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 .= 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`, `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'] ?? '');
$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["data"] = $jsonData;
}
}
// 关闭数据库连接
mysqli_close($conn);
header('Content-Type: application/json');
echo json_encode($jsonResult);exit;
+3
View File
@@ -0,0 +1,3 @@
2023-12-31 18:29:49 | Connection failed: Access denied for user 'root'@'localhost' (using password: YES)
2023-12-31 18:31:01 | Connection failed: Access denied for user 'root'@'localhost' (using password: YES)
2023-12-31 18:31:10 | Connection failed: Access denied for user 'root'@'localhost' (using password: YES)
+127
View File
@@ -0,0 +1,127 @@
<?php
set_time_limit(0);
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="export_'.date("Ymd").'.csv"');
require_once(dirname(__DIR__) . "/datatable/countries.php");
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");
session_start();
if(empty($_SESSION['password']) || $_SESSION['password'] != LOGIN_PASSWORD) {
unset($_SESSION['password']);
unset($_SESSION['check_result']);
die("404 Not Found");
}
$reasons = array(
"blank_referrer" => "过滤无来源的访问",
"blacklisted_ptr" => "过滤黑名单主机名的访问者",
"proxy" => " 过滤代理和VPN",
"filter_isps" => "过滤不常见的服务提供商",
"switched_browsers" => "过滤多少分钟内切换浏览器",
"invalid_google_click_id" => "必须是有效的googleID",
"non_touch_device" => "过滤非接触设备",
"spoofed_browser" => "过滤浏览器欺骗设备",
"sticky_filtering" => "启用粘贴过滤",
"whitelisted_browser_ids" => "可访问的用户ID",
"blacklisted_browser_ids" => "不可访问的用户ID",
"whitelisted_urlrules" => "白名单链接参数",
"blacklisted_urlrules" => "黑名单链接参数",
"device_desktop" => "过滤电脑访问",
"device_mobile" => "过滤手机的访问",
"device_tablet" => "过滤平板的访问",
"device_no_accel" => "过滤没有加速度计/陀螺仪的设备",
"device_headless_browser" => "过滤没有浏览器头的访问",
"isp_type" => "过滤指定的ISP类型",
"browser_time_zone" => "可以访问的浏览器时区",
"whitelisted_language_codes" => "允许访问的浏览器语言",
"blacklisted_language_codes" => "不允许访问的浏览器语言",
"agent" => "代理商列表",
"ip_lists" => "IP列表",
"referrer" => "来源用户列表",
"org" => "组织机构列表",
"deadbolt" => "是否限制访问",
"global_db" => "全球IP数据库",
"org_isp" => "组织或者ISP",
"cross_campaign_ip_visits" => "每个IP最多可访问多少个",
"too_many_ip_visits" => "每个IP最多可访问多少次",
"too_many_browser_visits" => "每个浏览器最多可访问多少次",
"whitelisted_safe_page_url" => "仅允许页面地址包含",
"blacklisted_safe_page_url" => "过滤页面地址包含",
"time_of_day" => "不可访问的日期",
);
$servername = "localhost";
$username = DB_USERNAME;
$password = DB_PASSWORD;
$dbname = DB_NAME;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
$error = "Connection failed: " . $conn->connect_error;
$handle = fopen(dirname(__FILE__) . "/err.txt", "a+");
fwrite($handle, date("Y-m-d H:i:s") . ' | ' . $error . "\n");
fclose($handle);
echo "数据库连接失败";exit;
} else {
VisitorLogSchema::ensureColumns($conn);
$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 .= 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`, `device`, `add_time` FROM `visitor_logs` WHERE {$where} ORDER BY `id` DESC";
// 执行查询并输出结果
$result = mysqli_query($conn, $sql);
echo "\xEF\xBB\xBF";
$fp = fopen('php://output', 'w');
while ($row = mysqli_fetch_assoc($result)) {
$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'] ?? '');
fputcsv($fp, $row);
}
fclose($fp);
exit("");
}
+36
View File
@@ -0,0 +1,36 @@
<?php
require_once dirname(__DIR__) . '/cong.php';
require_once dirname(__DIR__) . '/lib/DbHelper.php';
require_once dirname(__DIR__) . '/lib/Cloak/VisitorLogAnalytics.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(['code' => 1, 'msg' => '未授权', 'data' => null], JSON_UNESCAPED_UNICODE);
exit;
}
$conn = new mysqli('localhost', DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($conn->connect_error) {
echo json_encode(['code' => 1, 'msg' => '数据库连接失败', 'data' => null], JSON_UNESCAPED_UNICODE);
exit;
}
$filters = [
'date_from' => $_GET['date_from'] ?? '',
'date_to' => $_GET['date_to'] ?? '',
'domain' => $_GET['domain'] ?? '',
'campagin_id' => $_GET['campagin_id'] ?? '',
];
$data = VisitorLogAnalytics::buildReport($conn, $filters);
$conn->close();
echo json_encode([
'code' => 0,
'msg' => 'success',
'data' => $data,
], JSON_UNESCAPED_UNICODE);
+162
View File
@@ -0,0 +1,162 @@
<?php
require_once(dirname(__DIR__) . "/datatable/countries.php");
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");
$reasons = array(
"blank_referrer" => "过滤无来源的访问",
"blacklisted_ptr" => "过滤黑名单主机名的访问者",
"proxy" => " 过滤代理和VPN",
"filter_isps" => "过滤不常见的服务提供商",
"switched_browsers" => "过滤多少分钟内切换浏览器",
"invalid_google_click_id" => "必须是有效的googleID",
"non_touch_device" => "过滤非接触设备",
"spoofed_browser" => "过滤浏览器欺骗设备",
"sticky_filtering" => "启用粘贴过滤",
"whitelisted_browser_ids" => "可访问的用户ID",
"blacklisted_browser_ids" => "不可访问的用户ID",
"whitelisted_urlrules" => "白名单链接参数",
"blacklisted_urlrules" => "黑名单链接参数",
"device_desktop" => "过滤电脑访问",
"device_mobile" => "过滤手机的访问",
"device_tablet" => "过滤平板的访问",
"device_no_accel" => "过滤没有加速度计/陀螺仪的设备",
"device_headless_browser" => "过滤没有浏览器头的访问",
"isp_type" => "过滤指定的ISP类型",
"browser_time_zone" => "可以访问的浏览器时区",
"whitelisted_language_codes" => "允许访问的浏览器语言",
"blacklisted_language_codes" => "不允许访问的浏览器语言",
"agent" => "代理商列表",
"ip_lists" => "IP列表",
"referrer" => "来源用户列表",
"org" => "组织机构列表",
"deadbolt" => "是否限制访问",
"global_db" => "全球IP数据库",
"org_isp" => "组织或者ISP",
"cross_campaign_ip_visits" => "每个IP最多可访问多少个",
"too_many_ip_visits" => "每个IP最多可访问多少次",
"too_many_browser_visits" => "每个浏览器最多可访问多少次",
"whitelisted_safe_page_url" => "仅允许页面地址包含",
"blacklisted_safe_page_url" => "过滤页面地址包含",
"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
if ($conn->connect_error) {
$error = "Connection failed: " . $conn->connect_error;
$handle = fopen(dirname(__FILE__) . "/err.txt", "a+");
fwrite($handle, date("Y-m-d H:i:s") . ' | ' . $error . "\n");
fclose($handle);
$jsonResult["code"] = 1;
$jsonResult["msg"] = $error;
$jsonResult["count"] = 0;
$jsonResult["data"] = array();
} else {
VisitorLogSchema::ensureColumns($conn);
if(isset($_GET['clear']) && $_GET['clear'] == "true") { //清除日志数据表
$sql = "TRUNCATE `visitor_logs`";
// 执行查询并输出结果
$result = mysqli_query($conn, $sql);
$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;
// 计算起始位置
$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 .= 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`, `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'] ?? '');
$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["data"] = $jsonData;
}
}
// 关闭数据库连接
mysqli_close($conn);
header('Content-Type: application/json');
echo json_encode($jsonResult);exit;