Beispiel #1
0
def _get_user_settings(args, provider=None):
    user_settings = Settings()
    if 'config' in vars(args):
        user_settings.read_settings(filename=args.config)
    else:
        user_settings.read_settings()
    _merge_arguments(user_settings, provider, vars(args))
    return user_settings
Beispiel #2
0
class TestSettings(unittest.TestCase):
    def setUp(self):
        self.settings = Settings()
        self.settings.read_settings(
            os.path.join(os.path.dirname(__file__),
                         'resources/test_settings.cfg'))

    def test_read_config(self):
        self.assertIsNotNone(self.settings)

    def test_has_first_name(self):
        self.assertIsNotNone(self.settings.get('user', 'firstname'))

    def test_has_email(self):
        self.assertTrue("@" in self.settings.get('user', 'email'))

    def test_verify_config(self):
        verification = {"user": ["email", 'firstname', 'lastname']}
        self.assertTrue(self.settings.verify_options(verification))

    def test_verify_bad_config(self):
        verification = {
            "user": ["email", 'firstname', 'lastname'
                     "randomattribute"]
        }
        self.assertFalse(self.settings.verify_options(verification))

    def test_put(self):
        key = "putkey"
        section = "putsection"
        value = "putvalue"
        self.settings.put(section, key, value)
        self.assertEqual(self.settings.get(section, key), value)

    def test_get_merge(self):
        key = 'email'
        sections = ['testhoster', 'user']
        value = '*****@*****.**'
        self.assertEqual(self.settings.get_merge(sections, key), value)

    def test_get_merge_ordering(self):
        key = 'email'
        sections = ['user', 'testhoster']
        value = '*****@*****.**'
        self.assertEqual(self.settings.get_merge(sections, key), value)

    def test_custom_provider(self):
        self.assertEqual(self.settings.get("testhoster", "email"),
                         "*****@*****.**")
Beispiel #3
0
def _get_user_settings(args, provider=None):
    user_settings = Settings()
    if 'config' in vars(args):
        user_settings.read_settings(filename=args.config)
    else:
        user_settings.read_settings()
    _merge_arguments(user_settings, provider, vars(args))

    # Set global testnet variable according to configuration
    if user_settings.has_key('user', 'testnet') and user_settings.get(
            'user', 'testnet') == '1':
        os.environ['TESTNET'] = '1'
    else:
        os.environ['TESTNET'] = '0'
    return user_settings
Beispiel #4
0
class TestHosters(unittest.TestCase):
    def setUp(self):
        self.settings = Settings()
        self.settings.read_settings(
            os.path.join(os.path.dirname(__file__),
                         'resources/test_settings.cfg'))

    @parameterized.expand(providers)
    def test_vpn_hoster_options(self, hoster):
        options = hoster.get_options()
        self.assertTrue(len(options) > 0)

    @parameterized.expand(providers)
    def test_vpn_hoster_configuration(self, hoster):
        config = hoster(self.settings).get_configuration()
        self.assertTrue(len(config) > 0)
Beispiel #5
0
def child_account(index=None):
    """
    This method returns the configuration for a certain child number.
    :param index: The number of the child
    :type index: Integer
    :return: configuration of the child
    :rtype: Settings
    """
    if index is not None:
        account = AccountSettings()
        account.read_settings(
            os.path.join(user_config_dir(), 'child_config' + str(index) + '.cfg'))
    else:
        account = AccountSettings()
        account.read_settings(
            os.path.join(user_config_dir(), 'child_config' + str(PlebNetConfig().get("child_index")) + '.cfg'))
    return account
Beispiel #6
0
    def test_generate_child_has_content(self, mock):
        fake_generator.generate_child_account()
        account = Settings()
        account.read_settings(test_file)

        self.assertIsNotNone(account.get('user', 'email'))
        self.assertIsNotNone(account.get('user', 'firstname'))
        self.assertIsNotNone(account.get('user', 'lastname'))
        self.assertIsNotNone(account.get('user', 'companyname'))
        self.assertIsNotNone(account.get('user', 'phonenumber'))
        self.assertIsNotNone(account.get('user', 'password'))

        self.assertIsNotNone(account.get('address', 'address'))
        self.assertIsNotNone(account.get('address', 'city'))
        self.assertIsNotNone(account.get('address', 'state'))
        self.assertIsNotNone(account.get('address', 'countrycode'))
        self.assertIsNotNone(account.get('address', 'zipcode'))

        self.assertIsNotNone(account.get('server', 'root_password'))
        self.assertEqual(account.get('server', 'ns1'), 'ns1')
        self.assertEqual(account.get('server', 'ns2'), 'ns2')
        self.assertIsNotNone(account.get('server', 'hostname'))
Beispiel #7
0
class InstallMullvad(object):
    CONFIGURATION_URL = "https://mullvad.net/en/download/config/"
    TESTING_URL = "https://am.i.mullvad.net/json"

    def __init__(self):
        self._browser = StatefulBrowser(user_agent="Firefox")
        self._settings = Settings()
        self._settings.read_settings()

    def _check_vpn(self, setup=False):
        # Check if VPN is active
        response = requests.get(self.TESTING_URL)
        print(response.json())

        # Check if IP's country is Sweden
        if response.json()["country"] == "Sweden":
            print("VPN is active!")
        else:
            if setup:
                print("Error: VPN was not installed!")
            else:
                self.setup_vpn()

    # Automatically sets up VPN with settings from provider
    def setup_vpn(self):
        # Get the necessary files for connecting to the VPN service
        self._download_files()

        # Copy files to OpenVPN folder
        result = os.popen("sudo cp -a ./config-files/. /etc/openvpn/").read()
        print(result)

        os.chdir("/etc/openvpn/")

        # Start OpenVPN connection
        result = os.popen(
            "sudo nohup openvpn --config ./mullvad_se-sto.conf > /dev/null &"
        ).read()
        print(result)

        # Sleep for 10 seconds, so that VPN connection can be established in the
        # mean time
        time.sleep(10)
        self._check_vpn(True)

    # Download configuration files for setting up VPN and extract them
    def _download_files(self):
        # Fill information on website to get right files for openVPN
        self._browser.open(self.CONFIGURATION_URL)
        form = self._browser.select_form()
        form["account_token"] = self._settings.get("user", "accountnumber")
        form["platform"] = "linux"
        form["region"] = "se-sto"
        form["port"] = "0"
        self._browser.session.headers["Referer"] = self._browser.get_url()
        response = self._browser.submit_selected()
        content = response.content

        # Create the folder that will store the configuration files
        result = os.popen("mkdir config-files").read()
        print(result)

        # Download the zip file to the right location
        files_path = "./config-files/config.zip"
        with open(files_path, "wb") as output:
            output.write(content)

        # Unzip files
        zip_file = zipfile.ZipFile(files_path, "r")
        for member in zip_file.namelist():
            filename = os.path.basename(member)
            # Skip directories
            if not filename:
                continue

            # Copy file (taken from zipfile's extract)
            source = zip_file.open(member)
            target = open(os.path.join("./config-files/", filename), "wb")
            with source, target:
                shutil.copyfileobj(source, target)
        # Delete zip file
        os.remove(files_path)