Exemplo n.º 1
0
    def get_value_from_sample(key, sample_path=None):
        """Get suggestion from sample config."""
        fallback_path = None
        fallback_defaults = None

        if sample_path is None:
            container = _helper.sanitize_path(
                os.path.dirname(os.path.realpath(__file__)))
            sample_path = container + '/sovpn.json'
            fallback_path = sample_path
            override = container + 'local/'

            if not os.path.isdir(override):
                override = None

            if override and os.path.isfile(override + '/sovpn.json'):
                sample_path = override + '/sovpn.json'

        sample = _helper.read_file_as_value(sample_path)
        defaults = json.loads(sample)

        if fallback_path:
            fallback = _helper.read_file_as_value(fallback_path)
            fallback_defaults = json.loads(fallback)

        if key in defaults['server']:
            return defaults['server'][key]

        if fallback_defaults:
            if key in fallback_defaults['server']:
                return fallback_defaults['server'][key]

        return None
    def __init__(self):
        """Initialises SimplifiedOpenvpnShare class."""
        self.container = _helper.sanitize_path(
            os.path.dirname(os.path.realpath(__file__)))
        self.override = self.container + 'local/'

        if not os.path.isdir(self.override):
            self.override = None
Exemplo n.º 3
0
 def clients_dir(sample_path=None):
     # pylint: disable=E0602
     """Getting suggestion for clients_dir."""
     suggestion = __class__.get_value_from_sample(_helper.current_method(),
                                                  sample_path)
     if suggestion is None:
         suggestion = _helper.sanitize_path(
             os.path.expanduser('~')) + 'openvpn-clients'
     return suggestion
    def __init__(self):
        """Loads config if possible, else asks you to generate config."""
        self.container = _helper.sanitize_path(
            os.path.dirname(os.path.realpath(__file__)))
        self._config = SimplifiedOpenvpnConfig()

        # EasyRSA 2 requires loading environment variables manually.
        if self._config.easy_rsa_ver == 2:
            self.load_env()
Exemplo n.º 5
0
    def __init__(self, run_setup=True):
        """Loads config if possible, else asks you to generate config."""
        self.container = _helper.sanitize_path(
            os.path.dirname(os.path.realpath(__file__)))
        self.override = self.container + 'local/'
        self.loaded = False
        self.needs_rotation = False

        if self.needs_setup():
            if run_setup:
                self.setup()
        else:
            self.load()
Exemplo n.º 6
0
    def needs_setup():
        """Check if the script needs to run initial setup."""
        container = _helper.sanitize_path(
            os.path.dirname(os.path.realpath(__file__)))
        sovpn_config_pointer = container + 'sovpn_config_pointer.txt'

        if not os.path.isfile(sovpn_config_pointer):
            return True

        sovpn_config_file = _helper.read_file_as_value(sovpn_config_pointer)

        if os.path.isfile(sovpn_config_file):
            return False

        return True
Exemplo n.º 7
0
    def easy_rsa_dir(self, value):
        """Assings new value to easy_rsa_dir property if possible."""
        if value is None:
            self.settings['server']['easy_rsa_dir'] = None
            return

        status = os.path.isdir(value)

        if not status:
            print(
                "Value that you specified as directory for Easy RSA is invalid: ("
                + value + ")")
            print(
                'Make sure that the value you gave meets following requirements:'
            )
            print('> Does the directory really exist in your filesystem?')
            print(
                '> The specified directory has write and execute permissions.')
        else:
            self.settings['server']['easy_rsa_dir'] = _helper.sanitize_path(
                value)
Exemplo n.º 8
0
 def client_dir(self, create=True):
     """Assigns new value to client_dir property and creates directory for it if needed."""
     value = self.clients_dir + self.slug
     if create:
         _helper.create_directory(value)
     self.settings['client']['client_dir'] = _helper.sanitize_path(value)