Use non-static logger

This commit is contained in:
Daniil Gentili 2018-04-08 17:53:30 +00:00
parent 73e97fc620
commit c97aced309
25 changed files with 267 additions and 266 deletions

View File

@ -25,7 +25,7 @@ trait Constructors
}
mkdir('constructors');
$this->docs_constructors = [];
\danog\MadelineProto\Logger::log('Generating constructors documentation...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Generating constructors documentation...', \danog\MadelineProto\Logger::NOTICE);
$got = [];
foreach ($this->constructors->by_predicate_and_layer as $predicate => $id) {
$data = $this->constructors->by_id[$id];
@ -268,7 +268,7 @@ MadelineProto supports all html entities supported by [html_entity_decode](http:
}
file_put_contents('constructors/'.$constructor.$layer.'.md', $header.$table.$type.$example);
}
\danog\MadelineProto\Logger::log('Generating constructors index...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Generating constructors index...', \danog\MadelineProto\Logger::NOTICE);
ksort($this->docs_constructors);
$last_namespace = '';
foreach ($this->docs_constructors as $constructor => &$value) {

View File

@ -29,7 +29,7 @@ trait Methods
mkdir('methods');
$this->docs_methods = [];
$this->human_docs_methods = [];
\danog\MadelineProto\Logger::log('Generating methods documentation...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Generating methods documentation...', \danog\MadelineProto\Logger::NOTICE);
foreach ($this->methods->by_id as $id => $data) {
$method = str_replace('.', '_', $data['method']);
$php_method = str_replace('.', '->', $data['method']);
@ -310,7 +310,7 @@ MadelineProto supports all html entities supported by [html_entity_decode](http:
}
file_put_contents('methods/'.$method.'.md', $header.$table.$return.$example);
}
\danog\MadelineProto\Logger::log('Generating methods index...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Generating methods index...', \danog\MadelineProto\Logger::NOTICE);
ksort($this->docs_methods);
ksort($this->human_docs_methods);
$last_namespace = '';

View File

@ -122,12 +122,12 @@ class MTProto
}
$this->emojis = json_decode(self::JSON_EMOJIS);
// Connect to servers
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['inst_dc'], Logger::ULTRA_VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['inst_dc'], Logger::ULTRA_VERBOSE);
if (!isset($this->datacenter)) {
$this->datacenter = new DataCenter($this->settings['connection'], $this->settings['connection_settings']);
}
// Load rsa keys
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['load_rsa'], Logger::ULTRA_VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['load_rsa'], Logger::ULTRA_VERBOSE);
foreach ($this->settings['authorization']['rsa_keys'] as $key) {
$key = new RSA($key);
$this->rsa_keys[$key->fp] = $key;
@ -136,7 +136,7 @@ class MTProto
* ***********************************************************************
* Define some needed numbers for BigInteger
*/
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['dh_prime_check_0'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['dh_prime_check_0'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->zero = new \phpseclib\Math\BigInteger(0);
$this->one = new \phpseclib\Math\BigInteger(1);
$this->two = new \phpseclib\Math\BigInteger(2);
@ -147,14 +147,14 @@ class MTProto
$this->twoe2048 = new \phpseclib\Math\BigInteger('32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656');
$this->twozerotwosixone = new \phpseclib\Math\BigInteger(20261);
$this->zeroeight = new \phpseclib\Math\BigInteger('2147483648');
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['TL_translation'], Logger::ULTRA_VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['TL_translation'], Logger::ULTRA_VERBOSE);
$this->construct_TL($this->settings['tl_schema']['src']);
$this->connect_to_all_dcs();
$this->datacenter->curdc = 2;
if (!isset($this->authorization['user']['bot']) || !$this->authorization['user']['bot']) {
try {
$nearest_dc = $this->method_call('help.getNearestDc', [], ['datacenter' => $this->datacenter->curdc]);
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['nearest_dc'], $nearest_dc['country'], $nearest_dc['nearest_dc']), Logger::NOTICE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['nearest_dc'], $nearest_dc['country'], $nearest_dc['nearest_dc']), Logger::NOTICE);
if ($nearest_dc['nearest_dc'] != $nearest_dc['this_dc']) {
$this->settings['connection_settings']['default_dc'] = $this->datacenter->curdc = (int) $nearest_dc['nearest_dc'];
}
@ -225,13 +225,13 @@ class MTProto
$backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 3);
if (isset($backtrace[2]['function']) && isset($backtrace[2]['class']) && isset($backtrace[2]['args']) && $backtrace[2]['class'] === 'danog\\MadelineProto\\API' && $backtrace[2]['function'] === '__magic_construct') {
if (count($backtrace[2]['args']) === 2) {
Logger::log('Updating settings on wakeup');
$this->logger->logger('Updating settings on wakeup');
$this->parse_settings(array_replace_recursive($this->settings, $backtrace[2]['args'][1]));
}
//$this->wrapper = $backtrace[2]['object'];
}
if (!isset($this->v) || $this->v !== self::V) {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['serialization_ofd'], Logger::WARNING);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['serialization_ofd'], Logger::WARNING);
foreach ($this->datacenter->sockets as $dc_id => $socket) {
if ($this->authorized === self::LOGGED_IN && strpos($dc_id, '_') === false && $socket->auth_key !== null && $socket->temp_auth_key !== null) {
$socket->authorized = true;
@ -329,7 +329,7 @@ class MTProto
$this->get_dialogs($force);
}
if ($this->authorized === self::LOGGED_IN && $this->settings['updates']['handle_updates'] && !$this->updates_state['sync_loading']) {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['getupdates_deserialization'], Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['getupdates_deserialization'], Logger::NOTICE);
$this->get_updates_difference();
}
}
@ -593,6 +593,7 @@ class MTProto
Exception::$rollbar = false;
RPCErrorException::$rollbar = false;
}
$this->logger = new \danog\MadelineProto\Logger($this->settings['logger']['logger'], $this->settings['logger']['logger_param'], isset($this->authorization['user']) ? isset($this->authorization['user']['username']) ? $this->authorization['user']['username'] : $this->authorization['user']['id'] : '', isset($this->settings['logger']['logger_level']) ? $this->settings['logger']['logger_level'] : Logger::VERBOSE);
\danog\MadelineProto\Logger::constructor($this->settings['logger']['logger'], $this->settings['logger']['logger_param'], isset($this->authorization['user']) ? isset($this->authorization['user']['username']) ? $this->authorization['user']['username'] : $this->authorization['user']['id'] : '', isset($this->settings['logger']['logger_level']) ? $this->settings['logger']['logger_level'] : Logger::VERBOSE);
}
@ -603,7 +604,7 @@ class MTProto
}
foreach ($this->datacenter->sockets as $id => $socket) {
if ($de) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['reset_session_seqno'], $id), Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['reset_session_seqno'], $id), Logger::VERBOSE);
$socket->session_id = $this->random(8);
$socket->session_in_seq_no = 0;
$socket->session_out_seq_no = 0;
@ -668,7 +669,7 @@ class MTProto
$this->rsa_keys[$tempkey->fp] = $tempkey;
}
} catch (\danog\MadelineProto\TL\Exception $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::FATAL_ERROR);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::FATAL_ERROR);
}
}
@ -678,8 +679,8 @@ class MTProto
$this->parse_dc_options($this->config['dc_options']);
unset($this->config['dc_options']);
}
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['config_updated'], Logger::NOTICE);
\danog\MadelineProto\Logger::log($this->config, Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['config_updated'], Logger::NOTICE);
$this->logger->logger($this->config, Logger::NOTICE);
}
public function parse_dc_options($dc_options)
@ -707,7 +708,7 @@ class MTProto
$this->settings['connection'][$test][$ipv6][$id] = $dc;
}
$curdc = $this->datacenter->curdc;
\danog\MadelineProto\Logger::log('Got new DC options, reconnecting');
$this->logger->logger('Got new DC options, reconnecting');
$this->connect_to_all_dcs();
$this->datacenter->curdc = $curdc;
}
@ -717,7 +718,7 @@ class MTProto
try {
$this->authorization = ['user' => $this->method_call('users.getUsers', ['id' => [['_' => 'inputUserSelf']]], ['datacenter' => $this->datacenter->curdc])[0]];
} catch (RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage());
$this->logger->logger($e->getMessage());
return false;
}

View File

