コード例 #1
0
ファイル: userconfig.py プロジェクト: nakedible/vpnease-l2tp
        def _save_user_to_rdf(user, fda):
            username = fda['username']
            user.setS(ns_ui.username, rdf.String, username)

            # Password is tricky; we look up the previous config, and if a user
            # of this name existed and it had a password, use that password unless
            # a new one is specified.  This is not perfect, but at least it works
            # correctly w.r.t. changed username.  Note however that we do not track
            # user identity as such across a name change: if admin removes user XYZ
            # and adds a new user with name XYZ (with empty password field), that
            # user will simply inherit the older user XYZ password.
            
            if fda.has_key('password') and (fda['password'] is not None) and (fda['password'] != ''):
                # set hashed password entries
                uihelpers.set_user_password_hashes(user, fda['password'])
            else:
                if userpw_dict.has_key(username):
                    password_plain, password_md5, password_nt = userpw_dict[username]
                    user.setS(ns_ui.passwordMd5, rdf.String, password_md5)
                    user.setS(ns_ui.passwordNtHash, rdf.String, password_nt)
                    user.removeNodes(ns_ui.password)
                else:
                    # this should not happen; log but don't fail badly
                    _log.error('no password in form or userpw dict, should not happen')
                    user.setS(ns_ui.password, rdf.String, '')
                    
            uidatahelpers.save_optional_field_to_rdf(user, ns_ui.fixedIp, rdf.IPv4Address, fda, 'fixed_ip')
            user.setS(ns_ui.adminRights, rdf.Boolean, fda['admin_rights']) 
            user.setS(ns_ui.vpnRights, rdf.Boolean, fda['vpn_rights'])
コード例 #2
0
ファイル: userconfig.py プロジェクト: zeus911/vpnease-l2tp
        def _save_user_to_rdf(user, fda):
            username = fda['username']
            user.setS(ns_ui.username, rdf.String, username)

            # Password is tricky; we look up the previous config, and if a user
            # of this name existed and it had a password, use that password unless
            # a new one is specified.  This is not perfect, but at least it works
            # correctly w.r.t. changed username.  Note however that we do not track
            # user identity as such across a name change: if admin removes user XYZ
            # and adds a new user with name XYZ (with empty password field), that
            # user will simply inherit the older user XYZ password.

            if fda.has_key('password') and (fda['password'] is not None) and (
                    fda['password'] != ''):
                # set hashed password entries
                uihelpers.set_user_password_hashes(user, fda['password'])
            else:
                if userpw_dict.has_key(username):
                    password_plain, password_md5, password_nt = userpw_dict[
                        username]
                    user.setS(ns_ui.passwordMd5, rdf.String, password_md5)
                    user.setS(ns_ui.passwordNtHash, rdf.String, password_nt)
                    user.removeNodes(ns_ui.password)
                else:
                    # this should not happen; log but don't fail badly
                    _log.error(
                        'no password in form or userpw dict, should not happen'
                    )
                    user.setS(ns_ui.password, rdf.String, '')

            uidatahelpers.save_optional_field_to_rdf(user, ns_ui.fixedIp,
                                                     rdf.IPv4Address, fda,
                                                     'fixed_ip')
            user.setS(ns_ui.adminRights, rdf.Boolean, fda['admin_rights'])
            user.setS(ns_ui.vpnRights, rdf.Boolean, fda['vpn_rights'])
コード例 #3
0
 def _save_port_forward_to_rdf(rdf_node, fda):
     rdf_node.setS(ns_ui.protocol, rdf.String, fda['new_fw_protocol'])
     uidatahelpers.save_optional_field_to_rdf(rdf_node,
                                              ns_ui.incomingPort,
                                              rdf.Integer, fda,
                                              'new_fw_port_in')
     rdf_node.setS(ns_ui.ipAddress, rdf.IPv4Address,
                   fda['new_fw_ip_out'])
     uidatahelpers.save_optional_field_to_rdf(rdf_node,
                                              ns_ui.destinationPort,
                                              rdf.Integer, fda,
                                              'new_fw_port_out')
