diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..98c3335 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bot.lock +madeline.phar* +*.madeline* +phar.php +madeline.php diff --git a/HttpProxy.php b/HttpProxy.php deleted file mode 100644 index f091a05..0000000 --- a/HttpProxy.php +++ /dev/null @@ -1,153 +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'); - } -} \ No newline at end of file diff --git a/README.md b/README.md index 8518ada..8c84a48 100644 --- a/README.md +++ b/README.md @@ -6,12 +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 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 +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 check.log +Per fare un nuovo login, usare una cartella diversa o eliminare la sessione dalle impostazioni telegram. Per supporto entrare nel gruppo Telegram. diff --git a/_comandi.php b/_comandi.php index e759623..cccd0a0 100644 --- a/_comandi.php +++ b/_comandi.php @@ -1,61 +1,46 @@ - 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..ffa7da1 100644 --- a/_config.php +++ b/_config.php @@ -1,41 +1,9 @@ -= 30) { + exit; + } + sleep(1); + } +} + +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(); + +register_shutdown_function('shutdown_function', $lock); +closeConnection(); + +$running = true; +$offset = 0; +$started = 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']; + } + + 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 { + require '_comandi.php'; + } catch (Exception $e) { + if (isset($chatID)) { + try { + //sm($chatID, ''.$e.''); + } catch (Exception $e) { + } + } + } + } + + 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); + } + } +} diff --git a/files b/files new file mode 100644 index 0000000..6fc2ba2 --- /dev/null +++ b/files @@ -0,0 +1,4 @@ +functions.php +bot.php +LICENSE +av.version diff --git a/functions.php b/functions.php index b9bf720..be5b93f 100644 --- a/functions.php +++ b/functions.php @@ -1,89 +1,72 @@ -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]); -} - - - - - - - - - - - - - - - - - - - - - - -?> +

'.$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']); + 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) +{ + 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/CANALI o CRASH + global $MadelineProto; + $MadelineProto->channels->leaveChannel(['channel' => $chatID]); +} diff --git a/login.php b/login.php deleted file mode 100644 index 2ec26b5..0000000 --- a/login.php +++ /dev/null @@ -1,70 +0,0 @@ -Già loggato. Per nuovo login, elimina il file check.log 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

"; - file_put_contents("check.log", "ok"); - $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)
- -
- -
-
- session = __DIR__.'/session.madeline'; - -register_shutdown_function('endUpdates'); -echo "

USERBOT PARTITO

"; - -$running = true; -$offset = 0; -$lastser = time(); - -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"; - } - - 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"; - } - - try { - require "_comandi.php"; - } catch(Exception $e) { - if (isset($chatID)) { - try { - sm($chatID,''.$e.''); - } catch(Exception $e) { } - } - } - - } - - - if(isset($msg)) unset($msg); - if(isset($chatID)) unset($chatID); - if(isset($userID)) unset($userID); - if(isset($up)) unset($up); - - - } -}