diff --git a/dashboard.php b/dashboard.php index e240e13..6a8e8d0 100755 --- a/dashboard.php +++ b/dashboard.php @@ -35,14 +35,24 @@ if (!empty($_REQUEST["action"]) && $_REQUEST["action"] == "delUrlArgs") { // 确定当前配置上下文(供表单回显用) $isNewConfigDraft = false; +$configCopySource = ''; +$copyFrom = dash_sanitize_config_name($_REQUEST['copy_from'] ?? ''); 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)) { - // 新建或未保存的配置:仅回显 index 模板,不在此写盘 $isNewConfigDraft = true; - $config_file = "check_config/index_config.php"; + $sourceFile = ($copyFrom !== '') ? "check_config/{$copyFrom}_config.php" : ''; + if ($copyFrom !== '' && is_file($sourceFile)) { + $config_file = $sourceFile; + $configCopySource = $copyFrom; + if ($check_name === 'new_config' || $check_name === '') { + $check_name = dash_suggest_copy_config_name($copyFrom); + } + } else { + $config_file = "check_config/index_config.php"; + } } } else { $check_name = "index"; @@ -435,6 +445,31 @@ function dash_check_redis() { } catch (Throwable $e) { return false; } } +function dash_sanitize_config_name($name) +{ + $name = trim(str_replace('.php', '', (string) $name)); + if ($name === '' || !preg_match('/^[a-zA-Z0-9_-]+$/', $name)) { + return ''; + } + return $name; +} + +function dash_suggest_copy_config_name($source) +{ + $source = dash_sanitize_config_name($source); + if ($source === '') { + return 'new_config'; + } + $base = $source . '_copy'; + $candidate = $base; + $suffix = 2; + while (file_exists(__DIR__ . "/check_config/{$candidate}_config.php")) { + $candidate = $base . $suffix; + $suffix++; + } + return $candidate; +} + function dash_cfg_get($raw, $name) { if (preg_match("/define\('" . preg_quote($name, '/') . "',\s*'([^']*)'\)/", $raw, $m)) { @@ -662,7 +697,8 @@ $_d = function($name, $default) { return defined($name) ? constant($name) : $def
' + escapeHtml(full) + '' + content: '
' + body + '' }); } }); diff --git a/tools/verify_geoip.php b/tools/verify_geoip.php index 609328a..808a738 100644 --- a/tools/verify_geoip.php +++ b/tools/verify_geoip.php @@ -51,6 +51,13 @@ if ($tests['resolver_available']) { if (!$tests['allowlist_us'] || !$tests['allowlist_cn']) { $ok = false; } + + $tests['normalize_iso2'] = CountryCodeNormalizer::toAlpha2('us') === 'US'; + $tests['normalize_name'] = CountryCodeNormalizer::toAlpha2('United States') === 'US'; + $tests['allowlist_name'] = CountryAllowlist::isAllowed('United Kingdom', CountryAllowlist::parse('GB,US')); + if (!$tests['normalize_iso2'] || !$tests['normalize_name'] || !$tests['allowlist_name']) { + $ok = false; + } } echo json_encode([