api: Introduce dnslist and dnsentries

This provides lists of V2 routers to be used in DNS servers:

/api/dnslist - Plain tab-separated list to be used in custom scripts

/api/dnsentries - List of zone file entries without a header

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-03-05 18:28:49 +01:00
parent 306681eee0
commit 987bc91034
1 changed files with 38 additions and 0 deletions

View File

@ -247,6 +247,44 @@ def wifianalhelper(router_data, headline):
return Response(s,mimetype='text/plain')
@api.route('/dnslist')
def dnslist():
mysql = FreifunkMySQL()
router_data = mysql.fetchall("""
SELECT hostname, mac, MIN(ipv6) AS fd43
FROM router
INNER JOIN router_netif ON router.id = router_netif.router
INNER JOIN router_ipv6 ON router.id = router_ipv6.router AND router_netif.netif = router_ipv6.netif
WHERE LEFT(ipv6,4) = 'fd43'
GROUP BY hostname, mac
""",())
mysql.close()
s = ""
for router in router_data:
s += router["mac"].replace(":","") + "\t" + router["fd43"] + "\n"
return Response(s,mimetype='text/plain')
@api.route('/dnsentries')
def dnsentries():
mysql = FreifunkMySQL()
router_data = mysql.fetchall("""
SELECT hostname, mac, MIN(ipv6) AS fd43
FROM router
INNER JOIN router_netif ON router.id = router_netif.router
INNER JOIN router_ipv6 ON router.id = router_ipv6.router AND router_netif.netif = router_ipv6.netif
WHERE LEFT(ipv6,4) = 'fd43'
GROUP BY hostname, mac
""",())
mysql.close()
s = ""
for router in router_data:
s += router["mac"].replace(":","") + ".fff.community 300 IN AAAA " + router["fd43"] + " ; " + router["hostname"] + "\n"
return Response(s,mimetype='text/plain')
@api.route('/routers')
def routers():
# Suppresses routers without br-mesh