-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
70 lines (64 loc) · 1.82 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
function rip($msg)
{
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
echo $msg;
die;
}
$gz = false;
$de = false;
/*
if (preg_match("|googlebot|telegrambot|i", $_SERVER["HTTP_USER_AGENT"])) {
$de = true;
} else
*/
if (preg_match("|deflate|i", $_SERVER["HTTP_ACCEPT_ENCODING"])) {
$de = true;
} elseif (preg_match("|deflate|i", $_SERVER["HTTP_ACCEPT_ENCODING"])) {
$gz = true;
}
if(!empty($_GET["file_id"])) {
$fileid = $_GET["file_id"];
} else {
http_response_code(500);
rip("<html><body><h1>NO FILE ID</h1></body></html>");
}
if (file_exists("token.php")) {
require "token.php";
} elseif (!empty($_GET["api"])) {
$api = $_GET["api"];
} else {
http_response_code(500);
rip("<html><body><h1>NO BOT TOKEN</h1></body></html>");
}
$rr = file_get_contents("https://api.telegram.org/$api/getfile?file_id=$fileid");
$ar = json_decode($rr, true);
unset($rr);
if (!$ar["ok"]) {
http_response_code(502);
rip("<html><body><h1>BOTAPI ERROR</h1><br><p>".$ar["description"]."</p></body></html>");
}
$filepath = $ar["result"]["file_path"];
unset($ar);
if (!preg_match("#photos#i", $filepath)) {
http_response_code(405);
rip("<html><body><h1>NOT ALLOWED</h1><br><p>ONLY IMAGES FILE</p></body></html>");
}
$url = "http://api.telegram.org/file/$api/$filepath";
$imgstring = file_get_contents($url);
$imginfo = getimagesizefromstring($imgstring);
header("Content-type: {$imginfo['mime']}");
header("Cache-Control: max-age=31536000");
if ($de) {
error_log("DEFLATE");
header("Content-Encoding: deflate");
echo gzdeflate($imgstring);
} elseif ($gz) {
error_log("GZIP");
header("Content-Encoding: gzip");
echo gzencode($imgstring);
} else {
echo $imgstring;
}