mirror of
https://github.com/gryf/wicd.git
synced 2025-12-22 05:48:03 +01:00
Tweak encryption template code so that optional parameters can be supplied. Tweak UI code to reflect that new functionality.
Allow for slightly more variation in template formatting.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
name = EAP-FAST
|
name = EAP-FAST
|
||||||
author = Adam Blackburn
|
author = Adam Blackburn
|
||||||
version = 2
|
version = 2
|
||||||
require username *Username password *Password pac_file *Path_To_PAC_File
|
require username *Username password *Password
|
||||||
|
optional pac_file *Path_To_PAC_File
|
||||||
-----
|
-----
|
||||||
ctrl_interface=/var/run/wpa_supplicant
|
ctrl_interface=/var/run/wpa_supplicant
|
||||||
network={
|
network={
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
name = PEAP with TKIP
|
name = PEAP with TKIP/MSCHAPV2
|
||||||
author = Fralaltro
|
author = Fralaltro
|
||||||
version = 1
|
version = 1
|
||||||
require identity *Identity password *Password ca_cert *Path_to_CA_Cert
|
require identity *Identity password *Password
|
||||||
|
optional ca_cert *Path_to_CA_Cert
|
||||||
-----
|
-----
|
||||||
ctrl_interface=/var/run/wpa_supplicant
|
ctrl_interface=/var/run/wpa_supplicant
|
||||||
network={
|
network={
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name = WEP (Hex)
|
name = WEP (Hex [0-9/A-F])
|
||||||
author = Adam Blackburn
|
author = Adam Blackburn
|
||||||
version = 1
|
version = 1
|
||||||
require key *Key
|
require key *Key
|
||||||
|
|||||||
@@ -632,9 +632,12 @@ class appGui(object):
|
|||||||
# Make sure no entries are left blank
|
# Make sure no entries are left blank
|
||||||
if entry.chkbox_encryption.get_active():
|
if entry.chkbox_encryption.get_active():
|
||||||
encryption_info = entry.encryption_info
|
encryption_info = entry.encryption_info
|
||||||
for x in encryption_info:
|
for entry_info in encryption_info.itervalues():
|
||||||
if encryption_info[x].get_text() == "":
|
if entry_info[0].entry.get_text() == "" and \
|
||||||
error(self.window, language['encrypt_info_missing'])
|
entry_info[1] == 'required':
|
||||||
|
error(self, "%s (%s)" % (language['encrypt_info_missing'],
|
||||||
|
entry_info[0].label.get_label())
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
# Make sure the checkbox is checked when it should be
|
# Make sure the checkbox is checked when it should be
|
||||||
elif not entry.chkbox_encryption.get_active() and \
|
elif not entry.chkbox_encryption.get_active() and \
|
||||||
|
|||||||
102
wicd/misc.py
102
wicd/misc.py
@@ -262,10 +262,6 @@ def LoadEncryptionMethods():
|
|||||||
loaded, the template must be listed in the "active" file.
|
loaded, the template must be listed in the "active" file.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def parse_ent(line, key):
|
|
||||||
return line.replace(key, "").replace("=", "").strip()
|
|
||||||
|
|
||||||
encryptionTypes = []
|
|
||||||
try:
|
try:
|
||||||
enctypes = open(wpath.encryption + "active","r").readlines()
|
enctypes = open(wpath.encryption + "active","r").readlines()
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
@@ -273,48 +269,72 @@ def LoadEncryptionMethods():
|
|||||||
raise IOError(e)
|
raise IOError(e)
|
||||||
|
|
||||||
# Parse each encryption method
|
# Parse each encryption method
|
||||||
for x in enctypes:
|
encryptionTypes = []
|
||||||
x = x.strip()
|
for enctype in enctypes:
|
||||||
|
parsed_template = _parse_enc_template(enctype.strip())
|
||||||
|
if parsed_template:
|
||||||
|
encryptionTypes.append(parsed_template)
|
||||||
|
return encryptionTypes
|
||||||
|
|
||||||
|
def __parse_field_ent(fields, field_type='require'):
|
||||||
|
fields = fields.split(" ")
|
||||||
|
ret = []
|
||||||
|
# We need an even number of entries in the line for it to be valid.
|
||||||
|
if (len(fields) % 2) != 0:
|
||||||
|
print "Invalid '%s' line found in template %s" % (field_type, enctype)
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
for val, disp_val in grouper(2, fields, fillvalue=None):
|
||||||
|
if val.startswith("*") or not disp_val.startswith("*"):
|
||||||
|
print "Invalid '%s' line found in template %s" % (field_type, enctype)
|
||||||
|
return None
|
||||||
|
ret.append([val, disp_val[1:]])
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def _parse_enc_template(enctype):
|
||||||
|
""" Parse an encryption template. """
|
||||||
|
def parse_ent(line, key):
|
||||||
|
return line.replace(key, "").replace("=", "").strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open(wpath.encryption + x, "r")
|
f = open(os.path.join(wpath.encryption, enctype), "r")
|
||||||
except IOError:
|
except IOError:
|
||||||
print 'Failed to load encryption type ' + str(x)
|
print "Failed to open template file %s" % enctype
|
||||||
continue
|
return None
|
||||||
line = f.readlines()
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
cur_type = {}
|
cur_type = {}
|
||||||
cur_type[0] = parse_ent(line[0], "name")
|
cur_type["type"] = enctype
|
||||||
cur_type[1] = x
|
cur_type["fields"] = []
|
||||||
cur_type[2] = {}
|
cur_type['optional'] = []
|
||||||
|
cur_type['required'] = []
|
||||||
# Find the line containing our required fields.
|
for index, line in enumerate(f):
|
||||||
i = 1
|
if line.startswith("name") and not "name" in cur_type:
|
||||||
try:
|
cur_type["name"] = parse_ent(line, "name")
|
||||||
while not line[i].startswith("require"):
|
elif line.startswith("require"):
|
||||||
i += 1
|
cur_type["required"] = __parse_field_ent(parse_ent(line,
|
||||||
except IndexError:
|
"require"))
|
||||||
print "Bad encryption template: Couldn't find 'require' line"
|
if not cur_type["required"]:
|
||||||
requiredFields = parse_ent(line[i], "require")
|
# An error occured parsing the require line.
|
||||||
requiredFields = requiredFields.split(" ")
|
continue
|
||||||
|
elif line.startswith("optional"):
|
||||||
# Get the required fields.
|
cur_type["optional"] = __parse_field_ent(parse_ent(line,
|
||||||
index = -1
|
"optional"),
|
||||||
for current in requiredFields:
|
field_type="optional")
|
||||||
# The pretty names will start with an * so we can
|
if not cur_type["optional"]:
|
||||||
# separate them with that.
|
# An error occured parsing the optional line.
|
||||||
if current[0] == "*":
|
continue
|
||||||
# Make underscores spaces
|
elif line.startswith("----"):
|
||||||
# and remove the *
|
# We're done.
|
||||||
cur_type[2][index][0] = current.replace("_", " ").lstrip("*")
|
break
|
||||||
|
f.close()
|
||||||
|
if not cur_type["required"]:
|
||||||
|
print "Failed to find a 'require' line in template %s" % enctype
|
||||||
|
return None
|
||||||
|
if not cur_type["name"]:
|
||||||
|
print "Failed to find a 'name' line in template %s" % enctype
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
# Add to the list of things that are required.
|
return cur_type
|
||||||
index = len(cur_type[2])
|
|
||||||
cur_type[2][index] = {}
|
|
||||||
cur_type[2][index][1] = current
|
|
||||||
# Add the current type to the dict of encryption types.
|
|
||||||
encryptionTypes.append(cur_type)
|
|
||||||
return encryptionTypes
|
|
||||||
|
|
||||||
def noneToString(text):
|
def noneToString(text):
|
||||||
""" Convert None, "None", or "" to string type "None"
|
""" Convert None, "None", or "" to string type "None"
|
||||||
|
|||||||
@@ -308,8 +308,8 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
# Build the encryption menu
|
# Build the encryption menu
|
||||||
activeID = -1 # Set the menu to this item when we are done
|
activeID = -1 # Set the menu to this item when we are done
|
||||||
for x, enc_type in enumerate(self.encrypt_types):
|
for x, enc_type in enumerate(self.encrypt_types):
|
||||||
self.combo_encryption.append_text(enc_type[0])
|
self.combo_encryption.append_text(enc_type['name'])
|
||||||
if enc_type[1] == wireless.GetWirelessProperty(networkID, "enctype"):
|
if enc_type['type'] == wireless.GetWirelessProperty(networkID, "enctype"):
|
||||||
activeID = x
|
activeID = x
|
||||||
self.combo_encryption.set_active(activeID)
|
self.combo_encryption.set_active(activeID)
|
||||||
if activeID != -1:
|
if activeID != -1:
|
||||||
@@ -384,7 +384,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
activeID = -1 # Set the menu to this item when we are done
|
activeID = -1 # Set the menu to this item when we are done
|
||||||
user_enctype = wireless.GetWirelessProperty(networkID, "enctype")
|
user_enctype = wireless.GetWirelessProperty(networkID, "enctype")
|
||||||
for x, enc_type in enumerate(self.encrypt_types):
|
for x, enc_type in enumerate(self.encrypt_types):
|
||||||
if enc_type[1] == user_enctype:
|
if enc_type['type'] == user_enctype:
|
||||||
activeID = x
|
activeID = x
|
||||||
|
|
||||||
self.combo_encryption.set_active(activeID)
|
self.combo_encryption.set_active(activeID)
|
||||||
@@ -400,24 +400,32 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
# Check encryption info
|
# Check encryption info
|
||||||
if self.chkbox_encryption.get_active():
|
if self.chkbox_encryption.get_active():
|
||||||
print "setting encryption info..."
|
print "setting encryption info..."
|
||||||
encryption_info = self.encryption_info
|
encrypt_info = self.encryption_info
|
||||||
encrypt_methods = misc.LoadEncryptionMethods()
|
encrypt_methods = self.encrypt_types
|
||||||
self.set_net_prop("enctype",
|
self.set_net_prop("enctype",
|
||||||
encrypt_methods[self.combo_encryption.get_active()][1])
|
encrypt_methods[self.combo_encryption.get_active()]['type'])
|
||||||
for x in encryption_info:
|
# Make sure all required fields are filled in.
|
||||||
if encryption_info[x].get_text() == "":
|
for entry_info in encrypt_info.itervalues():
|
||||||
error(self, language['encrypt_info_missing'])
|
if entry_info[0].entry.get_text() == "" and \
|
||||||
|
entry_info[1] == 'required':
|
||||||
|
error(self, "%s (%s)" % (language['encrypt_info_missing'],
|
||||||
|
entry_info[0].label.get_label())
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
self.set_net_prop(x, noneToString(encryption_info[x].get_text()))
|
# Now save all the entries.
|
||||||
|
for entry_key, entry_info in encrypt_info.iteritems():
|
||||||
|
self.set_net_prop(entry_key,
|
||||||
|
noneToString(entry_info[0].entry.get_text()))
|
||||||
elif not self.chkbox_encryption.get_active() and \
|
elif not self.chkbox_encryption.get_active() and \
|
||||||
wireless.GetWirelessProperty(networkid, "encryption"):
|
wireless.GetWirelessProperty(networkid, "encryption"):
|
||||||
|
# Encrypt checkbox is off, but the network needs it.
|
||||||
error(self, language['enable_encryption'])
|
error(self, language['enable_encryption'])
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
print "no encryption specified..."
|
print "no encryption specified..."
|
||||||
self.set_net_prop("enctype", "None")
|
self.set_net_prop("enctype", "None")
|
||||||
for x in self.encryption_info:
|
for entry in encrypt_info.iterkeys():
|
||||||
self.set_net_prop(x, "")
|
self.set_net_prop(entry[0].entry, "")
|
||||||
AdvancedSettingsDialog.save_settings(self)
|
AdvancedSettingsDialog.save_settings(self)
|
||||||
|
|
||||||
if self.chkbox_global_settings.get_active():
|
if self.chkbox_global_settings.get_active():
|
||||||
@@ -444,7 +452,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
for z in self.vbox_encrypt_info:
|
for z in self.vbox_encrypt_info:
|
||||||
z.destroy() # Remove stuff in there already
|
z.destroy() # Remove stuff in there already
|
||||||
ID = self.combo_encryption.get_active()
|
ID = self.combo_encryption.get_active()
|
||||||
methods = misc.LoadEncryptionMethods()
|
methods = self.encrypt_types
|
||||||
self.encryption_info = {}
|
self.encryption_info = {}
|
||||||
|
|
||||||
# If nothing is selected, select the first entry.
|
# If nothing is selected, select the first entry.
|
||||||
@@ -452,22 +460,22 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
self.combo_encryption.set_active(0)
|
self.combo_encryption.set_active(0)
|
||||||
ID = 0
|
ID = 0
|
||||||
|
|
||||||
opts = methods[ID][2]
|
for type_ in ['required', 'optional']:
|
||||||
for x in opts:
|
fields = methods[ID][type_]
|
||||||
box = None
|
for field in fields:
|
||||||
if language.has_key(opts[x][0]):
|
if language.has_key(field[1]):
|
||||||
box = LabelEntry(language[opts[x][0].lower().replace(' ','_')])
|
box = LabelEntry(language[field[1].lower().replace(' ','_')])
|
||||||
else:
|
else:
|
||||||
box = LabelEntry(opts[x][0].replace('_',' '))
|
box = LabelEntry(field[1].replace('_',' '))
|
||||||
box.set_auto_hidden(True)
|
box.set_auto_hidden(True)
|
||||||
self.vbox_encrypt_info.pack_start(box)
|
self.vbox_encrypt_info.pack_start(box)
|
||||||
# Add the data to any array, so that the information
|
# Add the data to a dict, so that the information
|
||||||
# can be easily accessed by giving the name of the wanted
|
# can be easily accessed by giving the name of the wanted
|
||||||
# data.
|
# data.
|
||||||
self.encryption_info[opts[x][1]] = box.entry
|
self.encryption_info[field[0]] = [box, type_]
|
||||||
|
|
||||||
box.entry.set_text(noneToBlankString(
|
box.entry.set_text(noneToBlankString(
|
||||||
wireless.GetWirelessProperty(self.networkID, opts[x][1])))
|
wireless.GetWirelessProperty(self.networkID, field[0])))
|
||||||
self.vbox_encrypt_info.show_all()
|
self.vbox_encrypt_info.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user