-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.php
More file actions
183 lines (163 loc) · 5.79 KB
/
Copy pathget.php
File metadata and controls
183 lines (163 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
// Enable error reporting
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
error_reporting(E_ERROR | E_PARSE);
// Include the functions file
require "functions.php";
// Fetch the JSON data from the API and decode it into an associative array
$sourcesArray = json_decode(
file_get_contents("channels.json"),
true
);
// Function to process a batch of sources
function processBatch($batchSources, $sourcesArray, &$configsList)
{
// Initialize cURL multi handle
$multiHandle = curl_multi_init();
$curlHandles = [];
// Add individual cURL handles to the multi handle
foreach ($batchSources as $source) {
$url = "https://t.me/s/" . $source;
$curlHandle = curl_init($url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$curlHandles[$source] = $curlHandle;
curl_multi_add_handle($multiHandle, $curlHandle);
}
// Execute the multi handle
$running = null;
do {
curl_multi_exec($multiHandle, $running);
curl_multi_select($multiHandle);
} while ($running);
// Get the content from the individual cURL handles
foreach ($curlHandles as $source => $curlHandle) {
$tempData = curl_multi_getcontent($curlHandle);
$type = implode("|", $sourcesArray[$source]);
$tempExtract = extractLinksByType($tempData, $type);
if (!is_null($tempExtract)) {
$configsList[$source] = $tempExtract;
}
curl_multi_remove_handle($multiHandle, $curlHandle);
curl_close($curlHandle);
}
// Close the multi handle
curl_multi_close($multiHandle);
}
// Batch size
$batchSize = 10;
$totalSources = count($sourcesArray);
$sourceKeys = array_keys($sourcesArray);
$configsList = [];
echo "Fetching Configs\n";
// Process the sources in batches
for ($i = 0; $i < $totalSources; $i += $batchSize) {
$batchSources = array_slice($sourceKeys, $i, min($batchSize, $totalSources - $i));
processBatch($batchSources, $sourcesArray, $configsList);
echo "\rProgress: " . round(($i + count($batchSources)) / $totalSources * 100) . "% \n";
}
echo "\nProcessing Configs\n";
$finalOutput = [];
// $locationBased = [];
$needleArray = ["amp%3B"];
$replaceArray = [""];
// Define the hash and IP keys for each type of configuration
$configsHash = [
"vmess" => "ps",
"vless" => "hash",
"trojan" => "hash",
"tuic" => "hash",
"hy2" => "hash",
"ss" => "name",
];
$configsIp = [
"vmess" => "add",
"vless" => "hostname",
"trojan" => "hostname",
"tuic" => "hostname",
"hy2" => "hostname",
"ss" => "server_address",
];
$totalSources = count($configsList);
$tempSource = 1;
// Loop through each source in the configs list
foreach ($configsList as $source => $configs) {
$totalConfigs = count($configs);
$tempCounter = 1;
echo "\n" . strval($tempSource) . "/" . strval($totalSources) . "\n";
// Loop through each config in the configs array
$limitKey = count($configs) - 40;
foreach (array_reverse($configs) as $key => $config) {
// Calculate the percentage complete
$percentage = ($tempCounter / $totalConfigs) * 100;
// Print the progress bar
echo "\rProgress: [";
echo str_repeat("=", $tempCounter);
echo str_repeat(" ", $totalConfigs - $tempCounter);
echo "] $percentage%";
$tempCounter++;
// If the config is valid and the key is less than or equal to 15
if (is_valid($config) && $key >= $limitKey) {
$type = detect_type($config);
$configHash = $configsHash[$type];
$configIp = $configsIp[$type];
$decodedConfig = configParse(explode("<", $config)[0]);
// $configLocation =
// ip_info($decodedConfig[$configIp])->country ?? "XX";
// $configFlag =
// $configLocation === "XX" ? "❔" : ($configLocation === "CF" ? "🚩" : getFlags($configLocation));
$isEncrypted =
isEncrypted($config) ? "🔒" : "🔓";
$decodedConfig[$configHash] =
// $configFlag .
// $configLocation .
// " | " .
$isEncrypted .
" | " .
$type .
" | @" .
$source .
" | " .
strval($key);
$encodedConfig = reparseConfig($decodedConfig, $type);
if (substr($encodedConfig, 0, 10) !== "ss://Og==@") {
$finalOutput[] = str_replace(
$needleArray,
$replaceArray,
$encodedConfig
);
// $locationBased[$configLocation][] = str_replace(
// $needleArray,
// $replaceArray,
// $encodedConfig
// );
}
}
}
$tempSource++;
}
// deleteFolder("subscriptions/location/normal");
// deleteFolder("subscriptions/location/base64");
// mkdir("subscriptions/location/normal");
// mkdir("subscriptions/location/base64");
// Loop through each location in the location-based array
// foreach ($locationBased as $location => $configs) {
// $tempConfig = urldecode(implode("\n", $configs));
// $base64TempConfig = base64_encode($tempConfig);
// file_put_contents(
// "subscriptions/location/normal/" . $location,
// $tempConfig
// );
// file_put_contents(
// "subscriptions/location/base64/" . $location,
// $base64TempConfig
// );
// }
// Write the final output to a file only if it's not empty
if (!empty($finalOutput)) {
file_put_contents("config.txt", implode("\n", $finalOutput));
echo "\nConfig file written successfully.\n";
} else {
echo "\nNo valid new configurations found. Config file not written.\n";
}
echo "\nGetting Configs Done!\n";