1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-21 05:18:02 +01:00

Added support for two more DHCP clients: pump and dhcpcd.

Added check when DHCP is run to determine what DHCP clients are available.
Fixed bug where sometimes wicd wouldn't reconnect automatically when a wired connection was lost.
Cleaned up a couple of comments.
This commit is contained in:
imdano
2008-02-13 13:08:15 +00:00
parent 1bebb0bae2
commit d7141a8b78
3 changed files with 70 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
""" wicd - wireless connection daemon implementation. """ wicd - wireless connection daemon implementation.
This module implements the wicd daemon that provides network This module implements the wicd daemon that provides network
@@ -463,7 +464,6 @@ class ConnectionWizard(dbus.service.Object):
""" """
self.forced_disconnect = bool(value) self.forced_disconnect = bool(value)
#end function SetForcedDisconnect
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetGUIOpen(self): def GetGUIOpen(self):
@@ -830,6 +830,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def ConnectWired(self): def ConnectWired(self):
"""connects to a wired network. """ """connects to a wired network. """
self.SetForcedDisconnect(False)
self.wired.before_script = self.GetWiredProperty("beforescript") self.wired.before_script = self.GetWiredProperty("beforescript")
self.wired.after_script = self.GetWiredProperty("afterscript") self.wired.after_script = self.GetWiredProperty("afterscript")
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript") self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")

2
gui.py
View File

@@ -1361,7 +1361,7 @@ class appGui:
if entry.checkboxStaticDNS.get_active() and \ if entry.checkboxStaticDNS.get_active() and \
not entry.checkboxGlobalDNS.get_active(): not entry.checkboxGlobalDNS.get_active():
entlist.append(entry.txtDNS1) 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]: for ent in [entry.txtDNS2, entry.txtDNS3]:
if ent.get_text() != "": if ent.get_text() != "":
entlist.append(ent) entlist.append(ent)

View File

@@ -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) auth_pattern = re.compile('.*wpa_state=(.*?)\n', re.I | re.M | re.S)
RALINK_DRIVER = 'ralink legacy' RALINK_DRIVER = 'ralink legacy'
DHCP_CLIENT = None
def SetDNS(dns1=None, dns2=None, dns3=None): def SetDNS(dns1=None, dns2=None, dns3=None):
@@ -122,6 +123,20 @@ class Interface(object):
self.iface = iface self.iface = iface
self.verbose = verbose 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): def Check(self):
""" Check that all required tools are available.""" """ Check that all required tools are available."""
# TODO: Implement this function. # TODO: Implement this function.
@@ -194,21 +209,67 @@ class Interface(object):
else: else:
print 'DHCP connection failed: Reason unknown' print 'DHCP connection failed: Reason unknown'
return 'dhcp_failed' 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): def StartDHCP(self):
""" Start the DHCP client to obtain an IP address. """ """ Start the DHCP client to obtain an IP address. """
# TODO: Not all distros use dhclient to get an IP. We should self.CheckDHCP()
# add a way to determine what method is used (or let the user tell DHCP_CLIENT = self.DHCP_CLIENT
# us), and run the cmd based on that.
cmd = 'dhclient ' + self.iface cmd = DHCP_CLIENT + " " + self.iface
if self.verbose: print cmd if self.verbose: print cmd
pipe = misc.Run(cmd, include_stderr=True, return_pipe=True) 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): def StopDHCP(self):
""" Stop the DHCP client. """ """ Stop the DHCP client. """
cmd = 'killall dhclient dhclient3' cmd = 'killall dhclient dhclient3 pump dhcpcd-bin'
if self.verbose: print cmd if self.verbose: print cmd
misc.Run(cmd) misc.Run(cmd)