1
0
mirror of https://github.com/gryf/wicd.git synced 2026-03-03 15:25:50 +01:00

Merged with experimental (r216)

This commit is contained in:
Andrew Psaltis
2008-12-17 10:30:55 -05:00
14 changed files with 323 additions and 272 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Sun Oct 12 01:15:35 2008 --> <!--Generated with glade3 3.4.5 on Mon Dec 15 00:29:12 2008 -->
<glade-interface> <glade-interface>
<widget class="GtkWindow" id="window1"> <widget class="GtkWindow" id="window1">
<property name="width_request">450</property> <property name="width_request">450</property>
@@ -36,107 +36,33 @@
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<child> <child>
<widget class="GtkMenu" id="menu1"> <widget class="GtkMenu" id="menu2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="attach_widget">network_menu</property>
<child> <child>
<widget class="GtkImageMenuItem" id="create_adhoc_network_button"> <widget class="GtkImageMenuItem" id="create_ad_hoc_button">
<property name="visible">True</property> <property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="label" translatable="yes">Create an ad-hoc network</property>
<property name="label" translatable="yes">Create Ad-Hoc Network</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<signal name="activate" handler="create_adhoc_network_button_button"/> <signal name="activate" handler="create_adhoc_clicked"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="menu-item-image2"> <widget class="GtkImage" id="menu-item-image10">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-add</property> <property name="stock">gtk-add</property>
<property name="icon_size">1</property>
</widget> </widget>
</child> </child>
</widget> </widget>
</child> </child>
<child> <child>
<widget class="GtkMenuItem" id="iface_menu_button"> <widget class="GtkImageMenuItem" id="find_hidden_button">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Enable/Disable Interfaces</property> <property name="tooltip" translatable="yes">Enter a hidden network to try to locate.</property>
<property name="label" translatable="yes">Find a hidden network</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child> <signal name="activate" handler="hidden_clicked"/>
<widget class="GtkMenu" id="iface_menu">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkImageMenuItem" id="iface_menu_enable_wired">
<property name="visible">True</property>
<property name="label" translatable="yes">Enable Wired Interface</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_iface_menu_enable_wired"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image5">
<property name="visible">True</property>
<property name="stock">gtk-yes</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="iface_menu_enable_wireless">
<property name="visible">True</property>
<property name="label" translatable="yes">Enable Wireless Interface</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_iface_menu_enable_wireless"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image6">
<property name="visible">True</property>
<property name="stock">gtk-yes</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="iface_menu_disable_wired">
<property name="visible">True</property>
<property name="label" translatable="yes">Disable Wired Interface</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_iface_menu_disable_wired"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image7">
<property name="visible">True</property>
<property name="stock">gtk-stop</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="iface_menu_disable_wireless">
<property name="visible">True</property>
<property name="label" translatable="yes">Disable Wireless Interface</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_iface_menu_disable_wireless"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image8">
<property name="visible">True</property>
<property name="stock">gtk-stop</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="connect_button">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Hidden Network</property>
<property name="use_underline">True</property>
<signal name="activate" handler="connect_clicked"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="menu-item-image1"> <widget class="GtkImage" id="menu-item-image9">
<property name="visible">True</property> <property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="icon_name">wicd</property>
<property name="icon_name">network-wireless</property>
</widget> </widget>
</child> </child>
</widget> </widget>
@@ -468,7 +394,6 @@
<property name="title" translatable="yes">Preferences</property> <property name="title" translatable="yes">Preferences</property>
<property name="default_width">125</property> <property name="default_width">125</property>
<property name="default_height">560</property> <property name="default_height">560</property>
<property name="icon">.</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<child internal-child="vbox"> <child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox4"> <widget class="GtkVBox" id="dialog-vbox4">

View File

@@ -17,10 +17,6 @@ wicd_start() {
else else
echo "Starting wicd daemon..." echo "Starting wicd daemon..."
wicd 2>/dev/null 1>&2 wicd 2>/dev/null 1>&2
# Activate the pm-utils sleep hook
if [ ! -x /usr/lib/pm-utils/sleep.d/55wicd ]; then
chmod +x /usr/lib/pm-utils/sleep.d/55wicd
fi
fi fi
} }
@@ -32,11 +28,6 @@ wicd_stop() {
else else
pkill -f python.*wicd-daemon.py 2>/dev/null pkill -f python.*wicd-daemon.py 2>/dev/null
fi fi
# Deactivate the pm-utils sleep hook
if [ -x /usr/lib/pm-utils/sleep.d/55wicd ]; then
chmod -x /usr/lib/pm-utils/sleep.d/55wicd
fi
} }
# See how we were called and take appropriate action # See how we were called and take appropriate action

