Example #1
0
def parse_conf_file():
    """Parses configure file 'pia.conf' using the Parser Class"""

    try:
        pia_section = _Parser("pia")
        props.conf_section['pia'] = pia_section

    except configparser.NoSectionError:
        pia_section = None
        logger.debug("Reading configuration file error. No %s" % 'pia')
        pass

    try:
        configure_section = _Parser("configure")
        props.conf_section['configure'] = configure_section
    except configparser.NoSectionError:
        configure_section = None
        logger.debug("Reading configuration file error. No %s" % 'configure')

    if pia_section:
        appstrategy.set_option(getattr(props, 'openvpn'), autologin=getattr(pia_section, "openvpn_auto_login", False))
        props.strong_encryption = getattr(pia_section, "strong_encryption", False)

    if configure_section:
        [appstrategy.set_option(getattr(props, app_name), configure=False)
         for app_name in appstrategy.get_supported_apps()
         if app_name not in getattr(configure_section, "apps", appstrategy.get_supported_apps())]

        appstrategy.set_option(getattr(props, "openvpn"), configure=True)

        props.hosts = getattr(configure_section, "hosts", "")
        props.port = getattr(configure_section, "port", [props.default_port])[0]
        props.cipher = getattr(configure_section, "cipher", [props.default_cipher])[0]
        props.auth = getattr(configure_section, "auth", [props.default_auth])[0]
Example #2
0
def list_configurations():
    """Prints a list of installed OpenVPN configurations."""
    lis = properties.get_default_hosts_list(names_only=True)
    configs = dict()

    # Checks if configuration is installed for a given config_id
    for c in sorted(lis):
        config = {'host': re.sub('_', ' ', c), 'openvpn': '', 'apps': ''}

        for app_name in appstrategy.get_supported_apps():
            app = appstrategy.get_app(app_name)
            if app.configure and app.find_config(c):
                logger.debug('Configuring %s for %s' % (c, app.strategy))
                if app_name == 'openvpn':
                    config['openvpn'] = '*'
                else:
                    config['apps'] += '[' + app_name + ']'
        configs[c] = config

    print("List of OpenVPN configurations")
    for c in configs:
        if configs[c]['openvpn']:
            print('  {openvpn} {host} {apps}'.format(**configs[c]))
        else:
            print('    {host} {apps}'.format(**configs[c]))
    sys.exit()
Example #3
0
def list_configurations():
    """Prints a list of installed OpenVPN configurations."""
    lis = properties.get_default_hosts_list(names_only=True)
    configs = dict()

    # Checks if configuration is installed for a given config_id
    for c in sorted(lis):
        config = {'host': re.sub('_', ' ', c), 'openvpn': '', 'apps': ''}

        for app_name in appstrategy.get_supported_apps():
            app = appstrategy.get_app(app_name)
            if app.configure and app.find_config(c):
                logger.debug('Configuring %s for %s' % (c, app.strategy))
                if app_name == 'openvpn':
                    config['openvpn'] = '*'
                else:
                    config['apps'] += '[' + app_name + ']'
        configs[c] = config

        print("List of OpenVPN configurations")
    for c in configs:
        if configs[c]['openvpn']:
            print('  {openvpn} {host} {apps}'.format(**configs[c]))
        else:
            print('    {host} {apps}'.format(**configs[c]))
    sys.exit()
Example #4
0
def auto_configure():
    """Auto configures applications"""
    for config in properties.props.hosts:
        for app_name in appstrategy.get_supported_apps():
            app = appstrategy.get_app(app_name)
            if app.configure:
                logger.debug("Configuring configurations for %s" % app_name)
                app.config(config)
Example #5
0
def auto_configure():
    """Auto configures applications"""
    for config in properties.props.hosts:
        for app_name in appstrategy.get_supported_apps():
            app = appstrategy.get_app(app_name)
            if app.configure:
                logger.debug("Configuring configurations for %s" % app_name)
                app.config(config)
Example #6
0
def parse_conf_file():
    """Parses configure file 'pia.conf' using the Parser Class"""

    try:
        pia_section = _Parser("pia")
        props.conf_section['pia'] = pia_section

    except configparser.NoSectionError:
        pia_section = None
        logger.debug("Reading configuration file error. No %s" % 'pia')
        pass

    try:
        configure_section = _Parser("configure")
        props.conf_section['configure'] = configure_section
    except configparser.NoSectionError:
        configure_section = None
        logger.debug("Reading configuration file error. No %s" % 'configure')

    if pia_section:
        appstrategy.set_option(getattr(props, 'openvpn'),
                               autologin=getattr(pia_section,
                                                 "openvpn_auto_login", False))
        props.strong_encryption = getattr(pia_section, "strong_encryption",
                                          False)

    if configure_section:
        [
            appstrategy.set_option(getattr(props, app_name), configure=False)
            for app_name in appstrategy.get_supported_apps()
            if app_name not in getattr(configure_section, "apps",
                                       appstrategy.get_supported_apps())
        ]

        appstrategy.set_option(getattr(props, "openvpn"), configure=True)

        props.hosts = getattr(configure_section, "hosts", "")
        props.port = getattr(configure_section, "port",
                             [props.default_port])[0]
        props.dev = getattr(configure_section, "dev", [props.default_dev])[0]
Example #7
0
def remove_configurations():
    """Removes configurations based on openvpn.configs"""
    logger.debug("Removing configurations!")
    for app_name in appstrategy.get_supported_apps():
        app = appstrategy.get_app(app_name)
        app.remove_configs()
Example #8
0
def remove_configurations():
    """Removes configurations based on openvpn.configs"""
    logger.debug("Removing configurations!")
    for app_name in appstrategy.get_supported_apps():
        app = appstrategy.get_app(app_name)
        app.remove_configs()