diff --git a/data/wicd.glade b/data/wicd.glade index 00233b9..40d2ca3 100644 --- a/data/wicd.glade +++ b/data/wicd.glade @@ -1,6 +1,6 @@ - + 450 @@ -9,7 +9,6 @@ Wicd Manager GTK_WIN_POS_CENTER 550 - wicd.png GDK_GRAVITY_CENTER @@ -23,12 +22,131 @@ GTK_ICON_SIZE_MENU True - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK True - gtk-network - menu1 + + + True + + + True + gtk-network + True + True + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + network_menu + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Create Ad-Hoc Network + True + + + + True + gtk-add + 1 + + + + + + + True + Enable/Disable Interfaces + True + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + Enable Wired Interface + True + + + + True + gtk-yes + + + + + + + True + Enable Wireless Interface + True + + + + True + gtk-yes + + + + + + + True + Disable Wired Interface + True + + + + True + gtk-stop + + + + + + + True + Disable Wireless Interface + True + + + + True + gtk-stop + + + + + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Hidden Network + True + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + network-wireless + + + + + + + + + + @@ -36,6 +154,8 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK True + _Disconnect All + True gtk-disconnect @@ -47,6 +167,8 @@ True True + _Refresh + True gtk-refresh @@ -58,6 +180,8 @@ True True + _Preferences + True gtk-preferences @@ -69,6 +193,8 @@ True True + _About + True gtk-about @@ -81,6 +207,8 @@ True GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK True + _Quit + True gtk-quit @@ -179,111 +307,6 @@ - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Hidden Network - True - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - network-wireless - - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Create Ad-Hoc Network - True - - - - True - gtk-add - 1 - - - - - - - True - Enable/Disable Interfaces - True - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - True - Enable Wired Interface - True - - - - True - gtk-yes - - - - - - - True - Enable Wireless Interface - True - - - - True - gtk-yes - - - - - - - True - Disable Wired Interface - True - - - - True - gtk-stop - - - - - - - True - Disable Wireless Interface - True - - - - True - gtk-stop - - - - - - - - - 416 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/wicd/backends/be-external.py b/wicd/backends/be-external.py index 0134fca..73a9bd2 100644 --- a/wicd/backends/be-external.py +++ b/wicd/backends/be-external.py @@ -35,6 +35,8 @@ import wicd.misc as misc import wicd.wnettools as wnettools import re +import os +import os.path import time @@ -51,7 +53,7 @@ more stable for some set ups. # Compile the regex patterns that will be used to search the output of iwlist # scan for info these are well tested, should work on most cards -essid_pattern = re.compile('.*ESSID:"(.*?)"\n', re.I | re.M | re.S) +essid_pattern = re.compile('.*ESSID:(.*?)\n', re.I | re.M | re.S) ap_mac_pattern = re.compile('.*Address: (.*?)\n', re.I | re.M | re.S) channel_pattern = re.compile('.*Channel:? ?(\d\d?)', re.I | re.M | re.S) strength_pattern = re.compile('.*Quality:?=? ?(\d+)\s*/?\s*(\d*)', re.I | re.M | re.S) @@ -131,11 +133,23 @@ class Interface(wnettools.BaseInterface): def IsUp(self, ifconfig=None): """ Determines if the interface is up. - + Returns: True if the interface is up, False otherwise. - + """ + if not self.iface: return False + flags_file = '/sys/class/net/%s/flags' % self.iface + try: + flags = open(flags_file, "r").read().strip() + except IOError: + print "Could not open %s, using ifconfig to determine status" % flags_file + return self._slow_is_up(ifconfig) + return bool(int(flags, 16) & 1) + + + def _slow_is_up(self, ifconfig=None): + """ Determine if an interface is up using ifconfig. """ if not ifconfig: cmd = "ifconfig " + self.iface if self.verbose: print cmd @@ -145,11 +159,9 @@ class Interface(wnettools.BaseInterface): lines = output.split('\n') if len(lines) < 5: return False - for line in lines[1:4]: if line.strip().startswith('UP'): - return True - + return True return False @@ -168,24 +180,49 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface): def GetPluggedIn(self): """ Get the current physical connection state. - + The method will first attempt to use ethtool do determine physical connection state. Should ethtool fail to run properly, mii-tool will be used instead. - + Returns: True if a link is detected, False otherwise. - + """ if not self.iface: return False + # check for link using /sys/class/net/iface/carrier + # is usually more accurate + sys_device = '/sys/class/net/%s/' % self.iface + carrier_path = sys_device + 'carrier' + if not self.IsUp(): + MAX_TRIES = 3 + tries = 0 + self.Up() + while True: + tries += 1 + time.sleep(2) + if self.IsUp() or tries > MAX_TRIES: break + + if os.path.exists(carrier_path): + carrier = open(carrier_path, 'r') + try: + link = carrier.read().strip() + link = int(link) + if link == 1: + return True + elif link == 0: + return False + except (IOError, ValueError, TypeError): + print 'Error checking link using /sys/class/net/%s/carrier' % self.iface + if self.ETHTOOL_FOUND and self.link_detect != misc.MIITOOL: return self._eth_get_plugged_in() elif self.MIITOOL_FOUND: return self._mii_get_plugged_in() else: - print 'Error: No way of checking for a wired connection. Make \ - sure that either mii-tool or ethtool is installed.' + print 'Error: No way of checking for a wired connection. Make ' + \ + 'sure that either mii-tool or ethtool is installed.' return False def _eth_get_plugged_in(self): @@ -254,7 +291,6 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): cmd = 'iwlist ' + self.iface + ' scan' if self.verbose: print cmd results = misc.Run(cmd) - # Split the networks apart, using Cell as our split point # this way we can look at only one network at a time. # The spaces around ' Cell ' are to minimize the chance that someone @@ -293,17 +329,17 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): """ ap = {} - # ESSID - Switch '' to 'Hidden' to remove - # brackets that can mix up formatting. ap['essid'] = misc.RunRegex(essid_pattern, cell) + if ap['essid']: + ap['essid'] = ap['essid'].strip('"') try: ap['essid'] = misc.to_unicode(ap['essid']) except UnicodeDecodeError, UnicodeEncodeError: print 'Unicode problem with current network essid, ignoring!!' return None if ap['essid'] in ['', ""]: - ap['essid'] = 'Hidden' ap['hidden'] = True + ap['essid'] = "" else: ap['hidden'] = False diff --git a/wicd/backends/be-ioctl.py b/wicd/backends/be-ioctl.py index 228067d..bb242b9 100644 --- a/wicd/backends/be-ioctl.py +++ b/wicd/backends/be-ioctl.py @@ -306,7 +306,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): return None if ap['essid'] in [ "", '']: - ap['essid'] = 'Hidden' + ap['essid'] = '' ap['hidden'] = True else: ap['hidden'] = False diff --git a/wicd/gui.py b/wicd/gui.py index fab7f8d..6c4de68 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -258,11 +258,12 @@ class appGui(object): 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") + menu = self.wTree.get_widget("menu1") self.status_area.hide_all() - if os.path.exists(wpath.etc + "wicd.png"): - self.window.set_icon_from_file(wpath.etc + "wicd.png") + if os.path.exists(wpath.images + "wicd.png"): + self.window.set_icon_from_file(wpath.images + "wicd.png") self.statusID = None self.first_dialog_load = True self.is_visible = True @@ -825,7 +826,6 @@ class appGui(object): daemon.WriteWindowSize(width, height, "main") if self.standalone: - self.window.destroy() sys.exit(0) self.is_visible = False diff --git a/wicd/misc.py b/wicd/misc.py index ab3acf4..286ddfc 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -67,9 +67,9 @@ def Run(cmd, include_stderr=False, return_pipe=False): one output string from the command. """ - - cmd = to_unicode(str(cmd)) - cmd = cmd.split() + if type(cmd) is not list: + cmd = to_unicode(str(cmd)) + cmd = cmd.split() if include_stderr: err = STDOUT fds = True diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index 516e79f..10f52a1 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -558,7 +558,7 @@ class TrayIcon(object): self.tray = egg.trayicon.TrayIcon("WicdTrayIcon") self.pic = gtk.Image() self.tooltip.set_tip(self.eb, "Initializing wicd...") - self.pic.set_from_file("images/no-signal.png") + self.pic.set_from_file(wpath.images + "no-signal.png") self.eb.connect('button_press_event', self.tray_clicked) self.eb.add(self.pic) diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index de99c14..4e243e5 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -1025,8 +1025,6 @@ class WirelessDaemon(dbus.service.Object): cur_network = self.LastScan[id] essid_key = "essid:" + cur_network["essid"] bssid_key = cur_network["bssid"] - if self.debug_mode: - print bssid_key if self.config.get(essid_key, 'use_settings_globally'): section = essid_key @@ -1041,8 +1039,9 @@ class WirelessDaemon(dbus.service.Object): # Read the essid because we need to name those hidden # wireless networks now - but only read it if it is hidden. if cur_network["hidden"]: - cur_network["essid"] = misc.Noneify(self.config.get(section, - "essid")) + cur_network["essid"] = config.get(section, x) + if cur_network["essid"] in ["", "Hidden", ""]: + cur_network["essid"] = "" for x in self.config.options(section): if not cur_network.has_key(x) or x.endswith("script"): cur_network[x] = misc.Noneify(self.config.get(section, x)) diff --git a/wicd/wnettools.py b/wicd/wnettools.py index f680205..8414e5f 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -552,7 +552,7 @@ class BaseWirelessInterface(BaseInterface): def SetWpaDriver(self, driver): """ Sets the wpa_driver. """ - self.wpa_driver = _sanitize_string_strict(driver) + self.wpa_driver = _sanitize_string(driver) def SetEssid(self, essid): """ Set the essid of the wireless interface. @@ -561,8 +561,8 @@ class BaseWirelessInterface(BaseInterface): essid -- essid to set the interface to """ - cmd = 'iwconfig %s essid %s' % (self.iface, essid) - if self.verbose: print cmd + cmd = ['iwconfig', self.iface, 'essid', essid] + if self.verbose: print str(cmd) misc.Run(cmd) def StopWPA(self): @@ -623,7 +623,7 @@ class BaseWirelessInterface(BaseInterface): return ret def _GetRalinkInfo(self): - """ Get a network info list used for ralink drivers + """ Get a network info dict used for ralink drivers Calls iwpriv get_site_survey, which on some ralink cards will return encryption and signal @@ -631,49 +631,56 @@ class BaseWirelessInterface(BaseInterface): """ iwpriv = misc.Run('iwpriv ' + self.iface + ' get_site_survey') - lines = iwpriv.splitlines() - lines = lines[2:] - return lines + lines = iwpriv.splitlines()[2:] + aps = {} + patt = re.compile("((?:[0-9A-Z]{2}:){5}[0-9A-Z]{2})") + for x in lines: + ap = {} + info = x.split(" ") + info = filter(None, [x.strip() for x in info]) + if re.match(patt, info[2].upper()): + bssid = info[2].upper() + offset = -1 + elif re.match(patt, info[3].upper()): + bssid = info[3].upper() + offset = 0 + else: # Invalid + print 'Invalid iwpriv line. Skipping it.' + continue + ap['strength'] = info[1] + if info[5 + offset] == 'WEP' or info[4 + offset] == 'WEP': + ap['encryption_method'] = 'WEP' + elif info[5 + offset] in ['WPA-PSK', 'WPA']: + ap['encryption_method'] = 'WPA' + elif info[5 + offset] == 'WPA2-PSK': + ap['encryption_method'] = 'WPA2' + else: + print "Unknown AuthMode, can't assign encryption_method!" + ap['encryption_method'] = 'Unknown' + aps[bssid] = ap + return aps def _ParseRalinkAccessPoint(self, ap, ralink_info, cell): """ Parse encryption and signal strength info for ralink cards Keyword arguments: ap -- array containing info about the current access point - ralink_info -- string containing available network info + ralink_info -- dict containing available network info cell -- string containing cell information Returns: Updated array containing info about the current access point """ - lines = ralink_info wep_pattern = re.compile('.*Encryption key:(.*?)\n', re.I | re.M | re.S) - for x in lines: # Iterate through all networks found - info = x.split() - # Make sure we read in a valid entry - if len(info) < 5 or info == None or info == '': - break - if info[2] == ap['essid']: - if misc.RunRegex(wep_pattern, cell) == 'on': - ap['encryption'] = True - if info[5] == 'WEP' or ( - (info[5] == 'OPEN' or info[5] == 'SHARED') and - info[4] == 'WEP'): - ap['encryption_method'] = 'WEP' - elif info[5] == 'WPA-PSK': - ap['encryption_method'] = 'WPA' - elif info[5] == 'WPA2-PSK': - ap['encryption_method'] = 'WPA2' - else: - print 'Unknown AuthMode, can\'t assign encryption_method!!' - ap['encryption_method'] = 'Unknown' - else: - ap['encryption'] = False - - # Set signal strength here (in dBm, not %), - # ralink drivers don't return link quality - ap['strength'] = info[1] + if ralink_info.has_key(ap['bssid']): + info = ralink_info[ap['bssid']] + for key in info.keys(): + ap[key] = info[key] + if misc.RunRegex(wep_pattern, cell) == 'on': + ap['encryption'] = True + else: + ap['encryption'] = False return ap def SetMode(self, mode): @@ -729,12 +736,12 @@ class BaseWirelessInterface(BaseInterface): """ if not self.iface: return False - cmd = 'iwconfig %s essid "%s"' % (self.iface, essid) + cmd = ['iwconfig', self.iface, 'essid', essid] if channel: - cmd = ''.join([cmd, ' channel ', str(channel)]) + cmd.extend(['channel', str(channel)]) if bssid: - cmd = ''.join([cmd, ' ap ', bssid]) - if self.verbose: print cmd + cmd.extend(['ap', bssid]) + if self.verbose: print str(cmd) misc.Run(cmd) def GeneratePSK(self, network): @@ -841,7 +848,7 @@ class BaseWirelessInterface(BaseInterface): cmd_list.append('SSID=' + info[2]) for cmd in cmd_list: - cmd = 'iwpriv ' + self.iface + ' ' + cmd = 'iwpriv ' + self.iface + ' ' + cmd if self.verbose: print cmd misc.Run(cmd)