forked from Incognify/php-lg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
138 lines (124 loc) · 5.42 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
// 08/27/2023 - Looking Glass script.
// Still work to do, but this works as it is now.
// Will refine later.
//
// Set the below variables:
$lg_location = "🇺🇸 Liberty Lake, WA"; // Where is this looking glass install located?
$lg_ipv4 = "23.184.48.25"; // IPv4 address of your looking glass server
$lg_ipv6 = "2602:fc24:18:a5d8::1"; // IPv6 address of your looking glass server
$logo = "logo.svg"; //Logo or image to display above your other locations
// (Probably won't have to mess with the PHP below, but the HTML further down wants your attention)
// Rate limiting stuff. You can also do this with nginx (see readme)
session_start();
// Set a time limit for session, for example 60 seconds
$rate_limit_time = 60;
// Maximum number of requests within the time limit
$max_requests = 5;
if (!isset($_SESSION['first_request'])) {
$_SESSION['first_request'] = time();
$_SESSION['request_count'] = 0;
}
if (time() - $_SESSION['first_request'] > $rate_limit_time) {
// Reset the counter if the time limit is exceeded
$_SESSION['first_request'] = time();
$_SESSION['request_count'] = 0;
}
if ($_SESSION['request_count'] > $max_requests) {
die('Rate limit exceeded. Please wait.');
}
$_SESSION['request_count']++;
// Get the IP / hostname of the website visitor
function getUserInfo() {
$ipAddress = $_SERVER['REMOTE_ADDR'];
$hostName = gethostbyaddr($ipAddress);
return [
'ip' => $ipAddress,
'hostname' => $hostName
];
}
$userInfo = getUserInfo();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="<?php echo ("$description");?>">
<meta name="keywords" content="<?php echo ("$keywords");?>">
<meta name="author" content="IncogNET">
<meta name="robots" content="index, follow">
<link rel="preload" as="style" href="style.css">
<link rel="stylesheet" href="style.css">
<title><?php echo($lg_location)?> - Looking Glass</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<body>
<nav id="mainNav">
<h1>Network Looking Glass</h1>
</nav>
<div class="forms-container">
<div class="left-form">
<form id="lookupForm">
<div id="userInfo">
<p>This is a <b>beta</b> PHP driven looking glass tool. From the Looking Glass location shown below, you may test network connectivity to any publicly accessible IPv4 or IPv6 address or hostname that you enter.</p>
<hr>
<b>Looking Glass Location:</b> <span><?php echo($lg_location)?></span><br>
<b>Looking Glass IPv4:</b> <span><?php echo($lg_ipv4)?></span><br>
<b>Looking Glass IPv6:</b> <span><?php echo($lg_ipv6)?></span><br>
<hr>
<b>Your IP Address:</b> <span><?= $userInfo['ip'] ?></span><br>
<b>Your Hostname:</b> <span><?= $userInfo['hostname'] ?></span>
<hr>
</div>
IPv4 / IPv6 Address or Hostname: <input type="text" name="ip" required>
Run Command:
<select name="command">
<option value="ping">Ping</option>
<option value="ping6">Ping6</option>
<option value="traceroute">Traceroute</option>
<option value="traceroute6">Traceroute6</option>
<option value="mtr">MTR</option>
<option value="mtr6">MTR6</option>
</select>
<input type="submit" value="Proceed">
</form>
</div>
<div class="center-results">
<div id="loadingMessage" style="display: none;"><h2>Running test, please wait...<br>(This may take a moment)</h2></div>
<div id="results"></div>
</div>
<div class="right-form">
<form id="lookupForm">
<div id="userInfo">
<center>
<img src="<?php echo($logo)?>" width="313" height="63"><br>
<h4>Want to test from one of our other locations?</h4>
<hr>
<span>🇺🇸 Liberty Lake, WA</span> | <span>🇺🇸 Kansas City, MO</span><br>
<span>🇺🇸 Allentown, PA</span> | <span>🇺🇸 Miami, FL</span><br>
<span>🇺🇸 Las Vegas, NV</span> | <span>🇺🇸 New York, NY</span><br>
<span>🇳🇱 Naaldwijk, NL</span> | <span>🇱🇺 Roost, Bissen, LU</span>
<hr>
<small>The above links are for demonstration purposes only.<br><br>© 2023 <a href="https://incognet.io">IncogNET LLC</a> | <a href="#">GitHub</a> | <a href="https://twitter.com/IncogNETLLC">Twitter</a> | <a href="https://bgp.tools/as/21030">BGP.TOOLS</a> | v0.2</small></center>
</div>
</form>
</div>
</div>
<script>
$('#lookupForm').submit(function(e) {
e.preventDefault();
// Show the loading message
$('#loadingMessage').show();
$.post('result.php', $(this).serialize(), function(data) {
$('#results').html(data);
// Hide the loading message
$('#loadingMessage').hide();
}).fail(function() {
$('#results').html('<pre><code>Error fetching the results. Please try again later.</code></pre>');
// Hide the loading message
$('#loadingMessage').hide();
});
});
</script>
</body>
</html>