1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-20 04:48:00 +01:00

Made IsValidIP method check that each ip octet is an integer < 255.

Added checks to the network entry settings menu to make sure that all the settings are valid.
Fixed global dns being set to True whenever static IP address were enabled for wireless networks.
This commit is contained in:
imdano
2008-01-25 09:23:50 +00:00
parent 85bdd4b072
commit c09b49dd6c
3 changed files with 70 additions and 31 deletions

45
gui.py
View File

@@ -519,6 +519,8 @@ class NetworkEntry(gtk.Expander):
if stringToNone(netmask.get_text()) == None: # Make sure the netmask is blank 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 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): def resetStaticCheckboxes(self):
# Enable the right stuff # Enable the right stuff
@@ -1314,7 +1316,28 @@ class appGui:
def save_settings(self, type, networkid, networkentry): def save_settings(self, type, networkid, networkentry):
entry = networkentry.expander 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": if type == "wireless":
wireless.SetWirelessProperty(networkid, "automatic", wireless.SetWirelessProperty(networkid, "automatic",
noneToString(entry.checkboxAutoConnect.get_active())) noneToString(entry.checkboxAutoConnect.get_active()))
@@ -1381,7 +1404,7 @@ class appGui:
if entry.checkboxStaticDNS.get_active() and \ if entry.checkboxStaticDNS.get_active() and \
not entry.checkboxGlobalDNS.get_active(): not entry.checkboxGlobalDNS.get_active():
wireless.SetWiredProperty('use_static_dns', True) 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("dns1", noneToString(entry.txtDNS1.get_text()))
wired.SetWiredProperty("dns2", noneToString(entry.txtDNS2.get_text())) wired.SetWiredProperty("dns2", noneToString(entry.txtDNS2.get_text()))
wired.SetWiredProperty("dns3", noneToString(entry.txtDNS3.get_text())) wired.SetWiredProperty("dns3", noneToString(entry.txtDNS3.get_text()))
@@ -1396,6 +1419,7 @@ class appGui:
wired.SetWiredProperty("dns3",'') wired.SetWiredProperty("dns3",'')
config.SaveWiredNetworkProfile(entry.comboProfileNames.get_active_text()) config.SaveWiredNetworkProfile(entry.comboProfileNames.get_active_text())
return True
def editAdvanced(self, widget, event, type, networkid, networkentry): def editAdvanced(self, widget, event, type, networkid, networkentry):
dialog = gtk.Dialog(title=language['advanced_settings'], dialog = gtk.Dialog(title=language['advanced_settings'],
@@ -1405,17 +1429,28 @@ class appGui:
gtk.RESPONSE_REJECT)) gtk.RESPONSE_REJECT))
dialog.vbox.pack_start(networkentry.expander.vboxAdvanced) dialog.vbox.pack_start(networkentry.expander.vboxAdvanced)
dialog.show_all() dialog.show_all()
result = dialog.run() while True:
if result == gtk.RESPONSE_ACCEPT: if self.run_advanced(dialog, networkid, networkentry):
self.save_settings(type, networkid, networkentry) break
dialog.vbox.remove(networkentry.expander.vboxAdvanced) dialog.vbox.remove(networkentry.expander.vboxAdvanced)
dialog.destroy() 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): def connect(self, widget, event, type, networkid, networkentry):
cancelButton = self.wTree.get_widget("cancel_button") cancelButton = self.wTree.get_widget("cancel_button")
cancelButton.set_sensitive(True) cancelButton.set_sensitive(True)
self.save_settings(type, networkid, networkentry) if not self.save_settings(type, networkid, networkentry):
return False
if type == "wireless": if type == "wireless":
wireless.ConnectWireless(networkid) wireless.ConnectWireless(networkid)
elif type == "wired": elif type == "wired":

46
misc.py
View File

