def is_wired_setting_ok(self, info_dict):
        if info_dict["connection"]["type"] != "802-3-ethernet":
            return False
        else:
            if not self.check_conn_setting(info_dict):
                return False

            if not self.check_ip4_setting(info_dict):
                return False

            if "mac-address" in info_dict["802-3-ethernet"].keys():
                if not TypeConvert.is_valid_mac_address(
                    TypeConvert.mac_address_array2string(info_dict["802-3-ethernet"]["mac-address"])
                ):
                    print "wired invalid mac address"
                    return False

            if "cloned-mac-address" in info_dict["802-3-ethernet"].keys():
                if not TypeConvert.is_valid_mac_address(
                    TypeConvert.mac_address_array2string(info_dict["802-3-ethernet"]["mac-address"])
                ):
                    print "wired invalid clone mac address"
                    return False

            if "duplex" in info_dict["802-3-ethernet"].keys():
                if info_dict["802-3-ethernet"]["duplex"] not in ["full", "half"]:
                    print "wired invalid duplex"
                    return False
        return True
    def is_wired_setting_ok(self, info_dict):
        if info_dict["connection"]["type"] != "802-3-ethernet":
            return False
        else:
            if not self.check_conn_setting(info_dict):
                return False

            if not self.check_ip4_setting(info_dict):
                return False

            if "mac-address" in info_dict["802-3-ethernet"].keys():
                if not TypeConvert.is_valid_mac_address(
                        TypeConvert.mac_address_array2string(
                            info_dict["802-3-ethernet"]["mac-address"])):
                    print "wired invalid mac address"
                    return False

            if "cloned-mac-address" in info_dict["802-3-ethernet"].keys():
                if not TypeConvert.is_valid_mac_address(
                        TypeConvert.mac_address_array2string(
                            info_dict["802-3-ethernet"]["mac-address"])):
                    print "wired invalid clone mac address"
                    return False

            if "duplex" in info_dict["802-3-ethernet"].keys():
                if info_dict["802-3-ethernet"]["duplex"] not in [
                        "full", "half"
                ]:
                    print "wired invalid duplex"
                    return False
        return True
 def check_valid(self, name):
     if name == "ip4":
         return TypeConvert.is_valid_ip4(self.ip[0])
     elif name == "netmask":
         return TypeConvert.is_valid_netmask(self.ip[1])
     elif name == "gw":
         return TypeConvert.is_valid_gw(self.ip[0], self.ip[1], self.ip[2])
 def check_valid(self, name):
     if name == "ip4":
         return TypeConvert.is_valid_ip4(self.ip[0])
     elif name == "netmask":
         return TypeConvert.is_valid_netmask(self.ip[1])
     elif name == "gw":
         return TypeConvert.is_valid_gw(self.ip[0], self.ip[1], self.ip[2])
 def check_valid(self, name):
     if name == "ip6":
         return TypeConvert.is_valid_ip6(self.ip[0])
     # FIXME 应该用ipv6的网关检查
     elif name == "netmask":
         #return TypeConvert.is_valid_netmask(self.ip[1])
         return self.ip[1].isdigit()
     elif name == "gw":
         #return TypeConvert.is_valid_gw(self.ip[0], self.ip[1], self.ip[2])
         return TypeConvert.is_valid_ip6(self.ip[2])
 def check_valid(self, name):
     if name == "ip6":
         return TypeConvert.is_valid_ip6(self.ip[0])
     # FIXME 应该用ipv6的网关检查
     elif name == "netmask":
         #return TypeConvert.is_valid_netmask(self.ip[1])
         return self.ip[1].isdigit()
     elif name == "gw":
         #return TypeConvert.is_valid_gw(self.ip[0], self.ip[1], self.ip[2])
         return TypeConvert.is_valid_ip6(self.ip[2])
 def set_wep_key(self, idx, key):
     if idx == 0:
         self.prop_dict["wep-key0"] = TypeConvert.py2_dbus_string(key)
     elif idx == 1:
         self.prop_dict["wep-key1"] = TypeConvert.py2_dbus_string(key)
     elif idx == 2:
         self.prop_dict["wep-key2"] = TypeConvert.py2_dbus_string(key)
     elif idx == 3:
         self.prop_dict["wep-key3"] = TypeConvert.py2_dbus_string(key)
     else:
         print "invalid idx"
 def set_wep_key(self, idx, key):
     if idx == 0:
         self.prop_dict["wep-key0"] = TypeConvert.py2_dbus_string(key)
     elif idx == 1:
         self.prop_dict["wep-key1"] = TypeConvert.py2_dbus_string(key)
     elif idx == 2:
         self.prop_dict["wep-key2"] = TypeConvert.py2_dbus_string(key)
     elif idx == 3:
         self.prop_dict["wep-key3"] = TypeConvert.py2_dbus_string(key)
     else:
         print "invalid idx"
    def check_setting_finish(self):
        ###check if user complete his setting, avoid the missing property exception
        info_dict = TypeConvert.dbus2py(self.settings_dict)
        try:
            if info_dict["connection"]["type"] == "802-3-ethernet":
                return self.is_wired_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "802-11-wireless":
                return self.is_wireless_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "pppoe":
                return self.is_dsl_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "vpn":
                return self.is_vpn_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "cdma":
                return self.is_cdma_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "gsm":
                return self.is_gsm_setting_ok(info_dict)

            else:
                return False
        except:
            traceback.print_exc()
