Ejemplo n.º 1
0
        def _fill_route_to_form(rdf_node, fda, subnet_exist):
            if rdf_node.hasType(ns_ui.InternetConnectionRoute):
                fda['network_connection'] = 'internet'
            elif rdf_node.hasType(ns_ui.PrivateNetworkConnectionRoute):
                fda['network_connection'] = 'private'
            else:
                raise uidatahelpers.RdfDataError(
                    'Route\'s destination network is neither internet nor private network connection'
                )

            # Default route does not have subnet
            # XXX: why not 0.0.0.0/0 instead?
            if subnet_exist:
                fda['subnet'] = rdf_node.getS(ns_ui.subnet, rdf.IPv4Subnet)

            gw_node = rdf_node.getS(ns_ui.routeGateway)
            if gw_node.hasType(ns_ui.RouteGatewayNetworkDefault):
                fda['gateway_selection'] = 'nw_default_gw'
            elif gw_node.hasType(ns_ui.RouteGatewayManual):
                fda['gateway_selection'] = 'manual_gw'
                fda['gateway'] = gw_node.getS(ns_ui.ipAddress, rdf.IPv4Address)
            else:
                raise uidatahelpers.RdfDataError(
                    'Route\'s gateway is neither network default nor set gateway.'
                )
Ejemplo n.º 2
0
 def _fill_address_to_form(rdf_node, fda):
     if (rdf_node.getS(ns_ui.address).hasType(ns_ui.DhcpAddress)):
         fda['ip_address_selection'] = 'dhcp'
     elif (rdf_node.getS(ns_ui.address).hasType(ns_ui.StaticAddress)):
         fda['ip_address_selection'] = 'static'
         fda['ip_address'] = rdf_node.getS(ns_ui.address).getS(
             ns_ui.ipAddress, rdf.IPv4Address)
         fda['subnet_mask'] = rdf_node.getS(ns_ui.address).getS(
             ns_ui.subnetMask, rdf.IPv4Address)
     else:
         raise uidatahelpers.RdfDataError(
             'ns_ui.address is not dhcp or static')
Ejemplo n.º 3
0
    def fill_client_connection_group(self, form, ctx, cc_fda):
        ui_root = helpers.get_ui_config()

        # Server address & psk
        #if ui_root.hasS(ns_ui.vpnServerAddress):
        #    cc_fda['server_name'] = ui_root.getS(ns_ui.vpnServerAddress, rdf.String)
        #else:
        #    cc_fda['server_name'] = ''
        cc_fda['psk_1'] = ''
        cc_fda['psk_2'] = ''
        psk_seq = ui_root.getS(ns_ui.preSharedKeys,
                               rdf.Seq(rdf.Type(ns_ui.PreSharedKey)))
        if len(psk_seq) >= 1:
            cc_fda['psk_1'] = psk_seq[0].getS(ns_ui.preSharedKey, rdf.String)
        if len(psk_seq) >= 2:
            cc_fda['psk_2'] = psk_seq[1].getS(ns_ui.preSharedKey, rdf.String)
        dns_root = ui_root.getS(ns_ui.clientDnsServers)

        # DNS
        if dns_root.hasType(ns_ui.NetworkConnectionDns):
            cc_fda['dns'] = 'use_ic_dns'
        elif dns_root.hasType(ns_ui.SetDnsServers):
            cc_fda['dns'] = 'manual_dns'
            uidatahelpers.fill_optional_field_to_form(dns_root,
                                                      ns_ui.primaryDns,
                                                      rdf.IPv4Address, cc_fda,
                                                      'dns_1')
            uidatahelpers.fill_optional_field_to_form(dns_root,
                                                      ns_ui.secondaryDns,
                                                      rdf.IPv4Address, cc_fda,
                                                      'dns_2')
        else:
            raise uidatahelpers.RdfDataError(
                'Client connection dns servers is neither Network connection dns nor set dns servers.'
            )

        uidatahelpers.fill_optional_field_to_form(ui_root,
                                                  ns_ui.clientPrimaryWins,
                                                  rdf.IPv4Address, cc_fda,
                                                  'wins_1')
        uidatahelpers.fill_optional_field_to_form(ui_root,
                                                  ns_ui.clientSecondaryWins,
                                                  rdf.IPv4Address, cc_fda,
                                                  'wins_2')
        cc_fda['client_subnet'] = ui_root.getS(ns_ui.clientSubnet,
                                               rdf.IPv4Subnet)
        cc_fda['client_address_range'] = ui_root.getS(ns_ui.clientAddressRange,
                                                      rdf.IPv4AddressRange)
        cc_fda['client_compression'] = ui_root.getS(ns_ui.clientCompression,
                                                    rdf.Boolean)