コード例 #4
0
    def save_client_connection_data(self, ctx, form, data):
        cc_fda = formalutils.FormDataAccessor(form, ['client_connection'], ctx)
        ui_root = helpers.get_new_ui_config()

        # Server address & psk
        if cc_fda.has_key('server_name') and cc_fda['server_name'] is not None:
            ui_root.setS(ns_ui.vpnServerAddress, rdf.String,
                         cc_fda['server_name'])
        else:
            ui_root.setS(ns_ui.vpnServerAddress, rdf.String, '')
        psk_seq = ui_root.setS(ns_ui.preSharedKeys,
                               rdf.Seq(rdf.Type(ns_ui.PreSharedKey)))
        if cc_fda.has_key('psk_1') and (cc_fda['psk_1'] !=
                                        '') and (cc_fda['psk_1'] is not None):
            psk = psk_seq.new()
            psk.setS(ns_ui.preSharedKey, rdf.String, cc_fda['psk_1'])
        if cc_fda.has_key('psk_2') and (cc_fda['psk_2'] !=
                                        '') and (cc_fda['psk_2'] is not None):
            psk = psk_seq.new()
            psk.setS(ns_ui.preSharedKey, rdf.String, cc_fda['psk_2'])
        # DNS
        if cc_fda['dns'] == 'use_ic_dns':
            ui_root.setS(ns_ui.clientDnsServers,
                         rdf.Type(ns_ui.NetworkConnectionDns))
        elif cc_fda['dns'] == 'manual_dns':
            dns_root = ui_root.setS(ns_ui.clientDnsServers,
                                    rdf.Type(ns_ui.SetDnsServers))
            uidatahelpers.save_optional_field_to_rdf(dns_root,
                                                     ns_ui.primaryDns,
                                                     rdf.IPv4Address, cc_fda,
                                                     'dns_1')
            uidatahelpers.save_optional_field_to_rdf(dns_root,
                                                     ns_ui.secondaryDns,
                                                     rdf.IPv4Address, cc_fda,
                                                     'dns_2')
        else:
            raise uidatahelpers.FormDataError(
                'Client connection dns is neither network dns nor set dns.')
        # WINS
        # Note: parent node is ui-root, which may already have a value from old config, use empty default
        # value to remove old data in case form value is missing.
        uidatahelpers.save_optional_field_to_rdf(ui_root,
                                                 ns_ui.clientPrimaryWins,
                                                 rdf.IPv4Address,
                                                 cc_fda,
                                                 'wins_1',
                                                 default=None)
        uidatahelpers.save_optional_field_to_rdf(ui_root,
                                                 ns_ui.clientSecondaryWins,
                                                 rdf.IPv4Address,
                                                 cc_fda,
                                                 'wins_2',
                                                 default=None)
        ui_root.setS(ns_ui.clientSubnet, rdf.IPv4Subnet,
                     cc_fda['client_subnet'])
        ui_root.setS(ns_ui.clientAddressRange, rdf.IPv4AddressRange,
                     cc_fda['client_address_range'])

        ui_root.setS(ns_ui.clientCompression, rdf.Boolean,
                     cc_fda['client_compression'])
