def list_configurations(): """Prints a list of installed OpenVPN configurations.""" lis = Application.get_app('openvpn').app.configs configs = dict() for c in lis: configs[c] = [] # Checks if configuration is installed for a given config_id for app_name in Application.get_supported_apps(): app = Application.get_app(app_name) if not app.strategy == 'openvpn' and app.configure: # configured_list = [c for c in lis if app.find_config(c)] [configs[c].extend([app.strategy]) for c in lis if app.find_config(c)] if len(configs) > 0: # Prints out the list print("List of OpenVPN configurations") for c in sorted(configs): dis = '' for app in configs[c]: dis += '[' + app + ']' print(' %s %s' % (re.sub('_',' ',c), dis)) else: print("No OpenVPN configurations found!") sys.exit()
def parse_conf_file(): """Parses configure file 'pia.conf' using the Parser Class""" pia_section = _Parser("pia") configure_section = _Parser("configure") if getattr(pia_section, "openvpn_auto_login", None): Application.set_option(getattr(props, 'openvpn'), autologin=pia_section.openvpn_auto_login) if getattr(configure_section, "apps", None): for app in configure_section.apps: Application.set_option(getattr(props, app), configure=True) if getattr(configure_section, "hosts", None): props.hosts = configure_section.hosts
def auto_configure(): for config in openvpn.configs: for app_name in Application.get_supported_apps(): app = Application.get_app(app_name) if app.configure: app.config(*getattr(openvpn, config))
def remove_configurations(): for app_name in Application.get_supported_apps(): app = Application.get_app(app_name) if not app.strategy == 'openvpn': # We don't want to delete OpenVPN files! app.remove_configs(openvpn.configs)
def exclude(): ex = props.commandline['exclude'] for e in ex.split(): app = Application.get_app(e) if app and not app.strategy == 'openvpn': app.configure = False
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import os import sys import re from pia import properties, __version__ from pia.applications import Application from pia.properties import props from pia.docopt import docopt # Checks to see which supported applications are installed props.apps = Application.check_apps() # Shortcut for the openvpn app object openvpn = props.openvpn.app def run(): """Main function run from command line""" props.commandline = commandline_interface() tmp_dict = dict([(re.sub('-', '_', x[2:].strip()), props.commandline[x]) for x in props.commandline if not x == 'HOST']).copy() tmp_dict.update({'HOST': props.commandline['HOST']}) props.commandline = tmp_dict if props.commandline['list_configurations']: list_configurations()