-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeoIp.php
90 lines (77 loc) · 2.83 KB
/
geoIp.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
<?php
require_once __DIR__ . '/func-proxy.php';
global $isCli, $isWin;
if (!$isCli) {
exit('web server access disallowed');
}
if (function_exists('header') && !$isCli) {
header('Content-Type: application/json; charset=UTF-8');
// Allow from any origin
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Access-Control-Allow-Methods: *");
header('Content-Type: application/json; charset=utf-8');
// check admin
$isAdmin = !empty($_SESSION['admin']) && $_SESSION['admin'] === true;
}
$db = new \PhpProxyHunter\ProxyDB(__DIR__ . '/src/database.sqlite');
$lockFilePath = tmp() . "/runners/geoIp.lock";
$statusFile = __DIR__ . "/status.txt";
$config = getConfig(getUserId());
$options = getopt("", ["str:"]); // php geoIp.php --str "xsdsd dfdfd"
$string_data = '89.58.45.94:45729';
if ($isCli) {
if (isset($options['str'])) {
$string_data = rawurldecode(trim($options['str']));
} else {
$read_data = read_file(__DIR__ . '/proxies.txt');
if (!empty($read_data)) {
$string_data = $read_data;
}
}
} elseif (isset($_REQUEST['proxy'])) {
$string_data = rawurldecode(trim($_REQUEST['proxy']));
}
if (file_exists($lockFilePath) && !$isAdmin) {
echo date(DATE_RFC3339) . ' another process still running' . PHP_EOL;
exit();
} else {
write_file($lockFilePath, date(DATE_RFC3339));
write_file($statusFile, "geolocation $string_data");
}
\PhpProxyHunter\Scheduler::register(function () use ($lockFilePath, $statusFile, $db) {
echo "releasing lock" . PHP_EOL;
// clean lock files
if (file_exists($lockFilePath)) {
unlink($lockFilePath);
}
echo "update status to IDLE" . PHP_EOL;
write_file($statusFile, 'idle');
}, 'z_onExit' . basename(__FILE__));
if (function_exists('header')) {
// Set cache control headers to instruct the browser to cache the content for [n] hour
$hour = 1;
header('Cache-Control: max-age=3600, must-revalidate');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + ($hour * 3600)) . ' GMT');
}
$extract = extractProxies($string_data);
shuffle($extract);
foreach ($extract as $item) {
if (empty($item->lang) || empty($item->country) || empty($item->timezone) || empty($item->longitude) || empty($item->latitude)) {
get_geo_ip($item->proxy, 'http', $db);
}
if (empty($item->useragent)) {
$item->useragent = randomWindowsUa();
$db->updateData($item->proxy, ['useragent' => $item->useragent]);
echo $item->proxy . " missing useragent fix" . PHP_EOL;
}
if (empty($item->webgl_renderer) || empty($item->browser_vendor) || empty($item->webgl_vendor)) {
$webgl = random_webgl_data();
$db->updateData($item->proxy, [
'webgl_renderer' => $webgl->webgl_renderer,
'webgl_vendor' => $webgl->webgl_vendor,
'browser_vendor' => $webgl->browser_vendor
]);
echo $item->proxy . " missing WebGL fix" . PHP_EOL;
}
}