window.location='{$current_name}';"); exit(); } // 重置临时链接参数 if (!empty($_REQUEST["action"]) && $_REQUEST["action"] == "delUrlArgs") { $check_name = strip_tags($_REQUEST['check_name']); $dir = dirname(__FILE__) . '/args'; $files = glob($dir . '/' . $check_name . "_*.txt"); foreach ($files as $file) { if (preg_match('/_(\d{10})\.txt$/', $file, $m)) { unlink($file); } } header('Location: ' . $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?action=edit_config&name=' . urlencode($check_name)); exit; } // 确定当前配置上下文(供表单回显用) if (!empty($_REQUEST["name"])) { $check_name = trim($_REQUEST["name"]); $config_name = str_replace(".php", "", $check_name); $config_file = "check_config/" . $config_name . "_config.php"; if (!file_exists($config_file)) { copy("check_config/index_config.php", $config_file); } } else { $check_name = "index"; $config_file = "check_config/index_config.php"; } include($config_file); // 密码处理 if (!empty($_REQUEST['password'])) { $_SESSION['password'] = $_REQUEST['password']; $_SESSION["myaction"] = $_REQUEST['myaction']; } // 设置测试访问状态(写入完整 Session 判定缓存,便于测试广告落地链接直达真实页) if (!empty($_REQUEST["action"]) && $_REQUEST["action"] == "setuvi") { require_once __DIR__ . '/lib/Cloak/VisitorRepository.php'; if (!empty($_REQUEST["res"]) && $_REQUEST["res"] == "true") { cloak_session_mark_real_visitor(); } if (!empty($_REQUEST["res"]) && $_REQUEST["res"] == "false") { cloak_session_clear_real_visitor(); } echo(""); exit(); } // 保存配置 if (!empty($_REQUEST["action"]) && $_REQUEST["action"] == "submit") { $check_name = trim($_REQUEST["check_name"]); $methods = trim($_REQUEST["methods"]); $country = trim($_REQUEST["country"]); $blacklist_group_id = (int)($_REQUEST["blacklist_group_id"] ?? 0); $whitelist_group_id = (int)($_REQUEST["whitelist_group_id"] ?? 0); try { $pdoDash = new PDO( 'mysql:host=127.0.0.1;dbname=' . DB_NAME . ';charset=utf8mb4', DB_USERNAME, DB_PASSWORD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION] ); $chk = $pdoDash->prepare('SELECT 1 FROM ip_groups WHERE id = ? AND type = ? LIMIT 1'); if ($blacklist_group_id > 0) { $chk->execute([$blacklist_group_id, 'black']); if (!$chk->fetchColumn()) $blacklist_group_id = 0; } if ($whitelist_group_id > 0) { $chk->execute([$whitelist_group_id, 'white']); if (!$chk->fetchColumn()) $whitelist_group_id = 0; } } catch (Throwable $e) { $blacklist_group_id = $whitelist_group_id = 0; } $DB_fp = $_REQUEST["DB_fp"]; $DB_zp = trim($_REQUEST["DB_zp"]); $redirect_method = trim($_REQUEST["redirect_method"]); $show_content = trim($_REQUEST["show_content"]); $costm_ip_score = trim($_REQUEST["costm_ip_score"]); $write_log = trim($_REQUEST["write_log"]); $zh_on = trim($_REQUEST["zh_on"]); $os_on = trim($_REQUEST["os_on"]); $mobile_on = trim($_REQUEST["mobile_on"]); $v_referer = trim($_REQUEST["v_referer"]); $is_virtual = trim($_REQUEST["is_virtual"]); $auto_black = trim($_REQUEST["auto_black"]); $auto_black_times = trim($_REQUEST["auto_black_times"]); $white_params = trim($_REQUEST["white_params"]); $keep_params = trim($_REQUEST["keep_params"]); $iphone_model = $_REQUEST["iphone_model"]; $risk_number = $_REQUEST["risk_number"]; $risk_enhanced = in_array(strtoupper(trim($_REQUEST["risk_enhanced"] ?? '')), ['ON']) ? 'ON' : 'OFF'; $url_args_timeout = $_REQUEST["url_args_timeout"]; $debug_mode = in_array(strtoupper(trim($_REQUEST["debug_mode"] ?? '')), ['ON']) ? 'ON' : 'OFF'; $ad_fb = in_array(strtoupper(trim($_REQUEST["ad_fb"] ?? '')), ['ON']) ? 'ON' : 'OFF'; $ad_google = in_array(strtoupper(trim($_REQUEST["ad_google"] ?? '')), ['ON']) ? 'ON' : 'OFF'; $ad_tiktok = in_array(strtoupper(trim($_REQUEST["ad_tiktok"] ?? '')), ['ON']) ? 'ON' : 'OFF'; $ad_strict = in_array(strtoupper(trim($_REQUEST["ad_strict"] ?? '')), ['ON']) ? 'ON' : 'OFF'; $config_name_submit = str_replace('.php', '', $check_name); $existing_spm_id = ''; $existing_cfg = 'check_config/' . $config_name_submit . '_config.php'; if (file_exists($existing_cfg)) { $existing_raw = file_get_contents($existing_cfg); if (preg_match("/define\('CLOAK_AD_SPM_ID',\s*'([^']*)'\)/", $existing_raw, $spmM)) { $existing_spm_id = $spmM[1]; } } $ad_spm_id = CloakAdSourceGuard::isValidSpmId($existing_spm_id) ? $existing_spm_id : ''; if (($ad_fb === 'ON' || $ad_google === 'ON' || $ad_tiktok === 'ON') && $ad_spm_id === '') { $ad_spm_id = CloakAdSourceGuard::generateSpmId(); } if (strtoupper($auto_black) === 'ON' && $blacklist_group_id <= 0) { echo ""; exit(); } if (!empty($methods)) { ConfigWriter::save($check_name, [ 'methods' => $methods, 'blacklist_group_id' => $blacklist_group_id, 'whitelist_group_id' => $whitelist_group_id, 'country' => $country, 'show_content' => $show_content, 'DB_fp' => $DB_fp, 'costm_ip_score' => $costm_ip_score, 'auto_black' => $auto_black, 'is_virtual' => $is_virtual, 'auto_black_times' => $auto_black_times, 'white_params' => $white_params, 'iphone_model' => $iphone_model, 'write_log' => $write_log, 'zh_on' => $zh_on, 'os_on' => $os_on, 'keep_params' => $keep_params, 'redirect_method' => $redirect_method, 'DB_zp' => $DB_zp, 'mobile_on' => $mobile_on, 'v_referer' => $v_referer, 'risk_number' => $risk_number, 'risk_enhanced' => $risk_enhanced, 'url_args_timeout' => $url_args_timeout, 'debug_mode' => $debug_mode, 'ad_fb' => $ad_fb, 'ad_google' => $ad_google, 'ad_tiktok' => $ad_tiktok, 'ad_strict' => $ad_strict, 'ad_spm_id' => $ad_spm_id, ]); try { $pdoBind = DomainRepository::pdo(); DomainRepository::ensureTable($pdoBind); $siteDomainId = (int) ($_REQUEST['site_domain_id'] ?? 0); if ($siteDomainId > 0) { DomainRepository::bindConfigToDomain($pdoBind, $check_name, $siteDomainId); } else { DomainRepository::clearConfigBinding($pdoBind, $check_name); } } catch (Throwable $e) { } echo(""); exit(); } } function write_file($file_name, $text_str) { $f = fopen($file_name, "w"); rewind($f); fwrite($f, $text_str); fclose($f); } function onoff_radio($name, $val, $label_on='开启', $label_off='关闭') { $on = ($val == 'ON') ? 'active' : ''; $off = ($val != 'ON') ? 'active' : ''; return '
', array_map('htmlspecialchars', $res['nameservers']));
$cloakDomainMsg .= '。请到注册商将 NS 修改为:' . $nsHtml . ',然后点击「检测/刷新」。';
} else {
$cloakDomainMsg .= ',请在编辑配置时关联此域名。';
}
} else {
$cloakDomainErr = $res['error'] ?? '添加失败';
}
} catch (Throwable $e) {
$cloakDomainErr = $e->getMessage();
}
}
if (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'check_domain') {
$domainId = (int) ($_POST['domain_id'] ?? $_REQUEST['domain_id'] ?? 0);
$jsonOut = isset($_REQUEST['format']) && $_REQUEST['format'] === 'json';
try {
$res = DomainProvisioningService::checkAndProvision(DomainRepository::pdo(), $domainId);
if ($jsonOut) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode($res, JSON_UNESCAPED_UNICODE);
exit;
}
if ($res['ok']) {
$cloakDomainMsg = $res['message'] ?? '检测完成';
} else {
$cloakDomainErr = $res['message'] ?? '检测失败';
}
} catch (Throwable $e) {
if ($jsonOut) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['ok' => false, 'message' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
exit;
}
$cloakDomainErr = $e->getMessage();
}
}
if (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'delete_domain' && !empty($_REQUEST['domain_id'])) {
try {
$res = DomainProvisioningService::deleteWithCloudflare(DomainRepository::pdo(), (int) $_REQUEST['domain_id']);
if ($res['ok']) {
$cloakDomainMsg = $res['message'] ?? '域名已删除。';
if (!empty($res['warning'])) {
$cloakDomainErr = $res['warning'];
}
} else {
$cloakDomainErr = $res['message'] ?? '删除失败';
}
} catch (Throwable $e) {
$cloakDomainErr = $e->getMessage();
}
}
// 系统状态检测(列表页用)
function dash_check_mysql() {
try {
$pdo = new PDO('mysql:host=127.0.0.1;dbname=' . DB_NAME . ';charset=utf8mb4', DB_USERNAME, DB_PASSWORD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
return true;
} catch (Throwable $e) { return false; }
}
function dash_check_redis() {
if (!extension_loaded('redis') || strtoupper(REDIS_ENABLED) !== 'ON') return null;
try {
$r = new Redis();
if (!@$r->connect(REDIS_HOST, (int)REDIS_PORT, 0.5)) return false;
$r->ping();
return true;
} catch (Throwable $e) { return false; }
}
function dash_cfg_get($raw, $name)
{
if (preg_match("/define\('" . preg_quote($name, '/') . "',\s*'([^']*)'\)/", $raw, $m)) {
return $m[1];
}
return '';
}
function dash_build_ad_links($pf, $protocol, $host)
{
$path = __DIR__ . "/check_config/{$pf}_config.php";
try {
$pdoDashHost = DomainRepository::pdo();
DomainRepository::ensureTable($pdoDashHost);
$bound = DomainRepository::primaryHostnameForConfig($pdoDashHost, $pf);
if ($bound !== '') {
$host = $bound;
}
} catch (Throwable $e) {
}
$host = DomainRepository::normalizeHostname($host);
if ($host === '') {
$host = DomainRepository::normalizeHostname($_SERVER['HTTP_HOST'] ?? '');
}
$base = rtrim($protocol . $host, '/') . '/' . (($pf != 'index') ? $pf : '');
if (!file_exists($path)) {
return [['label' => '落地链接', 'url' => $base]];
}
$raw = file_get_contents($path);
$enabled = [];
if (dash_cfg_get($raw, 'CLOAK_AD_FB') === 'ON') {
$enabled[] = CloakAdSourceGuard::PLATFORM_FB;
}
if (dash_cfg_get($raw, 'CLOAK_AD_GOOGLE') === 'ON') {
$enabled[] = CloakAdSourceGuard::PLATFORM_GOOGLE;
}
if (dash_cfg_get($raw, 'CLOAK_AD_TIKTOK') === 'ON') {
$enabled[] = CloakAdSourceGuard::PLATFORM_TIKTOK;
}
if (empty($enabled)) {
return [['label' => '落地链接', 'url' => $base]];
}
$spmId = dash_cfg_get($raw, 'CLOAK_AD_SPM_ID');
$query = CloakAdSourceGuard::buildAdLinkQuery($enabled, $spmId);
$url = $base . ($query !== '' ? '?' . $query : '');
return [['label' => '落地链接', 'url' => $url]];
}
// 遍历配置列表
$products_file_ary = [];
$dd = opendir("check_config");
while (false !== ($f = readdir($dd))) {
if ($f == "." || $f == "..") continue;
if (filetype("check_config/$f") == "dir" || $f == "index.php" || $f == "a.txt") continue;
$fname = str_replace("_config.php", "", $f);
$products_file_ary[] = $fname;
if (!file_exists($fname . ".php")) {
copy("tem_link.php", $fname . ".php");
}
}
closedir($dd);
sort($products_file_ary);
// 加载 IP 组(编辑页用)
$blackGroups = $whiteGroups = [];
try {
$pdoDash = new PDO('mysql:host=127.0.0.1;dbname=' . DB_NAME . ';charset=utf8mb4', DB_USERNAME, DB_PASSWORD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]);
$stb = $pdoDash->prepare("SELECT id, name FROM ip_groups WHERE type = 'black' ORDER BY id ASC");
$stb->execute(); $blackGroups = $stb->fetchAll();
$stw = $pdoDash->prepare("SELECT id, name FROM ip_groups WHERE type = 'white' ORDER BY id ASC");
$stw->execute(); $whiteGroups = $stw->fetchAll();
} catch (Throwable $e) {}
$currentBlacklistGroupId = defined('BLACKLIST_GROUP_ID') ? (int)BLACKLIST_GROUP_ID : 0;
$currentWhitelistGroupId = defined('WHITELIST_GROUP_ID') ? (int)WHITELIST_GROUP_ID : 0;
$action = $_REQUEST['action'] ?? '';
$isEdit = in_array($action, ['edit_config', 'submit'], true);
$cloakSiteDomains = [];
$selectedDomainId = 0;
$dashboardDefaultHost = DomainRepository::normalizeHostname($_SERVER['HTTP_HOST'] ?? '');
try {
$pdoDash = $pdoDash ?? DomainRepository::pdo();
DomainRepository::ensureTable($pdoDash);
$cloakSiteDomains = DomainRepository::listAll($pdoDash);
if ($isEdit) {
$selectedDomainId = DomainRepository::domainIdForConfig($pdoDash, $check_name);
}
} catch (Throwable $e) {
$cloakSiteDomains = [];
}
// 视图判断
$_d = function($name, $default) { return defined($name) ? constant($name) : $default; };
?>
配置管理
管理 Cloak 配置、广告落地链接与站点域名
配置名称
绑定域名
广告链接(广告后台填入的链接)
真实页链接(客户到达的链接)
操作
默认
' . htmlspecialchars($pfHost) . '';
} else {
echo '' . htmlspecialchars($dashboardDefaultHost) . '
(默认后台域)';
}
?>
' . dash_truncate_attr($first, 48) . '';
if (is_array($pfp) && count($pfp) > 1) {
echo '+' . (count($pfp)-1) . ' 个链接';
}
} else { ?>
—
站点域名
Cloudflare 已启用:添加域名后将自动创建 Zone 并显示 Nameserver;请到注册商修改 NS 后点击「检测/刷新」。NS 生效后将自动配置 proxied A 记录、Flexible SSL 与 Always HTTPS。
源站仍需在宝塔添加站点并监听 (Flexible:访客↔CF 为 HTTPS,CF↔源站为 HTTP)。
使用前请先在宝塔完成:在宝塔面板 → 网站 → 添加站点(填写下方相同域名)→ 申请并开启 SSL 证书。完成后再在此添加域名并关联配置。
若在 cong.php 配置 Cloudflare API Token 与 Account ID,可自动创建 Zone 并管理 DNS/SSL。
尚未添加域名。未添加时,广告链接将使用当前后台访问域名:
域名
关联配置
Cloudflare Nameserver
操作
' . htmlspecialchars($dom['config_name']) . '';
} else {
echo '未关联';
}
?>
—
← 返回配置列表