Changeset - 19eee9446f54
[Not reviewed]
default
0 1 0
Dennis Fink - 11 years ago 2013-11-17 00:17:16
dennis.fink@c3l.lu
updated script
1 file changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
Scripts/update_server.py
Show inline comments
 
@@ -85,49 +85,51 @@ def create_server_json(tor_configfile='/
 

	
 
    tor_config = read_tor_config(tor_configfile)
 
    server_type, obfs = get_server_type(tor_config)
 
    hostname, fingerprint = get_tor_fingerprint(name)
 
    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):
 

	
 
    response = requests.post(url + '/api/update', data=json.dumps(server_json))
 
    headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
 

	
 
    response = requests.post(url + '/api/update', data=json.dumps(server_json), headers=headers)
 
    print(response.text)
 
    print(server_json)
 
    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()
 
            response = update_server(server_json, ennstatus_url)
 
        print(response)
 
    except Exception as e:
 
        print('Error: %s' % str(e))
0 comments (0 inline, 0 general)