@@ -17,8 +17,7 @@ |
||
17 | 17 | foreach ($update as $key=>$value) { |
18 | 18 | if (isset($subs[$key])) { |
19 | 19 | $this->$key = new ($subs[$key]) ($value); |
20 | - } |
|
21 | - else { |
|
20 | + } else { |
|
22 | 21 | $this->$key = $value; |
23 | 22 | if (ucfirst($key) === basename(get_class($this)).'_id') { |
24 | 23 | $this->{'id'} = $value; |
@@ -217,18 +217,18 @@ discard block |
||
217 | 217 | * @method getGameHighScores (int|null|array $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $return_array = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. On success, returns an Array of GameHighScore objects. |
218 | 218 | * @method getGameHigh (int|null|array $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $return_array = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. On success, returns an Array of GameHighScore objects. |
219 | 219 | */ |
220 | -class BPT{ |
|
220 | +class BPT { |
|
221 | 221 | public static update $update; |
222 | 222 | |
223 | 223 | public static BPT $handler; |
224 | 224 | |
225 | 225 | |
226 | - public function __construct (array|stdClass $settings) { |
|
226 | + public function __construct(array | stdClass $settings) { |
|
227 | 227 | settings::init($settings); |
228 | 228 | static::$handler = &$this; |
229 | 229 | } |
230 | 230 | |
231 | - public function __call (string $name, array $arguments) { |
|
231 | + public function __call(string $name, array $arguments) { |
|
232 | 232 | if (!isset($arguments[1]) && is_array($arguments[0])) { |
233 | 233 | return request::$name(...$arguments[0]); |
234 | 234 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - public static function exit (string|null $message = null) { |
|
240 | + public static function exit (string | null $message = null) { |
|
241 | 241 | die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>"); |
242 | 242 | } |
243 | 243 | } |
@@ -231,8 +231,7 @@ |
||
231 | 231 | public function __call (string $name, array $arguments) { |
232 | 232 | if (!isset($arguments[1]) && is_array($arguments[0])) { |
233 | 233 | return request::$name(...$arguments[0]); |
234 | - } |
|
235 | - else { |
|
234 | + } else { |
|
236 | 235 | return request::$name($arguments); |
237 | 236 | } |
238 | 237 | } |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | use BPT\settings; |
10 | 10 | |
11 | 11 | class curl extends webhook { |
12 | - public static function init (): string { |
|
12 | + public static function init(): string { |
|
13 | 13 | if (self::checkIP()) { |
14 | 14 | return self::getUpdate(); |
15 | 15 | } |
16 | 16 | else { |
17 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown','error'); |
|
17 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', 'error'); |
|
18 | 18 | BPT::exit(); |
19 | 19 | } |
20 | 20 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']; |
24 | 24 | } |
25 | 25 | |
26 | - private static function getUpdate (): string { |
|
26 | + private static function getUpdate(): string { |
|
27 | 27 | $input = json_decode(file_get_contents("php://input"), true); |
28 | 28 | webhook::telegramVerify($input['ip']); |
29 | 29 | return $input['update']; |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | $urls = self::setURLS(); |
34 | 34 | $file = $urls['file']; |
35 | 35 | $timeout = self::getTimeout($file); |
36 | - self::create($file,$timeout); |
|
36 | + self::create($file, $timeout); |
|
37 | 37 | self::setWebhook($urls['url']); |
38 | 38 | lock::set('BPT-MULTI-CURL'); |
39 | 39 | } |
40 | 40 | |
41 | - private static function getTimeout($url): float|int { |
|
41 | + private static function getTimeout($url): float | int { |
|
42 | 42 | $times = []; |
43 | - for ($i = 0; $i < 10; $i ++) { |
|
43 | + for ($i = 0; $i < 10; $i++) { |
|
44 | 44 | $ch = curl_init($url); |
45 | 45 | curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([]), CURLOPT_TIMEOUT_MS => 100, CURLOPT_NOBODY => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => 100, CURLOPT_HTTPHEADER => ['accept: application/json', 'content-type: application/json']]); |
46 | 46 | $start = microtime(true); |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | return $timeout > 50 ? $timeout + 10 : 50; |
52 | 52 | } |
53 | 53 | |
54 | - private static function create($file,$timeout) { |
|
55 | - file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\'' . $file . '\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => ' . $timeout . ', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => ' . $timeout . ', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>'); |
|
54 | + private static function create($file, $timeout) { |
|
55 | + file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\''.$file.'\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => '.$timeout.', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => '.$timeout.', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>'); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | private static function setURLS(): array { |
59 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
59 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
60 | 60 | $file = basename($_SERVER['REQUEST_URI']); |
61 | 61 | return [ |
62 | 62 | 'url'=>str_replace($file, 'receiver.php', $base_url), |
@@ -12,8 +12,7 @@ |
||
12 | 12 | public static function init (): string { |
13 | 13 | if (self::checkIP()) { |
14 | 14 | return self::getUpdate(); |
15 | - } |
|
16 | - else { |
|
15 | + } else { |
|
17 | 16 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown','error'); |
18 | 17 | BPT::exit(); |
19 | 18 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | return self::getUpdate(); |
14 | 14 | } |
15 | 15 | |
16 | - private static function getUpdate (): string { |
|
16 | + private static function getUpdate(): string { |
|
17 | 17 | $up = glob('*.update'); |
18 | 18 | if (isset($up[0])) { |
19 | 19 | $up = end($up); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | return $update; |
25 | 25 | } |
26 | 26 | else { |
27 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown','error'); |
|
27 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', 'error'); |
|
28 | 28 | BPT::exit(); |
29 | 29 | } |
30 | 30 | } |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 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 &");'); |
|
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 | 48 | } |
49 | 49 | |
50 | 50 | private static function setURLS(): array { |
51 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
51 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
52 | 52 | $file = basename($_SERVER['REQUEST_URI']); |
53 | 53 | return [ |
54 | 54 | 'url'=>str_replace($file, 'receiver.php', $base_url), |
@@ -22,8 +22,7 @@ |
||
22 | 22 | $update = file_get_contents($up); |
23 | 23 | unlink($up); |
24 | 24 | return $update; |
25 | - } |
|
26 | - else { |
|
25 | + } else { |
|
27 | 26 | logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown','error'); |
28 | 27 | BPT::exit(); |
29 | 28 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | use CURLFile; |
11 | 11 | |
12 | 12 | class webhook extends receiver { |
13 | - public static function init () { |
|
13 | + public static function init() { |
|
14 | 14 | if (settings::$multi) { |
15 | 15 | multi::init(); |
16 | 16 | } |
@@ -46,24 +46,24 @@ discard block |
||
46 | 46 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates); |
47 | 47 | if ($res->ok) { |
48 | 48 | lock::set('BPT'); |
49 | - logger::write('Webhook was set successfully','info'); |
|
49 | + logger::write('Webhook was set successfully', 'info'); |
|
50 | 50 | BPT::exit('Done'); |
51 | 51 | } |
52 | 52 | else { |
53 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),'error'); |
|
54 | - BPT::exit(print_r($res,true)); |
|
53 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), 'error'); |
|
54 | + BPT::exit(print_r($res, true)); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | 58 | protected static function checkURL() { |
59 | 59 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) { |
60 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)','error'); |
|
60 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', 'error'); |
|
61 | 61 | BPT::exit(); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | 65 | private static function setURL(): string { |
66 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
66 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | protected static function setCertificate() { |
@@ -13,14 +13,12 @@ discard block |
||
13 | 13 | public static function init () { |
14 | 14 | if (settings::$multi) { |
15 | 15 | multi::init(); |
16 | - } |
|
17 | - else { |
|
16 | + } else { |
|
18 | 17 | if (lock::exist('BPT-HOOK')) { |
19 | 18 | receiver::telegramVerify(); |
20 | 19 | BPT::$update = receiver::processUpdate(); |
21 | 20 | logger::write('Update received , lets process it ;)'); |
22 | - } |
|
23 | - else { |
|
21 | + } else { |
|
24 | 22 | self::deleteOldLocks(); |
25 | 23 | self::checkURL(); |
26 | 24 | self::setCertificate(); |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | lock::set('BPT'); |
49 | 47 | logger::write('Webhook was set successfully','info'); |
50 | 48 | BPT::exit('Done'); |
51 | - } |
|
52 | - else { |
|
49 | + } else { |
|
53 | 50 | logger::write("There is some problem happened , telegram response : \n".json_encode($res),'error'); |
54 | 51 | BPT::exit(print_r($res,true)); |
55 | 52 | } |
@@ -71,8 +68,7 @@ discard block |
||
71 | 68 | if (is_string(settings::$certificate)) { |
72 | 69 | if (file_exists(settings::$certificate)) { |
73 | 70 | settings::$certificate = new CURLFile(settings::$certificate); |
74 | - } |
|
75 | - else { |
|
71 | + } else { |
|
76 | 72 | settings::$certificate = null; |
77 | 73 | } |
78 | 74 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | if (lock::exist('BPT-MULTI-EXEC')) { |
14 | 14 | self::setUpdate(exec::init()); |
15 | 15 | } |
16 | - elseif(lock::exist('BPT-MULTI-CURL')) { |
|
16 | + elseif (lock::exist('BPT-MULTI-CURL')) { |
|
17 | 17 | self::setUpdate(curl::init()); |
18 | 18 | } |
19 | 19 | else { |
@@ -12,11 +12,9 @@ |
||
12 | 12 | public static function init() { |
13 | 13 | if (lock::exist('BPT-MULTI-EXEC')) { |
14 | 14 | self::setUpdate(exec::init()); |
15 | - } |
|
16 | - elseif(lock::exist('BPT-MULTI-CURL')) { |
|
15 | + } elseif(lock::exist('BPT-MULTI-CURL')) { |
|
17 | 16 | self::setUpdate(curl::init()); |
18 | - } |
|
19 | - else { |
|
17 | + } else { |
|
20 | 18 | self::deleteOldLocks(); |
21 | 19 | self::checkURL(); |
22 | 20 | self::setCertificate(); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | protected static function telegramVerify(string $ip = null) { |
13 | 13 | if (settings::$telegram_verify) { |
14 | 14 | if (!tools::isTelegram($ip ?? $_SERVER['REMOTE_ADDR'] ?? '')) { |
15 | - logger::write('not authorized access denied. IP : '. $ip ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown','error'); |
|
15 | + logger::write('not authorized access denied. IP : '.$ip ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown', 'error'); |
|
16 | 16 | BPT::exit(); |
17 | 17 | } |
18 | 18 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | return $update; |
29 | 29 | } |
30 | 30 | |
31 | - protected static function setMessageExtra (update &$update) { |
|
31 | + protected static function setMessageExtra(update & $update) { |
|
32 | 32 | if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) { |
33 | 33 | $type = isset($update->message) ? 'message' : 'edited_message'; |
34 | 34 | $text = &$update->$type->text; |