コード例 #5
0
    def save_client_connection_data(self, ctx, form, data):
        cc_fda = formalutils.FormDataAccessor(form, ['client_connection'], ctx)
        ui_root = helpers.get_new_ui_config()

        # Server address & psk
        if cc_fda.has_key('server_name') and cc_fda['server_name'] is not None:
            ui_root.setS(ns_ui.vpnServerAddress, rdf.String, cc_fda['server_name'])
        else:
            ui_root.setS(ns_ui.vpnServerAddress, rdf.String, '')
        psk_seq = ui_root.setS(ns_ui.preSharedKeys, rdf.Seq(rdf.Type(ns_ui.PreSharedKey)))
        if cc_fda.has_key('psk_1') and (cc_fda['psk_1'] != '') and (cc_fda['psk_1'] is not None):
            psk = psk_seq.new()
            psk.setS(ns_ui.preSharedKey, rdf.String, cc_fda['psk_1'])
        if cc_fda.has_key('psk_2') and (cc_fda['psk_2'] != '') and (cc_fda['psk_2'] is not None):
            psk = psk_seq.new()
            psk.setS(ns_ui.preSharedKey, rdf.String, cc_fda['psk_2'])
        # DNS
        if cc_fda['dns'] == 'use_ic_dns':
            ui_root.setS(ns_ui.clientDnsServers, rdf.Type(ns_ui.NetworkConnectionDns))
        elif cc_fda['dns'] == 'manual_dns':
            dns_root = ui_root.setS(ns_ui.clientDnsServers, rdf.Type(ns_ui.SetDnsServers))
            uidatahelpers.save_optional_field_to_rdf(dns_root, ns_ui.primaryDns, rdf.IPv4Address, cc_fda, 'dns_1')
            uidatahelpers.save_optional_field_to_rdf(dns_root, ns_ui.secondaryDns, rdf.IPv4Address, cc_fda, 'dns_2')
        else:
            raise uidatahelpers.FormDataError('Client connection dns is neither network dns nor set dns.')
        # WINS
        # Note: parent node is ui-root, which may already have a value from old config, use empty default
        # value to remove old data in case form value is missing.
        uidatahelpers.save_optional_field_to_rdf(ui_root, ns_ui.clientPrimaryWins, rdf.IPv4Address, cc_fda, 'wins_1', default=None)
        uidatahelpers.save_optional_field_to_rdf(ui_root, ns_ui.clientSecondaryWins, rdf.IPv4Address, cc_fda, 'wins_2', default=None)
        ui_root.setS(ns_ui.clientSubnet, rdf.IPv4Subnet, cc_fda['client_subnet'])
        ui_root.setS(ns_ui.clientAddressRange, rdf.IPv4AddressRange, cc_fda['client_address_range'])

        ui_root.setS(ns_ui.clientCompression, rdf.Boolean, cc_fda['client_compression'])
コード例 #6
0
        def _save_ppp_firewall_rule_to_rdf(rdf_node, fda):
            if isinstance(fda['ip_subnet'], datatypes.IPv4Address):
                rdf_node.setS(ns_ui.ipAddress, rdf.IPv4Address, fda['ip_subnet'])
            elif isinstance(fda['ip_subnet'], datatypes.IPv4Subnet):
                rdf_node.setS(ns_ui.subnet, rdf.IPv4Subnet, fda['ip_subnet'])
            else:
                raise uidatahelpers.FormDataError('Firewall rule IP/subnet is neither IPv4Address nor IPv4Subnet')
                    
            if fda['protocol'] == 'any':
                pass
            else:
                rdf_node.setS(ns_ui.protocol, rdf.String, fda['protocol'])

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

            rdf_node.setS(ns_ui.action, rdf.String, fda['action'])
コード例 #7
0
        def _save_ppp_firewall_rule_to_rdf(rdf_node, fda):
            if isinstance(fda['ip_subnet'], datatypes.IPv4Address):
                rdf_node.setS(ns_ui.ipAddress, rdf.IPv4Address,
                              fda['ip_subnet'])
            elif isinstance(fda['ip_subnet'], datatypes.IPv4Subnet):
                rdf_node.setS(ns_ui.subnet, rdf.IPv4Subnet, fda['ip_subnet'])
            else:
                raise uidatahelpers.FormDataError(
                    'Firewall rule IP/subnet is neither IPv4Address nor IPv4Subnet'
                )

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

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

            rdf_node.setS(ns_ui.action, rdf.String, fda['action'])
コード例 #8
0
 def _save_port_forward_to_rdf(rdf_node, fda):
     rdf_node.setS(ns_ui.protocol, rdf.String, fda['new_fw_protocol'])
     uidatahelpers.save_optional_field_to_rdf(rdf_node, ns_ui.incomingPort, rdf.Integer, fda, 'new_fw_port_in')
     rdf_node.setS(ns_ui.ipAddress, rdf.IPv4Address, fda['new_fw_ip_out'])
     uidatahelpers.save_optional_field_to_rdf(rdf_node, ns_ui.destinationPort, rdf.Integer, fda, 'new_fw_port_out')
