1
0
mirror of https://github.com/gryf/wicd.git synced 2026-01-08 06:44:20 +01:00

Merged r285 upstream

This commit is contained in:
Robby Workman
2009-02-07 16:51:03 -06:00
13 changed files with 226 additions and 189 deletions

View File

@@ -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? 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. 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 chaos, too, so you might want to check that (or ask me about changing the
keymaps to ctrl/meta+KEY) keymaps to ctrl/meta+KEY)

View File

@@ -323,8 +323,6 @@ class PrefsDialog(urwid.WidgetWrap):
pass # It defaults to 0 anyway pass # It defaults to 0 anyway
self.backends = daemon.GetBackendList() 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.thebackends= [unicode(w) for w in self.backends]
self.backend_cbox.set_list(self.thebackends) self.backend_cbox.set_list(self.thebackends)
cur_backend = daemon.GetSavedBackend() cur_backend = daemon.GetSavedBackend()
@@ -438,53 +436,3 @@ class PrefsDialog(urwid.WidgetWrap):
return False return False
if self.OK_PRESSED or 'meta enter' in keys: if self.OK_PRESSED or 'meta enter' in keys:
return True 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)

View File

@@ -27,7 +27,7 @@ import subprocess
# VERSIONNUMBER # VERSIONNUMBER
VERSION_NUM = '1.6.0' VERSION_NUM = '1.6.0'
REVISION_NUM = 'unknown' REVISION_NUM = 'unknown'
CURSES_REVNO = 'r269' CURSES_REVNO = 'r270'
try: try:
if not os.path.exists('vcsinfo.py'): if not os.path.exists('vcsinfo.py'):

View File

@@ -444,6 +444,12 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
print 'wpa_supplicant rescan forced...' print 'wpa_supplicant rescan forced...'
cmd = 'wpa_cli -i' + self.iface + ' scan' cmd = 'wpa_cli -i' + self.iface + ' scan'
misc.Run(cmd) 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): def GetBSSID(self, iwconfig=None):
""" Get the MAC address for the interface. """ """ Get the MAC address for the interface. """

View File

@@ -273,7 +273,11 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
print "GetNetworks caught an exception: %s" % e print "GetNetworks caught an exception: %s" % e
return [] 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]) return filter(None, [self._parse_ap(cell) for cell in results])
def _parse_ap(self, cell): def _parse_ap(self, cell):
@@ -334,6 +338,18 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
return ap 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): def ValidateAuthentication(self, auth_time):
""" Validate WPA authentication. """ Validate WPA authentication.
@@ -359,15 +375,10 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
if self.wpa_driver == RALINK_DRIVER: if self.wpa_driver == RALINK_DRIVER:
return True return True
ctrl_iface = '/var/run/wpa_supplicant' wpa = self._connect_to_wpa_ctrl_iface()
try: if not wpa:
socket = [os.path.join(ctrl_iface, s) \ print "Failed to open ctrl interface"
for s in os.listdir(ctrl_iface) if s == self.iface][0] return False
except OSError:
print error
return True
wpa = wpactrl.WPACtrl(socket)
MAX_TIME = 35 MAX_TIME = 35
MAX_DISCONNECTED_TIME = 3 MAX_DISCONNECTED_TIME = 3
@@ -402,6 +413,13 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
print 'wpa_supplicant authentication may have failed.' print 'wpa_supplicant authentication may have failed.'
return False 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): def _AuthenticateRalinkLegacy(self, network):
""" Authenticate with the specified wireless network. """ Authenticate with the specified wireless network.

View File

