diff --git a/gui.py b/gui.py index 98070e4..5b2708a 100644 --- a/gui.py +++ b/gui.py @@ -519,6 +519,8 @@ class NetworkEntry(gtk.Expander): if stringToNone(netmask.get_text()) == None: # Make sure the netmask is blank netmask.set_text('255.255.255.0') # Fill in the most common one + elif ipAddress != "": + misc.error(None, "Invalid IP Address Entered.") def resetStaticCheckboxes(self): # Enable the right stuff @@ -1314,7 +1316,28 @@ class appGui: def save_settings(self, type, networkid, networkentry): entry = networkentry.expander + entlist = [] + + # First make sure all the Addresses entered are valid. + if entry.checkboxStaticIP.get_active(): + for ent in [entry.txtIP, entry.txtNetmask, entry.txtGateway]: + entlist.append(ent) + + if entry.checkboxStaticDNS.get_active() and \ + not entry.checkboxGlobalDNS.get_active(): + entlist.append(entry.txtDNS1) + # Only append addition dns entries if they're entered. + for ent in [entry.txtDNS2, entry.txtDNS3]: + if ent.get_text() != "": + entlist.append(ent) + + for lblent in entlist: + if not misc.IsValidIP(lblent.get_text()): + misc.error(self.window, "Invalid address in " + + lblent.label.get_label() + " entry.") + return False + # Now save the settings. if type == "wireless": wireless.SetWirelessProperty(networkid, "automatic", noneToString(entry.checkboxAutoConnect.get_active())) @@ -1381,7 +1404,7 @@ class appGui: if entry.checkboxStaticDNS.get_active() and \ not entry.checkboxGlobalDNS.get_active(): wireless.SetWiredProperty('use_static_dns', True) - wireless.SetWiredProperty('use_global_dns', True) + wireless.SetWiredProperty('use_global_dns', False) wired.SetWiredProperty("dns1", noneToString(entry.txtDNS1.get_text())) wired.SetWiredProperty("dns2", noneToString(entry.txtDNS2.get_text())) wired.SetWiredProperty("dns3", noneToString(entry.txtDNS3.get_text())) @@ -1396,6 +1419,7 @@ class appGui: wired.SetWiredProperty("dns3",'') config.SaveWiredNetworkProfile(entry.comboProfileNames.get_active_text()) + return True def editAdvanced(self, widget, event, type, networkid, networkentry): dialog = gtk.Dialog(title=language['advanced_settings'], @@ -1405,17 +1429,28 @@ class appGui: gtk.RESPONSE_REJECT)) dialog.vbox.pack_start(networkentry.expander.vboxAdvanced) dialog.show_all() - result = dialog.run() - if result == gtk.RESPONSE_ACCEPT: - self.save_settings(type, networkid, networkentry) + while True: + if self.run_advanced(dialog, networkid, networkentry): + break dialog.vbox.remove(networkentry.expander.vboxAdvanced) dialog.destroy() + + def run_advanced(self, dialog, networkid, networkentry): + result = dialog.run() + if result == gtk.RESPONSE_ACCEPT: + if self.save_settings(type, networkid, networkentry): + return True + else: + return False + return True def connect(self, widget, event, type, networkid, networkentry): cancelButton = self.wTree.get_widget("cancel_button") cancelButton.set_sensitive(True) - self.save_settings(type, networkid, networkentry) + if not self.save_settings(type, networkid, networkentry): + return False + if type == "wireless": wireless.ConnectWireless(networkid) elif type == "wired": diff --git a/misc.py b/misc.py index 04f8665..a3f4c1f 100644 --- a/misc.py +++ b/misc.py @@ -1,4 +1,4 @@ -''' Misc - miscellaneous functions for wicd ''' +""" Misc - miscellaneous functions for wicd """ # # Copyright (C) 2007 Adam Blackburn @@ -23,13 +23,14 @@ import locale import gettext import time import sys +import gtk from subprocess import * if __name__ == '__main__': wpath.chdir(__file__) def Run(cmd, include_stderr=False, return_pipe=False): - ''' Run a command + """ Run a command. Runs the given command, returning either the output of the program, or a pipe to read output from. @@ -43,7 +44,7 @@ def Run(cmd, include_stderr=False, return_pipe=False): false, all that will be returned is one output string from the command. - ''' + """ cmd = to_unicode(str(cmd)) if include_stderr: @@ -61,16 +62,18 @@ def Run(cmd, include_stderr=False, return_pipe=False): return f.communicate()[0] def IsValidIP(ip): - ''' Make sure an entered IP is valid ''' - if ip != None: # Make sure there is an IP - if ip.count('.') == 3: # Make sure there are 3 periods - ipNumbers = ip.split('.') # Split it up - if not '' in ipNumbers: # Make sure the ip was split into 3 groups + """ Make sure an entered IP is valid """ + if ip != None: + if ip.count('.') == 3: + ipNumbers = ip.split('.') + for number in ipNumbers: + if not number.isdigit() or int(number) > 255: + return False return ipNumbers return False def PromptToStartDaemon(): - ''' Prompt the user to start the daemon ''' + """ Prompt the user to start the daemon """ daemonloc = wpath.bin + 'launchdaemon.sh' gksudo_args = ['gksudo', '--message', 'Wicd needs to access your computer\'s network cards.', @@ -78,7 +81,7 @@ def PromptToStartDaemon(): os.spawnvpe(os.P_WAIT, 'gksudo', gksudo_args, os.environ) def RunRegex(regex, string): - ''' runs a regex search on a string ''' + """ runs a regex search on a string """ m = regex.search(string) if m: return m.groups()[0] @@ -90,15 +93,15 @@ def log(text): log.write(text + "\n") def WriteLine(my_file, text): - ''' write a line to a file ''' + """ write a line to a file """ my_file.write(text + "\n") def ExecuteScript(script): - ''' Execute a command ''' + """ Execute a command """ os.system(script + ' &') def ReadFile(filename): - ''' read in a file and return it's contents as a string ''' + """ read in a file and return it's contents as a string """ if not os.path.exists(filename): return None my_file = open(filename,'r') @@ -115,7 +118,7 @@ def to_bool(var): return var def Noneify(variable): - ''' convert string types to either None or booleans''' + """ Convert string types to either None or booleans""" #set string Nones to real Nones if variable == "None" or variable == "": return None @@ -133,12 +136,12 @@ def Noneify(variable): return variable def ParseEncryption(network): - ''' Parse through an encryption template file + """ Parse through an encryption template file Parses an encryption template, reading in a network's info and creating a config file for it - ''' + """ #list = open("encryption/templates/active","r") #types = list.readlines() #for i in types: @@ -171,13 +174,13 @@ def ParseEncryption(network): file.close() def LoadEncryptionMethods(): - ''' Load encryption methods from configuration files + """ Load encryption methods from configuration files Loads all the encryption methods from the template files in /encryption/templates into a data structure. To be loaded, the template must be listed in the "active" file. - ''' + """ encryptionTypes = {} types = open("encryption/templates/active","r") enctypes = types.readlines() @@ -213,11 +216,12 @@ def LoadEncryptionMethods(): return encryptionTypes def noneToString(text): - ''' Convert None, "None", or "" to string type "None" + """ Convert None, "None", or "" to string type "None" - used for putting text in a text box if the value to put in is 'None' the box will be blank + Used for putting text in a text box. If the value to put in is 'None', + the box will be blank. - ''' + """ if text == None or text == "None" or text == "": return "None" else: diff --git a/wicd.py b/wicd.py index 865a5ae..17e8e4d 100755 --- a/wicd.py +++ b/wicd.py @@ -44,6 +44,11 @@ import dbus.service import getopt import time +# Wicd specific imports +import wpath +import misc +import gui + # Import egg.trayicon if we're using an older gtk version if not (gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10): import egg.trayicon @@ -54,11 +59,6 @@ else: if getattr(dbus, 'version', (0, 0, 0)) >= (0, 41, 0): import dbus.glib -# Wicd specific imports -import wpath -import misc -import gui - if sys.platform == 'linux2': # Set process name. Only works on Linux >= 2.1.57. try: