diff --git a/ffmap/db/gws.py b/ffmap/db/gws.py index f996bb4..047113c 100755 --- a/ffmap/db/gws.py +++ b/ffmap/db/gws.py @@ -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 """) diff --git a/ffmap/gwtools.py b/ffmap/gwtools.py index 557eec5..af8c548 100644 --- a/ffmap/gwtools.py +++ b/ffmap/gwtools.py @@ -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) diff --git a/ffmap/stattools.py b/ffmap/stattools.py index 49150a5..6d31d24 100644 --- a/ffmap/stattools.py +++ b/ffmap/stattools.py @@ -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 ( diff --git a/ffmap/web/templates/statistics.html b/ffmap/web/templates/statistics.html index b155e36..c045140 100644 --- a/ffmap/web/templates/statistics.html +++ b/ffmap/web/templates/statistics.html @@ -194,6 +194,15 @@ Interface{{ gws_info[selectgw]["gwif"] }} MAC address{{ selectgw }} BatX interface{{ gws_info[selectgw]["batX"] }} + {%- if gws_info[selectgw]["ipv4"] %} + Internal IPv4{{ gws_info[selectgw]["ipv4"] }} + {%- endif %} + {%- if gws_info[selectgw]["ipv6"] %} + Internal IPv6{{ gws_info[selectgw]["ipv6"] }} + {%- endif %} + {%- if gws_info[selectgw]["dhcpstart"] %} + DHCP range{{ gws_info[selectgw]["dhcpstart"] }} - {{ gws_info[selectgw]["dhcpend"] }} + {%- endif %} {%- if gws_info[selectgw]["stats_page"] %} Stats page{{ gws_info[selectgw]["stats_page"] }} {%- endif %} diff --git a/gwinfo/sendgwinfo.sh b/gwinfo/sendgwinfo.sh index fcf9fbe..ba4d32b 100755 --- a/gwinfo/sendgwinfo.sh +++ b/gwinfo/sendgwinfo.sh @@ -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