diff --git a/configscript.py b/configscript.py new file mode 100755 index 0000000..648dbf3 --- /dev/null +++ b/configscript.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python + +"""Configure the scripts for a particular network + +Script for configuring the scripts for a network passed in as a +command line argument. This needs to run a separate process because +editing scripts requires root access, and the GUI/Tray are typically +run as the current user. + +""" + +# +# Copyright (C) 2007 Adam Blackburn +# Copyright (C) 2007 Dan O'Reilly +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License Version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +import os +import sys +import gtk +import ConfigParser +import dbus +import dbus.service +import pygtk +import gtk.glade + +import wpath +import misc + +_ = misc.get_gettext() + +language = {} +language['configure_scripts'] = "Configure Scripts" +language['before_script'] = "Pre-connection Script" +language['after_script'] = "Post-connection Script" +language['disconnect_script'] = "Disconnection Script" + +bus = dbus.SystemBus() + +# Connect to the daemon +try: + print 'Attempting to connect tray to daemon...' + proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') + print 'Success.' +except Exception: + print 'Daemon not running...' + misc.PromptToStartDaemon() + sys.exit(1) + +wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless') +wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired') +config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config') + +wireless_conf = wpath.etc + 'wireless-settings.conf' +wired_conf = wpath.etc + 'wired-settings.conf' + + +def none_to_blank(text): + """if text is None, 'None', or '' then return '', otherwise return str(text)""" + if text == None or text == "None" or text == "": + return "" + else: + return str(text) + +def blank_to_none(text): + """Convert an empty or null string to 'None'""" + if text == "" or text == None: + return "None" + else: + return str(text) + +def get_script_info(network, network_type): + """Reads script info from disk and load it into the configuration dialog""" + info = {} + con = ConfigParser.ConfigParser() + if network_type == "wired": + con.read(wired_conf) + if con.has_section(network): + info["pre_entry"] = con.get(network, "beforescript") + info["post_entry"] = con.get(network, "afterscript") + info["disconnect_entry"] = con.get(network, "disconnectscript") + else: + bssid = wireless.GetWirelessProperty(int(network), "bssid") + con.read(wireless_conf) + if con.has_section(bssid): + info["pre_entry"] = con.get(bssid, "beforescript") + info["post_entry"] = con.get(bssid, "afterscript") + info["disconnect_entry"] = con.get(bssid, "disconnectscript") + + return info + +def write_scripts(network, network_type, script_info): + """Writes script info to disk and loads it into the daemon""" + con = ConfigParser.ConfigParser() + if network_type == "wired": + con.read(wired_conf) + if con.has_section(network): + con.set(network, "beforescript", script_info["pre_entry"]) + con.set(network, "afterscript", script_info["post_entry"]) + con.set(network, "disconnectscript", script_info["disconnect_entry"]) + con.write(open(wired_conf, "w")) + config.ReadWiredNetworkProfile(network) + else: + bssid = wireless.GetWirelessProperty(int(network), "bssid") + con.read(wireless_conf) + if con.has_section(bssid): + con.set(bssid, "beforescript", script_info["pre_entry"]) + con.set(bssid, "afterscript", script_info["post_entry"]) + con.set(bssid, "disconnectscript", script_info["disconnect_entry"]) + con.write(open(wireless_conf, "w")) + config.ReadWirelessNetworkProfile(int(network)) + config.SaveWirelessNetworkProfile(int(network)) + +def main (argv): + """Runs the script configuration dialog.""" + if len(argv) < 2: + print 'Network id to configure is missing, aborting.' + sys.exit(1) + + network = argv[1] + network_type = argv[2] + + script_info = get_script_info(network, network_type) + + gladefile = wpath.etc + "wicd.glade" + wTree = gtk.glade.XML(gladefile) + dialog = wTree.get_widget("configure_script_dialog") + wTree.get_widget("pre_label").set_label(language['before_script'] + ":") + wTree.get_widget("post_label").set_label(language['after_script'] + ":") + wTree.get_widget("disconnect_label").set_label(language['disconnect_script'] + ":") + wTree.get_widget("window1").hide() + + pre_entry = wTree.get_widget("pre_entry") + post_entry = wTree.get_widget("post_entry") + disconnect_entry = wTree.get_widget("disconnect_entry") + + pre_entry.set_text(none_to_blank(script_info["pre_entry"])) + post_entry.set_text(none_to_blank(script_info["post_entry"])) + disconnect_entry.set_text(none_to_blank(script_info["disconnect_entry"])) + + dialog.show_all() + + result = dialog.run() + if result == 1: + script_info["pre_entry"] = blank_to_none(pre_entry.get_text()) + script_info["post_entry"] = blank_to_none(post_entry.get_text()) + script_info["disconnect_entry"] = blank_to_none(disconnect_entry.get_text()) + write_scripts(network, network_type, script_info) + dialog.destroy() + + +if __name__ == '__main__': + main(sys.argv) diff --git a/daemon.py b/daemon.py index a8ce2df2..6b7678a 100644 --- a/daemon.py +++ b/daemon.py @@ -467,30 +467,6 @@ class ConnectionWizard(dbus.service.Object): self.wired.Disconnect() #end function DisconnectWireless - @dbus.service.method('org.wicd.daemon.wireless') - def SetWirelessBeforeScript(self,networkid,script): - if script == '': - script = None - self.SetWirelessProperty(networkid,"beforescript",script) - self.wifi.before_script = script - #end function SetWirelessBeforeScript - - @dbus.service.method('org.wicd.daemon.wireless') - def SetWirelessDisconnectScript(self,networkid,script): - if script == '': - script = None - self.SetWirelessProperty(networkid,"disconnectscript",script) - self.wifi.disconnect_script = script - #end function SetWirelessDisconnectScript - - @dbus.service.method('org.wicd.daemon.wireless') - def SetWirelessAfterScript(self,networkid,script): - if script == '': - script = None - self.SetWirelessProperty(networkid,"afterscript",script) - self.wifi.after_script = script - #end function SetWirelessAfterScript - @dbus.service.method('org.wicd.daemon.wireless') def GetNumberOfNetworks(self): '''returns number of networks''' @@ -528,7 +504,7 @@ class ConnectionWizard(dbus.service.Object): ''' Retrieves wireless property from the network specified ''' value = self.LastScan[networkid].get(property) try: - value = value.encode('utf-8') + value = misc.to_unicode(value) except: pass if self.debug_mode == 1: @@ -542,6 +518,10 @@ class ConnectionWizard(dbus.service.Object): ''' Sets property to value in network specified ''' #simple - set the value of the item in our current data #to the value the client asked for + if (property.strip()).endswith("script"): + print "Setting script properties through the daemon \ + is not permitted." + return False print 'setting wireless network',networkid,'property',property,'to value',value self.LastScan[networkid][property] = misc.Noneify(value) #end function SetProperty @@ -710,33 +690,6 @@ class ConnectionWizard(dbus.service.Object): return False #end function CheckIfWiredConnecting - @dbus.service.method('org.wicd.daemon.wired') - def SetWiredBeforeScript(self,script): - '''sets pre-connection script to run for a wired connection''' - if script == '': - script = None - self.SetWiredProperty("beforescript",script) - self.wired.before_script = script - #end function SetWiredBeforeScript - - @dbus.service.method('org.wicd.daemon.wired') - def SetWiredDisconnectScript(self,script): - '''sets script to run on connection disconnect''' - if script == '': - script = None - self.SetWiredProperty("disconnectscript",script) - self.wired.disconnect_script = script - #end function SetWirelessDisconnectScript - - @dbus.service.method('org.wicd.daemon.wired') - def SetWiredAfterScript(self,script): - '''sets post-connection script to run for a wired connection''' - if script == '': - script = None - self.SetWiredProperty("afterscript",script) - self.wired.after_script = script - #end function SetWiredAfterScript - @dbus.service.method('org.wicd.daemon.wired') def SetWiredAutoConnectMethod(self,method): '''sets which method the user wants to autoconnect to wired networks''' @@ -769,6 +722,10 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def SetWiredProperty(self,property,value): if self.WiredNetwork: + if (property.strip()).endswith("script"): + print "Setting script properties through the daemon \ + is not permitted." + return False self.WiredNetwork[property] = misc.Noneify(value) if self.debug_mode == 1: print 'set',property,'to',misc.Noneify(value) @@ -938,7 +895,7 @@ class ConnectionWizard(dbus.service.Object): def SaveWiredNetworkProfile(self,profilename): ''' Writes a wired network profile to disk ''' #should include: profilename,ip,netmask,gateway,dns1,dns2 - profilename = profilename.encode('utf-8') + profilename = misc.to_unicode(profilename) print "setting profile for " + str(profilename) config = ConfigParser.ConfigParser() config.read(self.wired_conf) @@ -955,7 +912,7 @@ class ConnectionWizard(dbus.service.Object): def ReadWiredNetworkProfile(self,profilename): ''' Reads a wired network profile in as the currently active profile ''' profile = {} - profilename = profilename.encode('utf-8') + profilename = misc.to_unicode(profilename) config = ConfigParser.ConfigParser() config.read(self.wired_conf) if config.has_section(profilename) == True: @@ -999,6 +956,9 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def SaveWirelessNetworkProperty(self,id,option): ''' Writes a particular wireless property to disk ''' + if (option.strip()).endswith("script"): + print 'you cannot save script information to disk through the daemon.' + return print "setting network option " + str(option) + " to " + str(self.LastScan[id][option]) config = ConfigParser.ConfigParser() config.read(self.wireless_conf) @@ -1015,27 +975,13 @@ class ConnectionWizard(dbus.service.Object): print self.LastScan[id]["bssid"] if config.has_section(self.LastScan[id]["bssid"]): self.LastScan[id]["has_profile"] = True - if config.has_option(self.LastScan[id]["bssid"], "beforescript"): - self.LastScan[id]["beforescript"] = misc.Noneify(config.get(self.LastScan[id]["bssid"], "beforescript")) - else: - self.LastScan[id]["beforescript"] = None - if config.has_option(self.LastScan[id]["bssid"], "afterscript"): - self.LastScan[id]["afterscript"] = misc.Noneify(config.get(self.LastScan[id]["bssid"], - "afterscript")) - else: - self.LastScan[id]["afterscript"] = None - if config.has_option(self.LastScan[id]["bssid"], "disconnectscript"): - self.LastScan[id]["disconnectscript"] = misc.Noneify(config.get(self.LastScan[id]["bssid"], - "disconnectscript")) - else: - self.LastScan[id]["disconnectscript"] = None - #read the essid because we be needing to name those hidden - #wireless networks now - but only read it if it is hidden + # Read the essid because we be needing to name those hidden + # wireless networks now - but only read it if it is hidden. if self.LastScan[id]["hidden"] == True: self.LastScan[id]["essid"] = misc.Noneify(config.get(self.LastScan[id]["bssid"], "essid")) for x in config.options(self.LastScan[id]["bssid"]): - if self.LastScan[id].has_key(x) == False: + if self.LastScan[id].has_key(x) == False or x.endswith("script"): self.LastScan[id][x] = misc.Noneify(config.get(self.LastScan[id]["bssid"], x)) return "100: Loaded Profile" else: @@ -1266,112 +1212,6 @@ class ConnectionWizard(dbus.service.Object): #end function ReadConfig -def usage(): - print """ -wicd 1.33 -wireless (and wired) connection daemon. - -Arguments: -\t-s\t--no-scan\tDon't auto-scan/auto-connect. -\t-f\t--no-daemon\tDon't daemonize (run in foreground). -\t-e\t--no-stderr\tDon't redirect stderr. -\t-o\t--no-stdout\tDon't redirect stdout. -\t-h\t--help\t\tPrint this help. -""" - - -def daemonize(): - """ Disconnect from the controlling terminal. - - Fork twice, once to disconnect ourselves from the parent terminal and a - second time to prevent any files we open from becoming our controlling - terminal. - - For more info see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 - - """ - # Fork the first time to disconnect from the parent terminal and - # exit the parent process. - try: - pid = os.fork() - if pid > 0: - sys.exit(0) - except OSError, e: - print >> sys.stderr, "Fork #1 failed: %d (%s)" % (e.errno, e.strerror) - sys.exit(1) - - # Decouple from parent environment to stop us from being a zombie. - os.setsid() - os.umask(0) - - # Fork the second time to prevent us from opening a file that will - # become our controlling terminal. - try: - pid = os.fork() - if pid > 0: - print "wicd daemon: pid " + str(pid) - sys.exit(0) - except OSError, e: - print >> sys.stderr, "Fork #2 failed: %d (%s)" % (e.errno, e.strerror) - sys.exit(1) - - -def main(argv): - """ The main daemon program. - - Keyword arguments: - argv -- The arguments passed to the script. - - """ - - do_daemonize = True - redirect_stderr = True - redirect_stdout = True - auto_scan = True - - try: - opts, args = getopt.getopt(sys.argv[1:], 'feos', - ['help', 'no-daemon', 'no-stderr', 'no-stdout', 'no-scan']) - except getopt.GetoptError: - # Print help information and exit - usage() - sys.exit(2) - - for o, a in opts: - if o in ('-h', '--help'): - usage() - sys.exit() - if o in ('-e', '--no-stderr'): - redirect_stderr = False - if o in ('-o', '--no-stdout'): - redirect_stdout = False - if o in ('-f', '--no-daemon'): - do_daemonize = False - if o in ('-s', '--no-scan'): - auto_scan = False - - if do_daemonize: daemonize() - - if redirect_stderr or redirect_stdout: output = LogWriter() - if redirect_stdout: sys.stdout = output - if redirect_stderr: sys.stderr = output - - print '---------------------------' - print 'wicd initializing...' - print '---------------------------' - - # Open the DBUS session - session_bus = dbus.SystemBus() - bus_name = dbus.service.BusName('org.wicd.daemon', bus=session_bus) - object = ConnectionWizard(bus_name, auto_connect=auto_scan) - connection_status = ConnectionStatus(object) - - gobject.timeout_add(3000, connection_status.update_connection_status) - - # Enter the main loop - mainloop = gobject.MainLoop() - mainloop.run() - class ConnectionStatus(): def __init__(self, connection): """Initialize variables needed for the connection status methods.""" @@ -1513,7 +1353,113 @@ class ConnectionStatus(): conn.AutoConnect(True) else: conn.AutoConnect(True) + +def usage(): + print """ +wicd 1.33 +wireless (and wired) connection daemon. + +Arguments: +\t-s\t--no-scan\tDon't auto-scan/auto-connect. +\t-f\t--no-daemon\tDon't daemonize (run in foreground). +\t-e\t--no-stderr\tDon't redirect stderr. +\t-o\t--no-stdout\tDon't redirect stdout. +\t-h\t--help\t\tPrint this help. +""" + + +def daemonize(): + """ Disconnect from the controlling terminal. + + Fork twice, once to disconnect ourselves from the parent terminal and a + second time to prevent any files we open from becoming our controlling + terminal. + + For more info see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 + + """ + # Fork the first time to disconnect from the parent terminal and + # exit the parent process. + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + print >> sys.stderr, "Fork #1 failed: %d (%s)" % (e.errno, e.strerror) + sys.exit(1) + + # Decouple from parent environment to stop us from being a zombie. + os.setsid() + os.umask(0) + + # Fork the second time to prevent us from opening a file that will + # become our controlling terminal. + try: + pid = os.fork() + if pid > 0: + print "wicd daemon: pid " + str(pid) + sys.exit(0) + except OSError, e: + print >> sys.stderr, "Fork #2 failed: %d (%s)" % (e.errno, e.strerror) + sys.exit(1) + + +def main(argv): + """ The main daemon program. + + Keyword arguments: + argv -- The arguments passed to the script. + + """ + + do_daemonize = True + redirect_stderr = True + redirect_stdout = True + auto_scan = True + + try: + opts, args = getopt.getopt(sys.argv[1:], 'feos', + ['help', 'no-daemon', 'no-stderr', 'no-stdout', 'no-scan']) + except getopt.GetoptError: + # Print help information and exit + usage() + sys.exit(2) + + for o, a in opts: + if o in ('-h', '--help'): + usage() + sys.exit() + if o in ('-e', '--no-stderr'): + redirect_stderr = False + if o in ('-o', '--no-stdout'): + redirect_stdout = False + if o in ('-f', '--no-daemon'): + do_daemonize = False + if o in ('-s', '--no-scan'): + auto_scan = False + + if do_daemonize: daemonize() + + if redirect_stderr or redirect_stdout: output = LogWriter() + if redirect_stdout: sys.stdout = output + if redirect_stderr: sys.stderr = output + + print '---------------------------' + print 'wicd initializing...' + print '---------------------------' + + # Open the DBUS session + session_bus = dbus.SystemBus() + bus_name = dbus.service.BusName('org.wicd.daemon', bus=session_bus) + object = ConnectionWizard(bus_name, auto_connect=auto_scan) + connection_status = ConnectionStatus(object) + + gobject.timeout_add(3000, connection_status.update_connection_status) + + # Enter the main loop + mainloop = gobject.MainLoop() + mainloop.run() if __name__ == '__main__': main(sys.argv) diff --git a/gui.py b/gui.py index 78db261..7199a9f 100644 --- a/gui.py +++ b/gui.py @@ -117,11 +117,9 @@ language['use_static_dns'] = _('Use Static DNS') language['use_encryption'] = _('Use Encryption') language['advanced_settings'] = _('Advanced Settings') language['wired_network'] = _('Wired Network') -language['wired_network_instructions'] = _('To connect to a wired network, you \ - must create a network profile. To \ - create a network profile, type a \ - name that describes this network, \ - and press Add.') +language['wired_network_instructions'] = _('To connect to a wired network, you' +' must create a network profile. To create a network profile, type a name that' +' describes this network, and press Add.') language['automatic_connect'] = _('Automatically connect to this network') language['secured'] = _('Secured') language['unsecured'] = _('Unsecured') @@ -166,6 +164,7 @@ language['choose_wired_profile'] = _('Select or create a wired profile to connec language['wired_network_found'] = _('Wired connection detected') language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporarily') language['display_type_dialog'] = _('Use dBm to measure signal strength') +language['scripts'] = _('Scripts') language['0'] = _('0') language['1'] = _('1') @@ -200,11 +199,11 @@ language['done'] = _('Done connecting...') class LinkButton(gtk.EventBox): label = None - def __init__(self): + def __init__(self, txt): gtk.EventBox.__init__(self) self.connect("realize",self.__setHandCursor) #set the hand cursor when the box is initalized label = gtk.Label() - label.set_markup(" " + language['connect'] + "") + label.set_markup("[ " + txt + " ]") label.set_alignment(0,.5) label.show() self.add(label) @@ -324,12 +323,13 @@ class PrettyNetworkEntry(gtk.HBox): self.expander.higherLevel = self # Do this so that the expander can access the stuff inside me self.tempVBox = gtk.VBox(False,1) self.tempVBox.show() - self.connectButton = LinkButton() + self.connectButton = LinkButton(language["connect"]) self.connectButton.show() self.tempVBox.pack_start(self.expander,fill=False,expand=False) self.tempVBox.pack_start(self.connectButton,fill=False,expand=False) self.pack_end(self.tempVBox) + class PrettyWiredNetworkEntry(PrettyNetworkEntry): def __init__(self): PrettyNetworkEntry.__init__(self,WiredNetworkEntry()) @@ -424,24 +424,13 @@ class NetworkEntry(gtk.Expander): self.txtDNS1 = LabelEntry(language['dns'] + ' ' + language['1']) self.txtDNS2 = LabelEntry(language['dns'] + ' ' + language['2']) self.txtDNS3 = LabelEntry(language['dns'] + ' ' + language['3']) - #dns_addresses = daemon.GetGlobalDNSAddresses() - #self.txtDNS1.set_text(dns_addresses[0]) - #self.txtDNS2.set_text(dns_addresses[1]) - #self.txtDNS3.set_text(dns_addresses[2]) - self.txtBeforeScript = LabelEntry(language['before_script']) - self.txtAfterScript = LabelEntry(language['after_script']) - self.txtDisconnectScript = LabelEntry(language['disconnect_script']) - self.txtBeforeScript.label.set_size_request(200,-1) - self.txtAfterScript.label.set_size_request(200,-1) - self.txtDisconnectScript.label.set_size_request(200,-1) + self.scriptButton = LinkButton(language['scripts']) self.checkboxStaticIP = gtk.CheckButton(language['use_static_ip']) self.checkboxStaticDNS = gtk.CheckButton(language['use_static_dns']) self.checkboxGlobalDNS = gtk.CheckButton(language['use_global_dns']) self.expanderAdvanced = gtk.Expander(language['advanced_settings']) - self.expanderScripts = gtk.Expander(language['script_settings']) self.vboxTop = gtk.VBox(False,0) self.vboxAdvanced = gtk.VBox(False,0) - self.vboxScripts = gtk.VBox(False,0) self.hboxDNS = gtk.HBox(False,0) self.hboxDNS.pack_start(self.checkboxStaticDNS) self.hboxDNS.pack_start(self.checkboxGlobalDNS) @@ -453,13 +442,8 @@ class NetworkEntry(gtk.Expander): self.vboxAdvanced.pack_start(self.txtDNS1,fill=False,expand=False) self.vboxAdvanced.pack_start(self.txtDNS2,fill=False,expand=False) self.vboxAdvanced.pack_start(self.txtDNS3,fill=False,expand=False) - self.vboxScripts.pack_start(self.txtBeforeScript,fill=False,expand=False) - self.vboxScripts.pack_start(self.txtAfterScript,fill=False,expand=False) - self.vboxScripts.pack_start(self.txtDisconnectScript,fill=False,expand=False) - self.vboxTop.pack_end(self.expanderScripts,fill=False,expand=False) - self.vboxTop.pack_end(self.expanderAdvanced,fill=False,expand=False) + self.vboxTop.pack_start(self.expanderAdvanced, fill=False, expand=False) self.expanderAdvanced.add(self.vboxAdvanced) - self.expanderScripts.add(self.vboxScripts) # Connect the events to the actions self.checkboxStaticIP.connect("toggled",self.toggleIPCheckbox) self.checkboxStaticDNS.connect("toggled",self.toggleDNSCheckbox) @@ -567,22 +551,22 @@ class WiredNetworkEntry(NetworkEntry): self.profileHelp = gtk.Label(language['wired_network_instructions']) self.checkboxDefaultProfile = gtk.CheckButton(language['default_wired']) - self.profileHelp.set_width_chars(5) #the default is a tad too long - self.profileHelp.set_padding(10,10) self.profileHelp.set_justify(gtk.JUSTIFY_LEFT) self.profileHelp.set_line_wrap(True) - self.vboxTop.pack_start(self.profileHelp,fill=False,expand=False) + self.vboxTop.pack_start(self.profileHelp,fill=True,expand=True) self.hboxTemp.pack_start(self.comboProfileNames,fill=True,expand=True) self.hboxTemp.pack_start(self.buttonAdd,fill=False,expand=False) self.hboxTemp.pack_start(self.buttonDelete,fill=False,expand=False) hboxDef.pack_start(self.checkboxDefaultProfile,fill=False,expand=False) - self.buttonAdd.connect("clicked",self.addProfile) #hook up our buttons + self.buttonAdd.connect("clicked",self.addProfile) self.buttonDelete.connect("clicked",self.removeProfile) self.comboProfileNames.connect("changed",self.changeProfile) + self.scriptButton.connect("button-press-event", self.editScripts) self.vboxTop.pack_start(self.hboxTemp) self.vboxTop.pack_start(hboxDef) + self.vboxTop.pack_start(self.scriptButton) if stringToBoolean(wired.GetWiredProperty("default")) == True: self.checkboxDefaultProfile.set_active(True) @@ -594,7 +578,7 @@ class WiredNetworkEntry(NetworkEntry): self.profileHelp.hide() if self.profileList != None: prof = config.GetDefaultWiredNetwork() - if prof != None: #make sure the default profile gets displayed + if prof != None: # Make sure the default profile gets displayed. i=0 while self.comboProfileNames.get_active_text() != prof: self.comboProfileNames.set_active(i) @@ -609,6 +593,11 @@ class WiredNetworkEntry(NetworkEntry): self.set_expanded(True) self.profileHelp.show() + def editScripts(self, widget=None, event=None): + profile = self.comboProfileNames.get_active_text() + os.spawnlpe(os.P_WAIT, "gksudo", "gksudo", "./configscript.py", + profile, "wired", os.environ) + def checkEnable(self): profileList = config.GetWiredProfileList() if profileList == None: @@ -674,10 +663,6 @@ class WiredNetworkEntry(NetworkEntry): self.txtDNS2.set_text(noneToBlankString(wired.GetWiredProperty("dns2"))) self.txtDNS3.set_text(noneToBlankString(wired.GetWiredProperty("dns3"))) - self.txtBeforeScript.set_text(noneToBlankString(wired.GetWiredProperty("beforescript"))) - self.txtAfterScript.set_text(noneToBlankString(wired.GetWiredProperty("afterscript"))) - self.txtDisconnectScript.set_text(noneToBlankString(wired.GetWiredProperty("disconnectscript"))) - self.checkboxDefaultProfile.set_active(stringToBoolean(wired.GetWiredProperty("default"))) self.resetStaticCheckboxes() @@ -715,6 +700,7 @@ class WirelessNetworkEntry(NetworkEntry): self.vboxTop.pack_start(self.checkboxAutoConnect,fill=False,expand=False) self.vboxTop.pack_start(self.hboxStatus,fill=True,expand=False) + self.vboxTop.pack_start(self.scriptButton) self.vboxAdvanced.pack_start(self.checkboxEncryption,fill=False,expand=False) @@ -734,10 +720,6 @@ class WirelessNetworkEntry(NetworkEntry): if wireless.GetWirelessProperty(networkID,'dns3') != None: self.txtDNS3.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"dns3"))) - self.txtBeforeScript.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"beforescript"))) - self.txtAfterScript.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"afterscript"))) - self.txtDisconnectScript.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"disconnectscript"))) - self.resetStaticCheckboxes() encryptionTypes = misc.LoadEncryptionMethods() @@ -769,10 +751,16 @@ class WirelessNetworkEntry(NetworkEntry): self.vboxAdvanced.pack_start(self.comboEncryption) self.vboxAdvanced.pack_start(self.vboxEncryptionInformation) self.changeEncryptionMethod() + self.scriptButton.connect("button-press-event", self.editScripts) self.checkboxEncryption.connect("toggled",self.toggleEncryption) self.comboEncryption.connect("changed",self.changeEncryptionMethod) self.show_all() + def editScripts(self, widget=None, event=None): + result = os.spawnlpe(os.P_WAIT, "gksudo", "gksudo", "./configscript.py", + str(self.networkID), "wireless", os.environ) + print result + def updateAutoConnect(self,widget): wireless.SetWirelessProperty(self.networkID,"automatic", self.checkboxAutoConnect.get_active()) @@ -1298,14 +1286,6 @@ class appGui: print "no encryption specified..." wireless.SetWirelessProperty(networkid,"enctype",noneToString(None)) - # Script info - before_script = networkentry.expander.txtBeforeScript.get_text() - after_script = networkentry.expander.txtAfterScript.get_text() - disconnect_script = networkentry.expander.txtDisconnectScript.get_text() - wireless.SetWirelessBeforeScript(networkid,before_script) - wireless.SetWirelessAfterScript(networkid,after_script) - wireless.SetWirelessDisconnectScript(networkid,disconnect_script) - # if it exists. maybe kept as a value in the network entry? Not sure... print "connecting to wireless network..." config.SaveWirelessNetworkProfile(networkid) @@ -1333,14 +1313,6 @@ class appGui: wired.SetWiredProperty("dns2",'') wired.SetWiredProperty("dns3",'') - # Script Info - before_script = networkentry.expander.txtBeforeScript.get_text() - after_script = networkentry.expander.txtAfterScript.get_text() - disconnect_script = networkentry.expander.txtDisconnectScript.get_text() - wired.SetWiredBeforeScript(before_script) - wired.SetWiredAfterScript(after_script) - wired.SetWiredDisconnectScript(disconnect_script) - config.SaveWiredNetworkProfile(networkentry.expander.comboProfileNames.get_active_text()) wired.ConnectWired() @@ -1354,7 +1326,7 @@ class appGui: return True def show_win(self): - self.window.show_all() + self.window.show() # hide the status bar, as it might be confusing if it # pops up randomly :) self.status_area.hide_all() diff --git a/misc.py b/misc.py index d3f5e91..c8f014c 100644 --- a/misc.py +++ b/misc.py @@ -217,6 +217,7 @@ def get_gettext(): def to_unicode(x): + """ Attempts to convert a string to unicode """ try: # This may never fail, but let's be safe default_encoding = locale.getpreferredencoding() except: diff --git a/run-script.py b/run-script.py deleted file mode 100755 index 8c69cab..0000000 --- a/run-script.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/python -## -#Simple script that converts command line args to a string and executes it in usermode -## -import os,sys,misc - -print 'executing script in user mode' -os.setuid(1000) -command = '' -for stuff in sys.argv[1:]: - command = command + ' ' + stuff -print 'command = ',command -pid = os.fork() -print 'hey' -if not pid: - misc.Run(command) diff --git a/wnettools.py b/wnettools.py index acd3f88..0337063 100644 --- a/wnettools.py +++ b/wnettools.py @@ -36,23 +36,23 @@ import wpath # Compile the regex patterns that will be used to search the output of iwlist # scan for info these are well tested, should work on most cards -essid_pattern = re.compile('.*ESSID:"(.*?)"\n', re.DOTALL | re.I | re.M | re.S) -ap_mac_pattern = re.compile('.*Address: (.*?)\n',re.DOTALL | re.I | re.M | re.S) -channel_pattern = re.compile('.*Channel:? ?(\d\d?)',re.DOTALL | re.I | re.M | re.S) -strength_pattern = re.compile('.*Quality:?=? ?(\d+)\s*/?\s*(\d*)',re.DOTALL | re.I | re.M | re.S) +essid_pattern = re.compile('.*ESSID:"(.*?)"\n', re.I | re.M | re.S) +ap_mac_pattern = re.compile('.*Address: (.*?)\n', re.I | re.M | re.S) +channel_pattern = re.compile('.*Channel:? ?(\d\d?)', re.I | re.M | re.S) +strength_pattern = re.compile('.*Quality:?=? ?(\d+)\s*/?\s*(\d*)', re.I | re.M | re.S) # These next two look a lot a like, altstrength is for Signal level = xx/100, # which is just an alternate way of displaying link quality, signaldbm is # for displaying actual signal strength (-xx dBm). -altstrength_pattern = re.compile('.*Signal level:?=? ?(\d\d*)',re.DOTALL | re.I | re.M | re.S) -signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)',re.DOTALL | re.I | re.M | re.S) -mode_pattern = re.compile('.*Mode:(.*?)\n',re.DOTALL | re.I | re.M | re.S) -freq_pattern = re.compile('.*Frequency:(.*?)\n',re.DOTALL | re.I | re.M | re.S) +altstrength_pattern = re.compile('.*Signal level:?=? ?(\d\d*)', re.I | re.M | re.S) +signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)', re.I | re.M | re.S) +mode_pattern = re.compile('.*Mode:(.*?)\n', re.I | re.M | re.S) +freq_pattern = re.compile('.*Frequency:(.*?)\n', re.I | re.M | re.S) ip_pattern = re.compile(r'inet [Aa]d?dr[^.]*:([^.]*\.[^.]*\.[^.]*\.[0-9]*)',re.S) -wep_pattern = re.compile('.*Encryption key:(.*?)\n',re.DOTALL | re.I | re.M | re.S) -altwpa_pattern = re.compile('(wpa_ie)',re.DOTALL | re.I | re.M | re.S) -wpa1_pattern = re.compile('(WPA Version 1)',re.DOTALL | re.I | re.M | re.S) -wpa2_pattern = re.compile('(WPA2)',re.DOTALL | re.I | re.M | re.S) +wep_pattern = re.compile('.*Encryption key:(.*?)\n', re.I | re.M | re.S) +altwpa_pattern = re.compile('(wpa_ie)', re.I | re.M | re.S) +wpa1_pattern = re.compile('(WPA Version 1)', re.I | re.M | re.S) +wpa2_pattern = re.compile('(WPA2)', re.I | re.M | re.S) def SetDNS(dns1=None, dns2=None, dns3=None): @@ -261,7 +261,7 @@ class WirelessInterface(Interface): # Split the networks apart, using Cell as our split point # this way we can look at only one network at a time. - # the spaces around ' Cell ' are to minimize the chance that someone + # The spaces around ' Cell ' are to minimize the chance that someone # has an essid named Cell... networks = results.split( ' Cell ' )