This repository has been archived by the owner on Mar 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
executable file
·80 lines (71 loc) · 2.13 KB
/
lib.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
71
72
73
74
75
76
77
78
79
80
<?php
class TWTXTdb extends SQLite3 {
function __construct() {
$this->open("twtxt.sqlite3");
}
}
function is_curlwget() {
# is the page being curl'd, wget'd or shown thru a browser ?
if (stristr($_SERVER["HTTP_USER_AGENT"], 'curl') or (stristr($_SERVER["HTTP_USER_AGENT"], 'wget'))) {
# page is cURL'd
return True;
} else {
# page is being accessed from a web browser
return False;
}
}
function init_html() {
if (!is_curlwget()) {
?>
<html lang="en">
<head>
<title>TWTXT Registry</title>
</head>
<body>
<?php
}
}
function end_html() {
if (!is_curlwget()) {
?>
</body>
</html>
<?php
}
}
function nl() {
# function to define variable $nl (=new line), <br>\n for browsers, \n for cURL/CLI
if (is_curlwget()) {
# in case of curl/wget/cli
return "\n";
} else {
# in case of web browser
return "<br>\n";
}
}
function ascii_logo() {
$nl = nl();
# print ascii logo only for cURL/Wget
if (is_curlwget()) {
echo " _____ _ _ _______ _______ ______ _ _ $nl";
echo "|_ _| | | |_ _\ \ / /_ _| | ___ \ (_) | | $nl";
echo " | | | | | | | | \ V / | | | |_/ /___ __ _ _ ___| |_ _ __ _ _ $nl";
echo " | | | |/\| | | | / \ | | | // _ \/ _` | / __| __| '__| | | |$nl";
echo " | | \ /\ / | | / /^\ \ | | | |\ \ __/ (_| | \__ \ |_| | | |_| |$nl";
echo " \_/ \/ \/ \_/ \/ \/ \_/ \_| \_\___|\__, |_|___/\__|_| \__, |$nl";
echo " __/ | __/ |$nl";
echo " |___/ |___/ $nl";
echo "$nl";
}
}
function ban() {
$banned_ips = [
'255.255.255.255', # example IP
'0.0.0.0' # Another example IP, you won't encounter them as they are out of range (1->254)
];
if (in_array($_SERVER['REMOTE_ADDR'], $banned_ips)) {
# if client IP is a banned one, give him a 403 error
http_response_code(403);
die("Banned");
}
}