Exemplo n.º 1
0
Arquivo: gui.py Projeto: wmak/wicd
    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
Exemplo n.º 2
0
    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'])
Exemplo n.º 3
0
 def test_invalid_ip_7(self):
     self.assertFalse(misc.IsValidIP('2001:0db8:85Z3:0000:0000:8a2e:0370:7334'))
Exemplo n.º 4
0
 def test_invalid_ip_6(self):
     self.assertFalse(misc.IsValidIP('ZZZZ:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF'))
Exemplo n.º 5
0
 def test_invalid_ip_5(self):
     self.assertFalse(misc.IsValidIP('1:'))
Exemplo n.º 6
0
 def test_invalid_ip_3(self):
     self.assertFalse(misc.IsValidIP('1000.0.0.1'))
Exemplo n.º 7
0
 def test_invalid_ip_2(self):
     self.assertFalse(misc.IsValidIP('256.0.0.1'))
Exemplo n.º 8
0
 def test_invalid_ip_1(self):
     self.assertFalse(misc.IsValidIP('-10.0.-1.-1'))
Exemplo n.º 9
0
 def test_valid_ip_7(self):
     self.assertTrue(misc.IsValidIP('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
Exemplo n.º 10
0
 def test_valid_ip_6(self):
     self.assertTrue(misc.IsValidIP('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF'))
Exemplo n.º 11
0
 def test_valid_ip_5(self):
     self.assertTrue(misc.IsValidIP('::1'))
Exemplo n.º 12
0
 def test_valid_ip_3(self):
     self.assertTrue(misc.IsValidIP('10.0.1.1'))
Exemplo n.º 13
0
 def test_valid_ip_2(self):
     self.assertTrue(misc.IsValidIP('255.255.255.255'))
Exemplo n.º 14
0
 def test_valid_ip_1(self):
     self.assertTrue(misc.IsValidIP('0.0.0.0'))