Changeset - 054c5e8fb877
[Not reviewed]
default
0 1 0
Dennis Fink - 11 years ago 2013-11-17 16:21:34
dennis.fink@c3l.lu
updated script
1 file changed with 9 insertions and 13 deletions:
0 comments (0 inline, 0 general)
Scripts/update_server.py
Show inline comments
 
@@ -89,50 +89,46 @@ def create_server_json(tor_configfile='/
 
    tor_status = get_tor_status(name)
 
    ip = get_ip(tor_config)
 

	
 
    dictionary = {'server_type': server_type, 'server_name': hostname,
 
                  'tor_status': tor_status}
 

	
 
    if ip is not None:
 
        dictionary['ip'] = ip
 

	
 
    if obfs is not None:
 
        dictionary['obfs'] = obfs
 

	
 
    if server_type != 'Bridge':
 
        dictionary['fingerprint'] = fingerprint
 

	
 
    return dictionary
 

	
 

	
 
def update_server(server_json, url):
 

	
 
    headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
 

	
 
    response = requests.post(url + '/api/update', data=json.dumps(server_json),
 
                             headers=headers)
 
    response.raise_for_status()
 

	
 
    return response.text
 

	
 

	
 
def main():
 

	
 
    config = get_config()
 
    ennstatus_url = config['main']['ennstatus_url']
 

	
 
    try:
 
        if 'servers' in config['main']:
 
            for server in literal_eval(config['main']['servers']):
 
                server_json = create_server_json(config[server]['configfile'],
 
                                                 server)
 
                response = update_server(server_json, ennstatus_url)
 
        else:
 
            server_json = create_server_json()
 
    if 'servers' in config['main']:
 
        for server in literal_eval(config['main']['servers']):
 
            server_json = create_server_json(config[server]['configfile'],
 
                                             server)
 
            response = update_server(server_json, ennstatus_url)
 
        print(response)
 
    except Exception as e:
 
        print('Error: %s' % str(e))
 
            print(response, end='')
 
    else:
 
        server_json = create_server_json()
 
        response = update_server(server_json, ennstatus_url)
 
        print(response, end='')
 

	
 

	
 
if __name__ == '__main__':
 
    main()
0 comments (0 inline, 0 general)