3 // Sets up the Network interface and the routes
6 // --------------------------------------------------------------
8 // --------------------------------------------------------------
17 return (ws.Exec(cmd).StdOut.ReadAll());
20 function getDefaultGateway()
22 if (run("route print").match(/Default Gateway: *(.*)/)) {
28 // --------------------------------------------------------------
30 // --------------------------------------------------------------
32 var internal_ip4_netmask = "255.255.255.0"
34 var ws = WScript.CreateObject("WScript.Shell");
35 var env = ws.Environment("Process");
37 switch (env("reason")) {
41 var gw = getDefaultGateway();
42 echo("VPN Gateway: " + env("VPNGATEWAY"));
43 echo("Internal Address: " + env("INTERNAL_IP4_ADDRESS"));
44 echo("Internal Netmask: " + env("INTERNAL_IP4_NETMASK"));
45 echo("Interface: \"" + env("TUNDEV") + "\"");
47 if (env("INTERNAL_IP4_NETMASK")) {
48 internal_ip4_netmask = env("INTERNAL_IP4_NETMASK");
51 echo("Configuring \"" + env("TUNDEV") + "\" interface...");
52 run("netsh interface ip set address \"" + env("TUNDEV") + "\" static " +
53 env("INTERNAL_IP4_ADDRESS") + " " + internal_ip4_netmask);
55 // Add direct route for the VPN gateway to avoid routing loops
56 run("route add " + env("VPNGATEWAY") +
57 " mask 255.255.255.255 " + gw);
59 if (env("INTERNAL_IP4_NBNS")) {
60 var wins = env("INTERNAL_IP4_NBNS").split(/ /);
61 for (var i = 0; i < wins.length; i++) {
62 run("netsh interface ip add wins \"" +
63 env("TUNDEV") + "\" " + wins[i]
68 if (env("INTERNAL_IP4_DNS")) {
69 var dns = env("INTERNAL_IP4_DNS").split(/ /);
70 for (var i = 0; i < dns.length; i++) {
71 run("netsh interface ip add dns \"" +
72 env("TUNDEV") + "\" " + dns[i]
78 // Add internal network routes
79 echo("Configuring networks:");
80 if (env("CISCO_SPLIT_INC")) {
81 for (var i = 0 ; i < parseInt(env("CISCO_SPLIT_INC")); i++) {
82 var network = env("CISCO_SPLIT_INC_" + i + "_ADDR");
83 var netmask = env("CISCO_SPLIT_INC_" + i + "_MASK");
84 var netmasklen = env("CISCO_SPLIT_INC_" + i +
86 run("route add " + network + " mask " + netmask +
87 " " + env("INTERNAL_IP4_ADDRESS"));
90 echo("Gateway did not provide network configuration.");
92 echo("Route configuration done.");
94 if (env("CISCO_BANNER")) {
95 echo("--------------------------------------------------");
96 echo(env("CISCO_BANNER"));
97 echo("--------------------------------------------------");
101 // Delete direct route for the VPN gateway to avoid
102 run("route delete " + env("VPNGATEWAY") + " mask 255.255.255.255");