mirror of
https://github.com/gryf/wicd.git
synced 2025-12-22 22:27:59 +01:00
Fix issue where GetForcedDisconnect was returning True when we had just connected.
Fix issues with auto-switch to wired. Change to how the gui handles changing state from connecting to not-connecting to be nicer. Make the gui trigger monitor state updates while in the connecting state. Make sure the monitor logs a warning when it catches a D-Bus exception. Make sure cancelling a wired connection attempt kills DHCP. Fix issue where DHCP wouldn't get run if automatic dhcp tool was enabled.
This commit is contained in:
20
wicd/gui.py
20
wicd/gui.py
@@ -197,6 +197,7 @@ class appGui(object):
|
||||
self.connecting = False
|
||||
self.refreshing = False
|
||||
self.prev_state = None
|
||||
self.update_cb = None
|
||||
self.network_list.set_sensitive(False)
|
||||
label = gtk.Label("%s..." % language['scanning'])
|
||||
self.network_list.pack_start(label)
|
||||
@@ -356,10 +357,11 @@ class appGui(object):
|
||||
if not self.is_visible:
|
||||
return True
|
||||
|
||||
daemon.UpdateState()
|
||||
if self.connecting:
|
||||
# If we're connecting, don't wait for the monitor to send
|
||||
# us a signal, since it won't until the connection is made.
|
||||
self._do_statusbar_update(*daemon.GetConnectionStatus())
|
||||
else:
|
||||
daemon.UpdateState()
|
||||
return True
|
||||
|
||||
def _do_statusbar_update(self, state, info):
|
||||
@@ -377,12 +379,16 @@ class appGui(object):
|
||||
return True
|
||||
|
||||
def set_wired_state(self, info):
|
||||
self._set_not_connecting_state()
|
||||
if self.connecting:
|
||||
# Adjust our state from connecting->connected.
|
||||
self._set_not_connecting_state()
|
||||
self.set_status(language['connected_to_wired'].replace('$A', info[0]))
|
||||
return True
|
||||
|
||||
def set_wireless_state(self, info):
|
||||
self._set_not_connecting_state()
|
||||
if self.connecting:
|
||||
# Adjust our state from connecting->connected.
|
||||
self._set_not_connecting_state()
|
||||
self.set_status(language['connected_to_wireless'].replace
|
||||
('$A', info[1]).replace
|
||||
('$B', daemon.FormatSignalForPrinting(info[2])).replace
|
||||
@@ -391,12 +397,13 @@ class appGui(object):
|
||||
|
||||
def set_not_connected_state(self, info):
|
||||
if self.connecting:
|
||||
# Adjust our state from connecting->not-connected.
|
||||
self._set_not_connecting_state()
|
||||
self.set_status(language['not_connected'])
|
||||
return True
|
||||
|
||||
def _set_not_connecting_state(self):
|
||||
if self.connecting:
|
||||
if self.connecting and self.update_cb:
|
||||
gobject.source_remove(self.update_cb)
|
||||
self.update_cb = misc.timeout_add(2, self.update_statusbar)
|
||||
self.connecting = False
|
||||
@@ -408,7 +415,7 @@ class appGui(object):
|
||||
gobject.idle_add(self.status_bar.remove, 1, self.statusID)
|
||||
|
||||
def set_connecting_state(self, info):
|
||||
if not self.connecting:
|
||||
if not self.connecting and self.update_cb:
|
||||
gobject.source_remove(self.update_cb)
|
||||
self.update_cb = misc.timeout_add(500, self.update_statusbar,
|
||||
milli=True)
|
||||
@@ -661,6 +668,7 @@ class appGui(object):
|
||||
"""
|
||||
widget.hide()
|
||||
networkentry.connect_button.show()
|
||||
daemon.SetForcedDisconnect(True)
|
||||
if nettype == "wired":
|
||||
wired.DisconnectWired()
|
||||
else:
|
||||
|
||||
@@ -53,7 +53,8 @@ def diewithdbus(func):
|
||||
ret = func(self, *__args, **__kargs)
|
||||
self.__lost_dbus_count = 0
|
||||
return ret
|
||||
except dbusmanager.DBusException:
|
||||
except dbusmanager.DBusException, e:
|
||||
print "Caught exception %e" % str(e)
|
||||
if not hasattr(self, "__lost_dbus_count"):
|
||||
self.__lost_dbus_count = 0
|
||||
if self.__lost_dbus_count > 3:
|
||||
@@ -102,6 +103,7 @@ class ConnectionStatus(object):
|
||||
2) A wired connection is currently active.
|
||||
|
||||
"""
|
||||
self.trigger_reconnect = False
|
||||
if not wired_ip and daemon.GetPreferWiredNetwork():
|
||||
if not daemon.GetForcedDisconnect() and wired.CheckPluggedIn():
|
||||
self.trigger_reconnect = True
|
||||
@@ -196,15 +198,6 @@ class ConnectionStatus(object):
|
||||
# Check for wired.
|
||||
wired_ip = wired.GetWiredIP("")
|
||||
wired_found = self.check_for_wired_connection(wired_ip)
|
||||
# Trigger an AutoConnect if we're plugged in, not connected
|
||||
# to a wired network, and the "autoswitch to wired" option
|
||||
# is on.
|
||||
if self.trigger_reconnect:
|
||||
self.trigger_reconnect = False
|
||||
wireless.DisconnectWireless()
|
||||
daemon.AutoConnect(False, reply_handler=lambda:None,
|
||||
error_handler=lambda:None)
|
||||
return True
|
||||
if wired_found:
|
||||
self.update_state(misc.WIRED, wired_ip=wired_ip)
|
||||
return True
|
||||
@@ -214,6 +207,22 @@ class ConnectionStatus(object):
|
||||
self.signal_changed = False
|
||||
wireless_found = self.check_for_wireless_connection(wifi_ip)
|
||||
if wireless_found:
|
||||
if self.trigger_reconnect:
|
||||
# If we made it here, that means we want to switch
|
||||
# to a wired network whenever possible, but a wireless
|
||||
# connection is active. So we kill the wireless connection
|
||||
# so the autoconnect logic will connect to the wired network.
|
||||
self.trigger_reconnect = False
|
||||
|
||||
# Don't trigger it if the gui is open, because autoconnect
|
||||
# is disabled while it's open.
|
||||
if not daemon.GetGUIOpen():
|
||||
print 'Killing wireless connection to switch to wired...'
|
||||
wireless.DisconnectWireless()
|
||||
daemon.AutoConnect(False, reply_handler=lambda:None,
|
||||
error_handler=lambda:None)
|
||||
self.update_state(misc.NOT_CONNECTED)
|
||||
return True
|
||||
self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
|
||||
return True
|
||||
|
||||
|
||||
@@ -218,6 +218,7 @@ class Controller(object):
|
||||
|
||||
def KillDHCP(self):
|
||||
""" Kill the managed DHCP client if its in a connecting state. """
|
||||
print 'running kill dhcp.'
|
||||
if (self.connecting_thread.is_connecting and
|
||||
self.iface.dhcp_object):
|
||||
if self.iface.dhcp_object.poll() is None:
|
||||
|
||||
@@ -323,12 +323,15 @@ class WicdDaemon(dbus.service.Object):
|
||||
|
||||
"""
|
||||
print "Autoconnecting..."
|
||||
if self.CheckIfConnecting():
|
||||
if self.debug_mode:
|
||||
print 'Already connecting, doing nothing.'
|
||||
return
|
||||
# We don't want to rescan/connect if the gui is open.
|
||||
if self.gui_open:
|
||||
if self.debug_mode:
|
||||
print "Skipping autoconnect because GUI is open."
|
||||
return
|
||||
|
||||
if self.wired_bus.CheckPluggedIn():
|
||||
if self.debug_mode:
|
||||
print "Starting wired autoconnect..."
|
||||
@@ -388,6 +391,7 @@ class WicdDaemon(dbus.service.Object):
|
||||
if self.wired.connecting_thread:
|
||||
self.wired.connecting_thread.should_die = True
|
||||
self.wired.ReleaseDHCP()
|
||||
self.wired.KillDHCP()
|
||||
self.wired.connecting_thread.connect_result = 'aborted'
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
@@ -425,9 +429,7 @@ class WicdDaemon(dbus.service.Object):
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def GetForcedDisconnect(self):
|
||||
""" Returns the forced_disconnect status. See SetForcedDisconnect. """
|
||||
return (bool(self.forced_disconnect) or
|
||||
bool(self.wireless_bus.GetForcedDisconnect()) or
|
||||
bool(self.wired_bus.GetForcedDisconnect()))
|
||||
return bool(self.forced_disconnect)
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def SetForcedDisconnect(self, value):
|
||||
@@ -440,8 +442,6 @@ class WicdDaemon(dbus.service.Object):
|
||||
"""
|
||||
if self.debug_mode and value: print "Forced disconnect on"
|
||||
self.forced_disconnect = bool(value)
|
||||
self.wireless_bus.SetForcedDisconnect(bool(value))
|
||||
self.wired_bus.SetForcedDisconnect(bool(value))
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def GetSignalDisplayType(self):
|
||||
@@ -923,7 +923,6 @@ class WirelessDaemon(dbus.service.Object):
|
||||
self.daemon = daemon
|
||||
self.wifi = wifi
|
||||
self._debug_mode = debug
|
||||
self.forced_disconnect = False
|
||||
self._scanning = False
|
||||
self.LastScan = []
|
||||
self.config = ConfigManager(os.path.join(wpath.etc,
|
||||
@@ -1041,26 +1040,9 @@ class WirelessDaemon(dbus.service.Object):
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def DisconnectWireless(self):
|
||||
""" Disconnects the wireless network. """
|
||||
self.SetForcedDisconnect(True)
|
||||
self.wifi.Disconnect()
|
||||
self.daemon.UpdateState()
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetForcedDisconnect(self):
|
||||
""" Returns the forced_disconnect status. See SetForcedDisconnect. """
|
||||
return bool(self.forced_disconnect)
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetForcedDisconnect(self, value):
|
||||
""" Sets the forced_disconnect status.
|
||||
|
||||
Set to True when a user manually disconnects or cancels a connection.
|
||||
It gets set to False as soon as the connection process is manually
|
||||
started.
|
||||
|
||||
"""
|
||||
self.forced_disconnect = bool(value)
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def IsWirelessUp(self):
|
||||
""" Returns a boolean specifying if wireless is up or down. """
|
||||
@@ -1119,13 +1101,13 @@ class WirelessDaemon(dbus.service.Object):
|
||||
# Will returned instantly, that way we don't hold up dbus.
|
||||
# CheckIfWirelessConnecting can be used to test if the connection
|
||||
# is done.
|
||||
self.SetForcedDisconnect(False)
|
||||
self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript')
|
||||
self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript')
|
||||
self.wifi.disconnect_script = self.GetWirelessProperty(id,
|
||||
'disconnectscript')
|
||||
print 'Connecting to wireless network ' + self.LastScan[id]['essid']
|
||||
self.daemon.wired_bus.DisconnectWired()
|
||||
self.daemon.wired_bus.wired.Disconnect()
|
||||
self.daemon.SetForcedDisconnect(False)
|
||||
conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
|
||||
self.daemon.UpdateState()
|
||||
|
||||
@@ -1298,7 +1280,6 @@ class WiredDaemon(dbus.service.Object):
|
||||
self.daemon = daemon
|
||||
self.wired = wired
|
||||
self._debug_mode = debug
|
||||
self.forced_disconnect = False
|
||||
self.WiredNetwork = {}
|
||||
self.config = ConfigManager(os.path.join(wpath.etc,
|
||||
"wired-settings.conf"),
|
||||
@@ -1378,7 +1359,6 @@ class WiredDaemon(dbus.service.Object):
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def DisconnectWired(self):
|
||||
""" Disconnects the wired network. """
|
||||
self.SetForcedDisconnect(True)
|
||||
self.wired.Disconnect()
|
||||
self.daemon.UpdateState()
|
||||
|
||||
@@ -1405,30 +1385,14 @@ class WiredDaemon(dbus.service.Object):
|
||||
""" Calls a method to disable the wired interface. """
|
||||
return self.wired.DisableInterface()
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def GetForcedDisconnect(self):
|
||||
""" Returns the forced_disconnect status. See SetForcedDisconnect. """
|
||||
return bool(self.forced_disconnect)
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def SetForcedDisconnect(self, value):
|
||||
""" Sets the forced_disconnect status.
|
||||
|
||||
Set to True when a user manually disconnects or cancels a connection.
|
||||
It gets set to False as soon as the connection process is manually
|
||||
started.
|
||||
|
||||
"""
|
||||
self.forced_disconnect = bool(value)
|
||||
|
||||
@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")
|
||||
self.daemon.wireless_bus.DisconnectWireless()
|
||||
self.daemon.wireless_bus.wifi.Disconnect()
|
||||
self.daemon.SetForcedDisconnect(False)
|
||||
self.wired.Connect(self.WiredNetwork, debug=self.debug_mode)
|
||||
self.daemon.UpdateState()
|
||||
|
||||
|
||||
@@ -217,15 +217,22 @@ class BaseInterface(object):
|
||||
cmd = ""
|
||||
return (client, cmd)
|
||||
|
||||
connect_dict = {
|
||||
"dhclient" : r"%s %s",
|
||||
"pump" : r"%s -i %s",
|
||||
"dhcpcd" : r"%s %s",
|
||||
}
|
||||
release_dict = {
|
||||
"dhclient" : r"%s -r %s",
|
||||
"pump" : r"%s -r -i %s",
|
||||
"dhcpcd" : r"%s -k %s",
|
||||
client_dict = {
|
||||
"dhclient" :
|
||||
{'connect' : r"%s %s",
|
||||
'release' : r"%s -r %s",
|
||||
'id' : misc.DHCLIENT,
|
||||
},
|
||||
"pump" :
|
||||
{ 'connect' : r"%s -i %s",
|
||||
'release' : r"%s -r -i %s",
|
||||
'id' : misc.PUMP,
|
||||
},
|
||||
"dhcpcd" :
|
||||
{'connect' : r"%s %s",
|
||||
'release' : r"%s -k %s",
|
||||
'id' : misc.DHCPCD,
|
||||
},
|
||||
}
|
||||
(client_name, cmd) = get_client_name(self.DHCP_CLIENT)
|
||||
if not client_name or not cmd:
|
||||
@@ -233,11 +240,11 @@ class BaseInterface(object):
|
||||
return ""
|
||||
|
||||
if flavor == "connect":
|
||||
return connect_dict[client_name] % (cmd, self.iface)
|
||||
return client_dict[client_name]['connect'] % (cmd, self.iface)
|
||||
elif flavor == "release":
|
||||
return release_dict[client_name] % (cmd, self.iface)
|
||||
return client_dict[client_name]['release'] % (cmd, self.iface)
|
||||
else:
|
||||
return str(cmd)
|
||||
return client_dict[client_name]['id']
|
||||
|
||||
def AppAvailable(self, app):
|
||||
""" Return whether a given app is available.
|
||||
@@ -451,18 +458,19 @@ class BaseInterface(object):
|
||||
if not self.iface: return False
|
||||
|
||||
cmd = self._get_dhcp_command('connect')
|
||||
#cmd = self.DHCP_CMD + " " + self.iface
|
||||
if self.verbose: print cmd
|
||||
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
|
||||
pipe = self.dhcp_object.stdout
|
||||
|
||||
DHCP_CLIENT = self.DHCP_CLIENT
|
||||
DHCP_CLIENT = self._get_dhcp_command()
|
||||
if DHCP_CLIENT == misc.DHCLIENT:
|
||||
return self._parse_dhclient(pipe)
|
||||
elif DHCP_CLIENT == misc.PUMP:
|
||||
return self._parse_pump(pipe)
|
||||
elif DHCP_CLIENT == misc.DHCPCD:
|
||||
return self._parse_dhcpcd(pipe)
|
||||
else:
|
||||
print 'ERROR no dhclient found!'
|
||||
|
||||
def ReleaseDHCP(self):
|
||||
""" Release the DHCP lease for this interface. """
|
||||
|
||||
Reference in New Issue
Block a user