simple-babelweb/babel.html

324 lines
8.7 KiB
HTML
Executable File

#!/usr/bin/haserl
<%
echo -en "Content-Type: text/html\r\n\r\n"
HOSTNAME="<Hostname>"
FFFV4="<IPv4>"
FFFGLOBALUNICAST="<IPv6>"
FFFTABLE="fff"
#lockfile="/tmp/simple.babelweb.lock" ; better nginx proxy cache
#
#if [ -e $lockfile ];then
# if [ 5 -gt $(( $(date +%s) - $(date -r $lockfile +%s) )) ];then
# echo "only one access per minute!!" && exit
# fi
#fi
data=$(echo "dump" | nc ::1 33123)
#touch $lockfile
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><%= ${HOSTNAME} %></title>
<link href="/style.css" rel="stylesheet" type="text/css" media="screen" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />
<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>
<h1>Simple Babelweb</h1>
<br />
<form action="babel.html" 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>
<input type="text" size="17" name="ip">
<button type="submit" name="weg" value="1">Wege zur IP Adresse</button>
<button type="submit" name="lg" value="1">Looking Glass</button>
</form>
<br />
<H2>Babel information</H2>
<table>
<tr>
<td><a href="https://github.com/rohammer/Simple-Babelweb">Quellcode Simple Babelweb</a></td>
</tr>
<tr>
<td><% echo "$data" | head -n 1 %> </td>
</tr>
<tr>
<td><% echo "$data" | head -n 2 | tail -n 1 %> </td>
</tr>
<%
if [ -f /bin/opkg ]; then
%>
<tr>
<td>opkg-version <% opkg list-installed | grep babeld | cut -f 3 -d ' ' %> </td>
</tr>
<%
fi
%>
<tr>
<td><% echo "$data" | head -n 3 | tail -n 1 %> </td>
</tr>
<tr>
<td><% echo "$data" | head -n 4 | tail -n 1 %> </td>
</tr>
</table>
<br />
<%
if ! [ ${GET_routes} ] && ! [ ${GET_v4table} ] && ! [ ${GET_v6table} ] && ! [ ${GET_weg} ] && ! [ ${GET_lg} ] ; then
%>
<H2>Interfaces</H2>
<table>
<%
echo "<tr><th>interface</th><th>up</th><th>since</th><th>ipv6</th><th>ipv4</th>"
echo "</tr>"
echo "$data" | grep interface | while read line ; do
tmp=${line##* interface }
tmpint=${tmp%% *}
newline="<tr><td>$tmpint</td><td>"
tmp=${line##* up }
newline="$newline${tmp%% *}</td><td>"
tmp=""
if [ -f "/sys/class/net/$tmpint/operstate" ]; then
tmp=$(($(date +%s) - $(stat -c %Y /sys/class/net/$tmpint/operstate)))
tmp="$((tmp/3600/24))d $((tmp/3600%24)):$((tmp/60%60)):$((tmp%60))"
fi
newline="$newline$tmp</td><td>"
tmp=${line##* ipv6 }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* ipv4 }
echo "$newline${tmp%% *}</td></tr>"
done
%>
</table>
<br />
<H2>Neighbours</H2>
<table>
<%
echo "<tr><th>id</th><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>"
echo "$data" | grep neighbour | while read line ; do
tmp=${line##*add neighbour }
tmp=${tmp%% *}
newline="<tr><td>${tmp:0:2}:${tmp:2:2}:${tmp:4:2}:${tmp:6:2}:${tmp:8:2}:${tmp:10:2}</td><td>"
tmp=${line##* address }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* if }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* reach }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* rxcost }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* txcost }
newline="$newline${tmp%% *}</td><td>"
newline="$newline$(echo "$line" | sed -n '/^.*\srtt\s\+\([0-9.]\+\).*$/s//\1/p')</td><td>"
newline="$newline$(echo "$line" | sed -n '/^.*\srttcost\s\+\([0-9]\+\).*$/s//\1/p')</td><td>"
tmp=${line##* cost }
echo "$newline${tmp%% *}</td></tr>"
done
%>
</table>
<br />
<H2>Redistributed routes</H2>
<table>
<%
echo "<tr><th>prefix</th><th>metric</th></tr>"
echo "$data" | grep xroute | while read line ; do
tmp=${line##*add xroute }
tmp=${tmp%% *}
newline="<tr><td>${tmp%%-*}</td><td>"
tmp=${line##* metric }
echo "$newline${tmp%% *}</td></tr>"
done
%>
</table>
<br />
<%
fi
echo "<table>"
if [ ${GET_routes} ]; then
%>
<H2>All routes</H2>
<table>
<%
echo "<tr><th>target</th>><th>from</th><th>installed</th><th>via</th><th>device</th><th>metric</th><th>destination id</th></tr>"
echo "$data" | grep -w route | while read line ; do
tmp=${line##* prefix }
tmp=${tmp%% *}
newline="<tr><td><a href=babel.html?weg=1&ip=${tmp%%/*}>$tmp</a></td><td>"
tmp=${line##* from }
tmp=${tmp##*/0}
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* installed }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* via }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* if }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* metric }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* id }
tmp=${tmp%% *}
echo "$newline<a href=babel.html?weg=1&ip=$tmp>$tmp</a></td></tr>"
done
%>
</table>
<%
fi
if [ ${GET_v4table} ]; then
%>
<H2>Show IPv4 Routing Tabele</H2>
<table>
<%
echo "<tr><th>target</th><th>via</th><th>device</th><th>proto</th></tr>"
v4routen=$(ip ro sh tab 10)
echo "$v4routen" | while read line ; do
tmp=${line%% *}
newline="<tr><td><a href=babel.html?weg=1&ip=${tmp%%/*}>$tmp</a></td><td>"
tmp=${line##* via }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* dev }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* proto }
echo "$newline${tmp%% *}</td></tr>"
done
%>
</table>
<%
fi
if [ ${GET_v6table} ]; then
%>
<H2>Show IPv6 Routing Tabele</H2>
<table>
<%
echo "<tr><th>target</th><th>from</th><th>via</th><th>device</th><th>proto</th><th>metric</th></tr>"
v6routes=$(ip -6 ro sh tab 10)
echo "$v6routes" | while read line ; do
tmp=${line%% *}
newline="<tr><td><a href=babel.html?weg=1&ip=${tmp%%/*}>$tmp</a></td><td>"
tmp="$line"" from "
tmp=${tmp#* from }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* via }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* dev }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* proto }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* metric }
echo "$newline${tmp%% *}</td></tr>"
done
%>
</table>
<%
fi
if [ ${GET_weg} ]; then
%>
<H2>Wege zu <% echo "${GET_ip}" %></H2>
<table>
<tr><th>target</th><th>from</th><th>installed</th><th>via</th><th>device</th><th>metric</th><th>destination id</th></tr>
<%
echo "$data" | grep -w route | grep "${GET_ip}" | while read line ; do
tmp=${line##* prefix }
tmp=${tmp%% *}
newline="<tr><td><a href=babel.html?weg=1&ip=${tmp%%/*}>$tmp</a></td><td>"
tmp=${line##* from }
tmp=${tmp##*/0}
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* installed }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* via }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* if }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* metric }
newline="$newline${tmp%% *}</td><td>"
tmp=${line##* id }
tmp=${tmp%% *}
echo "$newline<a href=babel.html?weg=1&ip=$tmp>$tmp</a></td></tr>"
done
%>
</table>
<%
fi
if [ ${GET_lg} ]; then
%>
<H2>Looking Glass</H2>
<H5>IP or Hostname:</H5>
<form action="babel.html" method="get">
<input type="text" size="25" name="lgip" value="<% echo -n "${GET_lgip}" %>">
<button type="submit" name="lg" value="1">OK</button>
</form>
<%
IPv4=1
if [ -n "$(echo "${GET_lgip}" | sed -e '/^[\.:0-9a-fA-F]\+$/!d')" ]; then
if [ "$(ping -4 -c1 -W0.01 "${GET_lgip}" >/dev/null 2>&1; echo "$?")" -ne 2 ]; then
IP="${GET_lgip}"
IPv4=0
elif [ "$(ping -6 -c1 -W0.01 "${GET_lgip}" >/dev/null 2>&1; echo "$?")" -ne 2 ]; then
IP="${GET_lgip}"
fi
else
if [ -n ${GET_lgip} ]; then
IP="$(nslookup -q=AAAA "${GET_lgip}" | sed -ne '/^Address: /{s/^Address: *//p;q}')"
if [ -z "$IP" ]; then
IP="$(nslookup -q=A "${GET_lgip}" | sed -ne '/^Address: /{s/^Address: *//p;q}')"
IPv4=0
fi
fi
fi
SourceTR=""
SourcePing=""
if [ -n "$IP" ]; then
if [ $IPv4 -eq 0 ]; then
SourceTR="-s""$FFFV4"
SourcePing="-I""$FFFV4"
elif [ -z "$(ip -6 ro get "$IP" 2>&1 | grep " table ""$FFFTABLE"" \| unreachable")" ]; then
SourceTR="-s""$FFFGLOBALUNICAST"
SourcePing="-I""$FFFGLOBALUNICAST"
fi
%>
<H3>Ping <% echo -n "$IP" %></H3>
<pre>
<% ping -c4 $SourcePing "$IP" 2>&1 | sed -e 's/ from \S\+//g'
%>
</pre>
<br />
<H3>Traceroute <% echo -n "$IP" %></H3>
<pre>
<% traceroute -w1 -q2 $SourceTR "$IP" 2>&1 | sed -e 's/ from \S\+,/,/g'
%>
<pre>
<%
fi
fi
%>
</table>
</body>
</html>