summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErmal <eri@pfsense.org>2011-03-25 21:56:38 +0000
committerErmal <eri@pfsense.org>2011-03-25 21:56:38 +0000
commit351b699013fb120fa78f7df17fe636f49c1285b8 (patch)
tree83c711e59a9997cff299a474587460c944ca165c
parent4fab0ce085c09fee4ed1383725fe45f880ddfe4e (diff)
downloadpfsense-351b699013fb120fa78f7df17fe636f49c1285b8.zip
pfsense-351b699013fb120fa78f7df17fe636f49c1285b8.tar.gz
Correctly synchronize the db of vouchers from master. Also correctly write it to the files since before it is only allowed during bootup and not from xmlrpc.
-rw-r--r--etc/inc/voucher.inc13
-rw-r--r--usr/local/www/services_captiveportal_vouchers.php100
2 files changed, 59 insertions, 54 deletions
diff --git a/etc/inc/voucher.inc b/etc/inc/voucher.inc
index 2d54f07..5ff95ac 100644
--- a/etc/inc/voucher.inc
+++ b/etc/inc/voucher.inc
@@ -301,8 +301,8 @@ function voucher_auth($voucher_received, $test = 0) {
return $total_minutes;
}
-function voucher_configure() {
- global $config, $g;
+function voucher_configure($sync = false) {
+ global $config, $g;
/* kill any running minicron */
killbypid("{$g['varrun_path']}/vouchercron.pid");
@@ -312,6 +312,8 @@ function voucher_configure() {
if ($g['booting'])
echo "Enabling voucher support... ";
+ if ($sync == true)
+ captiveportal_syslog("Writing voucher db from sync data...");
// start cron if we're asked to save runtime DB periodically
// to XML config if it changed
@@ -329,7 +331,7 @@ function voucher_configure() {
$fd = fopen("{$g['varetc_path']}/voucher.public", "w");
if (!$fd) {
captiveportal_syslog("Voucher error: cannot write voucher.public\n");
- unlock($voucherlck);
+ unlock($voucherlck);
return 1;
}
fwrite($fd, $pubkey);
@@ -348,7 +350,7 @@ function voucher_configure() {
@chmod("{$g['varetc_path']}/voucher.cfg", 0600);
unlock($voucherlck);
- if ($g['booting'] && is_array($config['voucher']['roll'])) {
+ if (($g['booting'] || $sync == true) && is_array($config['voucher']['roll'])) {
// create active and used DB per roll on ramdisk from config
$a_roll = &$config['voucher']['roll'];
@@ -375,7 +377,8 @@ function voucher_configure() {
}
unlock($voucherlck);
- echo "done\n";
+ if ($g['booting'])
+ echo "done\n";
}
return 0;
diff --git a/usr/local/www/services_captiveportal_vouchers.php b/usr/local/www/services_captiveportal_vouchers.php
index 0bd442e..d6ffc55 100644
--- a/usr/local/www/services_captiveportal_vouchers.php
+++ b/usr/local/www/services_captiveportal_vouchers.php
@@ -214,7 +214,9 @@ if ($_POST) {
$config['voucher']['privatekey'] = base64_encode($_POST['privatekey']);
$config['voucher']['msgnoaccess'] = $_POST['msgnoaccess'];
$config['voucher']['msgexpired'] = $_POST['msgexpired'];
- }
+ write_config();
+ voucher_configure();
+ } else {
$config['voucher']['vouchersyncdbip'] = $_POST['vouchersyncdbip'];
$config['voucher']['vouchersyncport'] = $_POST['vouchersyncport'];
$config['voucher']['vouchersyncusername'] = $_POST['vouchersyncusername'];
@@ -227,28 +229,22 @@ if ($_POST) {
$url = "https://{$config['voucher']['vouchersyncdbip']}";
else
$url = "http://{$config['voucher']['vouchersyncdbip']}";
+
$execcmd = <<<EOF
- \$toreturn['voucher']['roll'] = \$config['voucher']['roll'];
- \$toreturn['voucher']['charset'] = \$config['voucher']['charset'];
- \$toreturn['voucher']['rollbits'] = \$config['voucher']['rollbits'];
- \$toreturn['voucher']['ticketbits'] = \$config['voucher']['ticketbits'];
- \$toreturn['voucher']['saveinterval'] = \$config['voucher']['saveinterval'];
- \$toreturn['voucher']['checksumbits'] = \$config['voucher']['checksumbits'];
- \$toreturn['voucher']['magic'] = \$config['voucher']['magic'];
- \$toreturn['voucher']['publickey'] = \$config['voucher']['publickey'];
- \$toreturn['voucher']['privatekey'] = \$config['voucher']['privatekey'];
- \$toreturn['voucher']['msgnoaccess'] = \$config['voucher']['msgnoaccess'];
- \$toreturn['voucher']['msgexpired'] = \$config['voucher']['msgexpired'];
-
+ \$toreturn['voucher'] = \$config['voucher'];
+ unset(\$toreturn['vouchersyncport'], \$toreturn['vouchersyncpass'], \$toreturn['vouchersyncusername'], \$toreturn['vouchersyncdbip']);
+
EOF;
+
/* assemble xmlrpc payload */
$params = array(
XML_RPC_encode($config['voucher']['vouchersyncpass']),
XML_RPC_encode($execcmd)
);
+ $port = $config['voucher']['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, $config['voucher']['vouchersyncport']);
+ $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
$cli->setCredentials($config['voucher']['vouchersyncusername'], $config['voucher']['vouchersyncpass']);
$resp = $cli->send($msg, "250");
if(!is_object($resp)) {
@@ -266,43 +262,47 @@ EOF;
} else {
log_error("The Captive Portal voucher database has been synchronized with {$url}:{$port} (pfsense.exec_php).");
}
- $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'])
- $config['voucher']['roll'] = $toreturn['voucher']['roll'];
- if($toreturn['voucher']['rollbits'])
- $config['voucher']['rollbits'] = $toreturn['voucher']['rollbits'];
- if($toreturn['voucher']['ticketbits'])
- $config['voucher']['ticketbits'] = $toreturn['voucher']['ticketbits'];
- if($toreturn['voucher']['saveinterval'])
- $config['voucher']['saveinterval'] = $toreturn['voucher']['saveinterval'];
- if($toreturn['voucher']['checksumbits'])
- $config['voucher']['checksumbits'] = $toreturn['voucher']['checksumbits'];
- if($toreturn['voucher']['magic'])
- $config['voucher']['magic'] = $toreturn['voucher']['magic'];
- if($toreturn['voucher']['publickey'])
- $config['voucher']['publickey'] = $toreturn['voucher']['publickey'];
- if($toreturn['voucher']['privatekey'])
- $config['voucher']['privatekey'] = $toreturn['voucher']['privatekey'];
- if($toreturn['voucher']['msgnoaccess'])
- $config['voucher']['msgnoaccess'] = $toreturn['voucher']['msgnoaccess'];
- if($toreturn['voucher']['msgexpired'])
- $config['voucher']['msgexpired'] = $toreturn['voucher']['msgexpired'];
- if($toreturn['voucher']['msgnoaccess'])
- $config['voucher']['msgnoaccess'] = $toreturn['voucher']['msgnoaccess'];
- $savemsg = gettext("Voucher database has been synchronized from {$url}");
+ 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'])
+ $config['voucher']['roll'] = $toreturn['voucher']['roll'];
+ if($toreturn['voucher']['rollbits'])
+ $config['voucher']['rollbits'] = $toreturn['voucher']['rollbits'];
+ if($toreturn['voucher']['ticketbits'])
+ $config['voucher']['ticketbits'] = $toreturn['voucher']['ticketbits'];
+ if($toreturn['voucher']['saveinterval'])
+ $config['voucher']['saveinterval'] = $toreturn['voucher']['saveinterval'];
+ if($toreturn['voucher']['checksumbits'])
+ $config['voucher']['checksumbits'] = $toreturn['voucher']['checksumbits'];
+ if($toreturn['voucher']['magic'])
+ $config['voucher']['magic'] = $toreturn['voucher']['magic'];
+ if($toreturn['voucher']['publickey'])
+ $config['voucher']['publickey'] = $toreturn['voucher']['publickey'];
+ if($toreturn['voucher']['privatekey'])
+ $config['voucher']['privatekey'] = $toreturn['voucher']['privatekey'];
+ if($toreturn['voucher']['msgnoaccess'])
+ $config['voucher']['msgnoaccess'] = $toreturn['voucher']['msgnoaccess'];
+ if($toreturn['voucher']['msgexpired'])
+ $config['voucher']['msgexpired'] = $toreturn['voucher']['msgexpired'];
+ if($toreturn['voucher']['msgnoaccess'])
+ $config['voucher']['msgnoaccess'] = $toreturn['voucher']['msgnoaccess'];
+ $savemsg = gettext("Voucher database has been synchronized from {$url}:{$port}");
+
+ write_config();
+ voucher_configure(true);
+ }
}
}
- write_config();
- voucher_configure();
- 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($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.");
}
}
include("head.inc");
@@ -591,6 +591,8 @@ function enable_change(enable_change) {
<td colspan="2" class="list"><p class="vexpl">
<span class="red"><strong> <?=gettext("Note:"); ?><br> </strong></span>
<?=gettext("Changing any Voucher parameter (apart from managing the list of Rolls) on this page will render existing vouchers useless if they were generated with different settings."); ?>
+ <br/>
+ <?=gettext("Specifying the Voucher Database Synchronization options will not record any other value from the other options. They will be retrieved/synced from the master."); ?>
</p>
</td>
</tr>
OpenPOWER on IntegriCloud