From 2d38b8f0d40b69e9da28ba4ed3e6ef22d84918da Mon Sep 17 00:00:00 2001 From: imdano <> Date: Mon, 23 Jul 2007 07:05:05 +0000 Subject: [PATCH] Added wired auto-connect profile chooser, fixed some bugs in the ralink legacy connection code, reorganized edgy.py and fixed some bugs in it, probably a few other things too --- daemon.py | 219 ++++++++++++++++++++++++++++++++------------------ edgy.py | 61 +++++++++----- gui.py | 167 +++++++++++++++++++++++++++----------- networking.py | 40 +++++++-- 4 files changed, 333 insertions(+), 154 deletions(-) diff --git a/daemon.py b/daemon.py index 34aaea0..329c6c4 100644 --- a/daemon.py +++ b/daemon.py @@ -111,6 +111,7 @@ class ConnectionWizard(dbus.service.Object): self.wifi = networking.Wireless() self.wired = networking.Wired() self.forced_disconnect = False + self.need_profile_chooser = False #load the config file - it should have most of the stuff we need to run... self.ReadConfig() @@ -119,7 +120,7 @@ class ConnectionWizard(dbus.service.Object): #this will speed up the scanning process - if a client doesn't need a fresh scan, just #feed them the old one. a fresh scan can be done by calling FreshScan(self,interface) - self.LastScan = None + self.LastScan = '' #make a variable that will hold the wired network profile self.WiredNetwork = {} @@ -184,7 +185,7 @@ class ConnectionWizard(dbus.service.Object): configfile = open(self.app_conf,"w") config.write(configfile) #end function SetWirelessInterface - + @dbus.service.method('org.wicd.daemon') def SetWPADriver(self,driver): '''sets the wpa driver the wpa_supplicant will use''' @@ -269,12 +270,73 @@ class ConnectionWizard(dbus.service.Object): configfile = open(self.app_conf,"w") config.write(configfile) self.debug_mode = debug + #end function SetDebugMode @dbus.service.method('org.wicd.daemon') def GetDebugMode(self): '''returns whether debugging is enabled''' return bool(int(self.debug_mode)) + #end function GetDebugMode + @dbus.service.method('org.wicd.daemon') + def AutoConnect(self,fresh): + '''first tries to autoconnect to a wired network, if that fails it tries a wireless connection''' + if self.CheckPluggedIn() == True: + if self.GetWiredAutoConnectMethod() == False: + self.SetNeedWiredProfileChooser(True) + print 'alerting tray to display wired autoconnect wizard' + else: + defaultNetwork = self.GetDefaultWiredNetwork() + if defaultNetwork != None: + self.ReadWiredNetworkProfile(defaultNetwork) + self.ConnectWired() + time.sleep(1) + print "Attempting to autoconnect with wired interface..." + while self.CheckIfWiredConnecting(): # Keeps us from going into an infinite connecting loop + time.sleep(1) + print "...done autoconnecting." + else: + print "couldn't find a default wired connection, wired autoconnect failed" + else: + print "no wired connection present, wired autoconnect failed" + print 'attempting to autoconnect to wireless network' + if fresh: + self.Scan() + if self.GetWirelessInterface() != None: + for x in self.LastScan: + if bool(self.LastScan[x]["has_profile"]): + print str(self.LastScan[x]["essid"]) + ' has profile' + if bool(self.LastScan[x].get('automatic')): + print 'automatically connecting to...',str(self.LastScan[x]["essid"]) + self.ConnectWireless(x) + time.sleep(3) + while self.CheckIfWirelessConnecting(): + print "autoconnecting... hold" + #not sure why I need to get IPs, but + #it solves the autoconnect problem + #i think it has something to do with + #making IO calls while threads are working...? + #if anyone knows why...email me at compwiz18@gmail.com + #only some people need these statements for autoconnect + #to function properly + self.GetWirelessIP() + ### + # removed line below for 1.3.0 - if there is trouble with + # connecting at boot, + # add back to file -- adam + ### + # as far as I can tell, it seems fine - what does everyone else + # think? -- adam + ### + #self.GetWiredIP() + time.sleep(2) + print "autoconnecting... done" + return + print "unable to autoconnect, you'll have to manually connect" + else: + print 'autoconnect failed because wireless interface == None' + #end function AutoConnect + @dbus.service.method('org.wicd.daemon') def GetGlobalDNSAddresses(self): '''returns the global dns addresses''' @@ -282,6 +344,25 @@ class ConnectionWizard(dbus.service.Object): return (self.dns1,self.dns2,self.dns3) #end function GetWirelessInterface + @dbus.service.method('org.wicd.daemon') + def CheckIfConnecting(self): + '''returns if a network connection is being made''' + if self.CheckIfWiredConnecting() == False and self.CheckIfWirelessConnecting() == False: + return False + else: + return True + #end function CheckIfConnecting + + @dbus.service.method('org.wicd.daemon') + def SetNeedWiredProfileChooser(self,val): + self.need_profile_chooser = val + #end function SetNeedWiredProfileChooser + + @dbus.service.method('org.wicd.daemon') + def GetNeedWiredProfileChooser(self): + return self.need_profile_chooser + #end function GetNeedWiredProfileChooser + ########## WIRELESS FUNCTIONS ################################# @@ -313,12 +394,18 @@ class ConnectionWizard(dbus.service.Object): #end function DisconnectWireless @dbus.service.method('org.wicd.daemon.wireless') - def SetWirelessBeforeScript(self,script): + 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 SetWirelessAfterScript(self,script): + def SetWirelessAfterScript(self,networkid,script): + if script == '': + script = None + self.SetWirelessProperty(networkid,"afterscript",script) self.wifi.after_script = script #end function SetWirelessAfterScript @@ -341,7 +428,7 @@ class ConnectionWizard(dbus.service.Object): '''returns if wicd should automatically try to reconnect is connection is lost''' do = bool(int(self.auto_reconnect)) return self.__printReturn('returning automatically reconnect when connection drops',do) - #end function GetAutoReconnect + #end function GetAutoReconnect @dbus.service.method('org.wicd.daemon.wireless') def SetAutoReconnect(self,value): @@ -354,61 +441,6 @@ class ConnectionWizard(dbus.service.Object): self.auto_reconnect = value #end function SetAutoReconnect - @dbus.service.method('org.wicd.daemon.wireless') - def AutoConnect(self,fresh): - '''first tries to autoconnect to a wireled network, if that fails it tries a wireless connection''' - if fresh and self.CheckPluggedIn() == True: - defaultNetwork = self.GetDefaultWiredNetwork() - if defaultNetwork != None: - self.ReadWiredNetworkProfile(defaultNetwork) - self.ConnectWired() - time.sleep(1) - print "Attempting to autoconnect with wired interface..." - while self.CheckIfWiredConnecting(): # Keeps us from going into an infinite connecting loop - time.sleep(1) - print "...done autoconnecting." - else: - print "couldn't find a default wired connection, wired autoconnect failed" - else: - print "no wired connection present, wired autoconnect failed" - print 'attempting to autoconnect to wireless network' - if fresh: - self.Scan() - if self.GetWirelessInterface() != None: - for x in self.LastScan: - if bool(self.LastScan[x]["has_profile"]): - print str(self.LastScan[x]["essid"]) + ' has profile' - if bool(self.LastScan[x].get('automatic')): - print 'automatically connecting to...',str(self.LastScan[x]["essid"]) - self.ConnectWireless(x) - time.sleep(3) - while self.CheckIfWirelessConnecting(): - print "autoconnecting... hold" - #not sure why I need to get IPs, but - #it solves the autoconnect problem - #i think it has something to do with - #making IO calls while threads are working...? - #if anyone knows why...email me at compwiz18@gmail.com - #only some people need these statements for autoconnect - #to function properly - self.GetWirelessIP() - ### - # removed line below for 1.3.0 - if there is trouble with - # connecting at boot, - # add back to file -- adam - ### - # as far as I can tell, it seems fine - what does everyone else - # think? -- adam - ### - #self.GetWiredIP() - time.sleep(2) - print "autoconnecting... done" - return - print "unable to autoconnect, you'll have to manually connect" - else: - print 'autoconnect failed because wireless interface == None' - #end function AutoConnect - @dbus.service.method('org.wicd.daemon.wireless') def GetWirelessProperty(self,networkid,property): '''retrieves wireless property from the network specified''' @@ -558,15 +590,36 @@ class ConnectionWizard(dbus.service.Object): @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 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''' + print 'method = ',method + config = ConfigParser.ConfigParser() + config.read(self.app_conf) + config.set("Settings","use_default_profile",int(method)) + config.write(open(self.app_conf,"w")) + self.use_default_profile = method + + def GetWiredAutoConnectMethod(self): + '''returns the wired autoconnect method''' + return bool(int(self.use_default_profile)) + #end function GetWiredAutoConnectMethod + @dbus.service.method('org.wicd.daemon.wired') def CheckWiredConnectingMessage(self): '''returns the wired interface\'s status message''' @@ -856,13 +909,18 @@ class ConnectionWizard(dbus.service.Object): if config.has_option("Settings","auto_reconnect"): self.auto_reconnect = config.get("Settings","auto_reconnect") else: - config.set("Settings","auto_reconnect","False") + config.set("Settings","auto_reconnect","0") self.auto_reconnect = False if config.has_option("Settings","debug_mode"): self.debug_mode = config.get("Settings","debug_mode") else: - self.debug_mode = False - config.set("Settings","debug_mode","False") + self.debug_mode = 0 + config.set("Settings","debug_mode","0") + if config.has_option("Settings","use_default_profile"): + self.SetWiredAutoConnectMethod(config.get("Settings","use_default_profile")) + else: + config.set("Settings","use_default_profile","1") + self.SetWiredAutoConnectMethod(config.get("Settings","use_default_profile")) else: print "configuration file exists, no settings found, adding defaults..." configfile = open(self.app_conf,"w") @@ -870,20 +928,22 @@ class ConnectionWizard(dbus.service.Object): config.set("Settings","wireless_interface","wlan0") config.set("Settings","wired_interface","eth0") config.set("Settings","wpa_driver","wext") - config.set("Settings","always_show_wired_interface","False") - config.set("Settings","auto_reconnect","False") - config.set("Settings","debug_mode","False") + config.set("Settings","always_show_wired_interface","0") + config.set("Settings","auto_reconnect","0") + config.set("Settings","debug_mode","0") + config.set("Settings","use_default_profile","1") config.set("Settings","use_global_dns","False") config.set("Settings","dns1","None") config.set("Settings","dns2","None") config.set("Settings","dns3","None") self.SetGlobalDNS(config.get('Settings','dns1'),config.get('Settings','dns2'),config.get('Settings','dns3')) - self.SetWirelessInterface(config.get("Settings","wireless_interface")) - self.SetWiredInterface(config.get("Settings","wired_interface")) - self.SetWPADriver(config.get("Settings","wpa_driver")) - self.SetAlwaysShowWiredInterface(False) - self.SetAutoReconnect(True) - self.SetDebugMode(False) + self.SetWirelessInterface("wlan0") + self.SetWiredInterface("eth0") + self.SetWPADriver("wext") + self.SetAlwaysShowWiredInterface(0) + self.SetAutoReconnect(1) + self.SetDebugMode(0) + self.SetWiredAutoConnectMethod(1) config.write(configfile) else: @@ -894,9 +954,10 @@ class ConnectionWizard(dbus.service.Object): config.add_section("Settings") config.set("Settings","wireless_interface","wlan0") config.set("Settings","wired_interface","eth0") - config.set("Settings","always_show_wired_interface","False") - config.set("Settings","auto_reconnect","False") - config.set("Settings","debug_mode","False") + config.set("Settings","always_show_wired_interface","0") + config.set("Settings","auto_reconnect","0") + config.set("Settings","debug_mode","0") + config.set("Settings","use_default_profile","1") config.set("Settings","dns1","None") config.set("Settings","dns2","None") config.set("Settings","dns3","None") @@ -911,9 +972,11 @@ class ConnectionWizard(dbus.service.Object): self.SetWirelessInterface(config.get("Settings","wireless_interface")) self.SetWiredInterface(config.get("Settings","wired_interface")) self.SetWPADriver(config.get("Settings","wpa_driver")) - self.SetAlwaysShowWiredInterface(False) - self.SetAutoReconnect(True) - self.SetDebugMode(False) + self.SetAlwaysShowWiredInterface(0) + self.SetAutoReconnect(1) + self.SetHideDupeAPs(0) + self.SetDebugMode(0) + self.SetWiredAutoConnectMethod(1) self.SetGlobalDNS(None,None,None) #end If diff --git a/edgy.py b/edgy.py index 4315a4d..bcf9e97 100755 --- a/edgy.py +++ b/edgy.py @@ -77,15 +77,24 @@ def open_wicd_gui(): if ret == 0: lastWinId = os.spawnlpe(os.P_NOWAIT, './gui.py', os.environ) +def wired_profile_chooser(): + print 'profile chooser is running' + os.spawnlpe(os.P_WAIT, './gui.py', os.environ) + def set_signal_image(): global LastStrength global stillWired #keeps us from resetting the wired info over and over global network #declared as global so it gets initialized before initial use - # Disable logging if debugging isn't on to prevent log spam + #Disable logging if debugging isn't on to prevent log spam if not daemon.GetDebugMode(): config.DisableLogging() + #Check to see we wired profile autoconnect chooser needs to be displayed + if daemon.GetNeedWiredProfileChooser() == True: + wired_profile_chooser() + daemon.SetNeedWiredProfileChooser(False) + wired_ip = wired.GetWiredIP() if wired.CheckPluggedIn() == True and wired_ip != None: if stillWired == False: # Only set image/tooltip if it hasn't been set already @@ -94,7 +103,7 @@ def set_signal_image(): stillWired = True lock = '' else: - if stillWired == True: + if stillWired == True: #this only occurs when we were previously using wired but it became unplugged tr.set_from_file("images/no-signal.png") tr.set_tooltip(language['not_connected']) stillWired = False @@ -107,7 +116,7 @@ def set_signal_image(): #only update if the signal strength has changed because doing I/O calls is expensive, #and the icon flickers - if (signal != LastStrength or network != wireless.GetCurrentNetwork()) and wireless_ip != None: + if (signal != LastStrength or network != wireless.GetCurrentNetwork() or signal == 0) and wireless_ip != None: LastStrength = signal lock = '' #set the string to '' so that when it is put in "high-signal" + lock + ".png", there will be nothing curNetID = wireless.GetCurrentNetworkID() #the network ID needs to be checked because a negative value here will break the tray @@ -125,32 +134,38 @@ def set_signal_image(): tr.set_from_file("images/bad-signal" + lock + ".png") elif signal == 0: tr.set_from_file("images/no-signal.png") - #Auto-reconnect code - not sure how well this works. I know that without the ForcedDisconnect check it reconnects you when - #a disconnect is forced. People who have disconnection problems need to test it to determine if it actually works. - #First it will attempt to reconnect to the last known wireless network, and if that fails it should run a scan and try to - #connect to any network set to autoconnect. - if wireless.GetAutoReconnect() == True and wireless.CheckIfWirelessConnecting() == False and wireless.GetForcedDisconnect() == False: - curNetID = wireless.GetCurrentNetworkID() - if curNetID > -1: - wireless.ConnectWireless(wireless.GetCurrentNetworkID()) - print 'Trying to autoreconnect' - while wireless.CheckIfWirelessConnecting() == True: - time.sleep(1) - if wireless.GetCurrentSignalStrength() != 0: - print "Successfully autoreconnected." - else: - print "Couldn't reconnect to last used network, scanning for an autoconnect network..." - print wireless.AutoConnect(True) + auto_reconnect() - elif wireless_ip == None: - tr.set_from_file("images/no-signal.png") - tr.set_tooltip(language['not_connected']) + elif wireless_ip == None and wired_ip == None: + tr.set_from_file("images/no-signal.png") + tr.set_tooltip(language['not_connected']) + auto_reconnect() if not daemon.GetDebugMode(): config.EnableLogging() return True +def auto_reconnect(): + #Auto-reconnect code - not sure how well this works. I know that without the ForcedDisconnect check it reconnects you when + #a disconnect is forced. People who have disconnection problems need to test it to determine if it actually works. + #First it will attempt to reconnect to the last known wireless network, and if that fails it should run a scan and try to + #connect to a wired network or any wireless network set to autoconnect. + if wireless.GetAutoReconnect() == True and daemon.CheckIfConnecting() == False and wireless.GetForcedDisconnect() == False: + curNetID = wireless.GetCurrentNetworkID() + print 'Trying to autoreconnect to last used network' + if curNetID > -1: + wireless.ConnectWireless(curNetID) + while wireless.CheckIfWirelessConnecting() == True: + time.sleep(1) + if wireless.GetCurrentSignalStrength() != 0: + print "Successfully autoreconnected." + else: + print "Couldn't reconnect to last used network, scanning for an autoconnect network..." + daemon.AutoConnect(True) + else: + daemon.AutoConnect(True) + class TrackerStatusIcon(gtk.StatusIcon): def __init__(self): gtk.StatusIcon.__init__(self) @@ -184,6 +199,8 @@ class TrackerStatusIcon(gtk.StatusIcon): self.set_visible(True) self.connect('activate', self.on_activate) self.connect('popup-menu', self.on_popup_menu) + + wireless.SetForcedDisconnect(False) def on_activate(self, data): open_wicd_gui() diff --git a/gui.py b/gui.py index 01aec22..d1c510a 100644 --- a/gui.py +++ b/gui.py @@ -13,7 +13,7 @@ except: print 'Missing GTK and gtk.glade. Aborting.' sys.exit(1) -import time, os, misc, gettext, locale, gobject, dbus, dbus.service +import time, os, misc, gettext, locale, gobject, dbus, dbus.service,pango if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): import dbus.glib @@ -131,6 +131,11 @@ language['use_ics'] = _('Activate Internet Connection Sharing') language['default_wired'] = _('Use as default profile (overwrites any previous default)') language['use_debug_mode'] = _('Enable debug mode') language['use_global_dns'] = _('Use global DNS servers') +language['use_default_profile'] = _('Use default profile on wired auto-connect') +language['show_wired_list'] = _('Prompt for profile on wired auto-connect') +language['choose_wired_profile'] = _('Select or create a wired profile to connect with') +language['wired_network_found'] = _('Wired connection detected') +language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporarily') language['0'] = _('0') language['1'] = _('1') @@ -418,7 +423,6 @@ class NetworkEntry(gtk.Expander): if stringToNone(netmask.get_text()) == None: #make sure the netmask is blank netmask.set_text('255.255.255.0') #fill in the most common one - def resetStaticCheckboxes(self): #enable the right stuff if not stringToNone(self.txtIP.get_text()) == None: @@ -491,14 +495,15 @@ class WiredNetworkEntry(NetworkEntry): self.set_label(language['wired_network']) self.resetStaticCheckboxes() self.comboProfileNames = gtk.combo_box_entry_new_text() + self.isFullGUI = True - profileList = config.GetWiredProfileList() - if profileList: #make sure there is something in it... + self.profileList = config.GetWiredProfileList() + if self.profileList: #make sure there is something in it... for x in config.GetWiredProfileList(): #add all the names to the combobox self.comboProfileNames.append_text(x) - hboxTemp = gtk.HBox(False,0) + self.hboxTemp = gtk.HBox(False,0) hboxDef = gtk.HBox(False,0) - buttonOK = gtk.Button(stock=gtk.STOCK_ADD) + self.buttonAdd = gtk.Button(stock=gtk.STOCK_ADD) self.buttonDelete = gtk.Button(stock=gtk.STOCK_DELETE) self.profileHelp = gtk.Label(language['wired_network_instructions']) self.checkboxDefaultProfile = gtk.CheckButton(language['default_wired']) @@ -509,15 +514,15 @@ class WiredNetworkEntry(NetworkEntry): self.profileHelp.set_line_wrap(True) self.vboxTop.pack_start(self.profileHelp,fill=False,expand=False) - hboxTemp.pack_start(self.comboProfileNames,fill=True,expand=True) - hboxTemp.pack_start(buttonOK,fill=False,expand=False) - hboxTemp.pack_start(self.buttonDelete,fill=False,expand=False) + 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) - buttonOK.connect("clicked",self.addProfile) #hook up our buttons + self.buttonAdd.connect("clicked",self.addProfile) #hook up our buttons self.buttonDelete.connect("clicked",self.removeProfile) self.comboProfileNames.connect("changed",self.changeProfile) - self.vboxTop.pack_start(hboxTemp) + self.vboxTop.pack_start(self.hboxTemp) self.vboxTop.pack_start(hboxDef) if stringToBoolean(wired.GetWiredProperty("default")) == True: @@ -528,7 +533,7 @@ class WiredNetworkEntry(NetworkEntry): self.show_all() self.profileHelp.hide() - if profileList != None: + if self.profileList != None: self.comboProfileNames.set_active(0) print "wired profiles found" self.set_expanded(False) @@ -557,9 +562,10 @@ class WiredNetworkEntry(NetworkEntry): config.CreateWiredNetworkProfile(profileName) self.comboProfileNames.prepend_text(profileName) self.comboProfileNames.set_active(0) - self.buttonDelete.set_sensitive(True) - self.vboxAdvanced.set_sensitive(True) - self.higherLevel.connectButton.set_sensitive(True) + if self.isFullGUI == True: + self.buttonDelete.set_sensitive(True) + self.vboxAdvanced.set_sensitive(True) + self.higherLevel.connectButton.set_sensitive(True) def removeProfile(self,widget): print "removing profile" @@ -570,9 +576,10 @@ class WiredNetworkEntry(NetworkEntry): self.profileHelp.show() entry = self.comboProfileNames.child entry.set_text("") - self.buttonDelete.set_sensitive(False) - self.vboxAdvanced.set_sensitive(False) - self.higherLevel.connectButton.set_sensitive(False) + if self.isFullGUI == True: + self.buttonDelete.set_sensitive(False) + self.vboxAdvanced.set_sensitive(False) + self.higherLevel.connectButton.set_sensitive(False) else: self.profileHelp.hide() @@ -585,7 +592,9 @@ class WiredNetworkEntry(NetworkEntry): def changeProfile(self,widget): if self.comboProfileNames.get_active() > -1: #this way the name doesn't change - # #everytime someone types something in + # #everytime someone types something in + if self.isFullGUI == False: + return print "changing profile..." profileName = self.comboProfileNames.get_active_text() print profileName @@ -761,30 +770,80 @@ class appGui: def __init__(self): print "starting..." - gladefile = "data/wicd.glade" - self.windowname = "gtkbench" - self.wTree = gtk.glade.XML(gladefile) + #two possibilities here, one is that the normal GUI should be opened, the other is that wired auto-connect + #is set to prompt the user to select a profile. It's kind of hacked together, but it'll do. + if daemon.GetNeedWiredProfileChooser() == True: + #profile chooser init block + #import and init WiredNetworkEntry to steal some of the functions and widgets it uses + wiredNetEntry = WiredNetworkEntry() + wiredNetEntry.__init__() + + dialog = gtk.Dialog(title=language['wired_network_found'], flags = gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CONNECT,1,gtk.STOCK_CANCEL,2)) + dialog.set_has_separator(False) + dialog.set_size_request(400,150) + instructLabel = gtk.Label(language['choose_wired_profile'] + ':\n') + stoppopcheckbox = gtk.CheckButton(language['stop_showing_chooser']) - dic = { "refresh_clicked" : self.refresh_networks, "quit_clicked" : self.exit, 'disconnect_clicked' : self.disconnect_wireless, "main_exit" : self.exit, "cancel_clicked" : self.cancel_connect, "connect_clicked" : self.connect_hidden, "preferences_clicked" : self.settings_dialog, "about_clicked" : self.about_dialog, 'create_adhoc_network_button_button' : self.create_adhoc_network} - self.wTree.signal_autoconnect(dic) + wiredNetEntry.isFullGUI = False + instructLabel.set_alignment(0,0) + stoppopcheckbox.set_active(False) + + #remove widgets that were added to the normal WiredNetworkEntry so that they can be added to the pop-up wizard + wiredNetEntry.vboxTop.remove(wiredNetEntry.hboxTemp) + wiredNetEntry.vboxTop.remove(wiredNetEntry.profileHelp) + + dialog.vbox.pack_start(instructLabel,fill=False,expand=False) + dialog.vbox.pack_start(wiredNetEntry.profileHelp,fill=False,expand=False) + dialog.vbox.pack_start(wiredNetEntry.hboxTemp,fill=False,expand=False) + dialog.vbox.pack_start(stoppopcheckbox,fill=False,expand=False) + dialog.show_all() + + wiredNetEntry.profileHelp.hide() + if wiredNetEntry.profileList != None: + wiredNetEntry.comboProfileNames.set_active(0) + print "wired profiles found" + else: + print "no wired profiles found" + wiredNetEntry.profileHelp.show() + + response = dialog.run() + if response == 1: + print 'reading profile ', wiredNetEntry.comboProfileNames.get_active_text() + config.ReadWiredNetworkProfile(wiredNetEntry.comboProfileNames.get_active_text()) + wired.ConnectWired() + dialog.destroy() + sys.exit(0) + else: + if stoppopcheckbox.get_active() == True: + wired.use_default_profile = 1 #so that the pop-up doesn't keep appearing if you cancel it + dialog.destroy() + sys.exit(0) + else: + #normal init block + gladefile = "data/wicd.glade" + self.windowname = "gtkbench" + self.wTree = gtk.glade.XML(gladefile) - #set some strings in the GUI - they may be translated + dic = { "refresh_clicked" : self.refresh_networks, "quit_clicked" : self.exit, 'disconnect_clicked' : self.disconnect_wireless, "main_exit" : self.exit, "cancel_clicked" : self.cancel_connect, "connect_clicked" : self.connect_hidden, "preferences_clicked" : self.settings_dialog, "about_clicked" : self.about_dialog, 'create_adhoc_network_button_button' : self.create_adhoc_network} + self.wTree.signal_autoconnect(dic) - self.wTree.get_widget("label_instructions").set_label(language['select_a_network']) - #I don't know how to translate a menu entry - #more specifically, I don't know how to set a menu entry's text - #self.wTree.get_widget("connect_button").modify_text(language['hidden_network']) - self.wTree.get_widget("progressbar").set_text(language['connecting']) + #set some strings in the GUI - they may be translated - self.network_list = self.wTree.get_widget("network_list_vbox") - self.status_area = self.wTree.get_widget("connecting_hbox") - self.status_bar = self.wTree.get_widget("statusbar") - self.refresh_networks(fresh=False) + self.wTree.get_widget("label_instructions").set_label(language['select_a_network']) + #I don't know how to translate a menu entry + #more specifically, I don't know how to set a menu entry's text + #self.wTree.get_widget("connect_button").modify_text(language['hidden_network']) + self.wTree.get_widget("progressbar").set_text(language['connecting']) - self.statusID = None + self.network_list = self.wTree.get_widget("network_list_vbox") + self.status_area = self.wTree.get_widget("connecting_hbox") + self.status_bar = self.wTree.get_widget("statusbar") + self.refresh_networks(fresh=False) - gobject.timeout_add(300,self.update_statusbar) - gobject.timeout_add(100,self.pulse_progress_bar) + self.statusID = None + + gobject.timeout_add(300,self.update_statusbar) + gobject.timeout_add(100,self.pulse_progress_bar) def create_adhoc_network(self,widget=None): '''shows a dialog that creates a new adhoc network''' @@ -829,7 +888,7 @@ class appGui: self.keyEntry.set_sensitive(self.useEncryptionCheckbox.get_active()) def disconnect_wireless(self,widget=None): - wireless.DisconnectWireless() + wireless.DisconnectWireless() def about_dialog(self,widget,event=None): dialog = gtk.AboutDialog() @@ -843,14 +902,18 @@ class appGui: def settings_dialog(self,widget,event=None): dialog = gtk.Dialog(title=language['preferences'], flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_OK,1,gtk.STOCK_CANCEL,2)) dialog.set_has_separator(False) - dialog.set_size_request(375,-1) + dialog.set_size_request(465,-1) wiredcheckbox = gtk.CheckButton(language['wired_always_on']) wiredcheckbox.set_active(wired.GetAlwaysShowWiredInterface()) reconnectcheckbox = gtk.CheckButton(language['auto_reconnect']) reconnectcheckbox.set_active(wireless.GetAutoReconnect()) debugmodecheckbox = gtk.CheckButton(language['use_debug_mode']) debugmodecheckbox.set_active(daemon.GetDebugMode()) + sepline = gtk.HSeparator() + usedefaultradiobutton = gtk.RadioButton(None,language['use_default_profile'],False) + showlistradiobutton = gtk.RadioButton(usedefaultradiobutton,language['show_wired_list'],False) wpadriverlabel = SmallLabel(language['wpa_supplicant_driver'] + ':') + wpadriverlabel.set_size_request(75,-1) wpadrivercombo = gtk.combo_box_new_text() wpadrivercombo.set_size_request(50,-1) wpadrivers = [ "hostap","hermes","madwifi","atmel","wext","ndiswrapper","broadcom","ipw","ralink legacy" ] @@ -875,6 +938,9 @@ class appGui: entryWirelessInterface = LabelEntry(language['wireless_interface'] + ':') entryWiredInterface = LabelEntry(language['wired_interface'] + ':') + entryWirelessInterface.label.set_size_request(260,-1) + entryWiredInterface.label.set_size_request(260,-1) + entryWiredAutoMethod = gtk.Label('Wired Autoconnection options:') entryWirelessInterface.entry.set_text(daemon.GetWirelessInterface()) entryWiredInterface.entry.set_text(daemon.GetWiredInterface()) @@ -893,6 +959,13 @@ class appGui: dns2Entry.set_text(noneToBlankString(dns_addresses[1])) dns3Entry.set_text(noneToBlankString(dns_addresses[2])) + entryWiredAutoMethod.set_alignment(0,0) + sepline.set_size_request(2,8) + atrlist = pango.AttrList() + atrlist.insert(pango.AttrUnderline(pango.UNDERLINE_SINGLE,0,28)) + atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD,0,50)) + entryWiredAutoMethod.set_attributes(atrlist) + dialog.vbox.pack_start(wpabox) dialog.vbox.pack_start(entryWirelessInterface) dialog.vbox.pack_start(entryWiredInterface) @@ -905,8 +978,13 @@ class appGui: dialog.vbox.pack_start(wiredcheckbox) dialog.vbox.pack_start(reconnectcheckbox) dialog.vbox.pack_start(debugmodecheckbox) + dialog.vbox.pack_start(sepline) + dialog.vbox.pack_start(entryWiredAutoMethod) + dialog.vbox.pack_start(usedefaultradiobutton) + dialog.vbox.pack_start(showlistradiobutton) dialog.vbox.set_spacing(5) dialog.show_all() + response = dialog.run() if response == 1: daemon.SetUseGlobalDNS(useGlobalDNSCheckbox.get_active()) @@ -918,6 +996,7 @@ class appGui: wired.SetAlwaysShowWiredInterface(wiredcheckbox.get_active()) wireless.SetAutoReconnect(reconnectcheckbox.get_active()) daemon.SetDebugMode(debugmodecheckbox.get_active()) + wired.SetWiredAutoConnectMethod(usedefaultradiobutton.get_active()) dialog.destroy() else: dialog.destroy() @@ -977,7 +1056,7 @@ class appGui: if self.statusID: self.status_bar.remove(1,self.statusID) #use the chain approach to save calls to external programs - #external programs are quite CPU intensive + #external programs are quite CPU intensive if wireless_ip: network = wireless.GetCurrentNetwork() if network: @@ -1084,10 +1163,8 @@ class appGui: # Script info before_script = networkentry.expander.txtBeforeScript.get_text() after_script = networkentry.expander.txtAfterScript.get_text() - wireless.SetWirelessProperty(networkid,"beforescript",noneToString(before_script)) - wireless.SetWirelessProperty(networkid,"afterscript",noneToString(after_script)) - wireless.SetWirelessBeforeScript(before_script) - wireless.SetWirelessAfterScript(after_script) + wireless.SetWirelessBeforeScript(networkid,before_script) + wireless.SetWirelessAfterScript(networkid,after_script) # if it exists. maybe kept as a value in the network entry? Not sure... print "connecting to wireless network..." @@ -1117,8 +1194,6 @@ class appGui: #Script Info before_script = networkentry.expander.txtBeforeScript.get_text() after_script = networkentry.expander.txtAfterScript.get_text() - wired.SetWiredProperty("beforescript",noneToString(before_script)) - wired.SetWiredProperty("afterscript",noneToString(after_script)) wired.SetWiredBeforeScript(before_script) wired.SetWiredAfterScript(after_script) diff --git a/networking.py b/networking.py index 903640c..d8b2b71 100644 --- a/networking.py +++ b/networking.py @@ -39,15 +39,15 @@ class Wireless: #init 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) + 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\d*)',re.DOTALL | re.I | re.M | re.S) mode_pattern = re.compile('.*Mode:(.*?)\n',re.DOTALL | re.I | re.M | re.S) - wep_pattern = re.compile('.*Encryption key:(.*?)\n',re.DOTALL | re.I | re.M | re.S) + wep_pattern = re.compile('.*Encryption key:(.*?)\n',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) + wpa2_pattern = re.compile('(WPA2)',re.DOTALL | re.I | re.M | re.S) ##### ## PREPARE THE INTERFACE @@ -139,7 +139,8 @@ class Wireless: if len(info) < 5 or info == None or info == '': break; if info[2] == CurrentNetwork["essid"]: - if info[5] == 'WEP' or info[5] == 'OPEN': # Needs to be tested + CurrentNetwork["encryption"] = True + if info[5] == 'WEP' or ((info[5] == 'OPEN' or info[5] == 'SHARED') and info[4] == 'WEP'): # Needs to be tested CurrentNetwork["encryption_method"] = 'WEP' elif info[5] == 'WPA-PSK': CurrentNetwork["encrytion_method"] = 'WPA' @@ -148,7 +149,7 @@ class Wireless: else: print 'Unknown AuthMode, can\'t assign encryption_method!!' CurrentNetwork["encryption_method"] = 'Unknown' - CurrentNetwork["quality"] = info[1][1:] #set link strength here + CurrentNetwork["quality"] = info[1][1:] #set signal strength here (not link quality! dBm vs %) else: CurrentNetwork["encryption"] = False #end If @@ -355,9 +356,17 @@ class Wireless: if len(info) < 5 or info == None or info == '': #probably overkill, but the last 2 won't get run anyways break; if info[2] == network.get("essid"): - if info[5] == 'WEP' or info[5] == 'OPEN': # Needs to be tested + if info[5] == 'WEP' or (info[5] == 'OPEN' and info[4] == 'WEP'): # Needs to be tested print 'setting up WEP' misc.Run("iwconfig " + self.wireless_interface + " key " + network.get('key')) + elif info[5] == 'SHARED' and info[4] == 'WEP': + print 'setting up WEP' + misc.Run("iwpriv " + self.wireless_interface + " set NetworkType=" + info[6]) + misc.Run("iwpriv " + self.wireless_interface + " set AuthMode=SHARED") + misc.Run("iwpriv " + self.wireless_interface + " set EncrypType=" + info[4]) + misc.Run("iwpriv " + self.wireless_interface + " set Key1=" + network.get('key')) + misc.Run("iwpriv " + self.wireless_interface + " set DefaultKeyID=1") + misc.Run("iwpriv " + self.wireless_interface + " set SSID=" + info[2]) elif info[5] == 'WPA-PSK': print 'setting up WPA-PSK' misc.Run("iwpriv " + self.wireless_interface + " set NetworkType=" + info[6]) @@ -386,6 +395,21 @@ class Wireless: print "setting the broadcast address..." + network["broadcast"] misc.Run("ifconfig " + self.wireless_interface + " broadcast " + network["broadcast"]) + if not network.get("dns1") == None: + self.lock.acquire() + self.ConnectingMessage = 'setting_static_dns' + self.lock.release() + + print "setting the first dns server...", network["dns1"] + resolv = open("/etc/resolv.conf","w") + misc.WriteLine(resolv,"nameserver " + network["dns1"]) + if not network.get("dns2") == None: + print "setting the second dns server...", network["dns2"] + misc.WriteLine(resolv,"nameserver " + network["dns2"]) + if not network.get("dns3") == None: + print "setting the third dns server..." + misc.WriteLine(resolv,"nameserver " + network["dns3"]) + if not network.get('ip') == None: self.lock.acquire() self.ConnectingMessage = 'setting_static_ip'