Skip to content

Instantly share code, notes, and snippets.

@teleclient
Last active February 28, 2021 03:09
Show Gist options
  • Save teleclient/d3e53abf2217136b0e34cfc505c0531f to your computer and use it in GitHub Desktop.
Save teleclient/d3e53abf2217136b0e34cfc505c0531f to your computer and use it in GitHub Desktop.

Revisions

  1. teleclient revised this gist Feb 28, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion verify.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <?php // questions? bug? support? => contact t.me/webwarp

    /* Ensure that:
    /* The script ensures that:
    * The session is not logged-out;
    * The session is not terminated;
    * The session file is not corrupted;
  2. teleclient revised this gist Feb 28, 2021. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion verify.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,12 @@
    <?php // questions? bug? support? => contact t.me/webwarp

    /* Ensure that:
    * The session is not logged-out;
    * The session is not terminated;
    * The session file is not corrupted;
    * The logged-in account is not deleted.
    */

    declare(strict_types=1);
    define('SCRIPT_INFO', 'VERIFY V1.0.0'); // <== Do not change!

    @@ -14,7 +21,7 @@
    ini_set('log_errors', '1');
    ini_set('error_log', 'MadelineProto.log');

    includeMadeline('composer');
    includeMadeline('phar');

    $sessions = findSessions();
    if (count($sessions) !== 1) {
  3. teleclient created this gist Feb 28, 2021.
    93 changes: 93 additions & 0 deletions verify.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,93 @@
    <?php // questions? bug? support? => contact t.me/webwarp

    declare(strict_types=1);
    define('SCRIPT_INFO', 'VERIFY V1.0.0'); // <== Do not change!

    use \danog\MadelineProto\API;
    use \danog\MadelineProto\Logger;
    use \danog\MadelineProto\Shutdown;

    error_reporting(E_ALL);
    ini_set('ignore_repeated_errors', '1');
    ini_set('display_startup_errors', '1');
    ini_set('display_errors', '1');
    ini_set('log_errors', '1');
    ini_set('error_log', 'MadelineProto.log');

    includeMadeline('composer');

    $sessions = findSessions();
    if (count($sessions) !== 1) {
    suffocateRobot('No session file or more than one!');
    }

    $session = $sessions[0];
    $settings = [
    'logger' => [
    'logger' => Logger::CALLABLE_LOGGER,
    'logger_param' => 'filter',
    'logger_level' => Logger::ULTRA_VERBOSE,
    ]
    ];
    $mp = new API($session, $settings);
    Shutdown::removeCallback('restarter');
    if ($mp->API->authorized === 3 && !$mp->hasAllAuth()) {
    suffocateRobot('The Logged-in account might have been deleted!');
    }
    $mp->async(true);
    $mp->loop(function () use ($mp) {
    yield $mp->start();
    });
    suffocateRobot('Everythin is hunky-dory!');

    function filter($entry, int $level): void
    {
    if (\is_string($entry) && strpos($entry, 'Could not resend req_pq_multi') !== false) {
    suffocateRobot('Session is bad!');
    }
    }

    function suffocateRobot(string $message = 'Everything is OK!'): void
    {
    $buffer = @\ob_get_clean() ?: '';
    $buffer .= '<html><body><h1>' . \htmlentities($message) . '</h1></body></html>';
    \ignore_user_abort(true);
    \header('Connection: close');
    \header('Content-Type: text/html');
    echo $buffer;
    \flush();
    Shutdown::removeCallback('restarter');
    Shutdown::removeCallback(0);
    Shutdown::removeCallback(1);
    Shutdown::removeCallback(2);
    exit(1);
    }

    function findSessions(): array
    {
    $sessions = [];
    foreach (glob('*.*.lock') as $file) {
    $file = substr($file, 0, strlen($file) - 5);
    if (file_exists($file)) {
    $sessions[] = $file;
    }
    }
    return $sessions;
    }

    function includeMadeline(string $source = 'phar', string $param = '')
    {
    switch ($source) {
    case 'phar':
    if (!\file_exists('madeline.php')) {
    \copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
    }
    include 'madeline.php';
    break;
    case 'composer':
    include 'vendor/autoload.php';
    break;
    default:
    throw new \ErrorException("Invalid argument: '$source'");
    }
    }