|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace BPT\receiver\multi;
|
|
4
|
|
|
|
|
5
|
|
|
use BPT\BPT;
|
|
6
|
|
|
use BPT\lock;
|
|
7
|
|
|
use BPT\logger;
|
|
8
|
|
|
use BPT\receiver\webhook;
|
|
9
|
|
|
use BPT\settings;
|
|
10
|
|
|
|
|
11
|
|
|
class exec extends webhook {
|
|
12
|
|
|
public static function init(): string {
|
|
13
|
|
|
return self::getUpdate();
|
|
14
|
|
|
}
|
|
15
|
|
|
|
|
16
|
|
|
private static function getUpdate (): string {
|
|
17
|
|
|
$up = glob('*.update');
|
|
18
|
|
|
if (isset($up[0])) {
|
|
19
|
|
|
$up = end($up);
|
|
20
|
|
|
$ip = explode('-', $up)[0];
|
|
21
|
|
|
webhook::telegramVerify($ip);
|
|
22
|
|
|
$update = file_get_contents($up);
|
|
23
|
|
|
unlink($up);
|
|
24
|
|
|
return $update;
|
|
25
|
|
|
}
|
|
26
|
|
|
else {
|
|
27
|
|
|
logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown','error');
|
|
28
|
|
|
BPT::exit();
|
|
|
|
|
|
|
29
|
|
|
}
|
|
30
|
|
|
}
|
|
31
|
|
|
|
|
32
|
|
|
public static function support(): bool {
|
|
33
|
|
|
return function_exists('exec')
|
|
34
|
|
|
&& !in_array('exec', array_map('trim', explode(', ', ini_get('disable_functions'))))
|
|
35
|
|
|
&& strtolower(ini_get('safe_mode')) != 1;
|
|
36
|
|
|
}
|
|
37
|
|
|
|
|
38
|
|
|
public static function install() {
|
|
39
|
|
|
$urls = self::setURLS();
|
|
40
|
|
|
$url = $urls['url'];
|
|
41
|
|
|
self::create($urls['file']);
|
|
42
|
|
|
self::setWebhook($url);
|
|
43
|
|
|
lock::set('BPT-MULTI-EXEC');
|
|
44
|
|
|
}
|
|
45
|
|
|
|
|
46
|
|
|
private static function create($file) {
|
|
47
|
|
|
file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php ' . $file . ' > /dev/null &");');
|
|
48
|
|
|
}
|
|
49
|
|
|
|
|
50
|
|
|
private static function setURLS(): array {
|
|
51
|
|
|
$base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
|
52
|
|
|
$file = basename($_SERVER['REQUEST_URI']);
|
|
53
|
|
|
return [
|
|
54
|
|
|
'url'=>str_replace($file, 'receiver.php', $base_url),
|
|
55
|
|
|
'file'=>$file
|
|
56
|
|
|
];
|
|
57
|
|
|
}
|
|
58
|
|
|
} |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: