@@ -11,15 +11,15 @@ |
||
| 11 | 11 | return touch("$name.lock");
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public static function save(string $name, string $data): bool|int {
|
|
| 15 | - return file_put_contents("$name.lock", $data) && chmod("$name.lock",0640);
|
|
| 14 | + public static function save(string $name, string $data): bool | int {
|
|
| 15 | + return file_put_contents("$name.lock", $data) && chmod("$name.lock", 0640);
|
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public static function read(string $name): bool|string {
|
|
| 18 | + public static function read(string $name): bool | string {
|
|
| 19 | 19 | return file_get_contents("$name.lock");
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public static function mtime(string $name): bool|int {
|
|
| 22 | + public static function mtime(string $name): bool | int {
|
|
| 23 | 23 | return filemtime("$name.lock");
|
| 24 | 24 | } |
| 25 | 25 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use CURLFile; |
| 14 | 14 | |
| 15 | 15 | class webhook extends receiver {
|
| 16 | - public static function init () {
|
|
| 16 | + public static function init() {
|
|
| 17 | 17 | if (settings::$multi) {
|
| 18 | 18 | multi::init(); |
| 19 | 19 | } |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | self::setCertificate(); |
| 31 | 31 | $url = self::setURL(); |
| 32 | 32 | $secret = tools::randomString(64); |
| 33 | - self::setWebhook($url,$secret); |
|
| 34 | - lock::save('BPT-HOOK',$secret);
|
|
| 33 | + self::setWebhook($url, $secret); |
|
| 34 | + lock::save('BPT-HOOK', $secret);
|
|
| 35 | 35 | BPT::exit('Done');
|
| 36 | 36 | } |
| 37 | 37 | } |
@@ -49,26 +49,26 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - protected static function setWebhook(string $url,string $secret = '') {
|
|
| 52 | + protected static function setWebhook(string $url, string $secret = '') {
|
|
| 53 | 53 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates, secret_token: $secret); |
| 54 | 54 | if (telegram::$status) {
|
| 55 | - logger::write('Webhook was set successfully',loggerTypes::INFO);
|
|
| 55 | + logger::write('Webhook was set successfully', loggerTypes::INFO);
|
|
| 56 | 56 | } |
| 57 | 57 | else {
|
| 58 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
|
|
| 59 | - BPT::exit(print_r($res,true)); |
|
| 58 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
|
|
| 59 | + BPT::exit(print_r($res, true)); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | protected static function checkURL() {
|
| 64 | 64 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
|
| 65 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
|
|
| 65 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
|
|
| 66 | 66 | throw new bptException('WEBHOOK_NEED_URL');
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | private static function setURL(): string {
|
| 71 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; |
|
| 71 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | protected static function setCertificate() {
|
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | private static function checkSecret() {
|
| 88 | 88 | $secret = lock::read('BPT-HOOK');
|
| 89 | 89 | if (!isset($_SERVER['HTTP_X_TELEGRAM_BOT_API_SECRET_TOKEN']) || $_SERVER['HTTP_X_TELEGRAM_BOT_API_SECRET_TOKEN'] != $secret) {
|
| 90 | - logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
|
|
| 90 | + logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING);
|
|
| 91 | 91 | BPT::exit(); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -16,15 +16,13 @@ discard block |
||
| 16 | 16 | public static function init () {
|
| 17 | 17 | if (settings::$multi) {
|
| 18 | 18 | multi::init(); |
| 19 | - } |
|
| 20 | - else {
|
|
| 19 | + } else {
|
|
| 21 | 20 | if (lock::exist('BPT-HOOK')) {
|
| 22 | 21 | self::checkSecret(); |
| 23 | 22 | receiver::telegramVerify(); |
| 24 | 23 | receiver::processUpdate(); |
| 25 | 24 | logger::write('Update received , lets process it ;)');
|
| 26 | - } |
|
| 27 | - else {
|
|
| 25 | + } else {
|
|
| 28 | 26 | self::deleteOldLocks(); |
| 29 | 27 | self::checkURL(); |
| 30 | 28 | self::setCertificate(); |
@@ -53,8 +51,7 @@ discard block |
||
| 53 | 51 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates, secret_token: $secret); |
| 54 | 52 | if (telegram::$status) {
|
| 55 | 53 | logger::write('Webhook was set successfully',loggerTypes::INFO);
|
| 56 | - } |
|
| 57 | - else {
|
|
| 54 | + } else {
|
|
| 58 | 55 | logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
|
| 59 | 56 | BPT::exit(print_r($res,true)); |
| 60 | 57 | } |
@@ -76,8 +73,7 @@ discard block |
||
| 76 | 73 | if (is_string(settings::$certificate)) {
|
| 77 | 74 | if (file_exists(settings::$certificate)) {
|
| 78 | 75 | settings::$certificate = new CURLFile(settings::$certificate); |
| 79 | - } |
|
| 80 | - else {
|
|
| 76 | + } else {
|
|
| 81 | 77 | settings::$certificate = null; |
| 82 | 78 | } |
| 83 | 79 | } |