forked from rohammer/Simple-Babelweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
311 lines (293 loc) · 8.16 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Simple Babelweb</title>
<style>
table {
font-family: monospace, sans-serif;
border-collapse: collapse;
}
td, th {
border: 1px solid #fddddd;
text-align: left;
padding: 1px;
padding-right: 10px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<?php
error_reporting(0);
$file="/tmp/babeldump";
if (filemtime($file) < time()-10) {
shell_exec('echo "dump" | nc ::1 33123 -q 1 > '.$file.'');
}
$file_handle = fopen($file, 'r');
$set=0;
$i=0;
while (1) {
$line = fgets($file_handle);
if ($i <= 5) {
$data[] = $line;
$i++;
}
if (preg_match("/interface\b/", $line)) { $interface[] = $line; }
if (preg_match("/neighbour\b/", $line)) { $neighbour[] = $line; }
if (preg_match("/xroute\b/", $line)) { $xroute[] = $line; }
#if (preg_match("/\broute\b/", $read)){ break 1; }
if (preg_match("/\broute\b/", $line)){ $route[] = $line; }
if (preg_match("/ok/", $line)){ $set++; }
if ($set == 2) { break; }
}
fclose($file_handle);
$output['data'] = array(
'name' => $data[0],
'version' => $data[1],
'host' => $data[2],
'id' => $data[3],
);
foreach ($interface as $temp) {
$tempdata = explode(" ", $temp);
$output['interfaces'][] = array(
'interface' => $tempdata[2],
'up' => $tempdata[4],
'ipv6' => $tempdata[6],
'ipv4' => $tempdata[8],
);
}
foreach ($neighbour as $temp) {
$address=explode(" ",strstr($temp,"address"));
$interface=explode(" ",strstr($temp,"if"));
$reach=explode(" ",strstr($temp,"reach"));
$rxcost=explode(" ",strstr($temp,"rxcost"));
$txcost=explode(" ",strstr($temp,"txcost"));
$rtt=explode(" ",strstr($temp,"rtt"));
$rttcost=explode(" ",strstr($temp,"rttcost"));
$cost=explode(" ",strstr($temp,"cost"));
$output['neighbours'][] = array(
'address' => $address[1],
'interface' => $interface[1],
'reach' => $reach[1],
'rxcost' => $rxcost[1],
'txcost' => $txcost[1],
'rtt' => $rtt[1],
'rttcost' => $rttcost[1],
'cost' => $cost[1],
);
}
foreach ($xroute as $temp) {
$tempdata = explode(" ", $temp);
$output['xroutes'][] = array(
'prefix' => $tempdata[4],
'metric' => $tempdata[8],
);
}
foreach ($route as $temp) {
$tempdata = explode(" ", $temp);
$output['routes'][] = array(
'target' => $tempdata[4],
'installed' => $tempdata[8],
'via' => $tempdata[16],
'interface' => $tempdata[18],
'metric' => $tempdata[12],
'destid' => $tempdata[10],
);
}
if($_REQUEST['format'] == 'json') {
echo json_encode($output); }
else {
# Ausgabe
echo "<h1>Simple Babelweb</h1>";
?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<button type="submit" name="" value="">home</button>
<button type="submit" name="routes" value="1">show all babel routes</button>
<button type="submit" name="v4table" value="1">show import/export table ipv4</button>
<button type="submit" name="v6table" value="1">show import/export table ipv6</button>
<button type="submit" name="lg" value="1">Looking glass</button>
</form>
<H2>Babel information</H2><?php
echo "<table>";
echo '<tr><td><a href="https://github.com/rohammer/Simple-Babelweb">Quellcode Simple Babelweb</a></td></tr>';
foreach($output['data'] as $temp) { echo "<tr><td>$temp</td></tr>"; }
echo "</table>";
if($_GET['ip'] != '') {
$ipaddr = $_GET['ip'];
if ( preg_match("#/#", $ipaddr) == 0) {
if ( preg_match("#:#", $ipaddr) == 0) {
$ipaddr = $ipaddr . "/32";
} else {
$ipaddr = $ipaddr . "/128";
}
}
echo '<H2>Wege zu '.$ipaddr.'</H2>';
echo '<table>
<tr>
<th>target</th>
<th>installed</th>
<th>via</th>
<th>device</th>
<th>metric</th>
<th>Destination ID</th>
</tr>';
foreach($output['routes'] as $route) {
if ($route['target'] == $ipaddr) {
echo "<tr>";
foreach($route as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
}
echo "</table>";
}
if (empty($_GET)) {
echo "<H2>Interfaces</H2>";
echo '<table>
<tr>
<th>Interface</th>
<th>up</th>
<th>ipv6</th>
<th>ipv4</th>
</tr>';
foreach($output['interfaces'] as $interface) {
echo "<tr>";
foreach($interface as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
echo "</table>";
echo "<H2>Neighbours</H2>";
echo '<table>
<tr>
<th>address</th>
<th>interface</th>
<th>reach</th>
<th>rxcost</th>
<th>txcost</th>
<th>rtt</th>
<th>rttcost</th>
<th>cost</th>
</tr>';
foreach($output['neighbours'] as $neighbour) {
echo "<tr>";
foreach($neighbour as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
echo "</table>";
echo "<H2>Redistributed routes</H2>";
echo '<table>
<tr>
<th>prefix</th>
<th>metric</th>
</tr>';
foreach($output['xroutes'] as $xroute) {
echo "<tr>";
foreach($xroute as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
echo "</table>";
}
if($_GET['routes'] == '1') {
echo "<H2>routes</H2>";
echo '<table>
<tr>
<th>target</th>
<th>installed</th>
<th>via</th>
<th>device</th>
<th>metric</th>
<th>Destination ID</th>
</tr>';
foreach($output['routes'] as $route) {
$set=0;
echo "<tr>";
foreach($route as $temp) {
if ($set == 0) {
echo '<td><a href="'.$_SERVER["PHP_SELF"].'?ip='.$temp.'">'.$temp.'</a></td>';
$set=1;
}
else {
echo "<td>$temp</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
if($_GET['v4table'] == '1') {
echo "<H2>ipv4 routing table</H2>";
echo '<table>';
$v4routen = shell_exec('ip r s t $(grep import-table /etc/babeld.conf | cut -f2 -d" ")');
$v4route = explode(PHP_EOL, $v4routen);
for($i = 0; $i < count($v4route); ++$i) {
echo "<tr>";
$line = explode(" ", $v4route[$i]);
for($n = 0; $n < 5; ++$n) {
if ($n == 0) {
echo '<td><a href="'.$_SERVER["PHP_SELF"].'?ip='.$line[$n].'">'.$line[$n].'</a></td>';
}
else {
echo '<td>'.$line[$n].'</td>';
}
}
echo "</tr>";
}
echo "</table>";
}
if($_GET['v6table'] == '1') {
echo "<H2>ipv6 routing table</H2>";
echo '<table>
<tr>
<th>Destination</th>
<th>Source Specific</th>
<th>via</th>
<th>Device</th>
<th>proto</th>
<th>Kernelmetric</th>
</tr>';
$v6routen = shell_exec('ip -6 r s t $(grep import-table /etc/babeld.conf | cut -f2 -d" ")');
$v6route = explode(PHP_EOL, $v6routen);
for($i = 0; $i < count($v6route); ++$i) {
echo "<tr>";
$destination=explode(" ", $v6route[$i]);
$source=explode(" ", strstr($v6route[$i],"from"));
$via=explode(" ", strstr($v6route[$i],"via"));
$device=explode(" ", strstr($v6route[$i],"dev"));
$proto=explode(" ", strstr($v6route[$i],"proto"));
$metric=explode(" ", strstr($v6route[$i],"metric"));
echo '<td><a href="'.$_SERVER["PHP_SELF"].'?ip='.$destination[0].'">'.$destination[0].'</a></td>';
echo '<td>'.$source[1].'</td>';
echo '<td>'.$via[1].'</td>';
echo '<td>'.$device[1].'</td>';
echo '<td>'.$proto[1].'</td>';
echo '<td>'.$metric[1].'</td>';
echo "</tr>";
}
echo "</table>";
}
if($_GET['lg'] == '1') {
?>
<form action="index.php?lg=1" method="post">
IP Adresse (v4 und v6): <input type="text" size="17" name="IP">
<input type="submit" value="OK">
</form>
<?php
$ip =$_POST['IP'];
if (filter_var($ip, FILTER_VALIDATE_IP)) {
echo "Pinge $ip: <br /><pre>";
echo shell_exec('ping '.$ip.' -c 3 -W2');
echo "</pre>Traceroute $ip <br /><pre>";
echo shell_exec('traceroute -w2 '.$ip.'');
echo "</pre>Aktuelle Route:<pre>";
echo shell_exec('ip route get '.$ip.'');
echo "</pre>";
} else {
echo("This is not a valid IP address");
}
}
}
?>
<br>
</body>
</html>