diff --git a/daemon.py b/daemon.py index d584860..ea6b88f 100644 --- a/daemon.py +++ b/daemon.py @@ -294,7 +294,7 @@ class ConnectionWizard(dbus.service.Object): self.ConnectWired() time.sleep(1) print "Attempting to autoconnect with wired interface..." - while self.CheckIfWiredConnecting(): # Keeps us from going into an infinite connecting loop + while self.CheckIfWiredConnecting(): #Leaving this for wired since you're probably not going to have DHCP problems time.sleep(1) print "...done autoconnecting." else: @@ -307,11 +307,14 @@ class ConnectionWizard(dbus.service.Object): 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"]) + print 'trying to automatically connect to...',str(self.LastScan[x]["essid"]) self.ConnectWireless(x) - time.sleep(3) - while self.CheckIfWirelessConnecting(): - print "autoconnecting... hold" + time.sleep(5) + return + #Changed this because the while loop would cause dbus errors if + #there was trouble connecting or connecting took a long time + #print "autoconnecting... hold" + #while self.CheckIfWirelessConnecting(): #not sure why I need to get IPs, but #it solves the autoconnect problem #i think it has something to do with @@ -319,7 +322,7 @@ class ConnectionWizard(dbus.service.Object): #if anyone knows why...email me at compwiz18@gmail.com #only some people need these statements for autoconnect #to function properly - self.GetWirelessIP() + #self.GetWirelessIP() ### # removed line below for 1.3.0 - if there is trouble with # connecting at boot, @@ -329,9 +332,14 @@ class ConnectionWizard(dbus.service.Object): # think? -- adam ### #self.GetWiredIP() - time.sleep(2) - print "autoconnecting... done" - return + #time.sleep(3) + #if self.GetWirelessIP() != None: + # print "autoconnecting... done" + # return + #else: + # print 'autoconnect was taking too long, aborted.' + # self.SetForcedDisconnect(True) + # return print "unable to autoconnect, you'll have to manually connect" else: print 'autoconnect failed because wireless interface == None' @@ -898,7 +906,7 @@ class ConnectionWizard(dbus.service.Object): self.always_show_wired_interface = config.get("Settings","always_show_wired_interface") else: config.set("Settings","always_show_wired_interface","False") - self.always_show_wired_interface = False + self.always_show_wired_interface = 0 if config.has_option("Settings","use_global_dns"): print config.get("Settings","use_global_dns") self.SetUseGlobalDNS(int(config.get("Settings","use_global_dns"))) diff --git a/dapper.py b/dapper.py index 3ddf9dc..832dd2f 100644 --- a/dapper.py +++ b/dapper.py @@ -64,12 +64,12 @@ def set_signal_image(): if not daemon.GetDebugMode(): config.DisableLogging() - - #Check to see we wired profile autoconnect chooser needs to be displayed + + #Check if wired profile chooser should be launched if daemon.GetNeedWiredProfileChooser() == True: wired_profile_chooser() daemon.SetNeedWiredProfileChooser(False) - + #Are we using a wired connection? wired_ip = wired.GetWiredIP() if wired.CheckPluggedIn() == True and wired_ip: @@ -78,11 +78,13 @@ def set_signal_image(): tooltip.set_tip(eb,language['connected_to_wired'].replace('$A',wired_ip)) stillWired = True lock = '' + #Check for wireless or no connection else: if stillWired == True: #wire must have gotten unplugged pic.set_from_file("images/no-signal.png") - tooltip.set_tip(eb,"Wicd - No Connection") + tooltip.set_tip(eb,language['not_connected']) stillWired = False + wireless_ip = wireless.GetWirelessIP() #If ip returns as None, we are probably returning from hibernation and need to force signal to 0 to avoid crashing if wireless_ip != None: @@ -202,7 +204,7 @@ manager.insert_action_group(ag, 0) manager.add_ui_from_string(menu) menu = manager.get_widget('/Menubar/Menu/About').props.parent -gobject.timeout_add(2000,set_signal_image) +gobject.timeout_add(3000,set_signal_image) tooltip.set_tip(eb, "Wicd Systray") pic.set_from_file("images/no-signal.png") diff --git a/edgy.py b/edgy.py index bcf9e97..8d511cc 100755 --- a/edgy.py +++ b/edgy.py @@ -90,11 +90,12 @@ def set_signal_image(): if not daemon.GetDebugMode(): config.DisableLogging() - #Check to see we wired profile autoconnect chooser needs to be displayed + #Check if wired profile chooser should be launched if daemon.GetNeedWiredProfileChooser() == True: wired_profile_chooser() daemon.SetNeedWiredProfileChooser(False) + #Check for active wired connection 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 @@ -102,11 +103,13 @@ def set_signal_image(): tr.set_tooltip(language['connected_to_wired'].replace('$A',wired_ip)) stillWired = True lock = '' + #Check if using wireless/not-connected else: 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 + wireless_ip = wireless.GetWirelessIP() #If ip returns as None, we are probably returning from hibernation and need to force signal to 0 to avoid crashing if wireless_ip != None: @@ -119,7 +122,7 @@ def set_signal_image(): 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 + curNetID = wireless.GetCurrentNetworkID() #this needs to be checked because a negative value will break the tray if signal > 0 and curNetID > -1 and wireless.GetWirelessProperty(curNetID,"encryption"): lock = '-lock' #set the string to '-lock' so that it will display the lock picture network = str(wireless.GetCurrentNetwork()) @@ -199,6 +202,8 @@ class TrackerStatusIcon(gtk.StatusIcon): self.set_visible(True) self.connect('activate', self.on_activate) self.connect('popup-menu', self.on_popup_menu) + self.set_from_file("images/no-signal.png") + self.set_tooltip("Initializing wicd...") wireless.SetForcedDisconnect(False) @@ -217,7 +222,7 @@ class TrackerStatusIcon(gtk.StatusIcon): def on_about(self, data): dialog = gtk.AboutDialog() dialog.set_name('wicd tray icon') - dialog.set_version('0.2') + dialog.set_version('0.2') #Might be time to move the version number up? dialog.set_comments('an icon that shows your network connectivity') dialog.set_website('http://wicd.sourceforge.net') dialog.run() @@ -231,7 +236,6 @@ class TrackerStatusIcon(gtk.StatusIcon): LastStrength = -2 stillWired = False network = '' -tr=None tr=TrackerStatusIcon() gobject.timeout_add(3000,set_signal_image) diff --git a/misc.py b/misc.py index fbcb624..2c45416 100644 --- a/misc.py +++ b/misc.py @@ -31,8 +31,8 @@ def IsValidIP(ip): return False def PromptToStartDaemon(): - gksudo_args = ['gksudo', '--message', 'Wicd needs to access your computer\'s network cards.','--','./daemon.py'] - os.spawnvpe(os.P_NOWAIT, 'gksudo', gksudo_args, os.environ) + #script execution doesn't work correctly if daemon gets autostarted, so just prompt user to start manually + print 'You need to start the daemon before using the gui or tray. Use the command \'sudo /etc/init.d/wicd start\'.' def RunRegex(regex,string): m = regex.search( string ) diff --git a/networking.py b/networking.py index cb45ae7..81b4e4d 100644 --- a/networking.py +++ b/networking.py @@ -44,6 +44,7 @@ class Wireless: 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) + freq_pattern = re.compile('.*Frequency:(.*?)\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) @@ -112,6 +113,31 @@ class Wireless: CurrentNetwork["hidden"] = False CurrentNetwork["channel"] = misc.RunRegex(channel_pattern,cell) + if CurrentNetwork["channel"] == None: #some cards don't show the channel number + freq = misc.RunRegex(freq_pattern,cell) + if freq == '2.412 GHz': + CurrentNetwork["channel"] = 1 + elif freq == '2.417 GHz': + CurrentNetwork["channel"] = 2 + elif freq == '2.422 GHz': + CurrentNetwork["channel"] = 3 + elif freq == '2.427 GHz': + CurrentNetwork["channel"] = 4 + elif freq == '2.432 GHz': + CurrentNetwork["channel"] = 5 + elif freq == '2.437 GHz': + CurrentNetwork["channel"] = 6 + elif freq == '2.442 GHz': + CurrentNetwork["channel"] = 7 + elif freq == '2.447 GHz': + CurrentNetwork["channel"] = 8 + elif freq == '2.452 GHz': + CurrentNetwork["channel"] = 9 + elif freq == '2.457 GHz': + CurrentNetwork["channel"] = 10 + elif freq == '2.462 GHz': + CurrentNetwork["channel"] = 11 + CurrentNetwork["bssid"] = misc.RunRegex(ap_mac_pattern,cell) print " ##### " + CurrentNetwork["bssid"] CurrentNetwork["mode"] = misc.RunRegex(mode_pattern,cell) @@ -149,6 +175,7 @@ class Wireless: else: print 'Unknown AuthMode, can\'t assign encryption_method!!' CurrentNetwork["encryption_method"] = 'Unknown' + CurrentNetwork["quality"] = info[1][1:] #set signal strength here (not link quality! dBm vs %) else: CurrentNetwork["encryption"] = False @@ -258,15 +285,10 @@ class Wireless: self.IsConnecting = True network = self.network - self.lock.acquire() - self.ConnectingMessage = 'executing_before_script' - self.lock.release() - before_script = self.before_script - print 'before script is ', before_script - if before_script != '' and before_script != None: + if self.before_script != '' and self.before_script != None: print 'Executing pre-connection script' - misc.Run(before_script) + print misc.Run('./run-script.py ' + self.before_script) #put it down print "interface down..." @@ -339,7 +361,7 @@ class Wireless: else: misc.Run("iwconfig " + self.wireless_interface + " mode " + network["mode"]) - misc.Run("iwconfig " + self.wireless_interface + " essid \"" + network["essid"] + "\" channel " + str(network["channel"])) + " ap " + network["bssid"] + misc.Run("iwconfig " + self.wireless_interface + " essid \"" + network["essid"] + "\" channel " + str(network["channel"]) + " ap " + network["bssid"]) if self.wpa_driver == "ralink legacy": #Adds support for ralink cards that can't use wpasupplicant if network.get('key') != None: @@ -474,10 +496,9 @@ class Wireless: print "done" self.IsConnecting = False - after_script = self.after_script - if after_script != '' and after_script != None: + if self.after_script != '' and self.after_script != None: print 'executing post connection script' - misc.Run(after_script) + print misc.Run('./run-script.py ' + self.after_script) #end function Connect #end class Connect @@ -613,15 +634,12 @@ class Wired: #we don't touch the wifi interface #but we do remove all wifi entries from the #routing table - - before_script = self.before_script - print 'before script is ', before_script - if before_script != '' and before_script != None: - print 'Executing pre-connection script' - misc.Run(before_script) - self.IsConnecting = True - network = self.network + network = self.network + + if self.before_script != '' and self.before_script != None: + print 'executing pre-connection script' + misc.Run('./run-script.py ' + self.before_script) #put it down self.lock.acquire() @@ -703,8 +721,7 @@ class Wired: self.lock.release() self.IsConnecting = False - after_script = self.after_script - if after_script != '' and after_script != None: + if self.after_script != '' and self.after_script != None: print 'executing post connection script' - misc.Run(after_script) + misc.Run('./run-script.py ' + self.after_script) #end function run diff --git a/run-script.py b/run-script.py new file mode 100755 index 0000000..4ba165d --- /dev/null +++ b/run-script.py @@ -0,0 +1,13 @@ +#!/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 +print misc.Run(command)