@@ -38,6 +38,7 @@ from wicd import misc
from wicd import wpath from wicd import wpath
from wicd import dbusmanager from wicd import dbusmanager
from wicd import prefs from wicd import prefs
from wicd import netentry
from wicd.misc import noneToString from wicd.misc import noneToString
from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry
from wicd.prefs import PreferencesDialog from wicd.prefs import PreferencesDialog
@@ -67,6 +68,7 @@ def setup_dbus(force=True):
else: else:
return False return False
prefs.setup_dbus() prefs.setup_dbus()
netentry.setup_dbus()
bus = dbusmanager.get_bus() bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces() dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon'] daemon = dbus_ifaces['daemon']
@@ -91,7 +93,7 @@ class WiredProfileChooser:
""" Initializes and runs the wired profile chooser. """ """ Initializes and runs the wired profile chooser. """
# Import and init WiredNetworkEntry to steal some of the # Import and init WiredNetworkEntry to steal some of the
# functions and widgets it uses. # 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'], dialog = gtk.Dialog(title = language['wired_network_found'],
flags = gtk.DIALOG_MODAL, flags = gtk.DIALOG_MODAL,
@@ -213,14 +215,18 @@ class appGui(object):
'ConnectResultsSent', 'org.wicd.daemon') 'ConnectResultsSent', 'org.wicd.daemon')
bus.add_signal_receiver(lambda: setup_dbus(force=False), bus.add_signal_receiver(lambda: setup_dbus(force=False),
"DaemonStarting", "org.wicd.daemon") "DaemonStarting", "org.wicd.daemon")
bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged',
'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")
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() self.refresh_clicked()
def handle_connection_results(self, results): def handle_connection_results(self, results):
@@ -349,18 +355,20 @@ class appGui(object):
return True return True
def update_statusbar(self): def update_statusbar(self):
""" Updates the status bar """ Triggers a status update in wicd-monitor. """
if not self.is_visible:
Queries the daemon for network connection information and return True
updates the GUI status bar based on the results.
if self.connecting:
""" self._do_statusbar_update(*daemon.GetConnectionStatus())
if not self.is_visible or self.refreshing: else:
daemon.UpdateState()
return True
def _do_statusbar_update(self, state, info):
if not self.is_visible:
return True return True
daemon.UpdateState()
[state, info] = daemon.GetConnectionStatus()
if state == misc.WIRED: if state == misc.WIRED:
return self.set_wired_state(info) return self.set_wired_state(info)
elif state == misc.WIRELESS: elif state == misc.WIRELESS:
@@ -369,14 +377,15 @@ class appGui(object):
return self.set_connecting_state(info) return self.set_connecting_state(info)
elif state in (misc.SUSPENDED, misc.NOT_CONNECTED): elif state in (misc.SUSPENDED, misc.NOT_CONNECTED):
return self.set_not_connected_state(info) return self.set_not_connected_state(info)
return True
def set_wired_state(self, info): 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])) self.set_status(language['connected_to_wired'].replace('$A', info[0]))
return True return True
def set_wireless_state(self, info): def set_wireless_state(self, info):
self._set_connected_state() self._set_not_connecting_state()
self.set_status(language['connected_to_wireless'].replace self.set_status(language['connected_to_wireless'].replace
('$A', info[1]).replace ('$A', info[1]).replace
('$B', daemon.FormatSignalForPrinting(info[2])).replace ('$B', daemon.FormatSignalForPrinting(info[2])).replace
@@ -385,10 +394,11 @@ class appGui(object):
def set_not_connected_state(self, info): def set_not_connected_state(self, info):
self.connecting = False self.connecting = False
self._set_not_connecting_state()
self.set_status(language['not_connected']) self.set_status(language['not_connected'])
return True return True
def _set_connected_state(self): def _set_not_connecting_state(self):
self.connecting = False self.connecting = False
if self.pulse_active: if self.pulse_active:
self.pulse_active = False self.pulse_active = False
@@ -444,8 +454,7 @@ class appGui(object):
""" """
if not DBUS_AVAIL: return 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): def dbus_scan_started(self):
""" Called when a wireless scan starts. """ """ Called when a wireless scan starts. """
@@ -454,7 +463,7 @@ class appGui(object):
def refresh_clicked(self, widget=None): def refresh_clicked(self, widget=None):
""" Kick off an asynchronous wireless scan. """ """ Kick off an asynchronous wireless scan. """
if not DBUS_AVAIL: return if not DBUS_AVAIL or self.connecting: return
self.refreshing = True self.refreshing = True
wireless.Scan(False) wireless.Scan(False)
@@ -485,7 +494,7 @@ class appGui(object):
if wired.CheckPluggedIn() or daemon.GetAlwaysShowWiredInterface(): if wired.CheckPluggedIn() or daemon.GetAlwaysShowWiredInterface():
printLine = True # In this case we print a separator. 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) self.network_list.pack_start(wirednet, False, False)
wirednet.connect_button.connect("button-press-event", self.connect, wirednet.connect_button.connect("button-press-event", self.connect,
"wired", 0, wirednet) "wired", 0, wirednet)
@@ -499,7 +508,6 @@ class appGui(object):
instruct_label = self.wTree.get_widget("label_instructions") instruct_label = self.wTree.get_widget("label_instructions")
if num_networks > 0: if num_networks > 0:
instruct_label.show() instruct_label.show()
dbus_ifaces = dbusmanager.get_dbus_ifaces()
for x in range(0, num_networks): for x in range(0, num_networks):
if printLine: if printLine:
sep = gtk.HSeparator() sep = gtk.HSeparator()
@@ -508,7 +516,7 @@ class appGui(object):
sep.show() sep.show()
else: else:
printLine = True printLine = True
tempnet = WirelessNetworkEntry(x, dbus_ifaces) tempnet = WirelessNetworkEntry(x)
self.network_list.pack_start(tempnet, False, False) self.network_list.pack_start(tempnet, False, False)
tempnet.connect_button.connect("button-press-event", tempnet.connect_button.connect("button-press-event",
self.connect, "wireless", x, self.connect, "wireless", x,
@@ -676,6 +684,9 @@ class appGui(object):
""" """
self.window.hide() 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() [width, height] = self.window.get_size()
try: try:
daemon.WriteWindowSize(width, height, "main") daemon.WriteWindowSize(width, height, "main")
@@ -702,6 +713,12 @@ class appGui(object):
daemon.SetGUIOpen(True) daemon.SetGUIOpen(True)
self.wait_for_events(0.1) self.wait_for_events(0.1)
gobject.idle_add(self.refresh_clicked) 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__': if __name__ == '__main__':

View File

@@ -454,7 +454,7 @@ def get_language_list_gui():
language['use_static_ip'] = _('Use Static IPs') language['use_static_ip'] = _('Use Static IPs')
language['use_static_dns'] = _('Use Static DNS') language['use_static_dns'] = _('Use Static DNS')
language['use_encryption'] = _('Use Encryption') language['use_encryption'] = _('Use Encryption')
language['advanced_settings'] = _('Properties') language['advanced_settings'] = _('Advanced Settings')
language['wired_network'] = _('Wired Network') language['wired_network'] = _('Wired Network')
language['wired_network_instructions'] = _('To connect to a 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' ' 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.__name__ = f.__name__
wrapper.__dict__ = f.__dict__ wrapper.__dict__ = f.__dict__
wrapper.__doc__ = f.__doc__ wrapper.__doc__ = f.__doc__
wrapper.__module__ = f.__module__
return wrapper return wrapper

View File

@@ -26,6 +26,7 @@ when appropriate.
import gobject import gobject
import time import time
import sys
from dbus import DBusException from dbus import DBusException
@@ -46,23 +47,42 @@ wireless = dbus_dict["wireless"]
monitor = to_time = update_callback = None 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 ConnectionStatus(object):
""" Class for monitoring the computer's connection status. """ """ Class for monitoring the computer's connection status. """
def __init__(self): def __init__(self):
""" Initialize variables needed for the connection status methods. """ """ Initialize variables needed for the connection status methods. """
self.last_strength = -2 self.last_strength = -2
self.last_state = misc.NOT_CONNECTED
self.last_reconnect_time = time.time()
self.last_network = ""
self.displayed_strength = -1 self.displayed_strength = -1
self.still_wired = False self.still_wired = False
self.network = '' self.network = ''
self.tried_reconnect = False self.tried_reconnect = False
self.connection_lost_counter = 0 self.connection_lost_counter = 0
self.last_state = misc.NOT_CONNECTED
self.reconnecting = False self.reconnecting = False
self.reconnect_tries = 0 self.reconnect_tries = 0
self.last_reconnect_time = time.time()
self.signal_changed = False self.signal_changed = False
self.iwconfig = "" self.iwconfig = ""
self.trigger_reconnect = False self.trigger_reconnect = False
self.__lost_dbus_count = 0
bus = dbusmanager.get_bus() bus = dbusmanager.get_bus()
bus.add_signal_receiver(self._force_update_connection_status, bus.add_signal_receiver(self._force_update_connection_status,
@@ -136,13 +156,15 @@ class ConnectionStatus(object):
self.connection_lost_counter = 0 self.connection_lost_counter = 0
if (wifi_signal != self.last_strength or 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_strength = wifi_signal
self.last_network = self.network
self.signal_changed = True self.signal_changed = True
daemon.SetCurrentInterface(daemon.GetWirelessInterface()) daemon.SetCurrentInterface(daemon.GetWirelessInterface())
return True return True
@diewithdbus
def update_connection_status(self): def update_connection_status(self):
""" Updates the tray icon and current connection status. """ Updates the tray icon and current connection status.
@@ -153,56 +175,53 @@ class ConnectionStatus(object):
""" """
wired_ip = None wired_ip = None
wifi_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. if daemon.GetSuspend():
# Are we currently connecting? print "Suspended."
if daemon.CheckIfConnecting(): state = misc.SUSPENDED
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) self.update_state(state)
except DBusException, e: return True
print 'Ignoring DBus Error: ' + str(e)
# 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 return True
def _force_update_connection_status(self): def _force_update_connection_status(self):
@@ -245,8 +264,8 @@ class ConnectionStatus(object):
daemon.SetConnectionStatus(state, info) daemon.SetConnectionStatus(state, info)
# Send a D-Bus signal announcing status has changed if necessary. # Send a D-Bus signal announcing status has changed if necessary.
if state != self.last_state or \ if (state != self.last_state or (state == misc.WIRELESS and
(state == misc.WIRELESS and self.signal_changed): self.signal_changed)):
daemon.EmitStatusChanged(state, info) daemon.EmitStatusChanged(state, info)
self.last_state = state self.last_state = state
return True return True
@@ -311,12 +330,12 @@ def err_handle(error):
def add_poll_callback(): def add_poll_callback():
global monitor, to_time, update_callback global monitor, to_time, update_callback
try: if hasattr(gobject, "timeout_add_seconds"):
update_callback = gobject.timeout_add_seconds(to_time, update_callback = gobject.timeout_add_seconds(to_time,
monitor.update_connection_status) monitor.update_connection_status)
except: else:
update_callback = gobject.timeout_add(to_time * 1000, update_callback = gobject.timeout_add(to_time * 1000,
monitor.update_connection_status) monitor.update_connection_status)
def main(): def main():
""" Starts the connection monitor. """ Starts the connection monitor.

View File

@@ -20,6 +20,7 @@ import os
import misc import misc
import wpath import wpath
import dbusmanager
from misc import noneToString, stringToNone, noneToBlankString, to_bool from misc import noneToString, stringToNone, noneToBlankString, to_bool
from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input
@@ -30,6 +31,12 @@ daemon = None
wired = None wired = None
wireless = 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): class AdvancedSettingsDialog(gtk.Dialog):
def __init__(self): def __init__(self):
""" Build the base advanced settings dialog. """ Build the base advanced settings dialog.
@@ -466,17 +473,14 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
class NetworkEntry(gtk.HBox): class NetworkEntry(gtk.HBox):
def __init__(self, dbus_ifaces): def __init__(self):
""" Base network entry class. """ Base network entry class.
Provides gtk objects used by both the WiredNetworkEntry and Provides gtk objects used by both the WiredNetworkEntry and
WirelessNetworkEntry classes. WirelessNetworkEntry classes.
""" """
global daemon, wired, wireless setup_dbus()
daemon = dbus_ifaces["daemon"]
wired = dbus_ifaces["wired"]
wireless = dbus_ifaces["wireless"]
gtk.HBox.__init__(self, False, 2) gtk.HBox.__init__(self, False, 2)
self.image = gtk.Image() self.image = gtk.Image()
self.pack_start(self.image, False, False) self.pack_start(self.image, False, False)
@@ -533,9 +537,9 @@ class NetworkEntry(gtk.HBox):
class WiredNetworkEntry(NetworkEntry): class WiredNetworkEntry(NetworkEntry):
def __init__(self, dbus_ifaces): def __init__(self):
""" Load the wired network entry. """ """ Load the wired network entry. """
NetworkEntry.__init__(self, dbus_ifaces) NetworkEntry.__init__(self)
# Center the picture and pad it a bit # Center the picture and pad it a bit
self.image.set_padding(0, 0) self.image.set_padding(0, 0)
self.image.set_alignment(.5, .5) self.image.set_alignment(.5, .5)
@@ -718,9 +722,9 @@ class WiredNetworkEntry(NetworkEntry):
class WirelessNetworkEntry(NetworkEntry): class WirelessNetworkEntry(NetworkEntry):
def __init__(self, networkID, dbus_ifaces): def __init__(self, networkID):
""" Build the wireless network entry. """ """ Build the wireless network entry. """
NetworkEntry.__init__(self, dbus_ifaces) NetworkEntry.__init__(self)
self.networkID = networkID self.networkID = networkID
self.image.set_padding(0, 0) self.image.set_padding(0, 0)

View File

@@ -71,6 +71,7 @@ def abortable(func):
wrapper.__name__ = func.__name__ wrapper.__name__ = func.__name__
wrapper.__dict__ = func.__dict__ wrapper.__dict__ = func.__dict__
wrapper.__doc__ = func.__doc__ wrapper.__doc__ = func.__doc__
wrapper.__module = func.__module__
return wrapper return wrapper
def get_backend_list(): def get_backend_list():
@@ -151,11 +152,11 @@ class Controller(object):
self.iface = None self.iface = None
self.backend_manager = BackendManager() self.backend_manager = BackendManager()
def get_debug(self): return self._debug
def set_debug(self, value): def set_debug(self, value):
self._debug = value self._debug = value
if self.iface: if self.iface:
self.iface.SetDebugMode(value) self.iface.SetDebugMode(value)
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):
@@ -187,10 +188,6 @@ class Controller(object):
else: else:
return True return True
def StopDHCP(self):
""" Stops all running DHCP clients. """
return BACKEND.StopDHCP()
def GetIP(self, ifconfig=""): def GetIP(self, ifconfig=""):
""" Get the IP of the interface. """ Get the IP of the interface.
@@ -208,9 +205,14 @@ class Controller(object):
misc.ExecuteScript(expand_script_macros(self.disconnect_script, 'disconnection', *args)) misc.ExecuteScript(expand_script_macros(self.disconnect_script, 'disconnection', *args))
iface.ReleaseDHCP() iface.ReleaseDHCP()
iface.SetAddress('0.0.0.0') iface.SetAddress('0.0.0.0')
iface.FlushRoutes()
iface.Down() iface.Down()
iface.Up() iface.Up()
def ReleaseDHCP(self):
""" Release the DHCP lease for this interface. """
return self.iface.ReleaseDHCP()
def IsUp(self): def IsUp(self):
""" Calls the IsUp method for the wired interface. """ Calls the IsUp method for the wired interface.
@@ -435,12 +437,6 @@ class ConnectThread(threading.Thread):
print "Releasing DHCP leases..." print "Releasing DHCP leases..."
iface.ReleaseDHCP() 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. """ """ Sets the thread status to aborted. """
if self.abort_reason: if self.abort_reason:
@@ -643,8 +639,8 @@ class Wireless(Controller):
""" """
wiface = self.wiface wiface = self.wiface
print 'Creating ad-hoc network' print 'Creating ad-hoc network'
print 'Killing dhclient and wpa_supplicant' print 'Stopping dhcp client and wpa_supplicant'
BACKEND.StopDHCP() BACKEND.ReleaseDHCP()
wiface.StopWPA() wiface.StopWPA()
print 'Putting wireless interface down' print 'Putting wireless interface down'
wiface.Down() wiface.Down()
@@ -761,7 +757,6 @@ class WirelessConnectThread(ConnectThread):
self.put_iface_down(wiface) self.put_iface_down(wiface)
self.release_dhcp_clients(wiface) self.release_dhcp_clients(wiface)
self.reset_ip_addresses(wiface) self.reset_ip_addresses(wiface)
self.stop_dhcp_clients(wiface)
self.stop_wpa(wiface) self.stop_wpa(wiface)
self.flush_routes(wiface) self.flush_routes(wiface)
@@ -971,7 +966,6 @@ class WiredConnectThread(ConnectThread):
self.put_iface_down(liface) self.put_iface_down(liface)
self.release_dhcp_clients(liface) self.release_dhcp_clients(liface)
self.reset_ip_addresses(liface) self.reset_ip_addresses(liface)
self.stop_dhcp_clients(liface)
self.flush_routes(liface) self.flush_routes(liface)
# Bring up interface. # Bring up interface.

View File

@@ -74,6 +74,21 @@ DBUS_AVAIL = False
language = misc.get_language_list_tray() 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): class NetworkMenuItem(gtk.ImageMenuItem):
def __init__(self, lbl, is_active=False): def __init__(self, lbl, is_active=False):
gtk.ImageMenuItem.__init__(self) gtk.ImageMenuItem.__init__(self)
@@ -130,6 +145,7 @@ class TrayIcon(object):
handle_no_dbus() handle_no_dbus()
self.set_not_connected_state() self.set_not_connected_state()
@catchdbus
def wired_profile_chooser(self): def wired_profile_chooser(self):
""" Launch the wired profile chooser. """ """ Launch the wired profile chooser. """
gui.WiredProfileChooser() gui.WiredProfileChooser()
@@ -142,6 +158,7 @@ class TrayIcon(object):
self.tr.set_tooltip(language['connected_to_wired'].replace('$A', self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
wired_ip)) wired_ip))
@catchdbus
def set_wireless_state(self, info): def set_wireless_state(self, info):
""" Sets the icon info for a wireless state. """ """ Sets the icon info for a wireless state. """
lock = '' lock = ''
@@ -170,6 +187,7 @@ class TrayIcon(object):
cur_network + "...") cur_network + "...")
self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png")) self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
@catchdbus
def set_not_connected_state(self, info=None): def set_not_connected_state(self, info=None):
""" Set the icon info for the not connected state. """ """ Set the icon info for the not connected state. """
self.tr.set_from_file(wpath.images + "no-signal.png") self.tr.set_from_file(wpath.images + "no-signal.png")
@@ -182,6 +200,7 @@ class TrayIcon(object):
status = language['not_connected'] status = language['not_connected']
self.tr.set_tooltip(status) self.tr.set_tooltip(status)
@catchdbus
def update_tray_icon(self, state=None, info=None): def update_tray_icon(self, state=None, info=None):
""" Updates the tray icon and current connection status. """ """ Updates the tray icon and current connection status. """
if not self.use_tray or not DBUS_AVAIL: return False if not self.use_tray or not DBUS_AVAIL: return False
@@ -202,6 +221,7 @@ class TrayIcon(object):
return False return False
return True return True
@catchdbus
def set_signal_image(self, wireless_signal, lock): def set_signal_image(self, wireless_signal, lock):
""" Sets the tray icon image for an active wireless connection. """ """ Sets the tray icon image for an active wireless connection. """
if self.animate: if self.animate:
@@ -230,6 +250,7 @@ class TrayIcon(object):
img_file = ''.join([wpath.images, prefix, signal_img, lock, ".png"]) img_file = ''.join([wpath.images, prefix, signal_img, lock, ".png"])
self.tr.set_from_file(img_file) self.tr.set_from_file(img_file)
@catchdbus
def get_bandwidth_state(self): def get_bandwidth_state(self):
""" Determines what network activity state we are in. """ """ Determines what network activity state we are in. """
transmitting = False transmitting = False
@@ -408,6 +429,7 @@ class TrayIcon(object):
item.set_sensitive(False) item.set_sensitive(False)
del item del item
@catchdbus
def _get_img(self, net_id): def _get_img(self, net_id):
""" Determines which image to use for the wireless entries. """ """ Determines which image to use for the wireless entries. """
def fix_strength(val, default): def fix_strength(val, default):
@@ -441,6 +463,7 @@ class TrayIcon(object):
signal_img = 'signal-25.png' signal_img = 'signal-25.png'
return wpath.images + signal_img return wpath.images + signal_img
@catchdbus
def on_net_menu_activate(self, item): def on_net_menu_activate(self, item):
""" Trigger a background scan to populate the network menu. """ Trigger a background scan to populate the network menu.
@@ -464,6 +487,7 @@ class TrayIcon(object):
return True return True
wireless.Scan(False) wireless.Scan(False)
@catchdbus
def populate_network_menu(self, data=None): def populate_network_menu(self, data=None):
""" Populates the network list submenu. """ """ Populates the network list submenu. """
def get_prop(net_id, prop): def get_prop(net_id, prop):

View File

@@ -379,12 +379,12 @@ 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.ReleaseDHCP()
self.wifi.StopWPA() self.wifi.StopWPA()
self.wifi.connecting_thread.connect_result = 'aborted' 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
self.wired.StopDHCP() self.wired.ReleaseDHCP()
self.wired.connecting_thread.connect_result = 'aborted' self.wired.connecting_thread.connect_result = 'aborted'
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
@@ -1120,6 +1120,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']
self.daemon.wired_bus.DisconnectWired()
conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode) conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
self.daemon.UpdateState() self.daemon.UpdateState()
@@ -1424,6 +1425,7 @@ class WiredDaemon(dbus.service.Object):
self.wired.before_script = self.GetWiredProperty("beforescript") self.wired.before_script = self.GetWiredProperty("beforescript")
self.wired.after_script = self.GetWiredProperty("afterscript") self.wired.after_script = self.GetWiredProperty("afterscript")
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript") self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
self.daemon.wireless_bus.DisconnectWireless()
self.wired.Connect(self.WiredNetwork, debug=self.debug_mode) self.wired.Connect(self.WiredNetwork, debug=self.debug_mode)
self.daemon.UpdateState() self.daemon.UpdateState()

View File

@@ -47,7 +47,7 @@ blacklist_strict = '!"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ '
blacklist_norm = ";`$!*|><&\\" blacklist_norm = ";`$!*|><&\\"
blank_trans = maketrans("", "") blank_trans = maketrans("", "")
__all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces", "StopDHCP", __all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces",
"GetWirelessInterfaces", "IsValidWpaSuppDriver", "NeedsExternalCalls"] "GetWirelessInterfaces", "IsValidWpaSuppDriver", "NeedsExternalCalls"]
def _sanitize_string(string): def _sanitize_string(string):
@@ -107,11 +107,6 @@ def GetDefaultGateway():
print 'couldn\'t retrieve default gateway from route -n' print 'couldn\'t retrieve default gateway from route -n'
return gateway return gateway
def StopDHCP():
""" Stop the DHCP client. """
cmd = 'killall dhclient dhclient3 pump dhcpcd-bin'
misc.Run(cmd)
def GetWirelessInterfaces(): def GetWirelessInterfaces():
""" Get available wireless interfaces. """ Get available wireless interfaces.
@@ -455,7 +450,7 @@ class BaseInterface(object):
""" """
if not self.iface: return False 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 #cmd = self.DHCP_CMD + " " + self.iface
if self.verbose: print cmd if self.verbose: print cmd
pipe = misc.Run(cmd, include_stderr=True, return_pipe=True) pipe = misc.Run(cmd, include_stderr=True, return_pipe=True)
@@ -471,20 +466,31 @@ class BaseInterface(object):
def ReleaseDHCP(self): def ReleaseDHCP(self):
""" Release the DHCP lease for this interface. """ """ Release the DHCP lease for this interface. """
if not self.iface: return False if not self.iface: return False
cmd = "%s %s" % (self._get_dhcp_command("release"), self.iface) cmd = self._get_dhcp_command("release")
#cmd = self.DHCP_RELEASE + " " + self.iface
if self.verbose: print cmd if self.verbose: print cmd
misc.Run(cmd) misc.Run(cmd)
def FlushRoutes(self): def DelDefaultRoute(self):
""" Flush all network routes. """ """ Delete only the default route for a device. """
if not self.iface: return False if not self.iface: return False
if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]: if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]:
#cmd = "ip route flush dev " + self.iface cmd = '%s route del default dev %s' % (self.ip_cmd, self.iface)
cmds = ['%s route flush all' % self.ip_cmd]
elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]: elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]:
cmds = ['%s del default' % self.route_cmd] cmd = '%s del default dev %s' % (self.route_cmd, self.iface)
cmds.append('route del dev %s' % 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: else:
print "No flush command available!" print "No flush command available!"
cmds = [] cmds = []
@@ -583,9 +589,7 @@ class BaseWirelessInterface(BaseInterface):
def StopWPA(self): def StopWPA(self):
""" Stop wireless encryption. """ """ Stop wireless encryption. """
cmd = 'killall wpa_supplicant' raise NotImplementedError
if self.verbose: print cmd
misc.Run(cmd)
def GetKillSwitchStatus(self): def GetKillSwitchStatus(self):
""" Determines if the wireless killswitch is enabled. """ Determines if the wireless killswitch is enabled.