1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-20 04:48:00 +01:00

Changed script execution method so that scripts are always run in usermode.

Removed autostarting daemon code so that script execution would work properly.
Added channel display support for cards that only get frequency info in 'iwlist scan'.
Changed autoconnect behavior to fix a bug where dbus would crash if connecting was taking too long.
Changed/added some comments.
This commit is contained in:
imdano
2007-08-01 09:31:43 +00:00
parent 8a9497cc05
commit 626cd6010c
6 changed files with 87 additions and 43 deletions

View File

@@ -294,7 +294,7 @@ class ConnectionWizard(dbus.service.Object):
self.ConnectWired() self.ConnectWired()
time.sleep(1) time.sleep(1)
print "Attempting to autoconnect with wired interface..." 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) time.sleep(1)
print "...done autoconnecting." print "...done autoconnecting."
else: else:
@@ -307,11 +307,14 @@ class ConnectionWizard(dbus.service.Object):
if bool(self.LastScan[x]["has_profile"]): if bool(self.LastScan[x]["has_profile"]):
print str(self.LastScan[x]["essid"]) + ' has profile' print str(self.LastScan[x]["essid"]) + ' has profile'
if bool(self.LastScan[x].get('automatic')): 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) self.ConnectWireless(x)
time.sleep(3) time.sleep(5)
while self.CheckIfWirelessConnecting(): return
print "autoconnecting... hold" #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 #not sure why I need to get IPs, but
#it solves the autoconnect problem #it solves the autoconnect problem
#i think it has something to do with #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 #if anyone knows why...email me at compwiz18@gmail.com
#only some people need these statements for autoconnect #only some people need these statements for autoconnect
#to function properly #to function properly
self.GetWirelessIP() #self.GetWirelessIP()
### ###
# removed line below for 1.3.0 - if there is trouble with # removed line below for 1.3.0 - if there is trouble with
# connecting at boot, # connecting at boot,
@@ -329,9 +332,14 @@ class ConnectionWizard(dbus.service.Object):
# think? -- adam # think? -- adam
### ###
#self.GetWiredIP() #self.GetWiredIP()
time.sleep(2) #time.sleep(3)
print "autoconnecting... done" #if self.GetWirelessIP() != None:
return # 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" print "unable to autoconnect, you'll have to manually connect"
else: else:
print 'autoconnect failed because wireless interface == None' 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") self.always_show_wired_interface = config.get("Settings","always_show_wired_interface")
else: else:
config.set("Settings","always_show_wired_interface","False") 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"): if config.has_option("Settings","use_global_dns"):
print config.get("Settings","use_global_dns") print config.get("Settings","use_global_dns")
self.SetUseGlobalDNS(int(config.get("Settings","use_global_dns"))) self.SetUseGlobalDNS(int(config.get("Settings","use_global_dns")))

View File

@@ -65,7 +65,7 @@ def set_signal_image():
if not daemon.GetDebugMode(): if not daemon.GetDebugMode():
config.DisableLogging() 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: if daemon.GetNeedWiredProfileChooser() == True:
wired_profile_chooser() wired_profile_chooser()
daemon.SetNeedWiredProfileChooser(False) daemon.SetNeedWiredProfileChooser(False)
@@ -78,11 +78,13 @@ def set_signal_image():
tooltip.set_tip(eb,language['connected_to_wired'].replace('$A',wired_ip)) tooltip.set_tip(eb,language['connected_to_wired'].replace('$A',wired_ip))
stillWired = True stillWired = True
lock = '' lock = ''
#Check for wireless or no connection
else: else:
if stillWired == True: #wire must have gotten unplugged if stillWired == True: #wire must have gotten unplugged
pic.set_from_file("images/no-signal.png") pic.set_from_file("images/no-signal.png")
tooltip.set_tip(eb,"Wicd - No Connection") tooltip.set_tip(eb,language['not_connected'])
stillWired = False stillWired = False
wireless_ip = wireless.GetWirelessIP() 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 ip returns as None, we are probably returning from hibernation and need to force signal to 0 to avoid crashing
if wireless_ip != None: if wireless_ip != None:
@@ -202,7 +204,7 @@ manager.insert_action_group(ag, 0)
manager.add_ui_from_string(menu) manager.add_ui_from_string(menu)
menu = manager.get_widget('/Menubar/Menu/About').props.parent 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") tooltip.set_tip(eb, "Wicd Systray")
pic.set_from_file("images/no-signal.png") pic.set_from_file("images/no-signal.png")

12
edgy.py
View File

@@ -90,11 +90,12 @@ def set_signal_image():
if not daemon.GetDebugMode(): if not daemon.GetDebugMode():
config.DisableLogging() 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: if daemon.GetNeedWiredProfileChooser() == True:
wired_profile_chooser() wired_profile_chooser()
daemon.SetNeedWiredProfileChooser(False) daemon.SetNeedWiredProfileChooser(False)
#Check for active wired connection
wired_ip = wired.GetWiredIP() wired_ip = wired.GetWiredIP()
if wired.CheckPluggedIn() == True and wired_ip != None: if wired.CheckPluggedIn() == True and wired_ip != None:
if stillWired == False: # Only set image/tooltip if it hasn't been set already 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)) tr.set_tooltip(language['connected_to_wired'].replace('$A',wired_ip))
stillWired = True stillWired = True
lock = '' lock = ''
#Check if using wireless/not-connected
else: else:
if stillWired == True: #this only occurs when we were previously using wired but it became unplugged 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_from_file("images/no-signal.png")
tr.set_tooltip(language['not_connected']) tr.set_tooltip(language['not_connected'])
stillWired = False stillWired = False
wireless_ip = wireless.GetWirelessIP() 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 ip returns as None, we are probably returning from hibernation and need to force signal to 0 to avoid crashing
if wireless_ip != None: 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: if (signal != LastStrength or network != wireless.GetCurrentNetwork() or signal == 0) and wireless_ip != None:
LastStrength = signal LastStrength = signal
lock = '' #set the string to '' so that when it is put in "high-signal" + lock + ".png", there will be nothing 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"): 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 lock = '-lock' #set the string to '-lock' so that it will display the lock picture
network = str(wireless.GetCurrentNetwork()) network = str(wireless.GetCurrentNetwork())
@@ -199,6 +202,8 @@ class TrackerStatusIcon(gtk.StatusIcon):
self.set_visible(True) self.set_visible(True)
self.connect('activate', self.on_activate) self.connect('activate', self.on_activate)
self.connect('popup-menu', self.on_popup_menu) self.connect('popup-menu', self.on_popup_menu)
self.set_from_file("images/no-signal.png")
self.set_tooltip("Initializing wicd...")
wireless.SetForcedDisconnect(False) wireless.SetForcedDisconnect(False)
@@ -217,7 +222,7 @@ class TrackerStatusIcon(gtk.StatusIcon):
def on_about(self, data): def on_about(self, data):
dialog = gtk.AboutDialog() dialog = gtk.AboutDialog()
dialog.set_name('wicd tray icon') 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_comments('an icon that shows your network connectivity')
dialog.set_website('http://wicd.sourceforge.net') dialog.set_website('http://wicd.sourceforge.net')
dialog.run() dialog.run()
@@ -231,7 +236,6 @@ class TrackerStatusIcon(gtk.StatusIcon):
LastStrength = -2 LastStrength = -2
stillWired = False stillWired = False
network = '' network = ''
tr=None
tr=TrackerStatusIcon() tr=TrackerStatusIcon()
gobject.timeout_add(3000,set_signal_image) gobject.timeout_add(3000,set_signal_image)

View File

