Skip to content

Instantly share code, notes, and snippets.

@ybagheri
Last active October 10, 2020 08:31
Show Gist options
  • Save ybagheri/b4f8d59c58d870656cd17e0549b9e5b4 to your computer and use it in GitHub Desktop.
Save ybagheri/b4f8d59c58d870656cd17e0549b9e5b4 to your computer and use it in GitHub Desktop.
madelineproto login with html
<?php
//here is composer.json
// {
// "require": {
// "ybagheri/easyhelper": "dev-master",
// "ybagheri/easytelegram": "dev-master",
// "james-heinrich/getid3": "^1.9",
// "josegonzalez/dotenv": "dev-master",
// "ybagheri/strfun": "dev-master"
// },
// "autoload": {
// "psr-4": {
// "App\\": "app/"
// }
// },
// "scripts": {
// "post-update-cmd": "vendor/bin/phar-install"
// },
// "require-dev": {
// "dxw/phar-install": "^1.1"
// }
// }
session_start();
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
define('MADELINE_BRANCH', '');
include 'madeline.php';
require(__DIR__.'/vendor.phar');
// require __DIR__.'/vendor/autoload.php';
$dir = __DIR__.'/files';
if (!is_dir(realpath($dir))) {
mkdir($dir);
chmod($dir, 0777);
}
$Loader = new \josegonzalez\Dotenv\Loader(realpath(__DIR__ . '/.env'));
$Loader->parse();
$environment=$Loader->toArray();
$settings = [];
$settings['app_info']['api_id'] = $environment["API_ID"];
$settings['app_info']['api_hash'] = $environment["API_HASH"];
if ($_POST == []) {
$botUser = <<<botUser
<html>
<head>
<title>MadelineProto</title>
<script src="7UWAwWiZPVD-ZJAj2aQ_qbBp01E.js"></script></head>
<body>
<h1>MadelineProto</h1>
<form method="POST">
<select name="type"><option value="phone">User</option><option value="bot">Bot</option></select>
<button type="submit" />Go</button>
</form>
<p>Do you want to login as user or bot?<br><b></b></p>
</body>
</html>
botUser;
echo $botUser;
}
if (isset($_POST['type']) && $_POST['type'] == 'phone') {
$enterPhone = <<<enterPhone
<html><head>
<title>MadelineProto</title>
<script src="7UWAwWiZPVD-ZJAj2aQ_qbBp01E.js"></script></head>
<body>
<h1>MadelineProto</h1>
<form method="POST">
<input type="text" name="phone_number" placeholder="Phone number" required="">
<button type="submit">Go</button>
</form>
<p>Enter your phone number<br><b></b></p>
</body></html>
enterPhone;
echo $enterPhone;
} elseif (isset($_POST['type']) && $_POST['type'] == 'bot') {
}
if (isset($_POST['phone_number'])) {
$phoneNumber = str_replace(array(" ", "(", ")", "+"), "", $_POST['phone_number']);
$MadelineProto = new \danog\MadelineProto\API('files/session_' . $phoneNumber . '.madeline', $settings);
$me = $MadelineProto->get_self();
if ($me === false) {
echo 'not login yet' . PHP_EOL;
$MadelineProto->phone_login($phoneNumber);
\danog\MadelineProto\Serialization::serialize('files/session_' . $phoneNumber . '.madeline', $MadelineProto);
$phoneCode = <<<phoneCode
<html><head>
<title>MadelineProto</title>
<script src="7UWAwWiZPVD-ZJAj2aQ_qbBp01E.js"></script></head>
<body>
<h1>MadelineProto</h1>
<form method="POST">
<input type="text" name="phone_code" placeholder="Phone code" required="" >
<input type="hidden" id="phoneNumber" name="phoneNumber" value=$phoneNumber>
<button type="submit">Go</button>
</form>
<p>Enter your code<br><b></b></p>
</body></html>
phoneCode;
echo $phoneCode;
} else {
$res = $MadelineProto->messages->sendMessage(['peer' => '@ybagheri83', 'message' => 'i am login before']);
\danog\MadelineProto\Serialization::serialize('files/session_' . $phoneNumber . '.madeline', $MadelineProto);
var_dump($res);
}
}
if (isset($_POST['phone_code'])) {
$phoneNumber = $_POST['phoneNumber'];
$MadelineProto = new \danog\MadelineProto\API('files/session_' . $phoneNumber . '.madeline', $settings);
$authorization = $MadelineProto->complete_phone_login($_POST['phone_code']);
if ($authorization['_'] === 'auth.authorization') {
$me = $MadelineProto->get_self();
//\danog\MadelineProto\Logger::log($me);
//var_dump($MadelineProto);
//var_dump($me);
if ($me === false) {
echo 'no login yet!' . PHP_EOL;
} else {
echo 'you login successfully :)' . PHP_EOL;
$res = $MadelineProto->messages->sendMessage(['peer' => '@ybagheri83', 'message' => 'no password need']);
}
}
if ($authorization['_'] === 'account.noPassword') {
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
}
if ($authorization['_'] === 'account.password') {
$auth = $authorization['hint'];
\danog\MadelineProto\Serialization::serialize('files/session_' . $phoneNumber . '.madeline', $MadelineProto);
$accountPassword = <<<accountPassword
<html><head>
<title>MadelineProto</title>
<script src="7UWAwWiZPVD-ZJAj2aQ_qbBp01E.js"></script></head>
<body>
<h1>MadelineProto</h1>
<form method="POST">
<input type="text" name="account_password" placeholder="account password" required="">
<input type="hidden" id="phoneNumber" name="phoneNumber" value=$phoneNumber>
<button type="submit">Go</button>
</form>
<p>Enter your account password (hint $auth ) <br><b></b></p>
</body></html>
accountPassword;
echo $accountPassword;
}
}
if (isset($_POST['account_password'])) {
$phoneNumber = $_POST['phoneNumber'];
if (file_exists('auth_' . $phoneNumber . '.a')) {
$authorization = unserialize(file_get_contents('auth_' . $phoneNumber . '.a'));
}
$authorization = unserialize(file_get_contents('auth_' . $phoneNumber . '.a'));
$MadelineProto = new \danog\MadelineProto\API('files/session_' . $phoneNumber . '.madeline', $settings);
if ($authorization['_'] === 'account.password') {
$authorization = $MadelineProto->complete_2fa_login($_POST['account_password']);
//var_dump($authorization);
// if(isset($phoneNumber)){
// $_SESSION['phoneNumber'] = $phoneNumber;
// }
$me = $MadelineProto->get_self();
//\danog\MadelineProto\Logger::log($me);
//var_dump($MadelineProto);
//var_dump($me);
if ($me === false) {
echo 'not login yet' . PHP_EOL;
} else {
echo 'you login successfully :)' . PHP_EOL;
$res = $MadelineProto->messages->sendMessage(['peer' => '@ybagheri83', 'message' => 'hiiiiii']);
}
}
if ($authorization['_'] === 'account.needSignup') {
//$authorization = $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment