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 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 $statusurl = "status_captiveportal_vouchers.php"; $logurl = "diag_logs_auth.php"; require("guiconfig.inc"); require("functions.inc"); require("filter.inc"); require("shaper.inc"); require("captiveportal.inc"); require_once("voucher.inc"); $pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Vouchers")); if (!is_array($config['voucher'])) { $config['voucher'] = array(); } if (!is_array($config['voucher']['roll'])) { $config['voucher']['roll'] = array(); } if (!isset($config['voucher']['charset'])) { $config['voucher']['charset'] = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'; } if (!isset($config['voucher']['rollbits'])) { $config['voucher']['rollbits'] = 16; } if (!isset($config['voucher']['ticketbits'])) { $config['voucher']['ticketbits'] = 10; } if (!isset($config['voucher']['saveinterval'])) { $config['voucher']['saveinterval'] = 300; } if (!isset($config['voucher']['checksumbits'])) { $config['voucher']['checksumbits'] = 5; } if (!isset($config['voucher']['magic'])) { $config['voucher']['magic'] = rand(); // anything slightly random will do } if (!isset($config['voucher']['publickey'])) { /* generate a random 64 bit RSA key pair using the voucher binary */ $fd = popen("/usr/local/bin/voucher -g 64", "r"); if ($fd !== false) { $output = fread($fd, 16384); pclose($fd); list($privkey, $pubkey) = explode("\0", $output); $config['voucher']['publickey'] = base64_encode($pubkey); $config['voucher']['privatekey'] = base64_encode($privkey); } } if (!isset($config['voucher']['msgnoaccess'])) { $config['voucher']['msgnoaccess'] = gettext("Voucher invalid"); } if (!isset($config['voucher']['msgexpired'])) { $config['voucher']['msgexpired'] = gettext("Voucher expired"); } $a_roll = &$config['voucher']['roll']; if ($_GET['act'] == "del") { $id = $_GET['id']; if ($a_roll[$id]) { $roll = $a_roll[$id]['number']; $voucherlck = lock('voucher'); unset($a_roll[$id]); voucher_unlink_db($roll); unlock($voucherlck); write_config(); header("Location: services_captiveportal_vouchers.php"); exit; } } /* print all vouchers of the selected roll */ if ($_GET['act'] == "csv") { $privkey = base64_decode($config['voucher']['privatekey']); if (strstr($privkey,"BEGIN RSA PRIVATE KEY")) { $fd = fopen("{$g['varetc_path']}/voucher.private","w"); if (!$fd) { $input_errors[] = gettext("Cannot write private key file") . ".\n"; } else { chmod("{$g['varetc_path']}/voucher.private", 0600); fwrite($fd, $privkey); fclose($fd); $a_voucher = &$config['voucher']['roll']; $id = $_GET['id']; if (isset($id) && $a_voucher[$id]) { $number = $a_voucher[$id]['number']; $count = $a_voucher[$id]['count']; header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=vouchers_roll$number.csv"); system("/usr/local/bin/voucher -c {$g['varetc_path']}/voucher.cfg -p {$g['varetc_path']}/voucher.private $number $count"); unlink("{$g['varetc_path']}/voucher.private"); exit; } } } else { $input_errors[] = gettext("Need private RSA key to print vouchers") . "\n"; } } $pconfig['enable'] = isset($config['voucher']['enable']); $pconfig['charset'] = $config['voucher']['charset']; $pconfig['rollbits'] = $config['voucher']['rollbits']; $pconfig['ticketbits'] = $config['voucher']['ticketbits']; $pconfig['saveinterval'] = $config['voucher']['saveinterval']; $pconfig['checksumbits'] = $config['voucher']['checksumbits']; $pconfig['magic'] = $config['voucher']['magic']; $pconfig['publickey'] = base64_decode($config['voucher']['publickey']); $pconfig['privatekey'] = base64_decode($config['voucher']['privatekey']); $pconfig['msgnoaccess'] = $config['voucher']['msgnoaccess']; $pconfig['msgexpired'] = $config['voucher']['msgexpired']; if ($_POST) { unset($input_errors); $pconfig = $_POST; /* input validation */ if ($_POST['enable']) { $reqdfields = explode(" ", "charset rollbits ticketbits checksumbits publickey magic saveinterval"); $reqdfieldsn = array(gettext("charset"),gettext("rollbits"),gettext("ticketbits"),gettext("checksumbits"),gettext("publickey"),gettext("magic"),gettext("saveinterval")); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); } if ($_POST['charset'] && (strlen($_POST['charset'] < 2))) { $input_errors[] = gettext("Need at least 2 characters to create vouchers."); } if ($_POST['charset'] && (strpos($_POST['charset'],"\"")>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['saveinterval'] && (!is_numeric($_POST['saveinterval']) || ($_POST['saveinterval'] < 1))) { $input_errors[] = gettext("Save interval in minutes cant be negative."); } 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 (!$input_errors) { $config['voucher']['enable'] = $_POST['enable'] ? true : false; $config['voucher']['charset'] = $_POST['charset']; $config['voucher']['rollbits'] = $_POST['rollbits']; $config['voucher']['ticketbits'] = $_POST['ticketbits']; $config['voucher']['checksumbits'] = $_POST['checksumbits']; $config['voucher']['magic'] = $_POST['magic']; $config['voucher']['saveinterval'] = $_POST['saveinterval']; $config['voucher']['publickey'] = base64_encode($_POST['publickey']); $config['voucher']['privatekey'] = base64_encode($_POST['privatekey']); $config['voucher']['msgnoaccess'] = $_POST['msgnoaccess']; $config['voucher']['msgexpired'] = $_POST['msgexpired']; write_config(); voucher_configure(); if (isset($config['voucher']['enable']) && !isset($config['captiveportal']['enable'])) { $savemsg = gettext("Don't forget to configure and enable Captive Portal."); } } } include("head.inc"); ?>
  onClick="enable_change(false)">
\"""; } ?>
# #
        " width="17" height="17" border="0" alt=""> ')">" width="17" height="17" border="0" alt=""> " width="11" height="15" border="0" alt="">
. .

.

.

.
#
.
#
.
#
.

.

.

($PORTAL_MESSAGE$).

($PORTAL_MESSAGE$).
  " onClick="enable_change(true)">

:
.