View File

@@ -20,25 +20,23 @@
import dbus import dbus
import time import time
import gobject import gobject
import sys
from dbus.mainloop.glib import DBusGMainLoop from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True) DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus() bus = dbus.SystemBus()
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon')
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
loop = gobject.MainLoop()
def reply_handle():
loop.quit() def handler(*args):
def error_handle(e):
loop.quit() loop.quit()
print daemon.Hello() print daemon.Hello()
time.sleep(3) time.sleep(3)
daemon.SetSuspend(False) daemon.SetSuspend(False)
if not daemon.CheckIfConnecting(): if not daemon.CheckIfConnecting():
print daemon.AutoConnect(True, reply_handler=reply_handle,
error_handler=error_handle)
daemon.SetForcedDisconnect(False) daemon.SetForcedDisconnect(False)
daemon.AutoConnect(True, reply_handler=handler, error_handler=handler)
loop = gobject.MainLoop()
loop.run()

View File

@@ -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

View File

@@ -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.

View File

@@ -24,15 +24,15 @@ reusable for other purposes as well.
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from ConfigParser import ConfigParser from ConfigParser import RawConfigParser
from wicd.misc import stringToNone from wicd.misc import stringToNone
class ConfigManager(ConfigParser): class ConfigManager(RawConfigParser):
""" A class that can be used to manage a given configuration file. """ """ A class that can be used to manage a given configuration file. """
def __init__(self, path): def __init__(self, path):
ConfigParser.__init__(self) RawConfigParser.__init__(self)
self.config_file = path self.config_file = path
self.read(path) self.read(path)
@@ -58,7 +58,7 @@ class ConfigManager(ConfigParser):
if not self.has_section(section): if not self.has_section(section):
self.add_section(section) self.add_section(section)
ConfigParser.set(self, section, str(option), str(value)) RawConfigParser.set(self, section, str(option), str(value))
if save: if save:
self.write() self.write()
@@ -66,7 +66,7 @@ class ConfigManager(ConfigParser):
""" Calls the set_option method. """ """ Calls the set_option method. """
self.set_option(*args, **kargs) self.set_option(*args, **kargs)
def get_option(self, section, option, default=None): def get_option(self, section, option, default="__None__"):
""" Wrapper around ConfigParser.get. """ Wrapper around ConfigParser.get.
Automatically adds any missing sections, adds the ability Automatically adds any missing sections, adds the ability
@@ -78,14 +78,17 @@ class ConfigManager(ConfigParser):
self.add_section(section) self.add_section(section)
if self.has_option(section, option): if self.has_option(section, option):
ret = ConfigParser.get(self, section, option) ret = RawConfigParser.get(self, section, option)
if default: if default:
print ''.join(['found ', option, ' in configuration ', ret]) print ''.join(['found ', option, ' in configuration ', ret])
else: else:
print ''.join(['did not find ', option, if default != "__None__":
print ''.join(['did not find ', option,
' in configuration, setting default ', str(default)]) ' in configuration, setting default ', str(default)])
self.set(section, option, str(default), save=True) self.set(section, option, str(default), save=True)
ret = default ret = default
else:
ret = None
# Try to intelligently handle the type of the return value. # Try to intelligently handle the type of the return value.
try: try:
@@ -101,7 +104,7 @@ class ConfigManager(ConfigParser):
def write(self): def write(self):
""" Writes the loaded config file to disk. """ """ Writes the loaded config file to disk. """
configfile = open(self.config_file, 'w') configfile = open(self.config_file, 'w')
ConfigParser.write(self, configfile) RawConfigParser.write(self, configfile)
configfile.close() configfile.close()
def remove_section(self,section): def remove_section(self,section):
@@ -112,4 +115,7 @@ class ConfigManager(ConfigParser):
""" """
if self.has_section(section): if self.has_section(section):
ConfigParser.remove_section(self, section) RawConfigParser.remove_section(self, section)
def reload(self):
self.read(self.config_file)

