diff --git a/curses/README b/curses/README index 57fa171..377b764 100644 --- a/curses/README +++ b/curses/README @@ -49,7 +49,7 @@ Why didn't you call it wicd-urwid? There is a hachoir-urwid package out there. Why don't you support lower-case keybindings for most of the commands? I was trying to prevent mass chaos from happening because of mashing keys. - Of course, if you unwittingly have caps-lock on, that's going to cause said + Of course, if you unwittingly have caps-lock on, that's going to cause mass chaos, too, so you might want to check that (or ask me about changing the keymaps to ctrl/meta+KEY) diff --git a/curses/prefs_curses.py b/curses/prefs_curses.py index 1c92f82..b450886 100755 --- a/curses/prefs_curses.py +++ b/curses/prefs_curses.py @@ -323,8 +323,6 @@ class PrefsDialog(urwid.WidgetWrap): pass # It defaults to 0 anyway self.backends = daemon.GetBackendList() - # Remove the blank string b/c of some dbus mess - self.backends.remove('') self.thebackends= [unicode(w) for w in self.backends] self.backend_cbox.set_list(self.thebackends) cur_backend = daemon.GetSavedBackend() @@ -438,53 +436,3 @@ class PrefsDialog(urwid.WidgetWrap): return False if self.OK_PRESSED or 'meta enter' in keys: return True - - -### -### EXTERNAL ENTRY POINT STUFF -### -def run_it(): - dialog = PrefsDialog(None,(0,0),ui,dbusmanager.get_dbus_ifaces()) - keys = True - dim = ui.get_cols_rows() - dialog.load_settings() - dialog.ready_comboboxes(ui,dialog) - while True: - if keys: - ui.draw_screen(dim, dialog.render(dim, True)) - keys = ui.get_input() - - if "window resize" in keys: - dim = ui.get_cols_rows() - if "esc" in keys or 'Q' in keys: - return False - for k in keys: - dialog.keypress(dim, k) - if dialog.CANCEL_PRESSED: - return False - if dialog.OK_PRESSED: - dialog.save_results() - return True - -if __name__=='__main__': - try: - dbusmanager.connect_to_dbus() - except DBusException: - # I may need to be a little more verbose here. - # Suggestions as to what should go here - print "Can't connect to the daemon. Are you sure it is running?" - print "Please check the wicd log for error messages." - raise - ui = urwid.curses_display.Screen() - ui.register_palette([ - ('body','light gray','default'), - ('focus','dark magenta','light gray'), - ('header','light blue','default'), - ('important','light red','default'), - ('connected','dark green','default'), - ('connected focus','default','dark green'), - ('editcp', 'default', 'default', 'standout'), - ('editbx', 'light gray', 'dark blue'), - ('editfc', 'white','dark blue', 'bold'), - ('tab active','dark green','light gray')]) - ui.run_wrapper(run_it) diff --git a/setup.py b/setup.py index 2cd9e0c..da80ea5 100755 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ import subprocess # VERSIONNUMBER VERSION_NUM = '1.6.0' REVISION_NUM = 'unknown' -CURSES_REVNO = 'r269' +CURSES_REVNO = 'r270' try: if not os.path.exists('vcsinfo.py'): diff --git a/wicd/backends/be-external.py b/wicd/backends/be-external.py index d4180fc..5d74b85 100644 --- a/wicd/backends/be-external.py +++ b/wicd/backends/be-external.py @@ -444,6 +444,12 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): print 'wpa_supplicant rescan forced...' cmd = 'wpa_cli -i' + self.iface + ' scan' misc.Run(cmd) + + def StopWPA(self): + """ Terminates wpa using wpa_cli""" + cmd = 'wpa_cli -i %s terminate' % self.iface + if self.verbose: print cmd + misc.Run(cmd) def GetBSSID(self, iwconfig=None): """ Get the MAC address for the interface. """ diff --git a/wicd/backends/be-ioctl.py b/wicd/backends/be-ioctl.py index d0c5fe2..3ba9a48 100644 --- a/wicd/backends/be-ioctl.py +++ b/wicd/backends/be-ioctl.py @@ -273,7 +273,11 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): print "GetNetworks caught an exception: %s" % e return [] - results = self.scan_iface.Scan() + try: + results = self.scan_iface.Scan() + except iwscan.error, e: + print "ERROR: %s" + return [] return filter(None, [self._parse_ap(cell) for cell in results]) def _parse_ap(self, cell): @@ -334,6 +338,18 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): return ap + def _connect_to_wpa_ctrl_iface(self): + """ Connect to the wpa ctrl interface. """ + ctrl_iface = '/var/run/wpa_supplicant' + try: + socket = [os.path.join(ctrl_iface, s) \ + for s in os.listdir(ctrl_iface) if s == self.iface][0] + except OSError, error: + print error + return None + + return wpactrl.WPACtrl(socket) + def ValidateAuthentication(self, auth_time): """ Validate WPA authentication. @@ -359,15 +375,10 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): if self.wpa_driver == RALINK_DRIVER: return True - ctrl_iface = '/var/run/wpa_supplicant' - try: - socket = [os.path.join(ctrl_iface, s) \ - for s in os.listdir(ctrl_iface) if s == self.iface][0] - except OSError: - print error - return True - - wpa = wpactrl.WPACtrl(socket) + wpa = self._connect_to_wpa_ctrl_iface() + if not wpa: + print "Failed to open ctrl interface" + return False MAX_TIME = 35 MAX_DISCONNECTED_TIME = 3 @@ -402,6 +413,13 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): print 'wpa_supplicant authentication may have failed.' return False + + def StopWPA(self): + """ Terminates wpa_supplicant using its ctrl interface. """ + wpa = self._connect_to_wpa_ctrl_iface() + if not wpa: + return + wpa.request("TERMINATE") def _AuthenticateRalinkLegacy(self, network): """ Authenticate with the specified wireless network. diff --git a/wicd/gui.py b/wicd/gui.py index 88ef245..85be1ab 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -38,6 +38,7 @@ from wicd import misc from wicd import wpath from wicd import dbusmanager from wicd import prefs +from wicd import netentry from wicd.misc import noneToString from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry from wicd.prefs import PreferencesDialog @@ -67,6 +68,7 @@ def setup_dbus(force=True): else: return False prefs.setup_dbus() + netentry.setup_dbus() bus = dbusmanager.get_bus() dbus_ifaces = dbusmanager.get_dbus_ifaces() daemon = dbus_ifaces['daemon'] @@ -91,7 +93,7 @@ class WiredProfileChooser: """ Initializes and runs the wired profile chooser. """ # Import and init WiredNetworkEntry to steal some of the # functions and widgets it uses. - wired_net_entry = WiredNetworkEntry(dbusmanager.get_dbus_ifaces()) + wired_net_entry = WiredNetworkEntry() dialog = gtk.Dialog(title = language['wired_network_found'], flags = gtk.DIALOG_MODAL, @@ -213,14 +215,18 @@ class appGui(object): 'ConnectResultsSent', 'org.wicd.daemon') bus.add_signal_receiver(lambda: setup_dbus(force=False), "DaemonStarting", "org.wicd.daemon") + bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged', + 'org.wicd.daemon') if standalone: bus.add_signal_receiver(handle_no_dbus, "DaemonClosing", "org.wicd.daemon") - try: - gobject.timeout_add_seconds(2, self.update_statusbar) - except: - gobject.timeout_add(2000, self.update_statusbar) + self._do_statusbar_update(*daemon.GetConnectionStatus()) + self.wait_for_events(0.1) + if hasattr(gobject, "timeout_add_seconds"): + self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar) + else: + self.update_cb = gobject.timeout_add(2000, self.update_statusbar) self.refresh_clicked() def handle_connection_results(self, results): @@ -349,18 +355,20 @@ class appGui(object): return True def update_statusbar(self): - """ Updates the status bar - - Queries the daemon for network connection information and - updates the GUI status bar based on the results. - - """ - if not self.is_visible or self.refreshing: + """ Triggers a status update in wicd-monitor. """ + if not self.is_visible: + return True + + if self.connecting: + self._do_statusbar_update(*daemon.GetConnectionStatus()) + else: + daemon.UpdateState() + return True + + def _do_statusbar_update(self, state, info): + if not self.is_visible: return True - daemon.UpdateState() - [state, info] = daemon.GetConnectionStatus() - if state == misc.WIRED: return self.set_wired_state(info) elif state == misc.WIRELESS: @@ -369,14 +377,15 @@ class appGui(object): return self.set_connecting_state(info) elif state in (misc.SUSPENDED, misc.NOT_CONNECTED): return self.set_not_connected_state(info) + return True def set_wired_state(self, info): - self._set_connected_state() + self._set_not_connecting_state() self.set_status(language['connected_to_wired'].replace('$A', info[0])) return True def set_wireless_state(self, info): - self._set_connected_state() + self._set_not_connecting_state() self.set_status(language['connected_to_wireless'].replace ('$A', info[1]).replace ('$B', daemon.FormatSignalForPrinting(info[2])).replace @@ -385,10 +394,11 @@ class appGui(object): def set_not_connected_state(self, info): self.connecting = False + self._set_not_connecting_state() self.set_status(language['not_connected']) return True - def _set_connected_state(self): + def _set_not_connecting_state(self): self.connecting = False if self.pulse_active: self.pulse_active = False @@ -444,8 +454,7 @@ class appGui(object): """ if not DBUS_AVAIL: return - if not self.connecting: - gobject.idle_add(self.refresh_networks, None, False, None) + gobject.idle_add(self.refresh_networks, None, False, None) def dbus_scan_started(self): """ Called when a wireless scan starts. """ @@ -454,7 +463,7 @@ class appGui(object): def refresh_clicked(self, widget=None): """ Kick off an asynchronous wireless scan. """ - if not DBUS_AVAIL: return + if not DBUS_AVAIL or self.connecting: return self.refreshing = True wireless.Scan(False) @@ -485,7 +494,7 @@ class appGui(object): if wired.CheckPluggedIn() or daemon.GetAlwaysShowWiredInterface(): printLine = True # In this case we print a separator. - wirednet = WiredNetworkEntry(dbusmanager.get_dbus_ifaces()) + wirednet = WiredNetworkEntry() self.network_list.pack_start(wirednet, False, False) wirednet.connect_button.connect("button-press-event", self.connect, "wired", 0, wirednet) @@ -499,7 +508,6 @@ class appGui(object): instruct_label = self.wTree.get_widget("label_instructions") if num_networks > 0: instruct_label.show() - dbus_ifaces = dbusmanager.get_dbus_ifaces() for x in range(0, num_networks): if printLine: sep = gtk.HSeparator() @@ -508,7 +516,7 @@ class appGui(object): sep.show() else: printLine = True - tempnet = WirelessNetworkEntry(x, dbus_ifaces) + tempnet = WirelessNetworkEntry(x) self.network_list.pack_start(tempnet, False, False) tempnet.connect_button.connect("button-press-event", self.connect, "wireless", x, @@ -676,6 +684,9 @@ class appGui(object): """ self.window.hide() + gobject.source_remove(self.update_cb) + bus.remove_signal_receiver(self._do_statusbar_update, 'StatusChanged', + 'org.wicd.daemon') [width, height] = self.window.get_size() try: daemon.WriteWindowSize(width, height, "main") @@ -702,6 +713,12 @@ class appGui(object): daemon.SetGUIOpen(True) self.wait_for_events(0.1) gobject.idle_add(self.refresh_clicked) + bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged', + 'org.wicd.daemon') + if hasattr(gobject, "timeout_add_seconds"): + self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar) + else: + self.update_cb = gobject.timeout_add(2000, self.update_statusbar) if __name__ == '__main__': diff --git a/wicd/misc.py b/wicd/misc.py index d71b749..0f22f49 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -454,7 +454,7 @@ def get_language_list_gui(): language['use_static_ip'] = _('Use Static IPs') language['use_static_dns'] = _('Use Static DNS') language['use_encryption'] = _('Use Encryption') - language['advanced_settings'] = _('Properties') + language['advanced_settings'] = _('Advanced Settings') language['wired_network'] = _('Wired Network') language['wired_network_instructions'] = _('To connect to a wired network,' ' you must create a network profile. To create a network profile, type a' @@ -647,5 +647,6 @@ def threaded(f): wrapper.__name__ = f.__name__ wrapper.__dict__ = f.__dict__ wrapper.__doc__ = f.__doc__ + wrapper.__module__ = f.__module__ return wrapper diff --git a/wicd/monitor.py b/wicd/monitor.py index 2e4bac7..28be05a 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -26,6 +26,7 @@ when appropriate. import gobject import time +import sys from dbus import DBusException @@ -46,23 +47,42 @@ wireless = dbus_dict["wireless"] monitor = to_time = update_callback = None +def diewithdbus(func): + def wrapper(self, *__args, **__kargs): + try: + ret = func(self, *__args, **__kargs) + self.__lost_dbus_count = 0 + return ret + except dbusmanager.DBusException: + if self.__lost_dbus_count > 3: + sys.exit(1) + self.__lost_dbus_count += 1 + return True + + wrapper.__name__ = func.__name__ + wrapper.__dict__ = func.__dict__ + wrapper.__doc__ = func.__doc__ + return wrapper + class ConnectionStatus(object): """ Class for monitoring the computer's connection status. """ def __init__(self): """ Initialize variables needed for the connection status methods. """ self.last_strength = -2 + self.last_state = misc.NOT_CONNECTED + self.last_reconnect_time = time.time() + self.last_network = "" self.displayed_strength = -1 self.still_wired = False self.network = '' self.tried_reconnect = False self.connection_lost_counter = 0 - self.last_state = misc.NOT_CONNECTED self.reconnecting = False self.reconnect_tries = 0 - self.last_reconnect_time = time.time() self.signal_changed = False self.iwconfig = "" self.trigger_reconnect = False + self.__lost_dbus_count = 0 bus = dbusmanager.get_bus() bus.add_signal_receiver(self._force_update_connection_status, @@ -136,13 +156,15 @@ class ConnectionStatus(object): self.connection_lost_counter = 0 if (wifi_signal != self.last_strength or - self.network != wireless.GetCurrentNetwork(self.iwconfig)): + self.network != self.last_network): self.last_strength = wifi_signal + self.last_network = self.network self.signal_changed = True daemon.SetCurrentInterface(daemon.GetWirelessInterface()) return True + @diewithdbus def update_connection_status(self): """ Updates the tray icon and current connection status. @@ -153,56 +175,53 @@ class ConnectionStatus(object): """ wired_ip = None wifi_ip = None - - try: - if daemon.GetSuspend(): - print "Suspended." - state = misc.SUSPENDED - self.update_state(state) - return True - # Determine what our current state is. - # Are we currently connecting? - if daemon.CheckIfConnecting(): - state = misc.CONNECTING - self.update_state(state) - return True - - daemon.SendConnectResultsIfAvail() - - # Check for wired. - wired_ip = wired.GetWiredIP("") - wired_found = self.check_for_wired_connection(wired_ip) - # Trigger an AutoConnect if we're plugged in, not connected - # to a wired network, and the "autoswitch to wired" option - # is on. - if self.trigger_reconnect: - self.trigger_reconnect = False - wireless.DisconnectWireless() - daemon.AutoConnect(False, reply_handler=lambda:None, - error_handler=lambda:None) - return True - if wired_found: - self.update_state(misc.WIRED, wired_ip=wired_ip) - return True - - # Check for wireless - wifi_ip = wireless.GetWirelessIP("") - self.signal_changed = False - wireless_found = self.check_for_wireless_connection(wifi_ip) - if wireless_found: - self.update_state(misc.WIRELESS, wifi_ip=wifi_ip) - return True - - state = misc.NOT_CONNECTED - if self.last_state == misc.WIRELESS: - from_wireless = True - else: - from_wireless = False - self.auto_reconnect(from_wireless) + if daemon.GetSuspend(): + print "Suspended." + state = misc.SUSPENDED self.update_state(state) - except DBusException, e: - print 'Ignoring DBus Error: ' + str(e) + return True + + # Determine what our current state is. + # Are we currently connecting? + if daemon.CheckIfConnecting(): + state = misc.CONNECTING + self.update_state(state) + return True + + daemon.SendConnectResultsIfAvail() + + # Check for wired. + wired_ip = wired.GetWiredIP("") + wired_found = self.check_for_wired_connection(wired_ip) + # Trigger an AutoConnect if we're plugged in, not connected + # to a wired network, and the "autoswitch to wired" option + # is on. + if self.trigger_reconnect: + self.trigger_reconnect = False + wireless.DisconnectWireless() + daemon.AutoConnect(False, reply_handler=lambda:None, + error_handler=lambda:None) + return True + if wired_found: + self.update_state(misc.WIRED, wired_ip=wired_ip) + return True + + # Check for wireless + wifi_ip = wireless.GetWirelessIP("") + self.signal_changed = False + wireless_found = self.check_for_wireless_connection(wifi_ip) + if wireless_found: + self.update_state(misc.WIRELESS, wifi_ip=wifi_ip) + return True + + state = misc.NOT_CONNECTED + if self.last_state == misc.WIRELESS: + from_wireless = True + else: + from_wireless = False + self.auto_reconnect(from_wireless) + self.update_state(state) return True def _force_update_connection_status(self): @@ -245,8 +264,8 @@ class ConnectionStatus(object): daemon.SetConnectionStatus(state, info) # Send a D-Bus signal announcing status has changed if necessary. - if state != self.last_state or \ - (state == misc.WIRELESS and self.signal_changed): + if (state != self.last_state or (state == misc.WIRELESS and + self.signal_changed)): daemon.EmitStatusChanged(state, info) self.last_state = state return True @@ -311,12 +330,12 @@ def err_handle(error): def add_poll_callback(): global monitor, to_time, update_callback - try: + if hasattr(gobject, "timeout_add_seconds"): update_callback = gobject.timeout_add_seconds(to_time, monitor.update_connection_status) - except: + else: update_callback = gobject.timeout_add(to_time * 1000, - monitor.update_connection_status) + monitor.update_connection_status) def main(): """ Starts the connection monitor. diff --git a/wicd/netentry.py b/wicd/netentry.py index 8b4f541..ca92dc4 100644 --- a/wicd/netentry.py +++ b/wicd/netentry.py @@ -20,6 +20,7 @@ import os import misc import wpath +import dbusmanager from misc import noneToString, stringToNone, noneToBlankString, to_bool from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input @@ -30,6 +31,12 @@ daemon = None wired = None wireless = None +def setup_dbus(): + global daemon, wireless, wired + daemon = dbusmanager.get_interface('daemon') + wireless = dbusmanager.get_interface('wireless') + wired = dbusmanager.get_interface('wired') + class AdvancedSettingsDialog(gtk.Dialog): def __init__(self): """ Build the base advanced settings dialog. @@ -466,17 +473,14 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): class NetworkEntry(gtk.HBox): - def __init__(self, dbus_ifaces): + def __init__(self): """ Base network entry class. Provides gtk objects used by both the WiredNetworkEntry and WirelessNetworkEntry classes. """ - global daemon, wired, wireless - daemon = dbus_ifaces["daemon"] - wired = dbus_ifaces["wired"] - wireless = dbus_ifaces["wireless"] + setup_dbus() gtk.HBox.__init__(self, False, 2) self.image = gtk.Image() self.pack_start(self.image, False, False) @@ -533,9 +537,9 @@ class NetworkEntry(gtk.HBox): class WiredNetworkEntry(NetworkEntry): - def __init__(self, dbus_ifaces): + def __init__(self): """ Load the wired network entry. """ - NetworkEntry.__init__(self, dbus_ifaces) + NetworkEntry.__init__(self) # Center the picture and pad it a bit self.image.set_padding(0, 0) self.image.set_alignment(.5, .5) @@ -718,9 +722,9 @@ class WiredNetworkEntry(NetworkEntry): class WirelessNetworkEntry(NetworkEntry): - def __init__(self, networkID, dbus_ifaces): + def __init__(self, networkID): """ Build the wireless network entry. """ - NetworkEntry.__init__(self, dbus_ifaces) + NetworkEntry.__init__(self) self.networkID = networkID self.image.set_padding(0, 0) diff --git a/wicd/networking.py b/wicd/networking.py index 02a659f..627e3a3 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -71,6 +71,7 @@ def abortable(func): wrapper.__name__ = func.__name__ wrapper.__dict__ = func.__dict__ wrapper.__doc__ = func.__doc__ + wrapper.__module = func.__module__ return wrapper def get_backend_list(): @@ -151,11 +152,11 @@ class Controller(object): self.iface = None self.backend_manager = BackendManager() + def get_debug(self): return self._debug def set_debug(self, value): self._debug = value if self.iface: self.iface.SetDebugMode(value) - def get_debug(self): return self._debug debug = property(get_debug, set_debug) def set_dhcp_client(self, value): @@ -187,10 +188,6 @@ class Controller(object): else: return True - def StopDHCP(self): - """ Stops all running DHCP clients. """ - return BACKEND.StopDHCP() - def GetIP(self, ifconfig=""): """ Get the IP of the interface. @@ -208,9 +205,14 @@ class Controller(object): misc.ExecuteScript(expand_script_macros(self.disconnect_script, 'disconnection', *args)) iface.ReleaseDHCP() iface.SetAddress('0.0.0.0') + iface.FlushRoutes() iface.Down() iface.Up() + def ReleaseDHCP(self): + """ Release the DHCP lease for this interface. """ + return self.iface.ReleaseDHCP() + def IsUp(self): """ Calls the IsUp method for the wired interface. @@ -435,12 +437,6 @@ class ConnectThread(threading.Thread): 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): """ Sets the thread status to aborted. """ if self.abort_reason: @@ -643,8 +639,8 @@ class Wireless(Controller): """ wiface = self.wiface print 'Creating ad-hoc network' - print 'Killing dhclient and wpa_supplicant' - BACKEND.StopDHCP() + print 'Stopping dhcp client and wpa_supplicant' + BACKEND.ReleaseDHCP() wiface.StopWPA() print 'Putting wireless interface down' wiface.Down() @@ -761,7 +757,6 @@ class WirelessConnectThread(ConnectThread): self.put_iface_down(wiface) self.release_dhcp_clients(wiface) self.reset_ip_addresses(wiface) - self.stop_dhcp_clients(wiface) self.stop_wpa(wiface) self.flush_routes(wiface) @@ -971,7 +966,6 @@ class WiredConnectThread(ConnectThread): self.put_iface_down(liface) self.release_dhcp_clients(liface) self.reset_ip_addresses(liface) - self.stop_dhcp_clients(liface) self.flush_routes(liface) # Bring up interface. diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index 721e36c..5c46023 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -74,6 +74,21 @@ DBUS_AVAIL = False language = misc.get_language_list_tray() + +def catchdbus(func): + def wrapper(*args, **kwargs): + try: + return func(*args, **kwargs) + except DBusException, e: + print "warning: ignoring exception %s" % egg + return None + wrapper.__name__ = func.__name__ + wrapper.__module__ = func.__module__ + wrapper.__dict__ = func.__dict__ + wrapper.__doc__ = func.__doc__ + return wrapper + + class NetworkMenuItem(gtk.ImageMenuItem): def __init__(self, lbl, is_active=False): gtk.ImageMenuItem.__init__(self) @@ -130,6 +145,7 @@ class TrayIcon(object): handle_no_dbus() self.set_not_connected_state() + @catchdbus def wired_profile_chooser(self): """ Launch the wired profile chooser. """ gui.WiredProfileChooser() @@ -142,6 +158,7 @@ class TrayIcon(object): self.tr.set_tooltip(language['connected_to_wired'].replace('$A', wired_ip)) + @catchdbus def set_wireless_state(self, info): """ Sets the icon info for a wireless state. """ lock = '' @@ -170,6 +187,7 @@ class TrayIcon(object): cur_network + "...") self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png")) + @catchdbus def set_not_connected_state(self, info=None): """ Set the icon info for the not connected state. """ self.tr.set_from_file(wpath.images + "no-signal.png") @@ -182,6 +200,7 @@ class TrayIcon(object): status = language['not_connected'] self.tr.set_tooltip(status) + @catchdbus def update_tray_icon(self, state=None, info=None): """ Updates the tray icon and current connection status. """ if not self.use_tray or not DBUS_AVAIL: return False @@ -202,6 +221,7 @@ class TrayIcon(object): return False return True + @catchdbus def set_signal_image(self, wireless_signal, lock): """ Sets the tray icon image for an active wireless connection. """ if self.animate: @@ -230,6 +250,7 @@ class TrayIcon(object): img_file = ''.join([wpath.images, prefix, signal_img, lock, ".png"]) self.tr.set_from_file(img_file) + @catchdbus def get_bandwidth_state(self): """ Determines what network activity state we are in. """ transmitting = False @@ -408,6 +429,7 @@ class TrayIcon(object): item.set_sensitive(False) del item + @catchdbus def _get_img(self, net_id): """ Determines which image to use for the wireless entries. """ def fix_strength(val, default): @@ -441,6 +463,7 @@ class TrayIcon(object): signal_img = 'signal-25.png' return wpath.images + signal_img + @catchdbus def on_net_menu_activate(self, item): """ Trigger a background scan to populate the network menu. @@ -464,6 +487,7 @@ class TrayIcon(object): return True wireless.Scan(False) + @catchdbus def populate_network_menu(self, data=None): """ Populates the network list submenu. """ def get_prop(net_id, prop): diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 15e9ed4..44c6b2e 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -379,12 +379,12 @@ class WicdDaemon(dbus.service.Object): print 'canceling connection attempt' if self.wifi.connecting_thread: self.wifi.connecting_thread.should_die = True - self.wifi.StopDHCP() + self.wifi.ReleaseDHCP() self.wifi.StopWPA() self.wifi.connecting_thread.connect_result = 'aborted' if self.wired.connecting_thread: self.wired.connecting_thread.should_die = True - self.wired.StopDHCP() + self.wired.ReleaseDHCP() self.wired.connecting_thread.connect_result = 'aborted' @dbus.service.method('org.wicd.daemon') @@ -1120,6 +1120,7 @@ class WirelessDaemon(dbus.service.Object): self.wifi.disconnect_script = self.GetWirelessProperty(id, 'disconnectscript') print 'Connecting to wireless network ' + self.LastScan[id]['essid'] + self.daemon.wired_bus.DisconnectWired() conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode) self.daemon.UpdateState() @@ -1424,6 +1425,7 @@ class WiredDaemon(dbus.service.Object): self.wired.before_script = self.GetWiredProperty("beforescript") self.wired.after_script = self.GetWiredProperty("afterscript") self.wired.disconnect_script = self.GetWiredProperty("disconnectscript") + self.daemon.wireless_bus.DisconnectWireless() self.wired.Connect(self.WiredNetwork, debug=self.debug_mode) self.daemon.UpdateState() diff --git a/wicd/wnettools.py b/wicd/wnettools.py index dff9973..9dd9d8c 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -47,7 +47,7 @@ blacklist_strict = '!"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ ' blacklist_norm = ";`$!*|><&\\" blank_trans = maketrans("", "") -__all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces", "StopDHCP", +__all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces", "GetWirelessInterfaces", "IsValidWpaSuppDriver", "NeedsExternalCalls"] def _sanitize_string(string): @@ -107,11 +107,6 @@ def GetDefaultGateway(): print 'couldn\'t retrieve default gateway from route -n' return gateway -def StopDHCP(): - """ Stop the DHCP client. """ - cmd = 'killall dhclient dhclient3 pump dhcpcd-bin' - misc.Run(cmd) - def GetWirelessInterfaces(): """ Get available wireless interfaces. @@ -455,7 +450,7 @@ class BaseInterface(object): """ if not self.iface: return False - cmd = "%s %s" % (self._get_dhcp_command('connect'), self.iface) + cmd = self._get_dhcp_command('connect') #cmd = self.DHCP_CMD + " " + self.iface if self.verbose: print cmd pipe = misc.Run(cmd, include_stderr=True, return_pipe=True) @@ -471,20 +466,31 @@ class BaseInterface(object): def ReleaseDHCP(self): """ Release the DHCP lease for this interface. """ if not self.iface: return False - cmd = "%s %s" % (self._get_dhcp_command("release"), self.iface) - #cmd = self.DHCP_RELEASE + " " + self.iface + cmd = self._get_dhcp_command("release") if self.verbose: print cmd misc.Run(cmd) - def FlushRoutes(self): - """ Flush all network routes. """ + def DelDefaultRoute(self): + """ Delete only the default route for a device. """ if not self.iface: return False if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]: - #cmd = "ip route flush dev " + self.iface - cmds = ['%s route flush all' % self.ip_cmd] + cmd = '%s route del default dev %s' % (self.ip_cmd, self.iface) elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]: - cmds = ['%s del default' % self.route_cmd] - cmds.append('route del dev %s' % self.iface) + cmd = '%s del default dev %s' % (self.route_cmd, self.iface) + else: + print "No route manipulation command available!" + return + if self.verbose: print cmd + misc.Run(cmd) + + + def FlushRoutes(self): + """ Flush network routes for this device. """ + if not self.iface: return False + if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]: + cmds = ['%s route flush dev %s' % (self.ip_cmd, self.iface)] + elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]: + cmds = ['%s del dev %s' % (self.route_cmd, self.iface)] else: print "No flush command available!" cmds = [] @@ -583,9 +589,7 @@ class BaseWirelessInterface(BaseInterface): def StopWPA(self): """ Stop wireless encryption. """ - cmd = 'killall wpa_supplicant' - if self.verbose: print cmd - misc.Run(cmd) + raise NotImplementedError def GetKillSwitchStatus(self): """ Determines if the wireless killswitch is enabled.