@@ -11,16 +11,16 @@ |
||
| 11 | 11 | return touch("$name.lock");
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public static function save(string $name, string $data): bool|int {
|
|
| 14 | + public static function save(string $name, string $data): bool | int {
|
|
| 15 | 15 | return file_put_contents("$name.lock", $data);
|
| 16 | 16 | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public static function read(string $name): bool|string {
|
|
| 19 | + public static function read(string $name): bool | string {
|
|
| 20 | 20 | return file_get_contents("$name.lock");
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public static function mtime(string $name): bool|int {
|
|
| 23 | + public static function mtime(string $name): bool | int {
|
|
| 24 | 24 | return filemtime("$name.lock");
|
| 25 | 25 | } |
| 26 | 26 | |
@@ -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 {
|
@@ -9,19 +9,19 @@ discard block |
||
| 9 | 9 | use stdClass; |
| 10 | 10 | |
| 11 | 11 | class getUpdates extends receiver {
|
| 12 | - public static function init () {
|
|
| 12 | + public static function init() {
|
|
| 13 | 13 | $last_update_id = self::loadData(); |
| 14 | - while(true) {
|
|
| 14 | + while (true) {
|
|
| 15 | 15 | if (!lock::exist('getUpdate')) {
|
| 16 | - $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates)->result; |
|
| 16 | + $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates)->result; |
|
| 17 | 17 | self::handleUpdates($updates); |
| 18 | - lock::save('getUpdate',BPT::$update->update_id+1);
|
|
| 19 | - $last_update_id = BPT::$update->update_id+1; |
|
| 18 | + lock::save('getUpdate', BPT::$update->update_id + 1);
|
|
| 19 | + $last_update_id = BPT::$update->update_id + 1; |
|
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - private static function loadData(): bool|int|string {
|
|
| 24 | + private static function loadData(): bool | int | string {
|
|
| 25 | 25 | if (lock::exist('getUpdate')) {
|
| 26 | 26 | $last_update_id = lock::read('getUpdate');
|
| 27 | 27 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | self::deleteOldLocks(); |
| 30 | 30 | telegram::deleteWebhook(); |
| 31 | 31 | $last_update_id = 0; |
| 32 | - lock::save('getUpdate',0);
|
|
| 32 | + lock::save('getUpdate', 0);
|
|
| 33 | 33 | } |
| 34 | 34 | return $last_update_id; |
| 35 | 35 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | private static $handler; |
| 11 | 11 | |
| 12 | 12 | |
| 13 | - public static function init (int $log_size = 10) {
|
|
| 13 | + public static function init(int $log_size = 10) {
|
|
| 14 | 14 | self::$log_size = $log_size; |
| 15 | 15 | if (file_exists('BPT.log') && !(filesize('BPT.log') > self::$log_size * 1024 * 1024)) {
|
| 16 | 16 | $mode = 'a'; |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | self::$handler = fopen('BPT.log', $mode);
|
| 25 | 25 | |
| 26 | 26 | if ($write) {
|
| 27 | - fwrite(self::$handler,"♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
| 27 | + fwrite(self::$handler, "♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public static function write(string $data, string $type = loggerTypes::NONE) {
|
| 32 | 32 | if (!is_null(self::$handler)) {
|
| 33 | - $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" );
|
|
| 33 | + $text = date('Y/m/d H:i:s').($type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n");
|
|
| 34 | 34 | fwrite(self::$handler, $text); |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -26,12 +26,12 @@ |
||
| 26 | 26 | $this->$key[$sub_key][] = new ($subs['array']['array'][$key]) ($sub2_value); |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | - else{ |
|
| 29 | + else { |
|
| 30 | 30 | $this->$key[] = new ($subs['array'][$key]) ($sub_value); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | - else{ |
|
| 34 | + else { |
|
| 35 | 35 | $this->$key = $value; |
| 36 | 36 | if (ucfirst($key) === basename(get_class($this)).'_id') { |
| 37 | 37 | $this->{'id'} = $value; |
@@ -139,13 +139,13 @@ |
||
| 139 | 139 | public string $text; |
| 140 | 140 | |
| 141 | 141 | /** Optional. If user message was a commend , this parameter will be the commend */ |
| 142 | - public string|null $commend; |
|
| 142 | + public string | null $commend; |
|
| 143 | 143 | |
| 144 | 144 | /** Optional. If user message was a commend , this parameter will be the commend username(if exist) */ |
| 145 | - public string|null $commend_username; |
|
| 145 | + public string | null $commend_username; |
|
| 146 | 146 | |
| 147 | 147 | /** Optional. If user message was a commend , this parameter will be the commend payload(if exist) */ |
| 148 | - public string|null $commend_payload; |
|
| 148 | + public string | null $commend_payload; |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text |
@@ -10,12 +10,12 @@ discard block |
||
| 10 | 10 | use BPT\settings; |
| 11 | 11 | |
| 12 | 12 | class curl extends webhook {
|
| 13 | - public static function init (): string|null {
|
|
| 13 | + public static function init(): string | null {
|
|
| 14 | 14 | if (self::checkIP()) {
|
| 15 | 15 | return self::getUpdate(); |
| 16 | 16 | } |
| 17 | 17 | else {
|
| 18 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
|
|
| 18 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING);
|
|
| 19 | 19 | BPT::exit(); |
| 20 | 20 | } |
| 21 | 21 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR']; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - private static function getUpdate (): string {
|
|
| 27 | + private static function getUpdate(): string {
|
|
| 28 | 28 | $input = json_decode(file_get_contents("php://input"), true);
|
| 29 | 29 | webhook::telegramVerify($input['ip']); |
| 30 | 30 | return $input['update']; |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | $urls = self::setURLS(); |
| 35 | 35 | $file = $urls['file']; |
| 36 | 36 | $timeout = self::getTimeout($file); |
| 37 | - self::create($file,$timeout); |
|
| 37 | + self::create($file, $timeout); |
|
| 38 | 38 | self::setWebhook($urls['url']); |
| 39 | 39 | lock::set('BPT-MULTI-CURL');
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - private static function getTimeout($url): float|int {
|
|
| 42 | + private static function getTimeout($url): float | int {
|
|
| 43 | 43 | $times = []; |
| 44 | - for ($i = 0; $i < 10; $i ++) {
|
|
| 44 | + for ($i = 0; $i < 10; $i++) {
|
|
| 45 | 45 | $ch = curl_init($url); |
| 46 | 46 | 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']]); |
| 47 | 47 | $start = microtime(true); |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | return $timeout > 50 ? $timeout + 10 : 50; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private static function create($file,$timeout) {
|
|
| 56 | - 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);?>');
|
|
| 55 | + private static function create($file, $timeout) {
|
|
| 56 | + 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);?>');
|
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | private static function setURLS(): array {
|
| 60 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 60 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 61 | 61 | $file = basename($_SERVER['REQUEST_URI']); |
| 62 | 62 | return [ |
| 63 | 63 | 'url'=>str_replace($file, 'receiver.php', $base_url), |
@@ -10,11 +10,11 @@ discard block |
||
| 10 | 10 | use BPT\settings; |
| 11 | 11 | |
| 12 | 12 | class exec extends webhook {
|
| 13 | - public static function init(): string|null {
|
|
| 13 | + public static function init(): string | null {
|
|
| 14 | 14 | return self::getUpdate(); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - private static function getUpdate (): string|null {
|
|
| 17 | + private static function getUpdate(): string | null {
|
|
| 18 | 18 | $up = glob('*.update');
|
| 19 | 19 | if (isset($up[0])) {
|
| 20 | 20 | $up = end($up); |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | return $update; |
| 26 | 26 | } |
| 27 | 27 | else {
|
| 28 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
|
|
| 28 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING);
|
|
| 29 | 29 | BPT::exit(); |
| 30 | 30 | } |
| 31 | 31 | } |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | private static function create($file) {
|
| 48 | - 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 | + 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 &");');
|
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private static function setURLS(): array {
|
| 52 | - $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 52 | + $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 53 | 53 | return [ |
| 54 | 54 | 'url'=>str_replace(basename($_SERVER['REQUEST_URI']), 'receiver.php', $base_url), |
| 55 | 55 | 'file'=>basename($_SERVER['SCRIPT_NAME']) |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | use CURLFile; |
| 13 | 13 | |
| 14 | 14 | class webhook extends receiver {
|
| 15 | - public static function init () {
|
|
| 15 | + public static function init() {
|
|
| 16 | 16 | if (settings::$multi) {
|
| 17 | 17 | multi::init(); |
| 18 | 18 | } |
@@ -49,23 +49,23 @@ discard block |
||
| 49 | 49 | protected static function setWebhook(string $url) {
|
| 50 | 50 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates); |
| 51 | 51 | if ($res->ok) {
|
| 52 | - logger::write('Webhook was set successfully',loggerTypes::INFO);
|
|
| 52 | + logger::write('Webhook was set successfully', loggerTypes::INFO);
|
|
| 53 | 53 | } |
| 54 | 54 | else {
|
| 55 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
|
|
| 56 | - BPT::exit(print_r($res,true)); |
|
| 55 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
|
|
| 56 | + BPT::exit(print_r($res, true)); |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | protected static function checkURL() {
|
| 61 | 61 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
|
| 62 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
|
|
| 62 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
|
|
| 63 | 63 | throw new bptException('WEBHOOK_NEED_URL');
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | private static function setURL(): string {
|
| 68 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; |
|
| 68 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | protected static function setCertificate() {
|