From f11b60ab9424a4f764adfe83c75d343c0a43b922 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Feb 2018 22:25:26 +0100 Subject: [PATCH 01/29] Remove check.log check, remove session on AUTH_KEY_UNREGISTERED --- login.php | 9 ++---- updates.php | 92 ++++++++++++++++++++++++++++------------------------- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/login.php b/login.php index 2ec26b5..bc30223 100644 --- a/login.php +++ b/login.php @@ -1,13 +1,11 @@ Già loggato. Per nuovo login, elimina il file check.log e aggiorna questa pagina."; - exit; + echo "

Già loggato. Per nuovo login, elimina il file session.madeline e aggiorna questa pagina.

"; + exit; } - register_shutdown_function('failLogin'); require '_config.php'; @@ -22,7 +20,6 @@ if(isset($_POST["code"])){ $MadelineProto->complete_2fa_login($_POST["pwd2fa"]); } echo "



LOGIN EFFETTUATO



AVVIA USERBOT

"; - file_put_contents("check.log", "ok"); $MadelineProto->serialize(); register_shutdown_function('finePagina'); exit; diff --git a/updates.php b/updates.php index 044a548..32fc0fd 100644 --- a/updates.php +++ b/updates.php @@ -1,11 +1,9 @@ session = __DIR__.'/session.madeline'; register_shutdown_function('endUpdates'); echo "

USERBOT PARTITO