@@ -31,8 +31,8 @@ def IsValidIP(ip):
return False return False
def PromptToStartDaemon(): def PromptToStartDaemon():
gksudo_args = ['gksudo', '--message', 'Wicd needs to access your computer\'s network cards.','--','./daemon.py'] #script execution doesn't work correctly if daemon gets autostarted, so just prompt user to start manually
os.spawnvpe(os.P_NOWAIT, 'gksudo', gksudo_args, os.environ) 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): def RunRegex(regex,string):
m = regex.search( string ) m = regex.search( string )

View File

@@ -44,6 +44,7 @@ class Wireless:
channel_pattern = re.compile('.*Channel:? ?(\d\d?)',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) 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) 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) 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) 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["hidden"] = False
CurrentNetwork["channel"] = misc.RunRegex(channel_pattern,cell) 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) CurrentNetwork["bssid"] = misc.RunRegex(ap_mac_pattern,cell)
print " ##### " + CurrentNetwork["bssid"] print " ##### " + CurrentNetwork["bssid"]
CurrentNetwork["mode"] = misc.RunRegex(mode_pattern,cell) CurrentNetwork["mode"] = misc.RunRegex(mode_pattern,cell)
@@ -149,6 +175,7 @@ class Wireless:
else: else:
print 'Unknown AuthMode, can\'t assign encryption_method!!' print 'Unknown AuthMode, can\'t assign encryption_method!!'
CurrentNetwork["encryption_method"] = 'Unknown' CurrentNetwork["encryption_method"] = 'Unknown'
CurrentNetwork["quality"] = info[1][1:] #set signal strength here (not link quality! dBm vs %) CurrentNetwork["quality"] = info[1][1:] #set signal strength here (not link quality! dBm vs %)
else: else:
CurrentNetwork["encryption"] = False CurrentNetwork["encryption"] = False
@@ -258,15 +285,10 @@ class Wireless:
self.IsConnecting = True self.IsConnecting = True
network = self.network network = self.network
self.lock.acquire()
self.ConnectingMessage = 'executing_before_script'
self.lock.release()
before_script = self.before_script if self.before_script != '' and self.before_script != None:
print 'before script is ', before_script
if before_script != '' and before_script != None:
print 'Executing pre-connection script' print 'Executing pre-connection script'
misc.Run(before_script) print misc.Run('./run-script.py ' + self.before_script)
#put it down #put it down
print "interface down..." print "interface down..."
@@ -339,7 +361,7 @@ class Wireless:
else: else:
misc.Run("iwconfig " + self.wireless_interface + " mode " + network["mode"]) 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 self.wpa_driver == "ralink legacy": #Adds support for ralink cards that can't use wpasupplicant
if network.get('key') != None: if network.get('key') != None:
@@ -474,10 +496,9 @@ class Wireless:
print "done" print "done"
self.IsConnecting = False self.IsConnecting = False
after_script = self.after_script if self.after_script != '' and self.after_script != None:
if after_script != '' and after_script != None:
print 'executing post connection script' print 'executing post connection script'
misc.Run(after_script) print misc.Run('./run-script.py ' + self.after_script)
#end function Connect #end function Connect
#end class Connect #end class Connect
@@ -613,16 +634,13 @@ class Wired:
#we don't touch the wifi interface #we don't touch the wifi interface
#but we do remove all wifi entries from the #but we do remove all wifi entries from the
#routing table #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 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 #put it down
self.lock.acquire() self.lock.acquire()
self.ConnectingMessage = 'interface_down' self.ConnectingMessage = 'interface_down'
@@ -703,8 +721,7 @@ class Wired:
self.lock.release() self.lock.release()
self.IsConnecting = False self.IsConnecting = False
after_script = self.after_script if self.after_script != '' and self.after_script != None:
if after_script != '' and after_script != None:
print 'executing post connection script' print 'executing post connection script'
misc.Run(after_script) misc.Run('./run-script.py ' + self.after_script)
#end function run #end function run

13
run-script.py Executable file
View File

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