Ejemplo n.º 4
0
        def _fill_ppp_firewall_rule_to_form(rdf_node, fda):
            if rdf_node.hasS(ns_ui.ipAddress):
                # XXX: this is never encountered in practice?
                fda['ip_subnet'] = rdf_node.getS(ns_ui.ipAddress,
                                                 rdf.IPv4Address)
            elif rdf_node.hasS(ns_ui.subnet):
                fda['ip_subnet'] = rdf_node.getS(ns_ui.subnet, rdf.IPv4Subnet)
            else:
                raise uidatahelpers.RdfDataError(
                    'Prohibited service ip/subnet is neither ipaddress nor subnet.'
                )

            if rdf_node.hasS(ns_ui.protocol):
                fda['protocol'] = rdf_node.getS(ns_ui.protocol, rdf.String)
            else:
                fda['protocol'] = 'any'

            uidatahelpers.fill_optional_field_to_form(rdf_node, ns_ui.port,
                                                      rdf.Integer, fda, 'port')

            fda['action'] = rdf_node.getS(ns_ui.action, rdf.String)
Ejemplo n.º 5
0
    def fill_network_config(self, form, ctx, fda):
        def _fill_address_to_form(rdf_node, fda):
            if (rdf_node.getS(ns_ui.address).hasType(ns_ui.DhcpAddress)):
                fda['ip_address_selection'] = 'dhcp'
            elif (rdf_node.getS(ns_ui.address).hasType(ns_ui.StaticAddress)):
                fda['ip_address_selection'] = 'static'
                fda['ip_address'] = rdf_node.getS(ns_ui.address).getS(
                    ns_ui.ipAddress, rdf.IPv4Address)
                fda['subnet_mask'] = rdf_node.getS(ns_ui.address).getS(
                    ns_ui.subnetMask, rdf.IPv4Address)
            else:
                raise uidatahelpers.RdfDataError(
                    'ns_ui.address is not dhcp or static')

        def _fill_client_traffic_to_form(rdf_node, fda):
            if rdf_node.getS(ns_ui.clientConnectionNat, rdf.Boolean):
                fda['client_traffic'] = 'nat'
            elif rdf_node.getS(ns_ui.clientConnectionProxyArp, rdf.Boolean):
                fda['client_traffic'] = 'proxyarp'
            else:
                fda['client_traffic'] = 'none'

        root = helpers.get_ui_config()

        # interface count (ifcount_group)
        ifc_fda = fda.descend('ifcount_group')
        if root.hasS(ns_ui.privateNetworkConnection):
            ifc_fda['interface_count'] = 'twoif'
            pn_root = root.getS(ns_ui.privateNetworkConnection,
                                rdf.Type(ns_ui.NetworkConnection))
        else:
            ifc_fda['interface_count'] = 'oneif'
            pn_root = None

        # internet connection (ic_group)
        ic_root = root.getS(ns_ui.internetConnection,
                            rdf.Type(ns_ui.NetworkConnection))
        ic_fda = fda.descend('ic_group')
        ic_fda['if'] = ic_root.getS(ns_ui.interface, rdf.String)
        _fill_address_to_form(ic_root, ic_fda)
        uidatahelpers.fill_optional_field_to_form(ic_root,
                                                  ns_ui.defaultGateway,
                                                  rdf.IPv4Address, ic_fda,
                                                  'default_gateway')
        ic_fda['mtu'] = ic_root.getS(ns_ui.mtu, rdf.Integer)
        uidatahelpers.fill_optional_field_to_form(ic_root, ns_ui.vpnUplink,
                                                  rdf.Float, ic_fda, 'uplink')
        _fill_client_traffic_to_form(ic_root, ic_fda)

        # private network connection (pn_group)
        if not (pn_root is None):
            pn_fda = fda.descend('pn_group')
            pn_fda['if'] = pn_root.getS(ns_ui.interface, rdf.String)
            _fill_address_to_form(pn_root, pn_fda)
            uidatahelpers.fill_optional_field_to_form(pn_root,
                                                      ns_ui.defaultGateway,
                                                      rdf.IPv4Address, pn_fda,
                                                      'default_gateway')
            _fill_client_traffic_to_form(pn_root, pn_fda)

        # dns servers (dns_group)
        dns_root = root.getS(ns_ui.dnsServers)
        dns_fda = fda.descend('dns_group')
        if dns_root.hasType(ns_ui.InternetConnectionDhcp):
            dns_fda['dns_selection'] = 'use_dhcp_ic'
        elif dns_root.hasType(ns_ui.PrivateNetworkConnectionDhcp):
            dns_fda['dns_selection'] = 'use_dhcp_pn'
        elif dns_root.hasType(ns_ui.SetDnsServers):
            dns_fda['dns_selection'] = 'set_manually'
            dns_exists = False
            if dns_root.hasS(ns_ui.primaryDns):
                dns_exists = True
                dns_fda['dns_1'] = dns_root.getS(ns_ui.primaryDns,
                                                 rdf.IPv4Address)
            if dns_root.hasS(ns_ui.secondaryDns):
                dns_exists = True
                dns_fda['dns_2'] = dns_root.getS(ns_ui.secondaryDns,
                                                 rdf.IPv4Address)
            if not (dns_exists):
                _log.warning('no dns servers when filling form data')
        else:
            raise uidatahelpers.RdfDataError(
                'Unknown DNS server information selection')

        # dynamic dns (ddns_group)
        ddns_fda = fda.descend('ddns_group')
        if root.hasS(ns_ui.dynDnsServer):
            ddns_root = root.getS(ns_ui.dynDnsServer,
                                  rdf.Type(ns_ui.DynDnsServer))
            ddns_fda['ddns_provider'] = ddns_root.getS(ns_ui.dynDnsProvider,
                                                       rdf.String)
            ddns_fda['ddns_username'] = ddns_root.getS(ns_ui.dynDnsUsername,
                                                       rdf.String)
            ddns_fda['ddns_password'] = ddns_root.getS(ns_ui.dynDnsPassword,
                                                       rdf.String)
            ddns_fda['ddns_hostname'] = ddns_root.getS(ns_ui.dynDnsHostname,
                                                       rdf.String)
            if ddns_root.hasS(ns_ui.dynDnsAddress):
                tmp = ddns_root.getS(ns_ui.dynDnsAddress, rdf.String)
                if tmp == '':
                    ddns_fda['ddns_address_type'] = 'interface'
                    ddns_fda['ddns_address'] = ''
                elif tmp == 'natted':
                    ddns_fda['ddns_address_type'] = 'natted'
                    ddns_fda['ddns_address'] = ''
                else:
                    ddns_fda['ddns_address_type'] = 'static'
                    ddns_fda['ddns_address'] = tmp
            else:
                ddns_fda['ddns_address_type'] = 'interface'
                ddns_fda['ddns_address'] = ''
        else:
            ddns_fda['ddns_provider'] = 'none'