From 04af10a8917ade7244cc1d77bf2502cf578076e4 Mon Sep 17 00:00:00 2001 From: imdano <> Date: Mon, 10 Mar 2008 20:55:46 +0000 Subject: [PATCH] Added support for using one set of global settings for all networks with a given essid. Fixed a few wired autoconnect issues. --- daemon.py | 121 +++++++++++++++++++++++++++++++++++------------------ gui.py | 116 ++++++++++++++++++++++++++++---------------------- monitor.py | 3 +- 3 files changed, 147 insertions(+), 93 deletions(-) diff --git a/daemon.py b/daemon.py index 1aff173..73e6df3 100644 --- a/daemon.py +++ b/daemon.py @@ -367,17 +367,17 @@ class ConnectionWizard(dbus.service.Object): if self.GetWiredAutoConnectMethod() == 2 and \ not self.GetNeedWiredProfileChooser(): self.LaunchChooser() + return elif self.GetWiredAutoConnectMethod() == 1: network = self.GetDefaultWiredNetwork() if not network: - print "Couldn't find a default wired connection, wired \ - autoconnect failed." + print "Couldn't find a default wired connection, wired autoconnect failed." self._wireless_autoconnect() + return else: # Assume its last-used. network = self.GetLastUsedWiredNetwork() if not network: - print "no previous wired profile available, wired autoconnect \ - failed." + print "no previous wired profile available, wired autoconnect failed." self._wireless_autoconnect() return self.ReadWiredNetworkProfile(network) @@ -551,6 +551,7 @@ class ConnectionWizard(dbus.service.Object): info[1] = essid info[2] = signal strength info[3] = internal networkid + SUSPENDED - info[0] = "" """ @@ -983,7 +984,7 @@ class ConnectionWizard(dbus.service.Object): profileList = config.sections() for profile in profileList: if config.has_option(profile, "default"): - if config.get(profile, "default") == "True": + if misc.to_bool(config.get(profile, "default")): print "removing existing default", profile config.set(profile, "default", False) self.SaveWiredNetworkProfile(profile) @@ -996,7 +997,7 @@ class ConnectionWizard(dbus.service.Object): profileList = config.sections() for profile in profileList: if config.has_option(profile, "default"): - if config.get(profile, "default") == "True": + if misc.to_bool(config.get(profile, "default")): return profile return None @@ -1078,58 +1079,98 @@ class ConnectionWizard(dbus.service.Object): print "setting network profile" config = ConfigParser.ConfigParser() config.read(self.wireless_conf) - if config.has_section(self.LastScan[id]["bssid"]): - config.remove_section(self.LastScan[id]["bssid"]) - config.add_section(self.LastScan[id]["bssid"]) - #add the essid so that people reading the config can figure - #out which network is which. it will not be read - for x in self.LastScan[id]: - config.set(self.LastScan[id]["bssid"], x, self.LastScan[id][x]) + cur_network = self.LastScan[id] + bssid_key = cur_network["bssid"] + essid_key = "essid:" + cur_network["essid"] + + if config.has_section(bssid_key): + config.remove_section(bssid_key) + config.add_section(bssid_key) + + # We want to write the essid and bssid sections if global + # settings are enabled. + if cur_network["use_settings_globally"]: + if config.has_section(essid_key): + config.remove_section(essid_key) + config.add_section(essid_key) + + for x in cur_network: + config.set(bssid_key, x, cur_network[x]) + if cur_network["use_settings_globally"]: + config.set(essid_key, x, cur_network[x]) + config.write(open(self.wireless_conf, "w")) @dbus.service.method('org.wicd.daemon.config') def SaveWirelessNetworkProperty(self, id, option): """ Writes a particular wireless property to disk """ if (option.strip()).endswith("script"): - print 'you cannot save script information to disk through the daemon.' + print 'you cannot save script information to disk through \ + the daemon.' return - - print ("setting network option " + str(option) + " to " + - str(self.LastScan[id][option])) + cur_network = self.LastScan[id] + essid_key = "essid:" + cur_network["essid"] + print ''.join("setting network option ", str(option), " to ", + str(cur_network[option])) config = ConfigParser.ConfigParser() config.read(self.wireless_conf) - if config.has_section(self.LastScan[id]["bssid"]): - config.set(self.LastScan[id]["bssid"], option, - str(self.LastScan[id][option])) + + if config.has_section(cur_network["bssid"]): + config.set(cur_network["bssid"], option, + str(cur_network[option])) + + # Write the global section as well, if required. + if config.has_section(essid_key): + if config.get(essid_key, 'use_settings_globally'): + config.set(essid_key, option, str(cur_network[option])) + config.write(open(self.wireless_conf, "w")) + + @dbus.service.method('org.wicd.daemon.config') + def RemoveGlobalEssidEntry(self, networkid): + """ Removes the global entry for the networkid provided. """ + config = ConfigParser.ConfigParser() + config.read(self.wireless_conf) + cur_network = self.LastScan[networkid] + essid_key = "essid:" + cur_network["essid"] + if config.has_section(essid_key): + config.remove_section(essid_key) @dbus.service.method('org.wicd.daemon.config') def ReadWirelessNetworkProfile(self, id): """ Reads in wireless profile as the active network """ config = ConfigParser.ConfigParser() config.read(self.wireless_conf) - print self.LastScan[id]["bssid"] - if config.has_section(self.LastScan[id]["bssid"]): - self.LastScan[id]["has_profile"] = True - - # Read the essid because we be needing to name those hidden - # wireless networks now - but only read it if it is hidden. - if self.LastScan[id]["hidden"]: - self.LastScan[id]["essid"] = misc.Noneify(config.get(self.LastScan[id]["bssid"], - "essid")) - for x in config.options(self.LastScan[id]["bssid"]): - if not self.LastScan[id].has_key(x) or x.endswith("script"): - self.LastScan[id][x] = misc.Noneify(config.get(self.LastScan[id]["bssid"], x)) - self.LastScan[id]['use_static_dns'] = bool(self.LastScan[id].get('use_static_dns')) - self.LastScan[id]['use_global_dns'] = bool(self.LastScan[id].get('use_global_dns')) - self.LastScan[id]['encryption'] = bool(self.LastScan[id].get('encryption')) - return "100: Loaded Profile" + cur_network = self.LastScan[id] + essid_key = "essid:" + cur_network["essid"] + bssid_key = cur_network["bssid"] + print bssid_key + if config.has_section(essid_key): + if config.get(essid_key, 'use_settings_globally'): + return self._read_wireless_profile(config, cur_network, + essid_key) + elif config.has_section(bssid_key): + return self._read_wireless_profile(config, cur_network, bssid_key) else: - self.LastScan[id]["has_profile"] = False - # Are these next two lines needed? -Dan - self.LastScan[id]['use_static_dns'] = bool(self.GetUseGlobalDNS()) - self.LastScan[id]['use_global_dns'] = bool(self.GetUseGlobalDNS()) + cur_network["has_profile"] = False return "500: Profile Not Found" + + def _read_wireless_profile(self, config, cur_network, section): + cur_network["has_profile"] = True + + # Read the essid because we be needing to name those hidden + # wireless networks now - but only read it if it is hidden. + if cur_network["hidden"]: + cur_network["essid"] = misc.Noneify(config.get(section, + "essid")) + for x in config.options(section): + if not cur_network.has_key(x) or x.endswith("script"): + cur_network[x] = misc.Noneify(config.get(section, + x)) + for option in ['use_static_dns', 'use_global_dns', 'encryption', + 'use_settings_globally']: + cur_network[option] = bool(cur_network.get(option)) + return "100: Loaded Profile" @dbus.service.method('org.wicd.daemon.config') def WriteWindowSize(self, width, height): diff --git a/gui.py b/gui.py index e28d272..8a9e5a8 100644 --- a/gui.py +++ b/gui.py @@ -147,6 +147,7 @@ language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporaril language['display_type_dialog'] = _('Use dBm to measure signal strength') language['scripts'] = _('Scripts') language['invalid_address'] = _('Invalid address in $A entry.') +language['global_settings'] = _('Use these settings for all networks sharing this essid') language['encrypt_info_missing'] = _('Required encryption information is missing.') language['enable_encryption'] = _('This network requires encryption to be enabled.') @@ -453,6 +454,9 @@ class WiredSettingsDialog(AdvancedSettingsDialog): AdvancedSettingsDialog.__init__(self) self.des = self.connect("destroy", self.destroy_called) + def set_net_prop(self, option, value): + wired.SetWiredProperty(option, value) + def set_values(self): """ Fill in the Gtk.Entry objects with the correct values. """ self.txt_ip.set_text(self.format_entry("ip")) @@ -496,6 +500,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): self.networkID = networkID self.combo_encryption = gtk.combo_box_new_text() self.chkbox_encryption = gtk.CheckButton(language['use_encryption']) + self.chkbox_global_settings = gtk.CheckButton(language['global_settings']) # Make the vbox to hold the encryption stuff. self.vbox_encrypt_info = gtk.VBox(False, 0) self.toggle_encryption() @@ -518,8 +523,8 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): else: self.combo_encryption.set_active(0) self.change_encrypt_method() - self.vbox.pack_start(self.chkbox_encryption, fill=False, - expand=False) + self.vbox.pack_start(self.chkbox_global_settings, False, False) + self.vbox.pack_start(self.chkbox_encryption, False, False) self.vbox.pack_start(self.combo_encryption) self.vbox.pack_start(self.vbox_encrypt_info) @@ -547,6 +552,10 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): self.destroy() del self + def set_net_prop(self, option, value): + """ Sets the given option to the given value for this network. """ + wireless.SetWirelessProperty(self.networkID, option, value) + def set_values(self): """ Set the various network settings to the right values. """ networkID = self.networkID @@ -568,6 +577,9 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): self.chkbox_encryption.set_active(True) else: self.chkbox_encryption.set_active(False) + + if wireless.GetWirelessProperty(networkID, 'use_settings_globally'): + self.chkbox_global_settings.set_active(True) def format_entry(self, networkid, label): """ Helper method for fetching/formatting wireless properties. """ @@ -1633,30 +1645,30 @@ class appGui: def save_wired_settings(self, entry): """ Saved wired network settings. """ if entry.chkbox_static_ip.get_active(): - wired.SetWiredProperty("ip", noneToString(entry.txt_ip.get_text())) - wired.SetWiredProperty("netmask", noneToString(entry.txt_netmask.get_text())) - wired.SetWiredProperty("gateway", noneToString(entry.txt_gateway.get_text())) + entry.set_net_prop("ip", noneToString(entry.txt_ip.get_text())) + entry.set_net_prop("netmask", noneToString(entry.txt_netmask.get_text())) + entry.set_net_prop("gateway", noneToString(entry.txt_gateway.get_text())) else: - wired.SetWiredProperty("ip", '') - wired.SetWiredProperty("netmask", '') - wired.SetWiredProperty("gateway", '') + entry.set_net_prop("ip", '') + entry.set_net_prop("netmask", '') + entry.set_net_prop("gateway", '') if entry.chkbox_static_dns.get_active() and \ not entry.chkbox_global_dns.get_active(): - wired.SetWiredProperty('use_static_dns', True) - wired.SetWiredProperty('use_global_dns', False) - wired.SetWiredProperty("dns1", noneToString(entry.txt_dns_1.get_text())) - wired.SetWiredProperty("dns2", noneToString(entry.txt_dns_2.get_text())) - wired.SetWiredProperty("dns3", noneToString(entry.txt_dns_3.get_text())) + entry.set_net_prop('use_static_dns', True) + entry.set_net_prop('use_global_dns', False) + entry.set_net_prop("dns1", noneToString(entry.txt_dns_1.get_text())) + entry.set_net_prop("dns2", noneToString(entry.txt_dns_2.get_text())) + entry.set_net_prop("dns3", noneToString(entry.txt_dns_3.get_text())) elif entry.chkbox_static_dns.get_active() and \ entry.chkbox_global_dns.get_active(): - wired.SetWiredProperty('use_static_dns', True) - wired.SetWiredProperty('use_global_dns', True) + entry.set_net_prop('use_static_dns', True) + entry.set_net_prop('use_global_dns', True) else: - wired.SetWiredProperty('use_static_dns', False) - wired.SetWiredProperty("dns1", '') - wired.SetWiredProperty("dns2", '') - wired.SetWiredProperty("dns3", '') + entry.set_net_prop('use_static_dns', False) + entry.set_net_prop("dns1", '') + entry.set_net_prop("dns2", '') + entry.set_net_prop("dns3", '') config.SaveWiredNetworkProfile(entry.combo_profile_names.get_active_text()) return True @@ -1667,15 +1679,15 @@ class appGui: print "setting encryption info..." encryption_info = entry.encryption_info encrypt_methods = misc.LoadEncryptionMethods() - wireless.SetWirelessProperty(networkid, "enctype", - encrypt_methods[entry.combo_encryption. - get_active()][1]) + entry.set_net_prop("enctype", + encrypt_methods[entry.combo_encryption. + get_active()][1]) for x in encryption_info: if encryption_info[x].get_text() == "": misc.error(self.window, language['encrypt_info_missing']) return False - wireless.SetWirelessProperty(networkid, x, - noneToString(encryption_info[x].get_text())) + entry.set_net_prop(x, noneToString(encryption_info[x]. + get_text())) elif not entry.chkbox_encryption.get_active() and \ wireless.GetWirelessProperty(networkid, "encryption"): misc.error(self.window, language['enable_encryption']) @@ -1683,45 +1695,47 @@ class appGui: else: print 'encryption is', wireless.GetWirelessProperty(networkid, "encryption") print "no encryption specified..." - wireless.SetWirelessProperty(networkid, "enctype", "None") + entry.set_net_prop("enctype", "None") - wireless.SetWirelessProperty(networkid, "automatic", - noneToString(netent.chkbox_autoconnect.get_active())) + entry.set_net_prop("automatic", + noneToString(netent.chkbox_autoconnect.get_active())) # Save IP info if entry.chkbox_static_ip.get_active(): - wireless.SetWirelessProperty(networkid, "ip", - noneToString(entry.txt_ip.get_text())) - wireless.SetWirelessProperty(networkid, "netmask", - noneToString(entry.txt_netmask.get_text())) - wireless.SetWirelessProperty(networkid, "gateway", - noneToString(entry.txt_gateway.get_text())) + entry.set_net_prop("ip", noneToString(entry.txt_ip.get_text())) + entry.set_net_prop("netmask", + noneToString(entry.txt_netmask.get_text())) + entry.set_net_prop("gateway", + noneToString(entry.txt_gateway.get_text())) else: # Blank the values - wireless.SetWirelessProperty(networkid, "ip", '') - wireless.SetWirelessProperty(networkid, "netmask", '') - wireless.SetWirelessProperty(networkid, "gateway", '') + entry.set_net_prop("ip", '') + entry.set_net_prop("netmask", '') + entry.set_net_prop("gateway", '') # Save DNS info if entry.chkbox_static_dns.get_active() and \ not entry.chkbox_global_dns.get_active(): - wireless.SetWirelessProperty(networkid, 'use_static_dns', True) - wireless.SetWirelessProperty(networkid, 'use_global_dns', False) - wireless.SetWirelessProperty(networkid, 'dns1', - noneToString(entry.txt_dns_1.get_text())) - wireless.SetWirelessProperty(networkid, 'dns2', - noneToString(entry.txt_dns_2.get_text())) - wireless.SetWirelessProperty(networkid, 'dns3', - noneToString(entry.txt_dns_3.get_text())) + entry.set_net_prop('use_static_dns', True) + entry.set_net_prop('use_global_dns', False) + entry.set_net_prop('dns1', noneToString(entry.txt_dns_1.get_text())) + entry.set_net_prop('dns2', noneToString(entry.txt_dns_2.get_text())) + entry.set_net_prop('dns3', noneToString(entry.txt_dns_3.get_text())) elif entry.chkbox_static_dns.get_active() and \ entry.chkbox_global_dns.get_active(): - wireless.SetWirelessProperty(networkid, 'use_static_dns', True) - wireless.SetWirelessProperty(networkid, 'use_global_dns', True) + entry.set_net_prop('use_static_dns', True) + entry.set_net_prop('use_global_dns', True) else: - wireless.SetWirelessProperty(networkid, 'use_static_dns', False) - wireless.SetWirelessProperty(networkid, 'use_global_dns', False) - wireless.SetWirelessProperty(networkid, 'dns1', '') - wireless.SetWirelessProperty(networkid, 'dns2', '') - wireless.SetWirelessProperty(networkid, 'dns3', '') + entry.set_net_prop('use_static_dns', False) + entry.set_net_prop('use_global_dns', False) + entry.set_net_prop('dns1', '') + entry.set_net_prop('dns2', '') + entry.set_net_prop('dns3', '') + + if entry.chkbox_global_settings.get_active(): + entry.set_net_prop('use_settings_globally', True) + else: + entry.set_net_prop('use_settings_globally', False) + config.RemoveGlobalEssidEntry(networkid) config.SaveWirelessNetworkProfile(networkid) return True diff --git a/monitor.py b/monitor.py index f675317..85c07fc 100755 --- a/monitor.py +++ b/monitor.py @@ -3,7 +3,6 @@ # # Copyright (C) 2007 Adam Blackburn # Copyright (C) 2007 Dan O'Reilly -# Copyright (C) 2007 Byron Hillis # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License Version 2 as @@ -246,4 +245,4 @@ def main(): mainloop.run() if __name__ == '__main__': - main() \ No newline at end of file + main()