Sfoglia il codice sorgente

server: revamped vpn list

Helge Jung 9 anni fa
parent
commit
32ebd6804b
1 ha cambiato i file con 24 aggiunte e 5 eliminazioni
  1. 24 5
      ffstatus/server.py

+ 24 - 5
ffstatus/server.py

@@ -242,18 +242,37 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
 	def respond_vpnlist(self):
 		storage = self.server.storage
 
+		gateways = ['gw01','gw02','gw03','gw04']
+
 		self.send_headers()
 		self.wfile.write('<!DOCTYPE html>\n')
 		self.wfile.write('<html><head><title>BATCAVE - VPN LIST</title></head>\n')
 		self.wfile.write('<body>\n')
-		self.wfile.write('<table>\n<thead><tr><th>key</th><th>active</th><th>last</th></tr></thead>\n')
-		
+		self.wfile.write('<table>\n<thead>\n')
+		self.wfile.write('<tr><th>key</th><th colspan="' + str(len(gateways)) + '">active</th><th colspan="' + str(len(gateways)) + '">last</th></tr>\n')
+		self.wfile.write('<tr><th>name</th><th>' + '</th><th>'.join(gateways) + '</th><th>' + '</th><th>'.join(gateways) + '</th></tr>\n')
+		self.wfile.write('</thead>\n')
+
 		if self.DATAKEY_VPN in storage.data:
 			for key in storage.data[self.DATAKEY_VPN]:
 				item = storage.data[self.DATAKEY_VPN][key]
-				self.wfile.write('<tr><td>' + str(key) + '</td>')
-				self.wfile.write('<td>' + json.dumps(item['active'] if 'active' in item else {}) + '</td>')
-				self.wfile.write('<td>' + json.dumps(item['last'] if 'last' in item else {}) + '</td>')
+
+				names = set()
+				for t in [ 'active', 'last' ]:
+					if t in item:
+						for gw in item[t]:
+							if 'peer' in item[t][gw]:
+								names.add(item[t][gw])
+
+				self.wfile.write('<tr><td title="' + str(key) + '">' + ' / '.join(names) + '</td>')
+				for t in [ 'active', 'last' ]:
+					for gw in gateways:
+						ip = ''
+						details = ''
+						if t in item and gw in item[t]:
+							ip = item[t][gw]['remote'] if 'remote' in item[t][gw] else ''
+						self.wfile.write('<td>' + ip + '</td>')
+
 				self.wfile.write('</tr>\n')
 
 		self.wfile.write('</table>\n')