View File

@@ -122,6 +122,7 @@ def write_scripts(network, network_type, script_info):
con.set(network, "afterscript", script_info["post_entry"]) con.set(network, "afterscript", script_info["post_entry"])
con.set(network, "disconnectscript", script_info["disconnect_entry"]) con.set(network, "disconnectscript", script_info["disconnect_entry"])
con.write(open(wired_conf, "w")) con.write(open(wired_conf, "w"))
wired.ReloadConfig()
wired.ReadWiredNetworkProfile(network) wired.ReadWiredNetworkProfile(network)
wired.SaveWiredNetworkProfile(network) wired.SaveWiredNetworkProfile(network)
else: else:
@@ -133,9 +134,11 @@ def write_scripts(network, network_type, script_info):
con.set(bssid, "afterscript", script_info["post_entry"]) con.set(bssid, "afterscript", script_info["post_entry"])
con.set(bssid, "disconnectscript", script_info["disconnect_entry"]) con.set(bssid, "disconnectscript", script_info["disconnect_entry"])
con.write(open(wireless_conf, "w")) con.write(open(wireless_conf, "w"))
wireless.ReloadConfig()
wireless.ReadWirelessNetworkProfile(int(network)) wireless.ReadWirelessNetworkProfile(int(network))
wireless.SaveWirelessNetworkProfile(int(network)) wireless.SaveWirelessNetworkProfile(int(network))
def main (argv): def main (argv):
""" Runs the script configuration dialog. """ """ Runs the script configuration dialog. """
if len(argv) < 2: if len(argv) < 2:

View File