@@ -1,4 +1,4 @@
''' Misc - miscellaneous functions for wicd ''' """ Misc - miscellaneous functions for wicd """
# #
# Copyright (C) 2007 Adam Blackburn # Copyright (C) 2007 Adam Blackburn
@@ -23,13 +23,14 @@ import locale
import gettext import gettext
import time import time
import sys import sys
import gtk
from subprocess import * from subprocess import *
if __name__ == '__main__': if __name__ == '__main__':
wpath.chdir(__file__) wpath.chdir(__file__)
def Run(cmd, include_stderr=False, return_pipe=False): def Run(cmd, include_stderr=False, return_pipe=False):
''' Run a command """ Run a command.
Runs the given command, returning either the output Runs the given command, returning either the output
of the program, or a pipe to read output from. 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 false, all that will be returned is
one output string from the command. one output string from the command.
''' """
cmd = to_unicode(str(cmd)) cmd = to_unicode(str(cmd))
if include_stderr: if include_stderr:
@@ -61,16 +62,18 @@ def Run(cmd, include_stderr=False, return_pipe=False):
return f.communicate()[0] return f.communicate()[0]
def IsValidIP(ip): def IsValidIP(ip):
''' Make sure an entered IP is valid ''' """ Make sure an entered IP is valid """
if ip != None: # Make sure there is an IP if ip != None:
if ip.count('.') == 3: # Make sure there are 3 periods if ip.count('.') == 3:
ipNumbers = ip.split('.') # Split it up ipNumbers = ip.split('.')
if not '' in ipNumbers: # Make sure the ip was split into 3 groups for number in ipNumbers:
if not number.isdigit() or int(number) > 255:
return False
return ipNumbers return ipNumbers
return False return False
def PromptToStartDaemon(): def PromptToStartDaemon():
''' Prompt the user to start the daemon ''' """ Prompt the user to start the daemon """
daemonloc = wpath.bin + 'launchdaemon.sh' daemonloc = wpath.bin + 'launchdaemon.sh'
gksudo_args = ['gksudo', '--message', gksudo_args = ['gksudo', '--message',
'Wicd needs to access your computer\'s network cards.', '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) os.spawnvpe(os.P_WAIT, 'gksudo', gksudo_args, os.environ)
def RunRegex(regex, string): def RunRegex(regex, string):
''' runs a regex search on a string ''' """ runs a regex search on a string """
m = regex.search(string) m = regex.search(string)
if m: if m:
return m.groups()[0] return m.groups()[0]
@@ -90,15 +93,15 @@ def log(text):
log.write(text + "\n") log.write(text + "\n")
def WriteLine(my_file, text): def WriteLine(my_file, text):
''' write a line to a file ''' """ write a line to a file """
my_file.write(text + "\n") my_file.write(text + "\n")
def ExecuteScript(script): def ExecuteScript(script):
''' Execute a command ''' """ Execute a command """
os.system(script + ' &') os.system(script + ' &')
def ReadFile(filename): 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): if not os.path.exists(filename):
return None return None
my_file = open(filename,'r') my_file = open(filename,'r')
@@ -115,7 +118,7 @@ def to_bool(var):
return var return var
def Noneify(variable): 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 #set string Nones to real Nones
if variable == "None" or variable == "": if variable == "None" or variable == "":
return None return None
@@ -133,12 +136,12 @@ def Noneify(variable):
return variable return variable
def ParseEncryption(network): 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 Parses an encryption template, reading in a network's info
and creating a config file for it and creating a config file for it
''' """
#list = open("encryption/templates/active","r") #list = open("encryption/templates/active","r")
#types = list.readlines() #types = list.readlines()
#for i in types: #for i in types:
@@ -171,13 +174,13 @@ def ParseEncryption(network):
file.close() file.close()
def LoadEncryptionMethods(): def LoadEncryptionMethods():
''' Load encryption methods from configuration files """ Load encryption methods from configuration files
Loads all the encryption methods from the template files Loads all the encryption methods from the template files
in /encryption/templates into a data structure. To be in /encryption/templates into a data structure. To be
loaded, the template must be listed in the "active" file. loaded, the template must be listed in the "active" file.
''' """
encryptionTypes = {} encryptionTypes = {}
types = open("encryption/templates/active","r") types = open("encryption/templates/active","r")
enctypes = types.readlines() enctypes = types.readlines()
@@ -213,11 +216,12 @@ def LoadEncryptionMethods():
return encryptionTypes return encryptionTypes
def noneToString(text): 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 == "": if text == None or text == "None" or text == "":
return "None" return "None"
else: else:

10
wicd.py
View File

@@ -44,6 +44,11 @@ import dbus.service
import getopt import getopt
import time import time
# Wicd specific imports
import wpath
import misc
import gui
# Import egg.trayicon if we're using an older gtk version # Import egg.trayicon if we're using an older gtk version
if not (gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10): if not (gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10):
import egg.trayicon import egg.trayicon
@@ -54,11 +59,6 @@ else:
if getattr(dbus, 'version', (0, 0, 0)) >= (0, 41, 0): if getattr(dbus, 'version', (0, 0, 0)) >= (0, 41, 0):
import dbus.glib import dbus.glib
# Wicd specific imports
import wpath
import misc
import gui
if sys.platform == 'linux2': if sys.platform == 'linux2':
# Set process name. Only works on Linux >= 2.1.57. # Set process name. Only works on Linux >= 2.1.57.
try: try: