diff --git a/daemon.py b/daemon.py index 6830db0..85a8993 100644 --- a/daemon.py +++ b/daemon.py @@ -252,6 +252,23 @@ class ConnectionWizard(dbus.service.Object): return str(self.wifi.wireless_interface) #end function GetWirelessInterface +<<<<<<< .mine + @dbus.service.method('org.wicd.daemon') + def SetDebugMode(self,debug): + '''sets if debugging mode is on or off''' + config = ConfigParser.ConfigParser() + config.read(self.app_conf) + config.set("Settings","debug_mode",debug) + configfile = open(self.app_conf,"w") + config.write(configfile) + self.debug_mode = debug + + @dbus.service.method('org.wicd.daemon') + def GetDebugMode(self): + '''returns whether debugging is enabled''' + return bool(int(self.debug_mode)) + +======= @dbus.service.method('org.wicd.daemon') def GetGlobalDNSAddresses(self): '''returns the global dns addresses''' @@ -259,6 +276,7 @@ class ConnectionWizard(dbus.service.Object): return (self.dns1,self.dns2,self.dns3) #end function GetWirelessInterface +>>>>>>> .r63 ########## WIRELESS FUNCTIONS ################################# @@ -284,6 +302,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wireless') def DisconnectWireless(self): + '''disconnects all wireless networks''' self.SetForcedDisconnect(True) self.wifi.Disconnect() #end function DisconnectWireless @@ -307,28 +326,21 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wireless') def CreateAdHocNetwork(self,essid,channel,ip,enctype,key,encused,ics): + '''creates an ad-hoc network using user inputted settings''' print 'attempting to create ad-hoc network...' self.wifi.CreateAdHocNetwork(essid,channel,ip,enctype,key,encused,ics) #end function CreateAdHocNetwork - @dbus.service.method('org.wicd.daemon.wireless') - def GetHideDupeAPs(self): - return self.hide_dupe_aps - #end function GetHideDupeAPs - - @dbus.service.method('org.wicd.daemon.wireless') - def SetHideDupeAPs(self,value): - self.hide_dupe_aps = value - #end function SetHideDupeAPs - @dbus.service.method('org.wicd.daemon.wireless') def GetAutoReconnect(self): + '''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 @dbus.service.method('org.wicd.daemon.wireless') def SetAutoReconnect(self,value): + '''sets if wicd should try to reconnect with connection drops''' print 'setting automatically reconnect when connection drops' config = ConfigParser.ConfigParser() config.read(self.app_conf) @@ -339,7 +351,21 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wireless') def AutoConnect(self,fresh): - '''autoconnects to a wireless network''' + '''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() @@ -350,7 +376,7 @@ class ConnectionWizard(dbus.service.Object): if bool(self.LastScan[x].get('automatic')): print 'automatically connecting to...',str(self.LastScan[x]["essid"]) self.ConnectWireless(x) - time.sleep(1) + time.sleep(3) while self.CheckIfWirelessConnecting(): print "autoconnecting... hold" #not sure why I need to get IPs, but @@ -370,26 +396,10 @@ class ConnectionWizard(dbus.service.Object): # think? -- adam ### #self.GetWiredIP() - time.sleep(1) + time.sleep(2) print "autoconnecting... done" return - print "unable to find a network to autoconnect to, checking for a wired connection" - if 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 - #I didn't include a self.GetWired/WirelessIP call and it seems - #to work for me...could it cause problems? - Dan - time.sleep(1) - print "...done autoconnecting." - else: - print "couldn't find a default wired connection, couldn't autoconnect" - else: - print "no wired connection present, couldn't autoconnect." + print "unable to autoconnect, you'll have to manually connect" else: print 'autoconnect failed because wireless interface == None' #end function AutoConnect @@ -624,7 +634,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def DisableLogging(self): global logging_enabled - logging_enabled = False + logging_enabled = False @dbus.service.method('org.wicd.daemon.config') def EnableLogging(self): @@ -843,10 +853,18 @@ class ConnectionWizard(dbus.service.Object): else: config.set("Settings","auto_reconnect","False") self.auto_reconnect = False +<<<<<<< .mine + 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") +======= if config.has_option('Settings','dns1') and config.has_option('Settings','dns2') and config.has_option('Settings','dns3'): self.SetGlobalDNS(config.get('Settings','dns1'),config.get('Settings','dns2'),config.get('Settings','dns3')) else: self.SetGlobalDNS("None","None","None") +>>>>>>> .r63 else: print "configuration file exists, no settings found, adding defaults..." configfile = open(self.app_conf,"w") @@ -856,6 +874,15 @@ class ConnectionWizard(dbus.service.Object): config.set("Settings","wpa_driver","wext") config.set("Settings","always_show_wired_interface","False") config.set("Settings","auto_reconnect","False") +<<<<<<< .mine + config.set("Settings","debug_mode","False") + self.SetWirelessInterface("wlan0") + self.SetWiredInterface("eth0") + self.SetWPADriver("wext") + self.SetAlwaysShowWiredInterface(False) + self.SetAutoReconnect(True) + self.SetDebugMode(False) +======= config.set("Settings","use_global_dns","False") config.set("Settings","dns1","None") config.set("Settings","dns2","None") @@ -864,6 +891,7 @@ 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")) +>>>>>>> .r63 config.write(configfile) else: @@ -876,9 +904,13 @@ class ConnectionWizard(dbus.service.Object): config.set("Settings","wired_interface","eth0") config.set("Settings","always_show_wired_interface","False") config.set("Settings","auto_reconnect","False") +<<<<<<< .mine + config.set("Settings","debug_mode","False") +======= config.set("Settings","dns1","None") config.set("Settings","dns2","None") config.set("Settings","dns3","None") +>>>>>>> .r63 iface = self.DetectWirelessInterface() if iface: config.set("Settings","wireless_interface",iface) @@ -892,7 +924,11 @@ class ConnectionWizard(dbus.service.Object): self.SetWPADriver(config.get("Settings","wpa_driver")) self.SetAlwaysShowWiredInterface(False) self.SetAutoReconnect(True) +<<<<<<< .mine + self.SetDebugMode(False) +======= self.SetGlobalDNS(None,None,None) +>>>>>>> .r63 #end If if os.path.isfile( self.wireless_conf ): @@ -933,12 +969,13 @@ class ConnectionWizard(dbus.service.Object): ## fork from the parent terminal -if not True: #for easy disabling +if True: #for easy disabling try: pid = os.fork() if pid > 0: # exit first parent sys.exit(0) + except OSError, e: print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) @@ -960,8 +997,8 @@ if not True: #for easy disabling #kill output #POI:500 stdout redirection output = FlushWriter() -#sys.stdout = output #open("data/wicd.log","w") -#sys.stderr = output +sys.stdout = output #open("data/wicd.log","w") +sys.stderr = output print "---------------------------" print "wicd initalizing..." diff --git a/edgy.py b/edgy.py index 315263e..7bc44bc 100755 --- a/edgy.py +++ b/edgy.py @@ -40,7 +40,7 @@ except: proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') except: print 'daemon still not running, aborting.' -#daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') +daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') # Had to uncomment it 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') @@ -78,71 +78,76 @@ def open_wicd_gui(): lastWinId = os.spawnlpe(os.P_NOWAIT, './gui.py', os.environ) def set_signal_image(): - global LastStrength - global stillWired #keeps us from resetting the wired info over and over (I think?) - global network #declared as global so it is initialized once before it gets used in the if statement below - - config.DisableLogging() - - wired_ip = wired.GetWiredIP() - if wired.CheckPluggedIn() == True and wired_ip: - if stillWired == False: - tr.set_from_file("images/wired.png") - tr.set_tooltip(language['connected_to_wired'].replace('$A',wired_ip)) - stillWired = True - lock = '' - else: - 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: - signal = int(wireless.GetCurrentSignalStrength()) - else: - signal = 0 - - #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: - 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 - 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 + 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 - network = str(wireless.GetCurrentNetwork()) - tr.set_tooltip(language['connected_to_wireless'].replace('$A',network).replace('$B',str(signal)).replace('$C',str(wireless_ip))) - if signal > 75: - tr.set_from_file("images/high-signal" + lock + ".png") - elif signal > 50: - tr.set_from_file("images/good-signal" + lock + ".png") - elif signal > 25: - tr.set_from_file("images/low-signal" + lock + ".png") - elif signal > 0: - tr.set_from_file("images/bad-signal" + lock + ".png") - elif signal == 0: - tr.set_from_file("images/no-signal.png") - elif wireless_ip == None: - tr.set_from_file("images/no-signal.png") - tr.set_tooltip(language['not_connected']) - #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. It will continuously rescan until a network is found or the user manually reconnects - #This behavior could prove to be annoying, so we'll keep it in the experimental build for now - if wireless.GetAutoReconnect() == True and wireless.CheckIfWirelessConnecting() == False and wireless.GetForcedDisconnect() == False: - curNetID = wireless.GetCurrentNetworkID() - if curNetID > -1: - wireless.ConnectWireless(wireless.GetCurrentNetworkID()) - 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) - else: - print "Scanning for an autoconnect network..." - print wireless.AutoConnect(True) - config.EnableLogging() - return True + # Disable logging if debugging isn't on to prevent log spam + if not daemon.GetDebugMode(): + config.DisableLogging() + + wired_ip = wired.GetWiredIP() + if wired.CheckPluggedIn() == True and wired_ip: + if stillWired == False: # Only set image/tooltip if it hasn't been set already + tr.set_from_file("images/wired.png") + tr.set_tooltip(language['connected_to_wired'].replace('$A',wired_ip)) + stillWired = True + lock = '' + else: + 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: + signal = int(wireless.GetCurrentSignalStrength()) + else: + signal = 0 + + #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: + 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 + 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()) + tr.set_tooltip(language['connected_to_wireless'].replace('$A',network).replace('$B',str(signal)).replace('$C',str(wireless_ip))) + if signal > 75: + tr.set_from_file("images/high-signal" + lock + ".png") + elif signal > 50: + tr.set_from_file("images/good-signal" + lock + ".png") + elif signal > 25: + tr.set_from_file("images/low-signal" + lock + ".png") + elif signal > 0: + tr.set_from_file("images/bad-signal" + lock + ".png") + elif signal == 0: + tr.set_from_file("images/no-signal.png") + elif wireless_ip == None: + tr.set_from_file("images/no-signal.png") + tr.set_tooltip(language['not_connected']) + #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. It will continuously rescan until a network is found or the user manually reconnects + #This behavior could prove to be annoying, so we'll keep it in the experimental build for now + if wireless.GetAutoReconnect() == True and wireless.CheckIfWirelessConnecting() == False and wireless.GetForcedDisconnect() == False: + curNetID = wireless.GetCurrentNetworkID() + if curNetID > -1: #value of -1 is typically caused by hibernation and breaks the tray if passed to daemon + wireless.ConnectWireless(wireless.GetCurrentNetworkID()) + 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) + else: + print "Scanning for an autoconnect network..." + print wireless.AutoConnect(True) + + if not daemon.GetDebugMode(): + config.EnableLogging() + + return True class TrackerStatusIcon(gtk.StatusIcon): def __init__(self): @@ -172,7 +177,7 @@ class TrackerStatusIcon(gtk.StatusIcon): self.manager.insert_action_group(ag, 0) self.manager.add_ui_from_string(menu) self.menu = self.manager.get_widget('/Menubar/Menu/About').props.parent - self.current_icon_path = '' + self.current_icon_path = '' self.set_from_file("images/no-signal.png") self.set_visible(True) self.connect('activate', self.on_activate) @@ -200,9 +205,9 @@ class TrackerStatusIcon(gtk.StatusIcon): dialog.destroy() def set_from_file(self,path): - if path != self.current_icon_path: - self.current_icon_path = path - gtk.StatusIcon.set_from_file(self,path) + if path != self.current_icon_path: + self.current_icon_path = path + gtk.StatusIcon.set_from_file(self,path) LastStrength = -2 stillWired = False diff --git a/gui.py b/gui.py index 44a7626..ba5e8bd 100644 --- a/gui.py +++ b/gui.py @@ -129,7 +129,11 @@ language['after_script'] = _('Run script after connect') language['script_settings'] = _('Scripts') language['use_ics'] = _('Activate Internet Connection Sharing') language['default_wired'] = _('Use as default profile (overwrites any previous default)') +<<<<<<< .mine +language['use_debug_mode'] = _('Enable debug mode') +======= language['use_global_dns'] = _('Use global DNS servers') +>>>>>>> .r63 language['0'] = _('0') language['1'] = _('1') @@ -145,6 +149,7 @@ language['9'] = _('9') language['interface_down'] = _('Putting interface down...') language['resetting_ip_address'] = _('Resetting IP address...') language['interface_up'] = _('Putting interface up...') +language['setting_encryption_info'] = _('Setting encryption info') language['removing_old_connection'] = _('Removing old connection...') language['generating_psk'] = _('Generating PSK...') language['generating_wpa_config'] = _('Generating WPA configuration file...') @@ -838,10 +843,12 @@ class appGui: 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()) wpadriverlabel = SmallLabel(language['wpa_supplicant_driver'] + ':') wpadrivercombo = gtk.combo_box_new_text() wpadrivercombo.set_size_request(50,-1) - wpadrivers = [ "hostap","hermes","madwifi","atmel","wext","ndiswrapper","broadcom","ipw" ] + wpadrivers = [ "hostap","hermes","madwifi","atmel","wext","ndiswrapper","broadcom","ipw","ralink legacy" ] i = 0 found = False for x in wpadrivers: @@ -892,6 +899,7 @@ class appGui: dialog.vbox.pack_start(wiredcheckbox) dialog.vbox.pack_start(reconnectcheckbox) + dialog.vbox.pack_start(debugmodecheckbox) dialog.vbox.set_spacing(5) dialog.show_all() response = dialog.run() @@ -904,8 +912,7 @@ class appGui: daemon.SetWPADriver(wpadrivers[wpadrivercombo.get_active()]) wired.SetAlwaysShowWiredInterface(wiredcheckbox.get_active()) wireless.SetAutoReconnect(reconnectcheckbox.get_active()) - print wiredcheckbox.get_active() - print reconnectcheckbox.get_active() + daemon.SetDebugMode(debugmodecheckbox.get_active()) dialog.destroy() else: dialog.destroy() @@ -944,9 +951,10 @@ class appGui: def update_statusbar(self): #should update the status bar #every couple hundred milliseconds - config.DisableLogging() #stop log file spam + if not daemon.GetDebugMode(): + config.DisableLogging() #stop log file spam wireless_ip = wireless.GetWirelessIP() #do this so that it doesn't lock up. don't know how or why this works - #but it does so we leave it alone :) + #but it does so we leave it alone :) wiredConnecting = wired.CheckIfWiredConnecting() wirelessConnecting = wireless.CheckIfWirelessConnecting() if wirelessConnecting == True or wiredConnecting == True: @@ -974,16 +982,19 @@ class appGui: strength = str(strength) ip = str(wireless_ip) self.statusID=self.status_bar.push(1,language['connected_to_wireless'].replace('$A',network).replace('$B',strength).replace('$C',wireless_ip)) - config.EnableLogging() #reenable logging + if not daemon.GetDebugMode(): + config.EnableLogging() return True wired_ip = wired.GetWiredIP() if wired_ip: if wired.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn(): self.statusID = self.status_bar.push(1,language['connected_to_wired'].replace('$A',wired_ip)) - config.EnableLogging() #reenable logging + if not daemon.GetDebugMode(): + config.EnableLogging() return True self.statusID = self.status_bar.push(1,language['not_connected']) - config.EnableLogging() #reenable logging + if not daemon.GetDebugMode(): + config.EnableLogging() return True def refresh_networks(self,widget=None,fresh=True,hidden=None): diff --git a/networking.py b/networking.py index 328b3f6..b610d66 100644 --- a/networking.py +++ b/networking.py @@ -31,7 +31,6 @@ class Wireless: #Create a function to scan for wireless networks def Scan(self,essid=None): - #we ask for an essid, because then we can see hidden networks ##### @@ -116,30 +115,51 @@ class Wireless: CurrentNetwork["bssid"] = misc.RunRegex(ap_mac_pattern,cell) print " ##### " + CurrentNetwork["bssid"] CurrentNetwork["mode"] = misc.RunRegex(mode_pattern,cell) - + #since encryption needs a True or False #we have to do a simple if then to set it if misc.RunRegex(wep_pattern,cell) == "on": - CurrentNetwork["encryption"] = True - #set this, because if it is something else this will be overwritten - CurrentNetwork["encryption_method"] = "WEP" + if self.wpa_driver != 'ralink legacy': + CurrentNetwork["encryption"] = True + #set this, because if it is something else this will be overwritten + CurrentNetwork["encryption_method"] = "WEP" - if misc.RunRegex(wpa1_pattern,cell) == "WPA Version 1": - CurrentNetwork["encryption_method"] = "WPA" + if misc.RunRegex(wpa1_pattern,cell) == "WPA Version 1": + CurrentNetwork["encryption_method"] = "WPA" - if misc.RunRegex(wpa2_pattern,cell) == "WPA2": - CurrentNetwork["encryption_method"] = "WPA2" + if misc.RunRegex(wpa2_pattern,cell) == "WPA2": + CurrentNetwork["encryption_method"] = "WPA2" + + else: #support for ralink legacy drivers, may not work w/ hidden networks + iwpriv = misc.Run("iwpriv " + self.wireless_interface + " get_site_survey") + lines = iwpriv.splitlines() + lines = lines[2:] + for x in lines: + info = x.split() + 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_method"] = 'WEP' + elif info[5] == 'WPA-PSK': + CurrentNetwork["encrytion_method"] = 'WPA' + elif info[5] == 'WPA2-PSK': + CurrentNetwork["encryption_method"] = 'WPA2' + else: + print 'Unknown AuthMode, can\'t assign encryption_method!!' + CurrentNetwork["encryption_method"] = 'Unknown' + CurrentNetwork["quality"] = info[1][1:] #set link strength here else: CurrentNetwork["encryption"] = False #end If - #since stength needs a -1 if the quality isn't found - #we need a simple if then to set it - if misc.RunRegex(strength_pattern,cell): - CurrentNetwork["quality"] = misc.RunRegex(strength_pattern,cell) - else: - CurrentNetwork["quality"] = -1 - #end If + if self.wpa_driver != 'ralink legacy': + #since stength needs a -1 if the quality isn't found + #we need a simple if then to set it + if misc.RunRegex(strength_pattern,cell): + CurrentNetwork["quality"] = misc.RunRegex(strength_pattern,cell) + else: + CurrentNetwork["quality"] = -1 #add this network to the list of networks aps[ i ] = CurrentNetwork @@ -210,6 +230,7 @@ class Wireless: self.IsConnecting = False self.before_script = before_script self.after_script = after_script + self.lock.acquire() self.ConnectingMessage = 'interface_down' self.lock.release() @@ -259,14 +280,6 @@ class Wireless: misc.Run("ifconfig " + self.wired_interface + " 0.0.0.0") misc.Run("ifconfig " + self.wireless_interface + " 0.0.0.0") - #bring it up - print "interface up..." - self.lock.acquire() - self.ConnectingMessage = 'interface_up' - self.lock.release() - - print misc.Run("ifconfig " + self.wireless_interface + " up") - print "killing wpa_supplicant, dhclient, dhclient3" self.lock.acquire() self.ConnectingMessage = 'removing_old_connection' @@ -275,29 +288,28 @@ class Wireless: misc.Run("killall dhclient dhclient3 wpa_supplicant") #check to see if we need to generate a PSK + if self.wpa_driver != "ralink legacy": # Enhanced Ralink legacy drivers are handled later + if not network.get('key')== None: + self.lock.acquire() + self.ConnectingMessage = 'generating_psk' + self.lock.release() - if not network.get('key')== None: - self.lock.acquire() - self.ConnectingMessage = 'generating_psk' - self.lock.release() + print "generating psk..." + key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',re.DOTALL | re.I | re.M | re.S) + network["psk"] = misc.RunRegex(key_pattern,misc.Run('wpa_passphrase "' + network["essid"] + '" "' + network["key"] + '"')) + #generate the wpa_supplicant file... + if not network.get('enctype') == None: + self.lock.acquire() + self.ConnectingMessage = 'generating_wpa_config' + self.lock.release() - print "generating psk..." - key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',re.DOTALL | re.I | re.M | re.S) - network["psk"] = misc.RunRegex(key_pattern,misc.Run('wpa_passphrase "' + network["essid"] + '" "' + network["key"] + '"')) - #generate the wpa_supplicant file... - if not network.get('enctype') == None: - self.lock.acquire() - self.ConnectingMessage = 'generating_wpa_config' - self.lock.release() - - print "generating wpa_supplicant configuration file..." - misc.ParseEncryption(network) - print "wpa_supplicant -B -i " + self.wireless_interface + " -c \"encryption/configurations/" + network["bssid"].replace(":","").lower() + "\" -D " + self.wpa_driver - misc.Run("wpa_supplicant -B -i " + self.wireless_interface + " -c \"encryption/configurations/" + network["bssid"].replace(":","").lower() + "\" -D " + self.wpa_driver) + print "generating wpa_supplicant configuration file..." + misc.ParseEncryption(network) + print "wpa_supplicant -B -i " + self.wireless_interface + " -c \"encryption/configurations/" + network["bssid"].replace(":","").lower() + "\" -D " + self.wpa_driver + misc.Run("wpa_supplicant -B -i " + self.wireless_interface + " -c \"encryption/configurations/" + network["bssid"].replace(":","").lower() + "\" -D " + self.wpa_driver) print "flushing the routing table..." self.lock.acquire() - self.ConnectingMessage = 'flushing_routing_table' self.lock.release() @@ -306,10 +318,17 @@ class Wireless: print "configuring the wireless interface..." self.lock.acquire() - self.ConnectingMessage = 'configuring_interface' self.lock.release() + #bring it up + print "interface up..." + self.lock.acquire() + self.ConnectingMessage = 'interface_up' + self.lock.release() + + print misc.Run("ifconfig " + self.wireless_interface + " up") + if network["mode"].lower() == "master": misc.Run("iwconfig " + self.wireless_interface + " mode managed") else: @@ -317,9 +336,46 @@ class Wireless: 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: + self.lock.acquire() + self.ConnectingMessage = 'setting_encryption_info' + self.lock.release() + + print 'setting up ralink encryption' + iwpriv = misc.Run("iwpriv " + self.wireless_interface + " get_site_survey") + lines = iwpriv.splitlines() + lines = lines[2:] + for x in lines: + info = x.split() + 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 + print 'setting up WEP' + misc.Run("iwconfig " + self.wireless_interface + " key " + network.get('key')) + elif info[5] == 'WPA-PSK': + print 'setting up WPA-PSK' + misc.Run("iwpriv " + self.wireless_interface + " set NetworkType=" + info[6]) + misc.Run("iwpriv " + self.wireless_interface + " set AuthMode=WPAPSK") + misc.Run("iwpriv " + self.wireless_interface + " set EncrypType=" + info[4]) + misc.Run("iwpriv " + self.wireless_interface + " set SSID=" + info[2]) + misc.Run("iwpriv " + self.wireless_interface + " set WPAPSK=" + network.get('key')) + misc.Run("iwpriv " + self.wireless_interface + " set SSID=" + info[2]) + elif info[5] == 'WPA2-PSK': + print 'setting up WPA2-PSK' + misc.Run("iwpriv " + self.wireless_interface + " set NetworkType=" + info[6]) + misc.Run("iwpriv " + self.wireless_interface + " set AuthMode=WPA2PSK") + misc.Run("iwpriv " + self.wireless_interface + " set EncrypType=" + info[4]) + misc.Run("iwpriv " + self.wireless_interface + " set SSID=" + info[2]) + misc.Run("iwpriv " + self.wireless_interface + " set WPAPSK=" + network.get('key')) + misc.Run("iwpriv " + self.wireless_interface + " set SSID=" + info[2]) + else: + print 'Unknown AuthMode, can\'t complete connection process!!!' + print "done setting encryption info" + if not network.get('broadcast') == None: self.lock.acquire() - self.ConnectingMessage = 'setting_broadcast_address' self.lock.release() @@ -327,6 +383,22 @@ class Wireless: misc.Run("ifconfig " + self.wireless_interface + " broadcast " + network["broadcast"]) +<<<<<<< .mine + 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 network.get('static_dns') == True and network.get('global_dns') == False: if not network.get("dns1") == None: self.lock.acquire() @@ -355,10 +427,10 @@ class Wireless: if not self.global_dns_3 == None: print "setting the third dns server..." misc.WriteLine(resolv,"nameserver " + self.global_dns_3) +>>>>>>> .r63 if not network.get('ip') == None: self.lock.acquire() - self.ConnectingMessage = 'setting_static_ip' self.lock.release() @@ -370,7 +442,6 @@ class Wireless: else: #run dhcp... self.lock.acquire() - self.ConnectingMessage = 'running_dhcp' self.lock.release() @@ -619,4 +690,3 @@ class Wired: print 'executing post connection script' misc.Run(after_script) #end function run -