mirror of
https://github.com/gryf/wicd.git
synced 2025-12-19 20:38:00 +01:00
Improved automatic reconnection behavior.
Improved debug mode behavior. Improved the way networking.py interfaces passes attributes on to wnettools.py interfaces. Fixed crash in __printReturn when a parameter to return wasn't of type 'str'.
This commit is contained in:
@@ -292,6 +292,8 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
configfile = open(self.app_conf, "w")
|
configfile = open(self.app_conf, "w")
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
self.debug_mode = misc.to_bool(debug)
|
self.debug_mode = misc.to_bool(debug)
|
||||||
|
self.wifi.debug = self.debug_mode
|
||||||
|
self.wired.debug = self.debug_mode
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetDebugMode(self):
|
def GetDebugMode(self):
|
||||||
@@ -750,7 +752,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
self.wifi.disconnect_script = self.GetWirelessProperty(id,
|
self.wifi.disconnect_script = self.GetWirelessProperty(id,
|
||||||
'disconnectscript')
|
'disconnectscript')
|
||||||
print 'Connecting to wireless network', self.LastScan[id]['essid']
|
print 'Connecting to wireless network', self.LastScan[id]['essid']
|
||||||
return self.wifi.Connect(self.LastScan[id])
|
return self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def CheckIfWirelessConnecting(self):
|
def CheckIfWirelessConnecting(self):
|
||||||
@@ -901,7 +903,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
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")
|
||||||
self.wired.Connect(self.WiredNetwork)
|
self.wired.Connect(self.WiredNetwork, debug=self.debug_mode)
|
||||||
|
|
||||||
########## LOG FILE STUFF
|
########## LOG FILE STUFF
|
||||||
#################################
|
#################################
|
||||||
@@ -1193,7 +1195,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
def __printReturn(self, text, value):
|
def __printReturn(self, text, value):
|
||||||
"""prints the specified text and value, then returns the value"""
|
"""prints the specified text and value, then returns the value"""
|
||||||
if self.debug_mode:
|
if self.debug_mode:
|
||||||
print text + " " + value
|
print ''.join([text, " ", str(value)])
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def get_option(self, section, option, default=None):
|
def get_option(self, section, option, default=None):
|
||||||
|
|||||||
35
monitor.py
35
monitor.py
@@ -163,7 +163,11 @@ class ConnectionStatus():
|
|||||||
state = misc.CONNECTING
|
state = misc.CONNECTING
|
||||||
else: # No connection at all.
|
else: # No connection at all.
|
||||||
state = misc.NOT_CONNECTED
|
state = misc.NOT_CONNECTED
|
||||||
self.auto_reconnect()
|
if self.last_state == misc.WIRELESS:
|
||||||
|
from_wireless = True
|
||||||
|
else:
|
||||||
|
from_wireless = False
|
||||||
|
self.auto_reconnect(from_wireless)
|
||||||
self.update_state(state)
|
self.update_state(state)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -197,7 +201,7 @@ class ConnectionStatus():
|
|||||||
self.last_state = state
|
self.last_state = state
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def auto_reconnect(self):
|
def auto_reconnect(self, from_wireless=None):
|
||||||
""" Automatically reconnects to a network if needed.
|
""" Automatically reconnects to a network if needed.
|
||||||
|
|
||||||
If automatic reconnection is turned on, this method will
|
If automatic reconnection is turned on, this method will
|
||||||
@@ -215,27 +219,14 @@ class ConnectionStatus():
|
|||||||
if daemon.GetAutoReconnect() and not daemon.CheckIfConnecting() and \
|
if daemon.GetAutoReconnect() and not daemon.CheckIfConnecting() and \
|
||||||
not daemon.GetForcedDisconnect() and not daemon.GetAutoConnecting():
|
not daemon.GetForcedDisconnect() and not daemon.GetAutoConnecting():
|
||||||
print 'Starting automatic reconnect process'
|
print 'Starting automatic reconnect process'
|
||||||
# First try connecting through ethernet
|
|
||||||
if wired.CheckPluggedIn():
|
# If we just lost a wireless connection, try to connect to that
|
||||||
print "Wired connection available, trying to connect..."
|
# network again. Otherwise just call Autoconnect.
|
||||||
daemon.AutoConnect(False, reply_handler=reply_handle,
|
|
||||||
error_handler=err_handle)
|
|
||||||
self.reconnecting = False
|
|
||||||
return
|
|
||||||
|
|
||||||
# Next try the last wireless network we were connected to
|
|
||||||
cur_net_id = wireless.GetCurrentNetworkID(self.iwconfig)
|
cur_net_id = wireless.GetCurrentNetworkID(self.iwconfig)
|
||||||
if cur_net_id > -1: # Needs to be a valid network
|
if from_wireless and cur_net_id > -1: # Needs to be a valid network
|
||||||
if not self.tried_reconnect:
|
print 'Trying to reconnect to last used wireless ' + \
|
||||||
print 'Trying to reconnect to last used wireless \
|
'network'
|
||||||
network'
|
wireless.ConnectWireless(cur_net_id)
|
||||||
wireless.ConnectWireless(cur_net_id)
|
|
||||||
self.tried_reconnect = True
|
|
||||||
elif not wireless.CheckIfWirelessConnecting():
|
|
||||||
print "Couldn't reconnect to last used network, \
|
|
||||||
scanning for an autoconnect network..."
|
|
||||||
daemon.AutoConnect(True, reply_handler=reply_handle,
|
|
||||||
error_handler=err_handle)
|
|
||||||
else:
|
else:
|
||||||
daemon.AutoConnect(True, reply_handler=reply_handle,
|
daemon.AutoConnect(True, reply_handler=reply_handle,
|
||||||
error_handler=err_handle)
|
error_handler=err_handle)
|
||||||
|
|||||||
@@ -56,8 +56,6 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
""" Parent class for the different interface types. """
|
""" Parent class for the different interface types. """
|
||||||
wireless_interface = None
|
|
||||||
wired_interface = None
|
|
||||||
connecting_thread = None
|
connecting_thread = None
|
||||||
before_script = None
|
before_script = None
|
||||||
after_script = None
|
after_script = None
|
||||||
@@ -65,30 +63,45 @@ class Controller(object):
|
|||||||
driver = None
|
driver = None
|
||||||
wiface = None
|
wiface = None
|
||||||
liface = None
|
liface = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Initialise the class. """
|
""" Initialise the class. """
|
||||||
self.global_dns_1 = None
|
self.global_dns_1 = None
|
||||||
self.global_dns_2 = None
|
self.global_dns_2 = None
|
||||||
self.global_dns_3 = None
|
self.global_dns_3 = None
|
||||||
|
self._wired_interface = None
|
||||||
|
self._wireless_interface = None
|
||||||
|
self._debug = None
|
||||||
|
|
||||||
def __setattr__(self, attr, value):
|
def set_wireless_iface(self, value):
|
||||||
""" Provided custom self.variable assignments.
|
self._wireless_interface = value
|
||||||
|
if self.wiface:
|
||||||
Calls the appropriate methods if self.wireless_interface or
|
self.wiface.SetInterface(value)
|
||||||
self.wired_interface is set.
|
|
||||||
|
def get_wireless_iface(self):
|
||||||
|
return self._wireless_interface
|
||||||
|
|
||||||
"""
|
def set_wired_iface(self, value):
|
||||||
if attr == 'wireless_interface':
|
self._wired_interface = value
|
||||||
object.__setattr__(self, attr, value)
|
if self.liface:
|
||||||
if self.wiface:
|
self.liface.SetInterface(value)
|
||||||
self.SetWiface(value)
|
|
||||||
elif attr == 'wired_interface':
|
def get_wired_iface(self):
|
||||||
object.__setattr__(self, attr, value)
|
return self._wired_interface
|
||||||
if self.liface:
|
|
||||||
self.SetLiface(value)
|
def set_debug(self, value):
|
||||||
else:
|
self._debug = value
|
||||||
object.__setattr__(self, attr, value)
|
if self.wiface:
|
||||||
|
self.wiface.SetDebugMode(value)
|
||||||
|
if self.liface:
|
||||||
|
self.liface.SetDebugMode(value)
|
||||||
|
|
||||||
|
def get_debug(self):
|
||||||
|
return self._debug
|
||||||
|
|
||||||
|
wireless_interface = property(get_wireless_iface, set_wireless_iface)
|
||||||
|
wired_interface = property(get_wired_iface, set_wired_iface)
|
||||||
|
debug = property(get_debug, set_debug)
|
||||||
|
|
||||||
def SetWiface(self, iface):
|
def SetWiface(self, iface):
|
||||||
""" Sets the wireless interface for the associated wnettools class. """
|
""" Sets the wireless interface for the associated wnettools class. """
|
||||||
@@ -303,22 +316,24 @@ class Wireless(Controller):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Initialize the class. """
|
""" Initialize the class. """
|
||||||
Controller.__init__(self)
|
Controller.__init__(self)
|
||||||
self.wpa_driver = None
|
self._wpa_driver = None
|
||||||
self.wiface = wnettools.WirelessInterface(self.wireless_interface,
|
self.wiface = wnettools.WirelessInterface(self.wireless_interface,
|
||||||
self.wpa_driver)
|
self.wpa_driver)
|
||||||
|
|
||||||
|
def set_wpa_driver(self, value):
|
||||||
|
self._wpa_driver = value
|
||||||
|
if self.wiface:
|
||||||
|
self.SetWPADriver(value)
|
||||||
|
|
||||||
|
def get_wpa_driver(self): return self._wpa_driver
|
||||||
|
|
||||||
|
wpa_driver = property(get_wpa_driver, set_wpa_driver)
|
||||||
|
|
||||||
def __setattr__(self, attr, value):
|
|
||||||
if attr == 'wpa_driver':
|
|
||||||
self.__dict__[attr] = value
|
|
||||||
if self.wiface:
|
|
||||||
self.SetWPADriver(value)
|
|
||||||
else:
|
|
||||||
object.__setattr__(self, attr, value)
|
|
||||||
|
|
||||||
def LoadInterfaces(self):
|
def LoadInterfaces(self):
|
||||||
""" Load the wnettools controls for the wired/wireless interfaces. """
|
""" Load the wnettools controls for the wired/wireless interfaces. """
|
||||||
self.wiface = wnettools.WirelessInterface(self.wireless_interface,
|
self.wiface = wnettools.WirelessInterface(self.wireless_interface,
|
||||||
self.wpa_driver)
|
self.debug, self.wpa_driver)
|
||||||
|
|
||||||
def Scan(self, essid=None):
|
def Scan(self, essid=None):
|
||||||
""" Scan for available wireless networks.
|
""" Scan for available wireless networks.
|
||||||
@@ -347,7 +362,7 @@ class Wireless(Controller):
|
|||||||
aps.sort(key=lambda x: x['strength'])
|
aps.sort(key=lambda x: x['strength'])
|
||||||
return aps
|
return aps
|
||||||
|
|
||||||
def Connect(self, network):
|
def Connect(self, network, debug=False):
|
||||||
""" Spawn a connection thread to connect to the network.
|
""" Spawn a connection thread to connect to the network.
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
@@ -358,7 +373,7 @@ class Wireless(Controller):
|
|||||||
self.wireless_interface, self.wired_interface,
|
self.wireless_interface, self.wired_interface,
|
||||||
self.wpa_driver, self.before_script, self.after_script,
|
self.wpa_driver, self.before_script, self.after_script,
|
||||||
self.disconnect_script, self.global_dns_1,
|
self.disconnect_script, self.global_dns_1,
|
||||||
self.global_dns_2, self.global_dns_3)
|
self.global_dns_2, self.global_dns_3, debug)
|
||||||
self.connecting_thread.setDaemon(True)
|
self.connecting_thread.setDaemon(True)
|
||||||
self.connecting_thread.start()
|
self.connecting_thread.start()
|
||||||
return True
|
return True
|
||||||
@@ -657,14 +672,14 @@ class Wired(Controller):
|
|||||||
""" Initialise the class. """
|
""" Initialise the class. """
|
||||||
Controller.__init__(self)
|
Controller.__init__(self)
|
||||||
self.wpa_driver = None
|
self.wpa_driver = None
|
||||||
self.liface = wnettools.WiredInterface(self.wired_interface)
|
self.liface = wnettools.WiredInterface(self.wired_interface, self.debug)
|
||||||
|
|
||||||
def __setattr__(self, attr, val):
|
def __setattr__(self, attr, val):
|
||||||
object.__setattr__(self, attr, val)
|
object.__setattr__(self, attr, val)
|
||||||
|
|
||||||
def LoadInterfaces(self):
|
def LoadInterfaces(self):
|
||||||
""" Load the wnettools controls for the wired/wireless interfaces. """
|
""" Load the wnettools controls for the wired/wireless interfaces. """
|
||||||
self.liface = wnettools.WiredInterface(self.wired_interface)
|
self.liface = wnettools.WiredInterface(self.wired_interface, self.debug)
|
||||||
|
|
||||||
def CheckPluggedIn(self):
|
def CheckPluggedIn(self):
|
||||||
""" Check whether the wired connection is plugged in.
|
""" Check whether the wired connection is plugged in.
|
||||||
@@ -675,7 +690,7 @@ class Wired(Controller):
|
|||||||
"""
|
"""
|
||||||
return self.liface.GetPluggedIn()
|
return self.liface.GetPluggedIn()
|
||||||
|
|
||||||
def Connect(self, network):
|
def Connect(self, network, debug=False):
|
||||||
""" Spawn a connection thread to connect to the network.
|
""" Spawn a connection thread to connect to the network.
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
@@ -686,7 +701,7 @@ class Wired(Controller):
|
|||||||
self.wireless_interface, self.wired_interface,
|
self.wireless_interface, self.wired_interface,
|
||||||
self.before_script, self.after_script,
|
self.before_script, self.after_script,
|
||||||
self.disconnect_script, self.global_dns_1,
|
self.disconnect_script, self.global_dns_1,
|
||||||
self.global_dns_2, self.global_dns_3)
|
self.global_dns_2, self.global_dns_3, debug)
|
||||||
self.connecting_thread.setDaemon(True)
|
self.connecting_thread.setDaemon(True)
|
||||||
self.connecting_thread.start()
|
self.connecting_thread.start()
|
||||||
return True
|
return True
|
||||||
|
|||||||
24
wnettools.py
24
wnettools.py
@@ -131,6 +131,10 @@ class Interface(object):
|
|||||||
self.IP_FOUND = False
|
self.IP_FOUND = False
|
||||||
self.Check()
|
self.Check()
|
||||||
|
|
||||||
|
def SetDebugMode(self, value):
|
||||||
|
""" If True, verbose output is enabled. """
|
||||||
|
self.verbose = value
|
||||||
|
|
||||||
def SetInterface(self, iface):
|
def SetInterface(self, iface):
|
||||||
""" Sets the interface.
|
""" Sets the interface.
|
||||||
|
|
||||||
@@ -204,7 +208,7 @@ class Interface(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
cmd = 'ifconfig ' + self.iface + ' up'
|
cmd = 'ifconfig ' + self.iface + ' up'
|
||||||
#if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -390,7 +394,7 @@ class Interface(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
cmd = 'ifconfig ' + self.iface
|
cmd = 'ifconfig ' + self.iface
|
||||||
#if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
output = misc.Run(cmd)
|
output = misc.Run(cmd)
|
||||||
return misc.RunRegex(ip_pattern, output)
|
return misc.RunRegex(ip_pattern, output)
|
||||||
|
|
||||||
@@ -514,7 +518,7 @@ class WirelessInterface(Interface):
|
|||||||
essid -- essid to set the interface to
|
essid -- essid to set the interface to
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cmd = 'iwconfig ' + self.iface + ' essid "' + essid + '"'
|
cmd = ''.join(['iwconfig ', self.iface, ' essid "', essid, '"'])
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
@@ -573,7 +577,7 @@ class WirelessInterface(Interface):
|
|||||||
access_points = []
|
access_points = []
|
||||||
for cell in networks:
|
for cell in networks:
|
||||||
# Only use sections where there is an ESSID.
|
# Only use sections where there is an ESSID.
|
||||||
if cell.count('ESSID:') > 0:
|
if 'ESSID:' in cell:
|
||||||
# Add this network to the list of networks
|
# Add this network to the list of networks
|
||||||
entry = self._ParseAccessPoint(cell, ralink_info)
|
entry = self._ParseAccessPoint(cell, ralink_info)
|
||||||
if entry is not None:
|
if entry is not None:
|
||||||
@@ -891,9 +895,11 @@ class WirelessInterface(Interface):
|
|||||||
if len(info) < 5:
|
if len(info) < 5:
|
||||||
break
|
break
|
||||||
if info[2] == network.get('essid'):
|
if info[2] == network.get('essid'):
|
||||||
if info[5] == 'WEP' or (info[5] == 'OPEN' and info[4] == 'WEP'):
|
if info[5] == 'WEP' or (info[5] == 'OPEN' and \
|
||||||
|
info[4] == 'WEP'):
|
||||||
print 'Setting up WEP'
|
print 'Setting up WEP'
|
||||||
cmd = 'iwconfig ' + self.iface + ' key ' + network.get('key')
|
cmd = ''.join(['iwconfig ', self.iface, ' key ',
|
||||||
|
network.get('key')])
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
else:
|
else:
|
||||||
@@ -939,7 +945,7 @@ class WirelessInterface(Interface):
|
|||||||
"""
|
"""
|
||||||
if not iwconfig:
|
if not iwconfig:
|
||||||
cmd = 'iwconfig ' + self.iface
|
cmd = 'iwconfig ' + self.iface
|
||||||
# if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
output = misc.Run(cmd)
|
output = misc.Run(cmd)
|
||||||
else:
|
else:
|
||||||
output = iwconfig
|
output = iwconfig
|
||||||
@@ -968,7 +974,7 @@ class WirelessInterface(Interface):
|
|||||||
"""
|
"""
|
||||||
if iwconfig:
|
if iwconfig:
|
||||||
cmd = 'iwconfig ' + self.iface
|
cmd = 'iwconfig ' + self.iface
|
||||||
# if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
output = misc.Run(cmd)
|
output = misc.Run(cmd)
|
||||||
else:
|
else:
|
||||||
output = iwconfig
|
output = iwconfig
|
||||||
@@ -985,7 +991,7 @@ class WirelessInterface(Interface):
|
|||||||
"""
|
"""
|
||||||
if not iwconfig:
|
if not iwconfig:
|
||||||
cmd = 'iwconfig ' + self.iface
|
cmd = 'iwconfig ' + self.iface
|
||||||
# if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
output = misc.Run(cmd)
|
output = misc.Run(cmd)
|
||||||
else:
|
else:
|
||||||
output = iwconfig
|
output = iwconfig
|
||||||
|
|||||||
Reference in New Issue
Block a user