"; } if($_GET['act']=="new"){ $pconfig['autokey_enable'] = "yes"; $pconfig['tlsauth_enable'] = "yes"; $pconfig['autotls_enable'] = "yes"; $pconfig['dh_length'] = 1024; $pconfig['interface'] = "wan"; $pconfig['local_port'] = openvpn_port_next('UDP'); $pconfig['pool_enable'] = "yes"; } if($_GET['act']=="edit"){ if (isset($id) && $a_server[$id]) { $pconfig['disable'] = $a_server[$id]['disable']; $pconfig['mode'] = $a_server[$id]['mode']; $pconfig['protocol'] = $a_server[$id]['protocol']; $pconfig['interface'] = $a_server[$id]['interface']; $pconfig['local_port'] = $a_server[$id]['local_port']; $pconfig['description'] = $a_server[$id]['description']; if ($pconfig['mode'] != "p2p_shared_key") { if ($a_server[$id]['tls']) { $pconfig['tlsauth_enable'] = "yes"; $pconfig['tls'] = base64_decode($a_server[$id]['tls']); } $pconfig['caref'] = $a_server[$id]['caref']; $pconfig['certref'] = $a_server[$id]['certref']; $pconfig['dh_length'] = $a_server[$id]['dh_length']; } else $pconfig['shared_key'] = base64_decode($a_server[$id]['shared_key']); $pconfig['crypto'] = $a_server[$id]['crypto']; $pconfig['tunnel_network'] = $a_server[$id]['tunnel_network']; $pconfig['remote_network'] = $a_server[$id]['remote_network']; $pconfig['gwredir'] = $a_server[$id]['gwredir']; $pconfig['local_network'] = $a_server[$id]['local_network']; $pconfig['maxclients'] = $a_server[$id]['maxclients']; $pconfig['compression'] = $a_server[$id]['compression']; $pconfig['passtos'] = $a_server[$id]['passtos']; $pconfig['client2client'] = $a_server[$id]['client2client']; $pconfig['pool_enable'] = $a_server[$id]['pool_enable']; $pconfig['dns_domain'] = $a_server[$id]['dns_domain']; if ($pconfig['dns_domain']) $pconfig['dns_domain_enable'] = true; $pconfig['dns_server1'] = $a_server[$id]['dns_server1']; $pconfig['dns_server2'] = $a_server[$id]['dns_server2']; $pconfig['dns_server3'] = $a_server[$id]['dns_server3']; $pconfig['dns_server4'] = $a_server[$id]['dns_server4']; if ($pconfig['dns_server1'] || $pconfig['dns_server2'] || $pconfig['dns_server3'] || $pconfig['dns_server4']) $pconfig['dns_server_enable'] = true; $pconfig['ntp_server1'] = $a_server[$id]['ntp_server1']; $pconfig['ntp_server2'] = $a_server[$id]['ntp_server2']; if ($pconfig['ntp_server1'] || $pconfig['ntp_server2']) $pconfig['ntp_server_enable'] = true; $pconfig['netbios_enable'] = $a_server[$id]['netbios_enable']; $pconfig['netbios_ntype'] = $a_server[$id]['netbios_ntype']; $pconfig['netbios_scope'] = $a_server[$id]['netbios_scope']; $pconfig['wins_server1'] = $a_server[$id]['wins_server1']; $pconfig['wins_server2'] = $a_server[$id]['wins_server2']; if ($pconfig['wins_server1'] || $pconfig['wins_server2']) $pconfig['wins_server_enable'] = true; $pconfig['nbdd_server1'] = $a_server[$id]['nbdd_server1']; if ($pconfig['nbdd_server1']) $pconfig['nbdd_server_enable'] = true; // just in case the modes switch $pconfig['autokey_enable'] = "yes"; $pconfig['autotls_enable'] = "yes"; } } if ($_POST) { unset($input_errors); $pconfig = $_POST; if (isset($id) && $a_server[$id]) $vpnid = $a_server[$id]['vpnid']; else $vpnid = 0; if ($server['mode'] != "p2p_shared_key") $tls_mode = true; else $tls_mode = false; /* input validation */ if ($result = openvpn_validate_port($pconfig['local_port'], 'Local port')) $input_errors[] = $result; if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network')) $input_errors[] = $result; if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'Remote network')) $input_errors[] = $result; if ($result = openvpn_validate_cidr($pconfig['local_network'], 'Local network')) $input_errors[] = $result; if (openvpn_port_used($pconfig['protocol'], $pconfig['local_port']) != $vpnid) $input_errors[] = "The specified 'Local port' is in use. Please select another value"; if (!$tls_mode && !$pconfig['autokey_enable']) if (!strstr($pconfig['shared_key'], "-----BEGIN OpenVPN Static key V1-----") || !strstr($pconfig['shared_key'], "-----END OpenVPN Static key V1-----")) $input_errors[] = "The field 'Shared Key' does not appear to be valid"; if ($tls_mode && $pconfig['tlsauth_enable'] && !$pconfig['autotls_enable']) if (!strstr($pconfig['tls'], "-----BEGIN OpenVPN Static key V1-----") || !strstr($pconfig['tls'], "-----END OpenVPN Static key V1-----")) $input_errors[] = "The field 'TLS Authentication Key' does not appear to be valid"; if ($pconfig['dns_server_enable']) { if (!empty($pconfig['dns_server1']) && !is_ipaddr(trim($pconfig['dns_server1']))) $input_errors[] = "The field 'DNS Server #1' must contain a valid IP address"; if (!empty($pconfig['dns_server2']) && !is_ipaddr(trim($pconfig['dns_server2']))) $input_errors[] = "The field 'DNS Server #2' must contain a valid IP address"; if (!empty($pconfig['dns_server3']) && !is_ipaddr(trim($pconfig['dns_server3']))) $input_errors[] = "The field 'DNS Server #3' must contain a valid IP address"; if (!empty($pconfig['dns_server4']) && !is_ipaddr(trim($pconfig['dns_server4']))) $input_errors[] = "The field 'DNS Server #4' must contain a valid IP address"; } if ($pconfig['ntp_server_enable']) { if (!empty($pconfig['ntp_server1']) && !is_ipaddr(trim($pconfig['ntp_server1']))) $input_errors[] = "The field 'NTP Server #1' must contain a valid IP address"; if (!empty($pconfig['ntp_server2']) && !is_ipaddr(trim($pconfig['ntp_server2']))) $input_errors[] = "The field 'NTP Server #2' must contain a valid IP address"; if (!empty($pconfig['ntp_server3']) && !is_ipaddr(trim($pconfig['ntp_server3']))) $input_errors[] = "The field 'NTP Server #3' must contain a valid IP address"; if (!empty($pconfig['ntp_server4']) && !is_ipaddr(trim($pconfig['ntp_server4']))) $input_errors[] = "The field 'NTP Server #4' must contain a valid IP address"; } if ($pconfig['netbios_enable']) { if ($pconfig['wins_server_enable']) { if (!empty($pconfig['wins_server1']) && !is_ipaddr(trim($pconfig['wins_server1']))) $input_errors[] = "The field 'WINS Server #1' must contain a valid IP address"; if (!empty($pconfig['wins_server2']) && !is_ipaddr(trim($pconfig['wins_server2']))) $input_errors[] = "The field 'WINS Server #2' must contain a valid IP address"; } if ($pconfig['nbdd_server_enable']) if (!empty($pconfig['nbdd_server1']) && !is_ipaddr(trim($pconfig['nbdd_server1']))) $input_errors[] = "The field 'NetBIOS Data Distribution Server #1' must contain a valid IP address"; } if ($pconfig['maxclients'] && !is_numeric($pconfig['maxclients'])) $input_errors[] = "The field 'Concurrent connections' must be numeric."; if (!$tls_mode) { $reqdfields = array('shared_key'); $reqfieldsn = array('Shared key'); } else { $reqdfields = explode(" ", "caref certref"); $reqdfieldsn = explode(",", "Certificate Authority,Certificate");; } $reqdfields[] = 'tunnel_network'; $reqdfieldsn[] = 'Tunnel network'; do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if (!$input_errors) { $server = array(); if ($vpnid) $server['vpnid'] = $vpnid; else $server['vpnid'] = openvpn_vpnid_next(); $server['disable'] = $pconfig['disable']; $server['mode'] = $pconfig['mode']; $server['protocol'] = $pconfig['protocol']; $server['interface'] = $pconfig['interface']; $server['local_port'] = $pconfig['local_port']; $server['description'] = $pconfig['description']; if ($tls_mode) { if ($pconfig['tlsauth_enable']) { if ($pconfig['autotls_enable']) $pconfig['tls'] = openvpn_create_key(); $server['tls'] = base64_encode($pconfig['tls']); } $server['caref'] = $pconfig['caref']; $server['certref'] = $pconfig['certref']; $server['dh_length'] = $pconfig['dh_length']; } else { if ($pconfig['autokey_enable']) $pconfig['shared_key'] = openvpn_create_key(); $server['shared_key'] = base64_encode($pconfig['shared_key']); } $server['crypto'] = $pconfig['crypto']; $server['tunnel_network'] = $pconfig['tunnel_network']; $server['remote_network'] = $pconfig['remote_network']; $server['gwredir'] = $pconfig['gwredir']; $server['local_network'] = $pconfig['local_network']; $server['maxclients'] = $pconfig['maxclients']; $server['compression'] = $pconfig['compression']; $server['passtos'] = $pconfig['passtos']; $server['client2client'] = $pconfig['client2client']; $server['pool_enable'] = $pconfig['pool_enable']; if ($pconfig['dns_domain_enable']) $server['dns_domain'] = $pconfig['dns_domain']; if ($pconfig['dns_server_enable']) { $server['dns_server1'] = $pconfig['dns_server1']; $server['dns_server2'] = $pconfig['dns_server2']; $server['dns_server3'] = $pconfig['dns_server3']; $server['dns_server4'] = $pconfig['dns_server4']; } if ($pconfig['ntp_server_enable']) { $server['ntp_server1'] = $pconfig['ntp_server1']; $server['ntp_server2'] = $pconfig['ntp_server2']; } $server['netbios_enable'] = $pconfig['netbios_enable']; $server['netbios_ntype'] = $pconfig['netbios_ntype']; $server['netbios_scope'] = $pconfig['netbios_scope']; if ($pconfig['netbios_enable']) { if ($pconfig['wins_server_enable']) { $server['wins_server1'] = $pconfig['wins_server1']; $server['wins_server2'] = $pconfig['wins_server2']; } if ($pconfig['dns_server_enable']) $server['nbdd_server1'] = $pconfig['nbdd_server1']; } if (isset($id) && $a_server[$id]) $a_server[$id] = $server; else $a_server[] = $server; openvpn_resync('server', $server); write_config(); header("Location: vpn_openvpn_server.php"); exit; } } include("head.inc"); ?>
">