Changeset - 5a9d06b7e07d
[Not reviewed]
default
0 2 0
Dennis Fink - 11 years ago 2014-07-16 20:14:38
dennis.fink@c3l.lu
Fix bridge checking and version bump
2 files changed with 3 insertions and 4 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/functions.py
Show inline comments
 
@@ -8,74 +8,73 @@ 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}'
 
            r'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$')
 
IP_REGEX = re.compile(IP_REGEX)
 

	
 
PRIVATE_IP_REGEX = (r'(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)'
 
                    r'|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|'
 
                    r'255\.255\.255\.255')
 
PRIVATE_IP_REGEX = re.compile(PRIVATE_IP_REGEX)
 

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

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

	
 

	
 
def check_bridge(key, server):
 

	
 
    if key not in server:
 
        raise ValueError('%s key not present!\n' % key)
 
    else:
 
        if not isinstance(server[key], bool):
 
            error_message = ('%s has not the right type!'
 
                             ' Needs to be a boolean!\n') \
 
                % key
 
                             ' 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'):
 
        if key not in server:
 
            raise ValueError('%s key not present!\n' % key)
 

	
 
    if server['server_type'] not in ('Exit', 'Relay', 'Bridge'):
 
        error_message = ('server_type has not the right content!'
 
                         ' is: %s must be one of: Exit, Relay or Bridge\n') \
 
            % server['server_type']
 
        raise ValueError(error_message)
 

	
 
    if not server['tor_status'] in ('Online', 'Offline'):
 
        error_message = ('tor_status has not the right content!'
 
                         ' is: %s must be one of: Online or Offline\n') \
 
            % server['tor_status']
 

	
 
    if FINGERPRINT_REGEX.match(server['fingerprint']) is None:
 
        raise ValueError('fingerprint has not the right format!\n')
 

	
 
    if server['server_type'] == 'bridge':
 
    if server['server_type'] == 'Bridge':
 
        for key in ('obfs', 'fteproxy', 'flashproxy', 'meek'):
 
            check_bridge(key, server)
 

	
 
    if 'ip' in server:
 
        if IP_REGEX.match(server['ip']) is None:
 
            raise ValueError('ip is not the right format!\n')
 
        elif PRIVATE_IP_REGEX.match(server['ip']) is not None:
 
            raise ValueError('ip is not accepted!\n')
 

	
 
    return True
 

	
 

	
 
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':
 
        if 'ip' in server:
 
            del server['ip']
 
    else:
 
        if 'obfs' in server:
 
            del server['obfs']
setup.py
Show inline comments
 
from setuptools import setup, find_packages
 

	
 

	
 
def _get_requirements():
 

	
 
    with open('requirements.in', encoding='utf-8') as f:
 
        lines = f.readlines()
 

	
 
    lines = [line[:-1] for line in lines if not line.startswith('#')]
 
    return lines
 

	
 

	
 
setup(name='Ennstatus',
 
      version='4.2.0',
 
      version='4.2.1',
 
      description=('Ennstatus provides the user with vital information about '
 
                   'the status of the organizations Tor servers.'),
 
      author='Frënn vun der Ënn',
 
      author_email='info@enn.lu',
 
      url='https://bitbucket.org/fvde/ennstatus',
 
      license='GPLv3+',
 
      packages=find_packages(),
 
      package_data={'ennstatus': ['static/css/*.css',
 
                                  'static/css/flags/img/png/*.png',
 
                                  'static/css/flags/img/gif/*.gif',
 
                                  'static/css/flags/*.css',
 
                                  'static/files/*',
 
                                  'static/images/*',
 
                                  'static/videos/*',
 
                                  'templates/*.html',
 
                                  'templates/api/export/xml/*.xml',
 
                                  'templates/donate/*.html',
 
                                  'templates/root/*.html',
 
                                  'templates/status/*.html',
 
                                  'templates/stats/*.html',
 
                                  'templates/errorpages/*.html',
 
                                  ]},
 
      install_requires=_get_requirements(),
 
      classifiers=['Development Status :: 5 - Production/Stable',
0 comments (0 inline, 0 general)