diff --git a/daemon.py b/daemon.py index be26af4..f4418dc 100644 --- a/daemon.py +++ b/daemon.py @@ -1,4 +1,5 @@ #!/usr/bin/env python + """ wicd - wireless connection daemon implementation. This module implements the wicd daemon that provides network @@ -463,7 +464,6 @@ class ConnectionWizard(dbus.service.Object): """ self.forced_disconnect = bool(value) - #end function SetForcedDisconnect @dbus.service.method('org.wicd.daemon') def GetGUIOpen(self): @@ -830,6 +830,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def ConnectWired(self): """connects to a wired network. """ + self.SetForcedDisconnect(False) self.wired.before_script = self.GetWiredProperty("beforescript") self.wired.after_script = self.GetWiredProperty("afterscript") self.wired.disconnect_script = self.GetWiredProperty("disconnectscript") diff --git a/gui.py b/gui.py index a433370..4327bc7 100644 --- a/gui.py +++ b/gui.py @@ -1361,7 +1361,7 @@ class appGui: if entry.checkboxStaticDNS.get_active() and \ not entry.checkboxGlobalDNS.get_active(): entlist.append(entry.txtDNS1) - # Only append addition dns entries if they're entered. + # Only append additional dns entries if they're entered. for ent in [entry.txtDNS2, entry.txtDNS3]: if ent.get_text() != "": entlist.append(ent) diff --git a/wnettools.py b/wnettools.py index d850c3d..e67e36d 100644 --- a/wnettools.py +++ b/wnettools.py @@ -60,6 +60,7 @@ wpa2_pattern = re.compile('(WPA2)', re.I | re.M | re.S) auth_pattern = re.compile('.*wpa_state=(.*?)\n', re.I | re.M | re.S) RALINK_DRIVER = 'ralink legacy' +DHCP_CLIENT = None def SetDNS(dns1=None, dns2=None, dns3=None): @@ -122,6 +123,20 @@ class Interface(object): self.iface = iface self.verbose = verbose + def CheckDHCP(self): + """ Check that all required tools are available. """ + # TODO: Implement this function. + # THINGS TO CHECK FOR: ethtool, pptp-linux, dhclient, host + dhcpclients = ["dhclient", "dhcpcd", "pump -i"] + for client in dhcpclients: + if misc.Run("which " + client.split()[0]): + DHCP_CLIENT = client + break + + if not DHCP_CLIENT: + print "WARNING: NO DHCP CLIENT DETECTED!" + self.DHCP_CLIENT = DHCP_CLIENT + def Check(self): """ Check that all required tools are available.""" # TODO: Implement this function. @@ -194,21 +209,67 @@ class Interface(object): else: print 'DHCP connection failed: Reason unknown' return 'dhcp_failed' + + def _parse_pump(self, pipe): + """ Determines if obtaining an IP using pump succeeded. """ + pump_complete = False + pump_succeded = True + + while not pump_complete: + line = pipe.readline() + if line == '': + pump_complete = True + elif line.strip().lower().startswith('Operation failed.'): + pump_succeded = False + pump_complete = True + print line + + if pump_succeded: + print "DHCP connection successful" + return "success" + else: + print "DHCP connection failed: Reason unknown" + return 'dhcp_failed' + def _parse_dhcpcd(self, pipe): + dhcpcd_complete = False + dhcpcd_success = True + + while not dhcpcd_complete: + line = pipe.readline() + if line.startswith("Error"): + dhcpcd_success = False + dhcpcd_complete = True + elif line == '': + dhcpcd_complete = True + print line + + if dhcpcd_success: + print "DHCP connection successful" + return "success" + else: + print "DHCP connection failed" + return "dhcp_failed" + def StartDHCP(self): """ Start the DHCP client to obtain an IP address. """ - # TODO: Not all distros use dhclient to get an IP. We should - # add a way to determine what method is used (or let the user tell - # us), and run the cmd based on that. - cmd = 'dhclient ' + self.iface + self.CheckDHCP() + DHCP_CLIENT = self.DHCP_CLIENT + + cmd = DHCP_CLIENT + " " + self.iface if self.verbose: print cmd pipe = misc.Run(cmd, include_stderr=True, return_pipe=True) - return self._parse_dhclient(pipe) + if DHCP_CLIENT == "dhclient": + return self._parse_dhclient(pipe) + elif DHCP_CLIENT == "pump -i": + return self._parse_pump(pipe) + elif DHCP_CLIENT == "dhcpcd": + return self._parse_dhcpcd(pipe) def StopDHCP(self): """ Stop the DHCP client. """ - cmd = 'killall dhclient dhclient3' + cmd = 'killall dhclient dhclient3 pump dhcpcd-bin' if self.verbose: print cmd misc.Run(cmd)