From 46bc6e545a17e77202aaf01ec0cd8d5a46567525 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Tue, 25 Aug 2015 08:08:24 -0300 Subject: Move main pfSense content to src/ --- .../local/www/services_captiveportal_vouchers.php | 715 +++++++++++++++++++++ 1 file changed, 715 insertions(+) create mode 100644 src/usr/local/www/services_captiveportal_vouchers.php (limited to 'src/usr/local/www/services_captiveportal_vouchers.php') diff --git a/src/usr/local/www/services_captiveportal_vouchers.php b/src/usr/local/www/services_captiveportal_vouchers.php new file mode 100644 index 0000000..0bc7dae --- /dev/null +++ b/src/usr/local/www/services_captiveportal_vouchers.php @@ -0,0 +1,715 @@ + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ +/* + pfSense_BUILDER_BINARIES: /usr/local/bin/voucher /usr/bin/openssl + pfSense_MODULE: captiveportal +*/ + +##|+PRIV +##|*IDENT=page-services-captiveportal-vouchers +##|*NAME=Services: Captive portal Vouchers page +##|*DESCR=Allow access to the 'Services: Captive portal Vouchers' page. +##|*MATCH=services_captiveportal_vouchers.php* +##|-PRIV + +if ($_POST['postafterlogin']) { + $nocsrf= true; +} + +require("guiconfig.inc"); +require("functions.inc"); +require_once("filter.inc"); +require("shaper.inc"); +require("captiveportal.inc"); +require_once("voucher.inc"); + +if (isset($_POST['referer'])) { + $referer = $_POST['referer']; +} else { + $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_captiveportal_vouchers.php'); +} + +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) { + $cpzone = $_POST['zone']; +} + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + +if ($_REQUEST['generatekey']) { + exec("/usr/bin/openssl genrsa 64 > /tmp/key64.private"); + exec("/usr/bin/openssl rsa -pubout < /tmp/key64.private > /tmp/key64.public"); + $privatekey = str_replace("\n", "\\n", file_get_contents("/tmp/key64.private")); + $publickey = str_replace("\n", "\\n", file_get_contents("/tmp/key64.public")); + exec("rm /tmp/key64.private /tmp/key64.public"); + $alertmessage = gettext("You will need to recreate any existing Voucher Rolls due to the public and private key changes. Click cancel if you do not wish to recreate the vouchers."); + echo << 0)) { + $input_errors[] = gettext("Double quotes aren't allowed."); + } + if ($_POST['charset'] && (strpos($_POST['charset'], ",") > 0)) { + $input_errors[] = "',' " . gettext("aren't allowed."); + } + if ($_POST['rollbits'] && (!is_numeric($_POST['rollbits']) || ($_POST['rollbits'] < 1) || ($_POST['rollbits'] > 31))) { + $input_errors[] = gettext("# of Bits to store Roll Id needs to be between 1..31."); + } + if ($_POST['ticketbits'] && (!is_numeric($_POST['ticketbits']) || ($_POST['ticketbits'] < 1) || ($_POST['ticketbits'] > 16))) { + $input_errors[] = gettext("# of Bits to store Ticket Id needs to be between 1..16."); + } + if ($_POST['checksumbits'] && (!is_numeric($_POST['checksumbits']) || ($_POST['checksumbits'] < 1) || ($_POST['checksumbits'] > 31))) { + $input_errors[] = gettext("# of Bits to store checksum needs to be between 1..31."); + } + if ($_POST['publickey'] && (!strstr($_POST['publickey'], "BEGIN PUBLIC KEY"))) { + $input_errors[] = gettext("This doesn't look like an RSA Public key."); + } + if ($_POST['privatekey'] && (!strstr($_POST['privatekey'], "BEGIN RSA PRIVATE KEY"))) { + $input_errors[] = gettext("This doesn't look like an RSA Private key."); + } + if ($_POST['vouchersyncdbip'] && (is_ipaddr_configured($_POST['vouchersyncdbip']))) { + $input_errors[] = gettext("You cannot sync the voucher database to this host (itself)."); + } + } + + if (!$input_errors) { + if (empty($config['voucher'][$cpzone])) { + $newvoucher = array(); + } else { + $newvoucher = $config['voucher'][$cpzone]; + } + if ($_POST['enable'] == "yes") { + $newvoucher['enable'] = true; + } else { + unset($newvoucher['enable']); + } + if (empty($_POST['vouchersyncusername'])) { + unset($newvoucher['vouchersyncdbip']); + unset($newvoucher['vouchersyncport']); + unset($newvoucher['vouchersyncusername']); + unset($newvoucher['vouchersyncpass']); + $newvoucher['charset'] = $_POST['charset']; + $newvoucher['rollbits'] = $_POST['rollbits']; + $newvoucher['ticketbits'] = $_POST['ticketbits']; + $newvoucher['checksumbits'] = $_POST['checksumbits']; + $newvoucher['magic'] = $_POST['magic']; + $newvoucher['exponent'] = $_POST['exponent']; + $newvoucher['publickey'] = base64_encode($_POST['publickey']); + $newvoucher['privatekey'] = base64_encode($_POST['privatekey']); + $newvoucher['descrmsgnoaccess'] = $_POST['msgnoaccess']; + $newvoucher['descrmsgexpired'] = $_POST['msgexpired']; + $config['voucher'][$cpzone] = $newvoucher; + write_config(); + voucher_configure_zone(); + } else { + $newvoucher['vouchersyncdbip'] = $_POST['vouchersyncdbip']; + $newvoucher['vouchersyncport'] = $_POST['vouchersyncport']; + $newvoucher['vouchersyncusername'] = $_POST['vouchersyncusername']; + $newvoucher['vouchersyncpass'] = $_POST['vouchersyncpass']; + if ($newvoucher['vouchersyncpass'] && $newvoucher['vouchersyncusername'] && + $newvoucher['vouchersyncport'] && $newvoucher['vouchersyncdbip']) { + // Synchronize the voucher DB from the master node + require_once("xmlrpc.inc"); + + $protocol = "http"; + if (is_array($config['system']) && is_array($config['system']['webgui']) && !empty($config['system']['webgui']['protocol']) && + $config['system']['webgui']['protocol'] == "https") { + $protocol = "https"; + } + if ($protocol == "https" || $newvoucher['vouchersyncport'] == "443") { + $url = "https://{$newvoucher['vouchersyncdbip']}"; + } else { + $url = "http://{$newvoucher['vouchersyncdbip']}"; + } + + $execcmd = <<setCredentials($newvoucher['vouchersyncusername'], $newvoucher['vouchersyncpass']); + $resp = $cli->send($msg, "250"); + if (!is_object($resp)) { + $error = "A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} (pfsense.exec_php)."; + log_error($error); + file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", ""); + $input_errors[] = $error; + } elseif ($resp->faultCode()) { + $cli->setDebug(1); + $resp = $cli->send($msg, "250"); + $error = "An error code was received while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString(); + log_error($error); + file_notice("CaptivePortalVoucherSync", $error, "Error code received", ""); + $input_errors[] = $error; + } else { + log_error("The Captive Portal voucher database has been synchronized with {$url}:{$port} (pfsense.exec_php)."); + } + if (!$input_errors) { + $toreturn = XML_RPC_Decode($resp->value()); + if (!is_array($toreturn)) { + if ($toreturn == "Authentication failed") { + $input_errors[] = "Could not synchronize the voucher database: Authentication Failed."; + } + } else { + // If we received back the voucher roll and other information then store it. + if ($toreturn['voucher']['roll']) { + $newvoucher['roll'] = $toreturn['voucher']['roll']; + } + if ($toreturn['voucher']['rollbits']) { + $newvoucher['rollbits'] = $toreturn['voucher']['rollbits']; + } + if ($toreturn['voucher']['ticketbits']) { + $newvoucher['ticketbits'] = $toreturn['voucher']['ticketbits']; + } + if ($toreturn['voucher']['checksumbits']) { + $newvoucher['checksumbits'] = $toreturn['voucher']['checksumbits']; + } + if ($toreturn['voucher']['magic']) { + $newvoucher['magic'] = $toreturn['voucher']['magic']; + } + if ($toreturn['voucher']['exponent']) { + $newvoucher['exponent'] = $toreturn['voucher']['exponent']; + } + if ($toreturn['voucher']['publickey']) { + $newvoucher['publickey'] = $toreturn['voucher']['publickey']; + } + if ($toreturn['voucher']['privatekey']) { + $newvoucher['privatekey'] = $toreturn['voucher']['privatekey']; + } + if ($toreturn['voucher']['descrmsgnoaccess']) { + $newvoucher['descrmsgnoaccess'] = $toreturn['voucher']['descrmsgnoaccess']; + } + if ($toreturn['voucher']['descrmsgexpired']) { + $newvoucher['descrmsgexpired'] = $toreturn['voucher']['descrmsgexpired']; + } + $savemsg = gettext("Voucher database has been synchronized from {$url}:{$port}"); + + $config['voucher'][$cpzone] = $newvoucher; + write_config(); + voucher_configure_zone(true); + } + } + } + } + if (!$input_errors) { + header("Location: services_captiveportal_vouchers.php?zone={$cpzone}"); + exit; + } + } +} +$closehead = false; +include("head.inc"); +?> + + + + + + +
+ + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  + onclick="enable_change(false)" /> + +
+ + (Synchronized from {$pconfig['vouchersyncdbip']})"; + } + ?> + + + + + + + + + + + + + + + + + + + + +
\""
"; + } + ?> + +
##
+   + +   + +   + +   + + +
+ + + + + +
+ + + +
+ . +
+ +
+ . +
+ +
+ +
# + +
+ +
# + +
+ +
# + +
+ +
+ +
+ +
+ +
($PORTAL_MESSAGE$). +
+ +
($PORTAL_MESSAGE$). +
  +   +
+ +
+
+
+ +
+
+ +
+
+ +
+
  + + + " onclick="enable_change(true); before_save();" /> + " onclick="window.location.href=''" /> + +
+

+
+ +
+ +

+
+
+
+ + + + -- cgit v1.1