Changeset - fd0f9336d6d8
[Not reviewed]
default
0 2 0
Dennis Fink - 11 years ago 2014-07-15 23:16:16
dennis.fink@c3l.lu
Breaking API change. obfs and fteproxy need to be booleans not string
2 files changed with 9 insertions and 16 deletions:
0 comments (0 inline, 0 general)
Scripts/update_server.py
Show inline comments
 
@@ -60,24 +60,18 @@ def get_server_type(tor_config):
 
    else:
 
        return 'Exit', None
 

	
 

	
 
def get_obfs_proxy(tor_config):
 

	
 
    if any(OBFS_REGEX.match(i) for i in tor_config):
 
        return 'True'
 
    else:
 
        return 'False'
 
    return any(OBFS_REGEX.match(i) for i in tor_config)
 

	
 

	
 
def get_fte_proxy(tor_config):
 

	
 
    if any(FTEPROXY_REGEX.match(i) for i in tor_config):
 
        return 'True'
 
    else:
 
        return 'False'
 
    return any(FTEPROXY_REGEX.match(i) for i in tor_config)
 

	
 

	
 
def get_ip(tor_config):
 

	
 
    for i in tor_config:
 
        match = IP_REGEX.match(i)
ennstatus/api/functions.py
Show inline comments
 

	
 
import re
 
import json
 

	
 
from datetime import datetime
 
from ast import literal_eval
 

	
 
import pygeoip
 

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

	
 
IP_REGEX = (r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
 
@@ -25,16 +24,16 @@ gi4 = pygeoip.GeoIP('/usr/share/GeoIP/Ge
 

	
 
def check_bridge(key, server):
 

	
 
    if key not in server:
 
        raise ValueError('%s key not present!\n' % key)
 
    else:
 
        if server[key] not in ('True', 'False'):
 
            error_message = ('%s has not the right content!'
 
                             ' is: %s must be one of: True or False\n') \
 
                % (key, server[key])
 
        if not isinstance(server[key], bool):
 
            error_message = ('%s has not the right type!'
 
                             ' Needs to be a boolean!\n') \
 
                % key
 
            raise ValueError(error_message)
 

	
 

	
 
def check_json_format(server):
 

	
 
    for key in ('server_type', 'server_name', 'tor_status', 'fingerprint'):
 
@@ -72,21 +71,21 @@ 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 server['server_type'] == 'Bridge':
 
        server['obfs'] = literal_eval(server['obfs'])
 
        server['fteproxy'] = literal_eval(server['fteproxy'])
 

	
 
        if 'ip' in server:
 
            del server['ip']
 
    else:
 
        if 'obfs' in server:
 
            del server['obfs']
 

	
 
        if 'fteproxy' in server:
 
            del server['fteproxy']
 

	
 
        server['ip'] = ip
 

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

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