def activate_connection( meta, builder, verifier, lets_connect): # type: (Metadata, Gtk.builder, str, bool) -> None """do the actual connecting action""" logger.info("Connecting to {}".format(meta.display_name)) disconnect_all() _, name = get_brand(lets_connect) notification = init_notify(lets_connect) notify(notification, "{} connecting...".format(name), "Connecting to '{}'".format(meta.display_name)) try: if not meta.token: logger.error("metadata for {} doesn't contain oauth2 token".format( meta.uuid)) connect_provider(meta.uuid) else: oauth = oauth_from_token(meta=meta, lets_connect=lets_connect) thread_helper(lambda: _auth_check( oauth, meta, verifier, builder, lets_connect=lets_connect)) except Exception as e: switch = builder.get_object('connect-switch') GLib.idle_add(switch.set_active, False) window = builder.get_object('eduvpn-window') error_helper(window, "can't enable connection", "{}: {}".format(type(e).__name__, str(e))) raise
def _parse_user_input(builder, oauth, meta, config_dict, lets_connect): dialog = builder.get_object('yubi-enroll-dialog') code_entry = builder.get_object('yubi-code-entry') cancel_button = builder.get_object('yubi-cancel-button') submit_button = builder.get_object('yubi-submit-button') def callback(_, event): valid = chr(event.keyval).isdigit() logger.debug("user pressed {}, valid: {}".format(event.keyval, valid)) if event.keyval in (Gdk.KEY_Left, Gdk.KEY_Right, Gdk.KEY_BackSpace, Gdk.KEY_End, Gdk.KEY_Home, Gdk.KEY_Delete, Gdk.KEY_Return, Gdk.KEY_Escape): return False return event.keyval not in range(0x20, 0x7e) code_entry.connect("key-press-event", callback) cancel_button.set_sensitive(True) submit_button.set_sensitive(True) while True: response = dialog.run() if response == 0: key = code_entry.get_text() cancel_button.set_sensitive(False) submit_button.set_sensitive(False) thread_helper(lambda: _enroll(builder, oauth, meta, config_dict, key, lets_connect=lets_connect)) else: dialog.hide() break
def browser_step(builder, meta, verifier, lets_connect, force_token_refresh=False): # type: (Gtk.builder, Metadata, str, bool, Optional[bool]) -> None """The notorious browser step. if no token, starts webserver, wait for callback, show token dialog""" logger.info("opening token dialog") dialog = builder.get_object('token-dialog') thread_helper(lambda: _phase1_background(meta=meta, dialog=dialog, verifier=verifier, builder=builder, force_token_refresh=force_token_refresh, lets_connect=lets_connect)) dialog.show_all()
def fetch_profile_step(builder, meta, oauth): """background action step, fetches profiles and shows 'fetching' screen""" logger.info("fetching profile step") dialog = builder.get_object('fetch-dialog') dialog.show_all() thread_helper(lambda: _background(oauth, meta, builder, dialog))
def fetch_instance_step(meta, builder, verifier, lets_connect): # type: (Metadata, Gtk.builder, str, bool) -> None """fetch list of instances""" logger.info("fetching instances step") fetching_window(builder=builder, lets_connect=lets_connect) dialog = builder.get_object('fetch-dialog') thread_helper(lambda: _fetch_background(meta=meta, verifier=verifier, builder=builder, lets_connect=lets_connect)) dialog.run()
def fetch_messages(meta, builder, verifier, lets_connect): logger.info("fetching user and system messages from {} ({})".format( meta.display_name, meta.api_base_uri)) thread_helper(lambda: _background(meta=meta, builder=builder, verifier=verifier, lets_connect=lets_connect))
def browser_step(builder, meta, verifier): """The notorious browser step. if no token, starts webserver, wait for callback, show token dialog""" logger.info("opening token dialog") dialog = builder.get_object('token-dialog') thread_helper(lambda: _phase1_background( meta=meta, dialog=dialog, verifier=verifier, builder=builder)) dialog.show_all()
def finalizing_step(builder, oauth, meta): """finalise the add profile flow, add a configuration""" logger.info("finalizing step") dialog = builder.get_object('fetch-dialog') dialog.show_all() thread_helper(lambda: _background( meta=meta, oauth=oauth, dialog=dialog, builder=builder))
def two_auth_step(builder, oauth, meta, config_dict, lets_connect): """checks if 2auth is enabled. If more than 1 option presents user with choice""" thread_helper(lambda: _background(meta, oauth, builder, config_dict=config_dict, lets_connect=lets_connect))
def _parse_user_input(builder, oauth, meta, config_dict, lets_connect, secret=None): # type: (Gtk.builder, str, Metadata, dict, bool, str) -> None dialog = builder.get_object('totp-enroll-dialog') code_entry = builder.get_object('totp-code-entry') cancel_button = builder.get_object('totp-cancel-button') submit_button = builder.get_object('totp-submit-button') def callback(_, event): valid = chr(event.keyval).isdigit() logger.debug(u"user pressed {}, valid: {}".format(event.keyval, valid)) if event.keyval in (Gdk.KEY_Left, Gdk.KEY_Right, Gdk.KEY_BackSpace, Gdk.KEY_End, Gdk.KEY_Home, Gdk.KEY_Delete, Gdk.KEY_Return, Gdk.KEY_Escape): return False return not chr(event.keyval).isdigit() code_entry.connect("key-press-event", callback) code_entry.set_max_length(6) cancel_button.set_sensitive(True) submit_button.set_sensitive(True) while True: response = dialog.run() if response == 0: key = code_entry.get_text() cancel_button.set_sensitive(False) submit_button.set_sensitive(False) thread_helper(lambda: _enroll(builder, oauth, meta, config_dict, secret, key, lets_connect)) else: dialog.hide() break
def fetch_instance_step(meta, builder, verifier): """fetch list of instances""" logger.info("fetching instances step") dialog = builder.get_object('fetch-dialog') dialog.show_all() thread_helper(lambda: _fetch_background( dialog=dialog, meta=meta, verifier=verifier, builder=builder))
def fetch_messages(meta, builder, verifier, lets_connect): # type: (Metadata, Gtk.builder, str, bool) -> None logger.info(u"fetching user and system messages from {} ({})".format( meta.display_name, meta.api_base_uri)) thread_helper(lambda: _background(meta=meta, builder=builder, verifier=verifier, lets_connect=lets_connect))
def finalizing_step(builder, meta, config_dict, lets_connect): """finalise the add profile flow, add a configuration""" logger.info("finalizing step") fetching_window(builder=builder, lets_connect=lets_connect) dialog = builder.get_object('fetch-dialog') thread_helper(lambda: _background(meta=meta, dialog=dialog, builder=builder, config_dict=config_dict, lets_connect=lets_connect)) dialog.run()
def parse_config_step(builder, oauth, meta, lets_connect): # type : (Gtk.Builder, oauth, Metadata, bool) -> None """parse the config and see if action is still required, otherwise finalize""" logger.info("parse config step") fetching_window(builder=builder, lets_connect=lets_connect) dialog = builder.get_object('fetch-dialog') thread_helper(lambda: _background(meta=meta, oauth=oauth, dialog=dialog, builder=builder, lets_connect=lets_connect)) dialog.run()
def _phase1_callback(meta, port, code_verifier, oauth, auth_url, dialog, builder): thread_helper(lambda: _phase2_background(meta=meta, port=port, oauth=oauth, code_verifier=code_verifier, auth_url=auth_url, dialog=dialog, builder=builder)) _show_dialog(dialog, auth_url, builder)
def _phase1_callback(meta, port, code_verifier, oauth, auth_url, dialog, builder, state, lets_connect): # type: (Metadata, int, str, str, str, Any, Gtk.builder, str, bool) -> None thread_helper(lambda: _phase2_background(meta=meta, port=port, oauth=oauth, code_verifier=code_verifier, auth_url=auth_url, dialog=dialog, builder=builder, state=state, lets_connect=lets_connect)) _show_dialog(dialog, auth_url, builder)
def fetch_profile_step(builder, meta, oauth, lets_connect): # type : (Gtk.Builder, Metadata, oauth, bool) -> None """background action step, fetches profiles and shows 'fetching' screen""" logger.info("fetching profile step") if meta.profile_id: logger.info("we already selected the profile in the past, not presenting user with choice again") parse_config_step(builder=builder, oauth=oauth, meta=meta, lets_connect=lets_connect) return fetching_window(builder=builder, lets_connect=lets_connect) dialog = builder.get_object('fetch-dialog') thread_helper(lambda: _background(oauth, meta, builder, dialog, lets_connect=lets_connect)) dialog.run()
def test_thread_helper(self): thread_helper(lambda: [])
def two_auth_step(builder, oauth, meta): """checks if 2auth is enabled. If more than 1 option presents user with choice""" thread_helper(lambda: background(meta, oauth, builder))