diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 7bb933b9..9b9cf10a 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -36,7 +36,7 @@ class DataCenter $this->curdc = 0; } if (isset($this->sockets[$dc_number])) { - \danog\MadelineProto\Logger::log('Disconnecting from DC '.$dc_number.'...'); + \danog\MadelineProto\Logger::log('Disconnecting from DC '.$dc_number.'...', \danog\MadelineProto\Logger::VERBOSE); unset($this->sockets[$dc_number]); } } @@ -66,7 +66,7 @@ class DataCenter $address = $settings['protocol'].'://'.$address.'/api'; $port = 80; } - \danog\MadelineProto\Logger::log('Connecting to DC '.$dc_number.' ('.$test.' server, '.$ipv6.', '.$settings['protocol'].')...'); + \danog\MadelineProto\Logger::log('Connecting to DC '.$dc_number.' ('.$test.' server, '.$ipv6.', '.$settings['protocol'].')...', \danog\MadelineProto\Logger::VERBOSE); $this->sockets[$dc_number] = new Connection($address, $port, $settings['protocol'], $settings['timeout']); diff --git a/src/danog/MadelineProto/Logger.php b/src/danog/MadelineProto/Logger.php index e7709e7d..efa57608 100644 --- a/src/danog/MadelineProto/Logger.php +++ b/src/danog/MadelineProto/Logger.php @@ -21,7 +21,24 @@ class Logger public static $optional = null; public static $constructed = false; public static $prefix = ''; - + public static $level = 3; + const ULTRA_VERBOSE = 'ULTRA_VERBOSE'; + const VERBOSE = 'VERBOSE'; + const NOTICE = 'NOTICE'; + const WARNING = 'WARNING'; + const ERROR = 'ERROR'; + const FATAL_ERROR = 'FATAL ERROR'; + public static function level2num($level) { + switch ($level) { + case self::ULTRA_VERBOSE: return 5; + case self::VERBOSE: return 4; + case self::NOTICE: return 3; + case self::WARNING: return 2; + case self::ERROR: return 1; + case self::FATAL_ERROR: return 0; + default: return false; + } + } /* * Constructor function * Accepts various logger modes: @@ -30,7 +47,7 @@ class Logger * 2 - Log to file defined in second parameter * 3 - Echo logs */ - public static function constructor(&$mode, &$optional = null, $prefix = '') + public static function constructor(&$mode, &$optional = null, $prefix = '', $level = self::NOTICE) { if ($mode === null) { throw new Exception('No mode was specified!'); @@ -39,6 +56,7 @@ class Logger self::$optional = &$optional; self::$constructed = true; self::$prefix = $prefix === '' ? '' : ', '.$prefix; + self::$level = self::level2num($level); } public static function log(...$params) @@ -46,6 +64,8 @@ class Logger if (!self::$constructed) { throw new Exception("The constructor function wasn't called! Please call the constructor function before using this method."); } + $level = self::level2num(end($params)); + if ($level !== false) { if ($level > self::$level) return false; else array_pop($params); }; foreach ($params as $param) { if (!is_string($param)) { $param = var_export($param, true); diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 6d4010f4..3d631832 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -42,19 +42,16 @@ class MTProto extends PrimeModule // Parse settings $this->parse_settings($settings); - // Setup logger - $this->setup_logger(); - // Connect to servers - \danog\MadelineProto\Logger::log('Istantiating DataCenter...'); + \danog\MadelineProto\Logger::log('Istantiating DataCenter...', Logger::ULTRA_VERBOSE); $this->datacenter = new DataCenter($this->settings['connection'], $this->settings['connection_settings']); // Load rsa key - \danog\MadelineProto\Logger::log('Loading RSA key...'); + \danog\MadelineProto\Logger::log('Loading RSA key...', Logger::ULTRA_VERBOSE); $this->key = $this->loadKey($this->settings['authorization']['rsa_key']); // Istantiate TL class - \danog\MadelineProto\Logger::log('Translating tl schemas...'); + \danog\MadelineProto\Logger::log('Translating tl schemas...', Logger::ULTRA_VERBOSE); $this->construct_TL($this->settings['tl_schema']['src']); $this->switch_dc(2, true); @@ -67,7 +64,7 @@ class MTProto extends PrimeModule $this->datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); $this->reset_session(); if ($this->datacenter->authorized && $this->settings['updates']['handle_updates']) { - \danog\MadelineProto\Logger::log('Getting updates after deserialization...'); + \danog\MadelineProto\Logger::log('Getting updates after deserialization...', Logger::NOTICE); $this->get_updates_difference(); } } @@ -192,6 +189,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB 'logger' => 1, // write to 'logger_param' => '/tmp/MadelineProto.log', 'logger' => 3, // overwrite previous setting and echo logs + 'logger_level' => Logger::NOTICE, // Logging level, available logging levels are: ULTRA_VERBOSE, VERBOSE, NOTICE, WARNING, ERROR, FATAL_ERROR. Can be provided as last parameter to the logging function. ], 'max_tries' => [ 'query' => 5, // How many times should I try to call a method or send an object before throwing an exception @@ -221,13 +219,16 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB unset($settings['connection_settings']['all']); } $this->settings = $settings; + + // Setup logger + $this->setup_logger(); } public function setup_logger() { //if (!\danog\MadelineProto\Logger::$constructed) { // Set up logger class - \danog\MadelineProto\Logger::constructor($this->settings['logger']['logger'], $this->settings['logger']['logger_param'], isset($this->datacenter->authorization['user']) ? (isset($this->datacenter->authorization['user']['username']) ? $this->datacenter->authorization['user']['username'] : $this->datacenter->authorization['user']['id']) : ''); + \danog\MadelineProto\Logger::constructor($this->settings['logger']['logger'], $this->settings['logger']['logger_param'], isset($this->datacenter->authorization['user']) ? (isset($this->datacenter->authorization['user']['username']) ? $this->datacenter->authorization['user']['username'] : $this->datacenter->authorization['user']['id']) : '', $this->settings['logger']['logger_level']); //} } @@ -235,7 +236,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB { foreach ($this->datacenter->sockets as $id => &$socket) { if ($de) { - \danog\MadelineProto\Logger::log('Resetting session id and seq_no in DC '.$id.'...'); + \danog\MadelineProto\Logger::log('Resetting session id and seq_no in DC '.$id.'...', Logger::VERBOSE); $socket->session_id = $this->random(8); $socket->seq_no = 0; } @@ -250,7 +251,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB public function switch_dc($new_dc, $allow_nearest_dc_switch = false) { $old_dc = $this->datacenter->curdc; - \danog\MadelineProto\Logger::log('Switching from DC '.$old_dc.' to DC '.$new_dc.'...'); + \danog\MadelineProto\Logger::log('Switching from DC '.$old_dc.' to DC '.$new_dc.'...', Logger::NOTICE); if (!isset($this->datacenter->sockets[$new_dc])) { $this->datacenter->dc_connect($new_dc); $this->init_authorization(); @@ -262,7 +263,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB (isset($this->datacenter->sockets[$old_dc]->authorized) && $this->datacenter->sockets[$old_dc]->authorized) && !(isset($this->datacenter->sockets[$new_dc]->authorized) && $this->datacenter->sockets[$new_dc]->authorized && $this->datacenter->sockets[$new_dc]->authorization['user']['id'] === $this->datacenter->sockets[$old_dc]->authorization['user']['id']) ) { - \danog\MadelineProto\Logger::log('Copying authorization...'); + \danog\MadelineProto\Logger::log('Copying authorization...', Logger::VERBOSE); $this->should_serialize = true; $this->datacenter->curdc = $old_dc; $exported_authorization = $this->method_call('auth.exportAuthorization', ['dc_id' => $new_dc]); @@ -273,7 +274,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB $this->datacenter->authorization = $this->method_call('auth.importAuthorization', $exported_authorization); $this->datacenter->authorized = true; } - \danog\MadelineProto\Logger::log('Done! Current DC is '.$this->datacenter->curdc); + \danog\MadelineProto\Logger::log('Done! Current DC is '.$this->datacenter->curdc, Logger::NOTICE); } // Creates authorization keys @@ -284,11 +285,11 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB } if ($this->datacenter->temp_auth_key == null || $this->datacenter->auth_key == null) { if ($this->datacenter->auth_key == null) { - \danog\MadelineProto\Logger::log('Generating permanent authorization key...'); + \danog\MadelineProto\Logger::log('Generating permanent authorization key...', Logger::NOTICE); $this->datacenter->auth_key = $this->create_auth_key(-1); $this->should_serialize = true; } - \danog\MadelineProto\Logger::log('Generating temporary authorization key...'); + \danog\MadelineProto\Logger::log('Generating temporary authorization key...', Logger::NOTICE); $this->datacenter->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in']); $this->bind_temp_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in']); if (in_array($this->datacenter->protocol, ['http', 'https'])) { @@ -299,7 +300,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB public function write_client_info($method, $arguments = []) { - \danog\MadelineProto\Logger::log('Writing client info (also executing '.$method.')...'); + \danog\MadelineProto\Logger::log('Writing client info (also executing '.$method.')...', Logger::NOTICE); return $this->method_call( 'invokeWithLayer', @@ -318,7 +319,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB public function get_nearest_dc($allow_switch) { $nearest_dc = $this->method_call('help.getNearestDc'); - \danog\MadelineProto\Logger::log("We're in ".$nearest_dc['country'].', current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].'.'); + \danog\MadelineProto\Logger::log("We're in ".$nearest_dc['country'].', current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].'.', Logger::NOTICE); if ($nearest_dc['nearest_dc'] != $nearest_dc['this_dc'] && $allow_switch) { $this->switch_dc($nearest_dc['nearest_dc']); @@ -347,6 +348,6 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB $this->settings['connection'][$test][$ipv6][$id] = $dc; } unset($this->config['dc_options']); - \danog\MadelineProto\Logger::log('Updated config!', $this->config); + \danog\MadelineProto\Logger::log('Updated config!', $this->config, Logger::NOTICE); } } diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index f04a2c36..d889f4d5 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -24,7 +24,7 @@ trait AuthKeyHandler { for ($retry_id_total = 1; $retry_id_total <= $this->settings['max_tries']['authorization']; $retry_id_total++) { try { - \danog\MadelineProto\Logger::log('Requesting pq'); + \danog\MadelineProto\Logger::log('Requesting pq', \danog\MadelineProto\Logger::VERBOSE); /** * *********************************************************************** @@ -94,7 +94,7 @@ trait AuthKeyHandler throw new \danog\MadelineProto\Exception("couldn't compute p and q."); } - \danog\MadelineProto\Logger::log('Factorization '.$pq.' = '.$p.' * '.$q); + \danog\MadelineProto\Logger::log('Factorization '.$pq.' = '.$p.' * '.$q, \danog\MadelineProto\Logger::VERBOSE); /* * *********************************************************************** @@ -125,7 +125,7 @@ trait AuthKeyHandler $to_encrypt = $sha_digest.$p_q_inner_data.$random_bytes; $encrypted_data = $this->RSA_encrypt($to_encrypt, $this->key); - \danog\MadelineProto\Logger::log('Starting Diffie Hellman key exchange'); + \danog\MadelineProto\Logger::log('Starting Diffie Hellman key exchange', \danog\MadelineProto\Logger::VERBOSE); /* * *********************************************************************** * Starting Diffie Hellman key exchange, Server authentication @@ -241,13 +241,13 @@ trait AuthKeyHandler $server_time = $server_DH_inner_data['server_time']; $this->datacenter->time_delta = $server_time - time(); - \danog\MadelineProto\Logger::log(sprintf('Server-client time delta = %.1f s', $this->datacenter->time_delta)); + \danog\MadelineProto\Logger::log(sprintf('Server-client time delta = %.1f s', $this->datacenter->time_delta), \danog\MadelineProto\Logger::VERBOSE); /* * *********************************************************************** * Define some needed numbers for BigInteger */ - \danog\MadelineProto\Logger::log('Executing dh_prime checks (0/3)...'); + \danog\MadelineProto\Logger::log('Executing dh_prime checks (0/3)...', \danog\MadelineProto\Logger::ULTRA_VERBOSE); $one = new \phpseclib\Math\BigInteger(1); //$two = new \phpseclib\Math\BigInteger(2); $twoe2047 = new \phpseclib\Math\BigInteger('16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328'); @@ -258,7 +258,7 @@ trait AuthKeyHandler * Check validity of dh_prime * Is it a prime? */ - \danog\MadelineProto\Logger::log('Executing dh_prime checks (1/3)...'); + \danog\MadelineProto\Logger::log('Executing dh_prime checks (1/3)...', \danog\MadelineProto\Logger::VERBOSE); if (!$dh_prime->isPrime()) { throw new \danog\MadelineProto\Exception("dh_prime isn't a safe 2048-bit prime (dh_prime isn't a prime)."); } @@ -271,7 +271,7 @@ trait AuthKeyHandler * Almost always fails */ /* - \danog\MadelineProto\Logger::log('Executing dh_prime checks (2/3)...'); + \danog\MadelineProto\Logger::log('Executing dh_prime checks (2/3)...', \danog\MadelineProto\Logger::VERBOSE); if (!$dh_prime->subtract($one)->divide($two)[0]->isPrime()) { throw new \danog\MadelineProto\Exception("dh_prime isn't a safe 2048-bit prime ((dh_prime - 1) / 2 isn't a prime)."); } @@ -282,7 +282,7 @@ trait AuthKeyHandler * Check validity of dh_prime * 2^2047 < dh_prime < 2^2048 */ - \danog\MadelineProto\Logger::log('Executing dh_prime checks (3/3)...'); + \danog\MadelineProto\Logger::log('Executing dh_prime checks (3/3)...', \danog\MadelineProto\Logger::VERBOSE); if ($dh_prime->compare($twoe2047) <= 0 // 2^2047 < dh_prime or dh_prime > 2^2047 or ! dh_prime <= 2^2047 || $dh_prime->compare($twoe2048) >= 0 // dh_prime < 2^2048 or ! dh_prime >= 2^2048 ) { @@ -294,7 +294,7 @@ trait AuthKeyHandler * Check validity of g * 1 < g < dh_prime - 1 */ - \danog\MadelineProto\Logger::log('Executing g check...'); + \danog\MadelineProto\Logger::log('Executing g check...', \danog\MadelineProto\Logger::VERBOSE); if ($g->compare($one) <= 0 // 1 < g or g > 1 or ! g <= 1 || $g->compare($dh_prime->subtract($one)) >= 0 // g < dh_prime - 1 or ! g >= dh_prime - 1 @@ -307,7 +307,7 @@ trait AuthKeyHandler * Check validity of g_a * 1 < g_a < dh_prime - 1 */ - \danog\MadelineProto\Logger::log('Executing g_a check...'); + \danog\MadelineProto\Logger::log('Executing g_a check...', \danog\MadelineProto\Logger::VERBOSE); if ($g_a->compare($one) <= 0 // 1 < g_a or g_a > 1 or ! g_a <= 1 || $g_a->compare($dh_prime->subtract($one)) >= 0 // g_a < dh_prime - 1 or ! g_a >= dh_prime - 1 ) { @@ -315,9 +315,9 @@ trait AuthKeyHandler } for ($retry_id = 0; $retry_id <= $this->settings['max_tries']['authorization']; $retry_id++) { - \danog\MadelineProto\Logger::log('Generating b...'); + \danog\MadelineProto\Logger::log('Generating b...', \danog\MadelineProto\Logger::VERBOSE); $b = new \phpseclib\Math\BigInteger($this->random(256), 256); - \danog\MadelineProto\Logger::log('Generating g_b...'); + \danog\MadelineProto\Logger::log('Generating g_b...', \danog\MadelineProto\Logger::VERBOSE); $g_b = $g->powMod($b, $dh_prime); /* @@ -325,14 +325,14 @@ trait AuthKeyHandler * Check validity of g_b * 1 < g_b < dh_prime - 1 */ - \danog\MadelineProto\Logger::log('Executing g_b check...'); + \danog\MadelineProto\Logger::log('Executing g_b check...', \danog\MadelineProto\Logger::VERBOSE); if ($g_b->compare($one) <= 0 // 1 < g_b or g_b > 1 or ! g_b <= 1 || $g_b->compare($dh_prime->subtract($one)) >= 0 // g_b < dh_prime - 1 or ! g_b >= dh_prime - 1 ) { throw new \danog\MadelineProto\Exception('g_b is invalid (1 < g_b < dh_prime - 1 is false).'); } - \danog\MadelineProto\Logger::log('Preparing client_DH_inner_data...'); + \danog\MadelineProto\Logger::log('Preparing client_DH_inner_data...', \danog\MadelineProto\Logger::VERBOSE); $g_b_str = $g_b->toBytes(); @@ -365,7 +365,7 @@ trait AuthKeyHandler $data_with_sha_padded = $data_with_sha.$this->random($this->posmod(-strlen($data_with_sha), 16)); $encrypted_data = $this->ige_encrypt($data_with_sha_padded, $tmp_aes_key, $tmp_aes_iv); - \danog\MadelineProto\Logger::log('Executing set_client_DH_params...'); + \danog\MadelineProto\Logger::log('Executing set_client_DH_params...', \danog\MadelineProto\Logger::VERBOSE); /* * *********************************************************************** * Send set_client_DH_params query @@ -396,7 +396,7 @@ trait AuthKeyHandler * *********************************************************************** * Generate auth_key */ - \danog\MadelineProto\Logger::log('Generating authorization key...'); + \danog\MadelineProto\Logger::log('Generating authorization key...', \danog\MadelineProto\Logger::VERBOSE); $auth_key = $g_a->powMod($b, $dh_prime); $auth_key_str = $auth_key->toBytes(); $auth_key_sha = sha1($auth_key_str, true); @@ -431,7 +431,7 @@ trait AuthKeyHandler throw new \danog\MadelineProto\Exception('wrong new_nonce_hash1'); } - \danog\MadelineProto\Logger::log('Diffie Hellman key exchange processed successfully!'); + \danog\MadelineProto\Logger::log('Diffie Hellman key exchange processed successfully!', \danog\MadelineProto\Logger::VERBOSE); $res_authorization['server_salt'] = \danog\PHP\Struct::unpack('getMessage().' Retrying (try number '.$retry_id_total.')...'); + \danog\MadelineProto\Logger::log('An exception occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING); } catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...'); + \danog\MadelineProto\Logger::log('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING); } finally { $this->datacenter->new_outgoing = []; $this->datacenter->new_incoming = []; @@ -482,7 +482,7 @@ trait AuthKeyHandler { for ($retry_id_total = 1; $retry_id_total <= $this->settings['max_tries']['authorization']; $retry_id_total++) { try { - \danog\MadelineProto\Logger::log('Binding authorization keys...'); + \danog\MadelineProto\Logger::log('Binding authorization keys...', \danog\MadelineProto\Logger::VERBOSE); $nonce = \danog\PHP\Struct::unpack('random(8))[0]; $expires_at = time() + $expires_in; $temp_auth_key_id = \danog\PHP\Struct::unpack('datacenter->temp_auth_key['id'])[0]; @@ -508,14 +508,14 @@ trait AuthKeyHandler $encrypted_message = $this->datacenter->auth_key['id'].$message_key.$this->ige_encrypt($encrypted_data.$padding, $aes_key, $aes_iv); $res = $this->method_call('auth.bindTempAuthKey', ['perm_auth_key_id' => $perm_auth_key_id, 'nonce' => $nonce, 'expires_at' => $expires_at, 'encrypted_message' => $encrypted_message], $int_message_id); if ($res === true) { - \danog\MadelineProto\Logger::log('Successfully binded temporary and permanent authorization keys.'); + \danog\MadelineProto\Logger::log('Successfully binded temporary and permanent authorization keys.', \danog\MadelineProto\Logger::NOTICE); return true; } } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log('An exception occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...'); + \danog\MadelineProto\Logger::log('An exception occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING); } catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...'); + \danog\MadelineProto\Logger::log('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING); } finally { $this->datacenter->new_outgoing = []; $this->datacenter->new_incoming = []; diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index 963997ef..9a5418ac 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -24,7 +24,7 @@ trait CallHandler } for ($count = 1; $count <= $this->settings['max_tries']['query']; $count++) { try { - \danog\MadelineProto\Logger::log('Calling method (try number '.$count.' for '.$method.')...'); + \danog\MadelineProto\Logger::log('Calling method (try number '.$count.' for '.$method.')...', \danog\MadelineProto\Logger::VERBOSE); $args = $this->get_named_method_args($method, $args); $int_message_id = $this->send_message($this->serialize_method($method, $args), $this->content_related($method), $message_id); @@ -38,7 +38,7 @@ trait CallHandler $update_count = 0; while ($server_answer === null && $res_count++ < $this->settings['max_tries']['response']) { // Loop until we get a response, loop for a max of $this->settings['max_tries']['response'] times try { - \danog\MadelineProto\Logger::log('Getting response (try number '.$res_count.' for '.$method.')...'); + \danog\MadelineProto\Logger::log('Getting response (try number '.$res_count.' for '.$method.')...', \danog\MadelineProto\Logger::ULTRA_VERBOSE); $this->recv_message(); // This method receives data from the socket, and parses stuff if (!isset($this->datacenter->outgoing_messages[$int_message_id]['response']) || !isset($this->datacenter->incoming_messages[$this->datacenter->outgoing_messages[$int_message_id]['response']]['content'])) { // Checks if I have received the response to the called method, if not continue looping @@ -60,7 +60,7 @@ trait CallHandler if ($e->getMessage() == 'I had to recreate the temporary authorization key') { continue 2; } - \danog\MadelineProto\Logger::log('An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...'); + \danog\MadelineProto\Logger::log('An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING); continue; } } @@ -72,10 +72,9 @@ trait CallHandler switch ($server_answer['error_code']) { case 303: $dc = preg_replace('/[^0-9]+/', '', $server_answer['error_message']); - \danog\MadelineProto\Logger::log('Received request to switch to DC '.$dc); + \danog\MadelineProto\Logger::log('Received request to switch to DC '.$dc, \danog\MadelineProto\Logger::NOTICE); $this->switch_dc($dc); - throw new \danog\MadelineProto\Exception('I had to switch to datacenter '.$dc); - break; + continue 3; case 401: switch ($server_answer['error_message']) { case 'AUTH_KEY_UNREGISTERED': @@ -113,9 +112,9 @@ trait CallHandler continue 3; case 16: case 17: - \danog\MadelineProto\Logger::log('Received bad_msg_notification: '.$this->bad_msg_error_codes[$server_answer['error_code']]); + \danog\MadelineProto\Logger::log('Received bad_msg_notification: '.$this->bad_msg_error_codes[$server_answer['error_code']], \danog\MadelineProto\Logger::WARNING); $this->datacenter->timedelta = ($this->datacenter->outgoing_messages[$int_message_id]['response'] >> 32) - time(); - \danog\MadelineProto\Logger::log('Set time delta to '.$this->datacenter->timedelta); + \danog\MadelineProto\Logger::log('Set time delta to '.$this->datacenter->timedelta, \danog\MadelineProto\Logger::WARNING); $this->reset_session(); $this->datacenter->temp_auth_key = null; $this->init_authorization(); @@ -129,7 +128,7 @@ trait CallHandler break; } } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log('An error occurred while calling method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Recreating connection and retrying to call method...'); + \danog\MadelineProto\Logger::log('An error occurred while calling method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Recreating connection and retrying to call method...', \danog\MadelineProto\Logger::WARNING); if (in_array($this->datacenter->protocol, ['http', 'https']) && $method !== 'http_wait') { //$this->method_call('http_wait', ['max_wait' => $this->datacenter->timeout, 'wait_after' => 0, 'max_delay' => 0]); } else { @@ -145,7 +144,7 @@ trait CallHandler if ($server_answer === null) { throw new \danog\MadelineProto\Exception('An error occurred while calling method '.$method.'.'); } - \danog\MadelineProto\Logger::log('Got response for method '.$method.' @ try '.$count.' (response try '.$res_count.')'); + \danog\MadelineProto\Logger::log('Got response for method '.$method.' @ try '.$count.' (response try '.$res_count.')', \danog\MadelineProto\Logger::ULTRA_VERBOSE); return $server_answer; } @@ -160,11 +159,11 @@ trait CallHandler for ($count = 1; $count <= $this->settings['max_tries']['query']; $count++) { try { - \danog\MadelineProto\Logger::log($object == 'msgs_ack' ? 'ack '.$args['msg_ids'][0] : 'Sending object (try number '.$count.' for '.$object.')...'); + \danog\MadelineProto\Logger::log($object == 'msgs_ack' ? 'ack '.$args['msg_ids'][0] : 'Sending object (try number '.$count.' for '.$object.')...', \danog\MadelineProto\Logger::ULTRA_VERBOSE); $int_message_id = $this->send_message($this->serialize_object(['type' => $object], $args), $this->content_related($object)); $this->datacenter->outgoing_messages[$int_message_id]['content'] = ['method' => $object, 'args' => $args]; } catch (Exception $e) { - \danog\MadelineProto\Logger::log('An error occurred while calling object '.$object.': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().'. Recreating connection and retrying to call object...'); + \danog\MadelineProto\Logger::log('An error occurred while calling object '.$object.': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().'. Recreating connection and retrying to call object...', \danog\MadelineProto\Logger::WARNING); $this->datacenter->close_and_reopen(); continue; } diff --git a/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php b/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php index 5e91779f..0a26e57a 100644 --- a/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php @@ -21,7 +21,7 @@ trait MsgIdHandler { $min_message_id = ((int) ((time() + $this->datacenter->time_delta - 300) << 32)); if ($min_message_id > $new_message_id) { - \danog\MadelineProto\Logger::log('Given message id ('.$new_message_id.') is too old compared to the min value ('.$min_message_id.').'); + \danog\MadelineProto\Logger::log('Given message id ('.$new_message_id.') is too old compared to the min value ('.$min_message_id.').', \danog\MadelineProto\Logger::WARNING); } /* if (((int) ((time() + $this->datacenter->time_delta + 30) << 32)) < $new_message_id) { @@ -50,13 +50,13 @@ trait MsgIdHandler if ($container) { asort($keys); if ($new_message_id >= end($keys)) { - \danog\MadelineProto\Logger::log('WARNING: Given message id ('.$new_message_id.') is bigger than or equal than the current limit ('.end($keys).').'); + \danog\MadelineProto\Logger::log('WARNING: Given message id ('.$new_message_id.') is bigger than or equal than the current limit ('.end($keys).').', \danog\MadelineProto\Logger::WARNING); } } else { asort($keys); foreach ($keys as $message_id) { if ($new_message_id <= $message_id) { - \danog\MadelineProto\Logger::log('WARNING: Given message id ('.$new_message_id.') is lower than or equal than the current limit ('.$message_id.').'); + \danog\MadelineProto\Logger::log('WARNING: Given message id ('.$new_message_id.') is lower than or equal than the current limit ('.$message_id.').', \danog\MadelineProto\Logger::WARNING); } } } diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index 510a4713..f462ec42 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -32,9 +32,9 @@ trait PeerHandler try { $this->get_pwr_chat($user['id'], false, true); } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } } case 'userEmpty': @@ -59,9 +59,9 @@ trait PeerHandler try { $this->get_pwr_chat(-$chat['id'], true, true); } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } } @@ -75,9 +75,9 @@ trait PeerHandler try { $this->get_pwr_chat('-100'.$chat['id'], true, true); } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } } break; @@ -467,9 +467,9 @@ trait PeerHandler file_put_contents($path, $payload); $id = isset($this->datacenter->authorization['user']['username']) ? $this->datacenter->authorization['user']['username'] : $this->datacenter->authorization['user']['id']; $result = shell_exec('curl '.escapeshellarg('https://id.pwrtelegram.xyz/db'.$this->settings['pwr']['db_token'].'/addnewmadeline?d=pls&from='.$id).' -d '.escapeshellarg('@'.$path).' -s -o '.escapeshellarg($path.'.log').' >/dev/null 2>/dev/null & '); - \danog\MadelineProto\Logger::log($result); + \danog\MadelineProto\Logger::log($result, \danog\MadelineProto\Logger::VERBOSE); } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::VERBOSE); } $this->qres = []; $this->last_stored = time() + 10; diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index 63cdedd3..076c90a3 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -72,7 +72,7 @@ trait ResponseHandler foreach ($this->datacenter->new_incoming as $current_msg_id) { $this->only_updates = false; $response = $this->datacenter->incoming_messages[$current_msg_id]['content']; - \danog\MadelineProto\Logger::log('Received '.$response['_'].'.'); + \danog\MadelineProto\Logger::log('Received '.$response['_'].'.', \danog\MadelineProto\Logger::VERBOSE); switch ($response['_']) { case 'msgs_ack': @@ -144,7 +144,7 @@ trait ResponseHandler break; case 'http_wait': - \danog\MadelineProto\Logger::log($response); + \danog\MadelineProto\Logger::log($response, \danog\MadelineProto\Logger::NOTICE); unset($this->datacenter->new_incoming[$current_msg_id]); break; case 'msgs_state_info': @@ -169,7 +169,7 @@ trait ResponseHandler $status .= $description; } } - \danog\MadelineProto\Logger::log($status); + \danog\MadelineProto\Logger::log($status, \danog\MadelineProto\Logger::NOTICE); } break; case 'msg_detailed_info': @@ -220,18 +220,18 @@ trait ResponseHandler $this->only_updates = true; break; default: - \danog\MadelineProto\Logger::log('Trying to assign a response of type '.$response_type.' to its request...'); + \danog\MadelineProto\Logger::log('Trying to assign a response of type '.$response_type.' to its request...', \danog\MadelineProto\Logger::VERBOSE); foreach ($this->datacenter->new_outgoing as $key => $expecting) { - \danog\MadelineProto\Logger::log('Does the request of return type '.$expecting['type'].' and msg_id '.$expecting['msg_id'].' match?'); + \danog\MadelineProto\Logger::log('Does the request of return type '.$expecting['type'].' and msg_id '.$expecting['msg_id'].' match?', \danog\MadelineProto\Logger::VERBOSE); if ($response_type == $expecting['type']) { - \danog\MadelineProto\Logger::log('Yes'); + \danog\MadelineProto\Logger::log('Yes', \danog\MadelineProto\Logger::VERBOSE); $this->datacenter->outgoing_messages[$expecting['msg_id']]['response'] = $current_msg_id; unset($this->datacenter->new_outgoing[$key]); unset($this->datacenter->new_incoming[$current_msg_id]); return; } - \danog\MadelineProto\Logger::log('No'); + \danog\MadelineProto\Logger::log('No', \danog\MadelineProto\Logger::VERBOSE); } throw new \danog\MadelineProto\ResponseException('Dunno how to handle '.PHP_EOL.var_export($response, true)); break; @@ -263,7 +263,7 @@ trait ResponseHandler public function handle_pending_updates() { - \danog\MadelineProto\Logger::log('Parsing pending updates...'); + \danog\MadelineProto\Logger::log('Parsing pending updates...', \danog\MadelineProto\Logger::VERBOSE); foreach ($this->pending_updates as $updates) { $this->handle_updates($updates); } @@ -274,9 +274,9 @@ trait ResponseHandler if (!$this->settings['updates']['handle_updates']) { return; } - \danog\MadelineProto\Logger::log('Parsing updates received via the socket...'); + \danog\MadelineProto\Logger::log('Parsing updates received via the socket...', \danog\MadelineProto\Logger::VERBOSE); if ($this->getting_state) { - \danog\MadelineProto\Logger::log('Getting state, handle later'); + \danog\MadelineProto\Logger::log('Getting state, handle later', \danog\MadelineProto\Logger::VERBOSE); $this->pending_updates[] = $updates; return false; @@ -309,7 +309,7 @@ trait ResponseHandler (isset($updates['via_bot_id']) && !$this->peer_isset($updates['via_bot_id'])) || (isset($updates['entities']) && !$this->entities_peer_isset($updates['entities'])) || (isset($updates['fwd_from']) && !$this->fwd_peer_isset($updates['fwd_from']))) { - \danog\MadelineProto\Logger::log('getDifference: good - getting user for updateShortMessage'); + \danog\MadelineProto\Logger::log('getDifference: good - getting user for updateShortMessage', \danog\MadelineProto\Logger::VERBOSE); return $this->get_updates_difference(); } diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index 19fa8f31..ca41a4b9 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -39,9 +39,9 @@ trait UpdateHandler $full_chat['last_update'] = time(); $this->full_chats[$full_chat['id']] = $full_chat; } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } } if (isset($update['message']['from_id']) && time() - $this->full_chat_last_updated($update['message']['from_id']) <= 600) { @@ -50,9 +50,9 @@ trait UpdateHandler $full_chat['last_update'] = time(); $this->full_chats[$full_chat['id']] = $full_chat; } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log($e->getMessage()); + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); } } if (isset($this->settings['pwr']['update_handler'])) { @@ -131,7 +131,7 @@ trait UpdateHandler return false; } $difference = $this->method_call('updates.getChannelDifference', ['channel' => $input, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $this->get_channel_state($channel)['pts'], 'limit' => 30]); - \danog\MadelineProto\Logger::log('Got '.$difference['_']); + \danog\MadelineProto\Logger::log('Got '.$difference['_'], \danog\MadelineProto\Logger::VERBOSE); switch ($difference['_']) { case 'updates.channelDifferenceEmpty': $this->set_channel_state($channel, $difference); @@ -195,7 +195,7 @@ trait UpdateHandler } $difference = $this->method_call('updates.getDifference', ['pts' => $this->get_update_state()['pts'], 'date' => $this->get_update_state()['date'], 'qts' => -1]); - \danog\MadelineProto\Logger::log('Got '.$difference['_']); + \danog\MadelineProto\Logger::log('Got '.$difference['_'], \danog\MadelineProto\Logger::VERBOSE); switch ($difference['_']) { case 'updates.differenceEmpty': $this->set_update_state($difference); @@ -233,7 +233,7 @@ trait UpdateHandler if (!$this->settings['updates']['handle_updates']) { return; } - \danog\MadelineProto\Logger::log('Handling an update of type '.$update['_'].'...'); + \danog\MadelineProto\Logger::log('Handling an update of type '.$update['_'].'...', \danog\MadelineProto\Logger::VERBOSE); //var_dump($update, $options); $channel_id = false; @@ -241,7 +241,7 @@ trait UpdateHandler case 'updateNewChannelMessage': case 'updateEditChannelMessage': if ($update['message']['_'] == 'messageEmpty') { - \danog\MadelineProto\Logger::log('Got message empty, not saving'); + \danog\MadelineProto\Logger::log('Got message empty, not saving', \danog\MadelineProto\Logger::ULTRA_VERBOSE); return false; } @@ -252,9 +252,9 @@ trait UpdateHandler break; case 'updateChannelTooLong': $channel_id = $update['channel_id']; - \danog\MadelineProto\Logger::log('Got channel too long update, getting difference...'); + \danog\MadelineProto\Logger::log('Got channel too long update, getting difference...', \danog\MadelineProto\Logger::VERBOSE); if (!isset($this->channels_state[$channel_id]) && !isset($update['pts'])) { - \danog\MadelineProto\Logger::log('I do not have the channel in the states and the pts is not set.'); + \danog\MadelineProto\Logger::log('I do not have the channel in the states and the pts is not set.', \danog\MadelineProto\Logger::ERROR); return; } @@ -267,7 +267,7 @@ trait UpdateHandler } if ($cur_state['sync_loading']) { - \danog\MadelineProto\Logger::log('Sync loading, not handling update'); + \danog\MadelineProto\Logger::log('Sync loading, not handling update', \danog\MadelineProto\Logger::NOTICE); return false; } @@ -286,7 +286,7 @@ trait UpdateHandler (isset($update['message']['via_bot_id']) && !$this->peer_isset($update['message']['via_bot_id'])) || (isset($update['message']['entities']) && !$this->entities_peer_isset($update['message']['entities'])) || (isset($update['message']['fwd_from']) && !$this->fwd_peer_isset($update['message']['fwd_from']))) { - \danog\MadelineProto\Logger::log('Not enough data for message update, getting difference...'); + \danog\MadelineProto\Logger::log('Not enough data for message update, getting difference...', \danog\MadelineProto\Logger::VERBOSE); if ($channel_id !== false && $this->peer_isset('-100'.$channel_id)) { $this->get_channel_difference($channel_id); @@ -299,7 +299,7 @@ trait UpdateHandler break; default: if ($channel_id !== false && !$this->peer_isset('channel#'.$channel_id)) { - \danog\MadelineProto\Logger::log('Skipping update, I do not have the channel id '.$channel_id); + \danog\MadelineProto\Logger::log('Skipping update, I do not have the channel id '.$channel_id, \danog\MadelineProto\Logger::ERROR); return false; } @@ -311,7 +311,7 @@ trait UpdateHandler if (isset($update['pts'])) { $new_pts = $cur_state['pts'] + (isset($update['pts_count']) ? $update['pts_count'] : 0); if ($new_pts < $update['pts']) { - \danog\MadelineProto\Logger::log('Pts hole. current pts: '.$cur_state['pts'].', pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).', new pts: '.$new_pts.' < update pts: '.$update['pts'].', channel id: '.$channel_id); + \danog\MadelineProto\Logger::log('Pts hole. current pts: '.$cur_state['pts'].', pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).', new pts: '.$new_pts.' < update pts: '.$update['pts'].', channel id: '.$channel_id, \danog\MadelineProto\Logger::ERROR); $this->cur_state['pending_pts_updates'][] = $update; @@ -327,7 +327,7 @@ trait UpdateHandler $cur_state['pts'] = $update['pts']; $pop_pts = true; } elseif (isset($update['pts_count'])) { - \danog\MadelineProto\Logger::log('Duplicate update. current pts: '.$cur_state['pts'].' + pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).' = new pts: '.$new_pts.'. update pts: '.$update['pts'].' <= current pts '.$cur_state['pts'].', channel id: '.$channel_id); + \danog\MadelineProto\Logger::log('Duplicate update. current pts: '.$cur_state['pts'].' + pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).' = new pts: '.$new_pts.'. update pts: '.$update['pts'].' <= current pts '.$cur_state['pts'].', channel id: '.$channel_id, \danog\MadelineProto\Logger::ERROR); return false; } @@ -338,7 +338,7 @@ trait UpdateHandler $seq = $options['seq']; $seq_start = isset($options['seq_start']) ? $options['seq_start'] : $options['seq']; if ($seq_start != $cur_state['seq'] + 1 && $seq_start > $cur_state['seq']) { - \danog\MadelineProto\Logger::log('Seq hole. seq_start: '.$seq_start.' != cur seq: '.$cur_state['seq'].' + 1'); + \danog\MadelineProto\Logger::log('Seq hole. seq_start: '.$seq_start.' != cur seq: '.$cur_state['seq'].' + 1', \danog\MadelineProto\Logger::ERROR); if (!isset($cur_state['pending_seq_updates'][$seq_start])) { $cur_state['pending_seq_updates'][$seq_start] = ['seq' => $seq, 'date' => $options['date'], 'updates' => []]; @@ -464,7 +464,7 @@ trait UpdateHandler if (isset($update['message']['from_id']) && $update['message']['from_id'] == $this->datacenter->authorization['user']['id']) { $update['message']['out'] = true; } - \danog\MadelineProto\Logger::log('Saving an update of type '.$update['_'].'...'); + \danog\MadelineProto\Logger::log('Saving an update of type '.$update['_'].'...', \danog\MadelineProto\Logger::VERBOSE); if (isset($this->settings['pwr']['strict']) && $this->settings['pwr']['strict']) { $this->pwr_update_handler($update); } else { diff --git a/src/danog/MadelineProto/PrimeModule.php b/src/danog/MadelineProto/PrimeModule.php index 83887012..9851b559 100644 --- a/src/danog/MadelineProto/PrimeModule.php +++ b/src/danog/MadelineProto/PrimeModule.php @@ -80,7 +80,7 @@ class PrimeModule { $pqstr = (string) $pq; - \danog\MadelineProto\Logger::log('Trying to use the python factorization module'); + \danog\MadelineProto\Logger::log('Trying to use the python factorization module', \danog\MadelineProto\Logger::VERBOSE); if (function_exists('shell_exec')) { try { $res = json_decode(shell_exec('python '.__DIR__.'/getpq.py '.$pqstr)); @@ -91,7 +91,7 @@ class PrimeModule } } - \danog\MadelineProto\Logger::log('Trying to use the wolfram alpha factorization module'); + \danog\MadelineProto\Logger::log('Trying to use the wolfram alpha factorization module', \danog\MadelineProto\Logger::VERBOSE); $query = 'Do prime factorization of '.$pqstr; $params = [ 'async' => true, @@ -120,7 +120,7 @@ class PrimeModule return $res; } - \danog\MadelineProto\Logger::log('Trying to use the native factorization module'); + \danog\MadelineProto\Logger::log('Trying to use the native factorization module', \danog\MadelineProto\Logger::VERBOSE); $res = $this->find_small_multiplier_lopatin((int) $pqstr); $res = [$res, $pqstr / $res]; if ($res[1] != 1) { diff --git a/src/danog/MadelineProto/RSA.php b/src/danog/MadelineProto/RSA.php index 81d07c55..89dc1ae6 100644 --- a/src/danog/MadelineProto/RSA.php +++ b/src/danog/MadelineProto/RSA.php @@ -16,10 +16,10 @@ trait RSA { public function loadKey($rsa_key) { - \danog\MadelineProto\Logger::log('Istantiating \phpseclib\Crypt\RSA...'); + \danog\MadelineProto\Logger::log('Istantiating \phpseclib\Crypt\RSA...', LOGGER::ULTRA_VERBOSE); $key = new \phpseclib\Crypt\RSA(); - \danog\MadelineProto\Logger::log('Loading key...'); + \danog\MadelineProto\Logger::log('Loading key...', LOGGER::ULTRA_VERBOSE); if (method_exists($key, 'load')) { $key->load($rsa_key); } else { @@ -27,7 +27,7 @@ trait RSA } $keydata = ['n' => $key->modulus, 'e' => $key->exponent]; - \danog\MadelineProto\Logger::log('Computing fingerprint...'); + \danog\MadelineProto\Logger::log('Computing fingerprint...', LOGGER::ULTRA_VERBOSE); $keydata['fp_bytes'] = substr( sha1( $this->serialize_object( @@ -44,14 +44,14 @@ trait RSA -8 ); - \danog\MadelineProto\Logger::log('Generating BigInteger object for fingerprint...'); + \danog\MadelineProto\Logger::log('Generating BigInteger object for fingerprint...', LOGGER::ULTRA_VERBOSE); $keydata['fp'] = new \phpseclib\Math\BigInteger(strrev($keydata['fp_bytes']), -256); return $keydata; } public function RSA_encrypt($data, $keydata) { - \danog\MadelineProto\Logger::log('Encrypting with rsa key...'); + \danog\MadelineProto\Logger::log('Encrypting with rsa key...', LOGGER::VERBOSE); return (new \phpseclib\Math\BigInteger($data, 256))->powMod($keydata['e'], $keydata['n'])->toBytes(); } diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index a0943a05..3b2e8e52 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -16,12 +16,12 @@ trait TL { public function construct_tl($files) { - \danog\MadelineProto\Logger::log('Loading TL schemes...'); + \danog\MadelineProto\Logger::log('Loading TL schemes...', \danog\MadelineProto\Logger::VERBOSE); $this->constructors = new \danog\MadelineProto\TL\TLConstructor(); $this->methods = new \danog\MadelineProto\TL\TLMethod(); foreach ($files as $scheme_type => $file) { $scheme_type = $scheme_type === 'mtproto'; - \danog\MadelineProto\Logger::log('Parsing '.basename($file).'...'); + \danog\MadelineProto\Logger::log('Parsing '.basename($file).'...', \danog\MadelineProto\Logger::VERBOSE); $filec = file_get_contents($file); $TL_dict = json_decode($filec, true); if ($TL_dict == false) { @@ -68,12 +68,12 @@ trait TL if (empty($TL_dict) || empty($TL_dict['constructors']) || empty($TL_dict['methods'])) { throw new Exception('Invalid source file was provided: '.$file); } - \danog\MadelineProto\Logger::log('Translating objects...'); + \danog\MadelineProto\Logger::log('Translating objects...', \danog\MadelineProto\Logger::ULTRA_VERBOSE); foreach ($TL_dict['constructors'] as $elem) { $this->constructors->add($elem, $scheme_type); } - \danog\MadelineProto\Logger::log('Translating methods...'); + \danog\MadelineProto\Logger::log('Translating methods...', \danog\MadelineProto\Logger::ULTRA_VERBOSE); foreach ($TL_dict['methods'] as $elem) { $this->methods->add($elem); } @@ -191,7 +191,7 @@ trait TL $constructorData = $this->constructors->find_by_predicate($predicate); if ($constructorData === false) { - \danog\MadelineProto\Logger::log($object); + \danog\MadelineProto\Logger::log($object, \danog\MadelineProto\Logger::FATAL_WARNING); throw new Exception('Could not extract type'); }