コード例 #9
0
    def save_network_data(self, ctx, form, data):
        def _save_ip_address(rdf_node, fda):
            if fda['ip_address_selection'] == 'dhcp':
                rdf_node.setS(ns_ui.address, rdf.Type(ns_ui.DhcpAddress))
            elif fda['ip_address_selection'] == 'static':
                static_node = rdf_node.setS(ns_ui.address,
                                            rdf.Type(ns_ui.StaticAddress))
                static_node.setS(ns_ui.ipAddress, rdf.IPv4Address,
                                 fda['ip_address'])
                static_node.setS(ns_ui.subnetMask, rdf.IPv4Address,
                                 fda['subnet_mask'])
            else:
                raise uidatahelpers.FormDataError(
                    'ip_address_selection is neither dhcp nor static')

        def _save_client_traffic(rdf_node, fda):
            client_nat = False
            client_proxy = False
            if fda['client_traffic'] == 'nat':
                client_nat = True
            elif fda['client_traffic'] == 'proxyarp':
                client_proxy = True
            rdf_node.setS(ns_ui.clientConnectionNat, rdf.Boolean, client_nat)
            rdf_node.setS(ns_ui.clientConnectionProxyArp, rdf.Boolean,
                          client_proxy)

        fda = formalutils.FormDataAccessor(form, [], ctx)
        ui_root = helpers.get_new_ui_config()

        # Interface count
        ic_root = ui_root.setS(ns_ui.internetConnection,
                               rdf.Type(ns_ui.NetworkConnection))
        if fda['ifcount_group.interface_count'] == 'oneif':
            ui_root.removeNodes(ns_ui.privateNetworkConnection)
            pn_root = None
        elif fda['ifcount_group.interface_count'] == 'twoif':
            pn_root = ui_root.setS(ns_ui.privateNetworkConnection,
                                   rdf.Type(ns_ui.NetworkConnection))
        else:
            raise uidatahelpers.FormDataError(
                'interface_count is neither oneif nor twoif.')

        # Internet connection
        ic_fda = fda.descend('ic_group')
        ic_root.setS(ns_ui.interface, rdf.String, ic_fda['if'])
        _save_ip_address(ic_root, ic_fda)
        uidatahelpers.save_optional_field_to_rdf(ic_root, ns_ui.defaultGateway,
                                                 rdf.IPv4Address, ic_fda,
                                                 'default_gateway')
        ic_root.setS(ns_ui.mtu, rdf.Integer, int(ic_fda['mtu']))
        uidatahelpers.save_optional_field_to_rdf(ic_root, ns_ui.vpnUplink,
                                                 rdf.Float, ic_fda, 'uplink')
        _save_client_traffic(ic_root, ic_fda)

        # Private network connection, fill if exists.
        if not (pn_root is None):
            pn_fda = fda.descend('pn_group')
            pn_root.setS(ns_ui.interface, rdf.String, pn_fda['if'])
            _save_ip_address(pn_root, pn_fda)
            uidatahelpers.save_optional_field_to_rdf(pn_root,
                                                     ns_ui.defaultGateway,
                                                     rdf.IPv4Address, pn_fda,
                                                     'default_gateway')
            _save_client_traffic(pn_root, pn_fda)

        # DNS Servers
        dns_fda = fda.descend('dns_group')
        if dns_fda['dns_selection'] == 'use_dhcp_ic':
            dns_root = ui_root.setS(ns_ui.dnsServers,
                                    rdf.Type(ns_ui.InternetConnectionDhcp))
        elif dns_fda['dns_selection'] == 'use_dhcp_pn':
            dns_root = ui_root.setS(
                ns_ui.dnsServers, rdf.Type(ns_ui.PrivateNetworkConnectionDhcp))
        elif dns_fda['dns_selection'] == 'set_manually':
            dns_root = ui_root.setS(ns_ui.dnsServers,
                                    rdf.Type(ns_ui.SetDnsServers))

            # XXX: dns_1 is not really optional here; we should not save dns_2 if we don't have dns_1, it makes no sense
            uidatahelpers.save_optional_field_to_rdf(dns_root,
                                                     ns_ui.primaryDns,
                                                     rdf.IPv4Address, dns_fda,
                                                     'dns_1')
            uidatahelpers.save_optional_field_to_rdf(dns_root,
                                                     ns_ui.secondaryDns,
                                                     rdf.IPv4Address, dns_fda,
                                                     'dns_2')

        # Dyndns
        ddns_fda = fda.descend('ddns_group')
        if uidatahelpers.has_form_value(ddns_fda, 'ddns_provider') and \
           (ddns_fda['ddns_provider'] != 'none'):
            ddns_root = ui_root.setS(ns_ui.dynDnsServer,
                                     rdf.Type(ns_ui.DynDnsServer))
            ddns_root.setS(ns_ui.dynDnsProvider, rdf.String,
                           ddns_fda['ddns_provider'])
            ddns_root.setS(ns_ui.dynDnsUsername, rdf.String,
                           ddns_fda['ddns_username'])
            ddns_root.setS(ns_ui.dynDnsPassword, rdf.String,
                           ddns_fda['ddns_password'])
            ddns_root.setS(ns_ui.dynDnsHostname, rdf.String,
                           ddns_fda['ddns_hostname'])

            tmp = ddns_fda['ddns_address_type']
            if tmp == 'interface':
                ddns_root.setS(ns_ui.dynDnsAddress, rdf.String, '')
            elif tmp == 'natted':
                ddns_root.setS(ns_ui.dynDnsAddress, rdf.String, 'natted')
            elif tmp == 'static':
                if (ddns_fda.has_key('ddns_address')) and \
                       (ddns_fda['ddns_address'] is not None) and \
                       (ddns_fda['ddns_address'] != ''):
                    ddns_root.setS(ns_ui.dynDnsAddress, rdf.String,
                                   ddns_fda['ddns_address'])
                else:
                    ddns_root.setS(ns_ui.dynDnsAddress, rdf.String, '')
        else:
            ui_root.removeNodes(ns_ui.dynDnsServer)
