def setup_dbus(force=True): """ Initialize DBus. """ global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id print("Connecting to daemon...") try: dbusmanager.connect_to_dbus() except DBusException: if force: print(("Can't connect to the daemon, trying to start it " + \ "automatically...")) misc.PromptToStartDaemon() try: dbusmanager.connect_to_dbus() except DBusException: error( None, _("Could not connect to wicd's D-Bus interface. Check " "the wicd log for error messages.")) return False else: return False if lost_dbus_id: gobject.source_remove(lost_dbus_id) lost_dbus_id = None dbus_ifaces = dbusmanager.get_dbus_ifaces() daemon = dbus_ifaces['daemon'] wireless = dbus_ifaces['wireless'] wired = dbus_ifaces['wired'] DBUS_AVAIL = True print("Connected.") return True
def setup_dbus(force=True): """ Initialize DBus. """ global bus, daemon, wireless, wired, DBUS_AVAIL try: dbusmanager.connect_to_dbus() except DBusException: if force: print "Can't connect to the daemon, ' + \ 'trying to start it automatically..." if not misc.PromptToStartDaemon(): print "Failed to find a graphical sudo program, ' + \ 'cannot continue." return False try: dbusmanager.connect_to_dbus() except DBusException: error( None, _("Could not connect to wicd's D-Bus interface. " "Check the wicd log for error messages.")) return False else: return False prefs.setup_dbus() netentry.setup_dbus() bus = dbusmanager.get_bus() dbus_ifaces = dbusmanager.get_dbus_ifaces() daemon = dbus_ifaces['daemon'] wireless = dbus_ifaces['wireless'] wired = dbus_ifaces['wired'] DBUS_AVAIL = True return True
def setup_dbus(force=True): """ Initialize DBus. """ global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id print "Connecting to daemon..." try: dbusmanager.connect_to_dbus() except DBusException: if force: print "Can't connect to the daemon, trying to start it " + \ "automatically..." misc.PromptToStartDaemon() try: dbusmanager.connect_to_dbus() except DBusException: error(None, _("Could not connect to wicd's D-Bus interface. Check " "the wicd log for error messages.") ) return False else: return False if lost_dbus_id: gobject.source_remove(lost_dbus_id) lost_dbus_id = None dbus_ifaces = dbusmanager.get_dbus_ifaces() daemon = dbus_ifaces['daemon'] wireless = dbus_ifaces['wireless'] wired = dbus_ifaces['wired'] DBUS_AVAIL = True print "Connected." return True
def add_profile(self, widget): """ Add a profile to the profile list. """ response = string_input( "Enter a profile name", "The profile name " + "will not be used by the computer. It " + "allows you to " + "easily distinguish between different network " + "profiles.", "Profile name:").strip() # if response is "" or None if not response: error(None, "Invalid profile name", block=True) return False profile_name = response profile_list = wired.GetWiredProfileList() if profile_list: if profile_name in profile_list: return False self.profile_help.hide() wired.CreateWiredNetworkProfile(profile_name, False) self.combo_profile_names.prepend_text(profile_name) self.combo_profile_names.set_active(0) self.advanced_dialog.prof_name = profile_name if self.is_full_gui: self.button_delete.set_sensitive(True) self.connect_button.set_sensitive(True) self.advanced_button.set_sensitive(True)
def add_profile(self, widget): """ Add a profile to the profile list. """ response = string_input("Enter a profile name", "The profile name " + "will not be used by the computer. It " + "allows you to " + "easily distinguish between different network " + "profiles.", "Profile name:").strip() # if response is "" or None if not response: error(None, "Invalid profile name", block=True) return False profile_name = response profile_list = wired.GetWiredProfileList() if profile_list: if profile_name in profile_list: return False self.profile_help.hide() wired.CreateWiredNetworkProfile(profile_name, False) self.combo_profile_names.prepend_text(profile_name) self.combo_profile_names.set_active(0) self.advanced_dialog.prof_name = profile_name if self.is_full_gui: self.button_delete.set_sensitive(True) self.connect_button.set_sensitive(True) self.advanced_button.set_sensitive(True)
def handle_no_dbus(from_tray=False): global DBUS_AVAIL DBUS_AVAIL = False if from_tray: return False print "Wicd daemon is shutting down!" error(None, language['lost_dbus'], block=False) return False
def setup_dbus(force=True): global bus, daemon, wireless, wired, DBUS_AVAIL try: dbusmanager.connect_to_dbus() except DBusException: if force: print "Can't connect to the daemon, trying to start it automatically..." if not misc.PromptToStartDaemon(): print "Failed to find a graphical sudo program, cannot continue." return False try: dbusmanager.connect_to_dbus() except DBusException: error(None, "Could not connect to wicd's D-Bus interface. " + "Check the wicd log for error messages.") return False else: return False prefs.setup_dbus() netentry.setup_dbus() bus = dbusmanager.get_bus() dbus_ifaces = dbusmanager.get_dbus_ifaces() daemon = dbus_ifaces['daemon'] wireless = dbus_ifaces['wireless'] wired = dbus_ifaces['wired'] DBUS_AVAIL = True return True
def handle_no_dbus(from_tray=False): global DBUS_AVAIL DBUS_AVAIL = False if from_tray: return False print "Wicd daemon is shutting down!" error(None, _('The wicd daemon has shut down. The UI will not function properly until it is restarted.'), block=False) return False
def toggle_global_dns_checkbox(self, widget=None): """ Set the DNS entries' sensitivity based on the Global checkbox. """ global_dns_active = daemon.GetUseGlobalDNS() if not global_dns_active and self.chkbox_global_dns.get_active(): error(None, language['global_dns_not_enabled']) self.chkbox_global_dns.set_active(False) if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active(): for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain, self.txt_search_dom]: w.set_sensitive(not self.chkbox_global_dns.get_active())
def toggle_global_dns_checkbox(self, widget=None): """ Set the DNS entries' sensitivity based on the Global checkbox. """ global_dns_active = daemon.GetUseGlobalDNS() if not global_dns_active and self.chkbox_global_dns.get_active(): error(None, _('Global DNS has not been enabled in general preferences.')) self.chkbox_global_dns.set_active(False) if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active(): for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain, self.txt_search_dom]: w.set_sensitive(not self.chkbox_global_dns.get_active())
def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except DBusException, e: if e.get_dbus_name() != None and "DBus.Error.AccessDenied" in e.get_dbus_name(): error(None, _('Unable to contact the Wicd daemon due to an access denied error from DBus. Please check that your user is in the $A group.').replace("$A","<b>"+wpath.wicd_group+"</b>")) #raise raise DBusException(e) else: print "warning: ignoring exception %s" % e return None
def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except DBusException, e: if e.get_dbus_name() != None and "DBus.Error.AccessDenied" in e.get_dbus_name(): error(None, language['access_denied'].replace("$A","<b>"+wpath.wicd_group+"</b>")) #raise raise DBusException(e) else: print "warning: ignoring exception %s" % e return None
def toggle_global_dns_checkbox(self, widget=None): """ Set the DNS entries' sensitivity based on the Global checkbox. """ global_dns_active = daemon.GetUseGlobalDNS() if not global_dns_active and self.chkbox_global_dns.get_active(): error(None, language['global_dns_not_enabled']) self.chkbox_global_dns.set_active(False) if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active(): for w in [ self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain, self.txt_search_dom ]: w.set_sensitive(not self.chkbox_global_dns.get_active())
def handle_no_dbus(from_tray=False): """ Handle the case where no DBus is available. """ global DBUS_AVAIL DBUS_AVAIL = False if from_tray: return False print "Wicd daemon is shutting down!" error(None, _('The wicd daemon has shut down. The UI will not function ' 'properly until it is restarted.'), block=False) return False
def edit_scripts(self, widget=None, event=None): """ Launch the script editting dialog. """ cmdend = [os.path.join(wpath.gtk, "configscript.py"), str(self.networkID), "wireless"] if os.getuid() != 0: cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'], prog_num=daemon.GetSudoApp()) if not cmdbase: error(None, language["no_sudo_prog"]) return cmdbase.extend(cmdend) misc.LaunchAndWait(cmdbase) else: misc.LaunchAndWait(cmdend)
def handle_no_dbus(from_tray=False): """ Handle the case where no DBus is available. """ global DBUS_AVAIL DBUS_AVAIL = False if from_tray: return False print "Wicd daemon is shutting down!" error( None, _('The wicd daemon has shut down. The UI will not function ' 'properly until it is restarted.'), block=False ) return False
def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except DBusException, e: if e.get_dbus_name( ) != None and "DBus.Error.AccessDenied" in e.get_dbus_name(): error( None, language['access_denied'].replace( "$A", "<b>" + wpath.wicd_group + "</b>")) #raise raise DBusException(e) else: print "warning: ignoring exception %s" % e return None
def edit_scripts(self, widget=None, event=None): """ Launch the script editting dialog. """ profile = self.prof_name cmdend = [os.path.join(wpath.gtk, "configscript.py"), profile, "wired"] if os.getuid() != 0: cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'], prog_num=daemon.GetSudoApp()) if not cmdbase: error(None, language["no_sudo_prog"]) return cmdbase.extend(cmdend) misc.LaunchAndWait(cmdbase) else: misc.LaunchAndWait(cmdend)
def set_defaults(self, widget=None, event=None): """ Put some default values into entries to help the user out. """ self.txt_ip.set_text(self.txt_ip.get_text().strip()) ipAddress = self.txt_ip.get_text() # For easy typing :) netmask = self.txt_netmask gateway = self.txt_gateway ip_parts = misc.IsValidIP(ipAddress) if ip_parts: if stringToNone(gateway.get_text()) is None: # Make sure the gateway box is blank # Fill it in with a .1 at the end gateway.set_text('.'.join(ip_parts[0:3]) + '.1') if stringToNone(netmask.get_text()) is None: # Make sure the netmask is blank netmask.set_text('255.255.255.0') # Fill in the most common one elif ipAddress != "": error(None, language['invalid_ip_address'])
def edit_scripts(self, widget=None, event=None): """ Launch the script editting dialog. """ cmdend = [os.path.join(wpath.gtk, "configscript.py"), str(self.networkID), "wireless"] if os.getuid() != 0: cmdbase = misc.get_sudo_cmd(_('You must enter your password to configure scripts'), prog_num=daemon.GetSudoApp()) if not cmdbase: error(None, _('Could not find a graphical sudo program. '\ 'The script editor could not be launched. '\ "You'll have to edit scripts directly your configuration file.")) return cmdbase.extend(cmdend) misc.LaunchAndWait(cmdbase) else: misc.LaunchAndWait(cmdend)
def save_settings(self, nettype, networkid, networkentry): """ Verifies and saves the settings for the network entry. """ entry = networkentry.advanced_dialog opt_entlist = [] req_entlist = [] # First make sure all the Addresses entered are valid. if entry.chkbox_static_ip.get_active(): req_entlist = [entry.txt_ip, entry.txt_netmask] opt_entlist = [entry.txt_gateway] if entry.chkbox_static_dns.get_active() and \ not entry.chkbox_global_dns.get_active(): for ent in [entry.txt_dns_1, entry.txt_dns_2, entry.txt_dns_3]: opt_entlist.append(ent) # Required entries. for lblent in req_entlist: lblent.set_text(lblent.get_text().strip()) if not misc.IsValidIP(lblent.get_text()): error( self.window, _('Invalid address in $A entry.').replace( '$A', lblent.label.get_label())) return False # Optional entries, only check for validity if they're entered. for lblent in opt_entlist: lblent.set_text(lblent.get_text().strip()) if lblent.get_text() and not misc.IsValidIP(lblent.get_text()): error( self.window, _('Invalid address in $A entry.').replace( '$A', lblent.label.get_label())) return False # Now save the settings. if nettype == "wireless": if not networkentry.save_wireless_settings(networkid): return False elif nettype == "wired": if not networkentry.save_wired_settings(): return False return True
def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except DBusException as e: if e.get_dbus_name() is not None and \ "DBus.Error.AccessDenied" in e.get_dbus_name(): error( None, _('Unable to contact the Wicd daemon due to an access ' 'denied error from DBus. Please check that your user is ' 'in the $A group.').replace( "$A", "<b>" + wpath.wicd_group + "</b>")) #raise raise DBusException(e) else: print(("warning: ignoring exception %s" % e)) return None
def check_encryption_valid(self, networkid, entry): """ Make sure that encryption settings are properly filled in. """ # Make sure no entries are left blank if entry.chkbox_encryption.get_active(): encryption_info = entry.encryption_info for entry_info in encryption_info.itervalues(): if entry_info[0].entry.get_text() == "" and \ entry_info[1] == 'required': error(self.window, "%s (%s)" % (language['encrypt_info_missing'], entry_info[0].label.get_label()) ) return False # Make sure the checkbox is checked when it should be elif not entry.chkbox_encryption.get_active() and \ wireless.GetWirelessProperty(networkid, "encryption"): error(self.window, language['enable_encryption']) return False return True
def handle_no_dbus(): """ Called when dbus announces its shutting down. """ global DBUS_AVAIL, lost_dbus_id DBUS_AVAIL = False gui.handle_no_dbus(from_tray=True) print "Wicd daemon is shutting down!" lost_dbus_id = misc.timeout_add( 5, lambda: error(None, language['lost_dbus'], block=False)) return False
def handle_no_dbus(): """ Called when dbus announces its shutting down. """ global DBUS_AVAIL, lost_dbus_id DBUS_AVAIL = False gui.handle_no_dbus(from_tray=True) print "Wicd daemon is shutting down!" lost_dbus_id = misc.timeout_add(5, lambda:error(None, _('The wicd daemon has shut down. The UI will not function properly until it is restarted.'), block=False)) return False
def handle_no_dbus(): """ Called when dbus announces its shutting down. """ global DBUS_AVAIL, lost_dbus_id DBUS_AVAIL = False gui.handle_no_dbus(from_tray=True) print "Wicd daemon is shutting down!" lost_dbus_id = misc.timeout_add(5, lambda:error(None, language['lost_dbus'], block=False)) return False
def check_encryption_valid(self, networkid, entry): """ Make sure that encryption settings are properly filled in. """ # Make sure no entries are left blank if entry.chkbox_encryption.get_active(): encryption_info = entry.encryption_info for entry_info in encryption_info.itervalues(): if entry_info[0].entry.get_text() == "" and \ entry_info[1] == 'required': error( self.window, "%s (%s)" % (language['encrypt_info_missing'], entry_info[0].label.get_label())) return False # Make sure the checkbox is checked when it should be elif not entry.chkbox_encryption.get_active() and \ wireless.GetWirelessProperty(networkid, "encryption"): error(self.window, language['enable_encryption']) return False return True
def set_defaults(self, widget=None, event=None): """ Put some default values into entries to help the user out. """ self.txt_ip.set_text(self.txt_ip.get_text().strip()) ipAddress = self.txt_ip.get_text() # For easy typing :) netmask = self.txt_netmask gateway = self.txt_gateway ip_parts = misc.IsValidIP(ipAddress) if ip_parts: if stringToNone(gateway.get_text() ) is None: # Make sure the gateway box is blank # Fill it in with a .1 at the end gateway.set_text('.'.join(ip_parts[0:3]) + '.1') if stringToNone(netmask.get_text() ) is None: # Make sure the netmask is blank netmask.set_text( '255.255.255.0') # Fill in the most common one elif ipAddress != "": error(None, language['invalid_ip_address'])
def save_settings(self, nettype, networkid, networkentry): """ Verifies and saves the settings for the network entry. """ entry = networkentry.advanced_dialog opt_entlist = [] req_entlist = [] # First make sure all the Addresses entered are valid. if entry.chkbox_static_ip.get_active(): req_entlist = [entry.txt_ip, entry.txt_netmask] opt_entlist = [entry.txt_gateway] if entry.chkbox_static_dns.get_active() and \ not entry.chkbox_global_dns.get_active(): for ent in [entry.txt_dns_1, entry.txt_dns_2, entry.txt_dns_3]: opt_entlist.append(ent) # Required entries. for lblent in req_entlist: lblent.set_text(lblent.get_text().strip()) if not misc.IsValidIP(lblent.get_text()): error(self.window, language['invalid_address']. replace('$A', lblent.label.get_label())) return False # Optional entries, only check for validity if they're entered. for lblent in opt_entlist: lblent.set_text(lblent.get_text().strip()) if lblent.get_text() and not misc.IsValidIP(lblent.get_text()): error(self.window, language['invalid_address']. replace('$A', lblent.label.get_label())) return False # Now save the settings. if nettype == "wireless": if not networkentry.save_wireless_settings(networkid): return False elif nettype == "wired": if not networkentry.save_wired_settings(): return False return True
def check_encryption_valid(self, networkid, entry): """ Make sure that encryption settings are properly filled in. """ # Make sure no entries are left blank if entry.chkbox_encryption.get_active(): encryption_info = entry.encryption_info for entry_info in list(encryption_info.values()): if entry_info[0].entry.get_text() == "" and \ entry_info[1] == 'required': error( self.window, "%s (%s)" % (_('Required encryption information is missing.'), entry_info[0].label.get_label())) return False # Make sure the checkbox is checked when it should be elif not entry.chkbox_encryption.get_active() and \ wireless.GetWirelessProperty(networkid, "encryption"): error(self.window, _('This network requires encryption to be enabled.')) return False return True
def handle_no_dbus(): """ Called when dbus announces its shutting down. """ global DBUS_AVAIL, lost_dbus_id DBUS_AVAIL = False gui.handle_no_dbus(from_tray=True) print("Wicd daemon is shutting down!") lost_dbus_id = misc.timeout_add( 5, lambda: error( None, _('The wicd daemon has shut down. The UI will not function ' 'properly until it is restarted.'), block=False)) return False
def save_settings(self, networkid): # Check encryption info encrypt_info = self.encryption_info if self.chkbox_encryption.get_active(): print "setting encryption info..." encrypt_methods = self.encrypt_types self.set_net_prop( "enctype", encrypt_methods[self.combo_encryption.get_active()]['type']) # Make sure all required fields are filled in. for entry_info in encrypt_info.itervalues(): if entry_info[0].entry.get_text() == "" and \ entry_info[1] == 'required': error( self, "%s (%s)" % (language['encrypt_info_missing'], entry_info[0].label.get_label())) return False # Now save all the entries. for entry_key, entry_info in encrypt_info.iteritems(): self.set_net_prop(entry_key, noneToString(entry_info[0].entry.get_text())) elif not self.chkbox_encryption.get_active() and \ wireless.GetWirelessProperty(networkid, "encryption"): # Encrypt checkbox is off, but the network needs it. error(self, language['enable_encryption']) return False else: print "no encryption specified..." self.set_net_prop("enctype", "None") AdvancedSettingsDialog.save_settings(self) if self.chkbox_global_settings.get_active(): self.set_net_prop('use_settings_globally', True) else: self.set_net_prop('use_settings_globally', False) wireless.RemoveGlobalEssidEntry(networkid) wireless.SaveWirelessNetworkProfile(networkid) return True
def save_settings(self, networkid): # Check encryption info encrypt_info = self.encryption_info if self.chkbox_encryption.get_active(): print "setting encryption info..." encrypt_methods = self.encrypt_types self.set_net_prop("enctype", encrypt_methods[self.combo_encryption.get_active()]['type']) # Make sure all required fields are filled in. for entry_info in encrypt_info.itervalues(): if entry_info[0].entry.get_text() == "" and \ entry_info[1] == 'required': error(self, "%s (%s)" % (language['encrypt_info_missing'], entry_info[0].label.get_label()) ) return False # Now save all the entries. for entry_key, entry_info in encrypt_info.iteritems(): self.set_net_prop(entry_key, noneToString(entry_info[0].entry.get_text())) elif not self.chkbox_encryption.get_active() and \ wireless.GetWirelessProperty(networkid, "encryption"): # Encrypt checkbox is off, but the network needs it. error(self, language['enable_encryption']) return False else: print "no encryption specified..." self.set_net_prop("enctype", "None") AdvancedSettingsDialog.save_settings(self) if self.chkbox_global_settings.get_active(): self.set_net_prop('use_settings_globally', True) else: self.set_net_prop('use_settings_globally', False) wireless.RemoveGlobalEssidEntry(networkid) wireless.SaveWirelessNetworkProfile(networkid) return True
def handle_connection_results(self, results): """ Handle connection results. """ if results not in ['success', 'aborted'] and self.is_visible: error(self.window, language[results], block=False)
def handle_connection_results(self, results): if results not in ['Success', 'aborted'] and self.is_visible: error(self.window, language[results], block=False)