def delete_profile(builder, lets_connect): # type: (Gtk.builder, bool) -> None """called when the user presses the - button""" logger.info("delete provider clicked") meta = metadata_of_selected(builder) if not meta: logger.info("nothing selected") return window = builder.get_object('eduvpn-window') dialog = Gtk.MessageDialog( window, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, "Are you sure you want to remove '{}'?".format(meta.display_name)) dialog.format_secondary_text("This action can't be undone.") response = dialog.run() if response == Gtk.ResponseType.YES: logger.info("deleting provider config") try: delete_provider(meta.uuid) notification = init_notify(lets_connect) notify(notification, "eduVPN provider deleted", "Deleted '{}'".format(meta.display_name)) except Exception as e: error_helper(window, "can't delete profile", str(e)) dialog.hide() raise GLib.idle_add( lambda: refresh_start(builder, lets_connect=lets_connect)) elif response == Gtk.ResponseType.NO: logger.info("not deleting provider config") dialog.hide()
def delete_profile(builder): """called when the user presses the - button""" logger.info("delete provider clicked") meta = metadata_of_selected(builder) if not meta: logger.info("nothing selected") return window = builder.get_object('eduvpn-window') dialog = Gtk.MessageDialog( window, Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "Are you sure you want to remove '{}'?".format(meta.display_name)) dialog.format_secondary_text("This action can't be undone.") response = dialog.run() if response == Gtk.ResponseType.YES: logger.info("deleting provider config") try: delete_provider(meta.uuid) notify("eduVPN provider deleted", "Deleted '{}'".format(meta.display_name)) except Exception as e: error_helper(window, "can't delete profile", str(e)) dialog.destroy() raise GLib.idle_add(lambda: update_providers(builder)) elif response == Gtk.ResponseType.NO: logger.info("not deleting provider config") dialog.destroy()
def vpn_change(builder, lets_connect, state=0, reason=0): # type: (Gtk.builder, bool, Optional[int], Optional[int]) -> None logger.info(u"VPN status change") switch = builder.get_object('connect-switch') ipv4_label = builder.get_object('ipv4-label') ipv6_label = builder.get_object('ipv6-label') # get the currently selected uuid meta = metadata_of_selected(builder=builder) if not meta: logger.info(u"VPN status changed but no profile selected") return notification = init_notify(lets_connect) selected_uuid_active = False for active in list_active(): try: if active.Uuid == meta.uuid: selected_uuid_active = True if active.State == 2: # activated logger.info(u"setting ip for {}".format(meta.uuid)) logger.info(u"setting switch ON") switch.set_active(True) GLib.idle_add(lambda: ipv4_label.set_text( active.Ip4Config.AddressData[0]['address'])) GLib.idle_add(lambda: ipv6_label.set_text( active.Ip6Config.AddressData[0]['address'])) notify(notification, u"eduVPN connected", u"Connected to '{}'".format(meta.display_name)) elif active.State == 1: # activating logger.info(u"setting switch ON") switch.set_active(True) notify(notification, u"eduVPN connecting...", u"Activating '{}'".format(meta.display_name)) else: logger.info(u"clearing ip for '{}'".format(meta.uuid)) logger.info(u"setting switch OFF") switch.set_active(False) GLib.idle_add(lambda: ipv4_label.set_text("")) GLib.idle_add(lambda: ipv6_label.set_text("")) break except Exception as e: logger.warning( u"probably race condition in network manager: {}".format(e)) raise if not selected_uuid_active: logger.info(u"Our selected profile not active {}".format(meta.uuid)) notify(notification, u"eduVPN Disconnected", u"Disconnected from '{}'".format(meta.display_name)) logger.info(u"setting switch OFF") switch.set_active(False) GLib.idle_add(lambda: ipv4_label.set_text("-")) GLib.idle_add(lambda: ipv6_label.set_text("-"))
def select_profile(builder, verifier): """called when a users selects a configuration""" notebook = builder.get_object('outer-notebook') switch = builder.get_object('connect-switch') ipv4_label = builder.get_object('ipv4-label') ipv6_label = builder.get_object('ipv6-label') twofa_label = builder.get_object('2fa-label') twofa_label_label = builder.get_object('2fa-label-label') name_label = builder.get_object('name-label') profile_label = builder.get_object('profile-label') profile_image = builder.get_object('profile-image') meta = metadata_of_selected(builder) if not meta: logger.info("no configuration selected, showing main logo") notebook.set_current_page(0) return else: logger.info("configuration was selected {} ({})".format( meta.display_name, meta.uuid)) name_label.set_text(meta.display_name) if meta.icon_data: icon = bytes2pixbuf(base64.b64decode(meta.icon_data.encode()), width=icon_size['width'] * 2, height=icon_size['height'] * 2) else: _, icon = get_pixbuf() profile_image.set_from_pixbuf(icon) profile_label.set_text(meta.connection_type) connected = is_provider_connected(uuid=meta.uuid) switch.set_state(bool(connected)) if connected: ipv4, ipv6 = connected ipv4_label.set_text(ipv4) ipv6_label.set_text(ipv6) else: ipv4_label.set_text("") ipv6_label.set_text("") if meta.username: twofa_label.set_text(meta.username) twofa_label_label.set_text("2FA:") else: twofa_label.set_text("") twofa_label_label.set_text("") notebook.show_all() notebook.set_current_page(1) if meta.token: fetch_messages(meta=meta, builder=builder, verifier=verifier) else: logger.warning("no token available so net fetching messages") return meta
def vpn_change(builder): logger.info("VPN status change") switch = builder.get_object('connect-switch') ipv4_label = builder.get_object('ipv4-label') ipv6_label = builder.get_object('ipv6-label') # get the currently selected uuid meta = metadata_of_selected(builder=builder) selected_uuid_active = False for active in active_connections(): try: if active.Uuid == meta.uuid: selected_uuid_active = True if active.State == 2: # activated logger.info("setting ip for {}".format(meta.uuid)) logger.info("setting switch ON") switch.set_active(True) GLib.idle_add(lambda: ipv4_label.set_text( active.Ip4Config.AddressData[0]['address'])) GLib.idle_add(lambda: ipv6_label.set_text( active.Ip6Config.AddressData[0]['address'])) notify("eduVPN connected", "Connected to '{}'".format(meta.display_name)) elif active.State == 1: # activating logger.info("setting switch ON") switch.set_active(True) notify("eduVPN connecting...", "Activating '{}'".format(meta.display_name)) else: logger.info("clearing ip for '{}'".format(meta.uuid)) logger.info("setting switch OFF") switch.set_active(False) GLib.idle_add(lambda: ipv4_label.set_text("")) GLib.idle_add(lambda: ipv6_label.set_text("")) break except Exception as e: logger.warning( "probably race condition in network manager: {}".format(e)) pass if not selected_uuid_active: logger.info("Our selected profile not active {}".format(meta.uuid)) notify("eduVPN Disconnected", "Disconnected from '{}'".format(meta.display_name)) logger.info("setting switch OFF") switch.set_active(False) GLib.idle_add(lambda: ipv4_label.set_text("")) GLib.idle_add(lambda: ipv6_label.set_text(""))
def select_profile( builder, verifier, lets_connect): # type: (Gtk.builder, str, bool) -> Optional[Metadata] """called when a users selects a configuration""" messages_label = builder.get_object('messages-label') notebook = builder.get_object('outer-notebook') switch = builder.get_object('connect-switch') ipv4_label = builder.get_object('ipv4-label') ipv6_label = builder.get_object('ipv6-label') note_label = builder.get_object('note-label') note_label_label = builder.get_object('note-label-label') twofa_label = builder.get_object('2fa-label') twofa_label_label = builder.get_object('2fa-label-label') name_label = builder.get_object('name-label') profile_label = builder.get_object('profile-label') profile_name_label = builder.get_object('profile-name-label') profile_image = builder.get_object('profile-image') meta = metadata_of_selected(builder) logo, _ = get_brand(lets_connect) if not meta: logger.info(u"no configuration selected, showing main logo") notebook.set_current_page(0) return None else: logger.info(u"configuration was selected {} ({})".format( meta.display_name, meta.uuid)) name_label.set_text(meta.display_name) if meta.icon_data: icon = bytes2pixbuf(base64.b64decode(meta.icon_data.encode()), width=icon_size['width'] * 2, height=icon_size['height'] * 2) else: _, icon = get_pixbuf(logo) profile_image.set_from_pixbuf(icon) profile_label.set_text(meta.connection_type) profile_name_label.set_text(meta.profile_display_name) connected = is_provider_connected(uuid=meta.uuid) switch.set_state(bool(connected)) if connected: ipv4, ipv6 = connected ipv4_label.set_text(ipv4) ipv6_label.set_text(ipv6) else: ipv4_label.set_text("-") ipv6_label.set_text("-") if meta.username: twofa_label.set_text(meta.username) twofa_label_label.set_text("2FA:") else: twofa_label.set_text("") twofa_label_label.set_text("") note_label.set_text("") note_label_label.set_text("") notebook.show_all() notebook.set_current_page(1) messages_label.set_markup("") if meta.token: fetch_messages(meta=meta, builder=builder, verifier=verifier, lets_connect=lets_connect) else: logger.warning(u"no token available so not fetching messages") messages_label.set_markup( "<b><big>Warning</big></b>\nno token available so not fetching messages." ) return meta
def select_profile(builder, verifier, lets_connect): # type : (Gtk.Builder, verifier, bool) -> Optional[Metadata] """called when a users selects a configuration""" messages_label = builder.get_object('messages-label') notebook = builder.get_object('outer-notebook') switch = builder.get_object('connect-switch') ipv4_label = builder.get_object('ipv4-label') ipv6_label = builder.get_object('ipv6-label') note_label = builder.get_object('note-label') note_label_label = builder.get_object('note-label-label') twofa_label = builder.get_object('2fa-label') twofa_label_label = builder.get_object('2fa-label-label') name_label = builder.get_object('name-label') profile_label = builder.get_object('profile-label') profile_name_label = builder.get_object('profile-name-label') profile_image = builder.get_object('profile-image') meta = metadata_of_selected(builder) logo, _ = get_brand(lets_connect) if not meta: logger.info("no configuration selected, showing main logo") notebook.set_current_page(0) return else: logger.info("configuration was selected {} ({})".format( meta.display_name, meta.uuid)) name_label.set_text(meta.display_name) if meta.icon_data: icon = bytes2pixbuf(base64.b64decode(meta.icon_data.encode()), width=icon_size['width'] * 2, height=icon_size['height'] * 2) else: _, icon = get_pixbuf(logo) profile_image.set_from_pixbuf(icon) profile_label.set_text(meta.connection_type) profile_name_label.set_text(meta.profile_display_name) connected = is_provider_connected(uuid=meta.uuid) switch.set_state(bool(connected)) if connected: ipv4, ipv6 = connected ipv4_label.set_text(ipv4) ipv6_label.set_text(ipv6) else: ipv4_label.set_text("-") ipv6_label.set_text("-") if meta.username: twofa_label.set_text(meta.username) twofa_label_label.set_text("2FA:") else: twofa_label.set_text("") twofa_label_label.set_text("") if are_we_running_ubuntu1804(): note_label.set_markup( '<a href="https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1754671">Ubuntu 18.04 Leaks DNS info</a>' ) note_label_label.set_markup( '<span foreground="red">WARNING</span>:') else: note_label.set_text("") note_label_label.set_text("") notebook.show_all() notebook.set_current_page(1) messages_label.set_markup("") if meta.token: fetch_messages(meta=meta, builder=builder, verifier=verifier, lets_connect=lets_connect) else: logger.warning("no token available so not fetching messages") messages_label.set_markup( "<b><big>Warning</big></b>\nno token available so not fetching messages." ) return meta