Exemplo n.º 1
0
def interactive(
    args: Namespace
) -> Tuple[str, str, Optional[str], Optional[ServerListType]]:
    """
    returns:
        auth_url, display_name, support_contact, secure_internets
    """
    search_term = args.match

    if isinstance(search_term,
                  str) and search_term.lower().startswith('https://'):
        return search_term, search_term, None, None

    servers = list_servers(SERVER_URI)
    secure_internets = [
        s for s in servers if s['server_type'] == 'secure_internet'
    ]
    institute_access = [
        s for s in servers if s['server_type'] == 'institute_access'
    ]
    orgs = list_organisations(ORGANISATION_URI)
    choice = menu(institutes=institute_access,
                  orgs=orgs,
                  search_term=search_term)

    if not choice:
        exit(1)

    auth_url, display_name, support_contact, secure_internet = choice
    if not secure_internet:
        return auth_url, display_name, support_contact, None

    return auth_url, display_name, support_contact, secure_internets
Exemplo n.º 2
0
    def __init__(self, lets_connect: bool = False):
        self.uuid: Optional[str] = ""
        if lets_connect:
            self.servers = []
        else:
            self.servers = list_servers(SERVER_URI)
        self.secure_internet = [
            s for s in self.servers if s['server_type'] == 'secure_internet'
        ]
        self.institute_access = [
            s for s in self.servers if s['server_type'] == 'institute_access'
        ]

        if lets_connect:
            self.organisations = []
        else:
            self.organisations = list_organisations(ORGANISATION_URI)

        self.profiles: dict = {}
        self.locations: list = []
        self.secure_internet_home: str = ""
        self.oauth: OAuth2Session
        self.new_server_name: str = ""
        self.new_server_image = None
        self.new_support_contact: List[str] = []
        self.connection_state = NM.VpnConnectionState.UNKNOWN
        self.vpn_connection: VpnConnection = VpnConnection()
Exemplo n.º 3
0
    def update(self):
        """
        Download the list of institute and secure internet servers,
        and update this database.

        This method must be thread-safe.
        """
        new_servers = []
        server_list = remote.list_servers(SERVER_URI)
        organisation_list = remote.list_organisations(ORGANISATION_URI)
        for server_data in server_list:
            server_type = server_data.pop('server_type')
            if server_type == 'institute_access':
                server = InstituteAccessServer(**server_data)
                new_servers.append(server)
            elif server_type == 'secure_internet':
                server = SecureInternetServer(**server_data)
                new_servers.append(server)
            else:
                raise ValueError(server_type, server_data)
        for organisation_data in organisation_list:
            server = OrganisationServer(**organisation_data)
            new_servers.append(server)
        # Atomic update of server map.
        # TODO keep custom other servers
        self.servers = new_servers
        self.is_loaded = True
Exemplo n.º 4
0
def fetch_servers_orgs() -> Tuple[ServerListType, ServerListType]:
    servers = list_servers(SERVER_URI)
    orgs = list_organisations(ORGANISATION_URI)
    return servers, orgs
Exemplo n.º 5
0
def main():
    logging.basicConfig(level=logging.INFO)
    search_term = parse_args()

    verifier = make_verifier(Ed25519_PUBLIC_KEY)

    if isinstance(search_term,
                  str) and search_term.lower().startswith('https://'):
        base_url = search_term
        info_url = base_url
    else:
        servers = list_servers(SERVER_URI, verifier=verifier)
        secure_internet = [
            s for s in servers if s['server_type'] == 'secure_internet'
        ]
        institute_access = [
            s for s in servers if s['server_type'] == 'institute_access'
        ]
        orgs = list_orgs(ORGANISATION_URI, verifier=verifier)
        choice = menu(institutes=institute_access,
                      orgs=orgs,
                      search_term=search_term)

        if not choice:
            exit(1)

        type_, base_url = choice

        if type_ == 'secure_internet_home':
            secure_internets = [
                s for s in secure_internet if s['base_url'] == base_url
            ]
            info_url = secure_internet_choice(secure_internets)
        else:
            info_url = base_url

    exists = get_entry(base_url)

    if exists:
        token, api_base_uri, token_endpoint, authorization_endpoint = exists
        oauth = OAuth2Session(client_id=CLIENT_ID,
                              token=token,
                              auto_refresh_url=token_endpoint)
    else:
        api_base_uri, token_endpoint, auth_endpoint = get_info(
            info_url, verifier)
        oauth = get_oauth(token_endpoint, auth_endpoint)
        set_entry(base_url, oauth.token, api_base_uri, token_endpoint,
                  auth_endpoint)

    oauth.refresh_token(token_url=token_endpoint)
    profiles = list_profiles(oauth, api_base_uri)
    profile_id = profile_choice(profiles)
    config = get_config(oauth, api_base_uri, profile_id)
    private_key, certificate = create_keypair(oauth, api_base_uri)

    if write_to_nm_choice():
        save_connection(config, private_key, certificate)
    else:
        target = Path('eduVPN.ovpn').resolve()
        print(f"Writing configuration to {target}")
        write_config(config, private_key, certificate, target)