Changeset - de6292f200dc
[Not reviewed]
default
0 1 0
Dennis Fink - 11 years ago 2013-11-17 00:15:22
dennis.fink@c3l.lu
updated script
1 file changed with 7 insertions and 7 deletions:
0 comments (0 inline, 0 general)
Scripts/update_server.py
Show inline comments
 
@@ -25,25 +25,25 @@ def read_tor_config(configfile="/etc/tor
 
def get_tor_status(name='tor'):
 

	
 
    try:
 
        pids = subprocess.check_output(['pidof', 'tor']).decode('utf-8')
 
        pids = pids.split(' ')
 
        pid_file = '.'.join([name, 'pid'])
 
        pid = open('/'.join(['var', 'run', name, pid_file])).readline()
 
        pid = open('/'.join(['/var', 'run', name, pid_file])).readline()
 

	
 
        if pid in pids:
 
            return "Online"
 
        else:
 
            return "Offline"
 
    except subprocess.CalledProcessError:
 
        return "Offline"
 

	
 

	
 
def get_tor_fingerprint(name='tor'):
 

	
 
    fingerprint_file = '/'.join(['var', 'lib', name, 'fingerprint'])
 
    fingerprint_file = '/'.join(['/var', 'lib', name, 'fingerprint'])
 

	
 
    with open(fingerprint_file) as fb:
 
        line = fb.readline()[:-1]
 

	
 
    hostname, fingerprint = line.split(' ')
 
    return hostname, fingerprint
 
@@ -98,19 +98,20 @@ def create_server_json(tor_configfile='/
 
    if obfs is not None:
 
        dictionary['obfs'] = obfs
 

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

	
 
    return json.dumps(dictionary)
 
    return dictionary
 

	
 

	
 
def update_server(server_json, url):
 

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

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

	
 
    return response.text
 

	
 

	
 
def main():
 
@@ -124,14 +125,13 @@ def main():
 
                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))
 

	
 
    print(response)
 

	
 

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