diff --git a/encryption/templates/ttls b/encryption/templates/ttls index 65db422..002a92b 100644 --- a/encryption/templates/ttls +++ b/encryption/templates/ttls @@ -1,7 +1,7 @@ name = TTLS with WEP author = Adam Blackburn version = 1 -require anonymous_identity *Anonymous_Identity identity *Identity password *Password auth *Authentication +require identity *Identity password *Password auth *Authentication ----- ctrl_interface=/var/run/wpa_supplicant network={ @@ -9,7 +9,7 @@ network={ scan_ssid=$_SCAN eap=TTLS key_mgmt=IEEE8021X - identity="$_USERNAME" + identity="$_IDENTITY" password="$_PASSWORD" phase2="auth=$_AUTH" } diff --git a/setup.py b/setup.py index 65ee989..3235238 100755 --- a/setup.py +++ b/setup.py @@ -123,32 +123,32 @@ class configure(Command): self.distro_detect_failed = False self.initfile = 'init/default/wicd' - if os.access('/etc/redhat-release', os.F_OK): + if os.path.exists('/etc/redhat-release'): self.init = '/etc/rc.d/init.d/' self.initfile = 'init/redhat/wicd' - elif os.access('/etc/SuSE-release', os.F_OK): + elif os.path.exists('/etc/SuSE-release'): self.init = '/etc/init.d/' self.initfile = 'init/suse/wicd' - elif os.access('/etc/fedora-release', os.F_OK): + elif os.path.exists('/etc/fedora-release'): self.init = '/etc/rc.d/init.d/' self.initfile = 'init/redhat/wicd' - elif os.access('/etc/gentoo-release', os.F_OK): + elif os.path.exists('/etc/gentoo-release'): self.init = '/etc/init.d/' self.initfile = 'init/gentoo/wicd' - elif os.access('/etc/debian_version', os.F_OK): + elif os.path.exists('/etc/debian_version'): self.init = '/etc/init.d/' self.initfile = 'init/debian/wicd' - elif os.access('/etc/arch-release', os.F_OK): + elif os.path.exists('/etc/arch-release'): self.init = '/etc/rc.d/' self.initfile = 'init/arch/wicd' - elif os.access('/etc/slackware-version', os.F_OK) or \ - os.access('/etc/slamd64-version', os.F_OK): + elif os.path.exists('/etc/slackware-version') or \ + os.path.exists('/etc/slamd64-version'): self.init = '/etc/rc.d/' self.initfile = 'init/slackware/rc.wicd' self.docdir = '/usr/doc/wicd-%s' % VERSION_NUM self.mandir = '/usr/man/' self.no_install_acpi = True - elif os.access('/etc/pld-release', os.F_OK): + elif os.path.exists('/etc/pld-release'): self.init = '/etc/rc.d/init.d/' self.initfile = 'init/pld/wicd' else: @@ -174,7 +174,7 @@ class configure(Command): if len(pmutils_candidate) == 0 or returncode != 0 or not os.path.isabs(pmutils_candidate): raise ValueError else: - self.pmutils = pmutils_candidate + self.pmutils = pmutils_candidate except (OSError, ValueError): pass # use our default @@ -185,7 +185,7 @@ class configure(Command): if len(kdedir_candidate) == 0 or returncode != 0 or not os.path.isabs(kdedir_candidate): raise ValueError else: - self.kdedir = kdedir_candidate + '/share/autostart' + self.kdedir = kdedir_candidate + '/share/autostart' except (OSError, ValueError): # If kde-config isn't present or returns an error, then we can # assume that kde isn't installed on the user's system @@ -454,7 +454,10 @@ connect at startup to any preferred network within range. url="http://wicd.net", license="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html", ## scripts=['configscript.py', 'autoconnect.py', 'gui.py', 'wicd.py', 'daemon.py', 'suspend.py', 'monitor.py'], - py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', 'wicd.configmanager'], ext_modules=[iwscan_ext, wpactrl_ext], + py_modules=['wicd.networking', 'wicd.misc', 'wicd.gui', 'wicd.wnettools', 'wicd.wpath', + 'wicd.prefs', 'wicd.netentry', 'wicd.dbusmanager', 'wicd.logfile', 'wicd.backend', + 'wicd.configmanager', 'wicd.guiutil'], + ext_modules=[iwscan_ext, wpactrl_ext], data_files=data ) ##print "Running post-install configuration..." diff --git a/wicd/configmanager.py b/wicd/configmanager.py index c95b911..b636678 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -87,8 +87,7 @@ class ConfigManager(RawConfigParser): str(ret)]) else: if default != "__None__": - if self.debug: - print 'did not find %s in configuration, setting default %s' % (option, str(default)) + print 'did not find %s in configuration, setting default %s' % (option, str(default)) self.set(section, option, str(default), save=True) ret = default else: diff --git a/wicd/dbusmanager.py b/wicd/dbusmanager.py index 0063f64..0c25b6c 100644 --- a/wicd/dbusmanager.py +++ b/wicd/dbusmanager.py @@ -24,6 +24,7 @@ A module for managing wicd's dbus interfaces. # import dbus +from dbus import DBusException if getattr(dbus, "version", (0, 0, 0)) < (0, 80, 0): import dbus.glib else: diff --git a/wicd/gui.py b/wicd/gui.py index b1a3065..b630d15 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -40,6 +40,7 @@ from wicd import dbusmanager from wicd.misc import noneToString from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry from wicd.prefs import PreferencesDialog +from wicd.guiutil import error, GreyLabel, LabelEntry, SmallLabel if __name__ == '__main__': wpath.chdir(__file__) @@ -87,92 +88,6 @@ def handle_no_dbus(from_tray=False): error(None, language['lost_dbus'], block=False) return False -def error(parent, message, block=True): - """ Shows an error dialog """ - def delete_event(dialog, id): - dialog.destroy() - dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, - gtk.BUTTONS_OK) - dialog.set_markup(message) - if not block: - dialog.present() - dialog.connect("response", delete_event) - else: - dialog.run() - dialog.destroy() - -def alert(parent, message): - """ Shows an warning dialog """ - dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, - gtk.BUTTONS_OK) - dialog.set_markup(message) - dialog.present() - dialog.connect("response", lambda *args: dialog.destroy()) - -def dummy(x=None):pass - -######################################## -##### GTK EXTENSION CLASSES -######################################## - -class SmallLabel(gtk.Label): - def __init__(self, text=''): - gtk.Label.__init__(self, text) - self.set_size_request(50, -1) - -class LabelEntry(gtk.HBox): - """ A label on the left with a textbox on the right. """ - def __init__(self,text): - gtk.HBox.__init__(self) - self.entry = gtk.Entry() - self.entry.set_size_request(200, -1) - self.label = SmallLabel() - self.label.set_text(text) - self.label.set_size_request(170, -1) - self.pack_start(self.label, fill=False, expand=False) - self.pack_start(self.entry, fill=False, expand=False) - self.label.show() - self.entry.show() - self.entry.connect('focus-out-event', self.hide_characters) - self.entry.connect('focus-in-event', self.show_characters) - self.auto_hide_text = False - self.show() - - def set_text(self, text): - # For compatibility... - self.entry.set_text(text) - - def get_text(self): - return self.entry.get_text() - - def set_auto_hidden(self, value): - self.entry.set_visibility(False) - self.auto_hide_text = value - - def show_characters(self, widget=None, event=None): - # When the box has focus, show the characters - if self.auto_hide_text and widget: - self.entry.set_visibility(True) - - def set_sensitive(self, value): - self.entry.set_sensitive(value) - self.label.set_sensitive(value) - - def hide_characters(self, widget=None, event=None): - # When the box looses focus, hide them - if self.auto_hide_text and widget: - self.entry.set_visibility(False) - - -class GreyLabel(gtk.Label): - """ Creates a grey gtk.Label. """ - def __init__(self): - gtk.Label.__init__(self) - - def set_label(self, text): - self.set_markup("" + text + "") - self.set_alignment(0, 0) - class WiredProfileChooser: """ Class for displaying the wired profile chooser. """ @@ -291,6 +206,7 @@ class appGui(object): self.wait_for_events(0.2) self.window.connect('delete_event', self.exit) self.window.connect('key-release-event', self.key_event) + daemon.SetGUIOpen(True) bus.add_signal_receiver(self.dbus_scan_finished, 'SendEndScanSignal', 'org.wicd.daemon.wireless') bus.add_signal_receiver(self.dbus_scan_started, 'SendStartScanSignal', @@ -649,21 +565,30 @@ class appGui(object): # First make sure all the Addresses entered are valid. if entry.chkbox_static_ip.get_active(): - entlist = [ent for ent in [entry.txt_ip, entry.txt_netmask, - entry.txt_gateway]] + req_entlist = [entry.txt_ip, enty.txt_netmask] + opt_entlist = [entry.txt_gateway] if entry.chkbox_static_dns.get_active() and \ not entry.chkbox_global_dns.get_active(): - entlist.append(entry.txt_dns_1) + req_entlist.append(entry.txt_dns_1) # Only append additional dns entries if they're entered. for ent in [entry.txt_dns_2, entry.txt_dns_3]: if ent.get_text() != "": - entlist.append(ent) - for lblent in entlist: + opt_entlist.append(ent) + + # Required entries. + for lblent in req_entlist: if not misc.IsValidIP(lblent.get_text()): error(self.window, language['invalid_address']. replace('$A', lblent.label.get_label())) return False + + # Optional entries, only check for validity if they're entered. + for lblent in opt_entlist: + if lblent.get_text() and not misc.IsValidIP(lblent.get_text()): + error(self.window, language['invalid_address']. + replace('$A', lblent.label.get_label())) + return False # Now save the settings. if nettype == "wireless": diff --git a/wicd/misc.py b/wicd/misc.py index 5f7f928..30b473a 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -399,7 +399,7 @@ def choose_sudo_prog(): for p in env_path: paths.extend([p + '/gksudo', p + "/gksu", p + '/ktsuss']) for path in paths: - if os.access(path, os.F_OK): + if os.path.exists(path): return path return None @@ -414,7 +414,7 @@ def find_path(cmd): """ paths = os.getenv("PATH", default="/usr/bin:/usr/local/bin").split(':') for path in paths: - if os.access(os.path.join(path, cmd), os.F_OK): + if os.path.exists(os.path.join(path, cmd)): return os.path.join(path, cmd) return None diff --git a/wicd/monitor.py b/wicd/monitor.py index 0256932..47fe3b5 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -268,16 +268,16 @@ class ConnectionStatus(object): error_handler=err_handle) self.reconnecting = False - def rescan_networks(self): - """ Calls a wireless scan. """ - try: - if daemon.GetSuspend() or daemon.CheckIfConnecting(): - return True - wireless.Scan() - except dbus.exceptions.DBusException, e: - print 'dbus exception while attempting rescan: %s' % str(e) - finally: - return True + #def rescan_networks(self): + # """ Calls a wireless scan. """ + # try: + # if daemon.GetSuspend() or daemon.CheckIfConnecting(): + # return True + # wireless.Scan() + # except dbus.exceptions.DBusException, e: + # print 'dbus exception while attempting rescan: %s' % str(e) + # finally: + # return True def reply_handle(): """ Just a dummy function needed for asynchronous dbus calls. """ diff --git a/wicd/netentry.py b/wicd/netentry.py index e000e93..4474b99 100644 --- a/wicd/netentry.py +++ b/wicd/netentry.py @@ -19,8 +19,9 @@ import gtk import os import misc -from misc import noneToString, stringToNone, noneToBlankString, to_bool import wpath +from misc import noneToString, stringToNone, noneToBlankString, to_bool +from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel language = misc.get_language_list_gui() @@ -28,78 +29,6 @@ language = misc.get_language_list_gui() daemon = None wired = None wireless = None - -def error(parent, message): - """ Shows an error dialog """ - dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, - gtk.BUTTONS_OK) - dialog.set_markup(message) - dialog.run() - dialog.destroy() - -class SmallLabel(gtk.Label): - def __init__(self, text=''): - gtk.Label.__init__(self, text) - self.set_size_request(50, -1) - -class LeftAlignedLabel(gtk.Label): - def __init__(self, label=None): - gtk.Label.__init__(self, label) - self.set_alignment(0.0, 0.5) - -class LabelEntry(gtk.HBox): - """ A label on the left with a textbox on the right. """ - def __init__(self, text): - gtk.HBox.__init__(self) - self.entry = gtk.Entry() - self.entry.set_size_request(200, -1) - self.label = SmallLabel() - self.label.set_text(text) - self.label.set_size_request(170, -1) - self.pack_start(self.label, fill=False, expand=False) - self.pack_start(self.entry, fill=False, expand=False) - self.label.show() - self.entry.show() - self.entry.connect('focus-out-event', self.hide_characters) - self.entry.connect('focus-in-event', self.show_characters) - self.auto_hide_text = False - self.show() - - def set_text(self, text): - # For compatibility... - self.entry.set_text(text) - - def get_text(self): - return self.entry.get_text() - - def set_auto_hidden(self, value): - self.entry.set_visibility(False) - self.auto_hide_text = value - - def show_characters(self, widget=None, event=None): - # When the box has focus, show the characters - if self.auto_hide_text and widget: - self.entry.set_visibility(True) - - def set_sensitive(self, value): - self.entry.set_sensitive(value) - self.label.set_sensitive(value) - - def hide_characters(self, widget=None, event=None): - # When the box looses focus, hide them - if self.auto_hide_text and widget: - self.entry.set_visibility(False) - - -class GreyLabel(gtk.Label): - """ Creates a grey gtk.Label. """ - def __init__(self): - gtk.Label.__init__(self) - - def set_label(self, text): - self.set_markup("" + text + "") - self.set_alignment(0, 0) - class AdvancedSettingsDialog(gtk.Dialog): def __init__(self): @@ -651,7 +580,6 @@ class WiredNetworkEntry(NetworkEntry): self.chkbox_default_profile.connect("toggled", self.toggle_default_profile) self.combo_profile_names.connect("changed", self.change_profile) - self.script_button.connect("button-press-event", self.edit_scripts) # Toggle the default profile checkbox to the correct state. if to_bool(wired.GetWiredProperty("default")): @@ -701,7 +629,6 @@ class WiredNetworkEntry(NetworkEntry): self.button_delete.set_sensitive(False) self.connect_button.set_sensitive(False) self.advanced_button.set_sensitive(False) - self.script_button.set_sensitive(False) def update_connect_button(self, state, apbssid=None): """ Update the connection/disconnect button for this entry. """ @@ -730,7 +657,6 @@ class WiredNetworkEntry(NetworkEntry): self.button_delete.set_sensitive(True) self.connect_button.set_sensitive(True) self.advanced_button.set_sensitive(True) - self.script_button.set_sensitive(True) def remove_profile(self, widget): """ Remove a profile from the profile list. """ @@ -748,7 +674,6 @@ class WiredNetworkEntry(NetworkEntry): if self.is_full_gui: self.button_delete.set_sensitive(False) self.advanced_button.set_sensitive(False) - self.script_button.set_sensitive(False) self.connect_button.set_sensitive(False) else: self.profile_help.hide() diff --git a/wicd/networking.py b/wicd/networking.py index a0a8d58..dcecce8 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -393,8 +393,9 @@ class ConnectThread(threading.Thread): self.SetStatus('setting_static_ip') print 'Setting static IP : ' + self.network['ip'] iface.SetAddress(self.network['ip'], self.network['netmask']) - print 'Setting default gateway : ' + self.network['gateway'] - iface.SetDefaultRoute(self.network['gateway']) + if self.network.get('gateway'): + print 'Setting default gateway : ' + self.network['gateway'] + iface.SetDefaultRoute(self.network['gateway']) else: # Run dhcp... self.SetStatus('running_dhcp') diff --git a/wicd/prefs.py b/wicd/prefs.py index 29f5c12..b5779fb 100644 --- a/wicd/prefs.py +++ b/wicd/prefs.py @@ -40,14 +40,6 @@ wired = None language = misc.get_language_list_gui() -def alert(parent, message): - """ Shows an alert dialog """ - dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, - gtk.BUTTONS_OK) - dialog.set_markup(message) - dialog.run() - dialog.destroy() - class PreferencesDialog(object): """ Class for handling the wicd preferences dialog window. """ def __init__(self, wTree, dbus): diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index a74429a..b751965 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -43,13 +43,14 @@ import getopt import os import pango import time -from dbus import DBusException +import atexit # Wicd specific imports from wicd import wpath from wicd import misc from wicd import gui from wicd import dbusmanager +from wicd.guiutil import error ICON_AVAIL = True USE_EGG = False @@ -364,7 +365,7 @@ class TrayIcon(object): if DBUS_AVAIL: self.toggle_wicd_gui() else: - # gui.error(None, language["daemon_unavailable"]) + # error(None, language["daemon_unavailable"]) pass def on_quit(self, widget=None): @@ -652,8 +653,8 @@ def setup_dbus(force=True): misc.PromptToStartDaemon() try: dbusmanager.connect_to_dbus() - except DBusException: - gui.error(None, "Could not connect to wicd's D-Bus interface. " + + except dbusmanager.DBusException: + error(None, "Could not connect to wicd's D-Bus interface. " + "Check the wicd log for error messages.") return False else: @@ -669,12 +670,19 @@ def setup_dbus(force=True): return True +def on_exit(): + if DBUS_AVAIL: + try: + daemon.SetGUIOpen(False) + except dbusmanager.DBusException: + pass + 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) + error(None, language['lost_dbus'], block=False) return False def main(argv): @@ -709,7 +717,8 @@ def main(argv): print 'Loading...' setup_dbus() - + atexit.register(on_exit) + if not use_tray or not ICON_AVAIL: the_gui = gui.appGui(standalone=True) mainloop = gobject.MainLoop() diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index b12e0e4..8087c87 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -320,6 +320,10 @@ class WicdDaemon(dbus.service.Object): fails it tries a wireless connection. """ + # We don't want to rescan/connect if the gui is open. + if self.gui_open: + return + if fresh: self.wireless_bus.Scan() if self.wired_bus.CheckPluggedIn(): @@ -401,7 +405,8 @@ class WicdDaemon(dbus.service.Object): def ShouldAutoReconnect(self): """ Returns True if it's the right time to try autoreconnecting. """ if self.GetAutoReconnect() and not self.CheckIfConnecting() and \ - not self.GetForcedDisconnect() and not self.auto_connecting: + not self.GetForcedDisconnect() and not self.auto_connecting and \ + not self.gui_open: return True else: return False diff --git a/wicd/wnettools.py b/wicd/wnettools.py index 1df4398..0cea30e 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -33,6 +33,7 @@ class WirelessInterface() -- Control a wireless network interface. import os import re +import random from string import maketrans, translate, punctuation import wpath @@ -138,8 +139,8 @@ def NeedsExternalCalls(): 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"]) + output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iolan19", + "-c/etc/abcd%sdefzz.zconfz" % random.randint(1, 1000)]) if re.match("Unsupported driver", output): return False else: @@ -195,7 +196,7 @@ class BaseInterface(object): paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/', '/usr/local/sbin/', '/usr/local/bin/'] for path in paths: - if os.access("%s%s" % (path, client), os.F_OK): + if os.path.exists("%s%s" % (path, client)): return "%s%s" % (path, client) if self.verbose: print "WARNING: No path found for %s" % (client) @@ -416,7 +417,7 @@ class BaseInterface(object): pipe -- stdout pipe to the dhcpcd process. Returns: - 'success' if succesful', an error code string otherwise. + 'success' if succesful, an error code string otherwise. """ dhcpcd_complete = False