Changeset - a6b70b659863
[Not reviewed]
default
0 2 0
Dennis Fink - 11 years ago 2014-07-15 19:07:31
dennis.fink@c3l.lu
Updated update scripts to support fteproxy
2 files changed with 37 insertions and 7 deletions:
0 comments (0 inline, 0 general)
Scripts/update_server.pl
Show inline comments
 
#!/usr/bin/env perl
 
=About
 
==About
 
This is a perlized "Update Server" script which should run out of the box
 
on most machines. If not you need to install HTTP::Tiny
 
sudo cpan
 
>install HTTP::Tiny
 

	
 
by virii
 
=cut
 
==cut
 
use HTTP::Tiny;
 
use IO::Socket;
 
######## [defaults] ########
 
@@ -36,12 +36,16 @@ for (1..scalar @configs) {
 
            $data_dir    = $1       if /^DataDirectory (.*)/i;
 
            $pidfile     = $1       if /^PidFile (.*)/i;
 
            $obfs        = 'True'   if /^ServerTransportPlugin (obfs\d+|scramblesuit)/i;
 
	    $fteproxy    = 'True'   if /^ServerTransportPlugin fte/i;
 
            $ip          = $1       if /^OutboundBindAddress (\d+\.\d+\.\d+\.\d+)/i;
 
        }
 
    close config;
 
######## [obfs check] ########  
 
    $obfs = 'False' if $obfs ne 'True' and $server_type eq 'Bridge';
 
print $obfs . "\n";
 
######## [fte check] ########
 
$fteproxy = 'False' if $fteproxy ne 'True' and $server_type eq 'Bridge';
 
print $fteproxy . "\n";
 
######## [ip check] ########    
 
    if ($ip == "") {
 
        $socket = new IO::Socket::INET ( PeerAddr => "enn.lu",
 
@@ -72,6 +76,7 @@ if ($server_type eq "Bridge") {
 
                '", "server_name": "' . $server_name .
 
                '", "server_type": "' . $server_type .
 
                '", "obfs": "' . $obfs .
 
		'", "fteproxy": "' . $fteproxy .
 
                '", "tor_status": "' . $tor_status .
 
                '"}';
 
} else {
Scripts/update_server.py
Show inline comments
 
@@ -9,6 +9,8 @@ from ast import literal_eval
 

	
 
OBFS_REGEX = re.compile(r'^ServerTransportPlugin (obfs\d+|scramblesuit)')
 

	
 
FTEPROXY_REGEX = re.compile(r'^ServerTransportPlugin fte')
 

	
 
IP_REGEX = re.compile(r'^(OutboundBindAddress)\ (\d{1,3}\.\d{1,3}\.\d{1,3}\.'
 
                      r'\d{1,3})')
 

	
 
@@ -52,16 +54,29 @@ def get_tor_fingerprint(name='tor'):
 
def get_server_type(tor_config):
 

	
 
    if 'BridgeRelay 1' in tor_config:
 
        if any(OBFS_REGEX.match(i) for i in tor_config):
 
            return 'Bridge', 'True'
 
        else:
 
            return 'Bridge', 'False'
 
        return 'Bridge'
 
    elif 'ExitPolicy reject *:*' in tor_config:
 
        return 'Relay', None
 
    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'
 

	
 

	
 
def get_fte_proxy(tor_config):
 

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

	
 

	
 
def get_ip(tor_config):
 

	
 
    for i in tor_config:
 
@@ -84,11 +99,18 @@ def get_config():
 
def create_server_json(tor_configfile='/etc/tor/torrc', name='tor'):
 

	
 
    tor_config = read_tor_config(tor_configfile)
 
    server_type, obfs = get_server_type(tor_config)
 
    server_type = get_server_type(tor_config)
 
    hostname, fingerprint = get_tor_fingerprint(name)
 
    tor_status = get_tor_status(name)
 
    ip = get_ip(tor_config)
 

	
 
    obfs = None
 
    fte = None
 

	
 
    if server_type == 'Bridge':
 
        obfs = get_obfs_proxy(tor_config)
 
        fte = get_fte_proxy(tor_config)
 

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

	
 
@@ -98,6 +120,9 @@ def create_server_json(tor_configfile='/
 
    if obfs is not None:
 
        dictionary['obfs'] = obfs
 

	
 
    if fte is not None:
 
        dictionary['fteproxy'] = fte
 

	
 
    return dictionary
 

	
 

	
0 comments (0 inline, 0 general)