@@ -52,45 +52,62 @@ except:
proxy_obj = daemon = wireless = wired = bus = None proxy_obj = daemon = wireless = wired = bus = None
language = misc.get_language_list_gui() language = misc.get_language_list_gui()
DBUS_AVAIL = False
def setup_dbus(): def setup_dbus(force=True):
global bus, daemon, wireless, wired global bus, daemon, wireless, wired, DBUS_AVAIL
try: try:
dbusmanager.connect_to_dbus() dbusmanager.connect_to_dbus()
except DBusException: except DBusException:
print "Can't connect to the daemon, trying to start it automatically..." if force:
misc.PromptToStartDaemon() print "Can't connect to the daemon, trying to start it automatically..."
try: misc.PromptToStartDaemon()
dbusmanager.connect_to_dbus() try:
except DBusException: dbusmanager.connect_to_dbus()
error(None, "Could not connect to wicd's D-Bus interface. " + except DBusException:
"Make sure the daemon is started.") error(None, "Could not connect to wicd's D-Bus interface. " +
sys.exit(1) "Check the wicd log for error messages.")
return False
else:
return False
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']
wireless = dbus_ifaces['wireless'] wireless = dbus_ifaces['wireless']
wired = dbus_ifaces['wired'] wired = dbus_ifaces['wired']
DBUS_AVAIL = True
return True return True
def error(parent, message): def handle_no_dbus(from_tray=False):
global DBUS_AVAIL
DBUS_AVAIL = False
if from_tray: return False
print "Wicd daemon is shutting down!"
error(None, language['lost_dbus'], block=False)
return False
def error(parent, message, block=True):
""" 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
@@ -215,7 +232,7 @@ class appGui(object):
""" Initializes everything needed for the GUI. """ """ Initializes everything needed for the GUI. """
setup_dbus() setup_dbus()
gladefile = wpath.share + "wicd.glade" gladefile = os.path.join(wpath.share, "wicd.glade")
self.wTree = gtk.glade.XML(gladefile) self.wTree = gtk.glade.XML(gladefile)
self.window = self.wTree.get_widget("window1") self.window = self.wTree.get_widget("window1")
size = daemon.ReadWindowSize("main") size = daemon.ReadWindowSize("main")
@@ -232,10 +249,10 @@ class appGui(object):
"disconnect_clicked" : self.disconnect_all, "disconnect_clicked" : self.disconnect_all,
"main_exit" : self.exit, "main_exit" : self.exit,
"cancel_clicked" : self.cancel_connect, "cancel_clicked" : self.cancel_connect,
"connect_clicked" : self.connect_hidden, "hidden_clicked" : self.connect_hidden,
"preferences_clicked" : self.settings_dialog, "preferences_clicked" : self.settings_dialog,
"about_clicked" : self.about_dialog, "about_clicked" : self.about_dialog,
"create_adhoc_network_button_button" : self.create_adhoc_network, "create_adhoc_clicked" : self.create_adhoc_network,
} }
self.wTree.signal_autoconnect(dic) self.wTree.signal_autoconnect(dic)
@@ -253,12 +270,13 @@ class appGui(object):
self.status_area.hide_all() self.status_area.hide_all()
if os.path.exists(wpath.images + "wicd.png"): if os.path.exists(os.path.join(wpath.images, "wicd.png")):
self.window.set_icon_from_file(wpath.images + "wicd.png") self.window.set_icon_from_file(os.path.join(wpath.images, "wicd.png"))
self.statusID = None self.statusID = None
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
@@ -277,7 +295,11 @@ 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(setup_dbus, "DaemonClosing", "org.wicd.daemon") if standalone:
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
"org.wicd.daemon")
bus.add_signal_receiver(lambda: setup_dbus(force=False),
"DaemonStarting", "org.wicd.daemon")
try: try:
gobject.timeout_add_seconds(1, self.update_statusbar) gobject.timeout_add_seconds(1, self.update_statusbar)
except: except:
@@ -357,10 +379,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. """
@@ -465,6 +491,7 @@ class appGui(object):
current network state is the same as the previous. current network state is the same as the previous.
""" """
if not DBUS_AVAIL: return
if not state: if not state:
state, x = daemon.GetConnectionStatus() state, x = daemon.GetConnectionStatus()
@@ -520,15 +547,18 @@ class appGui(object):
This method is called after a wireless scan is completed. This method is called after a wireless scan is completed.
""" """
if not DBUS_AVAIL: return
if not self.connecting: 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. """
if not DBUS_AVAIL: return
self.network_list.set_sensitive(False) self.network_list.set_sensitive(False)
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
self.refreshing = True self.refreshing = True
wireless.Scan(reply_handler=None, error_handler=None) wireless.Scan(reply_handler=None, error_handler=None)

View File

@@ -69,7 +69,7 @@ def Run(cmd, include_stderr=False, return_pipe=False):
one output string from the command. one output string from the command.
""" """
if type(cmd) is not list: if not isinstance(cmd, list):
cmd = to_unicode(str(cmd)) cmd = to_unicode(str(cmd))
cmd = cmd.split() cmd = cmd.split()
if include_stderr: if include_stderr:
@@ -82,8 +82,12 @@ def Run(cmd, include_stderr=False, return_pipe=False):
tmpenv = os.environ.copy() tmpenv = os.environ.copy()
tmpenv["LC_ALL"] = "C" tmpenv["LC_ALL"] = "C"
tmpenv["LANG"] = "C" tmpenv["LANG"] = "C"
f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds, cwd='/', try:
env=tmpenv) f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds,
cwd='/', env=tmpenv)
except OSError, e:
print "Running command %s failed: %s" % (str(cmd), str(e))
return ""
if return_pipe: if return_pipe:
return f.stdout return f.stdout
@@ -383,7 +387,7 @@ def find_path(cmd):
the file can not be found. the file can not be found.
""" """
paths = os.getenv("PATH", default=["/usr/bin", "/usr/local/bin"]).split(':') paths = os.getenv("PATH", default="/usr/bin:/usr/local/bin").split(':')
for path in paths: for path in paths:
if os.access(os.path.join(path, cmd), os.F_OK): if os.access(os.path.join(path, cmd), os.F_OK):
return os.path.join(path, cmd) return os.path.join(path, cmd)
@@ -507,6 +511,7 @@ def get_language_list_gui():
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
@@ -531,6 +536,8 @@ def get_language_list_tray():
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['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):

View File

@@ -528,6 +528,11 @@ class Wireless(Controller):
""" Get the out of iwconfig. """ """ Get the out of iwconfig. """
return self.wiface.GetIwconfig() return self.wiface.GetIwconfig()
def GetWpaSupplicantDrivers(self, drivers):
""" Returns all valid wpa_supplicant drivers in a list. """
return [driver for driver in drivers if
BACKEND.IsValidWpaSuppDriver(driver)]
def IsUp(self): def IsUp(self):
""" Calls the IsUp method for the wireless interface. """ Calls the IsUp method for the wireless interface.

View File

@@ -27,8 +27,11 @@ 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.misc import checkboxTextboxToggle, noneToBlankString from wicd.misc import checkboxTextboxToggle, noneToBlankString
daemon = None daemon = None
@@ -53,85 +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'])
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()
@@ -145,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):
@@ -172,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))
@@ -198,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("")
@@ -226,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. """
@@ -287,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"])
@@ -309,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")

