2022-12-30 21:54:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-01-31 19:29:43 +01:00
|
|
|
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
/**
|
|
|
|
* MyTelegramOrgWrapper module.
|
|
|
|
*
|
|
|
|
* This file is part of MadelineProto.
|
|
|
|
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU Affero General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License along with MadelineProto.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @author Daniil Gentili <daniil@daniil.it>
|
2023-01-04 12:43:01 +01:00
|
|
|
* @copyright 2016-2023 Daniil Gentili <daniil@daniil.it>
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
|
2019-10-31 15:07:35 +01:00
|
|
|
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
*/
|
2018-03-22 22:23:46 +01:00
|
|
|
|
|
|
|
namespace danog\MadelineProto;
|
|
|
|
|
2023-01-04 13:02:41 +01:00
|
|
|
use Amp\Http\Client\Cookie\LocalCookieJar;
|
2019-12-13 13:29:53 +01:00
|
|
|
use Amp\Http\Client\Request;
|
2019-05-22 17:35:16 +02:00
|
|
|
|
2018-03-22 22:23:46 +01:00
|
|
|
/**
|
2018-03-23 16:39:58 +01:00
|
|
|
* Wrapper for my.telegram.org.
|
2018-03-22 22:23:46 +01:00
|
|
|
*/
|
2023-01-15 12:05:38 +01:00
|
|
|
final class MyTelegramOrgWrapper
|
2018-03-22 22:23:46 +01:00
|
|
|
{
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Whether we're logged in.
|
|
|
|
*/
|
|
|
|
private bool $logged = false;
|
|
|
|
/**
|
|
|
|
* Login hash.
|
|
|
|
*/
|
|
|
|
private string $hash = '';
|
|
|
|
/**
|
|
|
|
* Phone number.
|
|
|
|
*/
|
|
|
|
private string $number = '';
|
|
|
|
/**
|
|
|
|
* Creation hash.
|
|
|
|
*/
|
|
|
|
private string $creation_hash = '';
|
|
|
|
/**
|
|
|
|
* Settings.
|
2020-09-28 17:19:41 +02:00
|
|
|
*
|
2020-04-05 22:22:47 +02:00
|
|
|
*/
|
2023-01-04 15:13:55 +01:00
|
|
|
private Settings $settings;
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Datacenter instance.
|
|
|
|
*/
|
2023-01-04 16:04:05 +01:00
|
|
|
private DoHWrapper $datacenter;
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Cooke jar.
|
|
|
|
*
|
|
|
|
*/
|
2023-01-11 18:47:27 +01:00
|
|
|
private ?LocalCookieJar $jar = null;
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Endpoint.
|
|
|
|
*/
|
2020-10-08 11:27:37 +02:00
|
|
|
private const MY_TELEGRAM_URL = 'https://my.telegram.org';
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Sleep function.
|
|
|
|
*/
|
|
|
|
public function __sleep(): array
|
2019-05-22 17:35:16 +02:00
|
|
|
{
|
2019-06-22 20:34:15 +02:00
|
|
|
return ['logged', 'hash', 'number', 'creation_hash', 'settings', 'async', 'jar'];
|
2019-05-22 17:35:16 +02:00
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
2023-08-13 16:21:59 +02:00
|
|
|
public function __construct(SettingsAbstract $settings)
|
2018-03-23 16:39:58 +01:00
|
|
|
{
|
2023-01-14 19:18:23 +01:00
|
|
|
if (!$settings instanceof Settings) {
|
2020-10-03 15:36:03 +02:00
|
|
|
$settings = new Settings;
|
|
|
|
$settings->merge($this->settings);
|
|
|
|
}
|
2023-01-14 19:18:23 +01:00
|
|
|
$this->settings = $settings;
|
2019-05-22 17:35:16 +02:00
|
|
|
$this->__wakeup();
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Wakeup function.
|
|
|
|
*/
|
|
|
|
public function __wakeup(): void
|
2019-05-22 17:35:16 +02:00
|
|
|
{
|
2023-01-04 13:02:41 +01:00
|
|
|
if (!$this->jar || !$this->jar instanceof LocalCookieJar) {
|
|
|
|
$this->jar = new LocalCookieJar();
|
2019-06-22 20:34:15 +02:00
|
|
|
}
|
2023-01-04 16:04:05 +01:00
|
|
|
$this->datacenter = new DoHWrapper(
|
|
|
|
$this->settings->getConnection(),
|
|
|
|
new class(new Logger($this->settings->getLogger())) implements LoggerGetter {
|
|
|
|
public function __construct(private Logger $logger)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
public function getLogger(): Logger
|
|
|
|
{
|
|
|
|
return $this->logger;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
$this->jar
|
|
|
|
);
|
2019-05-22 17:35:16 +02:00
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Login.
|
|
|
|
*
|
|
|
|
* @param string $number Phone number
|
|
|
|
*/
|
2023-01-03 22:07:58 +01:00
|
|
|
public function login(string $number): void
|
2019-05-22 17:35:16 +02:00
|
|
|
{
|
2018-03-22 22:23:46 +01:00
|
|
|
$this->number = $number;
|
2020-04-05 22:22:47 +02:00
|
|
|
$request = new Request(self::MY_TELEGRAM_URL.'/auth/send_password', 'POST');
|
2019-12-13 13:29:53 +01:00
|
|
|
$request->setBody(\http_build_query(['phone' => $number]));
|
|
|
|
$request->setHeaders($this->getHeaders('origin'));
|
2023-01-11 18:47:27 +01:00
|
|
|
$response = $this->datacenter->HTTPClient->request($request);
|
2022-12-30 22:31:20 +01:00
|
|
|
$result = $response->getBody()->buffer();
|
2019-09-02 17:08:36 +02:00
|
|
|
$resulta = \json_decode($result, true);
|
2018-03-23 16:39:58 +01:00
|
|
|
if (!isset($resulta['random_hash'])) {
|
|
|
|
throw new Exception($result);
|
|
|
|
}
|
|
|
|
$this->hash = $resulta['random_hash'];
|
2018-03-22 22:23:46 +01:00
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Complete login.
|
|
|
|
*
|
|
|
|
* @param string $password Password
|
|
|
|
*/
|
2022-12-30 22:31:20 +01:00
|
|
|
public function completeLogin(string $password)
|
2018-03-23 16:39:58 +01:00
|
|
|
{
|
|
|
|
if ($this->logged) {
|
|
|
|
throw new Exception('Already logged in!');
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
$request = new Request(self::MY_TELEGRAM_URL.'/auth/login', 'POST');
|
2019-12-13 13:29:53 +01:00
|
|
|
$request->setBody(\http_build_query(['phone' => $this->number, 'random_hash' => $this->hash, 'password' => $password]));
|
|
|
|
$request->setHeaders($this->getHeaders('origin'));
|
|
|
|
$request->setHeader('user-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
|
2023-01-11 18:47:27 +01:00
|
|
|
$response = $this->datacenter->HTTPClient->request($request);
|
2022-12-30 22:31:20 +01:00
|
|
|
$result = $response->getBody()->buffer();
|
2019-05-22 17:35:16 +02:00
|
|
|
switch ($result) {
|
2018-03-22 22:23:46 +01:00
|
|
|
case 'true':
|
|
|
|
//Logger::log(['Login OK'], Logger::VERBOSE);
|
|
|
|
break;
|
|
|
|
default:
|
2019-05-22 17:35:16 +02:00
|
|
|
throw new Exception($result);
|
2018-03-22 22:23:46 +01:00
|
|
|
}
|
|
|
|
return $this->logged = true;
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Whether we are logged in.
|
|
|
|
*/
|
|
|
|
public function loggedIn(): bool
|
2018-03-23 16:39:58 +01:00
|
|
|
{
|
|
|
|
return $this->logged;
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Check if an app was already created.
|
|
|
|
*/
|
2022-12-30 22:31:20 +01:00
|
|
|
public function hasApp()
|
2018-03-23 16:39:58 +01:00
|
|
|
{
|
|
|
|
if (!$this->logged) {
|
|
|
|
throw new Exception('Not logged in!');
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
$request = new Request(self::MY_TELEGRAM_URL.'/apps');
|
2019-12-13 13:29:53 +01:00
|
|
|
$request->setHeaders($this->getHeaders('refer'));
|
2023-01-11 18:47:27 +01:00
|
|
|
$response = $this->datacenter->HTTPClient->request($request);
|
2022-12-30 22:31:20 +01:00
|
|
|
$result = $response->getBody()->buffer();
|
2019-09-02 17:08:36 +02:00
|
|
|
$title = \explode('</title>', \explode('<title>', $result)[1])[0];
|
2018-03-22 22:23:46 +01:00
|
|
|
switch ($title) {
|
2019-06-22 20:34:15 +02:00
|
|
|
case 'App configuration':
|
|
|
|
return true;
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
case 'Create new application':
|
2019-09-02 17:08:36 +02:00
|
|
|
$this->creation_hash = \explode('"/>', \explode('<input type="hidden" name="hash" value="', $result)[1])[0];
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
return false;
|
2018-03-22 22:23:46 +01:00
|
|
|
}
|
2019-06-22 20:34:15 +02:00
|
|
|
$this->logged = false;
|
2018-03-22 22:23:46 +01:00
|
|
|
throw new Exception($title);
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Get the currently created app.
|
|
|
|
*/
|
2022-12-30 22:31:20 +01:00
|
|
|
public function getApp()
|
2018-03-23 16:39:58 +01:00
|
|
|
{
|
|
|
|
if (!$this->logged) {
|
|
|
|
throw new Exception('Not logged in!');
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
$request = new Request(self::MY_TELEGRAM_URL.'/apps');
|
2019-12-13 13:29:53 +01:00
|
|
|
$request->setHeaders($this->getHeaders('refer'));
|
2023-01-11 18:47:27 +01:00
|
|
|
$response = $this->datacenter->HTTPClient->request($request);
|
2022-12-30 22:31:20 +01:00
|
|
|
$result = $response->getBody()->buffer();
|
2019-09-02 17:08:36 +02:00
|
|
|
$cose = \explode('<label for="app_id" class="col-md-4 text-right control-label">App api_id:</label>
|
2018-03-22 22:23:46 +01:00
|
|
|
<div class="col-md-7">
|
|
|
|
<span class="form-control input-xlarge uneditable-input" onclick="this.select();"><strong>', $result);
|
2019-09-02 17:08:36 +02:00
|
|
|
$asd = \explode('</strong></span>', $cose[1]);
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
$api_id = $asd[0];
|
2019-09-02 17:08:36 +02:00
|
|
|
$cose = \explode('<label for="app_hash" class="col-md-4 text-right control-label">App api_hash:</label>
|
2018-03-22 22:23:46 +01:00
|
|
|
<div class="col-md-7">
|
|
|
|
<span class="form-control input-xlarge uneditable-input" onclick="this.select();">', $result);
|
2019-09-02 17:08:36 +02:00
|
|
|
$asd = \explode('</span>', $cose[1]);
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
$api_hash = $asd[0];
|
2018-03-22 22:23:46 +01:00
|
|
|
return ['api_id' => (int) $api_id, 'api_hash' => $api_hash];
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
/**
|
|
|
|
* Create an app.
|
|
|
|
*
|
|
|
|
* @param array $settings App parameters
|
|
|
|
*/
|
2022-12-30 22:31:20 +01:00
|
|
|
public function createApp(array $settings)
|
2018-03-23 16:39:58 +01:00
|
|
|
{
|
|
|
|
if (!$this->logged) {
|
|
|
|
throw new Exception('Not logged in!');
|
|
|
|
}
|
2022-12-30 22:31:20 +01:00
|
|
|
if ($this->hasApp()) {
|
2018-03-23 16:39:58 +01:00
|
|
|
throw new Exception('The app was already created!');
|
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
$request = new Request(self::MY_TELEGRAM_URL.'/apps/create', 'POST');
|
2019-12-13 13:29:53 +01:00
|
|
|
$request->setHeaders($this->getHeaders('app'));
|
2019-12-27 15:08:24 +01:00
|
|
|
$request->setBody(\http_build_query(['hash' => $this->creation_hash, 'app_title' => $settings['app_title'], 'app_shortname' => $settings['app_shortname'], 'app_url' => $settings['app_url'], 'app_platform' => $settings['app_platform'], 'app_desc' => $settings['app_desc']]));
|
2023-01-11 18:47:27 +01:00
|
|
|
$response = $this->datacenter->HTTPClient->request($request);
|
2022-12-30 22:31:20 +01:00
|
|
|
$result = $response->getBody()->buffer();
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
if ($result) {
|
2019-09-02 17:08:36 +02:00
|
|
|
throw new Exception(\html_entity_decode($result));
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
}
|
2020-04-05 22:22:47 +02:00
|
|
|
$request = new Request(self::MY_TELEGRAM_URL.'/apps');
|
2019-12-13 13:29:53 +01:00
|
|
|
$request->setHeaders($this->getHeaders('refer'));
|
2023-01-11 18:47:27 +01:00
|
|
|
$response = $this->datacenter->HTTPClient->request($request);
|
2022-12-30 22:31:20 +01:00
|
|
|
$result = $response->getBody()->buffer();
|
2019-09-02 17:08:36 +02:00
|
|
|
$title = \explode('</title>', \explode('<title>', $result)[1])[0];
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
if ($title === 'Create new application') {
|
2019-09-02 17:08:36 +02:00
|
|
|
$this->creation_hash = \explode('"/>', \explode('<input type="hidden" name="hash" value="', $result)[1])[0];
|
2022-12-30 19:21:36 +01:00
|
|
|
throw new Exception('App creation failed');
|
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
$cose = \explode('<label for="app_id" class="col-md-4 text-right control-label">App api_id:</label>
|
2018-03-22 22:23:46 +01:00
|
|
|
<div class="col-md-7">
|
|
|
|
<span class="form-control input-xlarge uneditable-input" onclick="this.select();"><strong>', $result);
|
2019-09-02 17:08:36 +02:00
|
|
|
$asd = \explode('</strong></span>', $cose['1']);
|
2018-03-23 16:39:58 +01:00
|
|
|
$api_id = $asd['0'];
|
2019-09-02 17:08:36 +02:00
|
|
|
$cose = \explode('<label for="app_hash" class="col-md-4 text-right control-label">App api_hash:</label>
|
2018-03-22 22:23:46 +01:00
|
|
|
<div class="col-md-7">
|
|
|
|
<span class="form-control input-xlarge uneditable-input" onclick="this.select();">', $result);
|
2019-09-02 17:08:36 +02:00
|
|
|
$asd = \explode('</span>', $cose['1']);
|
2018-03-23 16:39:58 +01:00
|
|
|
$api_hash = $asd['0'];
|
2018-03-27 16:49:39 +02:00
|
|
|
return ['api_id' => (int) $api_id, 'api_hash' => $api_hash];
|
2018-03-22 22:23:46 +01:00
|
|
|
}
|
2019-05-22 17:35:16 +02:00
|
|
|
/**
|
|
|
|
* Function for generating curl request headers.
|
2020-04-05 22:22:47 +02:00
|
|
|
*
|
|
|
|
* @param string $httpType Origin
|
2019-05-22 17:35:16 +02:00
|
|
|
*/
|
2020-04-05 22:22:47 +02:00
|
|
|
private function getHeaders(string $httpType): array
|
2019-05-22 17:35:16 +02:00
|
|
|
{
|
|
|
|
// Common header flags.
|
|
|
|
$headers = [];
|
|
|
|
$headers[] = 'Dnt: 1';
|
|
|
|
$headers[] = 'Connection: keep-alive';
|
|
|
|
$headers[] = 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4';
|
|
|
|
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
|
|
|
|
// Add additional headers based on the type of request.
|
|
|
|
switch ($httpType) {
|
|
|
|
case 'origin':
|
2020-04-05 22:22:47 +02:00
|
|
|
$headers[] = 'Origin: '.self::MY_TELEGRAM_URL;
|
2019-05-22 17:35:16 +02:00
|
|
|
//$headers[] = 'Accept-Encoding: gzip, deflate, br';
|
|
|
|
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
|
|
|
|
$headers[] = 'Accept: application/json, text/javascript, */*; q=0.01';
|
2020-04-05 22:22:47 +02:00
|
|
|
$headers[] = 'Referer: '.self::MY_TELEGRAM_URL.'/auth';
|
2019-05-22 17:35:16 +02:00
|
|
|
$headers[] = 'X-Requested-With: XMLHttpRequest';
|
|
|
|
break;
|
|
|
|
case 'refer':
|
|
|
|
//$headers[] = 'Accept-Encoding: gzip, deflate, sdch, br';
|
|
|
|
$headers[] = 'Upgrade-Insecure-Requests: 1';
|
|
|
|
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
|
2020-04-05 22:22:47 +02:00
|
|
|
$headers[] = 'Referer: '.self::MY_TELEGRAM_URL;
|
2019-05-22 17:35:16 +02:00
|
|
|
$headers[] = 'Cache-Control: max-age=0';
|
|
|
|
break;
|
|
|
|
case 'app':
|
2020-04-05 22:22:47 +02:00
|
|
|
$headers[] = 'Origin: '.self::MY_TELEGRAM_URL;
|
2019-05-22 17:35:16 +02:00
|
|
|
//$headers[] = 'Accept-Encoding: gzip, deflate, br';
|
|
|
|
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
|
|
|
|
$headers[] = 'Accept: */*';
|
2020-04-05 22:22:47 +02:00
|
|
|
$headers[] = 'Referer: '.self::MY_TELEGRAM_URL.'/apps';
|
2019-05-22 17:35:16 +02:00
|
|
|
$headers[] = 'X-Requested-With: XMLHttpRequest';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$final_headers = [];
|
|
|
|
foreach ($headers as $header) {
|
2022-12-30 19:21:36 +01:00
|
|
|
[$key, $value] = \explode(':', $header, 2);
|
2019-09-02 17:08:36 +02:00
|
|
|
$final_headers[\trim($key)] = \trim($value);
|
2019-05-22 17:35:16 +02:00
|
|
|
}
|
|
|
|
return $final_headers;
|
|
|
|
}
|
2018-03-22 22:23:46 +01:00
|
|
|
}
|