gwinfo: Support internal IPv4/IPv6 and DHCP ranges (v1.4)
This updates gwinfo script AND evaluation code. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
fe4136167a
commit
478c0fb8dd
|
@ -47,6 +47,10 @@ mysql.execute("""
|
|||
`mac` char(17) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`netif` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`vpnmac` char(17) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`ipv4` char(18) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`ipv6` varchar(60) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`dhcpstart` char(15) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`dhcpend` char(15) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`last_contact` datetime NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
|
||||
""")
|
||||
|
|
|
@ -47,16 +47,28 @@ def import_gw_data(mysql, gw_data):
|
|||
n["vpnmac"] = nmacs.get(n["vpnif"],None)
|
||||
else:
|
||||
n["vpnmac"] = None
|
||||
if not "ipv4" in n or not n["ipv4"]:
|
||||
n["ipv4"] = None
|
||||
if not "ipv6" in n or not n["ipv6"]:
|
||||
n["ipv6"] = None
|
||||
if not "dhcpstart" in n or not n["dhcpstart"]:
|
||||
n["dhcpstart"] = None
|
||||
if not "dhcpend" in n or not n["dhcpend"]:
|
||||
n["dhcpend"] = None
|
||||
|
||||
ndata.append((newid,n["mac"],n["netif"],n["vpnmac"],time,))
|
||||
ndata.append((newid,n["mac"],n["netif"],n["vpnmac"],n["ipv4"],n["ipv6"],n["dhcpstart"],n["dhcpend"],time,))
|
||||
|
||||
mysql.executemany("""
|
||||
INSERT INTO gw_netif (gw, mac, netif, vpnmac, last_contact)
|
||||
VALUES (%s, %s, %s, %s, %s)
|
||||
INSERT INTO gw_netif (gw, mac, netif, vpnmac, ipv4, ipv6, dhcpstart, dhcpend, last_contact)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
gw=VALUES(gw),
|
||||
netif=VALUES(netif),
|
||||
vpnmac=VALUES(vpnmac),
|
||||
ipv4=VALUES(ipv4),
|
||||
ipv6=VALUES(ipv6),
|
||||
dhcpstart=VALUES(dhcpstart),
|
||||
dhcpend=VALUES(dhcpend),
|
||||
last_contact=VALUES(last_contact)
|
||||
""",ndata)
|
||||
|
||||
|
|
|
@ -316,7 +316,7 @@ def gws_info(mysql,selecthood=None):
|
|||
tup = ()
|
||||
|
||||
data = mysql.fetchdict("""
|
||||
SELECT router_gw.mac AS mac, gw.name AS gw, stats_page, n1.netif AS gwif, n2.netif AS batif, n2.mac AS batmac
|
||||
SELECT router_gw.mac AS mac, gw.name AS gw, stats_page, n1.netif AS gwif, n2.netif AS batif, n2.mac AS batmac, n2.ipv4 AS ipv4, n2.ipv6 AS ipv6, n2.dhcpstart AS dhcpstart, n2.dhcpend AS dhcpend
|
||||
FROM router
|
||||
INNER JOIN router_gw ON router.id = router_gw.router
|
||||
LEFT JOIN (
|
||||
|
|
|
@ -194,6 +194,15 @@
|
|||
<tr><th>Interface</th><td>{{ gws_info[selectgw]["gwif"] }}</td></tr>
|
||||
<tr><th>MAC address</th><td>{{ selectgw }}</td></tr>
|
||||
<tr><th>BatX interface</th><td>{{ gws_info[selectgw]["batX"] }}</td></tr>
|
||||
{%- if gws_info[selectgw]["ipv4"] %}
|
||||
<tr><th>Internal IPv4</th><td>{{ gws_info[selectgw]["ipv4"] }}</td></tr>
|
||||
{%- endif %}
|
||||
{%- if gws_info[selectgw]["ipv6"] %}
|
||||
<tr><th>Internal IPv6</th><td>{{ gws_info[selectgw]["ipv6"] }}</td></tr>
|
||||
{%- endif %}
|
||||
{%- if gws_info[selectgw]["dhcpstart"] %}
|
||||
<tr><th>DHCP range</th><td>{{ gws_info[selectgw]["dhcpstart"] }} - {{ gws_info[selectgw]["dhcpend"] }}</td></tr>
|
||||
{%- endif %}
|
||||
{%- if gws_info[selectgw]["stats_page"] %}
|
||||
<tr><th>Stats page</th><td>{{ gws_info[selectgw]["stats_page"] }}</td></tr>
|
||||
{%- endif %}
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
# Copyright Adrian Schmutzler, 2018.
|
||||
# License GPLv3
|
||||
#
|
||||
# v1.4 - 2018-08-23
|
||||
# - Transmit internal IPv4/IPv6
|
||||
# - Transmit DHCP range for dnsmasq
|
||||
#
|
||||
# v1.3 - 2018-08-23
|
||||
# - Support multiple Monitoring URLs
|
||||
# - Use https by default
|
||||
|
@ -27,6 +31,7 @@ admin1="Admin"
|
|||
admin2=
|
||||
admin3=
|
||||
statslink="" # Provide link to stats page (MRTG or similar)
|
||||
dhcp=1 # 0=disabled, 1=dnsmasq, 2=isc-dhcp-server
|
||||
|
||||
# Code
|
||||
tmp=$(/bin/mktemp)
|
||||
|
@ -39,7 +44,19 @@ for netif in $(ls /sys/class/net); do
|
|||
fi
|
||||
mac="$(cat "/sys/class/net/$netif/address")"
|
||||
batctl="$("$batctlpath" -m "$netif" if | grep "fff" | sed -n 's/:.*//p')"
|
||||
echo "$comma{\"mac\":\"$mac\",\"netif\":\"$netif\",\"vpnif\":\"$batctl\"}" >> $tmp
|
||||
|
||||
ipv4="$(ip -4 addr show dev "$netif" | grep "10\." | sed 's/.*\(10\.[^ ]*\) .*/\1/')"
|
||||
ipv6="$(ip -6 addr show dev "$netif" | grep "fd43" | sed 's/.*\(fd43[^ ]*\) .*/\1/')"
|
||||
|
||||
if [ "$dhcp" = "1" ]; then
|
||||
dhcpdata="$(ps ax | grep "dnsmasq" | grep "$netif" | sed 's/.*dhcp-range=\([^ ]*\) .*/\1/')"
|
||||
dhcpstart="$(echo "$dhcpdata" | cut -d',' -f1)"
|
||||
dhcpend="$(echo "$dhcpdata" | cut -d',' -f2)"
|
||||
#elif [ "$dhcp" = "2" ]; then
|
||||
# not implemented
|
||||
fi
|
||||
|
||||
echo "$comma{\"mac\":\"$mac\",\"netif\":\"$netif\",\"vpnif\":\"$batctl\",\"ipv4\":\"$ipv4\",\"ipv6\":\"$ipv6\",\"dhcpstart\":\"$dhcpstart\",\"dhcpend\":\"$dhcpend\"}" >> $tmp
|
||||
comma=","
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in New Issue