|
@@ -453,13 +453,6 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
vpn = self.server.storage.data[self.DATAKEY_VPN]
|
|
|
outputformat = query['format'].lower() if 'format' in query else 'html'
|
|
|
|
|
|
- geo = None
|
|
|
- try:
|
|
|
- geo = pygeoip.GeoIP('GeoIPISP.dat')
|
|
|
- except:
|
|
|
- self.return_error(500, 'The GeoIP-ISP database file could not be opened.')
|
|
|
- return
|
|
|
-
|
|
|
isps = {}
|
|
|
for key in vpn:
|
|
|
if key is None: continue
|
|
@@ -467,22 +460,32 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
if not isinstance(item, dict): continue
|
|
|
if not 'active' in item: continue
|
|
|
|
|
|
- ips = set()
|
|
|
+ ips = []
|
|
|
for gw in item['active']:
|
|
|
if 'remote' in item['active'][gw]:
|
|
|
- ips.add(item['active'][gw]['remote'])
|
|
|
+ ip = item['active'][gw]['remote']
|
|
|
+ if not isinstance(ip, dict):
|
|
|
+ # try to resolve ip now
|
|
|
+ resolved = ffstatus.resolve_ipblock(ip)
|
|
|
+ if not resolved is None:
|
|
|
+ self.logger.debug('Resolved IP \'{0}\' to block \'{1}\'.'.format(ip, resolved))
|
|
|
+ item['active'][gw]['remote'] = resolved
|
|
|
+ ip = resolved
|
|
|
+ ips.append(ip)
|
|
|
|
|
|
- if len(ips) == 0: continue
|
|
|
- if len(ips) > 1:
|
|
|
- self.logger.debug('VPN key \'{0}\' has {1} active ips. Possible cause is an in-progress re-dialin.'.format(key, len(ips)))
|
|
|
+ if len(ips) == 0:
|
|
|
+ # no active dialins -> no need to process this key any further
|
|
|
+ continue
|
|
|
|
|
|
item_isps = set()
|
|
|
for ip in ips:
|
|
|
- try:
|
|
|
- isp = geo.org_by_addr(ip)
|
|
|
- if not isp is None: item_isps.add(isp)
|
|
|
- except Exception as err:
|
|
|
- self.logger.debug('Failed to resolve ISP for \'{0}\': {1}'.format(ip, str(err)))
|
|
|
+ isp = "UNKNOWN"
|
|
|
+ if isinstance(ip, dict):
|
|
|
+ name_parts = ip['name'].split('-')
|
|
|
+ desc_lines = ip['description'].split('\n')
|
|
|
+ isp = name_parts[0] + ' (' + desc_lines[0] + ')'
|
|
|
+
|
|
|
+ item_isps.add(isp)
|
|
|
|
|
|
if len(item_isps) == 0:
|
|
|
item_isps.add('unknown')
|