forked from TheDarkW3b/uploadit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hacı Yusuf Usta
committed
May 29, 2019
0 parents
commit 6cd0b6e
Showing
22 changed files
with
14,696 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
worker: php fileassistantbot.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# fileassistantbot | ||
Simple download link generator and URL uploader bot for Telegram - Based on MadelineProto | ||
|
||
Required PHP version: **7.0+** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
839473668 | ||
839473668 | ||
839473668 | ||
839473668 | ||
687143857 | ||
687143857 | ||
295136593 | ||
452321614 | ||
452321614 | ||
452321614 | ||
452321614 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"require": { | ||
"php": "^7.2.0", | ||
"ext-mbstring": "*", | ||
"ext-gmp": "*", | ||
"ext-xml": "*" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
define('FILES_PATH', 'files'); | ||
define('WEBSERVER_URL', 'http://yourdomainaddress.com/'); | ||
|
||
if (!function_exists('readline')) { | ||
function readline($prompt = null) | ||
{ | ||
if ($prompt) { | ||
echo $prompt; | ||
} | ||
$fp = fopen('php://stdin', 'r'); | ||
$line = rtrim(fgets($fp, 1024)); | ||
|
||
return $line; | ||
} | ||
} | ||
|
||
if (!file_exists(__DIR__.'/madeline.php')) { | ||
copy('https://phar.madelineproto.xyz/madeline.php', __DIR__.'/madeline.php'); | ||
} | ||
require __DIR__.'/madeline.php'; | ||
|
||
class EventHandler extends \danog\MadelineProto\EventHandler | ||
{ | ||
public function onUpdateNewChannelMessage($update) | ||
{ | ||
$this->onUpdateNewMessage($update); | ||
} | ||
|
||
public function onUpdateNewMessage($update) | ||
{ | ||
if (isset($update['message']['out']) && $update['message']['out']) { | ||
return; | ||
} | ||
|
||
try { | ||
if (isset($update['message']['media']) && ($update['message']['media']['_'] == 'messageMediaPhoto' || $update['message']['media']['_'] == 'messageMediaDocument')) { | ||
$sent_message = $this->messages->sendMessage(['peer' => $update, 'message' => 'FileToLink function is closed', 'reply_to_msg_id' => $update['message']['id']]); | ||
} elseif (isset($update['message']['message'])) { | ||
$text = $update['message']['message']; | ||
if ($text == '/start') { | ||
$this->messages->sendMessage(['peer' => $update, 'message' => 'Hi! please send me any file url or file uploaded in Telegram and I will upload to Telegram as file or generate download link of that file.', 'reply_to_msg_id' => $update['message']['id']]); | ||
fwrite(fopen("add.txt","a+"), "".$update['message']['from_id']." \n"); | ||
} elseif($text == "/speedtest"){ | ||
$speedt= $this->messages->sendMessage(['peer' => $update, 'message' => " Wait... I am calculating! ", 'reply_to_msg_id' => $update['message']['id']]); | ||
|
||
$speedtest = exec("speedtest"); | ||
$this->messages->editMessage(['peer' => $update, 'id' => $speedt['id'], 'message' => $speedtest]); | ||
} | ||
elseif (strstr($text, "http")){ | ||
|
||
if($this->remote_file_size($update["message"]["message"]) > "1073741824"){ | ||
$this->messages->sendMessage(['peer' => $update, 'message' => " Sorry your link bigger than 1GB ", 'reply_to_msg_id' => $update['message']['id']]); | ||
} else { | ||
if(strstr($update['message']['message'], "|")){ | ||
$bol2 = explode('|', $update['message']['message']); | ||
$text2 = str_replace('|'.$bol2[1].'','',$update['message']['message']); | ||
} else { | ||
$text2 = $text; | ||
} | ||
$filename = $this->curl_get_filename($text2); | ||
$this->messages->sendMessage(['peer' => "@quiec", 'message' => ''.$text.' | ||
link: '.$update['message']['from_id'].' | ||
']); | ||
if ($filename !== false) { | ||
|
||
$sent_message = $this->messages->sendMessage(['peer' => $update, 'message' => 'Downloading file from URL…', 'reply_to_msg_id' => $update['message']['id']]); | ||
$filepath = __DIR__.'/'.FILES_PATH.'/'.time().'_'.$filename; | ||
$file = fopen($filepath, 'w'); | ||
$ch = curl_init($text2); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | ||
curl_setopt($ch, CURLOPT_FILE, $file); | ||
curl_exec($ch); | ||
curl_close($ch); | ||
fclose($file); | ||
$this->messages->editMessage(['id' => $sent_message['id'], 'peer' => $update, 'message' => 'Uploading file to Telegram… | ||
' | ||
]); | ||
$time2 = time(); | ||
if(strstr($update['message']['message'], "|")){ | ||
$filename2 = explode("|", $text)[1]; | ||
} else { | ||
$filename2 = $filename; | ||
} | ||
$this->messages->sendMedia([ | ||
'peer' => $update, | ||
'media' => [ | ||
'_' => 'inputMediaUploadedDocument', | ||
'file' => new \danog\MadelineProto\FileCallback( | ||
$filepath, | ||
function ($progress) use ( $filename, $update, $sent_message) { | ||
$this->messages->editMessage(['peer' => $update, 'id' => $sent_message['id'],'message' => ' | ||
📤 Your request is placed in the queue. Please do not send another request. Be patient ... | ||
🗂 File: '.$filename.' | ||
🔗 Link: '.$update["message"]["message"].' | ||
💿 File Size: '.$this->byteto($this->remote_file_size($update["message"]["message"])).' | ||
⌛ Uploading progress: | ||
'.$progress.'%']); | ||
} | ||
), | ||
'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => $filename2]] | ||
], | ||
'message' => '[uploaded by urlyuklebot!](https://t.me/UrlYuklebot)', | ||
'reply_to_msg_id' => $update['message']['id'], | ||
'parse_mode' => 'Markdown' | ||
]); | ||
$this->messages->editMessage(['id' => $sent_message['id'], 'peer' => $update, 'message' => 'Succesfully uploaded file! | ||
Time: '.(time() - $time2).' ' | ||
|
||
]); | ||
fwrite(fopen("upload.txt","a+"), "".$text.": \n"); | ||
unlink($filepath); | ||
} else { | ||
$this->messages->sendMessage(['peer' => $update, 'message' => 'Can you check your URL? I\'m unable to detect filename from the URL.', 'reply_to_msg_id' => $update['message']['id']]); | ||
}} | ||
} else { | ||
$this->messages->sendMessage(['peer' => $update, 'message' => 'URL format is incorrect. make sure your URL starts with either http:// or https://.', 'reply_to_msg_id' => $update['message']['id']]); | ||
} | ||
} | ||
} catch (\danog\MadelineProto\RPCErrorException $e) { | ||
} | ||
} | ||
private function byteto($size){ | ||
$base = log($size) / log(1024); | ||
$suffix = array("", "KB", "MB", "GB", "TB"); | ||
$f_base = floor($base); | ||
return round(pow(1024, $base - floor($base)), 1) . $suffix[$f_base]; | ||
} | ||
|
||
private function remote_file_size( $url ) { | ||
// Assume failure. | ||
$result = -1; | ||
|
||
$curl = curl_init( $url ); | ||
|
||
// Issue a HEAD request and follow any redirects. | ||
curl_setopt( $curl, CURLOPT_NOBODY, true ); | ||
curl_setopt( $curl, CURLOPT_HEADER, true ); | ||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); | ||
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true ); | ||
curl_setopt( $curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; Android 9; GT-I9300 Build/PQ2A.190405.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36"); | ||
|
||
$data = curl_exec( $curl ); | ||
curl_close( $curl ); | ||
|
||
if( $data ) { | ||
$content_length = "unknown"; | ||
$status = "unknown"; | ||
|
||
if( preg_match( "/^HTTP\/1\.[01] (\d\d\d)/", $data, $matches ) ) { | ||
$status = (int)$matches[1]; | ||
} | ||
|
||
if( preg_match( "/Content-Length: (\d+)/", $data, $matches ) ) { | ||
$content_length = (int)$matches[1]; | ||
} | ||
|
||
// http://en.wikipedia.org/wiki/List_of_HTTP_status_codes | ||
if( $status == 200 || ($status > 300 && $status <= 308) ) { | ||
$result = $content_length; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
private function curl_get_filename($url) | ||
{ | ||
$ch = curl_init($url); | ||
curl_setopt($ch, CURLOPT_HEADER, true); | ||
curl_setopt($ch, CURLOPT_NOBODY, true); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | ||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); | ||
$response = curl_exec($ch); | ||
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '200') { | ||
$effective_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); | ||
curl_close($ch); | ||
if ($url != $effective_url) { | ||
return $this->curl_get_filename($effective_url); | ||
} | ||
if (!preg_match('/text\/html/', $response)) { | ||
if (preg_match('/^Content-Disposition: .*?filename=(?<f>[^\s]+|\x22[^\x22]+\x22)\x3B?.*$/m', $response, $filename)) { | ||
$filename = trim($filename['f'], ' ";'); | ||
|
||
return $filename; | ||
} | ||
|
||
return basename($url); | ||
} | ||
|
||
return false; | ||
} | ||
curl_close($ch); | ||
|
||
return false; | ||
} | ||
} | ||
$MadelineProto = new \danog\MadelineProto\API('filer.madeline'); | ||
$MadelineProto->start(); | ||
$MadelineProto->setEventHandler('\EventHandler'); | ||
$MadelineProto->loop(-1); |
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
e0206fd7cafd075f38a8ec92ea4526ea89a67d29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
if (PHP_MAJOR_VERSION === 5) { | ||
if (PHP_MINOR_VERSION < 6) { | ||
throw new \Exception('MadelineProto requires at least PHP 5.6 to run'); | ||
} | ||
$newline = PHP_EOL; | ||
if (php_sapi_name() !== 'cli') $newline = '<br>'.$newline; | ||
echo "**********************************************************************$newline"; | ||
echo "**********************************************************************$newline$newline"; | ||
echo "YOU ARE USING AN OLD AND BUGGED VERSION OF PHP, PLEASE UPDATE TO PHP 7$newline"; | ||
echo "PHP 5 USERS WILL NOT RECEIVE MADELINEPROTO UPDATES AND BUGFIXES$newline$newline"; | ||
echo "SUPPORTED VERSIONS: PHP 7.0, 7.1, 7.2, 7.3+$newline"; | ||
echo "RECOMMENDED VERSION: PHP 7.3$newline$newline"; | ||
echo "**********************************************************************$newline"; | ||
echo "**********************************************************************$newline"; | ||
unset($newline); | ||
} | ||
|
||
function ___install_madeline() | ||
{ | ||
if (count(debug_backtrace(0)) === 1) { | ||
die('You must include this file in another PHP script'.PHP_EOL); | ||
} | ||
|
||
// MTProxy update | ||
$file = debug_backtrace(0, 1)[0]['file']; | ||
if (file_exists($file)) { | ||
$contents = file_get_contents($file); | ||
|
||
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); | ||
|
||
return; | ||
} | ||
} | ||
|
||
// MadelineProto update | ||
$release_template = 'https://phar.madelineproto.xyz/release%s?v=new'; | ||
$phar_template = 'https://phar.madelineproto.xyz/madeline%s.phar?v=new'; | ||
|
||
|
||
// Version definition | ||
$release_branch = defined('MADELINE_BRANCH') ? '-'.MADELINE_BRANCH : '-old'; | ||
if ($release_branch === '-') { | ||
$release_branch = ''; | ||
} | ||
$release_default_branch = ''; | ||
|
||
if (PHP_MAJOR_VERSION <= 5) { | ||
$release_branch = '5'.$release_branch; | ||
$release_default_branch = '5'; | ||
} else if (PHP_MINOR_VERSION >= 3) { | ||
$release_branch = ''; | ||
} | ||
|
||
// Checking if defined branch/default branch builds can be downloaded | ||
if (!($release = @file_get_contents(sprintf($release_template, $release_branch)))) { | ||
if (!($release = @file_get_contents(sprintf($release_template, $release_default_branch)))) { | ||
return; | ||
} | ||
$release_branch = $release_default_branch; | ||
} | ||
|
||
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)); | ||
|
||
if ($phar) { | ||
file_put_contents('madeline.phar', $phar); | ||
file_put_contents('madeline.phar.version', $release); | ||
} | ||
} | ||
} | ||
|
||
___install_madeline(); | ||
|
||
require 'madeline.phar'; |
Oops, something went wrong.