2019-06-07 20:36:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function ___install_madeline()
|
|
|
|
{
|
2019-10-28 19:53:07 +01:00
|
|
|
if (\count(\debug_backtrace(0)) === 1) {
|
2019-06-07 20:36:26 +02:00
|
|
|
die('You must include this file in another PHP script'.PHP_EOL);
|
|
|
|
}
|
2019-06-17 12:56:28 +02:00
|
|
|
$old = false;
|
|
|
|
if (PHP_MAJOR_VERSION === 5) {
|
|
|
|
if (PHP_MINOR_VERSION < 6) {
|
|
|
|
throw new \Exception('MadelineProto requires at least PHP 7.1 to run');
|
|
|
|
}
|
|
|
|
$old = true;
|
|
|
|
}
|
|
|
|
if (PHP_MAJOR_VERSION === 7 && PHP_MINOR_VERSION === 0) {
|
|
|
|
$old = true;
|
|
|
|
}
|
|
|
|
if ($old) {
|
|
|
|
$newline = PHP_EOL;
|
2019-10-28 19:53:07 +01:00
|
|
|
if (PHP_SAPI !== 'cli') {
|
2019-06-17 12:56:28 +02:00
|
|
|
$newline = '<br>'.$newline;
|
|
|
|
}
|
|
|
|
echo "**********************************************************************************$newline";
|
|
|
|
echo "**********************************************************************************$newline$newline";
|
|
|
|
echo "YOU ARE USING AN OLD AND BUGGED VERSION OF PHP, PLEASE UPDATE TO PHP 7.3$newline";
|
|
|
|
echo "PHP 5/7.0 USERS WILL NOT RECEIVE PHP UPDATES AND BUGFIXES: https://www.php.net/eol.php$newline";
|
|
|
|
echo "PHP 5/7.0 USERS WILL NOT RECEIVE MADELINEPROTO UPDATES AND BUGFIXES$newline$newline";
|
|
|
|
echo "SUPPORTED VERSIONS: PHP 7.1, 7.2, 7.3+$newline";
|
|
|
|
echo "RECOMMENDED VERSION: PHP 7.3$newline$newline";
|
|
|
|
echo "**********************************************************************************$newline";
|
|
|
|
echo "**********************************************************************************$newline";
|
|
|
|
unset($newline);
|
|
|
|
}
|
2019-06-07 20:36:26 +02:00
|
|
|
|
|
|
|
// MTProxy update
|
2019-10-28 19:53:07 +01:00
|
|
|
$file = \debug_backtrace(0, 1)[0]['file'];
|
|
|
|
if (\file_exists($file)) {
|
|
|
|
$contents = \file_get_contents($file);
|
2019-06-07 20:36:26 +02:00
|
|
|
|
2019-10-28 19:53:07 +01:00
|
|
|
if (\strpos($contents, 'new \danog\MadelineProto\Server') && \in_array($contents, [\file_get_contents('https://github.com/danog/MadelineProtoPhar/raw/2270bd9a94d168a5e6731ffd7e61821ea244beff/mtproxyd'), \file_get_contents('https://github.com/danog/MadelineProtoPhar/raw/7cabb718ec3ccb79e3c8e3d34f5bccbe3f63b0fd/mtproxyd')]) && ($mtproxyd = \file_get_contents('https://phar.madelineproto.xyz/mtproxyd?v=new'))) {
|
|
|
|
\file_put_contents($file, $mtproxyd);
|
2019-06-07 20:36:26 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 14:42:08 +02:00
|
|
|
// Template strings for madelineProto update URLs
|
2019-06-07 20:36:26 +02:00
|
|
|
$release_template = 'https://phar.madelineproto.xyz/release%s?v=new';
|
|
|
|
$phar_template = 'https://phar.madelineproto.xyz/madeline%s.phar?v=new';
|
|
|
|
|
2019-06-17 12:56:28 +02:00
|
|
|
// Version definition
|
2019-10-28 19:53:07 +01:00
|
|
|
$custom_branch = \defined('MADELINE_BRANCH') ? MADELINE_BRANCH : null;
|
2019-06-18 19:39:44 +02:00
|
|
|
if ($custom_branch === '') { // If the constant is an empty string, default to the latest alpha build
|
|
|
|
$custom_branch = 'master';
|
2019-10-28 19:53:07 +01:00
|
|
|
} elseif ($custom_branch === null) { // If the constant is not defined, default to the latest stable build
|
2019-06-18 19:39:44 +02:00
|
|
|
$custom_branch = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$release_branch = "-$custom_branch";
|
2019-06-17 12:56:28 +02:00
|
|
|
if ($release_branch === '-') {
|
|
|
|
$release_branch = '';
|
|
|
|
}
|
2019-06-18 14:42:08 +02:00
|
|
|
$release_fallback_branch = '';
|
2019-06-07 20:36:26 +02:00
|
|
|
|
2019-06-17 12:56:28 +02:00
|
|
|
if (PHP_MAJOR_VERSION <= 5) {
|
2019-06-07 20:36:26 +02:00
|
|
|
$release_branch = '5'.$release_branch;
|
2019-06-18 14:42:08 +02:00
|
|
|
$release_fallback_branch = '5'.$release_fallback_branch;
|
2019-12-25 21:14:57 +01:00
|
|
|
} elseif (PHP_MAJOR_VERSION === 7 && PHP_MINOR_VERSION < 4) {
|
2019-06-18 18:53:39 +02:00
|
|
|
$release_branch = '70'.$release_branch;
|
|
|
|
$release_fallback_branch = '70'.$release_fallback_branch;
|
2019-06-07 20:36:26 +02:00
|
|
|
}
|
|
|
|
|
2019-06-17 12:56:28 +02:00
|
|
|
// Checking if defined branch/default branch builds can be downloaded
|
2019-10-28 19:53:07 +01:00
|
|
|
if (!($release = @\file_get_contents(\sprintf($release_template, $release_branch)))) {
|
|
|
|
if (!($release = @\file_get_contents(\sprintf($release_template, $release_fallback_branch)))) {
|
2019-06-07 20:36:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-06-18 14:42:08 +02:00
|
|
|
$release_branch = $release_fallback_branch;
|
2019-06-07 20:36:26 +02:00
|
|
|
}
|
|
|
|
|
2019-10-28 19:53:07 +01:00
|
|
|
if (!\file_exists('madeline.phar') || !\file_exists('madeline.phar.version') || \file_get_contents('madeline.phar.version') !== $release) {
|
|
|
|
$phar = \file_get_contents(\sprintf($phar_template, $release_branch));
|
2019-06-07 20:36:26 +02:00
|
|
|
|
|
|
|
if ($phar) {
|
2019-10-28 19:53:07 +01:00
|
|
|
\file_put_contents('madeline.phar', $phar);
|
|
|
|
\file_put_contents('madeline.phar.version', $release);
|
2020-01-18 18:44:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
$composer = \json_decode(\file_get_contents('phar://madeline.phar/vendor/composer/installed.json'), true);
|
|
|
|
$postData = ['downloads' => []];
|
|
|
|
foreach ($composer as $dep) {
|
|
|
|
$postData['downloads'][] = [
|
|
|
|
'name' => $dep['name'],
|
|
|
|
'version' => $dep['version_normalized']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$opts = ['http' =>
|
|
|
|
[
|
|
|
|
'method' => 'POST',
|
|
|
|
'header' => ['Content-Type: application/json'],
|
|
|
|
'content' => \json_encode($postData),
|
|
|
|
'timeout' => 6,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
@\file_get_contents("https://packagist.org/downloads/", false, \stream_context_create($opts));
|
2019-06-07 20:36:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
___install_madeline();
|
|
|
|
|
2019-12-26 19:20:45 +01:00
|
|
|
return require_once 'madeline.phar';
|