<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
from time import sleep
from random import randint, choice


OONI_BINARY = " "  # Path to ooniprobe binary. 
PROBE_TEST = "siteprobe.py"
DNS_TEST = "dnscompare.py"
TCP_TEST = "tcpconnect.py"
PING_TEST = "ping.py"
TRACEROUTE_TEST = "traceroute.py"
TOR_MIRRORS = ["https://www.unicorncloud.org/public/torproject.org/", "https://mirror.ml/tor/", "https://www.oignon.net/", "https://tor.hackthissite.org/"]
TOR_DIRECTORY_AUTHORITIES = [
                             { "192.168.3.11": 80 },
                             { "192.168.3.11": 443 },
                             { "192.168.3.11": 9030 },
                             { "192.168.3.11": 9090 },
                             { "192.168.3.11": 443 },
                             { "192.168.3.11": 80 },
                             { "dannenberg.ccc.de": 80 },
                             { "192.168.3.11": 443 },
                             { "192.168.127.12": 443 }, 
                             { "192.168.127.12": 80 },
                             { "172.16.58.3": 9131 },
                             { "172.16.58.3": 9101 },
                             { "192.168.3.11": 80 },
                             { "192.168.3.11": 443 },
                             { "192.168.3.11": 80 },
                             { "192.168.3.11": 443 },
                             { "192.168.127.12": 80 },
                             { "192.168.127.12": 443 }
                            ]

class Analyser():
        
    def runTest(self, test, argv):
        if len(argv) > 1:
            args = (OONI_BINARY, "-n", test, argv[0], argv[1])
        else:
            args = (OONI_BINARY, "-n", test)
        print "Running test %s" % test
        popen = subprocess.Popen(args, stdout=subprocess.PIPE)
        popen.wait()
        output = popen.stdout.read()
        return output
        
    def probeSite(self, args):
        return self.runTest(PROBE_TEST, args)
    
    def compareDNS(self, args):
        return self.runTest(DNS_TEST, args)
        
    def testTCPConnection(self):
        return self.runTest(TCP_TEST, [])
    
    def ping(self, argv):
        return self.runTest(ICMP_TEST, argv)
        
def probeTorSite():
    if not "Site reachable" in analyser.probeSite([]):
        print "Tor site not reachable - running tests"
        tests = [
                    { TCP_TEST: ["-t", "bridges.torproject.org"] },
                    {  DNS_TEST: [] },
                    {  PROBE_TEST: ["-u", choice(TOR_MIRRORS)] },
                    {  TCP_TEST: [] }
                ]
        runTests(tests)
    else:
        print "Tor site reachable"
         
def probeDirectoryAuthorities():
    reachable = False
    for server in TOR_DIRECTORY_AUTHORITIES:
        host = server.keys()[0]
        port = server[host] 
        url = makeURL(host, port)

        if "Site reachable" in analyser.probeSite(["-u", url]):
            print "Consensus successfully fetched"
            reachable = True
            break

    if not reachable:
        print "Failed to fetch consensus - running tests"
        tests = [ 
                { PING_TEST: ["-f", "directory_authorities.txt"] },
                { TRACEROUTE_TEST : ["-f", "directory_authorities.txt"] }
                ]
        runTests(tests)

def makeURL(host, port):
    if port == 80: 
         url = "http://%s/tor/status-vote/current/consensus.z" % (host)
    elif port == 443:
         url = "https://%s/tor/status-vote/current/consensus.z" % (host)<commit_msg>minor changes in probeDirectoryAuthorities function<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
from time import sleep
from random import randint, choice


OONI_BINARY = "/home/analyser/ooni-probe/bin/ooniprobe"  # Path to ooniprobe binary. 
PROBE_TEST = "siteprobe.py"
DNS_TEST = "dnscompare.py"
TCP_TEST = "tcpconnect.py"
PING_TEST = "ping.py"
TRACEROUTE_TEST = "traceroute.py"
TOR_MIRRORS = ["https://www.unicorncloud.org/public/torproject.org/", "https://mirror.ml/tor/", "https://www.oignon.net/", "https://tor.hackthissite.org/"]
TOR_DIRECTORY_AUTHORITIES = [
                             { "192.168.3.11": 80 },
                             { "192.168.3.11": 443 },
                             { "192.168.3.11": 9030 },
                             { "192.168.3.11": 9090 },
                             { "192.168.3.11": 443 },
                             { "192.168.3.11": 80 },
                             { "dannenberg.ccc.de": 80 },
                             { "192.168.3.11": 443 },
                             { "192.168.127.12": 443 }, 
                             { "192.168.127.12": 80 },
                             { "172.16.58.3": 9131 },
                             { "172.16.58.3": 9101 },
                             { "192.168.3.11": 80 },
                             { "192.168.3.11": 443 },
                             { "192.168.3.11": 80 },
                             { "192.168.3.11": 443 },
                             { "192.168.127.12": 80 },
                             { "192.168.127.12": 443 }
                            ]

class Analyser():
        
    def runTest(self, test, argv):
        if len(argv) > 1:
            args = (OONI_BINARY, "-n", test, argv[0], argv[1])
        else:
            args = (OONI_BINARY, "-n", test)
        print "Running test %s" % test
        popen = subprocess.Popen(args, stdout=subprocess.PIPE)
        popen.wait()
        output = popen.stdout.read()
        return output
        
    def probeSite(self, args):
        return self.runTest(PROBE_TEST, args)
    
    def compareDNS(self, args):
        return self.runTest(DNS_TEST, args)
        
    def testTCPConnection(self):
        return self.runTest(TCP_TEST, [])
    
    def ping(self, argv):
        return self.runTest(ICMP_TEST, argv)
        
def probeTorSite():
    if not "Site reachable" in analyser.probeSite([]):
        print "Tor site not reachable - running tests"
        tests = [
                    { TCP_TEST: ["-t", "bridges.torproject.org"] },
                    {  DNS_TEST: [] },
                    {  PROBE_TEST: ["-u", choice(TOR_MIRRORS)] },
                    {  TCP_TEST: [] }
                ]
        runTests(tests)
    else:
        print "Tor site reachable"
         
def probeDirectoryAuthorities():
    for server in TOR_DIRECTORY_AUTHORITIES:
        host = server.keys()[0]
        port = server[host] 
        url = makeURL(host, port)

        if "Site reachable" in analyser.probeSite(["-u", url]):
            print "Consensus successfully fetched"
            return

    print "Failed to fetch consensus - running tests"
    tests = [ 
            { PING_TEST: ["-f", "directory_authorities.txt"] },
            { TRACEROUTE_TEST : ["-f", "directory_authorities.txt"] }
            ]

    runTests(tests)

def makeURL(host, port):
    if port == 80: 
         url = "http://%s/tor/status-vote/current/consensus.z" % (host)
    elif port == 443:
         url = "https://%s/tor/status-vote/current/consensus.z" % (host)
{'fraction_non_alphanumeric': 0.14129367195173284, 'fraction_numerical': 0.061737056264908094, 'mean_word_length': 1.3951612903225807, 'pattern_counts': {'":': 36, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 34, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2911375', 'n_tokens_mistral': 2551, 'n_tokens_neox': 2215, 'n_words': 435}