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.
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 "
";
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 "
";
}
?>