forked from xtoolkit/TVC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.php
154 lines (137 loc) · 4.69 KB
/
get.php
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
<?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
);
// Count the total number of sources
$totalSources = count($sourcesArray);
$tempCounter = 1;
// Initialize an empty array to store the configurations
$configsList = [];
echo "Fetching Configs\n";
// Loop through each source in the sources array
foreach ($sourcesArray as $source => $types) {
// Calculate the percentage complete
$percentage = ($tempCounter / $totalSources) * 100;
// Print the progress bar
echo "\rProgress: [";
echo str_repeat("=", $tempCounter);
echo str_repeat(" ", $totalSources - $tempCounter);
echo "] $percentage%";
$tempCounter++;
// Fetch the data from the source
$tempData = file_get_contents("https://t.me/s/" . $source);
$type = implode("|", $types);
$tempExtract = extractLinksByType($tempData, $type);
if (!is_null($tempExtract)) {
$configsList[$source] = $tempExtract;
}
}
// Initialize an empty array to store the final output
$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",
];
echo "\nProcessing Configs\n";
$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
file_put_contents("config.txt", implode("\n", $finalOutput));
echo "\nGetting Configs Done!\n";