/dev/null'); $updatedCrons = preg_replace( "/^.*" . preg_quote($shellScriptPath, '/') . ".*$/m", '', $currentCrons ); $updatedCrons = trim($updatedCrons) . "\n" . $cronJob . "\n"; $tempCronFile = tempnam(sys_get_temp_dir(), 'cron'); file_put_contents($tempCronFile, $updatedCrons); exec("crontab $tempCronFile"); unlink($tempCronFile); $timestamp = date('[ H:i:s ]'); file_put_contents($logFile, "$timestamp 定时任务已设置成功,Sing-box 将在 $cronExpression 自动更新。\n", FILE_APPEND); echo "
定时任务已设置: $cronExpression
"; } else { $timestamp = date('[ H:i:s ]'); file_put_contents($logFile, "$timestamp 无效的 Cron 表达式: $cronExpression\n", FILE_APPEND); echo "
无效的 Cron 表达式,请检查格式。
"; } } ?> 订阅链接不能为空。"; exit; } echo "
提交成功: 订阅链接已保存为 $SUBSCRIBE_URL
"; } if (isset($_POST['createShellScript'])) { $shellScriptContent = <<> "\$LOG_FILE" exit 1 fi echo "\$(date '+[ %H:%M:%S ]') 使用的订阅链接: \$SUBSCRIBE_URL" >> "\$LOG_FILE" CONFIG_DIR="/etc/neko/config" if [ ! -d "\$CONFIG_DIR" ]; then mkdir -p "\$CONFIG_DIR" if [ \$? -ne 0 ]; then echo "\$(date '+[ %H:%M:%S ]') 无法创建配置目录: \$CONFIG_DIR" >> "\$LOG_FILE" exit 1 fi fi CONFIG_FILE="\$CONFIG_DIR/sing-box.json" wget -q -O "\$CONFIG_FILE" "\$SUBSCRIBE_URL" >/dev/null 2>&1 if [ \$? -eq 0 ]; then echo "\$(date '+[ %H:%M:%S ]') Sing-box 配置文件更新成功,保存路径: \$CONFIG_FILE" >> "\$LOG_FILE" sed -i 's/"Proxy"/"DIRECT"/g' "\$CONFIG_FILE" if [ \$? -eq 0 ]; then echo "\$(date '+[ %H:%M:%S ]') 配置文件中的 Proxy 已成功替换为 DIRECT。" >> "\$LOG_FILE" else echo "\$(date '+[ %H:%M:%S ]') 替换 Proxy 为 DIRECT 失败,请检查配置文件。" >> "\$LOG_FILE" exit 1 fi else echo "\$(date '+[ %H:%M:%S ]') 配置文件更新失败,请检查链接或网络。" >> "\$LOG_FILE" exit 1 fi EOL; if (file_put_contents($shellScriptPath, $shellScriptContent) !== false) { chmod($shellScriptPath, 0755); echo "
Shell 脚本已创建成功!路径: $shellScriptPath
"; } else { echo "
无法创建 Shell 脚本,请检查权限。
"; } } } ?> singbox - Nekobox
Home Manager Template I Template II Template III

Sing-box Conversion Template One

Help Information

  • Template 1: No Region, No Groups.
  • Template 2: No Region, With Routing Rules.
  • Template 3: Hong Kong, Taiwan, Singapore, Japan, USA, South Korea, With Routing Rules.
  • Template 4: Same As Above, Multiple Rules.
