修复判断入口文件ip_check.php以及新增复制配置选项
This commit is contained in:
+41
-5
@@ -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
|
||||
</td>
|
||||
<td>
|
||||
<div class="action-btn-group">
|
||||
<a href="<?php echo $current_name . '?action=edit_config&name=' . $pf; ?>" class="btn btn-sm btn-outline-primary">编辑</a>
|
||||
<a href="<?php echo $current_name . '?action=edit_config&name=' . urlencode($pf); ?>" class="btn btn-sm btn-outline-primary">编辑</a>
|
||||
<a href="<?php echo $current_name . '?action=edit_config&name=new_config&copy_from=' . urlencode($pf); ?>" class="btn btn-sm btn-outline-info">复制</a>
|
||||
<a href="/<?php echo $pf; ?>.php" target="_blank" class="btn btn-sm btn-outline-secondary">查看</a>
|
||||
<?php if ($pf !== 'index'): ?>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="if(confirm('确定删除配置「<?php echo htmlspecialchars($pf); ?>」?')) location='<?php echo $current_name . '?action=delete_config&name=' . $pf; ?>'">删除</button>
|
||||
@@ -776,7 +812,7 @@ $_d = function($name, $default) { return defined($name) ? constant($name) : $def
|
||||
|
||||
<div class="card shadow-sm" style="border-radius:8px;overflow:hidden;">
|
||||
<div class="card-header-custom">
|
||||
<h5><?php echo $isNewConfigDraft ? '新增配置' : '编辑配置'; ?>:<?php echo htmlspecialchars($check_name); ?><?php if ($isNewConfigDraft): ?> <span class="badge badge-warning" style="font-size:.75rem;vertical-align:middle;">未保存</span><?php endif; ?></h5>
|
||||
<h5><?php echo $isNewConfigDraft ? '新增配置' : '编辑配置'; ?>:<?php echo htmlspecialchars($check_name); ?><?php if ($isNewConfigDraft): ?> <span class="badge badge-warning" style="font-size:.75rem;vertical-align:middle;">未保存</span><?php endif; ?><?php if ($isNewConfigDraft && $configCopySource !== ''): ?> <span class="badge badge-info" style="font-size:.75rem;vertical-align:middle;">从 <?php echo htmlspecialchars($configCopySource); ?> 复制</span><?php endif; ?></h5>
|
||||
<div>
|
||||
<?php if (empty($_SESSION["check_result"]) || $_SESSION["check_result"] != "true"): ?>
|
||||
<a href="<?php echo $current_name; ?>?action=setuvi&res=true&name=<?php echo $check_name; ?>" class="btn btn-sm btn-outline-success mr-1">设置当前浏览器为真实访客</a>
|
||||
@@ -802,7 +838,7 @@ $_d = function($name, $default) { return defined($name) ? constant($name) : $def
|
||||
<td class="form-label-cell"><strong>配置名称</strong></td>
|
||||
<td class="form-val-cell">
|
||||
<input type="text" name="check_name" class="form-control form-control-sm" value="<?php echo htmlspecialchars($check_name); ?>" style="max-width:300px;">
|
||||
<small class="text-muted">示例:f123、d258</small>
|
||||
<small class="text-muted"><?php echo ($isNewConfigDraft && $configCopySource !== '') ? '已按「' . htmlspecialchars($configCopySource) . '」预填,请确认配置名称后保存' : '示例:f123、d258'; ?></small>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user