rework + lookingglass

Signed-off-by: Blackyfff <freifunk@freifunk-herpf.de>
This commit is contained in:
Blackyfff 2023-04-03 02:17:42 +02:00
parent e5cac2fb79
commit 99e4af12c2
1 changed files with 207 additions and 25 deletions

View File

@ -2,17 +2,20 @@
<%
echo -en "Content-Type: text/html\r\n\r\n"
HOSTNAME="$(uci -q get "fff.system.hostname")"
lockfile="/tmp/simple.babelweb.lock"
if [ -e $lockfile ];then
if [ 30 -gt $(( $(date +%s) - $(date -r $lockfile +%s) )) ];then
echo "only one access per minute!!" && exit
fi
fi
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
#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">
@ -49,16 +52,29 @@ touch $lockfile
<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>
@ -69,32 +85,75 @@ touch $lockfile
<br />
<%
if ! [ ${GET_routes} ] && ! [ ${GET_v4table} ] && ! [ ${GET_v6table} ] && ! [ ${GET_weg} ] ; then
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
echo "$line"
echo "<br>"
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
echo $line
echo "<br>"
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
echo $line
echo "<br>"
tmp=${line##*add xroute }
tmp=${tmp%% *}
newline="<tr><td>${tmp%%-*}</td><td>"
tmp=${line##* metric }
echo "$newline${tmp%% *}</td></tr>"
done
%>
</table>
<br />
<%
fi
@ -102,41 +161,164 @@ 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
echo "<tr><td>$line</td></tr>"
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 IPv6 Routing Tabele</H2>
<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
echo "<tr><td>$line</td></tr>"
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>
<%
v6routen=$(ip -6 ro sh tab 10)
echo "$v6routen" | while read line ; do
echo "<tr><td>$line</td></tr>"
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>
<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
echo "<tr><td>$line</td></tr>"
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>
</html>