@@ -16,7 +16,7 @@ |
||
| 16 | 16 | "protocol" => $type, |
| 17 | 17 | "username" => isset($parsedUrl["user"]) ? $parsedUrl["user"] : "", |
| 18 | 18 | "hostname" => isset($parsedUrl["host"]) ? $parsedUrl["host"] : "", |
| 19 | - "port" => isset($parsedUrl["port"]) ? $parsedUrl["port"]: "", |
|
| 19 | + "port" => isset($parsedUrl["port"]) ? $parsedUrl["port"] : "", |
|
| 20 | 20 | "params" => $params, |
| 21 | 21 | "hash" => isset($parsedUrl["fragment"]) ? $parsedUrl["fragment"] : "", |
| 22 | 22 | ]; |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | function getFlags($country_code) |
| 3 | 3 | { |
| 4 | - $flag = mb_convert_encoding( '&#' . ( 127397 + ord( $country_code[0] ) ) . ';', 'UTF-8', 'HTML-ENTITIES'); |
|
| 5 | - $flag .= mb_convert_encoding( '&#' . ( 127397 + ord( $country_code[1] ) ) . ';', 'UTF-8', 'HTML-ENTITIES'); |
|
| 4 | + $flag = mb_convert_encoding('&#' . (127397 + ord($country_code[0])) . ';', 'UTF-8', 'HTML-ENTITIES'); |
|
| 5 | + $flag .= mb_convert_encoding('&#' . (127397 + ord($country_code[1])) . ';', 'UTF-8', 'HTML-ENTITIES'); |
|
| 6 | 6 | return $flag; |
| 7 | 7 | } |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | // Extract the title and image URL using regular expressions |
| 11 | 11 | $title_pattern = '#<meta property="twitter:title" content="(.*?)">#'; |
| 12 | 12 | $image_pattern = '#<meta property="twitter:image" content="(.*?)">#'; |
| 13 | - preg_match($image_pattern, $html , $image_match); |
|
| 14 | - preg_match($title_pattern, $html , $title_match); |
|
| 13 | + preg_match($image_pattern, $html, $image_match); |
|
| 14 | + preg_match($title_pattern, $html, $title_match); |
|
| 15 | 15 | |
| 16 | 16 | // Save the image file to local storage |
| 17 | 17 | file_put_contents("modules/channels/" . $channel . ".jpg", file_get_contents($image_match[1])); |
@@ -23,4 +23,4 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Save the channel data array as JSON |
| 26 | -file_put_contents("modules/channels/channels_assets.json", json_encode($channel_array , JSON_PRETTY_PRINT)); |
|
| 26 | +file_put_contents("modules/channels/channels_assets.json", json_encode($channel_array, JSON_PRETTY_PRINT)); |
|
@@ -30,29 +30,29 @@ discard block |
||
| 30 | 30 | return $a_time > $b_time ? -1 : 1; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | -function point_array($input){ |
|
| 33 | +function point_array($input) { |
|
| 34 | 34 | $usernames = array_column(array_column($input, "channel"), "username"); |
| 35 | 35 | $point_array = array_count_values($usernames); |
| 36 | 36 | return $point_array; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | -function lowest_ping($input){ |
|
| 39 | +function lowest_ping($input) { |
|
| 40 | 40 | return array_reduce($input, function($min, $item) { |
| 41 | 41 | return ($item['ping'] < $min) ? $item['ping'] : $min; |
| 42 | 42 | }, PHP_FLOAT_MAX); |
| 43 | 43 | } |
| 44 | -function time_coefficient($config_time){ |
|
| 44 | +function time_coefficient($config_time) { |
|
| 45 | 45 | $time_diff = strtotime(tehran_time()) - strtotime($config_time); |
| 46 | 46 | $time_coefficient = 1 / ($time_diff + 1); |
| 47 | 47 | return $time_coefficient; |
| 48 | 48 | } |
| 49 | -function ping_coefficient($config_ping, $lowest_ping){ |
|
| 49 | +function ping_coefficient($config_ping, $lowest_ping) { |
|
| 50 | 50 | $ping_diff = $config_ping - $lowest_ping; |
| 51 | 51 | $ping_coefficient = 1 / ($ping_diff + 1); |
| 52 | 52 | return $ping_coefficient; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | -function process_rank_file($type){ |
|
| 55 | +function process_rank_file($type) { |
|
| 56 | 56 | $last_point_array = []; |
| 57 | 57 | if (file_exists("ranking/channel_ranking_" . $type . ".json")) { |
| 58 | 58 | $last_point_array = json_decode( |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | true |
| 61 | 61 | ); |
| 62 | 62 | $last_rank_date = $last_point_array['date']; |
| 63 | - if (same_date($last_rank_date) === false){ |
|
| 63 | + if (same_date($last_rank_date) === false) { |
|
| 64 | 64 | unlink("ranking/channel_ranking_" . $type . ".json"); |
| 65 | 65 | $last_point_array['points'] = []; |
| 66 | 66 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | return $last_point_array; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | -function process_points($point_array, $last_point_array){ |
|
| 73 | +function process_points($point_array, $last_point_array) { |
|
| 74 | 74 | if (!empty(array_diff_assoc($point_array, $last_point_array['points']))) { |
| 75 | 75 | foreach ($point_array as $channel => $point) { |
| 76 | 76 | if (array_key_exists($channel, $last_point_array['points'])) { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $point_array = point_array($input); |
| 89 | 89 | $lowest_ping = lowest_ping($input); |
| 90 | 90 | |
| 91 | - foreach ($input as $key => $config){ |
|
| 91 | + foreach ($input as $key => $config) { |
|
| 92 | 92 | |
| 93 | 93 | $username_ch = $config['channel']['username']; |
| 94 | 94 | |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | $ping_coefficient = ping_coefficient($config['ping'], $lowest_ping); |
| 99 | 99 | $point_array[$username_ch] += $ping_coefficient; |
| 100 | 100 | |
| 101 | - switch ($config['type']){ |
|
| 101 | + switch ($config['type']) { |
|
| 102 | 102 | case "reality": |
| 103 | - $point_array[$username_ch] += 1 ; |
|
| 103 | + $point_array[$username_ch] += 1; |
|
| 104 | 104 | break; |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -104,7 +104,7 @@ |
||
| 104 | 104 | // Handle the error here, e.g. by logging it |
| 105 | 105 | $attempts++; |
| 106 | 106 | if ($attempts == $max_attempts) { |
| 107 | - // Reached max attempts, so throw an exception to indicate failure |
|
| 107 | + // Reached max attempts, so throw an exception to indicate failure |
|
| 108 | 108 | throw new Exception('Failed to retrieve data after ' . $max_attempts . ' attempts.'); |
| 109 | 109 | } |
| 110 | 110 | sleep(1); // Wait for 1 second before retrying |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | include "modules/ranking.php"; // Include the ranking module |
| 7 | 7 | include "modules/singbox.php"; // Include the singbox module |
| 8 | 8 | |
| 9 | -function addHeader ($subscription, $subscriptionName) { |
|
| 9 | +function addHeader($subscription, $subscriptionName) { |
|
| 10 | 10 | $headerText = "#profile-title: base64:" . base64_encode($subscriptionName) . " |
| 11 | 11 | #profile-update-interval: 1 |
| 12 | 12 | #subscription-userinfo: upload=0; download=0; total=10737418240000000; expire=2546249531 |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | rmdir($folder); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -function seprate_by_country($configs){ |
|
| 32 | +function seprate_by_country($configs) { |
|
| 33 | 33 | $configsArray = explode("\n", $configs); |
| 34 | 34 | $configLocation = ""; |
| 35 | 35 | $output = []; |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | if ($configType === "vmess") { |
| 40 | 40 | $configName = parse_config($config, "vmess", true)['ps']; |
| 41 | - } elseif ($configType === "vless" || $configType === "trojan" ){ |
|
| 41 | + } elseif ($configType === "vless" || $configType === "trojan") { |
|
| 42 | 42 | $configName = parse_config($config, $configType)['hash']; |
| 43 | - } elseif ($configType === "ss"){ |
|
| 43 | + } elseif ($configType === "ss") { |
|
| 44 | 44 | $configName = parse_config($config, "ss")['name']; |
| 45 | - } elseif ($configType === "tuic"){ |
|
| 45 | + } elseif ($configType === "tuic") { |
|
| 46 | 46 | $configName = parse_config($config, "tuic")['hash']; |
| 47 | - } elseif ($configType === "hy2"){ |
|
| 47 | + } elseif ($configType === "hy2") { |
|
| 48 | 48 | $configName = parse_config($config, "hy2")['hash']; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if (stripos($configName, "RELAY |
|
@@ -113,16 +113,16 @@ |
||
| 113 | 113 | sleep($accuracy); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | -function filtered_or_not($input, $accuracy = 3){ |
|
| 116 | +function filtered_or_not($input, $accuracy = 3) { |
|
| 117 | 117 | $request_id = check_the_host($input); |
| 118 | 118 | accuracy($accuracy); |
| 119 | 119 | $pings = check_the_ping($request_id); |
| 120 | 120 | $check_host_data = json_decode($pings, true); |
| 121 | 121 | $ping_count = 0; |
| 122 | 122 | $precent = [100, 66, 33, 0]; |
| 123 | - if (!is_null($check_host_data)){ |
|
| 123 | + if (!is_null($check_host_data)) { |
|
| 124 | 124 | $ping_count = count($check_host_data); |
| 125 | - $output = $precent[$ping_count] >= 66 ? true : false ; |
|
| 125 | + $output = $precent[$ping_count] >= 66 ? true : false; |
|
| 126 | 126 | } |
| 127 | 127 | return $output; |
| 128 | 128 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -function parseTuic ($config_str) { |
|
| 3 | +function parseTuic($config_str) { |
|
| 4 | 4 | $parsedUrl = parse_url($config_str); |
| 5 | 5 | |
| 6 | 6 | // Extract the parameters from the query string |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -function parseHy2 ($config_str) {
|
|
| 3 | +function parseHy2($config_str) {
|
|
| 4 | 4 | $parsedUrl = parse_url($config_str); |
| 5 | 5 | |
| 6 | 6 | // Extract the parameters from the query string |
@@ -3,10 +3,10 @@ discard block |
||
| 3 | 3 | header("Content-type: application/json;"); |
| 4 | 4 | |
| 5 | 5 | function create_tehran_timestamp_tomorrow() { |
| 6 | - date_default_timezone_set('Asia/Tehran'); |
|
| 7 | - $dateTomorrow = new DateTime('tomorrow'); |
|
| 8 | - $timestampTomorrow = strtotime($dateTomorrow->format('Y-m-d H:i:s')); |
|
| 9 | - return $timestampTomorrow; |
|
| 6 | + date_default_timezone_set('Asia/Tehran'); |
|
| 7 | + $dateTomorrow = new DateTime('tomorrow'); |
|
| 8 | + $timestampTomorrow = strtotime($dateTomorrow->format('Y-m-d H:i:s')); |
|
| 9 | + return $timestampTomorrow; |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | function isEvenLength($str) { |
@@ -22,27 +22,27 @@ discard block |
||
| 22 | 22 | function extract_names($input){ |
| 23 | 23 | foreach($input as $config){ |
| 24 | 24 | if ($config['tag'] !== ""){ |
| 25 | - $locationNames[] = $config['tag']; |
|
| 25 | + $locationNames[] = $config['tag']; |
|
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | return $locationNames; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | function processWsPath($input) { |
| 32 | - if (strpos($input, '/') === 0) { |
|
| 32 | + if (strpos($input, '/') === 0) { |
|
| 33 | 33 | $input = substr($input, 1); |
| 34 | - } |
|
| 35 | - $max_early_data = 0; |
|
| 36 | - if (strpos($input, '?ed=2048') !== false) { |
|
| 34 | + } |
|
| 35 | + $max_early_data = 0; |
|
| 36 | + if (strpos($input, '?ed=2048') !== false) { |
|
| 37 | 37 | $input = str_replace('?ed=2048', '', $input); |
| 38 | 38 | $max_early_data = 2048; |
| 39 | - } |
|
| 40 | - $output = [ |
|
| 41 | - "path" => "/" . $input, |
|
| 42 | - "max_early_data" => $max_early_data |
|
| 43 | - ]; |
|
| 39 | + } |
|
| 40 | + $output = [ |
|
| 41 | + "path" => "/" . $input, |
|
| 42 | + "max_early_data" => $max_early_data |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - return $output; |
|
| 45 | + return $output; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | function VmessSingbox($VmessUrl) |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | "ping_timeout" => "15s", |
| 107 | 107 | "permit_without_stream" => false, |
| 108 | 108 | ]; |
| 109 | - if ($configResult["transport"]["service_name"] === "" || is_null($configResult["transport"]["service_name"])) return null; |
|
| 109 | + if ($configResult["transport"]["service_name"] === "" || is_null($configResult["transport"]["service_name"])) return null; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | return $configResult; |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | ], |
| 323 | 323 | ]; |
| 324 | 324 | if (!isset($decodedTuic['params']['alpn']) || is_null($decodedTuic['params']['alpn']) || $decodedTuic['params']['alpn'] === "") { |
| 325 | - unset($configResult['tls']["alpn"]); |
|
| 325 | + unset($configResult['tls']["alpn"]); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | return $configResult; |
@@ -97,7 +97,9 @@ discard block |
||
| 97 | 97 | "max_early_data" => $pathProcess['max_early_data'], |
| 98 | 98 | "early_data_header_name" => "Sec-WebSocket-Protocol", |
| 99 | 99 | ]; |
| 100 | - if ($configResult["transport"]["headers"]["Host"] === "" || is_null($configResult["transport"]["headers"]["Host"])) return null; |
|
| 100 | + if ($configResult["transport"]["headers"]["Host"] === "" || is_null($configResult["transport"]["headers"]["Host"])) { |
|
| 101 | + return null; |
|
| 102 | + } |
|
| 101 | 103 | } elseif ($decode_vmess["net"] === "grpc") { |
| 102 | 104 | $configResult["transport"] = [ |
| 103 | 105 | "type" => $decode_vmess["net"], |
@@ -106,7 +108,9 @@ discard block |
||
| 106 | 108 | "ping_timeout" => "15s", |
| 107 | 109 | "permit_without_stream" => false, |
| 108 | 110 | ]; |
| 109 | - if ($configResult["transport"]["service_name"] === "" || is_null($configResult["transport"]["service_name"])) return null; |
|
| 111 | + if ($configResult["transport"]["service_name"] === "" || is_null($configResult["transport"]["service_name"])) { |
|
| 112 | + return null; |
|
| 113 | + } |
|
| 110 | 114 | } |
| 111 | 115 | |
| 112 | 116 | return $configResult; |
@@ -200,8 +204,12 @@ discard block |
||
| 200 | 204 | $transportTypes[$decoded_vless["params"]["type"]]; |
| 201 | 205 | } |
| 202 | 206 | } |
| 203 | - if ($decoded_vless["params"]["type"] === "ws" && ($configResult["transport"]["headers"]["Host"] === "" || is_null($configResult["transport"]["headers"]["Host"]))) return null; |
|
| 204 | - if ($decoded_vless["params"]["type"] === "grpc" && ($configResult["transport"]["service_name"] === "" || is_null($configResult["transport"]["service_name"]))) return null; |
|
| 207 | + if ($decoded_vless["params"]["type"] === "ws" && ($configResult["transport"]["headers"]["Host"] === "" || is_null($configResult["transport"]["headers"]["Host"]))) { |
|
| 208 | + return null; |
|
| 209 | + } |
|
| 210 | + if ($decoded_vless["params"]["type"] === "grpc" && ($configResult["transport"]["service_name"] === "" || is_null($configResult["transport"]["service_name"]))) { |
|
| 211 | + return null; |
|
| 212 | + } |
|
| 205 | 213 | return $configResult; |
| 206 | 214 | } |
| 207 | 215 | |
@@ -264,8 +272,12 @@ discard block |
||
| 264 | 272 | $transportTypes[$decoded_trojan["params"]["type"]]; |
| 265 | 273 | } |
| 266 | 274 | } |
| 267 | - if ($decoded_trojan["params"]["type"] === "ws" && ($configResult["transport"]["headers"]["Host"] === "" || is_null($configResult["transport"]["headers"]["Host"]))) return null; |
|
| 268 | - if ($decoded_trojan["params"]["type"] === "grpc" && ($configResult["transport"]["service_name"] === "" || is_null($configResult["transport"]["service_name"]))) return null; |
|
| 275 | + if ($decoded_trojan["params"]["type"] === "ws" && ($configResult["transport"]["headers"]["Host"] === "" || is_null($configResult["transport"]["headers"]["Host"]))) { |
|
| 276 | + return null; |
|
| 277 | + } |
|
| 278 | + if ($decoded_trojan["params"]["type"] === "grpc" && ($configResult["transport"]["service_name"] === "" || is_null($configResult["transport"]["service_name"]))) { |
|
| 279 | + return null; |
|
| 280 | + } |
|
| 269 | 281 | return $configResult; |
| 270 | 282 | } |
| 271 | 283 | |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | return $length % 2 == 0; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | -function process_jsons($input, $locationNames){ |
|
| 17 | +function process_jsons($input, $locationNames) { |
|
| 18 | 18 | $input[0]['outbounds'] = array_merge($input[0]['outbounds'], array_filter($locationNames)); |
| 19 | 19 | return $input; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -function extract_names($input){ |
|
| 23 | - foreach($input as $config){ |
|
| 24 | - if ($config['tag'] !== ""){ |
|
| 22 | +function extract_names($input) { |
|
| 23 | + foreach ($input as $config) { |
|
| 24 | + if ($config['tag'] !== "") { |
|
| 25 | 25 | $locationNames[] = $config['tag']; |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | |
| 272 | 272 | function ShadowsocksSingbox($ShadowsocksUrl) { |
| 273 | 273 | $decoded_shadowsocks = ParseShadowsocks($ShadowsocksUrl); |
| 274 | - if (is_null($decoded_shadowsocks['name']) || $decoded_shadowsocks['name'] === ""){ |
|
| 274 | + if (is_null($decoded_shadowsocks['name']) || $decoded_shadowsocks['name'] === "") { |
|
| 275 | 275 | return null; |
| 276 | 276 | } |
| 277 | 277 | if ($decoded_shadowsocks['encryption_method'] === "chacha20-poly1305") { |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | return $configResult; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | -function GenerateConfig($input, $output, $theType){ |
|
| 374 | +function GenerateConfig($input, $output, $theType) { |
|
| 375 | 375 | $outbound = []; |
| 376 | 376 | $v2ray_subscription = str_replace(" ", "%20", $input); |
| 377 | 377 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | foreach ($configArray as $config) { |
| 380 | 380 | $configType = detect_type($config); |
| 381 | 381 | $config = str_replace("%20", " ", $config); |
| 382 | - switch($configType) { |
|
| 382 | + switch ($configType) { |
|
| 383 | 383 | case "vmess": |
| 384 | 384 | $configSingbox = VmessSingbox($config); |
| 385 | 385 | break; |
@@ -399,9 +399,9 @@ discard block |
||
| 399 | 399 | $configSingbox = ShadowsocksSingbox($config); |
| 400 | 400 | break; |
| 401 | 401 | } |
| 402 | - if (!is_null($configSingbox)){ |
|
| 402 | + if (!is_null($configSingbox)) { |
|
| 403 | 403 | $configName = $configSingbox['tag']; |
| 404 | - if (stripos($configName, "RELAY |
|