Description:

This script creates a client access for the Advanced VPN Client based on the specified information. After executing the script, an  .ini  file is offered for download.

List of used variables:

VariableDescription




Add-in code:

/**
 * @param {Config} config
 * @param {Context} context
 * Do not edit this comment or parameter types. Required for code suggestions
*/
exports.main = function (config, context) {



    // Function to set Authentication Parameter
    var addVPNAuth = function (AuthName, LocalAuth, LocalIDType, LocalID, LocalPWD, RemoteAuth, RemoteIDType, RemoteID, RemotePWD) {
        var TableAUTH = config.getTableByOid("1.2.19.36.3.1");
        var TableAUTH_row = TableAUTH.createNewRow();
        TableAUTH_row.setByOid("1", AuthName);
        TableAUTH_row.setByOid("2", LocalAuth);
        TableAUTH_row.setByOid("3", LocalIDType);
        TableAUTH_row.setByOid("4", LocalID);
        TableAUTH_row.setByOid("5", LocalPWD);
        TableAUTH_row.setByOid("6", RemoteAuth);
        TableAUTH_row.setByOid("7", RemoteIDType);
        TableAUTH_row.setByOid("8", RemoteID);
        TableAUTH_row.setByOid("9", RemotePWD);
        TableAUTH.addOrMerge(TableAUTH_row);
    };
    // Function to create IPv4 Address Pool
    var addVPNPool = function (PoolName, StartAddr, EndAddr, PrimaryDNS) {
        var TableIPv4Pool = config.getTableByOid("1.2.19.36.7.1");
        var TableIPv4Pool_row = TableIPv4Pool.createNewRow();
        TableIPv4Pool_row.setByOid("1", PoolName);
        TableIPv4Pool_row.setByOid("2", StartAddr);
        TableIPv4Pool_row.setByOid("3", EndAddr);
        TableIPv4Pool_row.setByOid("4", PrimaryDNS);
        TableIPv4Pool.addOrMerge(TableIPv4Pool_row);
    };
    // Function to create VPN Peer
    var addVPNPeer = function (PeerName, EntryActive, RemoteGW, Auth, IKEcfgMode, IPv4Pool, RuleCreate, VPNRule) {
        var TableVPNPeer = config.getTableByOid("1.2.19.36.1");
        var TableVPNPeer_row = TableVPNPeer.createNewRow();
        TableVPNPeer_row.setByOid("1", PeerName);
        TableVPNPeer_row.setByOid("2", EntryActive);
        TableVPNPeer_row.setByOid("4", RemoteGW);
        TableVPNPeer_row.setByOid("7", Auth);
        TableVPNPeer_row.setByOid("10", IKEcfgMode);
        TableVPNPeer_row.setByOid("18", IPv4Pool);
        TableVPNPeer_row.setByOid("11", RuleCreate);
        TableVPNPeer_row.setByOid("12", VPNRule);
        TableVPNPeer.addOrMerge(TableVPNPeer_row);
    };

    // Variables
    var clientOS = context.vars.V1_clientOS;                            // Operating System of the Client PC (only affects .ini file)
    var peer = context.vars.V2_vpnPeer;                                    // Name of the VPN Peer
    var wanIp = context.vars.V3_wanIP;                                    // Public IP-Address of the VPN Gateway
    var pwd = Math.random().toString(36).slice(-8);                        // Randomly generated Password
    var poolStart = context.vars.V4_IPv4firstAddress;                    // First Address of IPv4 Address Pool
    var poolEnd = context.vars.V5_IPv4lastAddress;                        // Last Address of IPv4 Address Pool
    var poolDNS = context.vars.V6_IPv4Nameserver;                       // Nameserver of IPv4 Address Pool
    var splitTunnelIp = context.vars.V7_SplitTunnelingIP;                 // Split Tunneling IP Address (only affects .ini file)
    var splitTunnelMask = context.vars.V8_SplitTunnelingNetmask;        // Split Tunneling Netmask (only affects .ini file)

    // Global Configuration
    config.setScalarByOid("1.2.19.8", "1");                         // Set VPN to Operating
    config.setScalarByOid("1.2.19.27", "1");                         // Accept IPSec-over-HTTPS
    config.setScalarByOid("1.2.8.5", "1");                            // Activate Proxy ARP
    var outputStream = config.createOutputStream();
    var vpnINI = config.createOutputStream(peer + '.ini');

    // Peer Configuration

    addVPNAuth(peer, "PSK", "Email-Address", peer + "@intern", pwd, "PSK", "Email-Address", peer + "@intern", pwd);

    var tablePool = config.getTableByOid("1.2.19.36.7.1");
    var row = tablePool.getFirstRowByOids({ "2": poolStart }) || tablePool.getFirstRowByOids({ "3": poolEnd });

    if (row) {
        // IPv4 Pool = true
        var pool = row.getByOid("1");
        addVPNPeer(peer, "1", "0.0.0.0", peer, "2", pool, "1", "RAS-WITH-CONFIG-PAYLOAD");
    } else {
        // IPv4-Pool != true
        addVPNPool(peer + "-Pool", poolStart, poolEnd, poolDNS);
        addVPNPeer(peer, "1", "0.0.0.0", peer, "2", peer + "-Pool", "1", "RAS-WITH-CONFIG-PAYLOAD");
    }

    outputStream.addLine('Die VPN-Verbindung konnte erfolgreich angelegt werden.');
    outputStream.addLine('Bitte laden Sie die Datei .ini herunter und importieren Sie diese in den Advanced VPN-Client.');
    // Creation of INI-File
    vpnINI.addLine("[PROFILE1]");
    vpnINI.addLine("Name=" + peer);

    if (clientOS == "windows") {
        vpnINI.addLine("ConnMedia=21");
    } else if (clientOS == "mac") {
        vpnINI.addLine("ConnMedia=8");
    }

    vpnINI.addLine("ConnMode=0");
    vpnINI.addLine("SeamRoaming=1");
    vpnINI.addLine("PriVoIP=1");
    vpnINI.addLine("Gateway=" + wanIp);
    vpnINI.addLine("PFS=14");
    vpnINI.addLine("UseComp=0");
    vpnINI.addLine("IkeIdType=3");
    vpnINI.addLine("IkeIdStr=" + peer + "@intern");
    vpnINI.addLine("Secret=" + pwd);
    vpnINI.addLine("UseXAUTH=0");
    vpnINI.addLine("IpAddrAssign=0");
    vpnINI.addLine("IkeDhGroup=14");
    vpnINI.addLine("ExchMode=34");
    vpnINI.addLine("IKEv2Auth=2");
    vpnINI.addLine("IKEv2Policy=WIZ-AES256-SHA256");
    vpnINI.addLine("IPSEC-Policy=WIZ-AES256-SHA256");

    if (splitTunnelIp && splitTunnelMask) {
        vpnINI.addLine("Network1=" + splitTunnelIp);
        vpnINI.addLine("SubMask1=" + splitTunnelMask);
    }

    vpnINI.addLine("[IKEV2POLICY1]");
    vpnINI.addLine("Ikev2Name=WIZ-AES256-SHA256");
    vpnINI.addLine("Ikev2Crypt=6");
    vpnINI.addLine("Ikev2PRF=5");
    vpnINI.addLine("Ikev2IntAlgo=12");
    vpnINI.addLine("[IPSECPOLICY1]");
    vpnINI.addLine("IPSecName=WIZ-AES256-SHA256");
    vpnINI.addLine("IpsecCrypt=6");
    vpnINI.addLine("IpsecAuth=5");
};

Add-in as JSON file:

creating-advanced-VPNC-access.json