Choose Template
10) { array_shift($logEntries); } file_put_contents($dataFilePath, implode("\n\n", $logEntries) . "\n\n"); $subscribeUrlEncoded = urlencode($subscribeUrl); if (isset($_POST['defaultTemplate']) && $_POST['defaultTemplate'] == '0') { $templateUrlEncoded = ''; } elseif ($templateOption === 'custom' && !empty($customTemplateUrl)) { $templateUrlEncoded = urlencode($customTemplateUrl); } else { $defaultTemplates = [ '1' => "https://raw.githubusercontent.com/Thaolga/Rules/main/Clash/json/config_7.json", '2' => "https://raw.githubusercontent.com/Thaolga/Rules/main/Clash/json/config_6.json", '3' => "https://raw.githubusercontent.com/Thaolga/Rules/main/Clash/json/config_8.json", '4' => "https://raw.githubusercontent.com/Thaolga/Rules/main/Clash/json/config_12.json", '5' => "https://raw.githubusercontent.com/Thaolga/Rules/main/Clash/json/config_2.json" ]; $templateUrlEncoded = urlencode($defaultTemplates[$_POST['defaultTemplate']] ?? ''); } if (empty($templateUrlEncoded)) { $completeSubscribeUrl = "https://sing-box-subscribe-doraemon.vercel.app/config/{$subscribeUrlEncoded}"; } else { $completeSubscribeUrl = "https://sing-box-subscribe-doraemon.vercel.app/config/{$subscribeUrlEncoded}&file={$templateUrlEncoded}"; } $tempFilePath = '/etc/neko/' . $customFileName; $logMessages = []; $command = "wget -O " . escapeshellarg($tempFilePath) . " " . escapeshellarg($completeSubscribeUrl); exec($command, $output, $returnVar); if ($returnVar !== 0) { $command = "curl -s -L -o " . escapeshellarg($tempFilePath) . " " . escapeshellarg($completeSubscribeUrl); exec($command, $output, $returnVar); if ($returnVar !== 0) { $logMessages[] = "无法下载内容: " . htmlspecialchars($completeSubscribeUrl); } } if ($returnVar === 0) { $downloadedContent = file_get_contents($tempFilePath); if ($downloadedContent === false) { $logMessages[] = "无法读取下载的文件内容"; } else { $downloadedContent = preg_replace_callback( '/\{\s*"tag":\s*"(.*?)",\s*"type":\s*"selector",\s*"outbounds":\s*\[\s*"Proxy"\s*\]\s*\}/s', function ($matches) { return str_replace('"Proxy"', '"DIRECT"', $matches[0]); }, $downloadedContent ); if (isset($_POST['defaultTemplate']) && $_POST['defaultTemplate'] == '0') { $replacement = ' "clash_api": { "external_ui": "/etc/neko/ui/", "external_controller": "0.0.0.0:9090", "secret": "Akun", "external_ui_download_url": "" },'; $downloadedContent = preg_replace('/"clash_api":\s*\{.*?\},/s', $replacement, $downloadedContent); } $tmpFileSavePath = '/etc/neko/proxy_provider/' . $fixedFileName; if (file_put_contents($tmpFileSavePath, $completeSubscribeUrl) === false) { $logMessages[] = $translations['save_subscribe_url_failed'] . $tmpFileSavePath; } else { $logMessages[] = $translations['subscribe_url_saved'] . $tmpFileSavePath; } $configFilePath = '/etc/neko/config/' . $customFileName; if (file_put_contents($configFilePath, $downloadedContent) === false) { $logMessages[] = $translations['save_config_failed'] . $configFilePath; } else { $logMessages[] = $translations['config_saved'] . $configFilePath; } if (file_exists($tempFilePath)) { unlink($tempFilePath); $logMessages[] = $translations['temp_file_cleaned'] . $tempFilePath; } else { $logMessages[] = $translations['temp_file_not_found'] . $tempFilePath; } } } echo "
"; echo "
"; echo "
"; echo ""; echo "
"; echo "
"; echo ""; echo ""; echo ""; echo "
"; echo "
"; echo "
"; echo "
"; foreach ($logMessages as $message) { echo $message . "
"; } echo "
"; } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['saveContent'])) { if (isset($_POST['configContent'])) { $editedContent = trim($_POST['configContent']); if (file_put_contents($configFilePath, $editedContent) === false) { echo "
" . $translations['error_save_content'] . htmlspecialchars($configFilePath) . "
"; } else { echo "
" . $translations['success_save_content'] . htmlspecialchars($configFilePath) . "
"; } } } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['clearData'])) { if (file_exists($dataFilePath)) { file_put_contents($dataFilePath, ''); echo "
" . $translations['save_data_cleared'] . "
"; } } if (file_exists($dataFilePath)) { $savedData = file_get_contents($dataFilePath); echo "
"; echo "
"; echo "

" . $translations['data_saved'] . "

"; echo "
" . htmlspecialchars($savedData) . "
"; echo "
"; echo ''; echo "
"; echo "
"; echo "
"; } ?>