1
0
mirror of https://github.com/gryf/wicd.git synced 2026-01-04 21:04:15 +01:00
This commit is contained in:
Dan O'Reilly
2009-03-13 18:55:18 -04:00
8 changed files with 147 additions and 8 deletions

View File

@@ -10,4 +10,4 @@
# pidfile: %PIDFILE%
#
. /lib/lsb/init_functions $1
. /lib/lsb/init-functions $1

View File

@@ -289,7 +289,7 @@ class configure(Command):
item_in.close()
shutil.copymode(original_name, final_name)
class cleargenerated(Command):
class clear_generated(Command):
description = 'clears out files generated by configure'
user_options = []
@@ -346,21 +346,22 @@ class get_translations(Command):
import urllib, shutil
shutil.rmtree('translations/')
os.makedirs('translations')
filename, headers = urllib.urlretrieve('http://wicd.net/translator/get_id_list.php')
filename, headers = urllib.urlretrieve('http://wicd.net/translator/idlist')
id_file = open(filename, 'r')
lines = id_file.readlines()
# remove the \n from the end of lines, and remove blank entries
lines = [ x.strip() for x in lines if not x.strip() is '' ]
for id in lines:
# http://wicd.net/translator/download_po.php?language=11
pofile, poheaders = urllib.urlretrieve('http://wicd.net/translator/download_po.php?language='+str(id))
pofile, poheaders = urllib.urlretrieve('http://wicd.net/translator/download/'+str(id))
#for i in `cat ids`; do
#wget "http://wicd.sourceforge.net/translator/download_po.php?language=$i&version=$1" -O "language_$i"
#iden=`python -c "import sys; print open('language_$i','r').readlines()[1].strip()[2:]"`
#mv "language_$i" po/$iden.po
#mkdir -p $iden/LC_MESSAGES/
#msgfmt --output-file=$iden/LC_MESSAGES/wicd.mo po/$iden.po
lang_identifier = open(pofile,'r').readlines()[1].strip()[2:]
lang_identifier = open(pofile,'r').readlines()[0].strip()
lang_identifier = lang_identifier[lang_identifier.rindex('(')+1:lang_identifier.rindex(')')]
shutil.move(pofile, lang_identifier+'.po')
print 'Got',lang_identifier
os.makedirs('translations/'+lang_identifier+'/LC_MESSAGES')
@@ -486,7 +487,7 @@ iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'],
sources = ['depends/python-iwscan/pyiwscan.c'])
setup(cmdclass={'configure' : configure, 'get_translations' : get_translations,
'uninstall' : uninstall, 'test' : test, 'cleargenerated' : cleargenerated},
'uninstall' : uninstall, 'test' : test, 'clear_generated' : clear_generated},
name="Wicd",
version=VERSION_NUM,
description="A wireless and wired network manager",

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" ioctl Network interface control tools for wicd.
@@ -66,6 +67,7 @@ SIOCGIWESSID = 0x8B1B
SIOCGIWRANGE = 0x8B0B
SIOCGIWAP = 0x8B15
SIOCGIWSTATS = 0x8B0F
SIOCGIWRATE = 0x8B21
# Got these from /usr/include/sockios.h
SIOCGIFADDR = 0x8915
@@ -295,6 +297,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
ap["bssid"] = cell["bssid"]
ap["mode"] = cell["mode"]
ap["bitrates"] = cell["bitrate"]
if cell["enc"]:
ap["encryption"] = True
@@ -479,6 +482,31 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
raw_addr = struct.unpack("xxBBBBBB", result[:8])
return "%02X:%02X:%02X:%02X:%02X:%02X" % raw_addr
def GetCurrentBitrate(self, iwconfig=None):
""" Get the current bitrate for the interface. """
if not self.iface: return ""
data = (self.iface + '\0' * 32)[:32]
fmt = "ihbb"
size = struct.calcsize(fmt)
try:
result = fcntl.ioctl(self.sock.fileno(), SIOCGIWRATE, data)[16:]
except IOError, e:
if self.verbose:
print "SIOCGIWRATE failed: " + str(e)
return ""
f, e, x, x = struct.unpack(fmt, result[:size])
return "%s %s" % ((f / 1000000), 'Mb/s')
#def GetOperationalMode(self, iwconfig=None):
# """ Get the operational mode for the interface. """
# TODO: implement me
# return ''
#def GetAvailableAuthMethods(self, iwlistauth=None):
# """ Get the authentication methods for the interface. """
# TODO: Implement me
# return ''
def GetSignalStrength(self, iwconfig=None):
""" Get the signal strength of the current network.
@@ -544,3 +572,4 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
return None
return buff.strip('\x00')

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" networking - Provides wrappers for common network operations
@@ -629,6 +630,36 @@ class Wireless(Controller):
"""
return self.wiface.GetBSSID()
def GetCurrentBitrate(self, iwconfig):
""" Get the current bitrate of the interface.
Returns:
The bitrate of the active access point as a string, or
None the bitrate can't be found.
"""
return self.wiface.GetCurrentBitrate(iwconfig)
def GetOperationalMode(self, iwconfig):
""" Get the current operational mode of the interface.
Returns:
The operational mode of the interface as a string, or
None if the operational mode can't be found.
"""
return self.wiface.GetOperationalMode(iwconfig)
def GetAvailableAuthMethods(self, iwlistauth):
""" Get the available authentication methods for the interface.
Returns:
The available authentication methods of the interface as a string, or
None if the auth methods can't be found.
"""
return self.wiface.GetAvailableAuthMethods(iwlistauth)
def GetIwconfig(self):
""" Get the out of iwconfig. """
return self.wiface.GetIwconfig()

View File

@@ -160,6 +160,7 @@ language['cannot_start_daemon'] = _('Unable to connect to wicd daemon DBus inter
"This typically means there was a problem starting the daemon. " + \
"Check the wicd log for more info')
language['lost_dbus'] = _('The wicd daemon has shut down, the UI will not function properly until it is restarted.')
language['access_denied'] = _("Unable to contact the wicd dameon due to an access denied error from DBus. Please check your DBus configuration.")
language['configuring_wireless'] = _('Configuring preferences for wireless network "$A" ($B)')
language['configuring_wired'] = _('Configuring preferences for wired profile "$A"')
language['scan'] = _('Scan')

View File

@@ -79,7 +79,11 @@ def catchdbus(func):
try:
return func(*args, **kwargs)
except DBusException, e:
print "warning: ignoring exception %s" % e
if "DBus.Error.AccessDenied" in e:
error(None, language['access_denied'])
raise DBusException(e)
else:
print "warning: ignoring exception %s" % e
return None
wrapper.__name__ = func.__name__
wrapper.__module__ = func.__module__
@@ -693,6 +697,7 @@ def handle_no_dbus():
block=False))
return False
@catchdbus
def main(argv):
""" The main frontend program.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" wicd - wireless connection daemon implementation.
@@ -993,8 +994,24 @@ class WirelessDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wireless')
def GetApBssid(self):
""" Gets the MAC address for the active network. """
return self.wifi.GetBSSID()
@dbus.service.method('org.wicd.daemon.wireless')
def GetCurrentBitrate(self, iwconfig):
""" Returns the current bitrate for the active network. """
return self.wifi.GetCurrentBitrate(iwconfig)
@dbus.service.method('org.wicd.daemon.wireless')
def GetOperationalMode(self, iwconfig):
""" Returns the operational mode for the iwconfig parameter """
return misc.to_unicode(self.wifi.GetOperationalMode(iwconfig))
@dbus.service.method('org.wicd.daemon.wireless')
def GetAvailableAuthMethods(self, iwlistauth):
""" Returns the operational mode for the iwlistauth parameter """
return misc.to_unicode(self.wifi.GetAvailableAuthMethods(iwlistauth))
@dbus.service.method('org.wicd.daemon.wireless')
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
ics):
@@ -1125,6 +1142,12 @@ class WirelessDaemon(dbus.service.Object):
ip = self.wifi.GetIP(ifconfig)
return ip
@dbus.service.method('org.wicd.daemon.wireless')
def GetOperationalMode(self, ifconfig=""):
""" Returns the IP associated with the wireless interface. """
ip = self.wifi.GetOperationalMode(ifconfig)
return ip
@dbus.service.method('org.wicd.daemon.wireless')
def CheckWirelessConnectingMessage(self):
""" Returns the wireless interface's status message. """
@@ -1677,3 +1700,4 @@ if __name__ == '__main__':
sys.exit(1)
gobject.threads_init()
main(sys.argv)

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Network interface control tools for wicd.
@@ -49,6 +50,7 @@ channel_pattern = re.compile('.*Channel:? ?(\d\d?)', __re_mode)
strength_pattern = re.compile('.*Quality:?=? ?(\d+)\s*/?\s*(\d*)', __re_mode)
altstrength_pattern = re.compile('.*Signal level:?=? ?(\d+)\s*/?\s*(\d*)', __re_mode)
signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)', __re_mode)
bitrates_pattern = re.compile('.*Bit Rates:(.*?)E', __re_mode)
mode_pattern = re.compile('.*Mode:(.*?)\n', __re_mode)
freq_pattern = re.compile('.*Frequency:(.*?)\n', __re_mode)
wep_pattern = re.compile('.*Encryption key:(.*?)\n', __re_mode)
@@ -59,6 +61,9 @@ wpa2_pattern = re.compile('(WPA2)', __re_mode)
#iwconfig-only regular expressions.
ip_pattern = re.compile(r'inet [Aa]d?dr[^.]*:([^.]*\.[^.]*\.[^.]*\.[0-9]*)',re.S)
bssid_pattern = re.compile('.*Access Point: (([0-9A-Z]{2}:){5}[0-9A-Z]{2})', __re_mode)
bitrate_pattern = re.compile('.*Bit Rate=(.*?/s)', __re_mode)
opmode_pattern = re.compile('.*Mode:(.*?) ', __re_mode)
authmethods_pattern = re.compile('.*Authentication capabilities :\n(.*?)Current', __re_mode)
# Regular expressions for wpa_cli output
auth_pattern = re.compile('.*wpa_state=(.*?)\n', __re_mode)
@@ -1035,7 +1040,6 @@ class BaseWirelessInterface(BaseInterface):
A dictionary containing the cell networks properties.
"""
ap = {}
ap['essid'] = misc.RunRegex(essid_pattern, cell)
try:
@@ -1056,6 +1060,10 @@ class BaseWirelessInterface(BaseInterface):
freq = misc.RunRegex(freq_pattern, cell)
ap['channel'] = self._FreqToChannel(freq)
# Bit Rate
ap['bitrates'] = misc.RunRegex(bitrates_pattern, cell).split('\n')
ap['bitrates'] = '; '.join(m.strip() for m in ap['bitrates']).rstrip('; ')
# BSSID
ap['bssid'] = misc.RunRegex(ap_mac_pattern, cell)
@@ -1180,6 +1188,45 @@ class BaseWirelessInterface(BaseInterface):
bssid = misc.RunRegex(bssid_pattern, output)
return bssid
def GetCurrentBitrate(self, iwconfig=None):
""" Get the current bitrate for the interface. """
if not iwconfig:
cmd = 'iwconfig ' + self.iface
if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwconfig
bitrate = misc.RunRegex(bitrate_pattern, output)
return bitrate
def GetOperationalMode(self, iwconfig=None):
""" Get the operational mode for the interface. """
if not iwconfig:
cmd = 'iwconfig ' + self.iface
if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwconfig
opmode = misc.RunRegex(opmode_pattern, output)
if opmode:
opmode = opmode.strip()
return opmode
def GetAvailableAuthMethods(self, iwlistauth=None):
""" Get the available authentication methods for the interface. """
if not iwlistauth:
cmd = 'iwlist ' + self.iface + ' auth'
if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwlistauth
authm = misc.RunRegex(authmethods_pattern, output)
authm_list = [m.strip() for m in authm.split('\n') if m.strip()]
return ';'.join(authm_list)
def _get_link_quality(self, output):
""" Parse out the link quality from iwlist scan or iwconfig output. """
try:
@@ -1247,3 +1294,4 @@ class BaseWirelessInterface(BaseInterface):
if network:
network = misc.to_unicode(network)
return network