Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php <!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>VLESS به JSON</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="bg-gray-100 flex justify-center items-center min-h-screen font-sans"> <div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-3xl"> <h1 class="text-2xl font-bold mb-4 text-center">تبدیل VLESS به JSON</h1> <!-- ورودی URLها --> <form method="post" action=""> <div class="mb-4"> <label for="vlessUrls" class="block text-sm font-medium text-gray-700">URLهای VLESS (هر URL در یک خط):</label> <textarea id="vlessUrls" name="vlessUrls" rows="5" placeholder="vless://...\nvless://..." class="mt-1 p-2 w-full border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"><?php echo isset($_POST['vlessUrls']) ? htmlspecialchars($_POST['vlessUrls']) : ''; ?></textarea> </div> <!-- دکمه تبدیل --> <button type="submit" class="w-full bg-blue-500 text-white p-2 rounded-md hover:bg-blue-600 mb-4"> تبدیل به JSON </button> </form> <!-- خروجی JSON --> <div class="mb-4"> <label for="jsonOutput" class="block text-sm font-medium text-gray-700">خروجی JSON:</label> <textarea id="jsonOutput" rows="10" readonly class="mt-1 p-2 w-full border rounded-md bg-gray-50"><?php if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['vlessUrls'])) { function parseVlessToJson($vlessUrls) { $urls = array_filter(array_map('trim', explode("\n", $vlessUrls)), function($url) { return strpos($url, 'vless://') === 0; }); if (empty($urls)) { throw new Exception('هیچ URL VLESS معتبری وارد نشده است.'); } $config = [ 'api' => [ 'services' => ['HandlerService', 'LoggerService', 'StatsService'], 'tag' => 'api' ], 'inbounds' => [ [ 'listen' => '127.0.0.1', 'port' => 62789, 'protocol' => 'dokodemo-door', 'settings' => ['address' => '127.0.0.1'], 'tag' => 'api' ] ], 'log' => [ 'access' => 'none', 'dnsLog' => false, 'error' => '', 'loglevel' => 'warning', 'maskAddress' => '' ], 'outbounds' => [ [ 'protocol' => 'freedom', 'settings' => ['domainStrategy' => 'AsIs', 'noises' => [], 'redirect' => ''], 'tag' => 'direct' ], [ 'protocol' => 'blackhole', 'settings' => [], 'tag' => 'blocked' ] ], 'policy' => [ 'levels' => [ '0' => ['statsUserDownlink' => true, 'statsUserUplink' => true] ], 'system' => [ 'statsInboundDownlink' => true, 'statsInboundUplink' => true, 'statsOutboundDownlink' => true, 'statsOutboundUplink' => true ] ], 'routing' => [ 'domainStrategy' => 'AsIs', 'rules' => [ ['inboundTag' => ['api'], 'outboundTag' => 'api', 'type' => 'field'], ['ip' => ['geoip:private'], 'outboundTag' => 'blocked', 'type' => 'field'], ['outboundTag' => 'blocked', 'protocol' => ['bittorrent'], 'type' => 'field'] ] ], 'stats' => [] ]; foreach ($urls as $index => $vlessUrl) { try { $url = parse_url(str_replace('vless://', 'http://', $vlessUrl)); if ($url === false) { continue; } $uuid = isset($url['user']) ? $url['user'] : ''; $host = isset($url['host']) ? $url['host'] : ''; $port = isset($url['port']) ? (int)$url['port'] : 8880; parse_str(isset($url['query']) ? $url['query'] : '', $query); $encryption = isset($query['encryption']) ? $query['encryption'] : 'none'; $security = isset($query['security']) ? $query['security'] : ''; $network = isset($query['type']) ? $query['type'] : 'grpc'; $tag = (string)($index + 1); $config['outbounds'][] = [ 'tag' => $tag, 'protocol' => 'vless', 'settings' => [ 'vnext' => [ [ 'address' => $host, 'port' => $port, 'users' => [ [ 'id' => $uuid, 'flow' => '', 'encryption' => $encryption ] ] ] ] ], 'streamSettings' => [ 'network' => $network, 'security' => $security, 'grpcSettings' => [ 'serviceName' => '', 'authority' => '', 'multiMode' => false ] ] ]; $config['routing']['rules'][] = [ 'type' => 'field', 'user' => [$tag], 'inboundTag' => ['inbound-8080'], 'outboundTag' => $tag ]; } catch (Exception $e) { error_log("خطا در پردازش URL $vlessUrl: " . $e->getMessage()); } } return $config; } try { $jsonConfig = parseVlessToJson($_POST['vlessUrls']); echo json_encode($jsonConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } catch (Exception $e) { echo ''; } } ?></textarea> </div> <!-- دکمه کپی --> <button onclick="copyJson()" class="w-full bg-green-500 text-white p-2 rounded-md hover:bg-green-600"> کپی JSON </button> </div> <script> function copyJson() { const jsonOutput = document.getElementById('jsonOutput'); if (!jsonOutput.value) { alert('ابتدا JSON را تولید کنید.'); return; } navigator.clipboard.writeText(jsonOutput.value) .then(() => alert('JSON با موفقیت کپی شد!')) .catch(() => alert('خطا در کپی کردن JSON. لطفاً به صورت دستی کپی کنید.')); } </script> </body> </html>
Copy Clear