@ -22,7 +22,7 @@ trait AckHandler
{
// The server acknowledges that it received my message
if (!isset($this->datacenter->sockets[$datacenter]->outgoing_messages[$message_id])) {
\danog\MadelineProto\Logger::log("WARNING: Couldn't find message id ".$message_id.' in the array of outgoing messages. Maybe try to increase its size?', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger("WARNING: Couldn't find message id ".$message_id.' in the array of outgoing messages. Maybe try to increase its size?', \danog\MadelineProto\Logger::WARNING);
return false;
}
@ -34,7 +34,7 @@ trait AckHandler
{
// I let the server know that I received its message
if (!isset($this->datacenter->sockets[$datacenter]->incoming_messages[$message_id])) {
\danog\MadelineProto\Logger::log("WARNING: Couldn't find message id ".$message_id.' in the array of incomgoing messages. Maybe try to increase its size?', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger("WARNING: Couldn't find message id ".$message_id.' in the array of incomgoing messages. Maybe try to increase its size?', \danog\MadelineProto\Logger::WARNING);
//throw new \danog\MadelineProto\Exception("Couldn't find message id ".$message_id.' in the array of incoming message ids. Maybe try to increase its size?');
}
if ($this->datacenter->sockets[$datacenter]->temp_auth_key['id'] === null || $this->datacenter->sockets[$datacenter]->temp_auth_key['id'] === "\0\0\0\0\0\0\0\0") {

View File

@ -26,7 +26,7 @@ trait AuthKeyHandler
$req_pq = strpos($datacenter, 'cdn') ? 'req_pq' : 'req_pq_multi';
for ($retry_id_total = 1; $retry_id_total <= $this->settings['max_tries']['authorization']; $retry_id_total++) {
try {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['req_pq'], \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['req_pq'], \danog\MadelineProto\Logger::VERBOSE);
/**
* ***********************************************************************
* Make pq request, DH exchange initiation.
@ -81,7 +81,7 @@ trait AuthKeyHandler
}
}
if (!$pq->equals($p->multiply($q))) {
\danog\MadelineProto\Logger::log('Automatic factorization failed, trying native CPP module', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Automatic factorization failed, trying native CPP module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::native_single_cpp($pq->__toString()));
if (!$p->equals($this->zero)) {
$q = $pq->divide($p)[0];
@ -91,7 +91,7 @@ trait AuthKeyHandler
}
if (!$pq->equals($p->multiply($q))) {
\danog\MadelineProto\Logger::log('Automatic factorization failed, trying alt py module', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Automatic factorization failed, trying alt py module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::python_single_alt($pq->__toString()));
if (!$p->equals($this->zero)) {
$q = $pq->divide($p)[0];
@ -101,7 +101,7 @@ trait AuthKeyHandler
}
if (!$pq->equals($p->multiply($q))) {
\danog\MadelineProto\Logger::log('Automatic factorization failed, trying py module', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Automatic factorization failed, trying py module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::python_single($pq->__toString()));
if (!$p->equals($this->zero)) {
$q = $pq->divide($p)[0];
@ -111,7 +111,7 @@ trait AuthKeyHandler
}
if (!$pq->equals($p->multiply($q))) {
\danog\MadelineProto\Logger::log('Automatic factorization failed, trying native module', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Automatic factorization failed, trying native module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::native_single($pq->__toString()));
if (!$p->equals($this->zero)) {
$q = $pq->divide($p)[0];
@ -121,7 +121,7 @@ trait AuthKeyHandler
}
if (!$pq->equals($p->multiply($q))) {
\danog\MadelineProto\Logger::log('Automatic factorization failed, trying wolfram module', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Automatic factorization failed, trying wolfram module', \danog\MadelineProto\Logger::ERROR);
if (!extension_loaded('curl')) {
throw new Exception(['extension', 'curl']);
}
@ -143,7 +143,7 @@ trait AuthKeyHandler
}
}
\danog\MadelineProto\Logger::log('Factorization '.$pq.' = '.$p.' * '.$q, \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Factorization '.$pq.' = '.$p.' * '.$q, \danog\MadelineProto\Logger::VERBOSE);
/*
* ***********************************************************************
* Serialize object for req_DH_params
@ -161,7 +161,7 @@ trait AuthKeyHandler
$random_bytes = $this->random(255 - strlen($p_q_inner_data) - strlen($sha_digest));
$to_encrypt = $sha_digest.$p_q_inner_data.$random_bytes;
$encrypted_data = $key->encrypt($to_encrypt);
\danog\MadelineProto\Logger::log('Starting Diffie Hellman key exchange', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Starting Diffie Hellman key exchange', \danog\MadelineProto\Logger::VERBOSE);
/*
* ***********************************************************************
* Starting Diffie Hellman key exchange, Server authentication
@ -255,13 +255,13 @@ trait AuthKeyHandler
*/
$server_time = $server_DH_inner_data['server_time'];
$this->datacenter->sockets[$datacenter]->time_delta = $server_time - time();
\danog\MadelineProto\Logger::log(sprintf('Server-client time delta = %.1f s', $this->datacenter->sockets[$datacenter]->time_delta), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf('Server-client time delta = %.1f s', $this->datacenter->sockets[$datacenter]->time_delta), \danog\MadelineProto\Logger::VERBOSE);
$this->check_p_g($dh_prime, $g);
$this->check_G($g_a, $dh_prime);
for ($retry_id = 0; $retry_id <= $this->settings['max_tries']['authorization']; $retry_id++) {
\danog\MadelineProto\Logger::log('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('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::VERBOSE);
$this->logger->logger('Generating g_b...', \danog\MadelineProto\Logger::VERBOSE);
$g_b = $g->powMod($b, $dh_prime);
$this->check_G($g_b, $dh_prime);
/*
@ -269,11 +269,11 @@ trait AuthKeyHandler
* Check validity of g_b
* 1 < g_b < dh_prime - 1
*/
\danog\MadelineProto\Logger::log('Executing g_b check...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Executing g_b check...', \danog\MadelineProto\Logger::VERBOSE);
if ($g_b->compare($this->one) <= 0 || $g_b->compare($dh_prime->subtract($this->one)) >= 0) {
throw new \danog\MadelineProto\SecurityException('g_b is invalid (1 < g_b < dh_prime - 1 is false).');
}
\danog\MadelineProto\Logger::log('Preparing client_DH_inner_data...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Preparing client_DH_inner_data...', \danog\MadelineProto\Logger::VERBOSE);
$g_b_str = $g_b->toBytes();
/*
* ***********************************************************************
@ -294,7 +294,7 @@ trait AuthKeyHandler
$data_with_sha = sha1($data, true).$data;
$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::VERBOSE);
$this->logger->logger('Executing set_client_DH_params...', \danog\MadelineProto\Logger::VERBOSE);
/*
* ***********************************************************************
* Send set_client_DH_params query
@ -317,7 +317,7 @@ trait AuthKeyHandler
* ***********************************************************************
* Generate auth_key
*/
\danog\MadelineProto\Logger::log('Generating authorization key...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('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);
@ -348,12 +348,12 @@ trait AuthKeyHandler
if ($Set_client_DH_params_answer['new_nonce_hash1'] != $new_nonce_hash1) {
throw new \danog\MadelineProto\SecurityException('wrong new_nonce_hash1');
}
\danog\MadelineProto\Logger::log('Diffie Hellman key exchange processed successfully!', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Diffie Hellman key exchange processed successfully!', \danog\MadelineProto\Logger::VERBOSE);
$res_authorization['server_salt'] = substr($new_nonce, 0, 8 - 0) ^ substr($server_nonce, 0, 8 - 0);
$res_authorization['auth_key'] = $auth_key_str;
$res_authorization['id'] = substr($auth_key_sha, -8);
$res_authorization['connection_inited'] = false;
\danog\MadelineProto\Logger::log('Auth key generated', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Auth key generated', \danog\MadelineProto\Logger::NOTICE);
return $res_authorization;
case 'dh_gen_retry':
@ -361,13 +361,13 @@ trait AuthKeyHandler
throw new \danog\MadelineProto\SecurityException('wrong new_nonce_hash_2');
}
//repeat foreach
\danog\MadelineProto\Logger::log('Retrying Auth', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Retrying Auth', \danog\MadelineProto\Logger::VERBOSE);
break;
case 'dh_gen_fail':
if ($Set_client_DH_params_answer['new_nonce_hash3'] != $new_nonce_hash3) {
throw new \danog\MadelineProto\SecurityException('wrong new_nonce_hash_3');
}
\danog\MadelineProto\Logger::log('Auth Failed', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('Auth Failed', \danog\MadelineProto\Logger::WARNING);
break 2;
default:
throw new \danog\MadelineProto\SecurityException('Response Error');
@ -375,15 +375,15 @@ trait AuthKeyHandler
}
}
} catch (\danog\MadelineProto\SecurityException $e) {
\danog\MadelineProto\Logger::log('An exception occurred while generating the authorization key: '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('An exception occurred while generating the authorization key: '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log('An exception occurred while generating the authorization key: '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('An exception occurred while generating the authorization key: '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING);
$req_pq = $req_pq === 'req_pq_multi' ? 'req_pq' : 'req_pq_multi';
} catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc === 'RPC_CALL_FAIL') {
throw $e;
}
\danog\MadelineProto\Logger::log('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING);
} finally {
$this->datacenter->sockets[$datacenter]->new_outgoing = [];
$this->datacenter->sockets[$datacenter]->new_incoming = [];
@ -401,11 +401,11 @@ trait AuthKeyHandler
* Check validity of g_a
* 1 < g_a < p - 1
*/
\danog\MadelineProto\Logger::log('Executing g_a check (1/2)...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Executing g_a check (1/2)...', \danog\MadelineProto\Logger::VERBOSE);
if ($g_a->compare($this->one) <= 0 || $g_a->compare($p->subtract($this->one)) >= 0) {
throw new \danog\MadelineProto\SecurityException('g_a is invalid (1 < g_a < dh_prime - 1 is false).');
}
\danog\MadelineProto\Logger::log('Executing g_a check (2/2)...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Executing g_a check (2/2)...', \danog\MadelineProto\Logger::VERBOSE);
if ($g_a->compare($this->twoe1984) < 0 || $g_a->compare($p->subtract($this->twoe1984)) >= 0) {
throw new \danog\MadelineProto\SecurityException('g_a is invalid (2^1984 < gA < dh_prime - 2^1984 is false).');
}
@ -420,7 +420,7 @@ trait AuthKeyHandler
* Check validity of dh_prime
* Is it a prime?
*/
\danog\MadelineProto\Logger::log('Executing p/g checks (1/2)...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Executing p/g checks (1/2)...', \danog\MadelineProto\Logger::VERBOSE);
if (!$p->isPrime()) {
throw new \danog\MadelineProto\SecurityException("p isn't a safe 2048-bit prime (p isn't a prime).");
}
@ -432,7 +432,7 @@ trait AuthKeyHandler
* Almost always fails
*/
/*
\danog\MadelineProto\Logger::log('Executing p/g checks (2/3)...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Executing p/g checks (2/3)...', \danog\MadelineProto\Logger::VERBOSE);
if (!$p->subtract($this->one)->divide($this->two)[0]->isPrime()) {
throw new \danog\MadelineProto\SecurityException("p isn't a safe 2048-bit prime ((p - 1) / 2 isn't a prime).");
}
@ -442,7 +442,7 @@ trait AuthKeyHandler
* Check validity of p
* 2^2047 < p < 2^2048
*/
\danog\MadelineProto\Logger::log('Executing p/g checks (2/2)...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Executing p/g checks (2/2)...', \danog\MadelineProto\Logger::VERBOSE);
if ($p->compare($this->twoe2047) <= 0 || $p->compare($this->twoe2048) >= 0) {
throw new \danog\MadelineProto\SecurityException("g isn't a safe 2048-bit prime (2^2047 < p < 2^2048 is false).");
}
@ -451,7 +451,7 @@ trait AuthKeyHandler
* Check validity of g
* 1 < g < p - 1
*/
\danog\MadelineProto\Logger::log('Executing g check...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Executing g check...', \danog\MadelineProto\Logger::VERBOSE);
if ($g->compare($this->one) <= 0 || $g->compare($p->subtract($this->one)) >= 0) {
throw new \danog\MadelineProto\SecurityException('g is invalid (1 < g < p - 1 is false).');
}
@ -469,7 +469,7 @@ trait AuthKeyHandler
$this->updates_state['sync_loading'] = false;
}
if ($dh_config['_'] === 'messages.dhConfigNotModified') {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Logger::VERBOSE, ['DH configuration not modified']);
$this->logger->logger(\danog\MadelineProto\Logger::VERBOSE, ['DH configuration not modified']);
return $this->dh_config;
}
@ -484,7 +484,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::VERBOSE);
$this->logger->logger('Binding authorization keys...', \danog\MadelineProto\Logger::VERBOSE);
$nonce = $this->random(8);
$expires_at = time() + $expires_in;
$temp_auth_key_id = $this->datacenter->sockets[$datacenter]->temp_auth_key['id'];
@ -501,16 +501,16 @@ trait AuthKeyHandler
$encrypted_message = $this->datacenter->sockets[$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], ['message_id' => $message_id, 'datacenter' => $datacenter]);
if ($res === true) {
\danog\MadelineProto\Logger::log('Successfully binded temporary and permanent authorization keys, DC '.$datacenter, \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Successfully binded temporary and permanent authorization keys, DC '.$datacenter, \danog\MadelineProto\Logger::NOTICE);
return true;
}
} catch (\danog\MadelineProto\SecurityException $e) {
\danog\MadelineProto\Logger::log('An exception occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('An exception occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING);
} 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::WARNING);
$this->logger->logger('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::WARNING);
$this->logger->logger('An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...', \danog\MadelineProto\Logger::WARNING);
} finally {
$this->datacenter->sockets[$datacenter]->new_outgoing = [];
$this->datacenter->sockets[$datacenter]->new_incoming = [];
@ -541,20 +541,20 @@ trait AuthKeyHandler
if ($socket->temp_auth_key === null || $socket->auth_key === null) {
$dc_config_number = isset($this->settings['connection_settings'][$id]) ? $id : 'all';
if ($socket->auth_key === null && !$cdn) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['gen_perm_auth_key'], $id), \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['gen_perm_auth_key'], $id), \danog\MadelineProto\Logger::NOTICE);
$socket->auth_key = $this->create_auth_key(-1, $id);
$socket->authorized = false;
}
if ($this->settings['connection_settings'][$dc_config_number]['pfs']) {
if (!$cdn) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id), \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id), \danog\MadelineProto\Logger::NOTICE);
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
$this->bind_temp_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
$config = $this->method_call('help.getConfig', [], ['datacenter' => $id]);
$this->sync_authorization($id);
$this->get_config($config);
} elseif ($socket->temp_auth_key === null) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id), \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id), \danog\MadelineProto\Logger::NOTICE);
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
}
} else {
@ -564,7 +564,7 @@ trait AuthKeyHandler
$this->sync_authorization($id);
$this->get_config($config);
} elseif ($socket->temp_auth_key === null) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id), \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id), \danog\MadelineProto\Logger::NOTICE);
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
}
}
@ -593,15 +593,15 @@ trait AuthKeyHandler
}
if ($authorized_socket->temp_auth_key !== null && $authorized_socket->auth_key !== null && $authorized_socket->authorized === true && $this->authorized === self::LOGGED_IN && $socket->authorized === false && strpos($authorized_dc_id, 'cdn') === false) {
try {
\danog\MadelineProto\Logger::log('Trying to copy authorization from dc '.$authorized_dc_id.' to dc '.$id);
$this->logger->logger('Trying to copy authorization from dc '.$authorized_dc_id.' to dc '.$id);
$exported_authorization = $this->method_call('auth.exportAuthorization', ['dc_id' => preg_replace('|_.*|', '', $id)], ['datacenter' => $authorized_dc_id]);
$authorization = $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $id]);
$socket->authorized = true;
break;
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log('Failure while syncing authorization from DC '.$authorized_dc_id.' to DC '.$id.': '.$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Failure while syncing authorization from DC '.$authorized_dc_id.' to DC '.$id.': '.$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log('Failure while syncing authorization from DC '.$authorized_dc_id.' to DC '.$id.': '.$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Failure while syncing authorization from DC '.$authorized_dc_id.' to DC '.$id.': '.$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
if ($e->rpc === 'DC_ID_INVALID') {
break;
}

View File

@ -38,7 +38,7 @@ trait CallHandler
throw new \danog\MadelineProto\Exception(self::DISALLOWED_METHODS[$method], 0, null, 'MadelineProto', 1);
}
if ($this->wrapper instanceof \danog\MadelineProto\API && isset($this->wrapper->session) && !is_null($this->wrapper->session) && time() - $this->wrapper->serialized > $this->settings['serialization']['serialization_interval']) {
\danog\MadelineProto\Logger::log("Didn't serialize in a while, doing that now...");
$this->logger->logger("Didn't serialize in a while, doing that now...");
$this->wrapper->serialize($this->wrapper->session);
}
if (isset($args['message']) && is_string($args['message']) && $this->mb_strlen($args['message']) > 4096) {
@ -72,7 +72,7 @@ trait CallHandler
$serialized = $this->serialize_method($method, $args);
}
if ($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null && (!isset($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited']) || $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited'] === false)) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['write_client_info'], $method), \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['write_client_info'], $method), \danog\MadelineProto\Logger::NOTICE);
$serialized = $this->serialize_method('invokeWithLayer', ['layer' => $this->settings['tl_schema']['layer'], 'query' => $this->serialize_method('initConnection', ['api_id' => $this->settings['app_info']['api_id'], 'api_hash' => $this->settings['app_info']['api_hash'], 'device_model' => strpos($aargs['datacenter'], 'cdn') === false ? $this->settings['app_info']['device_model'] : 'n/a', 'system_version' => strpos($aargs['datacenter'], 'cdn') === false ? $this->settings['app_info']['system_version'] : 'n/a', 'app_version' => $this->settings['app_info']['app_version'], 'system_lang_code' => $this->settings['app_info']['lang_code'], 'lang_code' => $this->settings['app_info']['lang_code'], 'lang_pack' => '', 'query' => $serialized])]);
}
$content_related = $this->content_related($method);
@ -82,7 +82,7 @@ trait CallHandler
}
if ($this->settings['requests']['gzip_encode_if_gt'] !== -1 && ($l = strlen($serialized)) > $this->settings['requests']['gzip_encode_if_gt'] && ($g = strlen($gzipped = gzencode($serialized))) < $l) {
$serialized = $this->serialize_object(['type' => 'gzip_packed'], ['packed_data' => $gzipped], 'gzipped data');
\danog\MadelineProto\Logger::log('Using GZIP compression for '.$method.', saved '.($l - $g).' bytes of data, reduced call size by '.$g * 100 / $l.'%', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger('Using GZIP compression for '.$method.', saved '.($l - $g).' bytes of data, reduced call size by '.$g * 100 / $l.'%', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
}
$to_ack = [];
$last_recv = $this->datacenter->sockets[$aargs['datacenter']]->last_recv;
@ -98,10 +98,10 @@ trait CallHandler
}
try {
\danog\MadelineProto\Logger::log('Calling method (try number '.$count.' for '.$method.')...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger('Calling method (try number '.$count.' for '.$method.')...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
if ($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null) {
if (isset($message_id)) {
\danog\MadelineProto\Logger::log('Clearing old method call', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger('Clearing old method call', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
if (isset($this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id])) {
unset($this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id]);
}
@ -150,7 +150,7 @@ trait CallHandler
while ($server_answer === null && $res_count++ < $response_tries) {
// 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::ULTRA_VERBOSE);
$this->logger->logger('Getting response (try number '.$res_count.' for '.$method.')...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
if (!isset($this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id]['response']) || !isset($this->datacenter->sockets[$aargs['datacenter']]->incoming_messages[$this->datacenter->sockets[$aargs['datacenter']]->outgoing_messages[$message_id]['response']]['content'])) {
// Checks if I have received the response to the called method, if not continue looping
if ($only_updates) {
@ -169,7 +169,7 @@ trait CallHandler
if (($error = $this->recv_message($aargs['datacenter'])) !== true) {
if ($error === -404) {
if ($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null) {
\danog\MadelineProto\Logger::log('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null;
$this->init_authorization();
@ -186,12 +186,12 @@ trait CallHandler
if (in_array($e->getMessage(), ['Resend query', 'I had to recreate the temporary authorization key', 'Got bad message notification']) || $e->getCode() === 404) {
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::WARNING);
\danog\MadelineProto\Logger::log('Full trace '.$e, \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('Full trace '.$e, \danog\MadelineProto\Logger::WARNING);
continue;
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
$last_error = 'Nothing in the socket';
\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);
$this->logger->logger('An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING);
$only_updates = false;
if ($last_recv === $this->datacenter->sockets[$aargs['datacenter']]->last_recv) { // the socket is dead, resend request
$this->close_and_reopen($aargs['datacenter']);
@ -251,7 +251,7 @@ trait CallHandler
$this->settings['connection_settings']['default_dc'] = $this->authorized_dc = $this->datacenter->curdc;
}
$last_recv = $this->datacenter->sockets[$aargs['datacenter']]->last_recv;
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
continue;
}
$this->close_and_reopen($aargs['datacenter']);
@ -261,7 +261,7 @@ trait CallHandler
continue;
} catch (\RuntimeException $e) {
$last_error = $e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine();
\danog\MadelineProto\Logger::log('An error occurred while calling method '.$method.': '.$last_error.'. Recreating connection and retrying to call method...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('An error occurred while calling method '.$method.': '.$last_error.'. Recreating connection and retrying to call method...', \danog\MadelineProto\Logger::WARNING);
$this->close_and_reopen($aargs['datacenter']);
continue;
} finally {
@ -288,7 +288,7 @@ trait CallHandler
}
if ($server_answer === null) {
if ($last_recv === $this->datacenter->sockets[$aargs['datacenter']]->last_recv && $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null) {
\danog\MadelineProto\Logger::log('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null;
$this->init_authorization();
@ -297,7 +297,7 @@ trait CallHandler
throw new \danog\MadelineProto\Exception('An error occurred while calling method '.$method.' ('.$last_error.').');
}
\danog\MadelineProto\Logger::log('Got response for method '.$method.' @ try '.$count.' (response try '.$res_count.')', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger('Got response for method '.$method.' @ try '.$count.' (response try '.$res_count.')', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
if ($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null && (!isset($this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited']) || $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited'] === false)) {
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key['connection_inited'] = true;
}

View File

@ -38,7 +38,7 @@ trait Files
}
if ($cb === null) {
$cb = function ($percent) {
\danog\MadelineProto\Logger::log('Upload status: '.$percent.'%', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Upload status: '.$percent.'%', \danog\MadelineProto\Logger::NOTICE);
};
}
$part_size = 512 * 1024;
@ -323,7 +323,7 @@ trait Files
$file = realpath($file);
$message_media = $this->get_download_info($message_media);
$stream = fopen($file, 'r+b');
\danog\MadelineProto\Logger::log('Waiting for lock of file to download...');
$this->logger->logger('Waiting for lock of file to download...');
flock($stream, LOCK_EX);
try {
@ -346,7 +346,7 @@ trait Files
if ($cb === null) {
$cb = function ($percent) {
\danog\MadelineProto\Logger::log('Download status: '.$percent.'%', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Download status: '.$percent.'%', \danog\MadelineProto\Logger::NOTICE);
};
}
$message_media = $this->get_download_info($message_media);
@ -401,11 +401,11 @@ trait Files
$this->config['expires'] = -1;
$this->get_config([], ['datacenter' => $this->datacenter->curdc]);
}
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['stored_on_cdn'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['stored_on_cdn'], \danog\MadelineProto\Logger::NOTICE);
continue;
}
if ($res['_'] === 'upload.cdnFileReuploadNeeded') {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['cdn_reupload'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['cdn_reupload'], \danog\MadelineProto\Logger::NOTICE);
$this->get_config([], ['datacenter' => $this->datacenter->curdc]);
try {
@ -452,7 +452,7 @@ trait Files
}
$offset += strlen($res['bytes']);
$downloaded_size += strlen($res['bytes']);
\danog\MadelineProto\Logger::log(fwrite($stream, $res['bytes']), \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger(fwrite($stream, $res['bytes']), \danog\MadelineProto\Logger::ULTRA_VERBOSE);
if ($theend) {
break;
}

View File

@ -20,7 +20,7 @@ trait MessageHandler
{
public function send_unencrypted_message($type, $message_data, $message_id, $datacenter)
{
\danog\MadelineProto\Logger::log("Sending $type as unencrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Sending $type as unencrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$message_data = "\0\0\0\0\0\0\0\0".$message_id.$this->pack_unsigned_int(strlen($message_data)).$message_data;
$this->datacenter->sockets[$datacenter]->outgoing_messages[$message_id] = ['response' => -1];
$this->datacenter->sockets[$datacenter]->send_message($message_data);
@ -32,13 +32,13 @@ trait MessageHandler
if (count($this->datacenter->sockets[$datacenter]->object_queue) > 1) {
$messages = [];
\danog\MadelineProto\Logger::log("Sending msg_container as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Sending msg_container as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
foreach ($this->datacenter->sockets[$datacenter]->object_queue as $message) {
$message['seqno'] = $this->generate_out_seq_no($datacenter, $message['content_related']);
$message['bytes'] = strlen($message['body']);
//$has_ack = $has_ack || $message['_'] === 'msgs_ack';
\danog\MadelineProto\Logger::log("Inside of msg_container, sending {$message['_']} as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Inside of msg_container, sending {$message['_']} as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$message['_'] = 'MTmessage';
$messages[] = $message;
$this->datacenter->sockets[$datacenter]->outgoing_messages[$message['msg_id']] = ['seq_no' => $message['seqno'], 'response' => -1]; //, 'content' => $this->deserialize($message['body'], ['type' => '', 'datacenter' => $datacenter])];
@ -48,7 +48,7 @@ trait MessageHandler
$seq_no = $this->generate_out_seq_no($datacenter, false);
} elseif (count($this->datacenter->sockets[$datacenter]->object_queue)) {
$message = array_shift($this->datacenter->sockets[$datacenter]->object_queue);
\danog\MadelineProto\Logger::log("Sending {$message['_']} as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Sending {$message['_']} as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$message_data = $message['body'];
$message_id = $message['msg_id'];
$seq_no = $this->generate_out_seq_no($datacenter, $message['content_related']);
@ -82,7 +82,7 @@ trait MessageHandler
public function recv_message($datacenter)
{
if ($this->datacenter->sockets[$datacenter]->must_open) {
\danog\MadelineProto\Logger::log('Trying to read from closed socket, sending initial ping');
$this->logger->logger('Trying to read from closed socket, sending initial ping');
if ($this->is_http($datacenter)) {
$this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]);
} elseif (isset($this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) && $this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) {
@ -94,7 +94,7 @@ trait MessageHandler
$payload = $this->datacenter->sockets[$datacenter]->read_message();
if (strlen($payload) === 4) {
$payload = $this->unpack_signed_int($payload);
\danog\MadelineProto\Logger::log("Received $payload from DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Received $payload from DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
return $payload;
}
@ -113,7 +113,7 @@ trait MessageHandler
/*
$server_salt = substr($decrypted_data, 0, 8);
if ($server_salt != $this->datacenter->sockets[$datacenter]->temp_auth_key['server_salt']) {
\danog\MadelineProto\Logger::log('WARNING: Server salt mismatch (my server salt '.$this->datacenter->sockets[$datacenter]->temp_auth_key['server_salt'].' is not equal to server server salt '.$server_salt.').', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('WARNING: Server salt mismatch (my server salt '.$this->datacenter->sockets[$datacenter]->temp_auth_key['server_salt'].' is not equal to server server salt '.$server_salt.').', \danog\MadelineProto\Logger::WARNING);
}
*/
$session_id = substr($decrypted_data, 8, 8);

View File

@ -25,7 +25,7 @@ trait MsgIdHandler
}
$min_message_id = (new \phpseclib\Math\BigInteger(time() + $this->datacenter->sockets[$aargs['datacenter']]->time_delta - 300))->bitwise_leftShift(32);
if ($min_message_id->compare($new_message_id) > 0) {
\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);
$this->logger->logger('Given message id ('.$new_message_id.') is too old compared to the min value ('.$min_message_id.').', \danog\MadelineProto\Logger::WARNING);
}
$max_message_id = (new \phpseclib\Math\BigInteger(time() + $this->datacenter->sockets[$aargs['datacenter']]->time_delta + 30))->bitwise_leftShift(32);
if ($max_message_id->compare($new_message_id) < 0) {
@ -52,11 +52,11 @@ trait MsgIdHandler
$key = $this->get_max_id($aargs['datacenter'], true);
if ($aargs['container']) {
if ($new_message_id->compare($key = $this->get_max_id($aargs['datacenter'], true)) >= 0) {
\danog\MadelineProto\Logger::log('WARNING: Given message id ('.$new_message_id.') is bigger than or equal to the current limit ('.$key.'). Consider syncing your date.', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('WARNING: Given message id ('.$new_message_id.') is bigger than or equal to the current limit ('.$key.'). Consider syncing your date.', \danog\MadelineProto\Logger::WARNING);
}
} else {
if ($new_message_id->compare($key = $this->get_max_id($aargs['datacenter'], true)) <= 0) {
\danog\MadelineProto\Logger::log('WARNING: Given message id ('.$new_message_id.') is lower than or equal to the current limit ('.$key.'). Consider syncing your date.', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('WARNING: Given message id ('.$new_message_id.') is lower than or equal to the current limit ('.$key.'). Consider syncing your date.', \danog\MadelineProto\Logger::WARNING);
}
}
if (count($this->datacenter->sockets[$aargs['datacenter']]->incoming_messages) > $this->settings['msg_array_limit']['incoming']) {

View File

@ -38,16 +38,16 @@ trait PeerHandler
$this->postpone_pwrchat = true;
try {
\danog\MadelineProto\Logger::log('Handling pending pwrchat queries...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Handling pending pwrchat queries...', \danog\MadelineProto\Logger::VERBOSE);
foreach ($this->pending_pwrchat as $query => $params) {
unset($this->pending_pwrchat[$query]);
try {
$this->get_pwr_chat($query, ...$params);
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
} finally {
@ -66,9 +66,9 @@ trait PeerHandler
try {
$this->get_pwr_chat($user['username'], false, true);
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
}
@ -85,9 +85,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::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
}
@ -116,9 +116,9 @@ trait PeerHandler
try {
$this->get_pwr_chat(-$chat['id'], $this->settings['peer']['full_fetch'], true);
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
}
@ -135,9 +135,9 @@ trait PeerHandler
try {
$this->get_pwr_chat($chat['username'], $this->settings['peer']['full_fetch'], true);
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
}
@ -155,9 +155,9 @@ trait PeerHandler
}
}
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
$this->logger->logger($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
}
}
break;
@ -575,7 +575,7 @@ trait PeerHandler
foreach ($filters as $filter) {
$this->recurse_alphabet_search_participants($full['InputChannel'], $filter, $q, $total_count, $res);
}
\danog\MadelineProto\Logger::log('Fetched '.count($res['participants'])." out of $total_count");
$this->logger->logger('Fetched '.count($res['participants'])." out of $total_count");
$res['participants'] = array_values($res['participants']);
}
if (!$fullfetch) {
@ -665,7 +665,7 @@ trait PeerHandler
}
$res['participants'][$participant['user_id']] = $newres;
}
\danog\MadelineProto\Logger::log("Fetched channel participants with filter $filter, query $q, offset $offset, limit $limit, hash $hash: ".($cached ? 'cached' : 'not cached').', '.count($gres['participants']).' participants out of '.$gres['count'].', in total fetched '.count($res['participants']).' out of '.$total_count);
$this->logger->logger("Fetched channel participants with filter $filter, query $q, offset $offset, limit $limit, hash $hash: ".($cached ? 'cached' : 'not cached').', '.count($gres['participants']).' participants out of '.$gres['count'].', in total fetched '.count($res['participants']).' out of '.$total_count);
$offset += count($gres['participants']);
} while (count($gres['participants']));
@ -704,7 +704,7 @@ trait PeerHandler
shell_exec('curl '.escapeshellarg('https://api.pwrtelegram.xyz/getchat?chat_id=@'.$res['username']).' -s -o /dev/null >/dev/null 2>/dev/null & ');
}
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log([$e->getMessage());
$this->logger->logger([$e->getMessage());
}
*/
return;
@ -716,7 +716,7 @@ trait PeerHandler
$this->qres[] = $res;
}
if ($this->last_stored > time() && !$force) {
//\danog\MadelineProto\Logger::log("========== WILL SERIALIZE IN ".($this->last_stored - time())." =============");
//$this->logger->logger("========== WILL SERIALIZE IN ".($this->last_stored - time())." =============");
return false;
}
if (empty($this->qres)) {
@ -737,14 +737,14 @@ trait PeerHandler
$result = curl_exec($ch);
curl_close($ch);
//$result = shell_exec('curl '.escapeshellarg('https://id.pwrtelegram.xyz/db'.$this->settings['pwr']['db_token'].'/addnewmadeline?d=pls&from='.$id).' -d '.escapeshellarg('@'.$path).' -s >/dev/null 2>/dev/null & ');
\danog\MadelineProto\Logger::log("============ $result =============", \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger("============ $result =============", \danog\MadelineProto\Logger::VERBOSE);
$this->qres = [];
$this->last_stored = time() + 10;
} catch (\danog\MadelineProto\Exception $e) {
if (file_exists($path)) {
unlink($path);
}
\danog\MadelineProto\Logger::log('======= COULD NOT STORE IN DB DUE TO '.$e->getMessage().' =============', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('======= COULD NOT STORE IN DB DUE TO '.$e->getMessage().' =============', \danog\MadelineProto\Logger::VERBOSE);
}
}
@ -753,7 +753,7 @@ trait PeerHandler
try {
$res = $this->method_call('contacts.resolveUsername', ['username' => str_replace('@', '', $username)], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log('Username resolution failed with error '.$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Username resolution failed with error '.$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
if (strpos($e->rpc, 'FLOOD_WAIT_') === 0 || $e->rpc === 'AUTH_KEY_UNREGISTERED' || $e->rpc === 'USERNAME_INVALID') {
throw $e;
}

View File

@ -48,8 +48,8 @@ trait ResponseHandler
$only_updates = true;
foreach ($this->datacenter->sockets[$datacenter]->new_incoming as $current_msg_id) {
$unset = false;
\danog\MadelineProto\Logger::log((isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['from_container']) ? 'Inside of container, received ' : 'Received ').$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].' from DC '.$datacenter, \danog\MadelineProto\Logger::ULTRA_VERBOSE);
//\danog\MadelineProto\Logger::log($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger((isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['from_container']) ? 'Inside of container, received ' : 'Received ').$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].' from DC '.$datacenter, \danog\MadelineProto\Logger::ULTRA_VERBOSE);
//$this->logger->logger($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
switch ($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_']) {
case 'msgs_ack':
unset($this->datacenter->sockets[$datacenter]->new_incoming[$current_msg_id]);
@ -67,8 +67,8 @@ trait ResponseHandler
// Acknowledge that I received the server's response
$this->ack_outgoing_message_id($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['req_msg_id'], $datacenter);
// Acknowledge that the server received my request
//\danog\MadelineProto\Logger::log($this->datacenter->sockets[$datacenter]->outgoing_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['req_msg_id']]);
//\danog\MadelineProto\Logger::log($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']);
//$this->logger->logger($this->datacenter->sockets[$datacenter]->outgoing_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['req_msg_id']]);
//$this->logger->logger($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']);
$this->datacenter->sockets[$datacenter]->outgoing_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['req_msg_id']]['response'] = $current_msg_id;
$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'] = $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result'];
$this->check_in_seq_no($datacenter, $current_msg_id);
@ -100,9 +100,9 @@ trait ResponseHandler
throw new \danog\MadelineProto\Exception('Got bad message notification');
case 16:
case 17:
\danog\MadelineProto\Logger::log('Received bad_msg_notification: '.self::BAD_MSG_ERROR_CODES[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['error_code']], \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('Received bad_msg_notification: '.self::BAD_MSG_ERROR_CODES[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['error_code']], \danog\MadelineProto\Logger::WARNING);
$this->datacenter->sockets[$datacenter]->time_delta = (int) (new \phpseclib\Math\BigInteger(strrev($current_msg_id), 256))->bitwise_rightShift(32)->subtract(new \phpseclib\Math\BigInteger(time()))->toString();
\danog\MadelineProto\Logger::log('Set time delta to '.$this->datacenter->sockets[$datacenter]->time_delta, \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('Set time delta to '.$this->datacenter->sockets[$datacenter]->time_delta, \danog\MadelineProto\Logger::WARNING);
$this->reset_session();
$this->datacenter->sockets[$datacenter]->temp_auth_key = null;
$this->init_authorization();
@ -164,7 +164,7 @@ trait ResponseHandler
case 'http_wait':
$this->check_in_seq_no($datacenter, $current_msg_id);
$only_updates = false;
\danog\MadelineProto\Logger::log($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'], \danog\MadelineProto\Logger::NOTICE);
unset($this->datacenter->sockets[$datacenter]->new_incoming[$current_msg_id]);
$unset = true;
break;
@ -197,7 +197,7 @@ trait ResponseHandler
$status .= $description;
}
}
\danog\MadelineProto\Logger::log($status, \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger($status, \danog\MadelineProto\Logger::NOTICE);
}
break;
case 'msg_detailed_info':
@ -274,17 +274,17 @@ trait ResponseHandler
break;
default:
$only_updates = false;
\danog\MadelineProto\Logger::log('Trying to assign a response of type '.$response_type.' to its request...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Trying to assign a response of type '.$response_type.' to its request...', \danog\MadelineProto\Logger::VERBOSE);
foreach ($this->datacenter->sockets[$datacenter]->new_outgoing as $key => $expecting) {
\danog\MadelineProto\Logger::log('Does the request of return type '.$expecting['type'].' match?', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Does the request of return type '.$expecting['type'].' match?', \danog\MadelineProto\Logger::VERBOSE);
if ($response_type === $expecting['type']) {
\danog\MadelineProto\Logger::log('Yes', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Yes', \danog\MadelineProto\Logger::VERBOSE);
$this->datacenter->sockets[$datacenter]->outgoing_messages[$expecting['msg_id']]['response'] = $current_msg_id;
unset($this->datacenter->sockets[$datacenter]->new_outgoing[$key]);
unset($this->datacenter->sockets[$datacenter]->new_incoming[$current_msg_id]);
break 2;
}
\danog\MadelineProto\Logger::log('No', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('No', \danog\MadelineProto\Logger::VERBOSE);
}
throw new \danog\MadelineProto\ResponseException('Dunno how to handle '.PHP_EOL.var_export($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'], true));
@ -339,7 +339,7 @@ trait ResponseHandler
case 'USER_DEACTIVATED':
case 'SESSION_REVOKED':
case 'SESSION_EXPIRED':
\danog\MadelineProto\Logger::log($server_answer['error_message'], \danog\MadelineProto\Logger::FATAL_ERROR);
$this->logger->logger($server_answer['error_message'], \danog\MadelineProto\Logger::FATAL_ERROR);
foreach ($this->datacenter->sockets as $socket) {
$socket->temp_auth_key = null;
$socket->auth_key = null;
@ -355,13 +355,13 @@ trait ResponseHandler
if ($this->authorized !== self::LOGGED_IN) {
throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
}
\danog\MadelineProto\Logger::log('Auth key not registered, resetting temporary and permanent auth keys...', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Auth key not registered, resetting temporary and permanent auth keys...', \danog\MadelineProto\Logger::ERROR);
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null;
$this->datacenter->sockets[$aargs['datacenter']]->auth_key = null;
$this->datacenter->sockets[$aargs['datacenter']]->authorized = false;
if ($this->authorized_dc === $aargs['datacenter'] && $this->authorized === self::LOGGED_IN) {
\danog\MadelineProto\Logger::log('Permanent auth key was main authorized key, logging out...', \danog\MadelineProto\Logger::FATAL_ERROR);
$this->logger->logger('Permanent auth key was main authorized key, logging out...', \danog\MadelineProto\Logger::FATAL_ERROR);
foreach ($this->datacenter->sockets as $socket) {
$socket->temp_auth_key = null;
$socket->auth_key = null;
@ -380,7 +380,7 @@ trait ResponseHandler
if ($this->authorized !== self::LOGGED_IN) {
throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
}
\danog\MadelineProto\Logger::log('Temporary auth key not bound, resetting temporary auth key...', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Temporary auth key not bound, resetting temporary auth key...', \danog\MadelineProto\Logger::ERROR);
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null;
$this->init_authorization();
@ -391,7 +391,7 @@ trait ResponseHandler
$seconds = preg_replace('/[^0-9]+/', '', $server_answer['error_message']);
$limit = isset($aargs['FloodWaitLimit']) ? $aargs['FloodWaitLimit'] : $this->settings['flood_timeout']['wait_if_lt'];
if (is_numeric($seconds) && $seconds < $limit) {
\danog\MadelineProto\Logger::log('Flood, waiting '.$seconds.' seconds...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Flood, waiting '.$seconds.' seconds...', \danog\MadelineProto\Logger::NOTICE);
sleep($seconds);
throw new \danog\MadelineProto\Exception('Re-executing query...');
@ -408,7 +408,7 @@ trait ResponseHandler
return false;
}
if (count($this->pending_updates)) {
\danog\MadelineProto\Logger::log('Parsing pending updates...');
$this->logger->logger('Parsing pending updates...');
foreach (array_keys($this->pending_updates) as $key) {
if (isset($this->pending_updates[$key])) {
$updates = $this->pending_updates[$key];
@ -425,13 +425,13 @@ trait ResponseHandler
return;
}
if ($this->postpone_updates) {
\danog\MadelineProto\Logger::log('Postpone update handling', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Postpone update handling', \danog\MadelineProto\Logger::VERBOSE);
$this->pending_updates[] = $updates;
return false;
}
$this->handle_pending_updates();
\danog\MadelineProto\Logger::log('Parsing updates received via the socket...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Parsing updates received via the socket...', \danog\MadelineProto\Logger::VERBOSE);
try {
$this->postpone_updates = true;
@ -457,7 +457,7 @@ trait ResponseHandler
$from_id = isset($updates['from_id']) ? $updates['from_id'] : ($updates['out'] ? $this->authorization['user']['id'] : $updates['user_id']);
$to_id = isset($updates['chat_id']) ? -$updates['chat_id'] : ($updates['out'] ? $updates['user_id'] : $this->authorization['user']['id']);
if (!$this->peer_isset($from_id) || !$this->peer_isset($to_id) || 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::VERBOSE);
$this->logger->logger('getDifference: good - getting user for updateShortMessage', \danog\MadelineProto\Logger::VERBOSE);
$this->get_updates_difference();
}
$message = $updates;
@ -467,11 +467,11 @@ trait ResponseHandler
try {
$message['to_id'] = $this->get_info($to_id)['Peer'];
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log('Still did not get user in database, postponing update', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Still did not get user in database, postponing update', \danog\MadelineProto\Logger::ERROR);
//$this->pending_updates[] = $updates;
break;
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log('Still did not get user in database, postponing update', \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Still did not get user in database, postponing update', \danog\MadelineProto\Logger::ERROR);
//$this->pending_updates[] = $updates;
break;
}

View File

@ -23,14 +23,14 @@ trait SeqNoHandler
$in = $content_related ? 1 : 0;
$value = $this->datacenter->sockets[$datacenter]->session_out_seq_no;
$this->datacenter->sockets[$datacenter]->session_out_seq_no += $in;
//\danog\MadelineProto\Logger::log("OUT $datacenter: $value + $in = ".$this->datacenter->sockets[$datacenter]->session_out_seq_no);
//$this->logger->logger("OUT $datacenter: $value + $in = ".$this->datacenter->sockets[$datacenter]->session_out_seq_no);
return $value * 2 + $in;
}
public function check_in_seq_no($datacenter, $current_msg_id)
{
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) && ($seq_no = $this->generate_in_seq_no($datacenter, $this->content_related($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']))) !== $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) {
//\danog\MadelineProto\Logger::log('SECURITY WARNING: Seqno mismatch (should be '.$seq_no.', is '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no'].', '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].')', \danog\MadelineProto\Logger::ERROR);
//$this->logger->logger('SECURITY WARNING: Seqno mismatch (should be '.$seq_no.', is '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no'].', '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].')', \danog\MadelineProto\Logger::ERROR);
}
}
@ -39,7 +39,7 @@ trait SeqNoHandler
$in = $content_related ? 1 : 0;
$value = $this->datacenter->sockets[$datacenter]->session_in_seq_no;
$this->datacenter->sockets[$datacenter]->session_in_seq_no += $in;
//\danog\MadelineProto\Logger::log("IN $datacenter: $value + $in = ".$this->datacenter->sockets[$datacenter]->session_in_seq_no);
//$this->logger->logger("IN $datacenter: $value + $in = ".$this->datacenter->sockets[$datacenter]->session_in_seq_no);
return $value * 2 + $in;
}

View File

@ -45,7 +45,7 @@ trait UpdateHandler
return;
}
$this->updates[$this->updates_key++] = $update;
//\danog\MadelineProto\Logger::log(['Stored ', $update);
//$this->logger->logger(['Stored ', $update);
}
public function get_updates($params = [])
@ -71,7 +71,7 @@ trait UpdateHandler
if (($error = $this->recv_message($dc)) !== true) {
if ($error === -404) {
if ($this->datacenter->sockets[$dc]->temp_auth_key !== null) {
\danog\MadelineProto\Logger::log('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
$this->datacenter->sockets[$dc]->temp_auth_key = null;
$this->init_authorization();
@ -171,7 +171,7 @@ trait UpdateHandler
return;
}
if ($this->load_channel_state($channel)['sync_loading']) {
\danog\MadelineProto\Logger::log('Not fetching '.$channel.' difference, I am already fetching it');
$this->logger->logger('Not fetching '.$channel.' difference, I am already fetching it');
return;
}
@ -192,7 +192,7 @@ trait UpdateHandler
$this->postpone_updates = false;
$this->load_channel_state($channel)['sync_loading'] = false;
}
\danog\MadelineProto\Logger::log('Fetching '.$channel.' difference...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger('Fetching '.$channel.' difference...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->load_channel_state($channel)['sync_loading'] = true;
$this->postpone_updates = true;
@ -205,7 +205,7 @@ trait UpdateHandler
throw $e;
} catch (\danog\MadelineProto\PTSException $e) {
\danog\MadelineProto\Logger::log($e->getMessage());
$this->logger->logger($e->getMessage());
unset($this->channels_state[$channel]);
return false; //$this->get_channel_difference($channel);
@ -237,7 +237,7 @@ trait UpdateHandler
}
break;
case 'updates.channelDifferenceTooLong':
\danog\MadelineProto\Logger::log('Got '.$difference['_'], \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Got '.$difference['_'], \danog\MadelineProto\Logger::VERBOSE);
$this->load_channel_state($channel)['sync_loading'] = true;
$this->postpone_updates = true;
@ -293,13 +293,13 @@ trait UpdateHandler
return;
}
if ($this->updates_state['sync_loading']) {
\danog\MadelineProto\Logger::log('Not fetching normal difference, I am already fetching it');
$this->logger->logger('Not fetching normal difference, I am already fetching it');
return false;
}
$this->updates_state['sync_loading'] = true;
$this->postpone_updates = true;
\danog\MadelineProto\Logger::log('Fetching normal difference...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger('Fetching normal difference...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
while (!isset($difference)) {
try {
$difference = $this->method_call('updates.getDifference', ['pts' => $this->load_update_state()['pts'], 'date' => $this->load_update_state()['date'], 'qts' => $this->load_update_state()['qts']], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
@ -311,7 +311,7 @@ trait UpdateHandler
$this->updates_state['sync_loading'] = false;
}
}
\danog\MadelineProto\Logger::log('Got '.$difference['_'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger('Got '.$difference['_'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->postpone_updates = true;
$this->updates_state['sync_loading'] = true;
$this->last_getdifference = time();
@ -370,13 +370,13 @@ trait UpdateHandler
if (!$this->settings['updates']['handle_updates']) {
return;
}
\danog\MadelineProto\Logger::log('Handling an update of type '.$update['_'].'...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Handling an update of type '.$update['_'].'...', \danog\MadelineProto\Logger::VERBOSE);
$channel_id = false;
switch ($update['_']) {
case 'updateNewChannelMessage':
case 'updateEditChannelMessage':
if ($update['message']['_'] === 'messageEmpty') {
\danog\MadelineProto\Logger::log('Got message empty, not saving', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger('Got message empty, not saving', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
return false;
}
@ -387,9 +387,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::VERBOSE);
$this->logger->logger('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::ERROR);
$this->logger->logger('I do not have the channel in the states and the pts is not set.', \danog\MadelineProto\Logger::ERROR);
return;
}
@ -402,7 +402,7 @@ trait UpdateHandler
}
/*
if ($cur_state['sync_loading'] && in_array($update['_'], ['updateNewMessage', 'updateEditMessage', 'updateNewChannelMessage', 'updateEditChannelMessage'])) {
\danog\MadelineProto\Logger::log('Sync loading, not handling update', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Sync loading, not handling update', \danog\MadelineProto\Logger::NOTICE);
return false;
}*/
@ -416,7 +416,7 @@ trait UpdateHandler
case 'updateNewChannelMessage':
case 'updateEditChannelMessage':
if (isset($update['message']['from_id']) && !$this->peer_isset($update['message']['from_id']) || !$this->peer_isset($update['message']['to_id']) || 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::VERBOSE);
$this->logger->logger('Not enough data for message update, getting difference...', \danog\MadelineProto\Logger::VERBOSE);
if ($channel_id !== false && $this->peer_isset($this->to_supergroup($channel_id))) {
$this->get_channel_difference($channel_id);
} else {
@ -428,7 +428,7 @@ trait UpdateHandler
break;
default:
if ($channel_id !== false && !$this->peer_isset($this->to_supergroup($channel_id))) {
\danog\MadelineProto\Logger::log('Skipping update, I do not have the channel id '.$channel_id, \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Skipping update, I do not have the channel id '.$channel_id, \danog\MadelineProto\Logger::ERROR);
return false;
}
@ -436,12 +436,12 @@ trait UpdateHandler
}
if (isset($update['pts'])) {
if ($update['pts'] < $cur_state['pts']) {
\danog\MadelineProto\Logger::log('Duplicate update, channel id: '.$channel_id, \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Duplicate update, channel id: '.$channel_id, \danog\MadelineProto\Logger::ERROR);
return false;
}
if ($cur_state['pts'] + (isset($update['pts_count']) ? $update['pts_count'] : 0) !== $update['pts']) {
\danog\MadelineProto\Logger::log('Pts hole. current pts: '.$cur_state['pts'].', pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).', pts: '.$update['pts'].', channel id: '.$channel_id, \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Pts hole. current pts: '.$cur_state['pts'].', pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).', pts: '.$update['pts'].', channel id: '.$channel_id, \danog\MadelineProto\Logger::ERROR);
if ($channel_id !== false && $this->peer_isset($this->to_supergroup($channel_id))) {
$this->get_channel_difference($channel_id);
} else {
@ -452,12 +452,12 @@ trait UpdateHandler
}
if (isset($update['message']['id'], $update['message']['to_id'])) {
if (!$this->check_msg_id($update['message'])) {
\danog\MadelineProto\Logger::log('Duplicate update by message id, channel id: '.$channel_id, \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Duplicate update by message id, channel id: '.$channel_id, \danog\MadelineProto\Logger::ERROR);
return false;
}
}
\danog\MadelineProto\Logger::log('Applying pts. current pts: '.$cur_state['pts'].', new pts: '.$update['pts'].', channel id: '.$channel_id, \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Applying pts. current pts: '.$cur_state['pts'].', new pts: '.$update['pts'].', channel id: '.$channel_id, \danog\MadelineProto\Logger::VERBOSE);
$cur_state['pts'] = $update['pts'];
if ($channel_id === false && isset($options['date']) && $cur_state['date'] < $options['date']) {
$cur_state['date'] = $options['date'];
@ -467,7 +467,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::ERROR);
$this->logger->logger('Seq hole. seq_start: '.$seq_start.' != cur seq: '.$cur_state['seq'].' + 1', \danog\MadelineProto\Logger::ERROR);
$this->get_updates_difference();
return false;
@ -516,14 +516,14 @@ trait UpdateHandler
}
});
if ($update['_'] === 'updateDcOptions') {
\danog\MadelineProto\Logger::log('Got new dc options', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Got new dc options', \danog\MadelineProto\Logger::VERBOSE);
$this->parse_dc_options($update['dc_options']);
return;
}
if ($update['_'] === 'updatePhoneCall') {
if (!class_exists('\\danog\\MadelineProto\\VoIP')) {
\danog\MadelineProto\Logger::log('The php-libtgvoip extension is required to accept and manage calls. See daniil.it/MadelineProto for more info.', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('The php-libtgvoip extension is required to accept and manage calls. See daniil.it/MadelineProto for more info.', \danog\MadelineProto\Logger::WARNING);
return;
}
@ -562,17 +562,17 @@ trait UpdateHandler
$cur_state['qts'] = $update['qts'];
}
if ($update['qts'] < $cur_state['qts']) {
\danog\MadelineProto\Logger::log('Duplicate update. update qts: '.$update['qts'].' <= current qts '.$cur_state['qts'].', chat id: '.$update['message']['chat_id'], \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Duplicate update. update qts: '.$update['qts'].' <= current qts '.$cur_state['qts'].', chat id: '.$update['message']['chat_id'], \danog\MadelineProto\Logger::ERROR);
return false;
}
if ($update['qts'] > $cur_state['qts'] + 1) {
\danog\MadelineProto\Logger::log('Qts hole. Fetching updates manually: update qts: '.$update['qts'].' > current qts '.$cur_state['qts'].'+1, chat id: '.$update['message']['chat_id'], \danog\MadelineProto\Logger::ERROR);
$this->logger->logger('Qts hole. Fetching updates manually: update qts: '.$update['qts'].' > current qts '.$cur_state['qts'].'+1, chat id: '.$update['message']['chat_id'], \danog\MadelineProto\Logger::ERROR);
$this->get_updates_difference();
return false;
}
\danog\MadelineProto\Logger::log('Applying qts: '.$update['qts'].' over current qts '.$cur_state['qts'].', chat id: '.$update['message']['chat_id'], \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Applying qts: '.$update['qts'].' over current qts '.$cur_state['qts'].', chat id: '.$update['message']['chat_id'], \danog\MadelineProto\Logger::VERBOSE);
$this->method_call('messages.receivedQueue', ['max_qts' => $cur_state['qts'] = $update['qts']], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
$this->handle_encrypted_update($update);
@ -589,11 +589,11 @@ trait UpdateHandler
if ($this->settings['secret_chats']['accept_chats'] === false || is_array($this->settings['secret_chats']['accept_chats']) && !in_array($update['chat']['admin_id'], $this->settings['secret_chats']['accept_chats'])) {
return;
}
\danog\MadelineProto\Logger::log('Accepting secret chat '.$update['chat']['id'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Accepting secret chat '.$update['chat']['id'], \danog\MadelineProto\Logger::NOTICE);
$this->accept_secret_chat($update['chat']);
break;
case 'encryptedChatDiscarded':
\danog\MadelineProto\Logger::log('Deleting secret chat '.$update['chat']['id'].' because it was revoked by the other user', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Deleting secret chat '.$update['chat']['id'].' because it was revoked by the other user', \danog\MadelineProto\Logger::NOTICE);
if (isset($this->secret_chats[$update['chat']['id']])) {
unset($this->secret_chats[$update['chat']['id']]);
}
@ -602,11 +602,11 @@ trait UpdateHandler
}
break;
case 'encryptedChat':
\danog\MadelineProto\Logger::log('Completing creation of secret chat '.$update['chat']['id'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Completing creation of secret chat '.$update['chat']['id'], \danog\MadelineProto\Logger::NOTICE);
$this->complete_secret_chat($update['chat']);
break;
}
//\danog\MadelineProto\Logger::log($update, \danog\MadelineProto\Logger::NOTICE);
//$this->logger->logger($update, \danog\MadelineProto\Logger::NOTICE);
}
if (!$this->settings['updates']['handle_updates']) {
return;
@ -617,7 +617,7 @@ trait UpdateHandler
if (isset($update['message']['from_id']) && $update['message']['from_id'] === $this->authorization['user']['id']) {
$update['message']['out'] = true;
}
\danog\MadelineProto\Logger::log('Saving an update of type '.$update['_'].'...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Saving an update of type '.$update['_'].'...', \danog\MadelineProto\Logger::VERBOSE);
if (isset($this->settings['pwr']['strict']) && $this->settings['pwr']['strict'] && isset($this->settings['pwr']['update_handler'])) {
$this->pwr_update_handler($update);
} else {
@ -628,9 +628,9 @@ trait UpdateHandler
public function pwr_webhook($update)
{
$payload = json_encode($update);
\danog\MadelineProto\Logger::log($update, $payload, json_last_error());
$this->logger->logger($update, $payload, json_last_error());
if ($payload === '') {
\danog\MadelineProto\Logger::log('EMPTY UPDATE');
$this->logger->logger('EMPTY UPDATE');
return false;
}
@ -651,11 +651,11 @@ trait UpdateHandler
}
$result = curl_exec($ch);
curl_close($ch);
\danog\MadelineProto\Logger::log('Result of webhook query is '.$result, \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Result of webhook query is '.$result, \danog\MadelineProto\Logger::NOTICE);
$result = json_decode($result, true);
if (is_array($result) && isset($result['method']) && $result['method'] != '' && is_string($result['method'])) {
try {
\danog\MadelineProto\Logger::log('Reverse webhook command returned', $this->method_call($result['method'], $result, ['datacenter' => $this->datacenter->curdc]));
$this->logger->logger('Reverse webhook command returned', $this->method_call($result['method'], $result, ['datacenter' => $this->datacenter->curdc]));
} catch (\danog\MadelineProto\Exception $e) {
} catch (\danog\MadelineProto\TL\Exception $e) {
} catch (\danog\MadelineProto\RPCErrorException $e) {

View File

@ -25,20 +25,20 @@ trait AuthKeyHandler
public function accept_secret_chat($params)
{
//\danog\MadelineProto\Logger::log($params['id'],$this->secret_chat_status($params['id']));
//$this->logger->logger($params['id'],$this->secret_chat_status($params['id']));
if ($this->secret_chat_status($params['id']) !== 0) {
//\danog\MadelineProto\Logger::log($this->secret_chat_status($params['id']));
\danog\MadelineProto\Logger::log("I've already accepted secret chat ".$params['id']);
//$this->logger->logger($this->secret_chat_status($params['id']));
$this->logger->logger("I've already accepted secret chat ".$params['id']);
return false;
}
$dh_config = $this->get_dh_config();
\danog\MadelineProto\Logger::log('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib\Math\BigInteger($this->random(256), 256);
$params['g_a'] = new \phpseclib\Math\BigInteger($params['g_a'], 256);
$this->check_G($params['g_a'], $dh_config['p']);
$key = ['auth_key' => str_pad($params['g_a']->powMod($b, $dh_config['p'])->toBytes(), 256, chr(0), \STR_PAD_LEFT)];
//\danog\MadelineProto\Logger::log($key);
//$this->logger->logger($key);
$key['fingerprint'] = substr(sha1($key['auth_key'], true), -8);
$key['visualization_orig'] = substr(sha1($key['auth_key'], true), 16);
$key['visualization_46'] = substr(hash('sha256', $key['auth_key'], true), 20);
@ -48,7 +48,7 @@ trait AuthKeyHandler
$this->method_call('messages.acceptEncryption', ['peer' => $params['id'], 'g_b' => $g_b->toBytes(), 'key_fingerprint' => $key['fingerprint']], ['datacenter' => $this->datacenter->curdc]);
$this->notify_layer($params['id']);
$this->handle_pending_updates();
\danog\MadelineProto\Logger::log('Secret chat '.$params['id'].' accepted successfully!', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Secret chat '.$params['id'].' accepted successfully!', \danog\MadelineProto\Logger::NOTICE);
}
public function request_secret_chat($user)
@ -58,18 +58,18 @@ trait AuthKeyHandler
throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database');
}
$user = $user['InputUser'];
\danog\MadelineProto\Logger::log('Creating secret chat with '.$user['user_id'].'...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Creating secret chat with '.$user['user_id'].'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = $this->get_dh_config();
\danog\MadelineProto\Logger::log('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
$a = new \phpseclib\Math\BigInteger($this->random(256), 256);
\danog\MadelineProto\Logger::log('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
$this->check_G($g_a, $dh_config['p']);
$res = $this->method_call('messages.requestEncryption', ['user_id' => $user, 'g_a' => $g_a->toBytes()], ['datacenter' => $this->datacenter->curdc]);
$this->temp_requested_secret_chats[$res['id']] = $a;
$this->handle_pending_updates();
$this->get_updates_difference();
\danog\MadelineProto\Logger::log('Secret chat '.$res['id'].' requested successfully!', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Secret chat '.$res['id'].' requested successfully!', \danog\MadelineProto\Logger::NOTICE);
return $res['id'];
}
@ -77,8 +77,8 @@ trait AuthKeyHandler
public function complete_secret_chat($params)
{
if ($this->secret_chat_status($params['id']) !== 1) {
//\danog\MadelineProto\Logger::log($this->secret_chat_status($params['id']));
\danog\MadelineProto\Logger::log('Could not find and complete secret chat '.$params['id']);
//$this->logger->logger($this->secret_chat_status($params['id']));
$this->logger->logger('Could not find and complete secret chat '.$params['id']);
return false;
}
@ -88,7 +88,7 @@ trait AuthKeyHandler
$key = ['auth_key' => str_pad($params['g_a_or_b']->powMod($this->temp_requested_secret_chats[$params['id']], $dh_config['p'])->toBytes(), 256, chr(0), \STR_PAD_LEFT)];
unset($this->temp_requested_secret_chats[$params['id']]);
$key['fingerprint'] = substr(sha1($key['auth_key'], true), -8);
//\danog\MadelineProto\Logger::log($key);
//$this->logger->logger($key);
if ($key['fingerprint'] !== $params['key_fingerprint']) {
$this->discard_secret_chat($params['id']);
@ -99,7 +99,7 @@ trait AuthKeyHandler
$this->secret_chats[$params['id']] = ['key' => $key, 'admin' => true, 'user_id' => $params['participant_id'], 'InputEncryptedChat' => ['chat_id' => $params['id'], 'access_hash' => $params['access_hash'], '_' => 'inputEncryptedChat'], 'in_seq_no_x' => 0, 'out_seq_no_x' => 1, 'in_seq_no' => 0, 'out_seq_no' => 0, 'layer' => 8, 'ttl' => 0, 'ttr' => 100, 'updated' => time(), 'incoming' => [], 'outgoing' => [], 'created' => time(), 'rekeying' => [0], 'key_x' => 'to server', 'mtproto' => 1];
$this->notify_layer($params['id']);
$this->handle_pending_updates();
\danog\MadelineProto\Logger::log('Secret chat '.$params['id'].' completed successfully!', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Secret chat '.$params['id'].' completed successfully!', \danog\MadelineProto\Logger::NOTICE);
}
public function notify_layer($chat)
@ -114,11 +114,11 @@ trait AuthKeyHandler
if ($this->secret_chats[$chat]['rekeying'][0] !== 0) {
return;
}
\danog\MadelineProto\Logger::log('Rekeying secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Rekeying secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = $this->get_dh_config();
\danog\MadelineProto\Logger::log('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
$a = new \phpseclib\Math\BigInteger($this->random(256), 256);
\danog\MadelineProto\Logger::log('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
$this->check_G($g_a, $dh_config['p']);
$e = $this->random(8);
@ -136,7 +136,7 @@ trait AuthKeyHandler
if ($this->secret_chats[$chat]['rekeying'][0] !== 0) {
$my_exchange_id = new \phpseclib\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256);
$other_exchange_id = new \phpseclib\Math\BigInteger($params['exchange_id'], -256);
//\danog\MadelineProto\Logger::log($my, $params);
//$this->logger->logger($my, $params);
if ($my_exchange_id > $other_exchange_id) {
return;
}
@ -146,9 +146,9 @@ trait AuthKeyHandler
return;
}
}
\danog\MadelineProto\Logger::log('Accepting rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Accepting rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = $this->get_dh_config();
\danog\MadelineProto\Logger::log('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib\Math\BigInteger($this->random(256), 256);
$params['g_a'] = new \phpseclib\Math\BigInteger($params['g_a'], 256);
$this->check_G($params['g_a'], $dh_config['p']);
@ -172,7 +172,7 @@ trait AuthKeyHandler
return;
}
\danog\MadelineProto\Logger::log('Committing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Committing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = $this->get_dh_config();
$params['g_b'] = new \phpseclib\Math\BigInteger($params['g_b'], 256);
$this->check_G($params['g_b'], $dh_config['p']);
@ -206,7 +206,7 @@ trait AuthKeyHandler
throw new \danog\MadelineProto\SecurityException('Invalid key fingerprint!');
}
\danog\MadelineProto\Logger::log('Completing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Completing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$this->secret_chats[$chat]['rekeying'] = [0];
$this->secret_chats[$chat]['old_key'] = $this->secret_chats[$chat]['key'];
$this->secret_chats[$chat]['key'] = $this->temp_rekeyed_secret_chats[$chat];
@ -214,7 +214,7 @@ trait AuthKeyHandler
$this->secret_chats[$chat]['updated'] = time();
unset($this->temp_rekeyed_secret_chats[$params['exchange_id']]);
$this->method_call('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionNoop']]], ['datacenter' => $this->datacenter->curdc]);
\danog\MadelineProto\Logger::log('Secret chat '.$chat.' rekeyed successfully!', \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger('Secret chat '.$chat.' rekeyed successfully!', \danog\MadelineProto\Logger::VERBOSE);
return true;
}
@ -238,8 +238,8 @@ trait AuthKeyHandler
public function discard_secret_chat($chat)
{
\danog\MadelineProto\Logger::log('Discarding secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
//\danog\MadelineProto\Logger::log(debug_backtrace(0)[0]);
$this->logger->logger('Discarding secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
//$this->logger->logger(debug_backtrace(0)[0]);
if (isset($this->secret_chats[$chat])) {
unset($this->secret_chats[$chat]);
}

View File

@ -21,7 +21,7 @@ trait MessageHandler
public function encrypt_secret_message($chat_id, $message)
{
if (!isset($this->secret_chats[$chat_id])) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['secret_chat_skipping'], $chat_id));
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['secret_chat_skipping'], $chat_id));
return false;
}
@ -57,7 +57,7 @@ trait MessageHandler
public function handle_encrypted_update($message, $test = false)
{
if (!isset($this->secret_chats[$message['message']['chat_id']])) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['secret_chat_skipping'], $message['message']['chat_id']));
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['secret_chat_skipping'], $message['message']['chat_id']));
return false;
}
@ -80,27 +80,27 @@ trait MessageHandler
$message_key = substr($message['message']['bytes'], 8, 16);
$encrypted_data = substr($message['message']['bytes'], 24);
if ($this->secret_chats[$message['message']['chat_id']]['mtproto'] === 2) {
\danog\MadelineProto\Logger::log('Trying MTProto v2 decryption for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Trying MTProto v2 decryption for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
try {
$message_data = $this->try_mtproto_v2_decrypt($message_key, $message['message']['chat_id'], $old, $encrypted_data);
\danog\MadelineProto\Logger::log('MTProto v2 decryption OK for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('MTProto v2 decryption OK for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
} catch (\danog\MadelineProto\SecurityException $e) {
\danog\MadelineProto\Logger::log('MTProto v2 decryption failed with message '.$e->getMessage().', trying MTProto v1 decryption for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('MTProto v2 decryption failed with message '.$e->getMessage().', trying MTProto v1 decryption for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$message_data = $this->try_mtproto_v1_decrypt($message_key, $message['message']['chat_id'], $old, $encrypted_data);
\danog\MadelineProto\Logger::log('MTProto v1 decryption OK for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('MTProto v1 decryption OK for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->secret_chats[$message['message']['chat_id']]['mtproto'] = 1;
}
} else {
\danog\MadelineProto\Logger::log('Trying MTProto v1 decryption for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Trying MTProto v1 decryption for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
try {
$message_data = $this->try_mtproto_v1_decrypt($message_key, $message['message']['chat_id'], $old, $encrypted_data);
\danog\MadelineProto\Logger::log('MTProto v1 decryption OK for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('MTProto v1 decryption OK for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
} catch (\danog\MadelineProto\SecurityException $e) {
\danog\MadelineProto\Logger::log('MTProto v1 decryption failed with message '.$e->getMessage().', trying MTProto v2 decryption for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('MTProto v1 decryption failed with message '.$e->getMessage().', trying MTProto v2 decryption for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$message_data = $this->try_mtproto_v2_decrypt($message_key, $message['message']['chat_id'], $old, $encrypted_data);
\danog\MadelineProto\Logger::log('MTProto v2 decryption OK for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('MTProto v2 decryption OK for chat '.$message['message']['chat_id'].'...', \danog\MadelineProto\Logger::NOTICE);
$this->secret_chats[$message['message']['chat_id']]['mtproto'] = 2;
}
}

View File

@ -60,7 +60,7 @@ trait ResponseHandler
$update['message']['decrypted_message']['action']['end_seq_no'] -= $this->secret_chats[$update['message']['chat_id']]['out_seq_no_x'];
$update['message']['decrypted_message']['action']['start_seq_no'] /= 2;
$update['message']['decrypted_message']['action']['end_seq_no'] /= 2;
\danog\MadelineProto\Logger::log('Resending messages for secret chat '.$update['message']['chat_id'], \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('Resending messages for secret chat '.$update['message']['chat_id'], \danog\MadelineProto\Logger::WARNING);
foreach ($this->secret_chats[$update['message']['chat_id']]['outgoing'] as $seq => $message) {
if ($seq >= $update['message']['decrypted_message']['action']['start_seq_no'] && $seq <= $update['message']['decrypted_message']['action']['end_seq_no']) {
//throw new \danog\MadelineProto\ResponseException(\danog\MadelineProto\Lang::$current_lang['resending_unsupported']);

View File

@ -56,10 +56,10 @@ trait SeqNoHandler
}
}
}
//\danog\MadelineProto\Logger::log($C, $seqno);
//$this->logger->logger($C, $seqno);
if ($seqno < $C) {
// <= C
\danog\MadelineProto\Logger::log('WARNING: dropping repeated message with seqno '.$seqno);
$this->logger->logger('WARNING: dropping repeated message with seqno '.$seqno);
return false;
}

View File

@ -24,14 +24,14 @@ trait TL
public function construct_tl($files)
{
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['TL_loading'], \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['TL_loading'], \danog\MadelineProto\Logger::VERBOSE);
$this->constructors = new TLConstructor();
$this->methods = new TLMethod();
$this->td_constructors = new TLConstructor();
$this->td_methods = new TLMethod();
$this->td_descriptions = ['types' => [], 'constructors' => [], 'methods' => []];
foreach ($files as $scheme_type => $file) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['file_parsing'], basename($file)), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['file_parsing'], basename($file)), \danog\MadelineProto\Logger::VERBOSE);
$filec = file_get_contents(\danog\MadelineProto\Absolute::absolute($file));
$TL_dict = json_decode($filec, true);
if ($TL_dict === null) {
@ -104,7 +104,7 @@ trait TL
if (preg_match('/^[^\s]+#([a-f0-9]*)/i', $line, $matches)) {
$nid = str_pad($matches[1], 8, '0', \STR_PAD_LEFT);
if ($id !== $nid && $scheme_type !== 'botAPI') {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['crc32_mismatch'], $id, $nid, $line), \danog\MadelineProto\Logger::ERROR);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['crc32_mismatch'], $id, $nid, $line), \danog\MadelineProto\Logger::ERROR);
}
$id = $nid;
}
@ -144,14 +144,14 @@ trait TL
throw new Exception(\danog\MadelineProto\Lang::$current_lang['src_file_invalid'].$file);
}
$orig = $this->encrypted_layer;
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['translating_obj'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['translating_obj'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
foreach ($TL_dict['constructors'] as $elem) {
if ($scheme_type === 'secret') {
$this->encrypted_layer = max($this->encrypted_layer, $elem['layer']);
}
$this->{($scheme_type === 'td' ? 'td_' : '').'constructors'}->add($elem, $scheme_type);
}
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['translating_methods'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['translating_methods'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
foreach ($TL_dict['methods'] as $elem) {
$this->{($scheme_type === 'td' ? 'td_' : '').'methods'}->add($elem);
if ($scheme_type === 'secret') {
@ -360,7 +360,7 @@ trait TL
$predicate = $object['_'];
$constructorData = $this->constructors->find_by_predicate($predicate, $layer);
if ($constructorData === false) {
\danog\MadelineProto\Logger::log($object, \danog\MadelineProto\Logger::FATAL_ERROR);
$this->logger->logger($object, \danog\MadelineProto\Logger::FATAL_ERROR);
throw new Exception(sprintf(\danog\MadelineProto\Lang::$current_lang['type_extract_error'], $predicate));
}
@ -456,7 +456,7 @@ trait TL
foreach ($tl['params'] as $current_argument) {
if (!isset($arguments[$current_argument['name']])) {
if (isset($current_argument['pow']) && (in_array($current_argument['type'], ['true', 'false']) || ($flags & $current_argument['pow']) === 0)) {
//\danog\MadelineProto\Logger::log('Skipping '.$current_argument['name'].' of type '.$current_argument['type');
//$this->logger->logger('Skipping '.$current_argument['name'].' of type '.$current_argument['type');
continue;
}
if ($current_argument['name'] === 'random_bytes') {
@ -517,7 +517,7 @@ trait TL
$arguments[$current_argument['name']] = $this->secret_chats[$arguments[$current_argument['name']]]['InputEncryptedChat'];
}
}
//\danog\MadelineProto\Logger::log('Serializing '.$current_argument['name'].' of type '.$current_argument['type');
//$this->logger->logger('Serializing '.$current_argument['name'].' of type '.$current_argument['type');
$serialized .= $this->serialize_object($current_argument, $arguments[$current_argument['name']], $current_argument['name'], $layer);
}

View File

@ -34,7 +34,7 @@ class SocketHandler extends \Threaded implements \Collectable
if ($this->error !== true) {
if ($this->error === -404) {
if ($this->API->datacenter->sockets[$this->current]->temp_auth_key !== null) {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['resetting_auth_key'], \danog\MadelineProto\Logger::WARNING);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['resetting_auth_key'], \danog\MadelineProto\Logger::WARNING);
$this->API->datacenter->sockets[$this->current]->temp_auth_key = null;
$this->API->init_authorization();

View File

@ -33,7 +33,7 @@ class SocketReader extends \Threaded implements \Collectable
public function __destruct()
{
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['shutting_down_reader_pool'].$this->current, \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['shutting_down_reader_pool'].$this->current, \danog\MadelineProto\Logger::NOTICE);
}
/**
@ -47,18 +47,18 @@ class SocketReader extends \Threaded implements \Collectable
while ($this->API->run_workers) {
try {
$this->API->datacenter->sockets[$this->current]->reading = true;
//\danog\MadelineProto\Logger::log('RECEIVING');
//$this->logger->logger('RECEIVING');
$error = $this->API->recv_message($this->current);
\danog\MadelineProto\Logger::log('NOW HANDLE');
$this->logger->logger('NOW HANDLE');
$handler_pool->submit(new SocketHandler($this->API, $this->current, $error));
\danog\MadelineProto\Logger::log('SUBMITTED');
$this->logger->logger('SUBMITTED');
$this->API->datacenter->sockets[$this->current]->reading = false;
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
//\danog\MadelineProto\Logger::log('Nothing in the socket for dc '.$this->current, \danog\MadelineProto\Logger::VERBOSE);
//$this->logger->logger('Nothing in the socket for dc '.$this->current, \danog\MadelineProto\Logger::VERBOSE);
}
}
while ($number = $handler_pool->collect()) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['shutting_down_handler_pool'], $this->current, $number), \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['shutting_down_handler_pool'], $this->current, $number), \danog\MadelineProto\Logger::NOTICE);
}
$this->setGarbage();
}

View File

@ -38,11 +38,11 @@ trait AuthKeyHandler
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['peer_not_in_db']);
}
$user = $user['InputUser'];
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['calling_user'], $user['user_id']), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['calling_user'], $user['user_id']), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = $this->get_dh_config();
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['generating_a'], \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_a'], \danog\MadelineProto\Logger::VERBOSE);
$a = \phpseclib\Math\BigInteger::randomRange($this->two, $dh_config['p']->subtract($this->two));
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['generating_g_a'], \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_g_a'], \danog\MadelineProto\Logger::VERBOSE);
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
$this->check_G($g_a, $dh_config['p']);
$res = $this->method_call('phone.requestCall', ['user_id' => $user, 'g_a_hash' => hash('sha256', $g_a->toBytes(), true), 'protocol' => ['_' => 'phoneCallProtocol', 'udp_p2p' => true, 'udp_reflector' => true, 'min_layer' => 65, 'max_layer' => 65]], ['datacenter' => $this->datacenter->curdc]);
@ -65,13 +65,13 @@ trait AuthKeyHandler
}
});
if ($this->call_status($call['id']) !== \danog\MadelineProto\VoIP::CALL_STATE_ACCEPTED) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_error_1'], $call['id']));
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_error_1'], $call['id']));
return false;
}
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['accepting_call'], $this->calls[$call['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['accepting_call'], $this->calls[$call['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = $this->get_dh_config();
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['generating_b'], \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_b'], \danog\MadelineProto\Logger::VERBOSE);
$b = \phpseclib\Math\BigInteger::randomRange($this->two, $dh_config['p']->subtract($this->two));
$g_b = $dh_config['g']->powMod($b, $dh_config['p']);
$this->check_G($g_b, $dh_config['p']);
@ -80,12 +80,12 @@ trait AuthKeyHandler
$res = $this->method_call('phone.acceptCall', ['peer' => $call, 'g_b' => $g_b->toBytes(), 'protocol' => ['_' => 'phoneCallProtocol', 'udp_reflector' => true, 'udp_p2p' => true, 'min_layer' => 65, 'max_layer' => 65]], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc === 'CALL_ALREADY_ACCEPTED') {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_already_accepted'], $call['id']));
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_already_accepted'], $call['id']));
return true;
}
if ($e->rpc === 'CALL_ALREADY_DECLINED') {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['call_already_declined']);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['call_already_declined']);
$this->discard_call($call['id'], 'phoneCallDiscardReasonHangup');
return false;
@ -111,11 +111,11 @@ trait AuthKeyHandler
}
});
if ($this->call_status($params['id']) !== \danog\MadelineProto\VoIP::CALL_STATE_REQUESTED) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_error_2'], $params['id']));
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_error_2'], $params['id']));
return false;
}
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_confirming'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_confirming'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = $this->get_dh_config();
$params['g_b'] = new \phpseclib\Math\BigInteger($params['g_b'], 256);
$this->check_G($params['g_b'], $dh_config['p']);
@ -149,11 +149,11 @@ trait AuthKeyHandler
}
});
if ($this->call_status($params['id']) !== \danog\MadelineProto\VoIP::CALL_STATE_ACCEPTED || !isset($this->calls[$params['id']]->storage['b'])) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_error_3'], $params['id']));
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_error_3'], $params['id']));
return false;
}
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_completing'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_completing'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = $this->get_dh_config();
if (hash('sha256', $params['g_a_or_b'], true) != $this->calls[$params['id']]->storage['g_a_hash']) {
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['invalid_g_a']);
@ -218,7 +218,7 @@ trait AuthKeyHandler
if (!isset($this->calls[$call['id']])) {
return;
}
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_discarding'], $call['id']), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_discarding'], $call['id']), \danog\MadelineProto\Logger::VERBOSE);
try {
$res = $this->method_call('phone.discardCall', ['peer' => $call, 'duration' => time() - $this->calls[$call['id']]->whenCreated(), 'connection_id' => $this->calls[$call['id']]->getPreferredRelayID(), 'reason' => $reason], ['datacenter' => $this->datacenter->curdc]);
@ -228,12 +228,12 @@ trait AuthKeyHandler
}
}
if (!empty($rating)) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_set_rating'], $call['id']), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_set_rating'], $call['id']), \danog\MadelineProto\Logger::VERBOSE);
$this->method_call('phone.setCallRating', ['peer' => $call, 'rating' => $rating['rating'], 'comment' => $rating['comment']], ['datacenter' => $this->datacenter->curdc]);
}
if ($need_debug) {
//} && isset($this->calls[$call['id']]->storage['not_modified'])) {
\danog\MadelineProto\Logger::log(sprintf(\danog\MadelineProto\Lang::$current_lang['call_debug_saving'], $call['id']), \danog\MadelineProto\Logger::VERBOSE);
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_debug_saving'], $call['id']), \danog\MadelineProto\Logger::VERBOSE);
$this->method_call('phone.saveCallDebug', ['peer' => $call, 'debug' => $this->calls[$call['id']]->getDebugLog()], ['datacenter' => $this->datacenter->curdc]);
}
$update = ['_' => 'updatePhoneCall', 'phone_call' => $this->calls[$call['id']]];

View File

@ -24,13 +24,13 @@ trait MessageHandler
if (count($this->datacenter->sockets[$datacenter]->object_queue) > 1) {
$messages = [];
\danog\MadelineProto\Logger::log("Sending msg_container as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Sending msg_container as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
foreach ($this->datacenter->sockets[$datacenter]->object_queue as $message) {
$message['seqno'] = $this->generate_out_seq_no($datacenter, $message['content_related']);
$message['bytes'] = strlen($message['body']);
//$has_ack = $has_ack || $message['_'] === 'msgs_ack';
\danog\MadelineProto\Logger::log("Inside of msg_container, sending {$message['_']} as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Inside of msg_container, sending {$message['_']} as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$message['_'] = 'MTmessage';
$messages[] = $message;
$this->datacenter->sockets[$datacenter]->outgoing_messages[$message['msg_id']] = ['seq_no' => $message['seqno'], 'response' => -1]; //, 'content' => $this->deserialize($message['body'], ['type' => '', 'datacenter' => $datacenter])];
@ -40,7 +40,7 @@ trait MessageHandler
$seq_no = $this->generate_out_seq_no($datacenter, false);
} elseif (count($this->datacenter->sockets[$datacenter]->object_queue)) {
$message = array_shift($this->datacenter->sockets[$datacenter]->object_queue);
\danog\MadelineProto\Logger::log("Sending {$message['_']} as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Sending {$message['_']} as encrypted message to DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$message_data = $message['body'];
$message_id = $message['msg_id'];
$seq_no = $this->generate_out_seq_no($datacenter, $message['content_related']);
@ -74,7 +74,7 @@ trait MessageHandler
public function recv_message($datacenter)
{
if ($this->datacenter->sockets[$datacenter]->must_open) {
\danog\MadelineProto\Logger::log('Trying to read from closed socket, sending initial ping');
$this->logger->logger('Trying to read from closed socket, sending initial ping');
if ($this->is_http($datacenter)) {
$this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]);
} elseif (isset($this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) && $this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) {
@ -86,7 +86,7 @@ trait MessageHandler
$payload = $this->datacenter->sockets[$datacenter]->read_message();
if (strlen($payload) === 4) {
$payload = $this->unpack_signed_int($payload);
\danog\MadelineProto\Logger::log("Received $payload from DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$this->logger->logger("Received $payload from DC $datacenter", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
return $payload;
}
@ -105,7 +105,7 @@ trait MessageHandler
/*
$server_salt = substr($decrypted_data, 0, 8);
if ($server_salt != $this->datacenter->sockets[$datacenter]->temp_auth_key['server_salt']) {
\danog\MadelineProto\Logger::log('WARNING: Server salt mismatch (my server salt '.$this->datacenter->sockets[$datacenter]->temp_auth_key['server_salt'].' is not equal to server server salt '.$server_salt.').', \danog\MadelineProto\Logger::WARNING);
$this->logger->logger('WARNING: Server salt mismatch (my server salt '.$this->datacenter->sockets[$datacenter]->temp_auth_key['server_salt'].' is not equal to server server salt '.$server_salt.').', \danog\MadelineProto\Logger::WARNING);
}
*/
$session_id = substr($decrypted_data, 8, 8);

View File

@ -28,7 +28,7 @@ trait DialogHandler
try {
while ($this->dialog_params['count'] < $res['count']) {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['getting_dialogs']);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['getting_dialogs']);
$res = $this->method_call('messages.getDialogs', $this->dialog_params, ['datacenter' => $datacenter, 'FloodWaitLimit' => 100]);
foreach ($res['dialogs'] as $dialog) {
if (!in_array($dialog['peer'], $peers)) {

View File

@ -34,7 +34,7 @@ trait Login
if (!$this->method_call('auth.logOut', [], ['datacenter' => $this->datacenter->curdc])) {
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['logout_error']);
}
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['logout_ok'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['logout_ok'], \danog\MadelineProto\Logger::NOTICE);
return true;
}
@ -42,10 +42,10 @@ trait Login
public function bot_login($token)
{
if ($this->authorized === self::LOGGED_IN) {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['already_logged_in'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['already_logged_in'], \danog\MadelineProto\Logger::NOTICE);
$this->logout();
}
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_bot'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_bot'], \danog\MadelineProto\Logger::NOTICE);
$this->authorization = $this->method_call('auth.importBotAuthorization', ['bot_auth_token' => $token, 'api_id' => $this->settings['app_info']['api_id'], 'api_hash' => $this->settings['app_info']['api_hash']], ['datacenter' => $this->datacenter->curdc]);
$this->authorized = self::LOGGED_IN;
$this->authorized_dc = $this->datacenter->curdc;
@ -56,7 +56,7 @@ trait Login
@file_get_contents('https://api.pwrtelegram.xyz/bot'.$token.'/getme');
}
$this->init_authorization();
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
return $this->authorization;
}
@ -64,10 +64,10 @@ trait Login
public function phone_login($number, $sms_type = 5)
{
if ($this->authorized === self::LOGGED_IN) {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['already_logged_in'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['already_logged_in'], \danog\MadelineProto\Logger::NOTICE);
$this->logout();
}
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_code_sending'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_code_sending'], \danog\MadelineProto\Logger::NOTICE);
$this->authorization = $this->method_call('auth.sendCode', ['phone_number' => $number, 'sms_type' => $sms_type, 'api_id' => $this->settings['app_info']['api_id'], 'api_hash' => $this->settings['app_info']['api_hash'], 'lang_code' => $this->settings['app_info']['lang_code']], ['datacenter' => $this->datacenter->curdc]);
$this->authorized_dc = $this->datacenter->curdc;
$this->authorization['phone_number'] = $number;
@ -75,7 +75,7 @@ trait Login
$this->authorized = self::WAITING_CODE;
$this->updates = [];
$this->updates_key = 0;
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_code_sent'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_code_sent'], \danog\MadelineProto\Logger::NOTICE);
return $this->authorization;
}
@ -86,20 +86,20 @@ trait Login
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['login_code_uncalled']);
}
$this->authorized = self::NOT_LOGGED_IN;
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_user'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_user'], \danog\MadelineProto\Logger::NOTICE);
try {
$authorization = $this->method_call('auth.signIn', ['phone_number' => $this->authorization['phone_number'], 'phone_code_hash' => $this->authorization['phone_code_hash'], 'phone_code' => (string) $code], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc === 'SESSION_PASSWORD_NEEDED') {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_2fa_enabled'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_2fa_enabled'], \danog\MadelineProto\Logger::NOTICE);
$this->authorized = self::WAITING_PASSWORD;
$this->authorization = $this->method_call('account.getPassword', [], ['datacenter' => $this->datacenter->curdc]);
return $this->authorization;
}
if ($e->rpc === 'PHONE_NUMBER_UNOCCUPIED') {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_need_signup'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_need_signup'], \danog\MadelineProto\Logger::NOTICE);
$this->authorized = self::WAITING_SIGNUP;
$this->authorization['phone_code'] = $code;
@ -112,7 +112,7 @@ trait Login
$this->authorization = $authorization;
$this->datacenter->sockets[$this->datacenter->curdc]->authorized = true;
$this->init_authorization();
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
return $this->authorization;
}
@ -120,10 +120,10 @@ trait Login
public function import_authorization($authorization)
{
if ($this->authorized === self::LOGGED_IN) {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['already_logged_in'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['already_logged_in'], \danog\MadelineProto\Logger::NOTICE);
$this->logout();
}
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_auth_key'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_auth_key'], \danog\MadelineProto\Logger::NOTICE);
list($dc_id, $auth_key) = $authorization;
if (!is_array($auth_key)) {
$auth_key = ['auth_key' => $auth_key, 'id' => substr(sha1($auth_key, true), -8), 'server_salt' => ''];
@ -162,12 +162,12 @@ trait Login
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['signup_uncalled']);
}
$this->authorized = self::NOT_LOGGED_IN;
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['signing_up'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['signing_up'], \danog\MadelineProto\Logger::NOTICE);
$this->authorization = $this->method_call('auth.signUp', ['phone_number' => $this->authorization['phone_number'], 'phone_code_hash' => $this->authorization['phone_code_hash'], 'phone_code' => $this->authorization['phone_code'], 'first_name' => $first_name, 'last_name' => $last_name], ['datacenter' => $this->datacenter->curdc]);
$this->authorized = self::LOGGED_IN;
$this->datacenter->sockets[$this->datacenter->curdc]->authorized = true;
$this->init_authorization();
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['signup_ok'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['signup_ok'], \danog\MadelineProto\Logger::NOTICE);
return $this->authorization;
}
@ -178,12 +178,12 @@ trait Login
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['2fa_uncalled']);
}
$this->authorized = self::NOT_LOGGED_IN;
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_user'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_user'], \danog\MadelineProto\Logger::NOTICE);
$this->authorization = $this->method_call('auth.checkPassword', ['password_hash' => hash('sha256', $this->authorization['current_salt'].$password.$this->authorization['current_salt'], true)], ['datacenter' => $this->datacenter->curdc]);
$this->authorized = self::LOGGED_IN;
$this->datacenter->sockets[$this->datacenter->curdc]->authorized = true;
$this->init_authorization();
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE);
return $this->authorization;
}

View File

@ -35,13 +35,13 @@ trait Loop
set_time_limit(-1);
} catch (\danog\MadelineProto\Exception $e) {
register_shutdown_function(function () {
\danog\MadelineProto\Logger::log(['Restarting script...']);
$this->logger->logger(['Restarting script...']);
$a = fsockopen((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'tls' : 'tcp').'://'.$_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
fwrite($a, $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL']."\r\n".'Host: '.$_SERVER['SERVER_NAME']."\r\n\r\n");
});
}
}
\danog\MadelineProto\Logger::log('Started update loop', \danog\MadelineProto\Logger::NOTICE);
$this->logger->logger('Started update loop', \danog\MadelineProto\Logger::NOTICE);
$offset = 0;
if ($max_forks === -1) {
while (true) {