"; @@ -14,54 +12,62 @@ $running = true; $offset = 0; $lastser = time(); -while($running) -{ - $updates = $MadelineProto->get_updates(['offset' => $offset]); - foreach($updates as $update) +try { + while($running) { - $offset = $update['update_id'] + 1; - - if (isset($update['update']['message']['out']) && $update['update']['message']['out'] && !$leggi_messaggi_in_uscita) { - continue; - } - $up = $update['update']['_']; - - if($up == 'updateNewMessage' or $up == 'updateNewChannelMessage') + $updates = $MadelineProto->get_updates(['offset' => $offset]); + foreach($updates as $update) { + $offset = $update['update_id'] + 1; + + if (isset($update['update']['message']['out']) && $update['update']['message']['out'] && !$leggi_messaggi_in_uscita) { + continue; + } + $up = $update['update']['_']; + + if($up == 'updateNewMessage' or $up == 'updateNewChannelMessage') + { + + if (isset($update['update']['message']['message'])){ + $msg = $update["update"]["message"]["message"]; + } + + if (isset($update['update']['message']['to_id']['channel_id'])) { + $chatID = $update['update']['message']['to_id']['channel_id']; + $chatID = '-100'.$chatID; + $type = "supergruppo"; + } + + if (isset($update['update']['message']['to_id']['chat_id'])) { + $chatID = $update['update']['message']['to_id']['chat_id']; + $chatID = '-'.$chatID; + $type = "gruppo"; + } + + if (isset($update['update']['message']['from_id'])) $userID = $update['update']['message']['from_id']; + + if (isset($update['update']['message']['to_id']['user_id'])) { + $chatID = $update['update']['message']['from_id']; + $type = "privato"; + } + + @include("_comandi.php"); - if (isset($update['update']['message']['message'])){ - $msg = $update["update"]["message"]["message"]; } - if (isset($update['update']['message']['to_id']['channel_id'])) { - $chatID = $update['update']['message']['to_id']['channel_id']; - $chatID = '-100'.$chatID; - $type = "supergruppo"; - } - if (isset($update['update']['message']['to_id']['chat_id'])) { - $chatID = $update['update']['message']['to_id']['chat_id']; - $chatID = '-'.$chatID; - $type = "gruppo"; - } - - if (isset($update['update']['message']['from_id'])) $userID = $update['update']['message']['from_id']; - - if (isset($update['update']['message']['to_id']['user_id'])) { - $chatID = $update['update']['message']['from_id']; - $type = "privato"; - } - - @include("_comandi.php"); + if(isset($msg)) unset($msg); + if(isset($chatID)) unset($chatID); + if(isset($userID)) unset($userID); + if(isset($up)) unset($up); } - - - if(isset($msg)) unset($msg); - if(isset($chatID)) unset($chatID); - if(isset($userID)) unset($userID); - if(isset($up)) unset($up); - - } +} catch (\danog\MadelineProto\RPCErrorException $e) { + \danog\MadelineProto\Logger::log([(string)$e]); + if (in_array($e->rpc, ['SESSION_REVOKED', 'AUTH_KEY_UNREGISTERED'])) { + foreach (glob('session.madeline*') as $path) { + unlink($path); + } + } } From e1299c5015a554369b3dac0935a624a2b0527195 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 15:08:11 +0000 Subject: [PATCH 02/29] Apply fixes from StyleCI --- HttpProxy.php | 331 +++++++++++++++++++++++++++----------------------- _comandi.php | 101 ++++++--------- _config.php | 68 ++++------- functions.php | 159 +++++++++++------------- login.php | 108 ++++++++-------- phar.php | 20 +-- updates.php | 164 +++++++++++++------------ 7 files changed, 460 insertions(+), 491 deletions(-) diff --git a/HttpProxy.php b/HttpProxy.php index f091a05..0e76a03 100644 --- a/HttpProxy.php +++ b/HttpProxy.php @@ -1,153 +1,178 @@ -. -*/ - - -class HttpProxy implements \danog\MadelineProto\Proxy -{ - private $domain; - private $type; - private $protocol; - private $extra; - private $sock; - public function __construct($domain, $type, $protocol) { - if (!in_array($domain, [AF_INET, AF_INET6])) { - throw new \danog\MadelineProto\Exception('Wrong protocol family provided'); - } - if (!in_array($type, [SOCK_STREAM])) { - throw new \danog\MadelineProto\Exception('Wrong connection type provided'); - } - if (!in_array($protocol, [getprotobyname('tcp')])) { - throw new \danog\MadelineProto\Exception('Wrong protocol provided'); - } - $this->domain = $domain; - $this->type = $type; - $this->protocol = $protocol; - } - public function setExtra($extra) { - $this->extra = $extra; - $this->sock = new \Socket(strlen(@inet_pton($this->extra['address'])) !== 4 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, getprotobyname('tcp')); - } - public function setOption($level, $name, $value) { - return $this->sock->setOption($level, $name, $value); - } - - public function getOption($level, $name) { - return $this->sock->getOption($level, $name); - } - - public function setBlocking($blocking) { - return $this->sock->setBlocking($blocking); - } - - public function bind($address, $port = 0) { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function listen($backlog = 0) { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - public function accept() { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - - public function select(array &$read, array &$write, array &$except, $tv_sec, $tv_usec = 0) { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - public function connect($address, $port = 0) { - $this->sock->connect($this->extra['address'], $this->extra['port']); - - try { - if (strlen(inet_pton($address)) !== 4) { - $address = '['.$address.']'; - } - } catch (\danog\MadelineProto\Exception $e) { - } - $this->sock->write("CONNECT $address:$port HTTP/1.1\r\n\r\n"); - $response = $this->read_http_payload(); - if ($response['code'] !== 200) { - \danog\MadelineProto\Logger::log([$response['body']]); - throw new \danog\MadelineProto\Exception($response['description'], $response['code']); - } - \danog\MadelineProto\Logger::log(['Connected to '.$address.':'.$port.' via http']); - return true; - } - private function http_read($length) { - $packet = ''; - while (strlen($packet) < $length) { - $packet .= $this->sock->read($length - strlen($packet)); - if ($packet === false || strlen($packet) === 0) { - throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']); - } - } - return $packet; - } - public function read_http_line() - { - $line = ''; - while (($curchar = $this->http_read(1)) !== "\n") { - $line .= $curchar; - } - - return rtrim($line); - } - - public function read_http_payload() - { - $header = explode(' ', $this->read_http_line(), 3); - $protocol = $header[0]; - $code = (int) $header[1]; - $description = $header[2]; - $headers = []; - while (strlen($current_header = $this->read_http_line())) { - $current_header = explode(':', $current_header, 2); - $headers[strtolower($current_header[0])] = trim($current_header[1]); - } - - $read = ''; - if (isset($headers['content-length'])) { - $read = $this->http_read((int) $headers['content-length']); - }/* elseif (isset($headers['transfer-encoding']) && $headers['transfer-encoding'] === 'chunked') { - do { - $length = hexdec($this->read_http_line()); - $read .= $this->http_read($length); - $this->read_http_line(); - } while ($length); - }*/ - - return ['protocol' => $protocol, 'code' => $code, 'description' => $description, 'body' => $read, 'headers' => $headers]; - } - - public function read($length, $flags = 0) { - return $this->sock->read($length, $flags); - } - - public function write($buffer, $length = -1) { - return $this->sock->write($buffer, $length); - } - - public function send($data, $length, $flags) { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function close() { - $this->sock->close(); - } - - public function getPeerName($port = true) { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function getSockName($port = true) { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } -} \ No newline at end of file +. +*/ + +class HttpProxy implements \danog\MadelineProto\Proxy +{ + private $domain; + private $type; + private $protocol; + private $extra; + private $sock; + + public function __construct($domain, $type, $protocol) + { + if (!in_array($domain, [AF_INET, AF_INET6])) { + throw new \danog\MadelineProto\Exception('Wrong protocol family provided'); + } + if (!in_array($type, [SOCK_STREAM])) { + throw new \danog\MadelineProto\Exception('Wrong connection type provided'); + } + if (!in_array($protocol, [getprotobyname('tcp')])) { + throw new \danog\MadelineProto\Exception('Wrong protocol provided'); + } + $this->domain = $domain; + $this->type = $type; + $this->protocol = $protocol; + } + + public function setExtra($extra) + { + $this->extra = $extra; + $this->sock = new \Socket(strlen(@inet_pton($this->extra['address'])) !== 4 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, getprotobyname('tcp')); + } + + public function setOption($level, $name, $value) + { + return $this->sock->setOption($level, $name, $value); + } + + public function getOption($level, $name) + { + return $this->sock->getOption($level, $name); + } + + public function setBlocking($blocking) + { + return $this->sock->setBlocking($blocking); + } + + public function bind($address, $port = 0) + { + throw new \danog\MadelineProto\Exception('Not Implemented'); + } + + public function listen($backlog = 0) + { + throw new \danog\MadelineProto\Exception('Not Implemented'); + } + + public function accept() + { + throw new \danog\MadelineProto\Exception('Not Implemented'); + } + + public function select(array &$read, array &$write, array &$except, $tv_sec, $tv_usec = 0) + { + throw new \danog\MadelineProto\Exception('Not Implemented'); + } + + public function connect($address, $port = 0) + { + $this->sock->connect($this->extra['address'], $this->extra['port']); + + try { + if (strlen(inet_pton($address)) !== 4) { + $address = '['.$address.']'; + } + } catch (\danog\MadelineProto\Exception $e) { + } + $this->sock->write("CONNECT $address:$port HTTP/1.1\r\n\r\n"); + $response = $this->read_http_payload(); + if ($response['code'] !== 200) { + \danog\MadelineProto\Logger::log([$response['body']]); + + throw new \danog\MadelineProto\Exception($response['description'], $response['code']); + } + \danog\MadelineProto\Logger::log(['Connected to '.$address.':'.$port.' via http']); + + return true; + } + + private function http_read($length) + { + $packet = ''; + while (strlen($packet) < $length) { + $packet .= $this->sock->read($length - strlen($packet)); + if ($packet === false || strlen($packet) === 0) { + throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']); + } + } + + return $packet; + } + + public function read_http_line() + { + $line = ''; + while (($curchar = $this->http_read(1)) !== "\n") { + $line .= $curchar; + } + + return rtrim($line); + } + + public function read_http_payload() + { + $header = explode(' ', $this->read_http_line(), 3); + $protocol = $header[0]; + $code = (int) $header[1]; + $description = $header[2]; + $headers = []; + while (strlen($current_header = $this->read_http_line())) { + $current_header = explode(':', $current_header, 2); + $headers[strtolower($current_header[0])] = trim($current_header[1]); + } + + $read = ''; + if (isset($headers['content-length'])) { + $read = $this->http_read((int) $headers['content-length']); + }/* elseif (isset($headers['transfer-encoding']) && $headers['transfer-encoding'] === 'chunked') { + do { + $length = hexdec($this->read_http_line()); + $read .= $this->http_read($length); + $this->read_http_line(); + } while ($length); + }*/ + + return ['protocol' => $protocol, 'code' => $code, 'description' => $description, 'body' => $read, 'headers' => $headers]; + } + + public function read($length, $flags = 0) + { + return $this->sock->read($length, $flags); + } + + public function write($buffer, $length = -1) + { + return $this->sock->write($buffer, $length); + } + + public function send($data, $length, $flags) + { + throw new \danog\MadelineProto\Exception('Not Implemented'); + } + + public function close() + { + $this->sock->close(); + } + + public function getPeerName($port = true) + { + throw new \danog\MadelineProto\Exception('Not Implemented'); + } + + public function getSockName($port = true) + { + throw new \danog\MadelineProto\Exception('Not Implemented'); + } +} diff --git a/_comandi.php b/_comandi.php index e759623..06d3282 100644 --- a/_comandi.php +++ b/_comandi.php @@ -1,61 +1,40 @@ - 5) - { - sm($chatID, "Mi spengo."); - exit; - } - - if(stripos($msg, "!join ")===0) - { - joinChat(explode(" ", $msg, 2)[1], $chatID); - } - - if($msg == "!leave" && stripos($chatID, "-100")===0) - { - abbandonaChat($chatID); - } - //ALTRI COMANDI RISERVATI AGLI ADMIN - - - - - - - } - - - //COMANDI DESTINATI AL PUBBLICO - - - - - - -} + 5) { + sm($chatID, 'Mi spengo.'); + exit; + } + + if (stripos($msg, '!join ') === 0) { + joinChat(explode(' ', $msg, 2)[1], $chatID); + } + + if ($msg == '!leave' && stripos($chatID, '-100') === 0) { + abbandonaChat($chatID); + } + //ALTRI COMANDI RISERVATI AGLI ADMIN + } + + //COMANDI DESTINATI AL PUBBLICO +} diff --git a/_config.php b/_config.php index 2f285cd..764d6b7 100644 --- a/_config.php +++ b/_config.php @@ -1,41 +1,27 @@ -LOGIN FALLITO"; -} - -function failUpdates() -{ - echo "

USERBOT NON AVVIATO. RIAVVIO.

"; - file_get_contents($_SERVER['SCRIPT_URI']); -} - -function finePagina(){ - return true; -} - -function endUpdates() -{ - file_get_contents($_SERVER['SCRIPT_URI']); - echo "Timeout, lanciato nuovo script."; -} - - -function sm($chatID, $text, $parsemode = 'HTML', $reply = 0) { - global $MadelineProto; - if ($reply) $MadelineProto->messages->sendMessage(['peer' => $chatID, 'message' => $text, 'parse_mode' => $parsemode, 'reply_to_msg_id' => $reply]); - else $MadelineProto->messages->sendMessage(['peer' => $chatID, 'message' => $text, 'parse_mode' => $parsemode]); -} - -function setProfilo($nome, $cognome = '') -{ - global $MadelineProto; - $MadelineProto->account->updateProfile(['first_name' => $nome, 'last_name' => $cognome]); -} - -function joinChat($chatLink, $chatLOG) -{ - //ACCETTA SOLO https://t.me/joinchat/ksjdvbdskvhbsdk o @usernameChat in questo formato - global $MadelineProto; - try{ - if(stripos($chatLink, "joinchat")) - { - $MadelineProto->messages->importChatInvite([ - 'hash' => str_replace("https://t.me/joinchat/", "", $chatLink) - ]); - }else{ - $MadelineProto->channels->joinChannel([ - 'channel' => "@" . str_replace("@", "", $chatLink) - ]); - } - sm($chatLOG, "Sono entrato nel canale/gruppo"); - } catch (\danog\MadelineProto\RPCErrorException $e) { - sm($chatLOG, "NON sono entrato nel canale/gruppo."); - } catch (\danog\MadelineProto\Exception $e2) { - sm($chatLOG, "NON sono entrato nel canale/gruppo."); - } -} - -function abbandonaChat($chatID) -{ - //USARE SOLO SU SUPERGRUPPI o CRASH - global $MadelineProto; - $MadelineProto->channels->leaveChannel(['channel' => $chatID]); -} - - - - - - - - - - - - - - - - - - - - - - -?> +LOGIN FALLITO'; +} + +function failUpdates() +{ + echo '

USERBOT NON AVVIATO. RIAVVIO.

'; + file_get_contents($_SERVER['SCRIPT_URI']); +} + +function finePagina() +{ + return true; +} + +function endUpdates() +{ + file_get_contents($_SERVER['SCRIPT_URI']); + echo 'Timeout, lanciato nuovo script.'; +} + +function sm($chatID, $text, $parsemode = 'HTML', $reply = 0) +{ + global $MadelineProto; + if ($reply) { + $MadelineProto->messages->sendMessage(['peer' => $chatID, 'message' => $text, 'parse_mode' => $parsemode, 'reply_to_msg_id' => $reply]); + } else { + $MadelineProto->messages->sendMessage(['peer' => $chatID, 'message' => $text, 'parse_mode' => $parsemode]); + } +} + +function setProfilo($nome, $cognome = '') +{ + global $MadelineProto; + $MadelineProto->account->updateProfile(['first_name' => $nome, 'last_name' => $cognome]); +} + +function joinChat($chatLink, $chatLOG) +{ + //ACCETTA SOLO https://t.me/joinchat/ksjdvbdskvhbsdk o @usernameChat in questo formato + global $MadelineProto; + + try { + if (stripos($chatLink, 'joinchat')) { + $MadelineProto->messages->importChatInvite([ + 'hash' => str_replace('https://t.me/joinchat/', '', $chatLink), + ]); + } else { + $MadelineProto->channels->joinChannel([ + 'channel' => '@'.str_replace('@', '', $chatLink), + ]); + } + sm($chatLOG, 'Sono entrato nel canale/gruppo'); + } catch (\danog\MadelineProto\RPCErrorException $e) { + sm($chatLOG, 'NON sono entrato nel canale/gruppo.'); + } catch (\danog\MadelineProto\Exception $e2) { + sm($chatLOG, 'NON sono entrato nel canale/gruppo.'); + } +} + +function abbandonaChat($chatID) +{ + //USARE SOLO SU SUPERGRUPPI o CRASH + global $MadelineProto; + $MadelineProto->channels->leaveChannel(['channel' => $chatID]); +} diff --git a/login.php b/login.php index bc30223..71bb9b3 100644 --- a/login.php +++ b/login.php @@ -1,56 +1,52 @@ -Già loggato. Per nuovo login, elimina il file session.madeline e aggiorna questa pagina."; - exit; -} - -register_shutdown_function('failLogin'); - -require '_config.php'; - - -if(isset($_POST["code"])){ - $MadelineProto = new \danog\MadelineProto\API("session.madeline"); - $MadelineProto->complete_phone_login($_POST["code"]); - if(isset($_POST["pwd2fa"]) && $_POST["pwd2fa"]) - { - sleep(1); - $MadelineProto->complete_2fa_login($_POST["pwd2fa"]); - } - echo "



LOGIN EFFETTUATO



AVVIA USERBOT

"; - $MadelineProto->serialize(); - register_shutdown_function('finePagina'); - exit; -}else{ - $MadelineProto = new \danog\MadelineProto\API([ - 'app_info' => [ - 'api_id' => $api_id, - 'api_hash' => $api_hash - ], - 'connection_settings' => [ - 'all' => [ - 'protocol' => 'http', - 'pfs' => false, - 'proxy' => '\\HttpProxy', - 'proxy_extra' => [ - 'address' => 'localhost', - 'port' => 80 - ] - ] - ], - 'logger' => [ - 'logger' => 2, - 'logger_param' => __DIR__.'/Madeline.log', - 'logger_level' => 5 - ] - ]); - $MadelineProto->session = __DIR__.'/session.madeline'; - $MadelineProto->phone_login($numero_di_telefono); - $MadelineProto->serialize(); - register_shutdown_function('finePagina'); - ?> +Già loggato. Per nuovo login, elimina il file session.madeline e aggiorna questa pagina.'; + exit; +} + +register_shutdown_function('failLogin'); + +require '_config.php'; + +if (isset($_POST['code'])) { + $MadelineProto = new \danog\MadelineProto\API('session.madeline'); + $MadelineProto->complete_phone_login($_POST['code']); + if (isset($_POST['pwd2fa']) && $_POST['pwd2fa']) { + sleep(1); + $MadelineProto->complete_2fa_login($_POST['pwd2fa']); + } + echo "



LOGIN EFFETTUATO



AVVIA USERBOT

"; + $MadelineProto->serialize(); + register_shutdown_function('finePagina'); + exit; +} else { + $MadelineProto = new \danog\MadelineProto\API([ + 'app_info' => [ + 'api_id' => $api_id, + 'api_hash' => $api_hash, + ], + 'connection_settings' => [ + 'all' => [ + 'protocol' => 'http', + 'pfs' => false, + 'proxy' => '\\HttpProxy', + 'proxy_extra' => [ + 'address' => 'localhost', + 'port' => 80, + ], + ], + ], + 'logger' => [ + 'logger' => 2, + 'logger_param' => __DIR__.'/Madeline.log', + 'logger_level' => 5, + ], + ]); + $MadelineProto->session = __DIR__.'/session.madeline'; + $MadelineProto->phone_login($numero_di_telefono); + $MadelineProto->serialize(); + register_shutdown_function('finePagina'); ?>

Ok stai facendo il login dell'account con numero +

@@ -62,6 +58,6 @@ if(isset($_POST["code"])){
- USERBOT PARTITO"; - -$running = true; -$offset = 0; -$lastser = time(); - -try { - while($running) - { - $updates = $MadelineProto->get_updates(['offset' => $offset]); - foreach($updates as $update) - { - $offset = $update['update_id'] + 1; - - if (isset($update['update']['message']['out']) && $update['update']['message']['out'] && !$leggi_messaggi_in_uscita) { - continue; - } - $up = $update['update']['_']; - - if($up == 'updateNewMessage' or $up == 'updateNewChannelMessage') - { - - if (isset($update['update']['message']['message'])){ - $msg = $update["update"]["message"]["message"]; - } - - if (isset($update['update']['message']['to_id']['channel_id'])) { - $chatID = $update['update']['message']['to_id']['channel_id']; - $chatID = '-100'.$chatID; - $type = "supergruppo"; - } - - if (isset($update['update']['message']['to_id']['chat_id'])) { - $chatID = $update['update']['message']['to_id']['chat_id']; - $chatID = '-'.$chatID; - $type = "gruppo"; - } - - try { - require "_comandi.php"; - } catch(Exception $e) { - if (isset($chatID)) { - try { - sm($chatID,''.$e.''); - } catch(Exception $e) { } - } - } - - if (isset($update['update']['message']['to_id']['user_id'])) { - $chatID = $update['update']['message']['from_id']; - $type = "privato"; - } - - @include("_comandi.php"); - - } - - - if(isset($msg)) unset($msg); - if(isset($chatID)) unset($chatID); - if(isset($userID)) unset($userID); - if(isset($up)) unset($up); - - } - } -} catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log([(string)$e]); - if (in_array($e->rpc, ['SESSION_REVOKED', 'AUTH_KEY_UNREGISTERED'])) { - foreach (glob('session.madeline*') as $path) { - unlink($path); - } - } -} +USERBOT PARTITO'; + +$running = true; +$offset = 0; +$lastser = time(); + +try { + while ($running) { + $updates = $MadelineProto->get_updates(['offset' => $offset]); + foreach ($updates as $update) { + $offset = $update['update_id'] + 1; + + if (isset($update['update']['message']['out']) && $update['update']['message']['out'] && !$leggi_messaggi_in_uscita) { + continue; + } + $up = $update['update']['_']; + + if ($up == 'updateNewMessage' or $up == 'updateNewChannelMessage') { + if (isset($update['update']['message']['message'])) { + $msg = $update['update']['message']['message']; + } + + if (isset($update['update']['message']['to_id']['channel_id'])) { + $chatID = $update['update']['message']['to_id']['channel_id']; + $chatID = '-100'.$chatID; + $type = 'supergruppo'; + } + + if (isset($update['update']['message']['to_id']['chat_id'])) { + $chatID = $update['update']['message']['to_id']['chat_id']; + $chatID = '-'.$chatID; + $type = 'gruppo'; + } + + try { + require '_comandi.php'; + } catch (Exception $e) { + if (isset($chatID)) { + try { + sm($chatID, ''.$e.''); + } catch (Exception $e) { + } + } + } + + if (isset($update['update']['message']['to_id']['user_id'])) { + $chatID = $update['update']['message']['from_id']; + $type = 'privato'; + } + + @include '_comandi.php'; + } + + if (isset($msg)) { + unset($msg); + } + if (isset($chatID)) { + unset($chatID); + } + if (isset($userID)) { + unset($userID); + } + if (isset($up)) { + unset($up); + } + } + } +} catch (\danog\MadelineProto\RPCErrorException $e) { + \danog\MadelineProto\Logger::log([(string) $e]); + if (in_array($e->rpc, ['SESSION_REVOKED', 'AUTH_KEY_UNREGISTERED'])) { + foreach (glob('session.madeline*') as $path) { + unlink($path); + } + } +} From 026530f930a74d991eb0fbc466dccb2bebe9194d Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:23:15 +0200 Subject: [PATCH 03/29] AltervistaUserbot v2 --- .gitignore | 2 + HttpProxy.php | 178 ----------------------------------------- _comandi.php | 6 +- _config.php | 74 +++++++++++++---- updates.php => bot.php | 17 +++- files | 5 ++ functions.php | 27 ++----- login.php | 63 --------------- phar.php | 10 --- 9 files changed, 89 insertions(+), 293 deletions(-) create mode 100644 .gitignore delete mode 100644 HttpProxy.php rename updates.php => bot.php (89%) create mode 100644 files delete mode 100644 login.php delete mode 100644 phar.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a005e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +phar.php +madeline.php diff --git a/HttpProxy.php b/HttpProxy.php deleted file mode 100644 index 0e76a03..0000000 --- a/HttpProxy.php +++ /dev/null @@ -1,178 +0,0 @@ -. -*/ - -class HttpProxy implements \danog\MadelineProto\Proxy -{ - private $domain; - private $type; - private $protocol; - private $extra; - private $sock; - - public function __construct($domain, $type, $protocol) - { - if (!in_array($domain, [AF_INET, AF_INET6])) { - throw new \danog\MadelineProto\Exception('Wrong protocol family provided'); - } - if (!in_array($type, [SOCK_STREAM])) { - throw new \danog\MadelineProto\Exception('Wrong connection type provided'); - } - if (!in_array($protocol, [getprotobyname('tcp')])) { - throw new \danog\MadelineProto\Exception('Wrong protocol provided'); - } - $this->domain = $domain; - $this->type = $type; - $this->protocol = $protocol; - } - - public function setExtra($extra) - { - $this->extra = $extra; - $this->sock = new \Socket(strlen(@inet_pton($this->extra['address'])) !== 4 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, getprotobyname('tcp')); - } - - public function setOption($level, $name, $value) - { - return $this->sock->setOption($level, $name, $value); - } - - public function getOption($level, $name) - { - return $this->sock->getOption($level, $name); - } - - public function setBlocking($blocking) - { - return $this->sock->setBlocking($blocking); - } - - public function bind($address, $port = 0) - { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function listen($backlog = 0) - { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function accept() - { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function select(array &$read, array &$write, array &$except, $tv_sec, $tv_usec = 0) - { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function connect($address, $port = 0) - { - $this->sock->connect($this->extra['address'], $this->extra['port']); - - try { - if (strlen(inet_pton($address)) !== 4) { - $address = '['.$address.']'; - } - } catch (\danog\MadelineProto\Exception $e) { - } - $this->sock->write("CONNECT $address:$port HTTP/1.1\r\n\r\n"); - $response = $this->read_http_payload(); - if ($response['code'] !== 200) { - \danog\MadelineProto\Logger::log([$response['body']]); - - throw new \danog\MadelineProto\Exception($response['description'], $response['code']); - } - \danog\MadelineProto\Logger::log(['Connected to '.$address.':'.$port.' via http']); - - return true; - } - - private function http_read($length) - { - $packet = ''; - while (strlen($packet) < $length) { - $packet .= $this->sock->read($length - strlen($packet)); - if ($packet === false || strlen($packet) === 0) { - throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']); - } - } - - return $packet; - } - - public function read_http_line() - { - $line = ''; - while (($curchar = $this->http_read(1)) !== "\n") { - $line .= $curchar; - } - - return rtrim($line); - } - - public function read_http_payload() - { - $header = explode(' ', $this->read_http_line(), 3); - $protocol = $header[0]; - $code = (int) $header[1]; - $description = $header[2]; - $headers = []; - while (strlen($current_header = $this->read_http_line())) { - $current_header = explode(':', $current_header, 2); - $headers[strtolower($current_header[0])] = trim($current_header[1]); - } - - $read = ''; - if (isset($headers['content-length'])) { - $read = $this->http_read((int) $headers['content-length']); - }/* elseif (isset($headers['transfer-encoding']) && $headers['transfer-encoding'] === 'chunked') { - do { - $length = hexdec($this->read_http_line()); - $read .= $this->http_read($length); - $this->read_http_line(); - } while ($length); - }*/ - - return ['protocol' => $protocol, 'code' => $code, 'description' => $description, 'body' => $read, 'headers' => $headers]; - } - - public function read($length, $flags = 0) - { - return $this->sock->read($length, $flags); - } - - public function write($buffer, $length = -1) - { - return $this->sock->write($buffer, $length); - } - - public function send($data, $length, $flags) - { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function close() - { - $this->sock->close(); - } - - public function getPeerName($port = true) - { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } - - public function getSockName($port = true) - { - throw new \danog\MadelineProto\Exception('Not Implemented'); - } -} diff --git a/_comandi.php b/_comandi.php index 06d3282..58ba4c8 100644 --- a/_comandi.php +++ b/_comandi.php @@ -17,11 +17,15 @@ if (isset($msg) && isset($chatID)) { sm($chatID, "Hello world, I'm alive."); } + if ($msg == '!pony') { + sm($chatID, "This bot is powered by altervistabot & MadelineProto.\n\nCreated by a pony and a bruno."); + } + if (stripos($msg, '!say ') === 0) { sm($chatID, explode(' ', $msg, 2)[1]); } - if ($msg == '!off' and (time() - $lastser) > 5) { + if ($msg == '!off' and (time() - $started) > 5)) { sm($chatID, 'Mi spengo.'); exit; } diff --git a/_config.php b/_config.php index 764d6b7..5da1814 100644 --- a/_config.php +++ b/_config.php @@ -1,19 +1,5 @@

OK!

'); + $size = ob_get_length(); + header("Content-Length: $size"); + header("Content-Type: text/html"); + ob_end_flush(); + flush(); + + + if ($try++ >= 30) { + exit; + } + sleep(1); + } +} + + +require __DIR__.'/madeline.php'; require __DIR__.'/functions.php'; + +register_shutdown_function('shutdown_function', $lock); + + +$leggi_messaggi_in_uscita = false; + +$lista_admin = [ + 40955937, //id di Bruno :D + 101374607, //id del creatore di MadelineProto :D + 12344567, //un id probabilmente inesistente +]; + diff --git a/updates.php b/bot.php similarity index 89% rename from updates.php rename to bot.php index 7996560..1fb3e41 100644 --- a/updates.php +++ b/bot.php @@ -1,16 +1,25 @@ start(); -register_shutdown_function('endUpdates'); -echo '

USERBOT PARTITO

'; + +ob_end_clean(); +header("Connection: close"); +ignore_user_abort(true); +ob_start(); +echo('

OK!

'); +$size = ob_get_length(); +header("Content-Length: $size"); +header("Content-Type: text/html"); +ob_end_flush(); +flush(); $running = true; $offset = 0; -$lastser = time(); +$started = time(); try { while ($running) { diff --git a/files b/files new file mode 100644 index 0000000..e7347f6 --- /dev/null +++ b/files @@ -0,0 +1,5 @@ +_config.php +functions.php +bot.php +LICENSE +.version diff --git a/functions.php b/functions.php index e678086..b69c282 100644 --- a/functions.php +++ b/functions.php @@ -1,26 +1,11 @@ LOGIN FALLITO'; -} - -function failUpdates() -{ - echo '

USERBOT NON AVVIATO. RIAVVIO.

'; - file_get_contents($_SERVER['SCRIPT_URI']); -} - -function finePagina() -{ - return true; -} - -function endUpdates() -{ - file_get_contents($_SERVER['SCRIPT_URI']); - echo 'Timeout, lanciato nuovo 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"); + flock($lock, LOCK_UN); + fclose($lock); } function sm($chatID, $text, $parsemode = 'HTML', $reply = 0) @@ -64,7 +49,7 @@ function joinChat($chatLink, $chatLOG) function abbandonaChat($chatID) { - //USARE SOLO SU SUPERGRUPPI o CRASH + //USARE SOLO SU SUPERGRUPPI/CANALI o CRASH global $MadelineProto; $MadelineProto->channels->leaveChannel(['channel' => $chatID]); } diff --git a/login.php b/login.php deleted file mode 100644 index 71bb9b3..0000000 --- a/login.php +++ /dev/null @@ -1,63 +0,0 @@ -Già loggato. Per nuovo login, elimina il file session.madeline e aggiorna questa pagina.'; - exit; -} - -register_shutdown_function('failLogin'); - -require '_config.php'; - -if (isset($_POST['code'])) { - $MadelineProto = new \danog\MadelineProto\API('session.madeline'); - $MadelineProto->complete_phone_login($_POST['code']); - if (isset($_POST['pwd2fa']) && $_POST['pwd2fa']) { - sleep(1); - $MadelineProto->complete_2fa_login($_POST['pwd2fa']); - } - echo "



LOGIN EFFETTUATO



AVVIA USERBOT

"; - $MadelineProto->serialize(); - register_shutdown_function('finePagina'); - exit; -} else { - $MadelineProto = new \danog\MadelineProto\API([ - 'app_info' => [ - 'api_id' => $api_id, - 'api_hash' => $api_hash, - ], - 'connection_settings' => [ - 'all' => [ - 'protocol' => 'http', - 'pfs' => false, - 'proxy' => '\\HttpProxy', - 'proxy_extra' => [ - 'address' => 'localhost', - 'port' => 80, - ], - ], - ], - 'logger' => [ - 'logger' => 2, - 'logger_param' => __DIR__.'/Madeline.log', - 'logger_level' => 5, - ], - ]); - $MadelineProto->session = __DIR__.'/session.madeline'; - $MadelineProto->phone_login($numero_di_telefono); - $MadelineProto->serialize(); - register_shutdown_function('finePagina'); ?> -
-

Ok stai facendo il login dell'account con numero +

-
- CODICE SMS/TELEGRAM RICEVUTO
- -

EVENTUALE PASSWORD 2FA (lasciare vuoto se non impostata)
- -
- -
-
- Date: Tue, 27 Mar 2018 18:23:34 +0000 Subject: [PATCH 04/29] Apply fixes from StyleCI --- _config.php | 13 ++++--------- bot.php | 7 +++---- functions.php | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/_config.php b/_config.php index 5da1814..d287cca 100644 --- a/_config.php +++ b/_config.php @@ -27,24 +27,22 @@ if (!file_exists(__DIR__.'/.version') || file_get_contents(__DIR__.'/.version') } } - $try = 1; $locked = false; while (!$locked) { - $locked = flock($lock, LOCK_EX|LOCK_NB); + $locked = flock($lock, LOCK_EX | LOCK_NB); if (!$locked) { ob_end_clean(); - header("Connection: close"); + header('Connection: close'); ignore_user_abort(true); ob_start(); - echo('

OK!

'); + echo '

OK!

'; $size = ob_get_length(); header("Content-Length: $size"); - header("Content-Type: text/html"); + header('Content-Type: text/html'); ob_end_flush(); flush(); - if ($try++ >= 30) { exit; } @@ -52,13 +50,11 @@ while (!$locked) { } } - require __DIR__.'/madeline.php'; require __DIR__.'/functions.php'; register_shutdown_function('shutdown_function', $lock); - $leggi_messaggi_in_uscita = false; $lista_admin = [ @@ -66,4 +62,3 @@ $lista_admin = [ 101374607, //id del creatore di MadelineProto :D 12344567, //un id probabilmente inesistente ]; - diff --git a/bot.php b/bot.php index 1fb3e41..3521b58 100644 --- a/bot.php +++ b/bot.php @@ -5,15 +5,14 @@ require '_config.php'; $MadelineProto = new \danog\MadelineProto\API('session.madeline'); $MadelineProto->start(); - ob_end_clean(); -header("Connection: close"); +header('Connection: close'); ignore_user_abort(true); ob_start(); -echo('

OK!

'); +echo '

OK!

'; $size = ob_get_length(); header("Content-Length: $size"); -header("Content-Type: text/html"); +header('Content-Type: text/html'); ob_end_flush(); flush(); diff --git a/functions.php b/functions.php index b69c282..88db5d6 100644 --- a/functions.php +++ b/functions.php @@ -3,7 +3,7 @@ function shutdown_function($lock) { $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"); + fwrite($a, $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL']."\r\n".'Host: '.$_SERVER['SERVER_NAME']."\r\n\r\n"); flock($lock, LOCK_UN); fclose($lock); } From 8def437d05fb466257df087730b410b4c3ea837f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:26:53 +0200 Subject: [PATCH 05/29] Small fixes --- README.md | 10 ++++------ _config.php | 23 ----------------------- bot.php | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 8518ada..8573f94 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,10 @@ Per sapere come utilizzare questo codice, leggere la guida, oppure seguire quest 1. Creare spazio web altervista 2. Attivare cloudflare, https, s2s -3. Caricare file in sottocartella -4. Prendere api_id e api_hash da my.telegram.org -5. Settare le varie cose in \_config.php -6. Lanciare login.php e seguire le varie istruzioni (il caricamento è lento) -7. Lanciare updates.php e chiudere la pagina al termine del caricamento (che darà probabilmente errore 502) +3. Caricare bot.php in sottocartella +4. Settare le varie cose in \_config.php +5. Lanciare bot.php e seguire le varie istruzioni (il primo caricamento è lento) -Per fare un nuovo login, usare una cartella diversa o cancellare il file check.log +Per fare un nuovo login, usare una cartella diversa o cancellare il file session.madeline. Per supporto entrare nel gruppo Telegram. diff --git a/_config.php b/_config.php index 5da1814..0253edc 100644 --- a/_config.php +++ b/_config.php @@ -1,32 +1,9 @@ Date: Tue, 27 Mar 2018 20:28:19 +0200 Subject: [PATCH 06/29] Enable auto-updating --- .version | 1 + bot.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .version diff --git a/.version b/.version new file mode 100644 index 0000000..cd5ac03 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +2.0 diff --git a/bot.php b/bot.php index 90e93e9..7704d55 100644 --- a/bot.php +++ b/bot.php @@ -14,7 +14,7 @@ if (!isset($branch)) { $branch = 'master'; } $url = "https://raw.githubusercontent.com/$remote/$branch"; -$version = file_get_contents("$url/version"); +$version = file_get_contents("$url/.version"); if (!file_exists(__DIR__.'/.version') || file_get_contents(__DIR__.'/.version') !== $version) { foreach (explode("\n", file_get_contents("$url/files")) as $file) { From e485963ce7582e8e2f8111f98f6a656c6d8bec8a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:30:53 +0200 Subject: [PATCH 07/29] Test auto-updating --- .version | 2 +- bot.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.version b/.version index cd5ac03..38f77a6 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.0 +2.0.1 diff --git a/bot.php b/bot.php index 7704d55..e3bd280 100644 --- a/bot.php +++ b/bot.php @@ -18,7 +18,9 @@ $version = file_get_contents("$url/.version"); if (!file_exists(__DIR__.'/.version') || file_get_contents(__DIR__.'/.version') !== $version) { foreach (explode("\n", file_get_contents("$url/files")) as $file) { - copy("$url/$file", __DIR__."/$file"); + if ($file) { + copy("$url/$file", __DIR__."/$file"); + } } } From 4bd87acd081e61cba9c50f850aedb6de8a9174af Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 18:31:08 +0000 Subject: [PATCH 08/29] Apply fixes from StyleCI --- bot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.php b/bot.php index e3bd280..2a67c37 100644 --- a/bot.php +++ b/bot.php @@ -19,7 +19,7 @@ $version = file_get_contents("$url/.version"); if (!file_exists(__DIR__.'/.version') || file_get_contents(__DIR__.'/.version') !== $version) { foreach (explode("\n", file_get_contents("$url/files")) as $file) { if ($file) { - copy("$url/$file", __DIR__."/$file"); + copy("$url/$file", __DIR__."/$file"); } } } From ea23edddbcdb0a0109877e0f5b4a747e97723262 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:36:39 +0200 Subject: [PATCH 09/29] Improve auto-update --- .version | 2 +- bot.php | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.version b/.version index 38f77a6..e9307ca 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.0.1 +2.0.2 diff --git a/bot.php b/bot.php index 2a67c37..1dd9319 100644 --- a/bot.php +++ b/bot.php @@ -7,19 +7,15 @@ if (!file_exists(__DIR__.'/madeline.php') || !filesize(__DIR__.'/madeline.php')) copy('https://phar.madelineproto.xyz/madeline.php', __DIR__.'/madeline.php'); } -if (!isset($remote)) { - $remote = 'danog/AltervistaUserbot'; -} -if (!isset($branch)) { - $branch = 'master'; -} +$remote = 'danog/AltervistaUserbot'; +$branch = 'master'; $url = "https://raw.githubusercontent.com/$remote/$branch"; -$version = file_get_contents("$url/.version"); +$version = file_get_contents("$url/.version?v=new"); if (!file_exists(__DIR__.'/.version') || file_get_contents(__DIR__.'/.version') !== $version) { - foreach (explode("\n", file_get_contents("$url/files")) as $file) { + foreach (explode("\n", file_get_contents("$url/files?v=new")) as $file) { if ($file) { - copy("$url/$file", __DIR__."/$file"); + copy("$url/$file", __DIR__."/$file?v=new"); } } } @@ -113,3 +109,4 @@ try { } } } + From 6f8a129d4b64d6c94f3d13da53a2c5490f714d34 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 18:36:49 +0000 Subject: [PATCH 10/29] Apply fixes from StyleCI --- bot.php | 1 - 1 file changed, 1 deletion(-) diff --git a/bot.php b/bot.php index 1dd9319..8320966 100644 --- a/bot.php +++ b/bot.php @@ -109,4 +109,3 @@ try { } } } - From 2df501805d6bdae564f0261cab5df40145c312b1 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:54:45 +0200 Subject: [PATCH 11/29] Improve self-updates --- .version | 2 +- bot.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.version b/.version index e9307ca..50ffc5a 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.0.2 +2.0.3 diff --git a/bot.php b/bot.php index 8320966..af53a18 100644 --- a/bot.php +++ b/bot.php @@ -11,11 +11,12 @@ $remote = 'danog/AltervistaUserbot'; $branch = 'master'; $url = "https://raw.githubusercontent.com/$remote/$branch"; + $version = file_get_contents("$url/.version?v=new"); if (!file_exists(__DIR__.'/.version') || file_get_contents(__DIR__.'/.version') !== $version) { foreach (explode("\n", file_get_contents("$url/files?v=new")) as $file) { if ($file) { - copy("$url/$file", __DIR__."/$file?v=new"); + copy("$url/$file?v=new", __DIR__."/$file"); } } } From 535a883eeee91e39cf3d6eb298607483b5196757 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 18:54:56 +0000 Subject: [PATCH 12/29] Apply fixes from StyleCI --- bot.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bot.php b/bot.php index af53a18..8ffb561 100644 --- a/bot.php +++ b/bot.php @@ -11,12 +11,11 @@ $remote = 'danog/AltervistaUserbot'; $branch = 'master'; $url = "https://raw.githubusercontent.com/$remote/$branch"; - $version = file_get_contents("$url/.version?v=new"); if (!file_exists(__DIR__.'/.version') || file_get_contents(__DIR__.'/.version') !== $version) { foreach (explode("\n", file_get_contents("$url/files?v=new")) as $file) { if ($file) { - copy("$url/$file?v=new", __DIR__."/$file"); + copy("$url/$file?v=new", __DIR__."/$file"); } } } From 1f1aad5fbdc1fc3914646f6dbd34e5625e37b875 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:58:19 +0200 Subject: [PATCH 13/29] Bugfix --- .version | 2 +- bot.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.version b/.version index 50ffc5a..2165f8f 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.0.3 +2.0.4 diff --git a/bot.php b/bot.php index af53a18..d036c4b 100644 --- a/bot.php +++ b/bot.php @@ -3,6 +3,7 @@ ini_set('display_errors', true); error_reporting(E_ALL); +chdir(__DIR__); if (!file_exists(__DIR__.'/madeline.php') || !filesize(__DIR__.'/madeline.php')) { copy('https://phar.madelineproto.xyz/madeline.php', __DIR__.'/madeline.php'); } From 9570ba7403fe160fa3d9379e4d2717ac2110d9e6 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 19:36:20 +0000 Subject: [PATCH 14/29] Improve self-update mechanism --- .version | 1 - av.version | 1 + basefiles | 1 + bot.php | 9 +++++++-- 4 files changed, 9 insertions(+), 3 deletions(-) delete mode 100644 .version create mode 100644 av.version create mode 100644 basefiles diff --git a/.version b/.version deleted file mode 100644 index 2165f8f..0000000 --- a/.version +++ /dev/null @@ -1 +0,0 @@ -2.0.4 diff --git a/av.version b/av.version new file mode 100644 index 0000000..e010258 --- /dev/null +++ b/av.version @@ -0,0 +1 @@ +2.0.5 diff --git a/basefiles b/basefiles new file mode 100644 index 0000000..abcd323 --- /dev/null +++ b/basefiles @@ -0,0 +1 @@ +_comandi.php diff --git a/bot.php b/bot.php index c994f19..a31293c 100644 --- a/bot.php +++ b/bot.php @@ -12,13 +12,18 @@ $remote = 'danog/AltervistaUserbot'; $branch = 'master'; $url = "https://raw.githubusercontent.com/$remote/$branch"; -$version = file_get_contents("$url/.version?v=new"); -if (!file_exists(__DIR__.'/.version') || file_get_contents(__DIR__.'/.version') !== $version) { +$version = file_get_contents("$url/av.version?v=new"); +if (!file_exists(__DIR__.'/av.version') || file_get_contents(__DIR__.'/av.version') !== $version) { foreach (explode("\n", file_get_contents("$url/files?v=new")) as $file) { if ($file) { copy("$url/$file?v=new", __DIR__."/$file"); } } + foreach (explode("\n", file_get_contents("$url/basefiles?v=new")) as $file) { + if ($file && !file_exists(__DIR__."/$file")) { + copy("$url/$file?v=new", __DIR__."/$file"); + } + } } require '_config.php'; From 62ae28bd4c823aa3fa424ac2f476b66f9f94d008 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 19:37:54 +0000 Subject: [PATCH 15/29] Update files list --- files | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files b/files index e7347f6..d5ece2b 100644 --- a/files +++ b/files @@ -2,4 +2,4 @@ _config.php functions.php bot.php LICENSE -.version +av.version From 2fb450c297c06ced5c2c2c6eb84a077f2d9c72d1 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 19:53:10 +0000 Subject: [PATCH 16/29] Bugfixes --- _config.php | 12 +----------- av.version | 2 +- bot.php | 12 ++---------- functions.php | 13 +++++++++++++ 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/_config.php b/_config.php index 047839d..a5907ce 100644 --- a/_config.php +++ b/_config.php @@ -10,16 +10,7 @@ $locked = false; while (!$locked) { $locked = flock($lock, LOCK_EX | LOCK_NB); if (!$locked) { - ob_end_clean(); - header('Connection: close'); - ignore_user_abort(true); - ob_start(); - echo '

OK!

'; - $size = ob_get_length(); - header("Content-Length: $size"); - header('Content-Type: text/html'); - ob_end_flush(); - flush(); + closeConnection(); if ($try++ >= 30) { exit; @@ -31,7 +22,6 @@ while (!$locked) { require __DIR__.'/madeline.php'; require __DIR__.'/functions.php'; -register_shutdown_function('shutdown_function', $lock); $leggi_messaggi_in_uscita = false; diff --git a/av.version b/av.version index e010258..157e54f 100644 --- a/av.version +++ b/av.version @@ -1 +1 @@ -2.0.5 +2.0.6 diff --git a/bot.php b/bot.php index a31293c..d80515b 100644 --- a/bot.php +++ b/bot.php @@ -31,16 +31,8 @@ require '_config.php'; $MadelineProto = new \danog\MadelineProto\API('session.madeline'); $MadelineProto->start(); -ob_end_clean(); -header('Connection: close'); -ignore_user_abort(true); -ob_start(); -echo '

OK!

'; -$size = ob_get_length(); -header("Content-Length: $size"); -header('Content-Type: text/html'); -ob_end_flush(); -flush(); +register_shutdown_function('shutdown_function', $lock); +closeConnection(); $running = true; $offset = 0; diff --git a/functions.php b/functions.php index 88db5d6..d7cc578 100644 --- a/functions.php +++ b/functions.php @@ -1,5 +1,18 @@

'.$message.'

'; + $size = ob_get_length(); + header("Content-Length: $size"); + header('Content-Type: text/html'); + ob_end_flush(); + flush(); +} + function shutdown_function($lock) { $a = fsockopen((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'tls' : 'tcp').'://'.$_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']); From 12de1b2d1a842a9d14aad299c61c3337569a2717 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 19:53:25 +0000 Subject: [PATCH 17/29] Apply fixes from StyleCI --- _config.php | 1 - 1 file changed, 1 deletion(-) diff --git a/_config.php b/_config.php index a5907ce..1d99430 100644 --- a/_config.php +++ b/_config.php @@ -22,7 +22,6 @@ while (!$locked) { require __DIR__.'/madeline.php'; require __DIR__.'/functions.php'; - $leggi_messaggi_in_uscita = false; $lista_admin = [ From 7579981d1ce98d3eeb5705aab18aa178052c048f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 19:58:11 +0000 Subject: [PATCH 18/29] Testing self-updates with syntax mistakes --- av.version | 2 +- functions.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/av.version b/av.version index 157e54f..f1547e6 100644 --- a/av.version +++ b/av.version @@ -1 +1 @@ -2.0.6 +2.0.7 diff --git a/functions.php b/functions.php index d7cc578..9ea897f 100644 --- a/functions.php +++ b/functions.php @@ -1,6 +1,6 @@ Date: Tue, 27 Mar 2018 19:58:27 +0000 Subject: [PATCH 19/29] Apply fixes from StyleCI --- functions.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/functions.php b/functions.php index 9ea897f..1ba70a6 100644 --- a/functions.php +++ b/functions.php @@ -1,16 +1,17 @@

'.$message.'

'; - $size = ob_get_length(); - header("Content-Length: $size"); - header('Content-Type: text/html'); - ob_end_flush(); - flush(); +function closeConnection($message = 'OK!') +{ + ob_end_clean(); + header('Connection: close'); + ignore_user_abort(true); + ob_start(); + echo '

'.$message.'

'; + $size = ob_get_length(); + header("Content-Length: $size"); + header('Content-Type: text/html'); + ob_end_flush(); + flush(); } function shutdown_function($lock) From 29bd587ee80fff7d663f32cad742a145722abaf3 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:09:10 +0000 Subject: [PATCH 20/29] bugfixes --- _comandi.php | 2 +- av.version | 2 +- bot.php | 14 ++++---------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/_comandi.php b/_comandi.php index 58ba4c8..9392362 100644 --- a/_comandi.php +++ b/_comandi.php @@ -25,7 +25,7 @@ if (isset($msg) && isset($chatID)) { sm($chatID, explode(' ', $msg, 2)[1]); } - if ($msg == '!off' and (time() - $started) > 5)) { + if ($msg == '!off' and (time() - $started) > 5) { sm($chatID, 'Mi spengo.'); exit; } diff --git a/av.version b/av.version index f1547e6..815e68d 100644 --- a/av.version +++ b/av.version @@ -1 +1 @@ -2.0.7 +2.0.8 diff --git a/bot.php b/bot.php index d80515b..a00bbdd 100644 --- a/bot.php +++ b/bot.php @@ -58,12 +58,13 @@ try { $chatID = $update['update']['message']['to_id']['channel_id']; $chatID = '-100'.$chatID; $type = 'supergruppo'; - } - - if (isset($update['update']['message']['to_id']['chat_id'])) { + } else if (isset($update['update']['message']['to_id']['chat_id'])) { $chatID = $update['update']['message']['to_id']['chat_id']; $chatID = '-'.$chatID; $type = 'gruppo'; + } else (isset($update['update']['message']['to_id']['user_id'])) { + $chatID = $update['update']['message']['from_id']; + $type = 'privato'; } try { @@ -76,13 +77,6 @@ try { } } } - - if (isset($update['update']['message']['to_id']['user_id'])) { - $chatID = $update['update']['message']['from_id']; - $type = 'privato'; - } - - @include '_comandi.php'; } if (isset($msg)) { From a594088848092be937d25c2d8a7570f6661cee47 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:14:22 +0000 Subject: [PATCH 21/29] Use _config.php only for config --- _comandi.php | 2 ++ _config.php | 25 +------------------------ av.version | 2 +- basefiles | 1 + bot.php | 22 +++++++++++++++++++++- files | 1 - 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/_comandi.php b/_comandi.php index 9392362..cccd0a0 100644 --- a/_comandi.php +++ b/_comandi.php @@ -1,5 +1,7 @@ = 30) { - exit; - } - sleep(1); - } -} - -require __DIR__.'/madeline.php'; -require __DIR__.'/functions.php'; - -$leggi_messaggi_in_uscita = false; +$leggi_messaggi_in_uscita = true; $lista_admin = [ 40955937, //id di Bruno :D diff --git a/av.version b/av.version index 815e68d..09843e3 100644 --- a/av.version +++ b/av.version @@ -1 +1 @@ -2.0.8 +2.0.9 diff --git a/basefiles b/basefiles index abcd323..ea78b00 100644 --- a/basefiles +++ b/basefiles @@ -1 +1,2 @@ _comandi.php +_config.php diff --git a/bot.php b/bot.php index a00bbdd..97dc76e 100644 --- a/bot.php +++ b/bot.php @@ -26,7 +26,27 @@ if (!file_exists(__DIR__.'/av.version') || file_get_contents(__DIR__.'/av.versio } } -require '_config.php'; +if (!file_exists('bot.lock')) { + touch('bot.lock'); +} +$lock = fopen('bot.lock', 'r+'); + +$try = 1; +$locked = false; +while (!$locked) { + $locked = flock($lock, LOCK_EX | LOCK_NB); + if (!$locked) { + closeConnection(); + + if ($try++ >= 30) { + exit; + } + sleep(1); + } +} + +require __DIR__.'/madeline.php'; +require __DIR__.'/functions.php'; $MadelineProto = new \danog\MadelineProto\API('session.madeline'); $MadelineProto->start(); diff --git a/files b/files index d5ece2b..6fc2ba2 100644 --- a/files +++ b/files @@ -1,4 +1,3 @@ -_config.php functions.php bot.php LICENSE From c90ba53e107bd6855be5d22873290554c5af29cb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:15:15 +0000 Subject: [PATCH 22/29] Apply fixes from StyleCI --- _config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/_config.php b/_config.php index 8e316f6..ffa7da1 100644 --- a/_config.php +++ b/_config.php @@ -1,4 +1,5 @@ Date: Tue, 27 Mar 2018 20:34:17 +0000 Subject: [PATCH 23/29] Fix --- bot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.php b/bot.php index 97dc76e..9989fdc 100644 --- a/bot.php +++ b/bot.php @@ -82,7 +82,7 @@ try { $chatID = $update['update']['message']['to_id']['chat_id']; $chatID = '-'.$chatID; $type = 'gruppo'; - } else (isset($update['update']['message']['to_id']['user_id'])) { + } else if (isset($update['update']['message']['to_id']['user_id'])) { $chatID = $update['update']['message']['from_id']; $type = 'privato'; } From 7dd9fb506c707d7698b0006eaf05ac3e0b330da8 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 20:34:31 +0000 Subject: [PATCH 24/29] Apply fixes from StyleCI --- bot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot.php b/bot.php index 9989fdc..abf97f7 100644 --- a/bot.php +++ b/bot.php @@ -78,11 +78,11 @@ try { $chatID = $update['update']['message']['to_id']['channel_id']; $chatID = '-100'.$chatID; $type = 'supergruppo'; - } else if (isset($update['update']['message']['to_id']['chat_id'])) { + } elseif (isset($update['update']['message']['to_id']['chat_id'])) { $chatID = $update['update']['message']['to_id']['chat_id']; $chatID = '-'.$chatID; $type = 'gruppo'; - } else if (isset($update['update']['message']['to_id']['user_id'])) { + } elseif (isset($update['update']['message']['to_id']['user_id'])) { $chatID = $update['update']['message']['from_id']; $type = 'privato'; } From 78739a614997a85906c0ab51486372410bb09b00 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 22:44:51 +0000 Subject: [PATCH 25/29] Bugfixes & added CLI support --- .gitignore | 3 +++ av.version | 2 +- bot.php | 25 +++++++++++-------------- functions.php | 1 + 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 2a005e0..98c3335 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ +bot.lock +madeline.phar* +*.madeline* phar.php madeline.php diff --git a/av.version b/av.version index 09843e3..0a69206 100644 --- a/av.version +++ b/av.version @@ -1 +1 @@ -2.0.9 +2.0.10 diff --git a/bot.php b/bot.php index abf97f7..ff0dd17 100644 --- a/bot.php +++ b/bot.php @@ -48,7 +48,7 @@ while (!$locked) { require __DIR__.'/madeline.php'; require __DIR__.'/functions.php'; -$MadelineProto = new \danog\MadelineProto\API('session.madeline'); +$MadelineProto = new \danog\MadelineProto\API('session.madeline', ['logger' => ['logger_level' => 5]]); $MadelineProto->start(); register_shutdown_function('shutdown_function', $lock); @@ -74,17 +74,14 @@ try { $msg = $update['update']['message']['message']; } - if (isset($update['update']['message']['to_id']['channel_id'])) { - $chatID = $update['update']['message']['to_id']['channel_id']; - $chatID = '-100'.$chatID; - $type = 'supergruppo'; - } elseif (isset($update['update']['message']['to_id']['chat_id'])) { - $chatID = $update['update']['message']['to_id']['chat_id']; - $chatID = '-'.$chatID; - $type = 'gruppo'; - } elseif (isset($update['update']['message']['to_id']['user_id'])) { - $chatID = $update['update']['message']['from_id']; - $type = 'privato'; + try { + $chatID = $MadelineProto->get_info($update['update']); + $type = $chatID['type']; + $chatID = $chatID['bot_api_id']; + } catch (Exception $e) {} + + if (isset($update['update']['message']['from_id'])) { + $userID = $update['update']['message']['from_id']; } try { @@ -92,7 +89,7 @@ try { } catch (Exception $e) { if (isset($chatID)) { try { - sm($chatID, ''.$e.''); + //sm($chatID, ''.$e.''); } catch (Exception $e) { } } @@ -114,7 +111,7 @@ try { } } } catch (\danog\MadelineProto\RPCErrorException $e) { - \danog\MadelineProto\Logger::log([(string) $e]); + \danog\MadelineProto\Logger::log((string) $e); if (in_array($e->rpc, ['SESSION_REVOKED', 'AUTH_KEY_UNREGISTERED'])) { foreach (glob('session.madeline*') as $path) { unlink($path); diff --git a/functions.php b/functions.php index 1ba70a6..9565f07 100644 --- a/functions.php +++ b/functions.php @@ -2,6 +2,7 @@ function closeConnection($message = 'OK!') { + if (php_sapi_name() === 'cli') return; ob_end_clean(); header('Connection: close'); ignore_user_abort(true); From 0c5c45921cb38c0e24de45ed9968808cec7be744 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 22:45:11 +0000 Subject: [PATCH 26/29] Apply fixes from StyleCI --- bot.php | 3 ++- functions.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bot.php b/bot.php index ff0dd17..62200dd 100644 --- a/bot.php +++ b/bot.php @@ -78,7 +78,8 @@ try { $chatID = $MadelineProto->get_info($update['update']); $type = $chatID['type']; $chatID = $chatID['bot_api_id']; - } catch (Exception $e) {} + } catch (Exception $e) { + } if (isset($update['update']['message']['from_id'])) { $userID = $update['update']['message']['from_id']; diff --git a/functions.php b/functions.php index 9565f07..be5b93f 100644 --- a/functions.php +++ b/functions.php @@ -2,7 +2,9 @@ function closeConnection($message = 'OK!') { - if (php_sapi_name() === 'cli') return; + if (php_sapi_name() === 'cli') { + return; + } ob_end_clean(); header('Connection: close'); ignore_user_abort(true); From 4d15599943e56c2a93697922f5cf67b86f10be10 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 22:50:04 +0000 Subject: [PATCH 27/29] Final fixes --- av.version | 2 +- bot.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/av.version b/av.version index 0a69206..6cbacdc 100644 --- a/av.version +++ b/av.version @@ -1 +1 @@ -2.0.10 +2.0.11 diff --git a/bot.php b/bot.php index 62200dd..7584d20 100644 --- a/bot.php +++ b/bot.php @@ -47,6 +47,7 @@ while (!$locked) { require __DIR__.'/madeline.php'; require __DIR__.'/functions.php'; +require __DIR__.'/_config.php'; $MadelineProto = new \danog\MadelineProto\API('session.madeline', ['logger' => ['logger_level' => 5]]); $MadelineProto->start(); @@ -78,8 +79,7 @@ try { $chatID = $MadelineProto->get_info($update['update']); $type = $chatID['type']; $chatID = $chatID['bot_api_id']; - } catch (Exception $e) { - } + } catch (Exception $e) {} if (isset($update['update']['message']['from_id'])) { $userID = $update['update']['message']['from_id']; From 7b266eda4d2de3df4c3cbbaef57269a8db45caeb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 22:50:24 +0000 Subject: [PATCH 28/29] Apply fixes from StyleCI --- bot.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot.php b/bot.php index 7584d20..68ddd6f 100644 --- a/bot.php +++ b/bot.php @@ -79,7 +79,8 @@ try { $chatID = $MadelineProto->get_info($update['update']); $type = $chatID['type']; $chatID = $chatID['bot_api_id']; - } catch (Exception $e) {} + } catch (Exception $e) { + } if (isset($update['update']['message']['from_id'])) { $userID = $update['update']['message']['from_id']; From 18b0b34acec72d4dbe4cfda67d941c21eb4d75d6 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 27 Mar 2018 22:55:08 +0000 Subject: [PATCH 29/29] Update readme --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8573f94..8c84a48 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,9 @@ Per sapere come utilizzare questo codice, leggere la guida, oppure seguire quest 1. Creare spazio web altervista 2. Attivare cloudflare, https, s2s -3. Caricare bot.php in sottocartella -4. Settare le varie cose in \_config.php -5. Lanciare bot.php e seguire le varie istruzioni (il primo caricamento è lento) +3. Caricare bot.php +4. Lanciare bot.php e seguire le varie istruzioni (il primo caricamento è lento) -Per fare un nuovo login, usare una cartella diversa o cancellare il file session.madeline. +Per fare un nuovo login, usare una cartella diversa o eliminare la sessione dalle impostazioni telegram. Per supporto entrare nel gruppo Telegram.