From 4d1afb6ab23c1ae8e90209b6988cba17e4b38721 Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 1 Mar 2011 12:10:00 -0500 Subject: Finish up shared key client export (for non-pfsense clients) --- .../openvpn-client-export.inc | 12 + .../openvpn-client-export.xml | 12 +- .../openvpn-client-export/vpn_openvpn_export.php | 1 + .../vpn_openvpn_export_shared.php | 445 +++++++++++++++++++++ 4 files changed, 469 insertions(+), 1 deletion(-) create mode 100644 config/openvpn-client-export/vpn_openvpn_export_shared.php (limited to 'config') diff --git a/config/openvpn-client-export/openvpn-client-export.inc b/config/openvpn-client-export/openvpn-client-export.inc index 3e8038e4..49ed4ca6 100755 --- a/config/openvpn-client-export/openvpn-client-export.inc +++ b/config/openvpn-client-export/openvpn-client-export.inc @@ -51,10 +51,12 @@ function openvpn_client_export_install() { function openvpn_client_export_deinstall() { conf_mount_rw(); $phpfile = "vpn_openvpn_export.php"; + $phpfile2 = "vpn_openvpn_export_shared.php"; $ovpndir = "/usr/local/share/openvpn"; $workdir = "{$ovpndir}/client-export"; unlink_if_exists("/usr/local/www/{$phpfile}"); + unlink_if_exists("/usr/local/www/{$phpfile2}"); exec("/bin/rm -r {$workdir}"); conf_mount_ro(); } @@ -548,6 +550,16 @@ function openvpn_client_export_sharedkey_config($srvid, $useaddr, $proxy, $zipco $mask = gen_subnet_mask($mask); $conf .= "route $ip $mask\n"; } + if (!empty($settings['tunnel_network'])) { + list($ip, $mask) = explode('/', $settings['tunnel_network']); + $mask = gen_subnet_mask($mask); + $baselong = ip2long32($ip) & ip2long($mask); + $ip1 = long2ip32($baselong + 1); + $ip2 = long2ip32($baselong + 2); + $conf .= "ifconfig $ip2 $ip1\n"; + } + $conf .= "keepalive 10 60\n"; + $conf .= "ping-timer-rem\n"; if (!empty($proxy)) { if ($proto == "udp") { diff --git a/config/openvpn-client-export/openvpn-client-export.xml b/config/openvpn-client-export/openvpn-client-export.xml index cf163a20..9e0973f0 100755 --- a/config/openvpn-client-export/openvpn-client-export.xml +++ b/config/openvpn-client-export/openvpn-client-export.xml @@ -1,7 +1,7 @@ OpenVPN Client Export - 0.3 + 0.6 OpenVPN Client Export /usr/local/pkg/openvpn-client-export.inc @@ -13,6 +13,11 @@ OpenVPN /vpn_openvpn_export.php + + Shared Key Export + OpenVPN + /vpn_openvpn_export_shared.php + /usr/local/pkg/ @@ -29,6 +34,11 @@ 077 http://www.pfsense.com/packages/config/openvpn-client-export/vpn_openvpn_export.php + + /usr/local/www/ + 077 + http://www.pfsense.com/packages/config/openvpn-client-export/vpn_openvpn_export_shared.php + openvpn_client_export_install(); diff --git a/config/openvpn-client-export/vpn_openvpn_export.php b/config/openvpn-client-export/vpn_openvpn_export.php index 73833fbe..01a0507a 100755 --- a/config/openvpn-client-export/vpn_openvpn_export.php +++ b/config/openvpn-client-export/vpn_openvpn_export.php @@ -537,6 +537,7 @@ function useproxy_changed(obj) { $tab_array[] = array(gettext("Client Specific Overrides"), false, "vpn_openvpn_csc.php"); $tab_array[] = array(gettext("Wizards"), false, "wizard.php?xml=openvpn_wizard.xml"); $tab_array[] = array(gettext("Client Export"), true, "vpn_openvpn_export.php"); + $tab_array[] = array(gettext("Shared Key Export"), false, "vpn_openvpn_export_shared.php"); display_top_tabs($tab_array); ?> diff --git a/config/openvpn-client-export/vpn_openvpn_export_shared.php b/config/openvpn-client-export/vpn_openvpn_export_shared.php new file mode 100644 index 00000000..95cc37bd --- /dev/null +++ b/config/openvpn-client-export/vpn_openvpn_export_shared.php @@ -0,0 +1,445 @@ + $server) { + if (isset($server['disable'])) + continue; + $ras_user = array(); + if ($server['mode'] != "p2p_shared_key") + continue; + + $ras_serverent = array(); + $prot = $server['protocol']; + $port = $server['local_port']; + if ($server['description']) + $name = "{$server['description']} {$prot}:{$port}"; + else + $name = "Shared Key Server {$prot}:{$port}"; + $ras_serverent['index'] = $sindex; + $ras_serverent['name'] = $name; + $ras_server[] = $ras_serverent; +} + +$id = $_GET['id']; +if (isset($_POST['id'])) + $id = $_POST['id']; + +$act = $_GET['act']; +if (isset($_POST['act'])) + $act = $_POST['act']; + +$error = false; + +if(($act == "skconf") || ($act == "skzipconf")) { + $srvid = $_GET['srvid']; + if (($srvid === false) || ($config['openvpn']['openvpn-server'][$srvid]['mode'] != "p2p_shared_key")) { + pfSenseHeader("vpn_openvpn_export.php"); + exit; + } + + if (empty($_GET['useaddr'])) { + $error = true; + $input_errors[] = "You need to specify an IP or hostname."; + } else + $useaddr = $_GET['useaddr']; + + $proxy = ""; + if (!empty($_GET['proxy_addr']) || !empty($_GET['proxy_port'])) { + $proxy = array(); + if (empty($_GET['proxy_addr'])) { + $error = true; + $input_errors[] = "You need to specify an address for the proxy port."; + } else + $proxy['ip'] = $_GET['proxy_addr']; + if (empty($_GET['proxy_port'])) { + $error = true; + $input_errors[] = "You need to specify a port for the proxy ip."; + } else + $proxy['port'] = $_GET['proxy_port']; + $proxy['proxy_authtype'] = $_GET['proxy_authtype']; + if ($_GET['proxy_authtype'] != "none") { + if (empty($_GET['proxy_user'])) { + $error = true; + $input_errors[] = "You need to specify a username with the proxy config."; + } else + $proxy['user'] = $_GET['proxy_user']; + if (!empty($_GET['proxy_user']) && empty($_GET['proxy_password'])) { + $error = true; + $input_errors[] = "You need to specify a password with the proxy user."; + } else + $proxy['password'] = $_GET['proxy_password']; + } + } + + $exp_name = openvpn_client_export_prefix($srvid); + if ($act == "skzipconf") + $zipconf = true; + $exp_data = openvpn_client_export_sharedkey_config($srvid, $useaddr, $proxy, $zipconf); + if (!$exp_data) { + $input_errors[] = "Failed to export config files!"; + $error = true; + } + if (!$error) { + if ($zipconf) { + $exp_name = urlencode($exp_data); + $exp_size = filesize("{$g['tmp_path']}/{$exp_data}"); + } else { + $exp_name = urlencode($exp_name."-config.ovpn"); + $exp_size = strlen($exp_data); + } + + header('Pragma: '); + header('Cache-Control: '); + header("Content-Type: application/octet-stream"); + header("Content-Disposition: attachment; filename={$exp_name}"); + header("Content-Length: $exp_size"); + if ($zipconf) + readfile("{$g['tmp_path']}/{$exp_data}"); + else + echo $exp_data; + + @unlink("{$g['tmp_path']}/{$exp_data}"); + exit; + } +} + +include("head.inc"); + +?> + + + + + + + + + + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + +
Shared Key Server + +
Host Name Resolution + + + + +
+ +
+ +
+
Use HTTP Proxy + + + + + +
+ + + + + Use HTTP proxy to communicate with the server. + +
+ + + + + + + + +
+ + + + + +
 
Client Configuration Packages
+ + + + + +
+ + + + + +
+
+
+ + + -- cgit v1.2.3