View File

@@ -59,7 +59,7 @@ if not hasattr(gtk, "StatusIcon"):
import egg.trayicon import egg.trayicon
USE_EGG = True USE_EGG = True
except ImportError: except ImportError:
print 'Unable to load tray icon: Missing egg.trayicon module.' print 'Unable to load tray icon: Missing both egg.trayicon and gtk.StatusIcon modules.'
ICON_AVAIL = False ICON_AVAIL = False
misc.RenameProcess("wicd-client") misc.RenameProcess("wicd-client")
@@ -125,7 +125,11 @@ class TrayIcon(object):
self.max_snd_gain = 10000 self.max_snd_gain = 10000
self.max_rcv_gain = 10000 self.max_rcv_gain = 10000
self.animate = animate self.animate = animate
self.update_tray_icon() if DBUS_AVAIL:
self.update_tray_icon()
else:
handle_no_dbus()
self.set_not_connected_state()
def wired_profile_chooser(self): def wired_profile_chooser(self):
""" Launch the wired profile chooser. """ """ Launch the wired profile chooser. """
@@ -135,7 +139,7 @@ class TrayIcon(object):
def set_wired_state(self, info): def set_wired_state(self, info):
""" Sets the icon info for a wired state. """ """ Sets the icon info for a wired state. """
wired_ip = info[0] wired_ip = info[0]
self.tr.set_from_file(wpath.images + "wired.png") self.tr.set_from_file(os.path.join(wpath.images, "wired.png"))
self.tr.set_tooltip(language['connected_to_wired'].replace('$A', self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
wired_ip)) wired_ip))
@@ -165,12 +169,14 @@ class TrayIcon(object):
cur_network = info[1] cur_network = info[1]
self.tr.set_tooltip(language['connecting'] + " to " + self.tr.set_tooltip(language['connecting'] + " to " +
cur_network + "...") cur_network + "...")
self.tr.set_from_file(wpath.images + "no-signal.png") self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
def set_not_connected_state(self, info): 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")
if wireless.GetKillSwitchEnabled(): if not DBUS_AVAIL:
status = language['no_daemon_tooltip']
elif wireless.GetKillSwitchEnabled():
status = (language['not_connected'] + " (" + status = (language['not_connected'] + " (" +
language['killswitch_enabled'] + ")") language['killswitch_enabled'] + ")")
else: else:
@@ -179,7 +185,7 @@ class TrayIcon(object):
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: return False if not self.use_tray or not DBUS_AVAIL: return False
if not state or not info: if not state or not info:
[state, info] = daemon.GetConnectionStatus() [state, info] = daemon.GetConnectionStatus()
@@ -342,22 +348,15 @@ class TrayIcon(object):
def tray_scan_started(self): def tray_scan_started(self):
""" Callback for when a wireless scan is started. """ """ Callback for when a wireless scan is started. """
if not DBUS_AVAIL: return
self._is_scanning = True self._is_scanning = True
self.init_network_menu() self.init_network_menu()
def tray_scan_ended(self): def tray_scan_ended(self):
""" Callback for when a wireless scan finishes. """ """ Callback for when a wireless scan finishes. """
if not DBUS_AVAIL: return
self._is_scanning = False self._is_scanning = False
self.populate_network_menu() self.populate_network_menu()
def dbus_lost(self):
""" Callback for when the daemon is going down. """
global DBUS_AVAIL
print "The daemon is going down!!"
DBUS_AVAIL = False
time.sleep(1)
while not setup_dbus():
time.sleep(20)
def on_activate(self, data=None): def on_activate(self, data=None):
""" Opens the wicd GUI. """ """ Opens the wicd GUI. """
@@ -474,6 +473,9 @@ class TrayIcon(object):
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/") net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
submenu = net_menuitem.get_submenu() submenu = net_menuitem.get_submenu()
self._clear_menu(submenu) self._clear_menu(submenu)
if not DBUS_AVAIL:
net_menuitem.show()
return
is_connecting = daemon.CheckIfConnecting() is_connecting = daemon.CheckIfConnecting()
num_networks = wireless.GetNumberOfNetworks() num_networks = wireless.GetNumberOfNetworks()
@@ -638,26 +640,42 @@ Arguments:
\t-a\t--no-animate\tRun the tray without network traffic tray animations. \t-a\t--no-animate\tRun the tray without network traffic tray animations.
""" """
def setup_dbus(): def setup_dbus(force=True):
global 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:
print "Can't connect to the daemon, trying to start it automatically..." if force:
misc.PromptToStartDaemon() print "Can't connect to the daemon, trying to start it automatically..."
try: misc.PromptToStartDaemon()
dbusmanager.connect_to_dbus() try:
except DBusException: dbusmanager.connect_to_dbus()
gui.error(None, language['cannot_start_daemon']) except DBusException:
sys.exit(1) gui.error(None, "Could not connect to wicd's D-Bus interface. " +
"Check the wicd log for error messages.")
return False
else:
return False
bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces() dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon'] daemon = dbus_ifaces['daemon']
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
def handle_no_dbus():
global DBUS_AVAIL
DBUS_AVAIL = False
gui.handle_no_dbus(from_tray=True)
print "Wicd daemon is shutting down!"
gui.error(None, language['lost_dbus'], block=False)
return False
def main(argv): def main(argv):
""" The main frontend program. """ The main frontend program.
@@ -702,7 +720,7 @@ def main(argv):
# Check to see if wired profile chooser was called before icon # Check to see if wired profile chooser was called before icon
# was launched (typically happens on startup or daemon restart). # was launched (typically happens on startup or daemon restart).
if daemon.GetNeedWiredProfileChooser(): if DBUS_AVAIL and daemon.GetNeedWiredProfileChooser():
daemon.SetNeedWiredProfileChooser(False) daemon.SetNeedWiredProfileChooser(False)
tray_icon.icon_info.wired_profile_chooser() tray_icon.icon_info.wired_profile_chooser()
@@ -715,9 +733,11 @@ def main(argv):
'org.wicd.daemon.wireless') 'org.wicd.daemon.wireless')
bus.add_signal_receiver(tray_icon.tr.tray_scan_started, bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
'SendStartScanSignal', 'org.wicd.daemon.wireless') 'SendStartScanSignal', 'org.wicd.daemon.wireless')
bus.add_signal_receiver(tray_icon.tr.dbus_lost, 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()

View File

@@ -113,7 +113,8 @@ class WicdDaemon(dbus.service.Object):
self.wired.wiface = self.wifi.wiface 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())
@@ -705,6 +706,11 @@ class WicdDaemon(dbus.service.Object):
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. """
@@ -1066,7 +1072,8 @@ class WirelessDaemon(dbus.service.Object):
def SaveWirelessNetworkProfile(self, id): def SaveWirelessNetworkProfile(self, id):
""" Writes a wireless profile to disk. """ """ Writes a wireless profile to disk. """
def write_script_ent(prof, script): def write_script_ent(prof, script):
self.config.set(prof, script, None) if not self.config.has_option(prof, script):
self.config.set(prof, script, None)
cur_network = self.LastScan[id] cur_network = self.LastScan[id]
bssid_key = cur_network["bssid"] bssid_key = cur_network["bssid"]
@@ -1088,12 +1095,12 @@ class WirelessDaemon(dbus.service.Object):
write_script_ent(bssid_key, "beforescript") write_script_ent(bssid_key, "beforescript")
write_script_ent(bssid_key, "afterscript") write_script_ent(bssid_key, "afterscript")
write_script_ent(bssid_key, "disconnect") write_script_ent(bssid_key, "disconnectscript")
if cur_network["use_settings_globally"]: if cur_network["use_settings_globally"]:
write_script_ent(essid_key, "beforescript") write_script_ent(essid_key, "beforescript")
write_script_ent(essid_key, "afterscript") write_script_ent(essid_key, "afterscript")
write_script_ent(essid_key, "disconnect") write_script_ent(essid_key, "disconnectscript")
self.config.write() self.config.write()
@@ -1120,7 +1127,17 @@ class WirelessDaemon(dbus.service.Object):
""" Removes the global entry for the networkid provided. """ """ Removes the global entry for the networkid provided. """
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')
def ReloadConfig(self):
""" Reloads the active config file. """
self.config.reload()
@dbus.service.signal(dbus_interface='org.wicd.daemon.wireless', signature='') @dbus.service.signal(dbus_interface='org.wicd.daemon.wireless', signature='')
def SendStartScanSignal(self): def SendStartScanSignal(self):
""" Emits a signal announcing a scan has started. """ """ Emits a signal announcing a scan has started. """
@@ -1395,6 +1412,11 @@ class WiredDaemon(dbus.service.Object):
if not sections: if not sections:
sections = [""] sections = [""]
return sections return sections
@dbus.service.method('org.wicd.daemon.wired')
def ReloadConfig(self):
""" Reloads the active config file. """
self.config.reload()
def usage(): def usage():
@@ -1529,10 +1551,11 @@ def main(argv):
daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect) daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect)
gobject.threads_init() gobject.threads_init()
if not no_poll: if not no_poll:
(child_pid, x, x, x) = gobject.spawn_async(["/usr/bin/python", "-O", (child_pid, x, x, x) = gobject.spawn_async(
wpath.lib + "monitor.py"], [misc.find_path("python"), "-O", os.path.join(wpath.lib, "monitor.py")],
flags=gobject.SPAWN_CHILD_INHERITS_STDIN) flags=gobject.SPAWN_CHILD_INHERITS_STDIN
signal.signal(signal.SIGTERM, sigterm_caught) )
signal.signal(signal.SIGTERM, sigterm_caught)
# Enter the main loop # Enter the main loop
mainloop = gobject.MainLoop() mainloop = gobject.MainLoop()
@@ -1546,8 +1569,12 @@ def main(argv):
def sigterm_caught(sig=None, frame=None): def sigterm_caught(sig=None, frame=None):
""" Called when a SIGTERM is caught, kills monitor.py before exiting. """ """ Called when a SIGTERM is caught, kills monitor.py before exiting. """
global child_pid global child_pid
print 'Daemon going down, killing wicd-monitor...' if child_pid:
os.kill(child_pid, signal.SIGTERM) print 'Daemon going down, killing wicd-monitor...'
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)

View File

@@ -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. """
@@ -752,7 +762,7 @@ class BaseWirelessInterface(BaseInterface):
""" """
if not self.iface: return False if not self.iface: return False
cmd = ['iwconfig', self.iface, 'essid', essid] cmd = ['iwconfig', self.iface, 'essid', essid]
if channel: if channel and str(channel).isdigit():
cmd.extend(['channel', str(channel)]) cmd.extend(['channel', str(channel)])
if bssid: if bssid:
cmd.extend(['ap', bssid]) cmd.extend(['ap', bssid])
@@ -770,7 +780,8 @@ class BaseWirelessInterface(BaseInterface):
if not wpa_pass_path: return None if not wpa_pass_path: return None
key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*', key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',
re.I | re.M | re.S) re.I | re.M | re.S)
cmd = ' '.join([wpa_pass_path, network['essid'], network['key']]) cmd = [wpa_pass_path, network['essid'], network['key']]
if self.verbose: print cmd
return misc.RunRegex(key_pattern, misc.Run(cmd)) return misc.RunRegex(key_pattern, misc.Run(cmd))
def Authenticate(self, network): def Authenticate(self, network):
@@ -784,9 +795,10 @@ class BaseWirelessInterface(BaseInterface):
if self.wpa_driver == RALINK_DRIVER: if self.wpa_driver == RALINK_DRIVER:
self._AuthenticateRalinkLegacy(network) self._AuthenticateRalinkLegacy(network)
else: else:
cmd = ''.join(['wpa_supplicant -B -i ', self.iface, ' -c ', cmd = ['wpa_supplicant', '-B', '-i', self.iface, '-c',
wpath.networks, network['bssid'].replace(':','').lower(), os.path.join(wpath.networks,
' -D ', self.wpa_driver]) network['bssid'].replace(':', '').lower()),
'-D', self.wpa_driver]
if self.verbose: print cmd if self.verbose: print cmd
misc.Run(cmd) misc.Run(cmd)