コード例 #10
0
    def save_network_data(self, ctx, form, data):
        def _save_ip_address(rdf_node, fda):
            if fda['ip_address_selection'] == 'dhcp':
                rdf_node.setS(ns_ui.address, rdf.Type(ns_ui.DhcpAddress))
            elif fda['ip_address_selection'] == 'static':
                static_node = rdf_node.setS(ns_ui.address, rdf.Type(ns_ui.StaticAddress))
                static_node.setS(ns_ui.ipAddress, rdf.IPv4Address, fda['ip_address'])
                static_node.setS(ns_ui.subnetMask, rdf.IPv4Address, fda['subnet_mask']) 
            else:
                raise uidatahelpers.FormDataError('ip_address_selection is neither dhcp nor static') 
            
        def _save_client_traffic(rdf_node, fda):
            client_nat = False
            client_proxy = False
            if fda['client_traffic'] == 'nat':
                client_nat = True    
            elif fda['client_traffic'] == 'proxyarp':
                client_proxy = True    
            rdf_node.setS(ns_ui.clientConnectionNat, rdf.Boolean, client_nat)
            rdf_node.setS(ns_ui.clientConnectionProxyArp, rdf.Boolean, client_proxy)
        
        fda = formalutils.FormDataAccessor(form, [], ctx)
        ui_root = helpers.get_new_ui_config()

        # Interface count
        ic_root = ui_root.setS(ns_ui.internetConnection, rdf.Type(ns_ui.NetworkConnection))
        if fda['ifcount_group.interface_count'] == 'oneif':
            ui_root.removeNodes(ns_ui.privateNetworkConnection)
            pn_root = None
        elif fda['ifcount_group.interface_count'] == 'twoif':
            pn_root = ui_root.setS(ns_ui.privateNetworkConnection, rdf.Type(ns_ui.NetworkConnection))
        else:
            raise uidatahelpers.FormDataError('interface_count is neither oneif nor twoif.')
            
        # Internet connection
        ic_fda = fda.descend('ic_group')
        ic_root.setS(ns_ui.interface, rdf.String, ic_fda['if'])
        _save_ip_address(ic_root, ic_fda)
        uidatahelpers.save_optional_field_to_rdf(ic_root, ns_ui.defaultGateway, rdf.IPv4Address, ic_fda, 'default_gateway')
        ic_root.setS(ns_ui.mtu, rdf.Integer, int(ic_fda['mtu']))
        uidatahelpers.save_optional_field_to_rdf(ic_root, ns_ui.vpnUplink, rdf.Float, ic_fda, 'uplink')
        _save_client_traffic(ic_root, ic_fda)
               
        # Private network connection, fill if exists.
        if not(pn_root is None):
            pn_fda = fda.descend('pn_group')
            pn_root.setS(ns_ui.interface, rdf.String, pn_fda['if'])
            _save_ip_address(pn_root, pn_fda)
            uidatahelpers.save_optional_field_to_rdf(pn_root, ns_ui.defaultGateway, rdf.IPv4Address, pn_fda, 'default_gateway')
            _save_client_traffic(pn_root, pn_fda)  
                
        # DNS Servers
        dns_fda = fda.descend('dns_group')
        if dns_fda['dns_selection'] == 'use_dhcp_ic':
            dns_root = ui_root.setS(ns_ui.dnsServers, rdf.Type(ns_ui.InternetConnectionDhcp))
        elif dns_fda['dns_selection'] == 'use_dhcp_pn':
            dns_root = ui_root.setS(ns_ui.dnsServers, rdf.Type(ns_ui.PrivateNetworkConnectionDhcp))
        elif dns_fda['dns_selection'] == 'set_manually':
            dns_root = ui_root.setS(ns_ui.dnsServers, rdf.Type(ns_ui.SetDnsServers))

            # XXX: dns_1 is not really optional here; we should not save dns_2 if we don't have dns_1, it makes no sense
            uidatahelpers.save_optional_field_to_rdf(dns_root, ns_ui.primaryDns, rdf.IPv4Address, dns_fda, 'dns_1')
            uidatahelpers.save_optional_field_to_rdf(dns_root, ns_ui.secondaryDns, rdf.IPv4Address, dns_fda, 'dns_2')

        # Dyndns
        ddns_fda = fda.descend('ddns_group')
        if uidatahelpers.has_form_value(ddns_fda, 'ddns_provider') and \
           (ddns_fda['ddns_provider'] != 'none'):
            ddns_root = ui_root.setS(ns_ui.dynDnsServer, rdf.Type(ns_ui.DynDnsServer))
            ddns_root.setS(ns_ui.dynDnsProvider, rdf.String, ddns_fda['ddns_provider'])
            ddns_root.setS(ns_ui.dynDnsUsername, rdf.String, ddns_fda['ddns_username'])
            ddns_root.setS(ns_ui.dynDnsPassword, rdf.String, ddns_fda['ddns_password'])
            ddns_root.setS(ns_ui.dynDnsHostname, rdf.String, ddns_fda['ddns_hostname'])
            
            tmp = ddns_fda['ddns_address_type']
            if tmp == 'interface':
                ddns_root.setS(ns_ui.dynDnsAddress, rdf.String, '')
            elif tmp == 'natted':
                ddns_root.setS(ns_ui.dynDnsAddress, rdf.String, 'natted')
            elif tmp == 'static':
                if (ddns_fda.has_key('ddns_address')) and \
                       (ddns_fda['ddns_address'] is not None) and \
                       (ddns_fda['ddns_address'] != ''):
                    ddns_root.setS(ns_ui.dynDnsAddress, rdf.String, ddns_fda['ddns_address'])
                else:
                    ddns_root.setS(ns_ui.dynDnsAddress, rdf.String, '')            
        else:
            ui_root.removeNodes(ns_ui.dynDnsServer)