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 refresh_start(builder, lets_connect): # type: (Gtk.builder, bool) -> None logger.info(u"composing list of current eduVPN configurations") config_list = builder.get_object('configs-model') introduction = builder.get_object('introduction') main_image = builder.get_object('main_image') window = builder.get_object('eduvpn-window') logo, name = get_brand(lets_connect) main_image.set_from_file(logo) window.set_title("{} Configuration Manager".format(name)) config_list.clear() providers = list(list_providers()) providers.sort(key=lambda x: x.display_name) if len(providers) > 0: logger.info(u"hiding introduction") introduction.hide() for meta in providers: connection_type = u"<b>{}</b>\n{}\n<small><i>{}</i></small>".format(meta.display_name, meta.connection_type, meta.profile_display_name) if meta.icon_data: icon = bytes2pixbuf(base64.b64decode(meta.icon_data.encode())) else: icon, _ = get_pixbuf(logo) config_list.append((meta.uuid, meta.display_name, icon, connection_type)) else: logger.info(u"showing introduction") introduction.show()
def init_notify(lets_connect): # type: (bool) -> Notify icon, name = get_brand(lets_connect) Notify.init(name + " client") image_path = path.join(icon) image = GdkPixbuf.Pixbuf.new_from_file(image_path) notification = Notify.Notification.new(name) notification.set_icon_from_pixbuf(image) notification.set_app_name(name) return notification
def do_GET(self): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() logo, name = get_brand(lets_connect) logo = stringify_image(logo) content = landing_page.format(logo=logo, brand=name).encode('utf-8') self.wfile.write(content) self.server.path = self.path
def fetching_window(builder, lets_connect): # type: (Gtk.builder, bool) -> None """Don't forget to call dialog.run() after creating the fetch window!""" logger.info("fetching instances step") dialog = builder.get_object('fetch-dialog') image = builder.get_object('fetch-image') window = builder.get_object('eduvpn-window') dialog.set_transient_for(window) icon, _ = get_brand(lets_connect) image.set_from_file(icon) dialog.show_all()
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