Changeset - e7a2c084dcd0
[Not reviewed]
default
0 1 0
Dennis Fink - 10 years ago 2014-12-11 11:31:51
dennis.fink@c3l.lu
Fixed country and added ipv6 support
1 file changed with 11 insertions and 6 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/functions.py
Show inline comments
 
@@ -14,13 +14,13 @@ from ennstatus.status.functions import _
 

	
 
FINGERPRINT_REGEX = re.compile(r'^[A-Z0-9]{40}$', re.I)
 

	
 
DATE_FORMAT = '%d-%m-%Y %H:%M:%S'
 

	
 
gi4 = pygeoip.GeoIP('/usr/share/GeoIP/GeoIP.dat', pygeoip.MEMORY_CACHE)
 

	
 
gi6 = pygeoip.GeoIP('/usr/share/GeoIP/GeoIPv6.dat', pygeoip.MEMORY_CACHE)
 

	
 
mail_cache = dict()
 

	
 

	
 
def check_bridge(key, server):
 

	
 
@@ -92,13 +92,18 @@ def _send_offline_mail(server_name, last
 

	
 

	
 
def update_server(server, ip):
 

	
 
    server['last_updated'] = datetime.utcnow().strftime(DATE_FORMAT)
 
    server['server_status'] = 'Online'
 
    server['country'] = gi4.country_name_by_addr(ip)
 

	
 
    if ip.version == 4:
 
        server['country'] = gi4.country_name_by_addr(str(ip))
 
    elif ip.verion == 6:
 
        server['country'] = gi6.country_name_by_addr(str(ip))
 

	
 
    server_name = server['server_name']
 

	
 
    if server['server_type'] == 'Bridge':
 
        if 'ip' in server:
 
            del server['ip']
 

	
 
@@ -106,18 +111,18 @@ def update_server(server, ip):
 
            del server['ip6']
 
    else:
 
        for key in ('obfs', 'fteproxy', 'flashproxy', 'meek'):
 
            if key in server:
 
                del server[key]
 

	
 
        if isinstance(ip, ipaddress.IPv4Address):
 
        if ip.version == 4:
 
            if 'ip' not in server:
 
                server['ip'] = ip
 
        elif isinstance(ip, ipaddress.IPv6Address):
 
                server['ip'] = str(ip)
 
        elif ip.version == 6:
 
            if 'ip6' not in server:
 
                server['ip6'] = ip
 
                server['ip6'] = str(ip)
 

	
 
    try:
 
        filename = ''.join(['data/', server_name.lower(), '.json'])
 

	
 
        with open(filename, 'w', encoding='utf-8') as fb:
 
            json.dump(server, fb)
0 comments (0 inline, 0 general)