getHashBot(); if (!empty($_GET['hash'])) { $t = $_GET; unset($t['hash']); ksort($t); foreach ($t as $k => $v) { $s[] = "$k=$v"; } $s = implode("\n", $s); $sk = hash_hmac('sha256', $c['key'], "WebAppData", true); $webapp = hash_hmac('sha256', $s, $sk) == $_GET['hash']; } switch (true) { // tlgrm case 'POST' == $_SERVER['REQUEST_METHOD'] && preg_match('~^/tlgrm~', $_SERVER['REQUEST_URI']) && $_GET['k'] == $c['key']: $bot->input(); break; // save template case preg_match('~^' . preg_quote("/webapp$hash/save") . '~', $_SERVER['REQUEST_URI']) && $webapp && !empty($_POST['json']): echo json_encode($bot->saveTemplate($_POST['name'], $_POST['type'], $_POST['json'])); break; // adguard cookie case preg_match('~^' . preg_quote("/webapp$hash/check") . '~', $_SERVER['REQUEST_URI']) && $webapp: setcookie('c', $hash, 0, '/'); echo "/adguard$hash/"; break; case preg_match('~^' . preg_quote("/pac$hash/sub") . '~', $_SERVER['REQUEST_URI']) && file_exists(__DIR__ . '/subscription.php'): $bot->sub(); exit; // subs & pac case preg_match('~^' . preg_quote("/pac$hash") . '~', $_SERVER['REQUEST_URI']): if (!empty($t = unserialize(base64_decode(explode('/', $_SERVER['REQUEST_URI'])[2])))) { // fix sing-box import $_GET = array_merge($_GET, $t); } $type = $_GET['t'] ?? 'pac'; $address = $_GET['a'] ?: '127.0.0.1'; $port = $_GET['p'] ?: '1080'; switch ($type) { case 's': case 'si': case 'cl': $bot->subscription(); exit; case 'te': if (!empty($_GET['te'])) { $t = $bot->getPacConf()["{$_GET['ty']}templates"][$_GET['te']]; } else { $t = json_decode(file_get_contents("/config/{$_GET['ty']}.json"), true); } if ($t) { header('Content-Type: text/html'); $t = json_encode($t, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $name = $_GET['te'] ?: 'origin'; $type = $_GET['ty']; echo <<
HTML; exit; } default: if (file_exists($file = __DIR__ . "/zapretlists/$type")) { $pac = file_get_contents($file); header('Content-Type: text/plain'); echo str_replace([ '~address~', '~port~', ], [ $address, $port, ], $pac); exit; } break; } break; default: header('500', true, 500); }