Example #10
0
 def cloned_mac_address(self, new_cloned_mac_address):
     if len(new_cloned_mac_address) > 0:
         self.prop_dict[
             "cloned-mac-address"] = TypeConvert.mac_address_string2array(
                 new_cloned_mac_address)
     elif "cloned-mac-address" in self.prop_dict.iterkeys():
         del self.prop_dict["cloned-mac-address"]
Example #11
0
 def add_dns_search(self, dns):
     if dns in self.dns_search:
         print "already have the dns search"
     else:    
         if "dns-search" not in self.prop_dict.iterkeys():    
             self.clear_dns_search()
         self.prop_dict["dns-search"].append(TypeConvert.py2_dbus_string(dns))
    def check_setting_finish(self):
        ###check if user complete his setting, avoid the missing property exception
        info_dict = TypeConvert.dbus2py(self.settings_dict)
        try:
            if info_dict["connection"]["type"] == "802-3-ethernet":
                return self.is_wired_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "802-11-wireless":
                return self.is_wireless_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "pppoe":
                return self.is_dsl_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "vpn":
                return self.is_vpn_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "cdma":
                return self.is_cdma_setting_ok(info_dict)

            elif info_dict["connection"]["type"] == "gsm":
                return self.is_gsm_setting_ok(info_dict)

            else:
                return False
        except:
            traceback.print_exc()
 def method(self, new_method):
     if new_method in [
             "auto", "link-local", "manual", "shared", "disabled"
     ]:
         self.prop_dict["method"] = TypeConvert.py2_dbus_string(new_method)
     else:
         print "invalid value:%s to set ip4config method " % new_method
 def check_complete_dns(self):
     dns = []
     for address in self.dns:
         if TypeConvert.is_valid_ip6(address):
             dns.append(address)
         else:
             return dns
     return dns
 def check_complete_dns(self):
     dns = []
     for address in self.dns:
         if TypeConvert.is_valid_ip6(address):
             dns.append(address)
         else:
             return dns
     return dns
    def save_settings(self, widget, content, types):
        #value = None
        if types:
            setattr(self.ethernet, types, content)
        if self.settings_obj is None:
            return
        
        # check mac address whether is valid
        if types == "mac_address":
            mac_address = content
            cloned_mac_address = self.clone_entry.get_address()
        elif types == "cloned_mac_address":
            mac_address = self.mac_entry.get_address()
            cloned_mac_address = content
        else:
            mac_address = self.mac_entry.get_address()
            cloned_mac_address = self.clone_entry.get_address()

        if (mac_address == ":::::") or \
                (mac_address == "") or \
                (TypeConvert.is_valid_mac_address(mac_address)):
            mac_address_is_valid = True
        else:
            mac_address_is_valid = False
        if (cloned_mac_address == ":::::") or \
                (cloned_mac_address == "") or \
                (TypeConvert.is_valid_mac_address(cloned_mac_address)):
            cloned_mac_address_is_valid = True
        else:
            cloned_mac_address_is_valid = False
        if mac_address_is_valid and cloned_mac_address_is_valid:
            self.settings_obj.mac_is_valid = True
        else:
            self.settings_obj.mac_is_valid = False

        # 统一调用shared_methods.Settings的set_button
        log.debug('set_button True')
        self.settings_obj.set_button("save", True)

        """
    def check_ip4_setting(self, info_dict):
        if "ipv4" in info_dict.keys():
            if info_dict["ipv4"]["method"] == "manual":

                if not info_dict["ipv4"]["addresses"]:
                    print "ipv4 addresses not complete"
                    return False
                else:
                    [address, netmask, gateway] = TypeConvert.ip4address_net2native(info_dict["ipv4"]["addresses"][0])

                    if not TypeConvert.is_valid_ip4(address):
                        print "ipv4 invalid address"
                        return False

                    if not TypeConvert.is_valid_netmask(netmask):
                        print "ipv4 invalid netmask"
                        return False

                    if not TypeConvert.is_valid_gw(address, netmask, gateway):
                        print "ipv4 invalid gateway"
                        return False

            if "dns" in info_dict["ipv4"].keys() and len(info_dict["ipv4"]["dns"]) > 0:
                for dns in info_dict["ipv4"]["dns"]:
                    if not TypeConvert.is_valid_ip4(TypeConvert.ip4_net2native(dns)):
                        print "ipv4 invalid dns"
                        return False
        return True
    def check_ip4_setting(self, info_dict):
        if "ipv4" in info_dict.keys():
            if info_dict["ipv4"]["method"] == "manual":

                if not info_dict["ipv4"]["addresses"]:
                    print "ipv4 addresses not complete"
                    return False
                else:
                    [address, netmask,
                     gateway] = TypeConvert.ip4address_net2native(
                         info_dict["ipv4"]["addresses"][0])

                    if not TypeConvert.is_valid_ip4(address):
                        print "ipv4 invalid address"
                        return False

                    if not TypeConvert.is_valid_netmask(netmask):
                        print "ipv4 invalid netmask"
                        return False

                    if not TypeConvert.is_valid_gw(address, netmask, gateway):
                        print "ipv4 invalid gateway"
                        return False

            if "dns" in info_dict["ipv4"].keys() and len(
                    info_dict["ipv4"]["dns"]) > 0:
                for dns in info_dict["ipv4"]["dns"]:
                    if not TypeConvert.is_valid_ip4(
                            TypeConvert.ip4_net2native(dns)):
                        print "ipv4 invalid dns"
                        return False
        return True
    def check_setting_commit(self):
        ###delete invalid setting property before update
        for key in self.settings_dict.keys():
            for key2 in self.settings_dict[key]:
                if self.settings_dict[key][key2] == None:
                    self.settings_dict[key][key2] = ""

        info_dict = TypeConvert.dbus2py(self.settings_dict)
        try:
            if info_dict["connection"]["type"] == "802-3-ethernet":
                if not self.get_setting("802-3-ethernet").wired_valid():
                    ###or raise exception
                    return False
                self.get_setting("ipv4").adapt_ip4config_commit()

                if "ipv6" in info_dict.iterkeys():
                    self.get_setting("ipv6").adapt_ip6config_commit()

            elif info_dict["connection"]["type"] == "802-11-wireless":
                self.get_setting("802-11-wireless").adapt_wireless_commit()

                if "802-11-wireless-security" in info_dict.iterkeys():
                    self.get_setting("802-11-wireles-security"
                                     ).adapt_wireless_security_commit()

                self.get_setting("ipv4").adapt_ip4config_commit()

                if "ipv6" in info_dict.iterkeys():
                    self.get_setting("ipv6").adapt_ip6config_commit()

            elif info_dict["connection"]["type"] == "pppoe":
                if not self.get_setting("802-3-ethernet").wired_valid():
                    return False
                self.get_setting("ipv4").adapt_ip4config_commit()

                if "ipv6" in info_dict.iterkeys():
                    self.get_setting("ipv6").adapt_ip6config_commit()

            elif info_dict["connection"]["type"] == "vpn":
                pass

            elif info_dict["connection"]["type"] == "cdma":
                pass

            elif info_dict["connection"]["type"] == "gsm":
                pass

            else:
                print "invalid connection_type"
        except:
            pass
    def check_setting_commit(self):
        ###delete invalid setting property before update
        for key in self.settings_dict.keys():
            for key2 in self.settings_dict[key]:
                if self.settings_dict[key][key2] == None:
                    self.settings_dict[key][key2] = ""

        info_dict = TypeConvert.dbus2py(self.settings_dict)
        try:
            if info_dict["connection"]["type"] == "802-3-ethernet":
                if not self.get_setting("802-3-ethernet").wired_valid():
                    ###or raise exception
                    return False
                self.get_setting("ipv4").adapt_ip4config_commit()

                if "ipv6" in info_dict.iterkeys():
                    self.get_setting("ipv6").adapt_ip6config_commit()

            elif info_dict["connection"]["type"] == "802-11-wireless":
                self.get_setting("802-11-wireless").adapt_wireless_commit()

                if "802-11-wireless-security" in info_dict.iterkeys():
                    self.get_setting("802-11-wireles-security").adapt_wireless_security_commit()

                self.get_setting("ipv4").adapt_ip4config_commit()

                if "ipv6" in info_dict.iterkeys():
                    self.get_setting("ipv6").adapt_ip6config_commit()

            elif info_dict["connection"]["type"] == "pppoe":
                if not self.get_setting("802-3-ethernet").wired_valid():
                    return False
                self.get_setting("ipv4").adapt_ip4config_commit()

                if "ipv6" in info_dict.iterkeys():
                    self.get_setting("ipv6").adapt_ip6config_commit()

            elif info_dict["connection"]["type"] == "vpn":
                pass

            elif info_dict["connection"]["type"] == "cdma":
                pass

            elif info_dict["connection"]["type"] == "gsm":
                pass

            else:
                print "invalid connection_type"
        except:
            pass
 def entry_changed(self, widget, content, types):
     is_valid = True
     if types == "ssid":
         setattr(self.wireless, types, content)
     else:
         from nmlib.nm_utils import TypeConvert
         if (content == "") or TypeConvert.is_valid_mac_address(content):
             setattr(self.wireless, types, content)
             #check_settings(self.connection, self.set_button)
             is_valid = self.connection.check_setting_finish()
         else:
             is_valid = False
             #Dispatcher.set_button("save", False)
     self.settings_obj.mac_is_valid = is_valid
     self.settings_obj.set_button("save", is_valid)
Example #22
0
 def entry_changed(self, widget, content, types):
     is_valid = True
     if types == "ssid":
         setattr(self.wireless, types, content)
     else:
         from nmlib.nm_utils import TypeConvert
         if (content == "") or TypeConvert.is_valid_mac_address(content):
             setattr(self.wireless, types, content)
             #check_settings(self.connection, self.set_button)
             is_valid = self.connection.check_setting_finish()
         else:
             is_valid = False
             #Dispatcher.set_button("save", False)
     self.settings_obj.mac_is_valid = is_valid
     self.settings_obj.set_button("save", is_valid)
 def save_settings(self, widget, value, types):
     if type(value) is str:
         if (value == "") or TypeConvert.is_valid_mac_address(value):
             setattr(self.ethernet_setting, types, value)
             #if self.connection.check_setting_finish():
                 #Dispatcher.set_button("save", True)
             is_valid = self.connection.check_setting_finish()
         else:
             is_valid = False
             #Dispatcher.set_button("save", False)
         self.settings_obj.mac_is_valid = is_valid
         if not self._init:
             self.settings_obj.set_button("save", is_valid)
     else:
         setattr(self.ethernet_setting, types, value)
         if self.connection.check_setting_finish() and not self._init:
             Dispatcher.set_button("save", True)
    def set_dns_address(self, widget, content, index):
        self.dns[index] = content
        names = ["master", "slaver"]
        dns = self.check_complete_dns()
        if dns:
            is_valid = True
            self.setting.clear_dns()
            for d in dns:
                self.setting.add_dns(d)
        else:
            is_valid = False
            self.setting.clear_dns()

        if TypeConvert.is_valid_ip6(content):
            setattr(self, names[index] + "_flag", True)
        else:
            setattr(self, names[index] + "_flag", False)

        ############
        # 检查dns
        if self.settings_obj:
            self.settings_obj.ipv6_dns_is_valid = is_valid
            self.settings_obj.set_button("save", is_valid)
    def set_dns_address(self, widget, content, index):
        self.dns[index] = content
        names = ["master", "slaver"]
        dns = self.check_complete_dns()
        if dns:
            is_valid = True
            self.setting.clear_dns()
            for d in dns:
                self.setting.add_dns(d)
        else:
            is_valid = False
            self.setting.clear_dns()

        if TypeConvert.is_valid_ip6(content):
            setattr(self, names[index] + "_flag", True)
        else:
            setattr(self, names[index] + "_flag", False)

        ############
        # 检查dns
        if self.settings_obj:
            self.settings_obj.ipv6_dns_is_valid = is_valid
            self.settings_obj.set_button("save", is_valid)
 def remove_dns(self, dns):
     if dns not in self.dns:
         print "doesn't have the dns to remove"
     else:
         self.prop_dict["dns"].remove(TypeConvert.ip4_native2net(dns))
 def dns_search(self):
     if "dns-search" not in self.prop_dict.iterkeys():
         self.clear_dns_search()
     return TypeConvert.dbus2py(self.prop_dict["dns-search"])
 def dns(self, new_dns):
     self.prop_dict["dns"] = TypeConvert.py2_dbus_array(new_dns)
 def add_dns(self, dns):
     if dns in self.dns:
         print "dns already added"
     else:
         self.prop_dict["dns"].append(TypeConvert.ip4_native2net(dns))
 def zone(self):
     if "zone" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["zone"])
 def dns(self):
     if "dns" not in self.prop_dict.iterkeys():
         self.clear_dns()
     return map(lambda x: TypeConvert.ip4_net2native(x),
                self.prop_dict["dns"])
 def permissions(self, new_permissions):
     self.prop_dict["permissions"] = TypeConvert.py2_dbus_array(new_permissions)
 def method(self):
     if "method" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["method"])
 def timestamp(self):
     if "timestamp" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["timestamp"])
     else:
         return  0
 def type(self):
     if "type" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["type"])
 def dns_search(self, new_dns_search):
     self.prop_dict["dns-search"] = TypeConvert.py2_dbus_array(
         new_dns_search)
 def read_only(self, new_read_only):
     self.prop_dict["read_only"] = TypeConvert.py2_dbus_boolean(new_read_only)
 def master(self, new_master):
     self.prop_dict["master"] = TypeConvert.py2_dbus_string(new_master)
 def id(self, new_id):
     self.prop_dict["id"] = TypeConvert.py2_dbus_string(new_id)
 def autoconnect(self, new_autoconnect):
     self.prop_dict["autoconnect"] = TypeConvert.py2_dbus_boolean(new_autoconnect)
 def slave_type(self, new_slave_type):
     self.prop_dict["slave-type"] = TypeConvert.py2_dbus_string(new_slave_type)
 def never_default(self, new_never_default):
     self.prop_dict["never-default"] = TypeConvert.py2_dbus_boolean(
         new_never_default)
 def timestamp(self, new_timestamp):
     self.prop_dict["timestamp"] = TypeConvert.py2_dbus_uint64(new_timestamp)
 def may_fail(self):
     if "may-fail" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["may-fail"])
     else:
         return True
 def type(self, new_type):
     self.prop_dict["type"] = TypeConvert.py2_dbus_string(new_type)
 def may_fail(self, new_may_fail):
     self.prop_dict["may-fail"] = TypeConvert.py2_dbus_boolean(new_may_fail)
 def zone(self, new_zone):
     self.prop_dict["zone"] = TypeConvert.py2_dbus_string(new_zone)
 def dhcp_client_id(self):
     if "dhcp-client-id" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["dhcp-client-id"])
 def autoconnect(self):
     if "autoconnect" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["autoconnect"])
     else:
         return True
 def dhcp_client_id(self, new_dhcp_client_id):
     self.prop_dict["dhcp-client-id"] = TypeConvert.py2_dbus_string(
         new_dhcp_client_id)
 def id(self):
     if "id" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["id"])
 def dhcp_send_hostname(self, new_dhcp_send_hostname):
     self.prop_dict["dhcp_send_hostname"] = TypeConvert.py2_dbus_boolean(
         new_dhcp_send_hostname)
 def master(self):
     if "master" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["master"])
 def dhcp_hostname(self):
     if "dhcp-hostname" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["dhcp-hostname"])
 def read_only(self):
     if "read-only" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["read-only"])
     else:
         return False
 def dhcp_hostname(self, new_dhcp_host_name):
     self.prop_dict["dhcp-hostname"] = TypeConvert.py2_dbus_string(
         new_dhcp_host_name)
 def slave_type(self):
     if "slave-type" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["slave-type"])
 def never_default(self):
     if "never-default" in self.prop_dict.iterkeys():
         return TypeConvert.dbus2py(self.prop_dict["never-default"])
     else:
         return False