Exemplo n.º 1
0
def exists_conf_for(server_name, protocol):
    """
    Checks if exists a .ovpn file for the specified server and protocol
    :param server_name: the name of the server
    :param protocol: the protocol to be used
    :return: True if exists, False otherwise
    """
    import os.path
    from bin.vpn_util.openvpn import get_path_to_conf

    conf_filename = get_path_to_conf(server_name, protocol)
    logger.debug("Checking if exists " + conf_filename)

    return os.path.exists(conf_filename)
Exemplo n.º 2
0
def nm_connect(server, protocol, username, password):
    """
    Starts a connection to a particular server through nm
    :param server: the name of the server
    :param protocol: the protocol to be used (an integer between 1 and 0)
    """
    # removing imported vpns
    nm_delete(nm_list_vpn())

    pathToConf = get_path_to_conf(server, protocol)
    connection_name = get_connection_name(server, protocol)

    logger.info('Importing and configuring ' + pathToConf)

    # preparing connection
    nm_import(pathToConf)
    nm_set_credentials(username, connection_name)

    nm_launch(connection_name, password)