mirror of
https://github.com/gryf/wicd.git
synced 2026-01-05 13:24:13 +01:00
Merged r219 from main experimental branch.
This commit is contained in:
@@ -98,6 +98,10 @@ def GetWiredInterfaces(*args, **kargs):
|
|||||||
""" Call the wnettools GetWiredInterfaces method. """
|
""" Call the wnettools GetWiredInterfaces method. """
|
||||||
return wnettools.GetWiredInterfaces(*args, **kargs)
|
return wnettools.GetWiredInterfaces(*args, **kargs)
|
||||||
|
|
||||||
|
def IsValidWpaSuppDriver(*args, **kargs):
|
||||||
|
""" Call the wnettools IsValidWpaSuppDrive method. """
|
||||||
|
return wnettools.IsValidWpaSuppDriver(*args, **kargs)
|
||||||
|
|
||||||
def NeedsExternalCalls(*args, **kargs):
|
def NeedsExternalCalls(*args, **kargs):
|
||||||
""" Return True, since this backend using iwconfig/ifconfig. """
|
""" Return True, since this backend using iwconfig/ifconfig. """
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ def GetWiredInterfaces(*args, **kargs):
|
|||||||
""" Call the wnettools GetWiredInterfaces method. """
|
""" Call the wnettools GetWiredInterfaces method. """
|
||||||
return wnettools.GetWiredInterfaces(*args, **kargs)
|
return wnettools.GetWiredInterfaces(*args, **kargs)
|
||||||
|
|
||||||
|
def IsValidWpaSuppDriver(*args, **kargs):
|
||||||
|
""" Call the wnettools IsValidWpaSuppDrive method. """
|
||||||
|
return wnettools.IsValidWpaSuppDriver(*args, **kargs)
|
||||||
|
|
||||||
def get_iw_ioctl_result(iface, call):
|
def get_iw_ioctl_result(iface, call):
|
||||||
""" Makes the given ioctl call and returns the results.
|
""" Makes the given ioctl call and returns the results.
|
||||||
|
|
||||||
|
|||||||
55
wicd/gui.py
55
wicd/gui.py
@@ -84,38 +84,30 @@ def handle_no_dbus(from_tray=False):
|
|||||||
DBUS_AVAIL = False
|
DBUS_AVAIL = False
|
||||||
if from_tray: return False
|
if from_tray: return False
|
||||||
print "Wicd daemon is shutting down!"
|
print "Wicd daemon is shutting down!"
|
||||||
error(None, "The wicd daemon has shut down, the UI will not function properly until it is restarted.")
|
error(None, language['lost_dbus'], block=False)
|
||||||
_wait_for_dbus()
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@misc.threaded
|
def error(parent, message, block=True):
|
||||||
def _wait_for_dbus():
|
|
||||||
global DBUS_AVAIL
|
|
||||||
while True:
|
|
||||||
time.sleep(10)
|
|
||||||
print "Trying to reconnect.."
|
|
||||||
if not setup_dbus(force=False):
|
|
||||||
print "Failed to reconnect to the daemon."
|
|
||||||
else:
|
|
||||||
print "Successfully reconnected to the daemon."
|
|
||||||
DBUS_AVAIL = True
|
|
||||||
return
|
|
||||||
|
|
||||||
def error(parent, message):
|
|
||||||
""" Shows an error dialog """
|
""" Shows an error dialog """
|
||||||
|
def delete_event(dialog, id):
|
||||||
|
dialog.destroy()
|
||||||
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
|
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
|
||||||
gtk.BUTTONS_OK)
|
gtk.BUTTONS_OK)
|
||||||
dialog.set_markup(message)
|
dialog.set_markup(message)
|
||||||
dialog.run()
|
if not block:
|
||||||
dialog.destroy()
|
dialog.present()
|
||||||
|
dialog.connect("response", delete_event)
|
||||||
|
else:
|
||||||
|
dialog.run()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
def alert(parent, message):
|
def alert(parent, message):
|
||||||
""" Shows an error dialog """
|
""" Shows an warning dialog """
|
||||||
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
|
dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING,
|
||||||
gtk.BUTTONS_OK)
|
gtk.BUTTONS_OK)
|
||||||
dialog.set_markup(message)
|
dialog.set_markup(message)
|
||||||
dialog.run()
|
dialog.present()
|
||||||
dialog.destroy()
|
dialog.connect("response", lambda *args: dialog.destroy())
|
||||||
|
|
||||||
def dummy(x=None):pass
|
def dummy(x=None):pass
|
||||||
|
|
||||||
@@ -284,6 +276,7 @@ class appGui(object):
|
|||||||
self.first_dialog_load = True
|
self.first_dialog_load = True
|
||||||
self.is_visible = True
|
self.is_visible = True
|
||||||
self.pulse_active = False
|
self.pulse_active = False
|
||||||
|
self.pref = None
|
||||||
self.standalone = standalone
|
self.standalone = standalone
|
||||||
self.wpadrivercombo = None
|
self.wpadrivercombo = None
|
||||||
self.connecting = False
|
self.connecting = False
|
||||||
@@ -302,6 +295,10 @@ class appGui(object):
|
|||||||
'org.wicd.daemon.wireless')
|
'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(self.update_connect_buttons, 'StatusChanged',
|
bus.add_signal_receiver(self.update_connect_buttons, 'StatusChanged',
|
||||||
'org.wicd.daemon')
|
'org.wicd.daemon')
|
||||||
|
bus.add_signal_receiver(self.handle_connection_results,
|
||||||
|
'ConnectResultsSent', 'org.wicd.daemon')
|
||||||
|
bus.add_signal_receiver(lambda: setup_dbus(force=False),
|
||||||
|
"DaemonStarting", "org.wicd.daemon")
|
||||||
if standalone:
|
if standalone:
|
||||||
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
|
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
|
||||||
"org.wicd.daemon")
|
"org.wicd.daemon")
|
||||||
@@ -311,6 +308,10 @@ class appGui(object):
|
|||||||
gobject.timeout_add(1000, self.update_statusbar)
|
gobject.timeout_add(1000, self.update_statusbar)
|
||||||
|
|
||||||
self.refresh_clicked()
|
self.refresh_clicked()
|
||||||
|
|
||||||
|
def handle_connection_results(self, results):
|
||||||
|
if results not in ['Success', 'aborted'] and self.is_visible:
|
||||||
|
error(self.window, language[results], block=False)
|
||||||
|
|
||||||
def create_adhoc_network(self, widget=None):
|
def create_adhoc_network(self, widget=None):
|
||||||
""" Shows a dialog that creates a new adhoc network. """
|
""" Shows a dialog that creates a new adhoc network. """
|
||||||
@@ -384,10 +385,14 @@ class appGui(object):
|
|||||||
|
|
||||||
def settings_dialog(self, widget, event=None):
|
def settings_dialog(self, widget, event=None):
|
||||||
""" Displays a general settings dialog. """
|
""" Displays a general settings dialog. """
|
||||||
pref = PreferencesDialog(self.wTree, dbusmanager.get_dbus_ifaces())
|
if not self.pref:
|
||||||
if pref.run() == 1:
|
self.pref = PreferencesDialog(self.wTree,
|
||||||
pref.save_results()
|
dbusmanager.get_dbus_ifaces())
|
||||||
pref.hide()
|
else:
|
||||||
|
self.pref.load_preferences_diag()
|
||||||
|
if self.pref.run() == 1:
|
||||||
|
self.pref.save_results()
|
||||||
|
self.pref.hide()
|
||||||
|
|
||||||
def connect_hidden(self, widget):
|
def connect_hidden(self, widget):
|
||||||
""" Prompts the user for a hidden network, then scans for it. """
|
""" Prompts the user for a hidden network, then scans for it. """
|
||||||
|
|||||||
@@ -504,13 +504,15 @@ def get_language_list_gui():
|
|||||||
language['setting_static_ip'] = _('Setting static IP addresses...')
|
language['setting_static_ip'] = _('Setting static IP addresses...')
|
||||||
language['running_dhcp'] = _('Obtaining IP address...')
|
language['running_dhcp'] = _('Obtaining IP address...')
|
||||||
language['dhcp_failed'] = _('Connection Failed: Unable to Get IP Address')
|
language['dhcp_failed'] = _('Connection Failed: Unable to Get IP Address')
|
||||||
|
language['no_dhcp_offers'] = _('Connection Failed: No DHCP offers received.')
|
||||||
language['aborted'] = _('Connection Cancelled')
|
language['aborted'] = _('Connection Cancelled')
|
||||||
language['bad_pass'] = _('Connection Failed: Bad password')
|
language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)')
|
||||||
language['done'] = _('Done connecting...')
|
language['done'] = _('Done connecting...')
|
||||||
language['scanning'] = _('Scanning')
|
language['scanning'] = _('Scanning')
|
||||||
language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \
|
language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \
|
||||||
"This typically means there was a problem starting the daemon." + \
|
"This typically means there was a problem starting the daemon." + \
|
||||||
"Check the wicd log for more info")
|
"Check the wicd log for more info")
|
||||||
|
language['lost_dbus'] = _("The wicd daemon has shut down, the UI will not function properly until it is restarted.")
|
||||||
|
|
||||||
return language
|
return language
|
||||||
|
|
||||||
@@ -536,6 +538,7 @@ def get_language_list_tray():
|
|||||||
"This typically means there was a problem starting the daemon." + \
|
"This typically means there was a problem starting the daemon." + \
|
||||||
"Check the wicd log for more info")
|
"Check the wicd log for more info")
|
||||||
language['no_daemon_tooltip'] = _("Wicd daemon unreachable")
|
language['no_daemon_tooltip'] = _("Wicd daemon unreachable")
|
||||||
|
language['lost_dbus'] = _("The wicd daemon has shut down, the UI will not function properly until it is restarted.")
|
||||||
return language
|
return language
|
||||||
|
|
||||||
def noneToBlankString(text):
|
def noneToBlankString(text):
|
||||||
|
|||||||
@@ -146,6 +146,8 @@ class ConnectionStatus(object):
|
|||||||
state = misc.CONNECTING
|
state = misc.CONNECTING
|
||||||
self.update_state(state)
|
self.update_state(state)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
daemon.SendConnectResultsIfAvail()
|
||||||
|
|
||||||
# Check for wired.
|
# Check for wired.
|
||||||
wired_ip = wired.GetWiredIP("")
|
wired_ip = wired.GetWiredIP("")
|
||||||
|
|||||||
@@ -57,6 +57,22 @@ if __name__ == '__main__':
|
|||||||
BACKEND = None
|
BACKEND = None
|
||||||
BACKEND_MGR = BackendManager()
|
BACKEND_MGR = BackendManager()
|
||||||
|
|
||||||
|
def abortable(func):
|
||||||
|
""" Mark a method in a ConnectionThread as abortable.
|
||||||
|
|
||||||
|
This decorator runs a check that will abort the connection thread
|
||||||
|
if necessary before running a given method.
|
||||||
|
|
||||||
|
"""
|
||||||
|
def wrapper(self, *__args, **__kargs):
|
||||||
|
self.abort_if_needed()
|
||||||
|
return func(self, *__args, **__kargs)
|
||||||
|
|
||||||
|
wrapper.__name__ = func.__name__
|
||||||
|
wrapper.__dict__ = func.__dict__
|
||||||
|
wrapper.__doc__ = func.__doc__
|
||||||
|
return wrapper
|
||||||
|
|
||||||
def get_backend_list():
|
def get_backend_list():
|
||||||
if BACKEND_MGR:
|
if BACKEND_MGR:
|
||||||
return BACKEND_MGR.get_available_backends()
|
return BACKEND_MGR.get_available_backends()
|
||||||
@@ -83,8 +99,6 @@ class Controller(object):
|
|||||||
self.global_dns_2 = None
|
self.global_dns_2 = None
|
||||||
self.global_dns_3 = None
|
self.global_dns_3 = None
|
||||||
self.global_search_dom = None
|
self.global_search_dom = None
|
||||||
self._wired_interface = None
|
|
||||||
self._wireless_interface = None
|
|
||||||
self._dhcp_client = None
|
self._dhcp_client = None
|
||||||
self._flush_tool = None
|
self._flush_tool = None
|
||||||
self._debug = None
|
self._debug = None
|
||||||
@@ -94,50 +108,29 @@ class Controller(object):
|
|||||||
self.after_script = None
|
self.after_script = None
|
||||||
self.disconnect_script = None
|
self.disconnect_script = None
|
||||||
self.driver = None
|
self.driver = None
|
||||||
self.wiface = None
|
self.iface = None
|
||||||
self.liface = None
|
self.backend_manager = BackendManager()
|
||||||
self.backend_manager = BackendManager()
|
|
||||||
|
|
||||||
def set_wireless_iface(self, value):
|
|
||||||
self._wireless_interface = value
|
|
||||||
if self.wiface:
|
|
||||||
self.wiface.SetInterface(value)
|
|
||||||
def get_wireless_iface(self): return self._wireless_interface
|
|
||||||
wireless_interface = property(get_wireless_iface, set_wireless_iface)
|
|
||||||
|
|
||||||
def set_wired_iface(self, value):
|
|
||||||
self._wired_interface = value
|
|
||||||
if self.liface:
|
|
||||||
self.liface.SetInterface(value)
|
|
||||||
def get_wired_iface(self): return self._wired_interface
|
|
||||||
wired_interface = property(get_wired_iface, set_wired_iface)
|
|
||||||
|
|
||||||
def set_debug(self, value):
|
def set_debug(self, value):
|
||||||
self._debug = value
|
self._debug = value
|
||||||
if self.wiface:
|
if self.iface:
|
||||||
self.wiface.SetDebugMode(value)
|
self.iface.SetDebugMode(value)
|
||||||
if self.liface:
|
|
||||||
self.liface.SetDebugMode(value)
|
|
||||||
def get_debug(self): return self._debug
|
def get_debug(self): return self._debug
|
||||||
debug = property(get_debug, set_debug)
|
debug = property(get_debug, set_debug)
|
||||||
|
|
||||||
def set_dhcp_client(self, value):
|
def set_dhcp_client(self, value):
|
||||||
self._dhcp_client = value
|
self._dhcp_client = value
|
||||||
if self.wiface:
|
if self.iface:
|
||||||
self.wiface.DHCP_CLIENT = value
|
self.iface.DHCP_CLIENT = value
|
||||||
self.wiface.CheckDHCP()
|
self.iface.CheckDHCP()
|
||||||
if self.liface:
|
|
||||||
self.liface.DHCP_CLIENT = value
|
|
||||||
self.liface.CheckDHCP()
|
|
||||||
def get_dhcp_client(self): return self._dhcp_client
|
def get_dhcp_client(self): return self._dhcp_client
|
||||||
dhcp_client = property(get_dhcp_client, set_dhcp_client)
|
dhcp_client = property(get_dhcp_client, set_dhcp_client)
|
||||||
|
|
||||||
def set_flush_tool(self, value):
|
def set_flush_tool(self, value):
|
||||||
self._flush_tool = value
|
self._flush_tool = value
|
||||||
if self.wiface:
|
if self.iface:
|
||||||
self.wiface.flush_tool = value
|
self.iface.flush_tool = value
|
||||||
if self.liface:
|
|
||||||
self.liface.flush_tool = value
|
|
||||||
def get_flush_tool(self): return self._flush_tool
|
def get_flush_tool(self): return self._flush_tool
|
||||||
flush_tool = property(get_flush_tool, set_flush_tool)
|
flush_tool = property(get_flush_tool, set_flush_tool)
|
||||||
|
|
||||||
@@ -155,6 +148,57 @@ class Controller(object):
|
|||||||
return self._backend.NeedsExternalCalls()
|
return self._backend.NeedsExternalCalls()
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def StopDHCP(self):
|
||||||
|
return BACKEND.StopDHCP()
|
||||||
|
|
||||||
|
def GetIP(self, ifconfig=""):
|
||||||
|
""" Get the IP of the interface.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The IP address of the interface in dotted notation.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.iface.GetIP(ifconfig)
|
||||||
|
|
||||||
|
def Disconnect(self):
|
||||||
|
""" Disconnect from the network. """
|
||||||
|
iface = self.iface
|
||||||
|
if self.disconnect_script != None:
|
||||||
|
print 'Running wired disconnect script'
|
||||||
|
misc.Run(self.disconnect_script)
|
||||||
|
|
||||||
|
iface.ReleaseDHCP()
|
||||||
|
iface.SetAddress('0.0.0.0')
|
||||||
|
iface.Down()
|
||||||
|
iface.Up()
|
||||||
|
|
||||||
|
def IsUp(self):
|
||||||
|
""" Calls the IsUp method for the wired interface.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if the interface is up, False otherwise.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.iface.IsUp()
|
||||||
|
|
||||||
|
def EnableInterface(self):
|
||||||
|
""" Puts the interface up.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if the interface was put up succesfully, False otherwise.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.iface.Up()
|
||||||
|
|
||||||
|
def DisableInterface(self):
|
||||||
|
""" Puts the interface down.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if the interface was put down succesfully, False otherwise.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.iface.Down()
|
||||||
|
|
||||||
|
|
||||||
class ConnectThread(threading.Thread):
|
class ConnectThread(threading.Thread):
|
||||||
@@ -170,9 +214,9 @@ class ConnectThread(threading.Thread):
|
|||||||
should_die = False
|
should_die = False
|
||||||
lock = thread.allocate_lock()
|
lock = thread.allocate_lock()
|
||||||
|
|
||||||
def __init__(self, network, wireless, wired, before_script, after_script,
|
def __init__(self, network, interface_name, before_script, after_script,
|
||||||
disconnect_script, gdns1, gdns2, gdns3, gsearch_dom,
|
disconnect_script, gdns1, gdns2, gdns3, gsearch_dom,
|
||||||
wiface, liface, debug):
|
iface, debug):
|
||||||
""" Initialise the required object variables and the thread.
|
""" Initialise the required object variables and the thread.
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
@@ -190,24 +234,22 @@ class ConnectThread(threading.Thread):
|
|||||||
"""
|
"""
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.network = network
|
self.network = network
|
||||||
self.wireless_interface = wireless
|
|
||||||
self.wired_interface = wired
|
|
||||||
self.is_connecting = False
|
self.is_connecting = False
|
||||||
self.is_aborted = False
|
self.is_aborted = False
|
||||||
self.abort_msg = None
|
self.connect_result = None
|
||||||
self.before_script = before_script
|
self.before_script = before_script
|
||||||
self.after_script = after_script
|
self.after_script = after_script
|
||||||
self.disconnect_script = disconnect_script
|
self.disconnect_script = disconnect_script
|
||||||
self._should_die = False
|
self._should_die = False
|
||||||
self.abort_reason = ""
|
self.abort_reason = ""
|
||||||
|
self.connect_result = ""
|
||||||
|
|
||||||
self.global_dns_1 = gdns1
|
self.global_dns_1 = gdns1
|
||||||
self.global_dns_2 = gdns2
|
self.global_dns_2 = gdns2
|
||||||
self.global_dns_3 = gdns3
|
self.global_dns_3 = gdns3
|
||||||
self.global_search_dom = gsearch_dom
|
self.global_search_dom = gsearch_dom
|
||||||
|
|
||||||
self.wiface = wiface
|
self.iface = iface
|
||||||
self.liface = liface
|
|
||||||
|
|
||||||
self.connecting_message = None
|
self.connecting_message = None
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
@@ -251,7 +293,8 @@ class ConnectThread(threading.Thread):
|
|||||||
self.lock.release()
|
self.lock.release()
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def reset_ip_addresses(self, wiface, liface):
|
@abortable
|
||||||
|
def reset_ip_addresses(self, iface):
|
||||||
""" Resets the IP addresses for both wired/wireless interfaces.
|
""" Resets the IP addresses for both wired/wireless interfaces.
|
||||||
|
|
||||||
Sets a false ip so that when we set the real one, the correct
|
Sets a false ip so that when we set the real one, the correct
|
||||||
@@ -260,15 +303,16 @@ class ConnectThread(threading.Thread):
|
|||||||
"""
|
"""
|
||||||
print 'Setting false IP...'
|
print 'Setting false IP...'
|
||||||
self.SetStatus('resetting_ip_address')
|
self.SetStatus('resetting_ip_address')
|
||||||
wiface.SetAddress('0.0.0.0')
|
iface.SetAddress('0.0.0.0')
|
||||||
liface.SetAddress('0.0.0.0')
|
|
||||||
|
@abortable
|
||||||
def put_iface_down(self, iface):
|
def put_iface_down(self, iface):
|
||||||
""" Puts the given interface down. """
|
""" Puts the given interface down. """
|
||||||
print 'Putting interface down'
|
print 'Putting interface down'
|
||||||
self.SetStatus('interface_down')
|
self.SetStatus('interface_down')
|
||||||
iface.Down()
|
iface.Down()
|
||||||
|
|
||||||
|
@abortable
|
||||||
def run_script_if_needed(self, script, msg):
|
def run_script_if_needed(self, script, msg):
|
||||||
""" Execute a given script if needed.
|
""" Execute a given script if needed.
|
||||||
|
|
||||||
@@ -280,21 +324,23 @@ class ConnectThread(threading.Thread):
|
|||||||
if script:
|
if script:
|
||||||
print 'Executing %s script' % (msg)
|
print 'Executing %s script' % (msg)
|
||||||
misc.ExecuteScript(script)
|
misc.ExecuteScript(script)
|
||||||
|
|
||||||
def flush_routes(self, wiface, liface):
|
@abortable
|
||||||
|
def flush_routes(self, iface):
|
||||||
""" Flush the routes for both wired/wireless interfaces. """
|
""" Flush the routes for both wired/wireless interfaces. """
|
||||||
self.SetStatus('flushing_routing_table')
|
self.SetStatus('flushing_routing_table')
|
||||||
print 'Flushing the routing table...'
|
print 'Flushing the routing table...'
|
||||||
wiface.FlushRoutes()
|
iface.FlushRoutes()
|
||||||
liface.FlushRoutes()
|
|
||||||
|
@abortable
|
||||||
def set_broadcast_address(self, iface):
|
def set_broadcast_address(self, iface):
|
||||||
""" Set the broadcast address for the given interface. """
|
""" Set the broadcast address for the given interface. """
|
||||||
if not self.network.get('broadcast') == None:
|
if not self.network.get('broadcast') == None:
|
||||||
self.SetStatus('setting_broadcast_address')
|
self.SetStatus('setting_broadcast_address')
|
||||||
print 'Setting the broadcast address...' + self.network['broadcast']
|
print 'Setting the broadcast address...' + self.network['broadcast']
|
||||||
iface.SetAddress(broadcast=self.network['broadcast'])
|
iface.SetAddress(broadcast=self.network['broadcast'])
|
||||||
|
|
||||||
|
@abortable
|
||||||
def set_ip_address(self, iface):
|
def set_ip_address(self, iface):
|
||||||
""" Set the IP address for the given interface.
|
""" Set the IP address for the given interface.
|
||||||
|
|
||||||
@@ -315,7 +361,8 @@ class ConnectThread(threading.Thread):
|
|||||||
if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']:
|
if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']:
|
||||||
self.abort_connection(dhcp_status)
|
self.abort_connection(dhcp_status)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@abortable
|
||||||
def set_dns_addresses(self):
|
def set_dns_addresses(self):
|
||||||
""" Set the DNS address(es).
|
""" Set the DNS address(es).
|
||||||
|
|
||||||
@@ -336,6 +383,18 @@ class ConnectThread(threading.Thread):
|
|||||||
self.network.get('dns3'),
|
self.network.get('dns3'),
|
||||||
self.network.get('search_domain'))
|
self.network.get('search_domain'))
|
||||||
|
|
||||||
|
@abortable
|
||||||
|
def release_dhcp_clients(self, iface):
|
||||||
|
""" Release all running dhcp clients. """
|
||||||
|
print "Releasing DHCP leases..."
|
||||||
|
iface.ReleaseDHCP()
|
||||||
|
|
||||||
|
@abortable
|
||||||
|
def stop_dhcp_clients(self, iface):
|
||||||
|
""" Stop and running DHCP clients. """
|
||||||
|
print 'Stopping DHCP clients'
|
||||||
|
BACKEND.StopDHCP()
|
||||||
|
|
||||||
def connect_aborted(self, reason):
|
def connect_aborted(self, reason):
|
||||||
""" Sets the thread status to aborted in a thread-safe way.
|
""" Sets the thread status to aborted in a thread-safe way.
|
||||||
|
|
||||||
@@ -347,7 +406,7 @@ class ConnectThread(threading.Thread):
|
|||||||
reason = self.abort_reason
|
reason = self.abort_reason
|
||||||
self.connecting_message = reason
|
self.connecting_message = reason
|
||||||
self.is_aborted = True
|
self.is_aborted = True
|
||||||
self.abort_msg = reason
|
self.connect_result = reason
|
||||||
self.is_connecting = False
|
self.is_connecting = False
|
||||||
print 'exiting connection thread'
|
print 'exiting connection thread'
|
||||||
|
|
||||||
@@ -356,18 +415,6 @@ class ConnectThread(threading.Thread):
|
|||||||
self.abort_reason = reason
|
self.abort_reason = reason
|
||||||
self.should_die = True
|
self.should_die = True
|
||||||
|
|
||||||
def release_dhcp_clients(self, wiface, liface):
|
|
||||||
""" Release all running dhcp clients. """
|
|
||||||
print "Releasing DHCP leases..."
|
|
||||||
wiface.ReleaseDHCP()
|
|
||||||
liface.ReleaseDHCP()
|
|
||||||
|
|
||||||
def stop_dhcp_clients(self, iface):
|
|
||||||
""" Stop and running DHCP clients, as well as wpa_supplicant. """
|
|
||||||
print 'Stopping wpa_supplicant and any DHCP clients'
|
|
||||||
iface.StopWPA()
|
|
||||||
BACKEND.StopDHCP()
|
|
||||||
|
|
||||||
def abort_if_needed(self):
|
def abort_if_needed(self):
|
||||||
""" Abort the thread is it has been requested. """
|
""" Abort the thread is it has been requested. """
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
@@ -377,7 +424,8 @@ class ConnectThread(threading.Thread):
|
|||||||
thread.exit()
|
thread.exit()
|
||||||
finally:
|
finally:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
|
@abortable
|
||||||
def put_iface_up(self, iface):
|
def put_iface_up(self, iface):
|
||||||
""" Bring up given interface. """
|
""" Bring up given interface. """
|
||||||
print 'Putting interface up...'
|
print 'Putting interface up...'
|
||||||
@@ -392,16 +440,29 @@ class Wireless(Controller):
|
|||||||
""" Initialize the class. """
|
""" Initialize the class. """
|
||||||
Controller.__init__(self)
|
Controller.__init__(self)
|
||||||
self._wpa_driver = None
|
self._wpa_driver = None
|
||||||
|
self._wireless_interface = None
|
||||||
|
self.wiface = None
|
||||||
|
|
||||||
|
def set_wireless_iface(self, value):
|
||||||
|
self._wireless_interface = value
|
||||||
|
if self.wiface:
|
||||||
|
self.wiface.SetInterface(value)
|
||||||
|
def get_wireless_iface(self): return self._wireless_interface
|
||||||
|
wireless_interface = property(get_wireless_iface, set_wireless_iface)
|
||||||
|
|
||||||
def set_wpa_driver(self, value):
|
def set_wpa_driver(self, value):
|
||||||
self._wpa_driver = value
|
self._wpa_driver = value
|
||||||
if self.wiface:
|
if self.wiface:
|
||||||
self.SetWPADriver(value)
|
self.SetWPADriver(value)
|
||||||
|
|
||||||
def get_wpa_driver(self): return self._wpa_driver
|
def get_wpa_driver(self): return self._wpa_driver
|
||||||
|
|
||||||
wpa_driver = property(get_wpa_driver, set_wpa_driver)
|
wpa_driver = property(get_wpa_driver, set_wpa_driver)
|
||||||
|
|
||||||
|
def set_iface(self, value):
|
||||||
|
self.wiface = value
|
||||||
|
def get_iface(self):
|
||||||
|
return self.wiface
|
||||||
|
iface = property(get_iface, set_iface)
|
||||||
|
|
||||||
def LoadBackend(self, backend):
|
def LoadBackend(self, backend):
|
||||||
""" Load a given backend.
|
""" Load a given backend.
|
||||||
|
|
||||||
@@ -440,7 +501,7 @@ class Wireless(Controller):
|
|||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if not self.wireless_interface: return []
|
if not self.wiface: return []
|
||||||
|
|
||||||
wiface = self.wiface
|
wiface = self.wiface
|
||||||
|
|
||||||
@@ -466,14 +527,13 @@ class Wireless(Controller):
|
|||||||
network -- network to connect to
|
network -- network to connect to
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.wireless_interface: return False
|
if not self.wiface: return False
|
||||||
|
|
||||||
self.connecting_thread = WirelessConnectThread(network,
|
self.connecting_thread = WirelessConnectThread(network,
|
||||||
self.wireless_interface, self.wired_interface,
|
self.wireless_interface, self.wpa_driver, self.before_script,
|
||||||
self.wpa_driver, self.before_script, self.after_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_search_dom,
|
self.global_dns_2, self.global_dns_3, self.global_search_dom,
|
||||||
self.wiface, self.liface, debug)
|
self.wiface, debug)
|
||||||
self.connecting_thread.setDaemon(True)
|
self.connecting_thread.setDaemon(True)
|
||||||
self.connecting_thread.start()
|
self.connecting_thread.start()
|
||||||
return True
|
return True
|
||||||
@@ -504,15 +564,6 @@ class Wireless(Controller):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
return self.wiface.GetCurrentNetwork(iwconfig)
|
return self.wiface.GetCurrentNetwork(iwconfig)
|
||||||
|
|
||||||
def GetIP(self, ifconfig=""):
|
|
||||||
""" Get the IP of the interface.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The IP address of the interface in dotted notation.
|
|
||||||
|
|
||||||
"""
|
|
||||||
return self.wiface.GetIP(ifconfig)
|
|
||||||
|
|
||||||
def GetBSSID(self):
|
def GetBSSID(self):
|
||||||
""" Get the BSSID of the current access point.
|
""" Get the BSSID of the current access point.
|
||||||
@@ -528,17 +579,16 @@ class Wireless(Controller):
|
|||||||
""" Get the out of iwconfig. """
|
""" Get the out of iwconfig. """
|
||||||
return self.wiface.GetIwconfig()
|
return self.wiface.GetIwconfig()
|
||||||
|
|
||||||
def IsUp(self):
|
def GetWpaSupplicantDrivers(self, drivers):
|
||||||
""" Calls the IsUp method for the wireless interface.
|
""" Returns all valid wpa_supplicant drivers in a list. """
|
||||||
|
return [driver for driver in drivers if
|
||||||
Returns:
|
BACKEND.IsValidWpaSuppDriver(driver)]
|
||||||
True if the interface is up, False otherwise.
|
|
||||||
|
def StopWPA(self):
|
||||||
"""
|
return self.wiface.StopWPA()
|
||||||
return self.wiface.IsUp()
|
|
||||||
|
|
||||||
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key,
|
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key,
|
||||||
enc_used, ics):
|
enc_used):
|
||||||
""" Create an ad-hoc wireless network.
|
""" Create an ad-hoc wireless network.
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
@@ -568,34 +618,9 @@ class Wireless(Controller):
|
|||||||
wiface.SetKey(key)
|
wiface.SetKey(key)
|
||||||
print 'Putting interface up'
|
print 'Putting interface up'
|
||||||
wiface.Up()
|
wiface.Up()
|
||||||
# Just assume that the netmask is 255.255.255.0, it simplifies ICS
|
|
||||||
print 'Setting IP address'
|
print 'Setting IP address'
|
||||||
wiface.SetAddress(ip, '255.255.255.0')
|
wiface.SetAddress(ip, '255.255.255.0')
|
||||||
|
|
||||||
ip_parts = misc.IsValidIP(ip)
|
|
||||||
|
|
||||||
if ics and ip_parts:
|
|
||||||
# Set up internet connection sharing here
|
|
||||||
# Flush the forward tables
|
|
||||||
misc.Run('iptables -F FORWARD')
|
|
||||||
misc.Run('iptables -N fw-interfaces')
|
|
||||||
misc.Run('iptables -N fw-open')
|
|
||||||
misc.Run('iptables -F fw-interfaces')
|
|
||||||
misc.Run('iptables -F fw-open')
|
|
||||||
misc.Run('iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS \
|
|
||||||
--clamp-mss-to-pmtu')
|
|
||||||
misc.Run('iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT')
|
|
||||||
misc.Run('iptables -A FORWARD -j fw-interfaces ')
|
|
||||||
misc.Run('iptables -A FORWARD -j fw-open ')
|
|
||||||
misc.Run('iptables -A FORWARD -j REJECT --reject-with icmp-host-unreachable')
|
|
||||||
misc.Run('iptables -P FORWARD DROP')
|
|
||||||
misc.Run('iptables -A fw-interfaces -i ' + self.wireless_interface + ' -j ACCEPT')
|
|
||||||
net_ip = '.'.join(ip_parts[0:3]) + '.0'
|
|
||||||
misc.Run('iptables -t nat -A POSTROUTING -s ' + net_ip + \
|
|
||||||
'/255.255.255.0 -o ' + self.wired_interface + \
|
|
||||||
' -j MASQUERADE')
|
|
||||||
misc.Run('echo 1 > /proc/sys/net/ipv4/ip_forward') # Enable routing
|
|
||||||
|
|
||||||
def DetectWirelessInterface(self):
|
def DetectWirelessInterface(self):
|
||||||
""" Detect available wireless interfaces.
|
""" Detect available wireless interfaces.
|
||||||
|
|
||||||
@@ -621,23 +646,8 @@ class Wireless(Controller):
|
|||||||
Resets it's IP address, and puts the interface down then up.
|
Resets it's IP address, and puts the interface down then up.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
wiface = self.wiface
|
Controller.Disconnect(self)
|
||||||
if self.disconnect_script not in (None, ""):
|
self.StopWPA()
|
||||||
print 'Running wireless network disconnect script'
|
|
||||||
misc.ExecuteScript(self.disconnect_script)
|
|
||||||
|
|
||||||
wiface.ReleaseDHCP()
|
|
||||||
wiface.SetAddress('0.0.0.0')
|
|
||||||
wiface.Down()
|
|
||||||
wiface.Up()
|
|
||||||
|
|
||||||
def EnableInterface(self):
|
|
||||||
""" Puts the interface up. """
|
|
||||||
return self.wiface.Up()
|
|
||||||
|
|
||||||
def DisableInterface(self):
|
|
||||||
""" Puts the interface down. """
|
|
||||||
return self.wiface.Down()
|
|
||||||
|
|
||||||
def SetWPADriver(self, driver):
|
def SetWPADriver(self, driver):
|
||||||
""" Sets the wpa_supplicant driver associated with the interface. """
|
""" Sets the wpa_supplicant driver associated with the interface. """
|
||||||
@@ -651,15 +661,14 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, network, wireless, wired, wpa_driver,
|
def __init__(self, network, wireless, wpa_driver, before_script,
|
||||||
before_script, after_script, disconnect_script, gdns1,
|
after_script, disconnect_script, gdns1, gdns2, gdns3,
|
||||||
gdns2, gdns3, gsearch_dom, wiface, liface, debug=False):
|
gsearch_dom, wiface, debug=False):
|
||||||
""" Initialise the thread with network information.
|
""" Initialise the thread with network information.
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
network -- the network to connect to
|
network -- the network to connect to
|
||||||
wireless -- name of the wireless interface
|
wireless -- name of the wireless interface
|
||||||
wired -- name of the wired interface
|
|
||||||
wpa_driver -- type of wireless interface
|
wpa_driver -- type of wireless interface
|
||||||
before_script -- script to run before bringing up the interface
|
before_script -- script to run before bringing up the interface
|
||||||
after_script -- script to run after bringing up the interface
|
after_script -- script to run after bringing up the interface
|
||||||
@@ -669,9 +678,9 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
gdns3 -- global DNS server 3
|
gdns3 -- global DNS server 3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ConnectThread.__init__(self, network, wireless, wired,
|
ConnectThread.__init__(self, network, wireless, before_script,
|
||||||
before_script, after_script, disconnect_script, gdns1,
|
after_script, disconnect_script, gdns1, gdns2,
|
||||||
gdns2, gdns3, gsearch_dom, wiface, liface, debug)
|
gdns3, gsearch_dom, wiface, debug)
|
||||||
self.wpa_driver = wpa_driver
|
self.wpa_driver = wpa_driver
|
||||||
|
|
||||||
|
|
||||||
@@ -689,33 +698,27 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
5. Get/set IP address and DNS servers.
|
5. Get/set IP address and DNS servers.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
wiface = self.wiface
|
wiface = self.iface
|
||||||
liface = self.liface
|
|
||||||
self.is_connecting = True
|
self.is_connecting = True
|
||||||
|
|
||||||
# Run pre-connection script.
|
# Run pre-connection script.
|
||||||
self.abort_if_needed()
|
|
||||||
self.run_script_if_needed(self.before_script, 'pre-connection')
|
self.run_script_if_needed(self.before_script, 'pre-connection')
|
||||||
self.abort_if_needed()
|
|
||||||
|
|
||||||
# Take down interface and clean up previous connections.
|
# Take down interface and clean up previous connections.
|
||||||
self.put_iface_down(wiface)
|
self.put_iface_down(wiface)
|
||||||
self.abort_if_needed()
|
self.release_dhcp_clients(wiface)
|
||||||
self.release_dhcp_clients(wiface, liface)
|
self.reset_ip_addresses(wiface)
|
||||||
self.reset_ip_addresses(wiface, liface)
|
|
||||||
self.stop_dhcp_clients(wiface)
|
self.stop_dhcp_clients(wiface)
|
||||||
self.abort_if_needed()
|
self.stop_wpa(wiface)
|
||||||
self.flush_routes(wiface, liface)
|
self.flush_routes(wiface)
|
||||||
|
|
||||||
# Generate PSK and authenticate if needed.
|
# Generate PSK and authenticate if needed.
|
||||||
if self.wpa_driver != 'ralink legacy':
|
if self.wpa_driver != 'ralink legacy':
|
||||||
self.generate_psk_and_authenticate(wiface)
|
self.generate_psk_and_authenticate(wiface)
|
||||||
|
|
||||||
# Put interface up.
|
# Put interface up.
|
||||||
self.abort_if_needed()
|
|
||||||
self.SetStatus('configuring_interface')
|
self.SetStatus('configuring_interface')
|
||||||
self.put_iface_up(wiface)
|
self.put_iface_up(wiface)
|
||||||
self.abort_if_needed()
|
|
||||||
|
|
||||||
# Associate.
|
# Associate.
|
||||||
wiface.SetMode(self.network['mode'])
|
wiface.SetMode(self.network['mode'])
|
||||||
@@ -731,25 +734,31 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
if self.network.get('enctype'):
|
if self.network.get('enctype'):
|
||||||
self.SetStatus('validating_authentication')
|
self.SetStatus('validating_authentication')
|
||||||
if not wiface.ValidateAuthentication(time.time()):
|
if not wiface.ValidateAuthentication(time.time()):
|
||||||
self.abort_connection('bad_pass')
|
if not self.connect_result:
|
||||||
self.abort_if_needed()
|
self.abort_connection('bad_pass')
|
||||||
|
|
||||||
# Set up gateway, IP address, and DNS servers.
|
# Set up gateway, IP address, and DNS servers.
|
||||||
self.set_broadcast_address(wiface)
|
self.set_broadcast_address(wiface)
|
||||||
self.abort_if_needed()
|
|
||||||
self.set_ip_address(wiface)
|
self.set_ip_address(wiface)
|
||||||
self.set_dns_addresses()
|
self.set_dns_addresses()
|
||||||
|
|
||||||
# Run post-connection script.
|
# Run post-connection script.
|
||||||
self.abort_if_needed()
|
|
||||||
self.run_script_if_needed(self.after_script, 'post-connection')
|
self.run_script_if_needed(self.after_script, 'post-connection')
|
||||||
|
|
||||||
self.SetStatus('done')
|
self.SetStatus('done')
|
||||||
print 'Connecting thread exiting.'
|
print 'Connecting thread exiting.'
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print "IP Address is: " + str(wiface.GetIP())
|
print "IP Address is: " + str(wiface.GetIP())
|
||||||
|
self.connect_result = "Success"
|
||||||
self.is_connecting = False
|
self.is_connecting = False
|
||||||
|
|
||||||
|
@abortable
|
||||||
|
def stop_wpa(self, wiface):
|
||||||
|
""" Stops wpa_supplicant. """
|
||||||
|
print 'Stopping wpa_supplicant'
|
||||||
|
wiface.StopWPA()
|
||||||
|
|
||||||
|
@abortable
|
||||||
def generate_psk_and_authenticate(self, wiface):
|
def generate_psk_and_authenticate(self, wiface):
|
||||||
""" Generates a PSK and authenticates if necessary.
|
""" Generates a PSK and authenticates if necessary.
|
||||||
|
|
||||||
@@ -764,7 +773,7 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
if self.network.get('key') and 'wpa' in self.network.get('enctype'):
|
if self.network.get('key') and 'wpa' in self.network.get('enctype'):
|
||||||
self.SetStatus('generating_psk')
|
self.SetStatus('generating_psk')
|
||||||
print 'Generating psk...'
|
print 'Generating psk...'
|
||||||
self.network['psk'] = self.wiface.GeneratePSK(self.network)
|
self.network['psk'] = wiface.GeneratePSK(self.network)
|
||||||
|
|
||||||
if not self.network.get('psk'):
|
if not self.network.get('psk'):
|
||||||
self.network['psk'] = self.network['key']
|
self.network['psk'] = self.network['key']
|
||||||
@@ -786,6 +795,8 @@ class Wired(Controller):
|
|||||||
Controller.__init__(self)
|
Controller.__init__(self)
|
||||||
self.wpa_driver = None
|
self.wpa_driver = None
|
||||||
self._link_detect = None
|
self._link_detect = None
|
||||||
|
self._wired_interface = None
|
||||||
|
self.liface = None
|
||||||
|
|
||||||
def set_link_detect(self, value):
|
def set_link_detect(self, value):
|
||||||
self._link_detect = value
|
self._link_detect = value
|
||||||
@@ -794,6 +805,20 @@ class Wired(Controller):
|
|||||||
def get_link_detect(self): return self._link_detect
|
def get_link_detect(self): return self._link_detect
|
||||||
link_detect = property(get_link_detect, set_link_detect)
|
link_detect = property(get_link_detect, set_link_detect)
|
||||||
|
|
||||||
|
|
||||||
|
def set_wired_iface(self, value):
|
||||||
|
self._wired_interface = value
|
||||||
|
if self.liface:
|
||||||
|
self.liface.SetInterface(value)
|
||||||
|
def get_wired_iface(self): return self._wired_interface
|
||||||
|
wired_interface = property(get_wired_iface, set_wired_iface)
|
||||||
|
|
||||||
|
def set_iface(self, value):
|
||||||
|
self.liface = value
|
||||||
|
def get_iface(self):
|
||||||
|
return self.liface
|
||||||
|
iface = property(get_iface, set_iface)
|
||||||
|
|
||||||
def LoadBackend(self, backend):
|
def LoadBackend(self, backend):
|
||||||
""" Load the backend up. """
|
""" Load the backend up. """
|
||||||
Controller.LoadBackend(self, backend)
|
Controller.LoadBackend(self, backend)
|
||||||
@@ -817,16 +842,14 @@ class Wired(Controller):
|
|||||||
network -- network to connect to
|
network -- network to connect to
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.wired_interface: return False
|
if not self.liface: return False
|
||||||
self.connecting_thread = WiredConnectThread(network,
|
self.connecting_thread = WiredConnectThread(network,
|
||||||
self.wireless_interface, self.wired_interface,
|
self.wired_interface, self.before_script, self.after_script,
|
||||||
self.before_script, self.after_script,
|
self.disconnect_script, self.global_dns_1, self.global_dns_2,
|
||||||
self.disconnect_script, self.global_dns_1,
|
self.global_dns_3, self.global_search_dom, self.liface, debug)
|
||||||
self.global_dns_2, self.global_dns_3, self.global_search_dom,
|
|
||||||
self.wiface, self.liface, debug)
|
|
||||||
self.connecting_thread.setDaemon(True)
|
self.connecting_thread.setDaemon(True)
|
||||||
self.connecting_thread.start()
|
self.connecting_thread.start()
|
||||||
return True
|
return self.connecting_thread
|
||||||
|
|
||||||
def DetectWiredInterface(self):
|
def DetectWiredInterface(self):
|
||||||
""" Attempts to automatically detect a wired interface. """
|
""" Attempts to automatically detect a wired interface. """
|
||||||
@@ -835,54 +858,6 @@ class Wired(Controller):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def GetIP(self, ifconfig=""):
|
|
||||||
""" Get the IP of the interface.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The IP address of the interface in dotted notation.
|
|
||||||
|
|
||||||
"""
|
|
||||||
return self.liface.GetIP(ifconfig)
|
|
||||||
|
|
||||||
def Disconnect(self):
|
|
||||||
""" Disconnect from the network. """
|
|
||||||
liface = self.liface
|
|
||||||
if self.disconnect_script != None:
|
|
||||||
print 'Running wired disconnect script'
|
|
||||||
misc.Run(self.disconnect_script)
|
|
||||||
|
|
||||||
liface.ReleaseDHCP()
|
|
||||||
liface.SetAddress('0.0.0.0')
|
|
||||||
liface.Down()
|
|
||||||
liface.Up()
|
|
||||||
|
|
||||||
def IsUp(self):
|
|
||||||
""" Calls the IsUp method for the wired interface.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
True if the interface is up, False otherwise.
|
|
||||||
|
|
||||||
"""
|
|
||||||
return self.liface.IsUp()
|
|
||||||
|
|
||||||
def EnableInterface(self):
|
|
||||||
""" Puts the interface up.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
True if the interface was put up succesfully, False otherwise.
|
|
||||||
|
|
||||||
"""
|
|
||||||
return self.liface.Up()
|
|
||||||
|
|
||||||
def DisableInterface(self):
|
|
||||||
""" Puts the interface down.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
True if the interface was put down succesfully, False otherwise.
|
|
||||||
|
|
||||||
"""
|
|
||||||
return self.liface.Down()
|
|
||||||
|
|
||||||
|
|
||||||
class WiredConnectThread(ConnectThread):
|
class WiredConnectThread(ConnectThread):
|
||||||
""" A thread class to perform the connection to a wired network.
|
""" A thread class to perform the connection to a wired network.
|
||||||
@@ -891,9 +866,9 @@ class WiredConnectThread(ConnectThread):
|
|||||||
to the specified network.
|
to the specified network.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, network, wireless, wired,
|
def __init__(self, network, wired, before_script, after_script,
|
||||||
before_script, after_script, disconnect_script, gdns1,
|
disconnect_script, gdns1, gdns2, gdns3, gsearch_dom, liface,
|
||||||
gdns2, gdns3, gsearch_dom, wiface, liface, debug=False):
|
debug=False):
|
||||||
""" Initialise the thread with network information.
|
""" Initialise the thread with network information.
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
@@ -908,9 +883,9 @@ class WiredConnectThread(ConnectThread):
|
|||||||
gdns3 -- global DNS server 3
|
gdns3 -- global DNS server 3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ConnectThread.__init__(self, network, wireless, wired,
|
ConnectThread.__init__(self, network, wired, before_script,
|
||||||
before_script, after_script, disconnect_script, gdns1,
|
after_script, disconnect_script, gdns1, gdns2,
|
||||||
gdns2, gdns3, gsearch_dom, wiface, liface, debug)
|
gdns3, gsearch_dom, liface, debug)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" The main function of the connection thread.
|
""" The main function of the connection thread.
|
||||||
@@ -926,34 +901,27 @@ class WiredConnectThread(ConnectThread):
|
|||||||
5. Run post-connection script.
|
5. Run post-connection script.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
wiface = self.wiface
|
liface = self.iface
|
||||||
liface = self.liface
|
|
||||||
|
|
||||||
self.is_connecting = True
|
self.is_connecting = True
|
||||||
|
|
||||||
# Run pre-connection script.
|
# Run pre-connection script.
|
||||||
self.abort_if_needed()
|
|
||||||
self.run_script_if_needed(self.before_script, 'pre-connection')
|
self.run_script_if_needed(self.before_script, 'pre-connection')
|
||||||
self.abort_if_needed()
|
|
||||||
|
|
||||||
# Take down interface and clean up previous connections.
|
# Take down interface and clean up previous connections.
|
||||||
self.put_iface_down(liface)
|
self.put_iface_down(liface)
|
||||||
self.release_dhcp_clients(wiface, liface)
|
self.release_dhcp_clients(liface)
|
||||||
self.reset_ip_addresses(wiface, liface)
|
self.reset_ip_addresses(liface)
|
||||||
self.stop_dhcp_clients(wiface)
|
self.stop_dhcp_clients(liface)
|
||||||
self.abort_if_needed()
|
self.flush_routes(liface)
|
||||||
self.flush_routes(wiface, liface)
|
|
||||||
|
|
||||||
# Bring up interface.
|
# Bring up interface.
|
||||||
self.put_iface_up(liface)
|
self.put_iface_up(liface)
|
||||||
self.abort_if_needed()
|
|
||||||
|
|
||||||
# Set gateway, IP adresses, and DNS servers.
|
# Set gateway, IP adresses, and DNS servers.
|
||||||
self.set_broadcast_address(liface)
|
self.set_broadcast_address(liface)
|
||||||
self.abort_if_needed()
|
|
||||||
self.set_ip_address(liface)
|
self.set_ip_address(liface)
|
||||||
self.set_dns_addresses()
|
self.set_dns_addresses()
|
||||||
self.abort_if_needed()
|
|
||||||
|
|
||||||
# Run post-connection script.
|
# Run post-connection script.
|
||||||
self.run_script_if_needed(self.after_script, 'post-connection')
|
self.run_script_if_needed(self.after_script, 'post-connection')
|
||||||
@@ -962,4 +930,6 @@ class WiredConnectThread(ConnectThread):
|
|||||||
print 'Connecting thread exiting.'
|
print 'Connecting thread exiting.'
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print "IP Address is: " + str(liface.GetIP())
|
print "IP Address is: " + str(liface.GetIP())
|
||||||
|
|
||||||
|
self.connect_result = "Success"
|
||||||
self.is_connecting = False
|
self.is_connecting = False
|
||||||
|
|||||||
178
wicd/prefs.py
178
wicd/prefs.py
@@ -27,6 +27,8 @@ handles recieving/sendings the settings from/to the daemon.
|
|||||||
import gtk
|
import gtk
|
||||||
import gobject
|
import gobject
|
||||||
import pango
|
import pango
|
||||||
|
import os
|
||||||
|
import gtk.glade
|
||||||
|
|
||||||
from wicd import misc
|
from wicd import misc
|
||||||
from wicd import wpath
|
from wicd import wpath
|
||||||
@@ -54,87 +56,28 @@ class PreferencesDialog(object):
|
|||||||
wireless = dbus['wireless']
|
wireless = dbus['wireless']
|
||||||
wired = dbus['wired']
|
wired = dbus['wired']
|
||||||
self.wTree = wTree
|
self.wTree = wTree
|
||||||
|
self.wpadrivers = None
|
||||||
self.prep_settings_diag()
|
self.prep_settings_diag()
|
||||||
self.build_preferences_diag()
|
self.load_preferences_diag()
|
||||||
|
|
||||||
def build_preferences_diag(self):
|
def load_preferences_diag(self):
|
||||||
""" Builds the preferences dialog window. """
|
""" Loads data into the preferences Dialog. """
|
||||||
def build_combobox(lbl):
|
|
||||||
""" Sets up a ComboBox using the given widget name. """
|
|
||||||
liststore = gtk.ListStore(gobject.TYPE_STRING)
|
|
||||||
combobox = self.wTree.get_widget(lbl)
|
|
||||||
combobox.clear()
|
|
||||||
combobox.set_model(liststore)
|
|
||||||
cell = gtk.CellRendererText()
|
|
||||||
combobox.pack_start(cell, True)
|
|
||||||
combobox.add_attribute(cell, 'text', 0)
|
|
||||||
return combobox
|
|
||||||
|
|
||||||
def setup_label(name, lbl=""):
|
|
||||||
""" Sets up a label for the given widget name. """
|
|
||||||
widget = self.wTree.get_widget(name)
|
|
||||||
if lbl:
|
|
||||||
widget.set_label(language[lbl])
|
|
||||||
return widget
|
|
||||||
|
|
||||||
self.dialog = self.wTree.get_widget("pref_dialog")
|
|
||||||
self.dialog.set_title(language['preferences'])
|
|
||||||
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
|
|
||||||
self.dialog.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
|
|
||||||
size = daemon.ReadWindowSize("pref")
|
|
||||||
width = size[0]
|
|
||||||
height = size[1]
|
|
||||||
if width > -1 and height > -1:
|
|
||||||
self.dialog.resize(int(width), int(height))
|
|
||||||
else:
|
|
||||||
self.dialog.resize(gtk.gdk.screen_width() / 3,
|
|
||||||
gtk.gdk.screen_height() / 2)
|
|
||||||
|
|
||||||
self.wiredcheckbox = setup_label("pref_always_check",
|
|
||||||
'wired_always_on')
|
|
||||||
self.wiredcheckbox.set_active(daemon.GetAlwaysShowWiredInterface())
|
self.wiredcheckbox.set_active(daemon.GetAlwaysShowWiredInterface())
|
||||||
self.reconnectcheckbox = setup_label("pref_auto_check",
|
|
||||||
'auto_reconnect')
|
|
||||||
self.reconnectcheckbox.set_active(daemon.GetAutoReconnect())
|
self.reconnectcheckbox.set_active(daemon.GetAutoReconnect())
|
||||||
self.debugmodecheckbox = setup_label("pref_debug_check",
|
|
||||||
'use_debug_mode')
|
|
||||||
self.debugmodecheckbox.set_active(daemon.GetDebugMode())
|
self.debugmodecheckbox.set_active(daemon.GetDebugMode())
|
||||||
self.displaytypecheckbox = setup_label("pref_dbm_check",
|
|
||||||
'display_type_dialog')
|
|
||||||
self.displaytypecheckbox.set_active(daemon.GetSignalDisplayType())
|
self.displaytypecheckbox.set_active(daemon.GetSignalDisplayType())
|
||||||
self.usedefaultradiobutton = setup_label("pref_use_def_radio",
|
|
||||||
'use_default_profile')
|
|
||||||
self.showlistradiobutton = setup_label("pref_prompt_radio",
|
|
||||||
'show_wired_list')
|
|
||||||
self.lastusedradiobutton = setup_label("pref_use_last_radio",
|
|
||||||
'use_last_used_profile')
|
|
||||||
|
|
||||||
# DHCP Clients
|
|
||||||
self.dhcpautoradio = setup_label("dhcp_auto_radio", "wicd_auto_config")
|
|
||||||
self.dhclientradio = self.wTree.get_widget("dhclient_radio")
|
|
||||||
self.pumpradio = self.wTree.get_widget("pump_radio")
|
|
||||||
self.dhcpcdradio = self.wTree.get_widget("dhcpcd_radio")
|
|
||||||
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
|
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
|
||||||
self.pumpradio]
|
self.pumpradio]
|
||||||
|
|
||||||
dhcp_method = daemon.GetDHCPClient()
|
dhcp_method = daemon.GetDHCPClient()
|
||||||
dhcp_list[dhcp_method].set_active(True)
|
dhcp_list[dhcp_method].set_active(True)
|
||||||
|
|
||||||
# Wired Link Detection Apps
|
|
||||||
self.linkautoradio = setup_label("link_auto_radio", 'wicd_auto_config')
|
|
||||||
self.linkautoradio = setup_label("link_auto_radio")
|
|
||||||
self.ethtoolradio = setup_label("ethtool_radio")
|
|
||||||
self.miitoolradio = setup_label("miitool_radio")
|
|
||||||
wired_link_list = [self.linkautoradio, self.ethtoolradio,
|
wired_link_list = [self.linkautoradio, self.ethtoolradio,
|
||||||
self.miitoolradio]
|
self.miitoolradio]
|
||||||
wired_link_method = daemon.GetLinkDetectionTool()
|
wired_link_method = daemon.GetLinkDetectionTool()
|
||||||
wired_link_list[wired_link_method].set_active(True)
|
wired_link_list[wired_link_method].set_active(True)
|
||||||
|
|
||||||
# Route Flushing Apps
|
|
||||||
self.flushautoradio = setup_label("flush_auto_radio",
|
|
||||||
'wicd_auto_config')
|
|
||||||
self.ipflushradio = setup_label("ip_flush_radio")
|
|
||||||
self.routeflushradio = setup_label("route_flush_radio")
|
|
||||||
flush_list = [self.flushautoradio, self.ipflushradio,
|
flush_list = [self.flushautoradio, self.ipflushradio,
|
||||||
self.routeflushradio]
|
self.routeflushradio]
|
||||||
flush_method = daemon.GetFlushTool()
|
flush_method = daemon.GetFlushTool()
|
||||||
@@ -148,16 +91,9 @@ class PreferencesDialog(object):
|
|||||||
elif auto_conn_meth == 3:
|
elif auto_conn_meth == 3:
|
||||||
self.lastusedradiobutton.set_active(True)
|
self.lastusedradiobutton.set_active(True)
|
||||||
|
|
||||||
self.entryWirelessInterface = self.wTree.get_widget("pref_wifi_entry")
|
|
||||||
self.entryWirelessInterface.set_text(daemon.GetWirelessInterface())
|
self.entryWirelessInterface.set_text(daemon.GetWirelessInterface())
|
||||||
|
|
||||||
self.entryWiredInterface = self.wTree.get_widget("pref_wired_entry")
|
|
||||||
self.entryWiredInterface.set_text(daemon.GetWiredInterface())
|
self.entryWiredInterface.set_text(daemon.GetWiredInterface())
|
||||||
|
|
||||||
# Replacement for the combo box hack
|
|
||||||
self.wpadrivercombo = build_combobox("pref_wpa_combobox")
|
|
||||||
self.wpadrivers = ["wext", "hostap", "madwifi", "atmel", "ndiswrapper",
|
|
||||||
"ipw", "ralink legacy"]
|
|
||||||
found = False
|
found = False
|
||||||
def_driver = daemon.GetWPADriver()
|
def_driver = daemon.GetWPADriver()
|
||||||
for i, x in enumerate(self.wpadrivers):
|
for i, x in enumerate(self.wpadrivers):
|
||||||
@@ -175,14 +111,6 @@ class PreferencesDialog(object):
|
|||||||
# Use wext as default, since normally it is the correct driver.
|
# Use wext as default, since normally it is the correct driver.
|
||||||
self.wpadrivercombo.set_active(0)
|
self.wpadrivercombo.set_active(0)
|
||||||
|
|
||||||
# Set up global DNS stuff
|
|
||||||
self.useGlobalDNSCheckbox = setup_label("pref_global_check",
|
|
||||||
'use_global_dns')
|
|
||||||
self.searchDomEntry = self.wTree.get_widget("pref_search_dom_entry")
|
|
||||||
self.dns1Entry = self.wTree.get_widget("pref_dns1_entry")
|
|
||||||
self.dns2Entry = self.wTree.get_widget("pref_dns2_entry")
|
|
||||||
self.dns3Entry = self.wTree.get_widget("pref_dns3_entry")
|
|
||||||
|
|
||||||
self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
|
self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
|
||||||
(self.dns1Entry, self.dns2Entry,
|
(self.dns1Entry, self.dns2Entry,
|
||||||
self.dns3Entry, self.searchDomEntry))
|
self.dns3Entry, self.searchDomEntry))
|
||||||
@@ -201,7 +129,6 @@ class PreferencesDialog(object):
|
|||||||
self.dns3Entry.set_sensitive(False)
|
self.dns3Entry.set_sensitive(False)
|
||||||
|
|
||||||
# Load backend combobox
|
# Load backend combobox
|
||||||
self.backendcombo = build_combobox("pref_backend_combobox")
|
|
||||||
self.backends = daemon.GetBackendList()
|
self.backends = daemon.GetBackendList()
|
||||||
# "" is included as a hack for DBus limitations, so we remove it.
|
# "" is included as a hack for DBus limitations, so we remove it.
|
||||||
self.backends.remove("")
|
self.backends.remove("")
|
||||||
@@ -229,9 +156,12 @@ class PreferencesDialog(object):
|
|||||||
""" Hides the preferences dialog window. """
|
""" Hides the preferences dialog window. """
|
||||||
self.dialog.hide()
|
self.dialog.hide()
|
||||||
|
|
||||||
|
def destroy(self):
|
||||||
|
self.dialog.destroy()
|
||||||
|
|
||||||
def show_all(self):
|
def show_all(self):
|
||||||
""" Shows the preferences dialog window. """
|
""" Shows the preferences dialog window. """
|
||||||
self.show_all()
|
self.dialog.show()
|
||||||
|
|
||||||
def save_results(self):
|
def save_results(self):
|
||||||
""" Pushes the selected settings to the daemon. """
|
""" Pushes the selected settings to the daemon. """
|
||||||
@@ -290,6 +220,24 @@ class PreferencesDialog(object):
|
|||||||
|
|
||||||
def prep_settings_diag(self):
|
def prep_settings_diag(self):
|
||||||
""" Set up anything that doesn't have to be persisted later. """
|
""" Set up anything that doesn't have to be persisted later. """
|
||||||
|
def build_combobox(lbl):
|
||||||
|
""" Sets up a ComboBox using the given widget name. """
|
||||||
|
liststore = gtk.ListStore(gobject.TYPE_STRING)
|
||||||
|
combobox = self.wTree.get_widget(lbl)
|
||||||
|
combobox.clear()
|
||||||
|
combobox.set_model(liststore)
|
||||||
|
cell = gtk.CellRendererText()
|
||||||
|
combobox.pack_start(cell, True)
|
||||||
|
combobox.add_attribute(cell, 'text', 0)
|
||||||
|
return combobox
|
||||||
|
|
||||||
|
def setup_label(name, lbl=""):
|
||||||
|
""" Sets up a label for the given widget name. """
|
||||||
|
widget = self.wTree.get_widget(name)
|
||||||
|
if lbl:
|
||||||
|
widget.set_label(language[lbl])
|
||||||
|
return widget
|
||||||
|
|
||||||
# External Programs tab
|
# External Programs tab
|
||||||
self.wTree.get_widget("gen_settings_label").set_label(language["gen_settings"])
|
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("ext_prog_label").set_label(language["ext_programs"])
|
||||||
@@ -312,3 +260,71 @@ class PreferencesDialog(object):
|
|||||||
self.set_label("pref_wifi_label", "%s:" % language['wireless_interface'])
|
self.set_label("pref_wifi_label", "%s:" % language['wireless_interface'])
|
||||||
self.set_label("pref_wired_label", "%s:" % language['wired_interface'])
|
self.set_label("pref_wired_label", "%s:" % language['wired_interface'])
|
||||||
self.set_label("pref_driver_label", "%s:" % language['wpa_supplicant_driver'])
|
self.set_label("pref_driver_label", "%s:" % language['wpa_supplicant_driver'])
|
||||||
|
|
||||||
|
self.dialog = self.wTree.get_widget("pref_dialog")
|
||||||
|
self.dialog.set_title(language['preferences'])
|
||||||
|
if os.path.exists(os.path.join(wpath.images, "wicd.png")):
|
||||||
|
self.dialog.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
|
||||||
|
size = daemon.ReadWindowSize("pref")
|
||||||
|
width = size[0]
|
||||||
|
height = size[1]
|
||||||
|
if width > -1 and height > -1:
|
||||||
|
self.dialog.resize(int(width), int(height))
|
||||||
|
else:
|
||||||
|
self.dialog.resize(gtk.gdk.screen_width() / 3,
|
||||||
|
gtk.gdk.screen_height() / 2)
|
||||||
|
|
||||||
|
self.wiredcheckbox = setup_label("pref_always_check",
|
||||||
|
'wired_always_on')
|
||||||
|
|
||||||
|
self.reconnectcheckbox = setup_label("pref_auto_check",
|
||||||
|
'auto_reconnect')
|
||||||
|
self.debugmodecheckbox = setup_label("pref_debug_check",
|
||||||
|
'use_debug_mode')
|
||||||
|
self.displaytypecheckbox = setup_label("pref_dbm_check",
|
||||||
|
'display_type_dialog')
|
||||||
|
self.usedefaultradiobutton = setup_label("pref_use_def_radio",
|
||||||
|
'use_default_profile')
|
||||||
|
self.showlistradiobutton = setup_label("pref_prompt_radio",
|
||||||
|
'show_wired_list')
|
||||||
|
self.lastusedradiobutton = setup_label("pref_use_last_radio",
|
||||||
|
'use_last_used_profile')
|
||||||
|
|
||||||
|
|
||||||
|
# DHCP Clients
|
||||||
|
self.dhcpautoradio = setup_label("dhcp_auto_radio", "wicd_auto_config")
|
||||||
|
self.dhclientradio = self.wTree.get_widget("dhclient_radio")
|
||||||
|
self.pumpradio = self.wTree.get_widget("pump_radio")
|
||||||
|
self.dhcpcdradio = self.wTree.get_widget("dhcpcd_radio")
|
||||||
|
|
||||||
|
# Wired Link Detection Apps
|
||||||
|
self.linkautoradio = setup_label("link_auto_radio", 'wicd_auto_config')
|
||||||
|
self.linkautoradio = setup_label("link_auto_radio")
|
||||||
|
self.ethtoolradio = setup_label("ethtool_radio")
|
||||||
|
self.miitoolradio = setup_label("miitool_radio")
|
||||||
|
|
||||||
|
# Route Flushing Apps
|
||||||
|
self.flushautoradio = setup_label("flush_auto_radio",
|
||||||
|
'wicd_auto_config')
|
||||||
|
self.ipflushradio = setup_label("ip_flush_radio")
|
||||||
|
self.routeflushradio = setup_label("route_flush_radio")
|
||||||
|
|
||||||
|
# Replacement for the combo box hack
|
||||||
|
self.wpadrivercombo = build_combobox("pref_wpa_combobox")
|
||||||
|
self.wpadrivers = ["wext", "hostap", "madwifi", "atmel",
|
||||||
|
"ndiswrapper", "ipw"]
|
||||||
|
self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers)
|
||||||
|
self.wpadrivers.append("ralink_legacy")
|
||||||
|
|
||||||
|
self.entryWirelessInterface = self.wTree.get_widget("pref_wifi_entry")
|
||||||
|
self.entryWiredInterface = self.wTree.get_widget("pref_wired_entry")
|
||||||
|
|
||||||
|
# Set up global DNS stuff
|
||||||
|
self.useGlobalDNSCheckbox = setup_label("pref_global_check",
|
||||||
|
'use_global_dns')
|
||||||
|
self.searchDomEntry = self.wTree.get_widget("pref_search_dom_entry")
|
||||||
|
self.dns1Entry = self.wTree.get_widget("pref_dns1_entry")
|
||||||
|
self.dns2Entry = self.wTree.get_widget("pref_dns2_entry")
|
||||||
|
self.dns3Entry = self.wTree.get_widget("pref_dns3_entry")
|
||||||
|
|
||||||
|
self.backendcombo = build_combobox("pref_backend_combobox")
|
||||||
@@ -642,7 +642,7 @@ Arguments:
|
|||||||
|
|
||||||
def setup_dbus(force=True):
|
def setup_dbus(force=True):
|
||||||
global bus, daemon, wireless, wired, DBUS_AVAIL
|
global bus, daemon, wireless, wired, DBUS_AVAIL
|
||||||
|
print "Connecting to daemon..."
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
@@ -653,7 +653,7 @@ def setup_dbus(force=True):
|
|||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
gui.error(None, "Could not connect to wicd's D-Bus interface. " +
|
gui.error(None, "Could not connect to wicd's D-Bus interface. " +
|
||||||
"Check the wicd log for error messages.")
|
"Check the wicd log for error messages.")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@@ -664,6 +664,7 @@ def setup_dbus(force=True):
|
|||||||
wireless = dbus_ifaces['wireless']
|
wireless = dbus_ifaces['wireless']
|
||||||
wired = dbus_ifaces['wired']
|
wired = dbus_ifaces['wired']
|
||||||
DBUS_AVAIL = True
|
DBUS_AVAIL = True
|
||||||
|
print "Connected."
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -672,25 +673,9 @@ def handle_no_dbus():
|
|||||||
DBUS_AVAIL = False
|
DBUS_AVAIL = False
|
||||||
gui.handle_no_dbus(from_tray=True)
|
gui.handle_no_dbus(from_tray=True)
|
||||||
print "Wicd daemon is shutting down!"
|
print "Wicd daemon is shutting down!"
|
||||||
gui.error(None, "The wicd daemon has shut down, the UI will not function " +
|
gui.error(None, language['lost_dbus'], block=False)
|
||||||
"properly until it is restarted.")
|
|
||||||
_wait_for_dbus()
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@misc.threaded
|
|
||||||
def _wait_for_dbus():
|
|
||||||
global DBUS_AVAIL
|
|
||||||
while True:
|
|
||||||
time.sleep(10)
|
|
||||||
print "Trying to reconnect.."
|
|
||||||
if not setup_dbus(force=False):
|
|
||||||
print "Failed to reconnect to the daemon."
|
|
||||||
else:
|
|
||||||
print "Successfully reconnected to the daemon."
|
|
||||||
gui.setup_dbus(force=False)
|
|
||||||
DBUS_AVAIL = True
|
|
||||||
return
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
""" The main frontend program.
|
""" The main frontend program.
|
||||||
|
|
||||||
@@ -750,7 +735,9 @@ def main(argv):
|
|||||||
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(lambda: handle_no_dbus() or tray_icon.icon_info.set_not_connected_state(),
|
bus.add_signal_receiver(lambda: handle_no_dbus() or tray_icon.icon_info.set_not_connected_state(),
|
||||||
"DaemonClosing", 'org.wicd.daemon')
|
"DaemonClosing", 'org.wicd.daemon')
|
||||||
print 'Done.'
|
bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting",
|
||||||
|
"org.wicd.daemon")
|
||||||
|
print 'Done loading.'
|
||||||
mainloop = gobject.MainLoop()
|
mainloop = gobject.MainLoop()
|
||||||
mainloop.run()
|
mainloop.run()
|
||||||
|
|
||||||
|
|||||||
@@ -83,9 +83,8 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
self.wired = networking.Wired()
|
self.wired = networking.Wired()
|
||||||
self.config = ConfigManager(os.path.join(wpath.etc,
|
self.config = ConfigManager(os.path.join(wpath.etc,
|
||||||
"manager-settings.conf"))
|
"manager-settings.conf"))
|
||||||
self.wired_bus= WiredDaemon(bus_name, wired=self.wired, wifi=self.wifi)
|
self.wired_bus= WiredDaemon(bus_name, self, wired=self.wired)
|
||||||
self.wireless_bus = WirelessDaemon(bus_name, wired=self.wired,
|
self.wireless_bus = WirelessDaemon(bus_name, self, wifi=self.wifi)
|
||||||
wifi=self.wifi)
|
|
||||||
self.forced_disconnect = False
|
self.forced_disconnect = False
|
||||||
self.need_profile_chooser = False
|
self.need_profile_chooser = False
|
||||||
self.current_interface = None
|
self.current_interface = None
|
||||||
@@ -106,14 +105,10 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
# need a fresh scan, just feed them the old one. A fresh scan
|
# need a fresh scan, just feed them the old one. A fresh scan
|
||||||
# can be done by calling Scan(fresh=True).
|
# can be done by calling Scan(fresh=True).
|
||||||
self.LastScan = ''
|
self.LastScan = ''
|
||||||
|
|
||||||
# Kind of hackish way to set correct wnettools interfaces.
|
|
||||||
#TODO remove the need for this.
|
|
||||||
self.wifi.liface = self.wired.liface
|
|
||||||
self.wired.wiface = self.wifi.wiface
|
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, self.DaemonClosing)
|
signal.signal(signal.SIGTERM, self.DaemonClosing)
|
||||||
|
self.DaemonStarting()
|
||||||
|
|
||||||
# Scan since we just got started
|
# Scan since we just got started
|
||||||
if auto_connect:
|
if auto_connect:
|
||||||
print "autoconnecting if needed...", str(self.GetWirelessInterface())
|
print "autoconnecting if needed...", str(self.GetWirelessInterface())
|
||||||
@@ -145,7 +140,6 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
""" Sets the wired interface for the daemon to use. """
|
""" Sets the wired interface for the daemon to use. """
|
||||||
print "setting wired interface %s" % (str(interface))
|
print "setting wired interface %s" % (str(interface))
|
||||||
self.wired.wired_interface = noneToBlankString(interface)
|
self.wired.wired_interface = noneToBlankString(interface)
|
||||||
self.wifi.wired_interface = noneToBlankString(interface)
|
|
||||||
self.config.set("Settings", "wired_interface", interface, True)
|
self.config.set("Settings", "wired_interface", interface, True)
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
@@ -153,7 +147,6 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
""" Sets the wireless interface the daemon will use. """
|
""" Sets the wireless interface the daemon will use. """
|
||||||
print "setting wireless interface %s" % (str(interface))
|
print "setting wireless interface %s" % (str(interface))
|
||||||
self.wifi.wireless_interface = noneToBlankString(interface)
|
self.wifi.wireless_interface = noneToBlankString(interface)
|
||||||
self.wired.wireless_interface = noneToBlankString(interface)
|
|
||||||
self.config.set("Settings", "wireless_interface", interface, True)
|
self.config.set("Settings", "wireless_interface", interface, True)
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
@@ -319,9 +312,7 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetAutoReconnect(self):
|
def GetAutoReconnect(self):
|
||||||
""" Returns the value of self.auto_reconnect. See SetAutoReconnect. """
|
""" Returns the value of self.auto_reconnect. See SetAutoReconnect. """
|
||||||
do = bool(self.auto_reconnect)
|
return bool(self.auto_reconnect)
|
||||||
return self.__printReturn('returning automatically reconnect when ' \
|
|
||||||
+ 'connection drops', do)
|
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetAutoReconnect(self, value):
|
def SetAutoReconnect(self, value):
|
||||||
@@ -357,9 +348,13 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
print 'canceling connection attempt'
|
print 'canceling connection attempt'
|
||||||
if self.wifi.connecting_thread:
|
if self.wifi.connecting_thread:
|
||||||
self.wifi.connecting_thread.should_die = True
|
self.wifi.connecting_thread.should_die = True
|
||||||
|
self.wifi.StopDHCP()
|
||||||
|
self.wifi.StopWPA()
|
||||||
|
self.wifi.connecting_thread.connect_result = 'aborted'
|
||||||
if self.wired.connecting_thread:
|
if self.wired.connecting_thread:
|
||||||
self.wired.connecting_thread.should_die = True
|
self.wired.connecting_thread.should_die = True
|
||||||
misc.Run("killall dhclient dhclient3 wpa_supplicant")
|
self.wired.StopDHCP()
|
||||||
|
self.wired.connecting_thread.connect_result = 'aborted'
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetCurrentInterface(self):
|
def GetCurrentInterface(self):
|
||||||
@@ -698,13 +693,44 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
return False
|
return False
|
||||||
self.auto_connecting = False
|
self.auto_connecting = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@dbus.service.method("org.wicd.daemon")
|
||||||
|
def ConnectResultsAvailable(self):
|
||||||
|
if ((self.wired.connecting_thread and self.wired.connecting_thread.connect_result) or
|
||||||
|
(self.wifi.connecting_thread and self.wifi.connecting_thread.connect_result)):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@dbus.service.method("org.wicd.daemon")
|
||||||
|
def SendConnectResultsIfAvail(self):
|
||||||
|
if self.ConnectResultsAvailable():
|
||||||
|
self.SendConnectResult()
|
||||||
|
|
||||||
|
@dbus.service.method("org.wicd.daemon")
|
||||||
|
def SendConnectResult(self):
|
||||||
|
if self.wired.connecting_thread and self.wired.connecting_thread.connect_result:
|
||||||
|
self.ConnectResultsSent(self.wired.connecting_thread.connect_result)
|
||||||
|
self.wired.connecting_thread.connect_result = ""
|
||||||
|
elif self.wifi.connecting_thread and self.wifi.connecting_thread.connect_result:
|
||||||
|
self.ConnectResultsSent(self.wifi.connecting_thread.connect_result)
|
||||||
|
self.wifi.connecting_thread.connect_result = ""
|
||||||
|
|
||||||
|
@dbus.service.signal(dbus_interface="org.wicd.daemon",signature='s')
|
||||||
|
def ConnectResultsSent(self, result):
|
||||||
|
print "Sending connection attempt result %s" % result
|
||||||
|
|
||||||
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
|
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
|
||||||
def LaunchChooser(self):
|
def LaunchChooser(self):
|
||||||
""" Emits the wired profile chooser dbus signal. """
|
""" Emits the wired profile chooser dbus signal. """
|
||||||
print 'calling wired profile chooser'
|
print 'calling wired profile chooser'
|
||||||
self.SetNeedWiredProfileChooser(True)
|
self.SetNeedWiredProfileChooser(True)
|
||||||
|
|
||||||
|
@dbus.service.signal(dbus_interface="org.wicd.daemon", signature='')
|
||||||
|
def DaemonStarting(self):
|
||||||
|
""" Emits a signa indicating the daemon is starting. """
|
||||||
|
pass
|
||||||
|
|
||||||
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
|
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
|
||||||
def DaemonClosing(self):
|
def DaemonClosing(self):
|
||||||
""" Emits a signal indicating the daemon will be closing. """
|
""" Emits a signal indicating the daemon will be closing. """
|
||||||
@@ -725,12 +751,6 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __printReturn(self, text, value):
|
|
||||||
""" Prints the specified text and value, then returns the value. """
|
|
||||||
if self.debug_mode:
|
|
||||||
print ''.join([text, " ", str(value)])
|
|
||||||
return value
|
|
||||||
|
|
||||||
def ReadConfig(self):
|
def ReadConfig(self):
|
||||||
""" Reads the manager-settings.conf file.
|
""" Reads the manager-settings.conf file.
|
||||||
|
|
||||||
@@ -817,12 +837,12 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
|
|
||||||
class WirelessDaemon(dbus.service.Object):
|
class WirelessDaemon(dbus.service.Object):
|
||||||
""" DBus interface for wireless connection operations. """
|
""" DBus interface for wireless connection operations. """
|
||||||
def __init__(self, bus_name, wired=None, wifi=None, debug=False):
|
def __init__(self, bus_name, daemon, wifi=None, debug=False):
|
||||||
""" Intitialize the wireless DBus interface. """
|
""" Intitialize the wireless DBus interface. """
|
||||||
dbus.service.Object.__init__(self, bus_name=bus_name,
|
dbus.service.Object.__init__(self, bus_name=bus_name,
|
||||||
object_path='/org/wicd/daemon/wireless')
|
object_path='/org/wicd/daemon/wireless')
|
||||||
self.hidden_essid = None
|
self.hidden_essid = None
|
||||||
self.wired = wired
|
self.daemon = daemon
|
||||||
self.wifi = wifi
|
self.wifi = wifi
|
||||||
self.debug_mode = debug
|
self.debug_mode = debug
|
||||||
self.forced_disconnect = False
|
self.forced_disconnect = False
|
||||||
@@ -877,8 +897,7 @@ class WirelessDaemon(dbus.service.Object):
|
|||||||
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
|
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
|
||||||
ics):
|
ics):
|
||||||
""" Creates an ad-hoc network using user inputted settings. """
|
""" Creates an ad-hoc network using user inputted settings. """
|
||||||
self.wifi.CreateAdHocNetwork(essid, channel, ip, enctype, key, encused,
|
self.wifi.CreateAdHocNetwork(essid, channel, ip, enctype, key, encused)
|
||||||
ics)
|
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def GetKillSwitchEnabled(self):
|
def GetKillSwitchEnabled(self):
|
||||||
@@ -1006,7 +1025,7 @@ class WirelessDaemon(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], debug=self.debug_mode)
|
conthread = 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):
|
||||||
@@ -1122,6 +1141,11 @@ class WirelessDaemon(dbus.service.Object):
|
|||||||
essid_key = "essid:" + str(self.LastScan[networkid])
|
essid_key = "essid:" + str(self.LastScan[networkid])
|
||||||
self.config.remove_section(essid_key)
|
self.config.remove_section(essid_key)
|
||||||
|
|
||||||
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
|
def GetWpaSupplicantDrivers(self, drivers):
|
||||||
|
""" Returns all valid wpa_supplicant drivers in a given list. """
|
||||||
|
return self.wifi.GetWpaSupplicantDrivers(drivers)
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def ReloadConfig(self):
|
def ReloadConfig(self):
|
||||||
""" Reloads the active config file. """
|
""" Reloads the active config file. """
|
||||||
@@ -1163,12 +1187,12 @@ class WirelessDaemon(dbus.service.Object):
|
|||||||
|
|
||||||
class WiredDaemon(dbus.service.Object):
|
class WiredDaemon(dbus.service.Object):
|
||||||
""" DBus interface for wired connection operations. """
|
""" DBus interface for wired connection operations. """
|
||||||
def __init__(self, bus_name, wired=None, wifi=None, debug=False):
|
def __init__(self, bus_name, daemon, wired=None, debug=False):
|
||||||
""" Intitialize the wireless DBus interface. """
|
""" Intitialize the wireless DBus interface. """
|
||||||
dbus.service.Object.__init__(self, bus_name=bus_name,
|
dbus.service.Object.__init__(self, bus_name=bus_name,
|
||||||
object_path="/org/wicd/daemon/wired")
|
object_path="/org/wicd/daemon/wired")
|
||||||
|
self.daemon = daemon
|
||||||
self.wired = wired
|
self.wired = wired
|
||||||
self.wifi = wifi
|
|
||||||
self.debug_mode = debug
|
self.debug_mode = debug
|
||||||
self.forced_disconnect = False
|
self.forced_disconnect = False
|
||||||
self.WiredNetwork = {}
|
self.WiredNetwork = {}
|
||||||
@@ -1560,7 +1584,10 @@ def sigterm_caught(sig=None, frame=None):
|
|||||||
global child_pid
|
global child_pid
|
||||||
if child_pid:
|
if child_pid:
|
||||||
print 'Daemon going down, killing wicd-monitor...'
|
print 'Daemon going down, killing wicd-monitor...'
|
||||||
os.kill(child_pid, signal.SIGTERM)
|
try:
|
||||||
|
os.kill(child_pid, signal.SIGTERM)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
print 'Removing PID file...'
|
print 'Removing PID file...'
|
||||||
if os.path.exists(wpath.pidfile):
|
if os.path.exists(wpath.pidfile):
|
||||||
os.remove(wpath.pidfile)
|
os.remove(wpath.pidfile)
|
||||||
@@ -1573,4 +1600,5 @@ if __name__ == '__main__':
|
|||||||
print ("Root privileges are required for the daemon to run properly." +
|
print ("Root privileges are required for the daemon to run properly." +
|
||||||
" Exiting.")
|
" Exiting.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
gobject.threads_init()
|
||||||
main(sys.argv)
|
main(sys.argv)
|
||||||
|
|||||||
@@ -131,6 +131,16 @@ def NeedsExternalCalls():
|
|||||||
""" Returns True if the backend needs to use an external program. """
|
""" Returns True if the backend needs to use an external program. """
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
def IsValidWpaSuppDriver(driver):
|
||||||
|
""" Returns True if given string is a valid wpa_supplicant driver. """
|
||||||
|
output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iwlan9",
|
||||||
|
"-c/etc/zzzzzzzz.confzzz"])
|
||||||
|
if re.match("Unsupported driver", output):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class BaseInterface(object):
|
class BaseInterface(object):
|
||||||
""" Control a network interface. """
|
""" Control a network interface. """
|
||||||
|
|||||||
Reference in New Issue
Block a user