diff options
author | Ermal <eri@pfsense.org> | 2011-09-07 06:42:58 +0000 |
---|---|---|
committer | Ermal <eri@pfsense.org> | 2011-09-07 13:04:01 +0000 |
commit | b4792bf8fe3b1cef416c7135fea88c1a0b08800a (patch) | |
tree | d32a5fb188939e28cd42c92aa9b4cf6729ff4947 /usr/local/www/services_captiveportal_vouchers.php | |
parent | 9b55203f878786a2bbd0b7d5dda4474d2533695b (diff) | |
download | pfsense-b4792bf8fe3b1cef416c7135fea88c1a0b08800a.zip pfsense-b4792bf8fe3b1cef416c7135fea88c1a0b08800a.tar.gz |
Add the multi instance CP to master branch. This allows to define CP with different properties on different interfaces.
Diffstat (limited to 'usr/local/www/services_captiveportal_vouchers.php')
-rw-r--r-- | usr/local/www/services_captiveportal_vouchers.php | 207 |
1 files changed, 112 insertions, 95 deletions
diff --git a/usr/local/www/services_captiveportal_vouchers.php b/usr/local/www/services_captiveportal_vouchers.php index 05bce04..df423a0 100644 --- a/usr/local/www/services_captiveportal_vouchers.php +++ b/usr/local/www/services_captiveportal_vouchers.php @@ -39,8 +39,18 @@ $statusurl = "status_captiveportal_vouchers.php"; $logurl = "diag_logs_auth.php"; +$cpzone = $_GET['zone']; +if (isset($_POST['zone'])) + $cpzone = $_POST['zone']; + +if (empty($cpzone)) { + header("Location: services_captiveportal_zones.php"); + exit; +} + if ($_POST['postafterlogin']) $nocsrf= true; + require("guiconfig.inc"); require("functions.inc"); require("filter.inc"); @@ -65,77 +75,81 @@ EOF; exit; } -$pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Vouchers")); +if (!is_array($config['captiveportal'])) + $config['captiveportal'] = array(); +$a_cp =& $config['captiveportal']; 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']['checksumbits'])) - $config['voucher']['checksumbits'] = 5; -if (!isset($config['voucher']['magic'])) - $config['voucher']['magic'] = rand(); // anything slightly random will do +$pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Vouchers"), $a_cp[$cpzone]['zone']); + +if (!is_array($config['voucher'][$cpzone]['roll'])) + $config['voucher'][$cpzone]['roll'] = array(); +if (!isset($config['voucher'][$cpzone]['charset'])) + $config['voucher'][$cpzone]['charset'] = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'; +if (!isset($config['voucher'][$cpzone]['rollbits'])) + $config['voucher'][$cpzone]['rollbits'] = 16; +if (!isset($config['voucher'][$cpzone]['ticketbits'])) + $config['voucher'][$cpzone]['ticketbits'] = 10; +if (!isset($config['voucher'][$cpzone]['checksumbits'])) + $config['voucher'][$cpzone]['checksumbits'] = 5; +if (!isset($config['voucher'][$cpzone]['magic'])) + $config['voucher'][$cpzone]['magic'] = rand(); // anything slightly random will do -if (!isset($config['voucher']['publickey'])) { +if (!isset($config['voucher'][$cpzone]['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); + $config['voucher'][$cpzone]['publickey'] = base64_encode($pubkey); + $config['voucher'][$cpzone]['privatekey'] = base64_encode($privkey); } } // Check for invalid or expired vouchers -if (!isset($config['voucher']['msgnoaccess'])) - $config['voucher']['msgnoaccess'] = gettext("Voucher invalid"); -if (!isset($config['voucher']['msgexpired'])) - $config['voucher']['msgexpired'] = gettext("Voucher expired"); +if (!isset($config['voucher'][$cpzone]['msgnoaccess'])) + $config['voucher'][$cpzone]['msgnoaccess'] = gettext("Voucher invalid"); +if (!isset($config['voucher'][$cpzone]['msgexpired'])) + $config['voucher'][$cpzone]['msgexpired'] = gettext("Voucher expired"); -$a_roll = &$config['voucher']['roll']; +$a_roll = &$config['voucher'][$cpzone]['roll']; if ($_GET['act'] == "del") { $id = $_GET['id']; if ($a_roll[$id]) { $roll = $a_roll[$id]['number']; - $voucherlck = lock('voucher'); + $voucherlck = lock("voucher{$cpzone}"); unset($a_roll[$id]); voucher_unlink_db($roll); unlock($voucherlck); write_config(); - header("Location: services_captiveportal_vouchers.php"); + header("Location: services_captiveportal_vouchers.php?zone={$cpzone}"); exit; } } /* print all vouchers of the selected roll */ else if ($_GET['act'] == "csv") { - $privkey = base64_decode($config['voucher']['privatekey']); + $privkey = base64_decode($config['voucher'][$cpzone]['privatekey']); if (strstr($privkey,"BEGIN RSA PRIVATE KEY")) { - $fd = fopen("{$g['varetc_path']}/voucher.private","w"); + $fd = fopen("{$g['varetc_path']}/voucher_{$cpzone}.private","w"); if (!$fd) { $input_errors[] = gettext("Cannot write private key file") . ".\n"; } else { - chmod("{$g['varetc_path']}/voucher.private", 0600); + chmod("{$g['varetc_path']}/voucher_{$cpzone}.private", 0600); fwrite($fd, $privkey); fclose($fd); - $a_voucher = &$config['voucher']['roll']; + $a_voucher = &$config['voucher'][$cpzone]['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"); + header("Content-Disposition: attachment; filename=vouchers_{$cpzone}_roll{$number}.csv"); + system("/usr/local/bin/voucher -c {$g['varetc_path']}/voucher_{$cpzone}.cfg -p {$g['varetc_path']}/voucher_{$cpzone}.private $number $count"); + unlink("{$g['varetc_path']}/voucher_{$cpzone}.private"); exit; } } @@ -144,20 +158,20 @@ else if ($_GET['act'] == "csv") { } } -$pconfig['enable'] = isset($config['voucher']['enable']); -$pconfig['charset'] = $config['voucher']['charset']; -$pconfig['rollbits'] = $config['voucher']['rollbits']; -$pconfig['ticketbits'] = $config['voucher']['ticketbits']; -$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']; -$pconfig['vouchersyncdbip'] = $config['voucher']['vouchersyncdbip']; -$pconfig['vouchersyncport'] = $config['voucher']['vouchersyncport']; -$pconfig['vouchersyncpass'] = $config['voucher']['vouchersyncpass']; -$pconfig['vouchersyncusername'] = $config['voucher']['vouchersyncusername']; +$pconfig['enable'] = isset($config['voucher'][$cpzone]['enable']); +$pconfig['charset'] = $config['voucher'][$cpzone]['charset']; +$pconfig['rollbits'] = $config['voucher'][$cpzone]['rollbits']; +$pconfig['ticketbits'] = $config['voucher'][$cpzone]['ticketbits']; +$pconfig['checksumbits'] = $config['voucher'][$cpzone]['checksumbits']; +$pconfig['magic'] = $config['voucher'][$cpzone]['magic']; +$pconfig['publickey'] = base64_decode($config['voucher'][$cpzone]['publickey']); +$pconfig['privatekey'] = base64_decode($config['voucher'][$cpzone]['privatekey']); +$pconfig['msgnoaccess'] = $config['voucher'][$cpzone]['msgnoaccess']; +$pconfig['msgexpired'] = $config['voucher'][$cpzone]['msgexpired']; +$pconfig['vouchersyncdbip'] = $config['voucher'][$cpzone]['vouchersyncdbip']; +$pconfig['vouchersyncport'] = $config['voucher'][$cpzone]['vouchersyncport']; +$pconfig['vouchersyncpass'] = $config['voucher'][$cpzone]['vouchersyncpass']; +$pconfig['vouchersyncusername'] = $config['voucher'][$cpzone]['vouchersyncusername']; if ($_POST) { @@ -206,52 +220,54 @@ if ($_POST) { } if (!$input_errors) { + $newvoucher = array(); if ($_POST['enable'] == "yes") - $config['voucher']['enable'] = true; + $newvoucher['enable'] = true; else - unset($config['voucher']['enable']); + unset($newvoucher['enable']); if (empty($_POST['vouchersyncusername'])) { - $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']['publickey'] = base64_encode($_POST['publickey']); - $config['voucher']['privatekey'] = base64_encode($_POST['privatekey']); - $config['voucher']['msgnoaccess'] = $_POST['msgnoaccess']; - $config['voucher']['msgexpired'] = $_POST['msgexpired']; + $newvoucher['charset'] = $_POST['charset']; + $newvoucher['rollbits'] = $_POST['rollbits']; + $newvoucher['ticketbits'] = $_POST['ticketbits']; + $newvoucher['checksumbits'] = $_POST['checksumbits']; + $newvoucher['magic'] = $_POST['magic']; + $newvoucher['publickey'] = base64_encode($_POST['publickey']); + $newvoucher['privatekey'] = base64_encode($_POST['privatekey']); + $newvoucher['msgnoaccess'] = $_POST['msgnoaccess']; + $newvoucher['msgexpired'] = $_POST['msgexpired']; + $config['voucher'][$cpzone] = $newvoucher; write_config(); - voucher_configure(); + voucher_configure_zone(); } else { - $config['voucher']['vouchersyncdbip'] = $_POST['vouchersyncdbip']; - $config['voucher']['vouchersyncport'] = $_POST['vouchersyncport']; - $config['voucher']['vouchersyncusername'] = $_POST['vouchersyncusername']; - $config['voucher']['vouchersyncpass'] = $_POST['vouchersyncpass']; - if($config['voucher']['vouchersyncpass'] && $config['voucher']['vouchersyncusername'] && - $config['voucher']['vouchersyncport'] && $config['voucher']['vouchersyncdbip']) { + $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"); - if($config['voucher']['vouchersyncport'] == "443") - $url = "https://{$config['voucher']['vouchersyncdbip']}"; + if($newvoucher['vouchersyncport'] == "443") + $url = "https://{$newvoucher['vouchersyncdbip']}"; else - $url = "http://{$config['voucher']['vouchersyncdbip']}"; + $url = "http://{$newvoucher['vouchersyncdbip']}"; $execcmd = <<<EOF - \$toreturn['voucher'] = \$config['voucher']; + \$toreturn['voucher'] = \$config['voucher'][$cpzone]; unset(\$toreturn['vouchersyncport'], \$toreturn['vouchersyncpass'], \$toreturn['vouchersyncusername'], \$toreturn['vouchersyncdbip']); EOF; /* assemble xmlrpc payload */ $params = array( - XML_RPC_encode($config['voucher']['vouchersyncpass']), + XML_RPC_encode($newvoucher['vouchersyncpass']), XML_RPC_encode($execcmd) ); - $port = $config['voucher']['vouchersyncport']; + $port = $newvoucher['vouchersyncport']; log_error("voucher XMLRPC sync data {$url}:{$port}."); $msg = new XML_RPC_Message('pfsense.exec_php', $params); $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port); - $cli->setCredentials($config['voucher']['vouchersyncusername'], $config['voucher']['vouchersyncpass']); + $cli->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)."; @@ -276,37 +292,37 @@ EOF; } else { // If we received back the voucher roll and other information then store it. if($toreturn['voucher']['roll']) - $config['voucher']['roll'] = $toreturn['voucher']['roll']; + $config['voucher'][$cpzone]['roll'] = $toreturn['voucher']['roll']; if($toreturn['voucher']['rollbits']) - $config['voucher']['rollbits'] = $toreturn['voucher']['rollbits']; + $config['voucher'][$cpzone]['rollbits'] = $toreturn['voucher']['rollbits']; if($toreturn['voucher']['ticketbits']) - $config['voucher']['ticketbits'] = $toreturn['voucher']['ticketbits']; + $config['voucher'][$cpzone]['ticketbits'] = $toreturn['voucher']['ticketbits']; if($toreturn['voucher']['checksumbits']) - $config['voucher']['checksumbits'] = $toreturn['voucher']['checksumbits']; + $config['voucher'][$cpzone]['checksumbits'] = $toreturn['voucher']['checksumbits']; if($toreturn['voucher']['magic']) - $config['voucher']['magic'] = $toreturn['voucher']['magic']; + $config['voucher'][$cpzone]['magic'] = $toreturn['voucher']['magic']; if($toreturn['voucher']['publickey']) - $config['voucher']['publickey'] = $toreturn['voucher']['publickey']; + $config['voucher'][$cpzone]['publickey'] = $toreturn['voucher']['publickey']; if($toreturn['voucher']['privatekey']) - $config['voucher']['privatekey'] = $toreturn['voucher']['privatekey']; + $config['voucher'][$cpzone]['privatekey'] = $toreturn['voucher']['privatekey']; if($toreturn['voucher']['msgnoaccess']) - $config['voucher']['msgnoaccess'] = $toreturn['voucher']['msgnoaccess']; + $config['voucher'][$cpzone]['msgnoaccess'] = $toreturn['voucher']['msgnoaccess']; if($toreturn['voucher']['msgexpired']) - $config['voucher']['msgexpired'] = $toreturn['voucher']['msgexpired']; + $config['voucher'][$cpzone]['msgexpired'] = $toreturn['voucher']['msgexpired']; if($toreturn['voucher']['msgnoaccess']) - $config['voucher']['msgnoaccess'] = $toreturn['voucher']['msgnoaccess']; - $savemsg = sprintf(gettext("Voucher database has been synchronized from %1\$s:%2\$s"),$url,$port); + $config['voucher'][$cpzone]['msgnoaccess'] = $toreturn['voucher']['msgnoaccess']; + $savemsg = gettext("Voucher database has been synchronized from {$url}:{$port}"); write_config(); - voucher_configure(true); + voucher_configure_zone(true); } } } } - if($savemsg && isset($config['voucher']['enable']) && !isset($config['captiveportal']['enable'])) - $savemsg .= "<br/>"; - if (isset($config['voucher']['enable']) && !isset($config['captiveportal']['enable'])) - $savemsg .= gettext("Don't forget to configure and enable Captive Portal."); + if (!$input_errors) { + header("Location: services_captiveportal_vouchers.php?zone={$cpzone}"); + exit; + } } } include("head.inc"); @@ -384,12 +400,12 @@ function enable_change(enable_change) { <ul id="tabnav"> <?php $tab_array = array(); - $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php"); - $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php"); - $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php"); - $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php"); - $tab_array[] = array(gettext("Vouchers"), true, "services_captiveportal_vouchers.php"); - $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php"); + $tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Pass-through MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}"); + $tab_array[] = array(gettext("Vouchers"), true, "services_captiveportal_vouchers.php?zone={$cpzone}"); + $tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}"); display_top_tabs($tab_array, true); ?> </ul> @@ -439,9 +455,9 @@ function enable_change(enable_change) { <td valign="middle" nowrap class="list"> <div id='addeditdelete<?=$i?>'> <?php if ($pconfig['enable']): ?> - <a href="services_captiveportal_vouchers_edit.php?id=<?=$i; ?>"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit voucher"); ?>" width="17" height="17" border="0" alt="<?=gettext("edit voucher"); ?>"></a> - <a href="services_captiveportal_vouchers.php?act=del&id=<?=$i; ?>" onclick="return confirm('<?=gettext("Do you really want to delete this voucher? This makes all vouchers from this roll invalid"); ?>')"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete vouchers"); ?>" width="17" height="17" border="0" alt="<?=gettext("delete vouchers"); ?>"></a> - <a href="services_captiveportal_vouchers.php?act=csv&id=<?=$i; ?>"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_log_s.gif" title="<?=gettext("generate vouchers for this roll to CSV file"); ?>" width="11" height="15" border="0" alt="<?=gettext("generate vouchers for this roll to CSV file"); ?>"></a> + <a href="services_captiveportal_vouchers_edit.php?zone=<?=$cpzone;?>&id=<?=$i; ?>"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit voucher"); ?>" width="17" height="17" border="0" alt="<?=gettext("edit voucher"); ?>"></a> + <a href="services_captiveportal_vouchers.php?zone=<?=$cpzone;?>&act=del&id=<?=$i; ?>" onclick="return confirm('<?=gettext("Do you really want to delete this voucher? This makes all vouchers from this roll invalid"); ?>')"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete vouchers"); ?>" width="17" height="17" border="0" alt="<?=gettext("delete vouchers"); ?>"></a> + <a href="services_captiveportal_vouchers.php?zone=<?=$cpzone;?>&act=csv&id=<?=$i; ?>"><img src="/themes/<?=$g['theme']; ?>/images/icons/icon_log_s.gif" title="<?=gettext("generate vouchers for this roll to CSV file"); ?>" width="11" height="15" border="0" alt="<?=gettext("generate vouchers for this roll to CSV file"); ?>"></a> <?php endif;?> </div> </td> @@ -451,7 +467,7 @@ function enable_change(enable_change) { <td class="list" colspan="4"></td> <?php if ($pconfig['enable']) - echo "<td class=\"list\"><div id='addnewroll'> <a href=\"services_captiveportal_vouchers_edit.php\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" title=\"" . gettext("add voucher") . "\" width=\"17\" height=\"17\" border=\"0\" alt=\"" . gettext("add voucher") . "\"></a></div></td>"; + echo "<td class=\"list\"><div id='addnewroll'> <a href=\"services_captiveportal_vouchers_edit.php?zone={$cpzone}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" title=\"" . gettext("add voucher") . "\" width=\"17\" height=\"17\" border=\"0\" alt=\"" . gettext("add voucher") . "\"></a></div></td>"; ?> </tr> </table> @@ -577,6 +593,7 @@ function enable_change(enable_change) { <tr> <td width="22%" valign="top"> </td> <td width="78%"> + <input type="hidden" name="zone" id="zone" value="<?=$cpzone;?>" /> <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onClick="enable_change(true); before_save();"> <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()"> </td> |