|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BPT\receiver\multi; |
|
4
|
|
|
|
|
5
|
|
|
use BPT\BPT; |
|
6
|
|
|
use BPT\constants\loggerTypes; |
|
7
|
|
|
use BPT\lock; |
|
8
|
|
|
use BPT\logger; |
|
9
|
|
|
use BPT\receiver\webhook; |
|
10
|
|
|
use JetBrains\PhpStorm\ArrayShape; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* exec class , for multiprocessing with exec method |
|
14
|
|
|
*/ |
|
15
|
|
|
class exec extends webhook { |
|
16
|
|
|
/** |
|
17
|
|
|
* @internal Only for BPT self usage , Don't use it in your source! |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function init(): string|null { |
|
20
|
|
|
return self::getUpdate(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
private static function getUpdate (): string|null { |
|
24
|
|
|
$up = glob('*.update'); |
|
25
|
|
|
if (!isset($up[0])) { |
|
26
|
|
|
logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING); |
|
27
|
|
|
BPT::exit(); |
|
28
|
|
|
} |
|
29
|
|
|
$up = end($up); |
|
30
|
|
|
webhook::telegramVerify(explode('-', $up)[0]); |
|
31
|
|
|
$update = file_get_contents($up); |
|
32
|
|
|
unlink($up); |
|
33
|
|
|
return $update; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @internal Only for BPT self usage , Don't use it in your source! |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function support(): bool { |
|
40
|
|
|
return function_exists('exec') |
|
41
|
|
|
&& !in_array('exec', array_map('trim', explode(',', ini_get('disable_functions')))) |
|
42
|
|
|
&& strtolower(ini_get('safe_mode')) != 1; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @internal Only for BPT self usage , Don't use it in your source! |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function install() { |
|
49
|
|
|
$urls = self::setURLS(); |
|
50
|
|
|
self::create($urls['file']); |
|
51
|
|
|
self::setWebhook($urls['url']); |
|
52
|
|
|
lock::set('BPT-MULTI-EXEC'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private static function create($file) { |
|
56
|
|
|
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 &");'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
#[ArrayShape(['url' => 'array|string|string[]', 'file' => 'string'])] |
|
60
|
|
|
private static function setURLS(): array { |
|
61
|
|
|
$base_url = self::setURL(); |
|
62
|
|
|
return [ |
|
63
|
|
|
'url'=>str_replace(basename($_SERVER['REQUEST_URI']), 'receiver.php', $base_url), |
|
64
|
|
|
'file'=>basename($_SERVER['SCRIPT_NAME']) |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
} |