Ejemplo n.º 1
0
def _background(oauth, meta, builder, dialog, lets_connect):
    # type: (str, Metadata, Gtk.builder, Any, bool) -> None
    try:
        profiles = list_profiles(oauth, meta.api_base_uri)
        logger.info("There are {} profiles on {}".format(
            len(profiles), meta.api_base_uri))
        if len(profiles) > 1:
            GLib.idle_add(lambda: dialog.hide())
            GLib.idle_add(
                lambda: _select_profile_step(builder=builder,
                                             profiles=profiles,
                                             meta=meta,
                                             oauth=oauth,
                                             lets_connect=lets_connect))
        elif len(profiles) == 1:
            _parse_choice(builder,
                          meta,
                          oauth,
                          profiles[0],
                          lets_connect=lets_connect)
        else:
            raise EduvpnException(
                "Either there are no VPN profiles defined, or this account does not have the "
                "required permissions to create a new VPN configurations for any of the "
                "available profiles.")

    except Exception as e:
        error = str(e)
        GLib.idle_add(
            lambda: error_helper(dialog, "Can't fetch profile list", error))
        GLib.idle_add(lambda: dialog.hide())
        raise
Ejemplo n.º 2
0
def _background(oauth, meta, builder, dialog):
    try:
        profiles = list_profiles(oauth, meta.api_base_uri)
        logger.info("There are {} profiles on {}".format(len(profiles), meta.api_base_uri))
        if len(profiles) > 1:
            GLib.idle_add(lambda: dialog.hide())
            GLib.idle_add(lambda: select_profile_step(builder=builder, profiles=profiles, meta=meta, oauth=oauth))
        elif len(profiles) == 1:
            meta.profile_display_name, meta.profile_id, meta.two_factor = profiles[0]
            two_auth_step(builder=builder, oauth=oauth, meta=meta)
        else:
            raise EduvpnException("Either there are no VPN profiles defined, or this account does not have the "
                                  "required permissions to create a new VPN configurations for any of the "
                                  "available profiles.")

    except Exception as e:
        GLib.idle_add(lambda: error_helper(dialog, "Can't fetch profile list", str(e)))
        GLib.idle_add(lambda: dialog.hide())
        raise
Ejemplo n.º 3
0
def get_profile(oauth: OAuth2Session, api_url: str, interactive: bool = False):
    profiles = list_profiles(oauth, api_url)
    if interactive:
        return profile_choice(profiles)
    else:
        return profile_choice(profiles[:1])
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def test_list_profiles(self):
     list_profiles(oauth=self.oauth, api_base_uri='http://test')