From c055ea0d3689ca1bce422b5a7fcd8189050d8089 Mon Sep 17 00:00:00 2001 From: imdano <> Date: Fri, 21 Mar 2008 17:07:47 +0000 Subject: [PATCH] Added support in the preferences window for specifying which dhcp client, link detection tool, and route flushing tool to use. It can also be left up to wicd to decide automatically. Made a few logic optimizations. --- daemon.py | 107 ++++-- data/wicd.glade | 939 ++++++++++++++++++++++++++++++------------------ gui.py | 115 +++++- misc.py | 11 + networking.py | 53 ++- wnettools.py | 38 +- 6 files changed, 841 insertions(+), 422 deletions(-) diff --git a/daemon.py b/daemon.py index dcdde62..a39d8f5 100644 --- a/daemon.py +++ b/daemon.py @@ -148,6 +148,9 @@ class ConnectionWizard(dbus.service.Object): self.connection_state = misc.NOT_CONNECTED self.connection_info = [""] self.auto_connecting = False + self.dhcp_client = 0 + self.link_detect_tool = 0 + self.flush_tool = 0 # Load the config file self.ReadConfig() @@ -342,7 +345,7 @@ class ConnectionWizard(dbus.service.Object): self.suspended = val if self.suspended: self.Disconnect() - + @dbus.service.method('org.wicd.daemon') def GetSuspend(self): """ Returns True if the computer is in the suspend state. """ @@ -376,6 +379,8 @@ class ConnectionWizard(dbus.service.Object): not self.GetNeedWiredProfileChooser(): self.LaunchChooser() return + + # Default Profile. elif self.GetWiredAutoConnectMethod() == 1: network = self.GetDefaultWiredNetwork() if not network: @@ -383,6 +388,8 @@ class ConnectionWizard(dbus.service.Object): " wired autoconnect failed." self._wireless_autoconnect() return + + # Last-Used. else: # Assume its last-used. network = self.GetLastUsedWiredNetwork() if not network: @@ -390,6 +397,7 @@ class ConnectionWizard(dbus.service.Object): "autoconnect failed." self._wireless_autoconnect() return + self.ReadWiredNetworkProfile(network) self.ConnectWired() print "Attempting to autoconnect with wired interface..." @@ -454,18 +462,16 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon') def GetGlobalDNSAddresses(self): """ Returns the global dns addresses. """ - print 'returning global dns addresses to client' return (misc.noneToString(self.dns1), misc.noneToString(self.dns2), misc.noneToString(self.dns3)) @dbus.service.method('org.wicd.daemon') def CheckIfConnecting(self): """ Returns if a network connection is being made. """ - if not self.CheckIfWiredConnecting() and \ - not self.CheckIfWirelessConnecting(): - return False - else: + if self.CheckIfWiredConnecting() or self.CheckIfWirelessConnecting(): return True + else: + return False @dbus.service.method('org.wicd.daemon') def CancelConnect(self): @@ -588,6 +594,48 @@ class ConnectionWizard(dbus.service.Object): """ return bool(self.need_profile_chooser) + @dbus.service.method('org.wicd.daemon') + def GetDHCPClient(self): + return self.dhcp_client + + @dbus.service.method('org.wicd.daemon') + def SetDHCPClient(self, client): + self.dhcp_client = int(client) + self.wifi.dhcp_client = int(client) + self.wired.dhcp_client = int(client) + config = ConfigParser.ConfigParser() + config.read(self.app_conf) + config.set("Settings", "dhcp_client", client) + config.write(open(self.app_conf, "w")) + + @dbus.service.method('org.wicd.daemon') + def GetLinkDetectionTool(self): + return self.link_detect_tool + + + @dbus.service.method('org.wicd.daemon') + def SetLinkDetectionTool(self, link_tool): + self.link_detect_tool = int(link_tool) + self.wired.link_tool = int(link_tool) + config = ConfigParser.ConfigParser() + config.read(self.app_conf) + config.set("Settings", "link_detect_tool", link_tool) + config.write(open(self.app_conf, "w")) + + @dbus.service.method('org.wicd.daemon') + def GetFlushTool(self): + return self.flush_tool + + @dbus.service.method('org.wicd.daemon') + def SetFlushTool(self, flush_tool): + self.flush_tool = int(flush_tool) + self.wired.flush_tool = int(flush_tool) + self.wifi.flush_tool = int(flush_tool) + config = ConfigParser.ConfigParser() + config.read(self.app_conf) + config.set("Settings", "flush_tool", flush_tool) + config.write(open(self.app_conf, "w")) + @dbus.service.signal(dbus_interface='org.wicd.daemon', signature='') def LaunchChooser(self): """ Emits the wired profile chooser dbus signal. """ @@ -629,7 +677,7 @@ class ConnectionWizard(dbus.service.Object): self.LastScan = scan if self.debug_mode: print 'scanning done' - print 'found' + str(len(scan)) + 'networks:' + print 'found ' + str(len(scan)) + ' networks:' for i, network in enumerate(scan): self.ReadWirelessNetworkProfile(i) @@ -805,11 +853,8 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def CheckIfWiredConnecting(self): """ Returns True if wired interface is connecting, otherwise False. """ - if self.wired.connecting_thread is not None: - #if connecting_thread exists, then check for it's - #status, if it doesn't exist, we aren't connecting - status = self.wired.connecting_thread.is_connecting - return status + if self.wired.connecting_thread: + return self.wired.connecting_thread.is_connecting else: return False @@ -833,9 +878,8 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def CheckWiredConnectingMessage(self): """ Returns the wired interface\'s status message. """ - if not self.wired.connecting_thread == None: - status = self.wired.connecting_thread.GetStatus() - return status + if self.wired.connecting_thread: + return self.wired.connecting_thread.GetStatus() else: return False @@ -898,14 +942,12 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def EnableWiredInterface(self): """ Calls a method to enable the wired interface. """ - result = self.wired.EnableInterface() - return result - + return self.wired.EnableInterface() + @dbus.service.method('org.wicd.daemon.wired') def DisableWiredInterface(self): """ Calls a method to disable the wired interface. """ - result = self.wired.DisableInterface() - return result + return self.wired.DisableInterface() @dbus.service.method('org.wicd.daemon.wired') def ConnectWired(self): @@ -1075,8 +1117,8 @@ class ConnectionWizard(dbus.service.Object): config.remove_section(bssid_key) config.add_section(bssid_key) - # We want to write the essid and bssid sections if global - # settings are enabled. + # We want to write the essid in addition to bssid + # sections if global settings are enabled. if cur_network["use_settings_globally"]: if config.has_section(essid_key): config.remove_section(essid_key) @@ -1091,10 +1133,10 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def SaveWirelessNetworkProperty(self, id, option): - """ Writes a particular wireless property to disk """ + """ 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 cur_network = self.LastScan[id] essid_key = "essid:" + cur_network["essid"] @@ -1255,7 +1297,6 @@ class ConnectionWizard(dbus.service.Object): dns2 = self.get_option("Settings", "global_dns_2", default='None') dns3 = self.get_option("Settings", "global_dns_3", default='None') self.SetGlobalDNS(dns1, dns2, dns3) - self.SetAutoReconnect(self.get_option("Settings", "auto_reconnect", default=False)) self.SetDebugMode(self.get_option("Settings", "debug_mode", @@ -1267,6 +1308,13 @@ class ConnectionWizard(dbus.service.Object): self.SetSignalDisplayType(self.get_option("Settings", "signal_display_type", default=0)) + self.SetDHCPClient(self.get_option("Settings", "dhcp_client", + default=0)) + self.SetLinkDetectionTool(self.get_option("Settings", + "link_detect_tool", + default=0)) + self.SetFlushTool(self.get_option("Settings", "flush_tool", + default=0)) else: # Write some defaults maybe? print "Configuration file not found, creating, adding defaults..." @@ -1280,6 +1328,9 @@ class ConnectionWizard(dbus.service.Object): config.set("Settings", "debug_mode", "False") config.set("Settings", "wired_connect_mode", "1") config.set("Settings", "signal_display_type", "0") + config.set("Settings", "dhcp_client", "0") + config.set("Settings", "link_detect_tool", "0") + config.set("Settings", "flush_tool", "0") config.set("Settings", "dns1", "None") config.set("Settings", "dns2", "None") config.set("Settings", "dns3", "None") @@ -1297,6 +1348,10 @@ class ConnectionWizard(dbus.service.Object): "wired_interface")) self.SetWPADriver(config.get("Settings", "wpa_driver")) + self.SetDHCPClient(config.get("Settings", "dhcp_client")) + self.SetLinkDetectionTool(config.get("Settings", + "link_detect_tool")) + self.SetFlushTool(config.get("Settings", "flush_tool")) self.SetAlwaysShowWiredInterface(False) self.SetAutoReconnect(False) self.SetDebugMode(False) diff --git a/data/wicd.glade b/data/wicd.glade index 5f4cf8d..f08f13e 100644 --- a/data/wicd.glade +++ b/data/wicd.glade @@ -413,15 +413,12 @@ True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK GTK_BUTTONBOX_END True True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-ok + gtk-ok True 1 @@ -430,9 +427,7 @@ True True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-cancel + gtk-cancel True 0 @@ -450,384 +445,628 @@ - 465 - 525 - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 5 - Wicd Preferences - GTK_WIN_POS_CENTER_ON_PARENT + Preferences GDK_WINDOW_TYPE_HINT_DIALOG - False - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 5 - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True - - 75 + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - WPA Supplicant Driver: + 5 + + + True + + + 75 + True + WPA Supplicant Driver: + + + + + + + + False + False + 1 + + + + + True + + + 260 + True + Wireless Interface: + + + + + 200 + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + False + 1 + + + + + False + False + 1 + + + + + True + + + 260 + True + Wired Interface: + + + + + 200 + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + False + 1 + + + + + False + False + 2 + + + + + True + True + Use global DNS servers + True + 0 + True + + + False + 3 + + + + + True + + + 170 + True + DNS 1 + + + False + False + + + + + 200 + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + False + 1 + + + + + False + False + 4 + + + + + True + + + 170 + True + DNS 2 + + + False + False + + + + + 200 + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + False + 1 + + + + + False + False + 5 + + + + + True + + + 170 + True + DNS 3 + + + False + False + + + + + 200 + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + False + 1 + + + + + False + 6 + + + + + True + True + Always show wired interface + True + 0 + True + + + False + False + 7 + + + + + True + True + Automatically reconnect on connection loss + True + 0 + True + + + False + False + 8 + + + + + True + True + Enable Debug Mode + True + 0 + True + + + False + False + 9 + + + + + True + True + Use dBm to measure signal strength + True + 0 + True + + + False + False + 10 + + + + + 2 + 8 + True + + + False + 11 + + + + + True + Wired Autoconnect Setting: + True + + + False + False + 12 + + + + + True + True + Use default profile on wired autoconnect + True + 0 + True + True + + + False + 13 + + + + + True + True + Prompt for profile on wired autoconnect + True + 0 + True + True + pref_use_def_radio + + + False + 14 + + + + + True + True + Use last profile on wired autoconnect + True + 0 + True + True + pref_use_def_radio + + + False + 15 + + - - - - - False - False - 1 - 1 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - 260 + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Wireless Interface: - - - - - 200 - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + General Settings + + + tab + False + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + DHCP Client: + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Automatic (recommended) + 0 + True + True + + + 1 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + dhclient + 0 + True + True + dhcp_auto_radio + + + 2 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + dhcpcd + 0 + True + True + dhcp_auto_radio + + + 3 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + pump + 0 + True + True + dhcp_auto_radio + + + 4 + + + + + False + False + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + 4 + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Wired Link Detection: + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Automatic (recommended) + 0 + True + True + + + 1 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + ethtool + 0 + True + True + link_auto_radio + + + 2 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + mii-tool + 0 + True + True + link_auto_radio + + + 3 + + + + + False + False + 2 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + 4 + 3 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Route Table Flushing: + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Automatic (recommended) + 0 + True + True + + + 1 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + ip + 0 + True + True + flush_auto_radio + + + 2 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + route + 0 + True + True + flush_auto_radio + + + 3 + + + + + False + False + 4 + + - False - False 1 + + + True + External Programs + + + tab + 1 + False + + - False - False 2 - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - 260 - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Wired Interface: - - - - - 200 - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - False - 1 - - - - - False - False - 3 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Use global DNS servers - 0 - True - - - False - 4 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - 170 - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - DNS 1 - - - False - False - - - - - 200 - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - False - 1 - - - - - False - False - 5 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - 170 - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - DNS 2 - - - False - False - - - - - 200 - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - False - 1 - - - - - False - False - 6 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - 170 - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - DNS 3 - - - False - False - - - - - 200 - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - False - 1 - - - - - False - 7 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Always show wired interface - 0 - True - - - False - False - 8 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Automatically reconnect on connection loss - 0 - True - - - False - False - 9 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Enable Debug Mode - 0 - True - - - False - False - 10 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Use dBm to measure signal strength - 0 - True - - - False - False - 11 - - - - - 2 - 8 - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - 12 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Wired Autoconnect Setting: - True - - - False - False - 13 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Use default profile on wired autoconnect - 0 - True - True - - - False - 14 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Prompt for profile on wired autoconnect - 0 - True - True - pref_use_def_radio - - - False - 15 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Use last profile on wired autoconnect - 0 - True - True - pref_use_def_radio - - - False - 16 - - - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK GTK_BUTTONBOX_END - + True True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-ok + True + gtk-cancel True - 1 + 0 - + True True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-cancel + True + gtk-ok True - 2 + 1 1 diff --git a/gui.py b/gui.py index 21f2d74..fc2b341 100644 --- a/gui.py +++ b/gui.py @@ -147,6 +147,12 @@ 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.') +language['wicd_auto_config'] = _('Automatic (recommended)') +language["gen_settings"] = _("General Settings") +language["ext_programs"] = _("External Programs") +language["dhcp_client"] = _("DHCP Client") +language["wired_detect"] = _("Wired Link Detection") +language["route_flush"] = _("Route Table Flushing") language['0'] = _('0') language['1'] = _('1') @@ -1273,6 +1279,43 @@ class appGui: showlistradiobutton.set_label(language['show_wired_list']) lastusedradiobutton = self.wTree.get_widget("pref_use_last_radio") lastusedradiobutton.set_label(language['use_last_used_profile']) + + ## External Programs tab + self.wTree.get_widget("gen_settings_label").set_label(language["gen_settings"]) + self.wTree.get_widget("ext_prog_label").set_label(language["ext_programs"]) + self.wTree.get_widget("dhcp_client_label").set_label(language["dhcp_client"]) + self.wTree.get_widget("wired_detect_label").set_label(language["wired_detect"]) + self.wTree.get_widget("route_flush_label").set_label(language["route_flush"]) + + # DHCP Clients + dhcpautoradio = self.wTree.get_widget("dhcp_auto_radio") + dhcpautoradio.set_label(language["wicd_auto_config"]) + dhclientradio = self.wTree.get_widget("dhclient_radio") + pumpradio = self.wTree.get_widget("pump_radio") + dhcpcdradio = self.wTree.get_widget("dhcpcd_radio") + dhcp_list = [dhcpautoradio, dhclientradio, pumpradio, dhcpcdradio] + + dhcp_method = daemon.GetDHCPClient() + dhcp_list[dhcp_method].set_active(True) + + # Wired Link Detection Apps + linkautoradio = self.wTree.get_widget("link_auto_radio") + linkautoradio.set_label(language['wicd_auto_config']) + linkautoradio = self.wTree.get_widget("link_auto_radio") + ethtoolradio = self.wTree.get_widget("ethtool_radio") + miitoolradio = self.wTree.get_widget("miitool_radio") + wired_link_list = [linkautoradio, ethtoolradio, miitoolradio] + wired_link_method = daemon.GetLinkDetectionTool() + wired_link_list[wired_link_method].set_active(True) + + # Route Flushing Apps + flushautoradio = self.wTree.get_widget("flush_auto_radio") + flushautoradio.set_label(language['wicd_auto_config']) + ipflushradio = self.wTree.get_widget("ip_flush_radio") + routeflushradio = self.wTree.get_widget("route_flush_radio") + flush_list = [flushautoradio, ipflushradio, routeflushradio] + flush_method = daemon.GetFlushTool() + flush_list[flush_method].set_active(True) if wired.GetWiredAutoConnectMethod() == 1: usedefaultradiobutton.set_active(True) @@ -1350,6 +1393,8 @@ class appGui: atrlist = pango.AttrList() atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50)) entryWiredAutoMethod.set_attributes(atrlist) + + self.wTree.get_widget("notebook2").set_current_page(0) dialog.show_all() response = dialog.run() @@ -1370,6 +1415,34 @@ class appGui: wired.SetWiredAutoConnectMethod(3) else: wired.SetWiredAutoConnectMethod(1) + + # External Programs Tab + if dhcpautoradio.get_active(): + dhcp_client = misc.AUTO + elif dhclientradio.get_active(): + dhcp_client = misc.DHCLIENT + elif dhcpcdradio.get_active(): + dhcp_client = misc.DHCPCD + else: + dhcp_client = misc.PUMP + daemon.SetDHCPClient(dhcp_client) + + if linkautoradio.get_active(): + link_tool = misc.AUTO + elif ethtoolradio.get_active(): + link_tool = misc.ETHTOOL + else: + link_tool = misc.MIITOOL + daemon.SetLinkDetectionTool(link_tool) + + if flushautoradio.get_active(): + flush_tool = misc.AUTO + elif ipflushradio.get_active(): + flush_tool = misc.IP + else: + flush_tool = misc.ROUTE + daemon.SetFlushTool(flush_tool) + dialog.hide() def set_label(self, glade_str, label): @@ -1523,21 +1596,21 @@ class appGui: if not network: return False - strength = wireless.GetCurrentSignalStrength(iwconfig) - dbm_strength = wireless.GetCurrentDBMStrength(iwconfig) - if strength is not None and dbm_strength is not None: - network = str(network) - if daemon.GetSignalDisplayType() == 0: - strength = str(strength) - else: - strength = str(dbm_strength) - ip = str(wireless_ip) - self.set_status(language['connected_to_wireless'].replace - ('$A', network).replace - ('$B', daemon.FormatSignalForPrinting(strength)).replace - ('$C', wireless_ip)) - return True - return False + network = str(network) + if daemon.GetSignalDisplayType() == 0: + strength = wireless.GetCurrentSignalStrength(iwconfig) + else: + strength = wireless.GetCurrentDBMStrength(iwconfig) + + if strength is None: + return False + strength = str(strength) + ip = str(wireless_ip) + self.set_status(language['connected_to_wireless'].replace + ('$A', network).replace + ('$B', daemon.FormatSignalForPrinting(strength)).replace + ('$C', wireless_ip)) + return True def set_status(self, msg): """ Sets the status bar message for the GUI. """ @@ -1660,9 +1733,12 @@ class appGui: not entry.chkbox_global_dns.get_active(): 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())) + 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(): entry.set_net_prop('use_static_dns', True) @@ -1696,7 +1772,8 @@ class appGui: misc.error(self.window, language['enable_encryption']) return False else: - print 'encryption is', wireless.GetWirelessProperty(networkid, "encryption") + print 'encryption is ' + str(wireless.GetWirelessProperty(networkid, + "encryption")) print "no encryption specified..." entry.set_net_prop("enctype", "None") diff --git a/misc.py b/misc.py index c47960b..91d842f 100644 --- a/misc.py +++ b/misc.py @@ -35,6 +35,17 @@ WIRELESS = 2 WIRED = 3 SUSPENDED = 4 +AUTO = 0 +DHCLIENT = 1 +DHCPCD = 2 +PUMP = 3 + +ETHTOOL = 1 +MIITOOL = 2 + +IP = 1 +ROUTE = 2 + def Run(cmd, include_stderr=False, return_pipe=False): """ Run a command. diff --git a/networking.py b/networking.py index d5aa918..810c67c 100644 --- a/networking.py +++ b/networking.py @@ -71,6 +71,8 @@ class Controller(object): self.global_dns_3 = None self._wired_interface = None self._wireless_interface = None + self._dhcp_client = None + self._flush_tool = None self._debug = None def set_wireless_iface(self, value): @@ -98,10 +100,32 @@ class Controller(object): def get_debug(self): return self._debug + + def set_dhcp_client(self, value): + self._dhcp_client = value + if self.wiface: + self.wiface.DHCP_CLIENT = value + if self.liface: + self.liface.DHCP_CLIENT = value + + def get_dhcp_client(self): + return self._dhcp_client + + def set_flush_tool(self, value): + self._flush_tool = value + if self.wiface: + self.wiface.flush_tool = value + if self.liface: + self.liface.flush_tool = value + + def get_flush_tool(self): + return self._flush_tool wireless_interface = property(get_wireless_iface, set_wireless_iface) wired_interface = property(get_wired_iface, set_wired_iface) debug = property(get_debug, set_debug) + flush_tool = property(get_flush_tool, set_flush_tool) + dhcp_client = property(get_dhcp_client, set_dhcp_client) def SetWiface(self, iface): """ Sets the wireless interface for the associated wnettools class. """ @@ -266,17 +290,15 @@ class ConnectThread(threading.Thread): Otherwise do nothing. """ - if (((self.network.get('dns1') or self.network.get('dns2') or - self.network.get('dns3')) and self.network.get('use_static_dns')) or - self.network.get('use_global_dns')): + if self.network.get('use_global_dns'): + wnettools.SetDNS(misc.Noneify(self.global_dns_1), + misc.Noneify(self.global_dns_2), + misc.Noneify(self.global_dns_3)) + elif self.network.get('use_static_dns') and (self.network.get('dns1') or + self.network.get('dns2') or self.network.get('dns3')): self.SetStatus('setting_static_dns') - if self.network.get('use_global_dns'): - wnettools.SetDNS(misc.Noneify(self.global_dns_1), - misc.Noneify(self.global_dns_2), - misc.Noneify(self.global_dns_3)) - else: - wnettools.SetDNS(self.network.get('dns1'), - self.network.get('dns2'), self.network.get('dns3')) + wnettools.SetDNS(self.network.get('dns1'), self.network.get('dns2'), + self.network.get('dns3')) def connect_aborted(self, reason): """ Sets the thread status to aborted in a thread-safe way. @@ -672,10 +694,17 @@ class Wired(Controller): """ Initialise the class. """ Controller.__init__(self) self.wpa_driver = None + self._link_detect = None self.liface = wnettools.WiredInterface(self.wired_interface, self.debug) - def __setattr__(self, attr, val): - object.__setattr__(self, attr, val) + def set_link_detect(self, value): + self._link_detect = value + if self.liface: + self.liface.link_detect = value + + def get_link_detect(self): return self._link_detect + + link_detect = property(get_link_detect, set_link_detect) def LoadInterfaces(self): """ Load the wnettools controls for the wired/wireless interfaces. """ diff --git a/wnettools.py b/wnettools.py index f6c4fbf..ee94636 100644 --- a/wnettools.py +++ b/wnettools.py @@ -129,6 +129,8 @@ class Interface(object): self.MIITOOL_FOUND = False self.ETHTOOL_FOUND = False self.IP_FOUND = False + self.flush_tool = None + self.link_detect = None self.Check() def SetDebugMode(self, value): @@ -142,7 +144,7 @@ class Interface(object): iface -- the name of the interface. """ - self.iface = iface + self.iface = str(iface) def CheckDHCP(self): """ Check for a valid DHCP client. @@ -153,23 +155,29 @@ class Interface(object): warning is printed. """ - dhcpclients = ["dhclient", "dhcpcd", "pump"] - for client in dhcpclients: - if misc.Run("which " + client): - DHCP_CLIENT = client - break + if self.DHCP_CLIENT: + DHCP_CLIENT = self.DHCP_CLIENT + else: + dhcpclients = ["dhclient", "dhcpcd", "pump"] + for client in dhcpclients: + if misc.Run("which " + client): + DHCP_CLIENT = client + break if not DHCP_CLIENT: print "WARNING: NO DHCP CLIENT DETECTED! Make sure there is one \ set in your path." return - elif DHCP_CLIENT == "dhclient": + elif DHCP_CLIENT in [misc.DHCLIENT, "dhclient"]: + DHCP_CLIENT = misc.DHCLIENT DHCP_CMD = "dhclient" DHCP_RELEASE = "dhclient -r" - elif DHCP_CLIENT == "pump": + elif DHCP_CLIENT in [misc.PUMP, "pump"]: + DHCP_CLIENT = misc.PUMP DHCP_CMD = "pump -i" DHCP_RELEASE = "pump -r -i" - elif DHCP_CLIENT == "dhcpcd": + elif DHCP_CLIENT in [misc.DHCPCD, "dhcpcd"]: + DHCP_CLIENT = misc.DHCPCD DHCP_CMD = "dhcpcd" DHCP_RELEASE = "dhcpcd -r" @@ -352,11 +360,11 @@ class Interface(object): pipe = misc.Run(cmd, include_stderr=True, return_pipe=True) DHCP_CLIENT = self.DHCP_CLIENT - if DHCP_CLIENT == "dhclient": + if DHCP_CLIENT == misc.DHCLIENT: return self._parse_dhclient(pipe) - elif DHCP_CLIENT == "pump": + elif DHCP_CLIENT == misc.PUMP: return self._parse_pump(pipe) - elif DHCP_CLIENT == "dhcpcd": + elif DHCP_CLIENT == misc.DHCPCD: return self._parse_dhcpcd(pipe) def ReleaseDHCP(self): @@ -368,7 +376,7 @@ class Interface(object): """ Flush all network routes. """ if not self.iface: return - if self.IP_FOUND: + if self.IP_FOUND and self.flush_tool != misc.ROUTE: cmd = "ip route flush dev " + self.iface else: cmd = 'route del dev ' + self.iface @@ -443,7 +451,7 @@ class WiredInterface(Interface): """ if not self.iface: return False - if self.ETHTOOL_FOUND: + if self.ETHTOOL_FOUND and self.link_detect != misc.MIITOOL: return self._eth_get_plugged_in() elif self.MIITOOL_FOUND: return self._mii_get_plugged_in() @@ -839,7 +847,7 @@ class WirelessInterface(Interface): if self.wpa_driver == RALINK_DRIVER: return True - MAX_TIME = 10 + MAX_TIME = 15 MAX_DISCONNECTED_TIME = 3 while (time.time() - auth_time) < MAX_TIME: cmd = 'wpa_cli -i ' + self.iface + ' status'