Ejemplo n.º 1
0
    def from_dict(cls, settings):
        """Returns a new `:class:DialerConf` out of ``settings``"""
        ret = cls()
        # connection
        ret.uuid = settings["connection"]["uuid"]
        ret.autoconnect = settings["connection"].get("autoconnect", False)
        # gsm
        ret.apn = settings["gsm"]["apn"]
        ret.username = settings["gsm"].get("username", "")
        ret.password = settings["gsm"].get("password")
        ret.band = settings["gsm"].get("band")
        ret.network_type = settings["gsm"].get("network-type")
        # ipv4 might not be present
        if "ipv4" in settings:
            ret.staticdns = settings["ipv4"].get("ignore-auto-dns", False)
            if settings["ipv4"].get("dns"):
                dns1 = settings["ipv4"]["dns"][0]
                ret.dns1 = convert_int_to_ip(dns1)
                if len(settings["ipv4"]["dns"]) > 1:
                    dns2 = settings["ipv4"]["dns"][1]
                    ret.dns2 = convert_int_to_ip(dns2)
        # ppp might not be present
        if "ppp" in settings:
            # get authentication options
            ret.refuse_pap = settings["ppp"].get("refuse-pap", True)
            ret.refuse_chap = settings["ppp"].get("refuse-chap", True)

        return ret
Ejemplo n.º 2
0
    def from_dict(cls, settings):
        """Returns a new `:class:DialerConf` out of ``settings``"""
        ret = cls()
        # connection
        ret.uuid = settings['connection']['uuid']
        ret.autoconnect = settings['connection'].get('autoconnect', False)
        # gsm
        ret.apn = settings['gsm']['apn']
        ret.username = settings['gsm'].get('username', '')
        ret.password = settings['gsm'].get('password')
        ret.band = settings['gsm'].get('band')
        ret.network_type = settings['gsm'].get('network-type')
        # ipv4 might not be present
        if 'ipv4' in settings:
            ret.staticdns = settings['ipv4'].get('ignore-auto-dns', False)
            if settings['ipv4'].get('dns'):
                dns1 = settings['ipv4']['dns'][0]
                ret.dns1 = convert_int_to_ip(dns1)
                if len(settings['ipv4']['dns']) > 1:
                    dns2 = settings['ipv4']['dns'][1]
                    ret.dns2 = convert_int_to_ip(dns2)
        # ppp might not be present
        if 'ppp' in settings:
            # get authentication options
            ret.refuse_pap = settings['ppp'].get('refuse-pap', True)
            ret.refuse_chap = settings['ppp'].get('refuse-chap', True)

        return ret
Ejemplo n.º 3
0
    def setup_view(self, view):
        if self.model.name:
            self.view['profile_name_entry'].set_text(self.model.name)
        if self.model.username:
            self.view['username_entry'].set_text(self.model.username)
        if self.model.apn:
            self.view['apn_entry'].set_text(self.model.apn)
        if self.model.primary_dns:
            dns1 = convert_int_to_ip(self.model.primary_dns)
            self.view['primary_dns_entry'].set_text(dns1)
        if self.model.secondary_dns:
            dns2 = convert_int_to_ip(self.model.secondary_dns)
            self.view['secondary_dns_entry'].set_text(dns2)

        if self.model.static_dns:
            self.view['static_dns_check'].set_active(self.model.static_dns)
            self.view.enable_static_dns()
        else:
            self.view['static_dns_check'].set_active(False)

        if not self.model.password:

            def load_secrets(secrets):
                self.model.password = secrets['gsm'].get('passwd', '')
                self.view['password_entry'].set_text(self.model.password)

            try:
                self.model.load_password(load_secrets)
            except KeyringNoMatchError, e:
                logger.error("Error while loading connection password: %s" % e)
                title = _("Error while getting connection password")
                details = _("NoMatchError: No password was retrieved "
                            "from connection, please set one again")
                show_error_dialog(title, details)
                return
Ejemplo n.º 4
0
    def setup_view(self, view):
        self.view['profile_name_entry'].set_text(self.model.name)
        self.view['username_entry'].set_text(self.model.username)
        self.view.set_network_mode(self.model.network_type)
        self.view.set_band(self.model.band)
        self.view['apn_entry'].set_text(self.model.apn)
        self.view['static_dns_check'].set_active(self.model.static_dns)
        if self.model.primary_dns:
            dns1 = convert_int_to_ip(self.model.primary_dns)
            self.view['primary_dns_entry'].set_text(dns1)
        if self.model.secondary_dns:
            dns2 = convert_int_to_ip(self.model.secondary_dns)
            self.view['secondary_dns_entry'].set_text(dns2)

        if self.model.static_dns:
            self.view.enable_static_dns()

        if not self.model.password:
            try:
                self.model.load_password()
            except KeyringNoMatchError, e:
                logger.error("Error while loading connection password: %s" % e)
                title = _("Error while getting connection password")
                details = _("NoMatchError: No password was retrieved "
                            "from connection, please set one again")
                show_error_dialog(title, details)
                return
Ejemplo n.º 5
0
 def test_ip_to_int_conversion(self):
     for ip in ip_generator(50000):
         num = convert_ip_to_int(ip)
         self.failIf(num < 0)
         self.assertEqual(ip, convert_int_to_ip(num))
Ejemplo n.º 6
0
    def property_secondary_dns_value_change(self, model, old, new):
        if not old and new and old != new:
            self.view.enable_static_dns()

        self.view['secondary_dns_entry'].set_text(convert_int_to_ip(new))