def save_settings(self, nettype, networkid, networkentry): """ Verifies and saves the settings for the network entry. """ entry = networkentry.advanced_dialog opt_entlist = [] req_entlist = [] # First make sure all the Addresses entered are valid. if entry.chkbox_static_ip.get_active(): req_entlist = [entry.txt_ip, entry.txt_netmask] opt_entlist = [entry.txt_gateway] if entry.chkbox_static_dns.get_active() and \ not entry.chkbox_global_dns.get_active(): for ent in [entry.txt_dns_1, entry.txt_dns_2, entry.txt_dns_3]: opt_entlist.append(ent) # Required entries. for lblent in req_entlist: lblent.set_text(lblent.get_text().strip()) if not misc.IsValidIP(lblent.get_text()): error( self.window, _('Invalid address in $A entry.').replace( '$A', lblent.label.get_label())) return False # Optional entries, only check for validity if they're entered. for lblent in opt_entlist: lblent.set_text(lblent.get_text().strip()) if lblent.get_text() and not misc.IsValidIP(lblent.get_text()): error( self.window, _('Invalid address in $A entry.').replace( '$A', lblent.label.get_label())) return False # Now save the settings. if nettype == "wireless": if not networkentry.save_wireless_settings(networkid): return False elif nettype == "wired": if not networkentry.save_wired_settings(): return False return True
def set_defaults(self, widget=None, event=None): """ Put some default values into entries to help the user out. """ self.txt_ip.set_text(self.txt_ip.get_text().strip()) ipAddress = self.txt_ip.get_text() # For easy typing :) netmask = self.txt_netmask gateway = self.txt_gateway ip_parts = misc.IsValidIP(ipAddress) if ip_parts: if stringToNone(gateway.get_text() ) is None: # Make sure the gateway box is blank # Fill it in with a .1 at the end gateway.set_text('.'.join(ip_parts[0:3]) + '.1') if stringToNone(netmask.get_text() ) is None: # Make sure the netmask is blank netmask.set_text( '255.255.255.0') # Fill in the most common one elif ipAddress != "": error(None, language['invalid_ip_address'])
def test_invalid_ip_7(self): self.assertFalse(misc.IsValidIP('2001:0db8:85Z3:0000:0000:8a2e:0370:7334'))
def test_invalid_ip_6(self): self.assertFalse(misc.IsValidIP('ZZZZ:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF'))
def test_invalid_ip_5(self): self.assertFalse(misc.IsValidIP('1:'))
def test_invalid_ip_3(self): self.assertFalse(misc.IsValidIP('1000.0.0.1'))
def test_invalid_ip_2(self): self.assertFalse(misc.IsValidIP('256.0.0.1'))
def test_invalid_ip_1(self): self.assertFalse(misc.IsValidIP('-10.0.-1.-1'))
def test_valid_ip_7(self): self.assertTrue(misc.IsValidIP('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
def test_valid_ip_6(self): self.assertTrue(misc.IsValidIP('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF'))
def test_valid_ip_5(self): self.assertTrue(misc.IsValidIP('::1'))
def test_valid_ip_3(self): self.assertTrue(misc.IsValidIP('10.0.1.1'))
def test_valid_ip_2(self): self.assertTrue(misc.IsValidIP('255.255.255.255'))
def test_valid_ip_1(self): self.assertTrue(misc.IsValidIP('0.0.0.0'))