From 63460113b86395ee8e5375e07337d92826e37cc7 Mon Sep 17 00:00:00 2001 From: David Paleino Date: Fri, 4 May 2012 19:39:04 +0200 Subject: [PATCH] Implement WEP key index specification --- encryption/templates/wep-hex | 7 ++++--- encryption/templates/wep-passphrase | 7 ++++--- encryption/templates/wep-shared | 7 ++++--- po/wicd.pot | 6 +++++- tests/testmisc.py | 6 ++++++ wicd/misc.py | 31 +++++++++++++++-------------- wicd/translations.py | 1 + wicd/wicd-daemon.py | 6 +++++- 8 files changed, 45 insertions(+), 26 deletions(-) diff --git a/encryption/templates/wep-hex b/encryption/templates/wep-hex index d0cb285..b881efd 100644 --- a/encryption/templates/wep-hex +++ b/encryption/templates/wep-hex @@ -1,7 +1,8 @@ name = WEP (Hex [0-9/A-F]) author = Adam Blackburn -version = 1 +version = 2 require key *Key +optional key_index *Key_Index protected key *Key ----- ctrl_interface=/var/run/wpa_supplicant @@ -9,7 +10,7 @@ network={ ssid="$_ESSID" scan_ssid=$_SCAN key_mgmt=NONE - wep_key0=$_KEY - wep_tx_keyidx=0 + wep_key$_KEY_INDEX=$_KEY + wep_tx_keyidx=$_KEY_INDEX priority=5 } diff --git a/encryption/templates/wep-passphrase b/encryption/templates/wep-passphrase index 838369b..6351f3d 100644 --- a/encryption/templates/wep-passphrase +++ b/encryption/templates/wep-passphrase @@ -1,7 +1,8 @@ name = WEP (Passphrase) author = Adam Blackburn -version = 1 +version = 2 require passphrase *Passphrase +optional key_index *Key_Index protected passphrase *Passphrase ----- ctrl_interface=/var/run/wpa_supplicant @@ -9,7 +10,7 @@ network={ ssid="$_ESSID" scan_ssid=$_SCAN key_mgmt=NONE - wep_key0="$_PASSPHRASE" - wep_tx_keyidx=0 + wep_key$_KEY_INDEX="$_PASSPHRASE" + wep_tx_keyidx=$_KEY_INDEX priority=5 } diff --git a/encryption/templates/wep-shared b/encryption/templates/wep-shared index ba3da27..5707ca7 100644 --- a/encryption/templates/wep-shared +++ b/encryption/templates/wep-shared @@ -1,7 +1,8 @@ name = WEP Shared/Restricted author = Dan O'Reilly -version = 1 +version = 2 require key *Key +optional key_index *Key_Index protected key *Key ----- ctrl_interface=/var/run/wpa_supplicant @@ -10,7 +11,7 @@ network={ scan_ssid=$_SCAN key_mgmt=NONE auth_alg=SHARED - wep_key0=$_KEY - wep_tx_keyidx=0 + wep_key$_KEY_INDEX=$_KEY + wep_tx_keyidx=$_KEY_INDEX priority=5 } diff --git a/po/wicd.pot b/po/wicd.pot index e8d1da9..1c8f2d6 100644 --- a/po/wicd.pot +++ b/po/wicd.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-12-07 23:04+0100\n" +"POT-Creation-Date: 2012-05-04 00:29+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -360,6 +360,10 @@ msgstr "" msgid "Key" msgstr "" +#: wicd/translations.py:81 +msgid "Key index" +msgstr "" + #: curses/netentry_curses.py:51 gtk/netentry.py:76 msgid "Netmask" msgstr "" diff --git a/tests/testmisc.py b/tests/testmisc.py index c58b952..8c2f8cd 100644 --- a/tests/testmisc.py +++ b/tests/testmisc.py @@ -84,6 +84,12 @@ class TestMisc(unittest.TestCase): def test_noneify_11(self): self.assertEquals(misc.Noneify(5), 5) + def test_noneify_12(self): + self.assertEquals(misc.Noneify(1, False), 1) + + def test_noneify_13(self): + self.assertEquals(misc.Noneify(0, False), 0) + def test_none_to_string_1(self): self.assertEquals(misc.noneToString(None), 'None') diff --git a/wicd/misc.py b/wicd/misc.py index cc882e3..a8b09fa 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -252,15 +252,16 @@ def to_bool(var): var = bool(var) return var -def Noneify(variable): +def Noneify(variable, to_bool=True): """ Convert string types to either None or booleans""" #set string Nones to real Nones if variable in ("None", "", None): return None - if variable in ("False", "0"): - return False - if variable in ("True", "1"): - return True + if to_bool: + if variable in ("False", "0"): + return False + if variable in ("True", "1"): + return True return variable def ParseEncryption(network): @@ -288,18 +289,18 @@ def ParseEncryption(network): elif "$_" in line: cur_val = re.findall('\$_([A-Z0-9_]+)', line) if cur_val: - if cur_val[0] == 'SCAN': - #TODO should this be hardcoded? - line = line.replace("$_SCAN", "1") + rep_val = network.get(cur_val[0].lower()) + if not rep_val: + # hardcode some default values + if cur_val[0] == 'SCAN': + rep_val = '1' + elif cur_val[0] == 'KEY_INDEX': + rep_val = '0' + if rep_val: + line = line.replace("$_%s" % cur_val[0], str(rep_val)) config_file = ''.join([config_file, line]) else: - rep_val = network.get(cur_val[0].lower()) - if rep_val: - line = line.replace("$_%s" % cur_val[0], - str(rep_val)) - config_file = ''.join([config_file, line]) - else: - print "Ignoring template line: '%s'" % line + print "Ignoring template line: '%s'" % line else: print "Weird parsing error occurred" else: # Just a regular entry. diff --git a/wicd/translations.py b/wicd/translations.py index c560e01..3e7a052 100644 --- a/wicd/translations.py +++ b/wicd/translations.py @@ -78,6 +78,7 @@ language['authentication'] = _('Authentication') language['domain'] = _('Domain') language['identity'] = _('Identity') language['key'] = _('Key') +language['key_index'] = _('Key index') language['passphrase'] = _('Passphrase') language['password'] = _('Password') language['path_to_ca_cert'] = _('Path to CA cert') diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 69062f7..b8c3e5e 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -1069,7 +1069,11 @@ class WirelessDaemon(dbus.service.Object): print 'Setting script properties through the daemon' \ + ' is not permitted.' return False - self.LastScan[netid][prop] = misc.to_unicode(misc.Noneify(value)) + # whitelist some props that need different handling + if prop in ('key_index', ): + self.LastScan[netid][prop] = misc.to_unicode(misc.Noneify(value, False)) + else: + self.LastScan[netid][prop] = misc.to_unicode(misc.Noneify(value)) @dbus.service.method('org.wicd.daemon.wireless') def DetectWirelessInterface(self):