-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
349 lines (315 loc) · 10.3 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
/*
* show me your ip!
*/
ini_set('display_errors','on');
include "db.class.php";
//print_r($_SERVER);
//die();
if ($_SERVER['REQUEST_URI'] != "/")
{
//echo $_SERVER['REQUEST_URI'];
switch ($_SERVER['REQUEST_URI'])
{
case "/ip":
header("Content-Type: text/plain");
echo showIP();
break;
case "/fqdn":
header("Content-Type: text/plain");
echo showFQDN();
break;
case "/ping":
header("Content-Type: text/plain");
$out = array();
$pat = '/Win/';
if (preg_match($pat,$_SERVER['SERVER_SIGNATURE']))
{
exec('ping -n 4 '.$_SERVER['REMOTE_ADDR'], $out);
}
else {
exec('ping -c 4 '.$_SERVER['REMOTE_ADDR'], $out);
}
print_r($out);
break;
case "/dl":
header("Content-Type: text/plain");
echo "Under Construction.";
break;
case "/ul":
header("Content-Type: text/plain");
echo "Under Construction.";
break;
case "/server":
header("Content-Type: text/plain");
echo json_encode($_SERVER);
break;
case "/os":
header("Content-Type: text/plain");
echo getOS();
break;
case "/browser":
header("Content-Type: text/plain");
echo getBrowser();
break;
case "/help":
header("Content-Type: text/html");
echo getHelp();
break;
default:
//echo $_SERVER['REQUEST_URI'] . "<BR>\n";
$s = explode("/",$_SERVER['REQUEST_URI']);
//print_r($s);
//echo "<BR>\n";
if (sizeOf($s) == 3)
{
switch (strtolower($s[2]))
{
case "asn":
case "asn1":
case "xml":
header("Content-Type: application/xml");
//$xml = new SimpleXMLElement('<root/>');
$data = processData();
//echo "XML: " . $data . "<BR>\n";
//array_walk_recursive($data, array ($xml, 'addChild'));
//print_r($data);
//die();
if ($s[1]=="server")
{
echo '<?xml version="1.0"?><root>';
$xml = "";
foreach ($data[0] as $i=>$d)
{
$xml .= "<" . $i . ">".$d."</".$i.">";
}
//array_walk_recursive($data, array ($xml, 'addChild'));
echo $xml . "</root>";
//print_r($xml);
}
else {
# code...
$xml = new SimpleXMLElement('<root/>');
$data = processData();
//echo "XML: " . $data . "<BR>\n";
array_walk_recursive($data, array ($xml, 'addChild'));
echo $xml->asXML();
}
break;
case "xml-rpc":
break;
case "json":
header("Content-Type:text/plain");
echo json_encode(processData());
break;
case "jsonp":
break;
case "bson":
$bson = MongoDB\BSON\fromPHP(processData());
echo bin2hex($bson), "\n";
break;
case "csv":
header("Content-Type: text/plain");
outputCSV(processData());
break;
case "javaarray":
break;
case "yaml":
echo "Under development.";
break;
default:
echo "DEFAULT";
break;
}
}
break;
}
$db = new MyDB() or die ("SQL CLASS ERROR");
$type= str_replace("/",":",$_SERVER['REQUEST_URI']);
$db->run("insert into ip (type,address,aDate,aTime) values ('$type','" . showIP2() . "','".date("Y-m-d")."','".date("H:i:s")."');");
}
else {
# code...
echo showIP();
}
function outputCSV($data) {
//$outputBuffer = fopen("php://output", 'w');
if (sizeOf($data) == 1 && isset($data[0]['REQUEST_URI'])){$data = $data[0];}
//foreach($data as $val) {
// fputcsv($outputBuffer, array($val));
//}
//fclose($outputBuffer);
foreach ($data as $i=>$d)
{
echo $i . ",'" . addslashes($d) . "'\n";
}
}
function processData()
{
$id = explode("/",$_SERVER['REQUEST_URI']);
//echo $id[1];
switch ($id[1])
{
case "ip":
if ($id[2]=="xml"){return array(showIP()=>"data");}else{return array("data"=>showIP());}
break;
case "fqdn":
if ($id[2] == "xml"){
return array(showFQDN()=>"data");
}
else{
return array("data"=>showFQDN());
}
break;
case "ping":
$out = array();
$pat = '/Win/';
if (preg_match($pat,$_SERVER['SERVER_SIGNATURE']))
{
exec('ping -n 4 '.$_SERVER['REMOTE_ADDR'], $out);
}
else {
exec('ping -c 4 '.$_SERVER['REMOTE_ADDR'], $out);
}
return ($out);
break;
case "dl":
if ($id[2] == "xml"){ return array("Under Construction."=>"data");}else{return array("Under Contruction");}
break;
case "ul":
if ($id[2] == "xml"){return array("Under Construction."=>"data");}else{return array("Under Construction");}
break;
case "server":
ini_set('display_errors','off');
return array($_SERVER);
break;
case "os":
if ($id[2] == "xml"){return array(getOS()=>"data");}else{return array(getOS());}
break;
case "browser":
return array(getBrowser());
break;
case "help":
return array(getHelp());
break;
}
}
function getHelp(){
echo "<!DOCTYPE html>
<head>
<title>Help</title>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' integrity='sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u' crossorigin='anonymous'>
<!-- Optional theme -->
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css' integrity='sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp' crossorigin='anonymous'>
<!-- Latest compiled and minified jQuery -->
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script>
<!-- Latest compiled and minified JavaScript -->
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' integrity='sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa' crossorigin='anonymous'></script>";
echo "<div class='col-md-4'></div>";
echo "<div class='col-md-4'>";
echo "<div class='well'>";
echo "<h2>Help</h2>";
echo "<p>/ip - list your ip address<BR>";
echo "/fqdn - list your FQDN<BR>";
echo "/ping - ping your IP<BR>";
echo "/dl - download speed<BR>";
echo "/ul - upload speed<BR>";
echo "/server - server info<BR>";
echo "/os - show operating system<BR>";
echo "/browser - browser system<BR></p>";
echo "<hr><p>Simply add the data format as the second parameter (eg:/server/json) and it will represent the data as you want it.<br>The available formats are: CSV, JSON, XML, YAML, and Array.</p>";
echo "</div>";
echo "</div>";
}
function getOS() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$os_platform = "Unknown OS Platform";
$os_array = array(
'/windows nt 10/i' => 'Windows 10',
'/windows nt 6.3/i' => 'Windows 8.1',
'/windows nt 6.2/i' => 'Windows 8',
'/windows nt 6.1/i' => 'Windows 7',
'/windows nt 6.0/i' => 'Windows Vista',
'/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
'/windows nt 5.1/i' => 'Windows XP',
'/windows xp/i' => 'Windows XP',
'/windows nt 5.0/i' => 'Windows 2000',
'/windows me/i' => 'Windows ME',
'/win98/i' => 'Windows 98',
'/win95/i' => 'Windows 95',
'/win16/i' => 'Windows 3.11',
'/macintosh|mac os x/i' => 'Mac OS X',
'/mac_powerpc/i' => 'Mac OS 9',
'/linux/i' => 'Linux',
'/ubuntu/i' => 'Ubuntu',
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
foreach ($os_array as $regex => $value) {
if (preg_match($regex, $user_agent)) {
$os_platform = $value;
}
}
return $os_platform;
}
function getBrowser() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$browser = "Unknown Browser";
$browser_array = array(
'/msie/i' => 'Internet Explorer',
'/firefox/i' => 'Firefox',
'/safari/i' => 'Safari',
'/chrome/i' => 'Chrome',
'/edge/i' => 'Edge',
'/opera/i' => 'Opera',
'/netscape/i' => 'Netscape',
'/maxthon/i' => 'Maxthon',
'/konqueror/i' => 'Konqueror',
'/mobile/i' => 'Handheld Browser'
);
foreach ($browser_array as $regex => $value) {
if (preg_match($regex, $user_agent)) {
$browser = $value;
}
}
return $browser;
}
function showFQDN(){
return gethostbyaddr(showIP());
}
function showIP()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
$f = fopen("ips.txt","a") or die("Unable to open appended file!");
fwrite($f, date("Y-m-d,H:i:s") . "," . $ip . "\n") or die("Cannot write to file");
fclose($f) or die("Cannot close the file");
$db = new MyDB() or die ("SQL CLASS ERROR");
$db->run("insert into ip (type,address,aDate,aTime) values ('IP','" . $ip . "','".date("Y-m-d")."','".date("H:i:s")."');");
return $ip;
//print_r($_SERVER);
}
function showIP2()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
//print_r($_SERVER);
}
?>