Added first alpha of web version and fixed bugs
This commit is contained in:
parent
322ec6ce09
commit
96efd18e13
3
.gitignore
vendored
3
.gitignore
vendored
@ -72,3 +72,6 @@ session.mad
|
|||||||
enc.tar.xz
|
enc.tar.xz
|
||||||
a
|
a
|
||||||
web_data.php
|
web_data.php
|
||||||
|
web_API.log
|
||||||
|
db_connect.php
|
||||||
|
sessions
|
||||||
|
15
Caddyfile
15
Caddyfile
@ -1,4 +1,15 @@
|
|||||||
http://localhost {
|
http://localhost {
|
||||||
root docs/
|
markdown /docs
|
||||||
markdown
|
rewrite {
|
||||||
|
to {path} /index.php
|
||||||
|
}
|
||||||
|
|
||||||
|
fastcgi / unix:/run/php/php7.0-fpm.sock {
|
||||||
|
index index.php
|
||||||
|
}
|
||||||
|
|
||||||
|
cors
|
||||||
|
gzip
|
||||||
|
|
||||||
|
errors web_API.log
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"keywords": ["telegram", "mtproto", "protocol", "bytes", "messenger", "client", "PHP", "video", "stickers", "audio", "files", "GB"],
|
"keywords": ["telegram", "mtproto", "protocol", "bytes", "messenger", "client", "PHP", "video", "stickers", "audio", "files", "GB"],
|
||||||
"require": {
|
"require": {
|
||||||
"danog/phpstruct": "^1.2",
|
"danog/phpstruct": "^1.2",
|
||||||
"phpseclib/phpseclib": "^2.0.4",
|
"phpseclib/phpseclib": "^2.0",
|
||||||
"paragonie/constant_time_encoding": "^1|^2",
|
"paragonie/constant_time_encoding": "^1|^2",
|
||||||
"paragonie/random_compat": "^2.0",
|
"paragonie/random_compat": "^2.0",
|
||||||
"php": ">=5.6.0"
|
"php": ">=5.6.0"
|
||||||
|
4
composer.lock
generated
4
composer.lock
generated
@ -4,8 +4,8 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "a3550de91348f940ebab2aeeb8f21fc3",
|
"hash": "fc800fb5f8bf5490499819d3b4b2330d",
|
||||||
"content-hash": "ccb8a44823601a32fc613cf58345263d",
|
"content-hash": "3a10bc147a48cd4573bcc9654d3be153",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "danog/phpstruct",
|
"name": "danog/phpstruct",
|
||||||
|
30
id.php
30
id.php
@ -12,26 +12,36 @@ If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
$id = 'AgADBAADcKoxG4_aCgYKET2oLMua7pxRaRkABKoeLWY9bpazGdcCAAEC';
|
$id = ['AgADBAADcKoxG4_aCgYKET2oLMua7pxRaRkABKoeLWY9bpazGdcCAAEC', "BQADBAADhQEAAo_aCgZOb3LWhOazMQI"];
|
||||||
|
|
||||||
function foreach_offset_length($string, $callback)
|
function foreach_offset_length($string)
|
||||||
{
|
{
|
||||||
|
$res = [];
|
||||||
$strlen = strlen($string);
|
$strlen = strlen($string);
|
||||||
for ($offset = 0; $offset < strlen($string); $offset++) {
|
for ($offset = 0; $offset < strlen($string); $offset++) {
|
||||||
for ($length = $strlen - $offset; $length > 0; $length--) {
|
for ($length = $strlen - $offset; $length > 0; $length--) {
|
||||||
$s = substr($string, $offset, $length);
|
$s = substr($string, $offset, $length);
|
||||||
echo 'Offset: '.$offset.', length: '.$length.', res: ';
|
$number = (string) (new \phpseclib\Math\BigInteger(strrev($s), 256));
|
||||||
$callback($s);
|
$res []= ['number' => $number, 'offset' => $offset, 'length' => $length];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
$res = [];
|
||||||
|
foreach ($id as $file_id) {
|
||||||
|
$base256 = base64url_decode($file_id);
|
||||||
|
$res = foreach_offset_length($base256);
|
||||||
|
if (!isset($same)) {
|
||||||
|
$same = $res;
|
||||||
|
} else {
|
||||||
|
foreach ($same as $key => $s) {
|
||||||
|
if (!in_array($s, $res)) {
|
||||||
|
unset($same[$key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$base256 = base64url_decode($id);
|
|
||||||
foreach_offset_length($base256, function ($s) {
|
|
||||||
$int = (string) (new \phpseclib\Math\BigInteger(strrev($s), 256));
|
|
||||||
echo $int.PHP_EOL;
|
|
||||||
});
|
|
||||||
|
|
||||||
function base64url_decode($data)
|
function base64url_decode($data)
|
||||||
{
|
{
|
||||||
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
|
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
|
||||||
|
@ -25,7 +25,7 @@ class Exception extends \Exception
|
|||||||
if (error_reporting() === 0) {
|
if (error_reporting() === 0) {
|
||||||
return true; // return true to continue through the others error handlers
|
return true; // return true to continue through the others error handlers
|
||||||
}
|
}
|
||||||
$e = new self($errstr, $errno);
|
$e = new \danog\MadelineProto\Exception($errstr, $errno);
|
||||||
$e->file = $errfile;
|
$e->file = $errfile;
|
||||||
$e->line = $errline;
|
$e->line = $errline;
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -48,13 +48,13 @@ class Logger
|
|||||||
if (!is_string($param)) {
|
if (!is_string($param)) {
|
||||||
$param = var_export($param, true);
|
$param = var_export($param, true);
|
||||||
}
|
}
|
||||||
$param = str_pad(basename(debug_backtrace()[0]['file'], '.php').': ', 16).((self::$mode == 3) ? "\t" : '').$param;
|
$param = str_pad(basename(debug_backtrace()[0]['file'], '.php').': ', 16)."\t".$param;
|
||||||
switch (self::$mode) {
|
switch (self::$mode) {
|
||||||
case 1:
|
case 1:
|
||||||
error_log($param);
|
error_log($param);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
error_log($param, 3, self::$optional);
|
error_log($param.PHP_EOL, 3, self::$optional);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
echo $param.PHP_EOL;
|
echo $param.PHP_EOL;
|
||||||
|
@ -158,7 +158,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
|||||||
'protocol' => 'tcp_full', // can be tcp_full, tcp_abridged, tcp_intermediate, http (unsupported), https (unsupported), udp (unsupported)
|
'protocol' => 'tcp_full', // can be tcp_full, tcp_abridged, tcp_intermediate, http (unsupported), https (unsupported), udp (unsupported)
|
||||||
'test_mode' => false, // decides whether to connect to the main telegram servers or to the testing servers (deep telegram)
|
'test_mode' => false, // decides whether to connect to the main telegram servers or to the testing servers (deep telegram)
|
||||||
'ipv6' => $this->ipv6, // decides whether to use ipv6, ipv6 attribute of API attribute of API class contains autodetected boolean
|
'ipv6' => $this->ipv6, // decides whether to use ipv6, ipv6 attribute of API attribute of API class contains autodetected boolean
|
||||||
'timeout' => 10, // timeout for sockets
|
'timeout' => 5, // timeout for sockets
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'app_info' => [ // obtained in https://my.telegram.org
|
'app_info' => [ // obtained in https://my.telegram.org
|
||||||
|
@ -32,13 +32,21 @@ trait CallHandler
|
|||||||
$this->datacenter->new_outgoing[$int_message_id] = ['msg_id' => $int_message_id, 'method' => $method, 'type' => $this->methods->find_by_method($method)['type']];
|
$this->datacenter->new_outgoing[$int_message_id] = ['msg_id' => $int_message_id, 'method' => $method, 'type' => $this->methods->find_by_method($method)['type']];
|
||||||
$res_count = 0;
|
$res_count = 0;
|
||||||
$server_answer = null;
|
$server_answer = null;
|
||||||
while ($server_answer === null && $res_count++ < $this->settings['max_tries']['response']) {
|
while ($server_answer === null && $res_count++ < $this->settings['max_tries']['response']) { // Loop until we get a response, loop for a max of $this->settings['max_tries']['response'] times
|
||||||
\danog\MadelineProto\Logger::log('Getting response (try number '.$res_count.' for '.$method.')...');
|
try {
|
||||||
$this->recv_message();
|
\danog\MadelineProto\Logger::log('Getting response (try number '.$res_count.' for '.$method.')...');
|
||||||
if (!isset($this->datacenter->outgoing_messages[$int_message_id]['response']) || !isset($this->datacenter->incoming_messages[$this->datacenter->outgoing_messages[$int_message_id]['response']]['content'])) {
|
$this->recv_message(); // This method receives data from the socket, and parses stuff
|
||||||
|
|
||||||
|
if (!isset($this->datacenter->outgoing_messages[$int_message_id]['response']) || !isset($this->datacenter->incoming_messages[$this->datacenter->outgoing_messages[$int_message_id]['response']]['content'])) { // Checks if I have received the response to the called method, if not continue looping
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$server_answer = $this->datacenter->incoming_messages[$this->datacenter->outgoing_messages[$int_message_id]['response']]['content']; // continue was not called, so I got a response
|
||||||
|
|
||||||
|
} catch (\danog\MadelineProto\Exception $e) {
|
||||||
|
\danog\MadelineProto\Logger::log('An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$server_answer = $this->datacenter->incoming_messages[$this->datacenter->outgoing_messages[$int_message_id]['response']]['content'];
|
|
||||||
}
|
}
|
||||||
if ($server_answer == null) {
|
if ($server_answer == null) {
|
||||||
throw new \danog\MadelineProto\Exception("Couldn't get response");
|
throw new \danog\MadelineProto\Exception("Couldn't get response");
|
||||||
|
@ -49,13 +49,13 @@ trait MsgIdHandler
|
|||||||
if ($container) {
|
if ($container) {
|
||||||
asort($keys);
|
asort($keys);
|
||||||
if ($new_message_id >= end($keys)) {
|
if ($new_message_id >= end($keys)) {
|
||||||
throw new \danog\MadelineProto\Exception('Given message id ('.$new_message_id.') is bigger than or equal than the current limit ('.end($keys).').');
|
\danog\MadelineProto\Logger::log('WARNING: Given message id ('.$new_message_id.') is bigger than or equal than the current limit ('.end($keys).').');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
asort($keys);
|
asort($keys);
|
||||||
foreach ($keys as $message_id) {
|
foreach ($keys as $message_id) {
|
||||||
if ($new_message_id <= $message_id) {
|
if ($new_message_id <= $message_id) {
|
||||||
throw new \danog\MadelineProto\Exception('Given message id ('.$new_message_id.') is lower than or equal than the current limit ('.$message_id.').');
|
\danog\MadelineProto\Logger::log('WARNING: Given message id ('.$new_message_id.') is lower than or equal than the current limit ('.$message_id.').');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ trait UpdateHandler
|
|||||||
public $updates_state = ['pending_seq_updates' => [], 'pending_pts_updates' => [], 'sync_loading' => true, 'seq' => 0, 'pts' => 0, 'date' => 0];
|
public $updates_state = ['pending_seq_updates' => [], 'pending_pts_updates' => [], 'sync_loading' => true, 'seq' => 0, 'pts' => 0, 'date' => 0];
|
||||||
public $channels_state = [];
|
public $channels_state = [];
|
||||||
public $updates = [];
|
public $updates = [];
|
||||||
|
public $updates_key = 0;
|
||||||
private $getting_state = false;
|
private $getting_state = false;
|
||||||
|
|
||||||
public function get_updates_update_handler($update)
|
public function get_updates_update_handler($update)
|
||||||
@ -27,7 +28,7 @@ trait UpdateHandler
|
|||||||
if (count($this->updates) > $this->settings['updates']['updates_array_limit']) {
|
if (count($this->updates) > $this->settings['updates']['updates_array_limit']) {
|
||||||
array_shift($this->updates);
|
array_shift($this->updates);
|
||||||
}
|
}
|
||||||
$this->updates[] = $update;
|
$this->updates[$this->updates_key++] = $update;
|
||||||
//\danog\MadelineProto\Logger::log('Stored ', $update);
|
//\danog\MadelineProto\Logger::log('Stored ', $update);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +77,12 @@ trait UpdateHandler
|
|||||||
$this->get_channel_state($channel)['sync_loading'] = true;
|
$this->get_channel_state($channel)['sync_loading'] = true;
|
||||||
$this->get_channel_state($channel)['pending_pts_updates'] = [];
|
$this->get_channel_state($channel)['pending_pts_updates'] = [];
|
||||||
}
|
}
|
||||||
$difference = $this->method_call('updates.getChannelDifference', ['channel' => $this->get_info('channel#'.$channel)['InputChannel'], 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $this->get_channel_state($channel)['pts'], 'limit' => 30]);
|
try {
|
||||||
|
$input = $this->get_info('channel#'.$channel)['InputChannel'];
|
||||||
|
} catch (\danog\MadelineProto\Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$difference = $this->method_call('updates.getChannelDifference', ['channel' => $input, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $this->get_channel_state($channel)['pts'], 'limit' => 30]);
|
||||||
\danog\MadelineProto\Logger::log('Got '.$difference['_']);
|
\danog\MadelineProto\Logger::log('Got '.$difference['_']);
|
||||||
$this->get_channel_state($channel)['sync_loading'] = false;
|
$this->get_channel_state($channel)['sync_loading'] = false;
|
||||||
switch ($difference['_']) {
|
switch ($difference['_']) {
|
||||||
@ -185,13 +191,10 @@ trait UpdateHandler
|
|||||||
break;
|
break;
|
||||||
case 'updateChannelTooLong':
|
case 'updateChannelTooLong':
|
||||||
$channel_id = $update['channel_id'];
|
$channel_id = $update['channel_id'];
|
||||||
\danog\MadelineProto\Logger::log('Update channel too long');
|
\danog\MadelineProto\Logger::log('Got channel too long update, getting difference...');
|
||||||
if (!isset($this->channels_state[$channel_id])) {
|
if (!isset($this->channels_state[$channel_id]) && !isset($update['pts'])) {
|
||||||
if (!isset($update['pts'])) {
|
\danog\MadelineProto\Logger::log('I do not have the channel in the states and the pts is not set.');
|
||||||
\danog\MadelineProto\Logger::log('I do not have the channel in the states');
|
return;
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -200,16 +203,15 @@ trait UpdateHandler
|
|||||||
} else {
|
} else {
|
||||||
$cur_state = &$this->get_channel_state($channel_id, (isset($update['pts']) ? $update['pts'] : 0) - (isset($update['pts_count']) ? $update['pts_count'] : 0));
|
$cur_state = &$this->get_channel_state($channel_id, (isset($update['pts']) ? $update['pts'] : 0) - (isset($update['pts_count']) ? $update['pts_count'] : 0));
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if ($cur_state['sync_loading']) {
|
if ($cur_state['sync_loading']) {
|
||||||
\danog\MadelineProto\Logger::log('Sync loading, not handling update');
|
\danog\MadelineProto\Logger::log('Sync loading, not handling update');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
switch ($update['_']) {
|
switch ($update['_']) {
|
||||||
case 'updateChannelTooLong':
|
case 'updateChannelTooLong':
|
||||||
\danog\MadelineProto\Logger::log('Got channel too long update, getting difference...');
|
|
||||||
$this->get_channel_difference($channel_id);
|
$this->get_channel_difference($channel_id);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -263,7 +265,7 @@ trait UpdateHandler
|
|||||||
if ($update['pts'] > $cur_state['pts']) {
|
if ($update['pts'] > $cur_state['pts']) {
|
||||||
$cur_state['pts'] = $update['pts'];
|
$cur_state['pts'] = $update['pts'];
|
||||||
$pop_pts = true;
|
$pop_pts = true;
|
||||||
} elseif (isset($update['pts_count'])) {
|
} elseif (isset($update['pts_count']) && $update['pts_count']) {
|
||||||
\danog\MadelineProto\Logger::log('Duplicate update. current pts: '.$cur_state['pts'].' + pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).' = new pts: '.$new_pts.'. update pts: '.$update['pts'].' <= current pts '.$cur_state['pts'].', channel id: '.$channel_id);
|
\danog\MadelineProto\Logger::log('Duplicate update. current pts: '.$cur_state['pts'].' + pts count: '.(isset($update['pts_count']) ? $update['pts_count'] : 0).' = new pts: '.$new_pts.'. update pts: '.$update['pts'].' <= current pts '.$cur_state['pts'].', channel id: '.$channel_id);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -172,7 +172,7 @@ trait TL
|
|||||||
{
|
{
|
||||||
$tl = $this->methods->find_by_method($method);
|
$tl = $this->methods->find_by_method($method);
|
||||||
if ($tl === false) {
|
if ($tl === false) {
|
||||||
throw new Exception('Could not extract type: '.$method);
|
throw new Exception('Could not find method: '.$method);
|
||||||
}
|
}
|
||||||
|
|
||||||
return \danog\PHP\Struct::pack('<i', $tl['id']).$this->serialize_params($tl, $arguments);
|
return \danog\PHP\Struct::pack('<i', $tl['id']).$this->serialize_params($tl, $arguments);
|
||||||
|
@ -49,6 +49,7 @@ trait Login
|
|||||||
);
|
);
|
||||||
$this->API->datacenter->authorized = true;
|
$this->API->datacenter->authorized = true;
|
||||||
$this->API->updates = [];
|
$this->API->updates = [];
|
||||||
|
$this->API->updates_key = 0;
|
||||||
$this->API->get_updates_state();
|
$this->API->get_updates_state();
|
||||||
$this->API->should_serialize = true;
|
$this->API->should_serialize = true;
|
||||||
|
|
||||||
@ -78,6 +79,7 @@ trait Login
|
|||||||
$this->API->datacenter->waiting_code = true;
|
$this->API->datacenter->waiting_code = true;
|
||||||
$this->API->should_serialize = true;
|
$this->API->should_serialize = true;
|
||||||
$this->API->updates = [];
|
$this->API->updates = [];
|
||||||
|
$this->API->updates_key = 0;
|
||||||
|
|
||||||
\danog\MadelineProto\Logger::log('Code sent successfully! Once you receive the code you should use the complete_phone_login function.');
|
\danog\MadelineProto\Logger::log('Code sent successfully! Once you receive the code you should use the complete_phone_login function.');
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ if (file_exists('number.php') && $MadelineProto === false) {
|
|||||||
}
|
}
|
||||||
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
|
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
|
||||||
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
||||||
|
|
||||||
$message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sembre) (yo lavorar siempre)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
|
$message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sembre) (yo lavorar siempre)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
|
||||||
|
|
||||||
$flutter = 'https://storage.pwrtelegram.xyz/pwrtelegrambot/document/file_6570.mp4';
|
$flutter = 'https://storage.pwrtelegram.xyz/pwrtelegrambot/document/file_6570.mp4';
|
||||||
@ -78,3 +77,8 @@ foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
|
|||||||
}
|
}
|
||||||
sleep(5);
|
sleep(5);
|
||||||
var_dump($MadelineProto->API->get_updates());
|
var_dump($MadelineProto->API->get_updates());
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => '@pwrtelegramgroupita', 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user