diff service/wifi/scrape_unmaintained.py @ 1226:7de8f0cd3392

very big rewrite. py3; orbi-only for now; n3 config file; delete or move out dead code Ignore-this: bfecea6f4990d34b36cc6d97cc6c6fa2 darcs-hash:79a3d55bfae5776b2374faa2020b6e27f17eb390
author drewp <drewp@bigasterisk.com>
date Sat, 30 Mar 2019 23:38:47 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/service/wifi/scrape_unmaintained.py	Sat Mar 30 23:38:47 2019 -0700
@@ -0,0 +1,57 @@
+    
+@inlineCallbacks
+def loadUvaData():
+    import lxml.html.soupparser
+
+    config = json.load(open("priv-uva.json"))
+    headers = {'Authorization': ['Basic %s' % config['userPass'].encode('base64').strip()]}
+    resp = yield fetch('http://10.2.0.2/wlstationlist.cmd', headers=headers)
+    root = lxml.html.soupparser.fromstring(resp.body)
+    byMac = {}
+    for tr in root.cssselect('tr'):
+        mac, connected, auth, ssid, iface = [td.text_content().strip() for td in tr.getchildren()]
+        if mac == "MAC":
+            continue
+        connected = connected.lower() == 'yes'
+        byMac[mac] = dict(mac=mac, connected=connected, auth=auth == 'Yes', ssid=ssid, iface=iface)
+        
+    resp = yield fetch('http://10.2.0.2/DHCPTable.asp', headers=headers)
+    for row in re.findall(r'new AAA\((.*)\)', resp.body):
+        clientHostname, ipaddr, mac, expires, iface = [s.strip("'") for s in row.rsplit(',', 4)]
+        if clientHostname == 'wlanadv.none':
+            continue
+        byMac.setdefault(mac, {}).update(dict(
+            clientHostname=clientHostname, connection=iface, ipaddr=ipaddr, dhcpExpires=expires))
+    
+    returnValue(sorted(byMac.values()))
+
+@inlineCallbacks
+def loadCiscoData():
+    config = json.load(open("priv-uva.json"))
+    headers = {'Authorization': ['Basic %s' % config['userPass'].encode('base64').strip()]}
+    print(headers)
+    resp = yield fetch('http://10.2.0.2/', headers=headers)
+    print(resp.body)
+    returnValue([])
+
+            
+def jsValue(js, variableName):
+    # using literal_eval instead of json parser to handle the trailing commas
+    val = re.search(variableName + r'\s*=\s*(.*?);', js, re.DOTALL).group(1)
+    return ast.literal_eval(val)
+
+            
+def _parseZyxel(self, data, routerName):
+    import lxml.html.soupparser
+
+    root = lxml.html.soupparser.fromstring(data)
+    for tr in root.cssselect('tr'):
+        mac, assoc, uth, ssid, iface = [td.text_content().strip() for td in tr.getchildren()]
+        if mac == "MAC":
+            continue
+        assoc = assoc.lower() == 'yes'
+        yield dict(router=routerName, mac=mac, assoc=assoc, connected=assoc)
+
+def _parseTomato(self, data, routerName):
+    for iface, mac, signal in jsValue(data, 'wldev'):
+        yield dict(router=routerName, mac=mac, signal=signal, connected=bool(signal))