Exemple #1
0
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()

    # Make sure we are running as root
    if os.getuid() > 0:
        print('ERROR: You must run this script with administrative privileges!')
        sys.exit(1)

    properties.parse_conf_file()

    if props.commandline['HOST'] or props.hosts:
        custom_hosts()

    try:
        [globals()[name]() for name in props.commandline if not name == 'HOST' and props.commandline[name]]
    except KeyError as e:
        docopt(globals()['commandline_interface'].__doc__, argv=['-h'], version=__version__)
Exemple #2
0
def commandline_interface():
    """
Usage: pia -a [-e STRATEGIES] [HOST [HOST]... ]
       pia -r [HOST [HOST]... ]
       pia -l
       pia -h | --help
       pia --version

Configures PIA VPN Services for Connman, Network Manager, and OpenVPN

Arguments:
  HOST [HOST]...                       A list of host names to configure
                                       (Example: Japan 'US East' Russia)

Options:
  -a, --auto-configure                 Automatically generates configurations
  -r, --remove-configurations          Removes auto-generated configurations
  -l, --list-configurations            Lists known OpenVPN hosts
  -e STRATEGIES, --exclude STRATEGIES  Excludes modifying the configurations of the listed
                                       program. (Example: -e cm,nm)
  -h, --help                           show this help message and exit
  --version                            show program's version number and exit

    """
    args = docopt(commandline_interface.__doc__, version=__version__)
    return args