diff options
author | Renato Botelho <renato@netgate.com> | 2016-09-13 15:56:00 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-09-13 15:56:00 -0300 |
commit | 0ae266afd3a2130398855ec2a5eddb71631defd0 (patch) | |
tree | 8573f708ff13b4e25e6494687017930ca7c5ec48 /src/usr/local/www/services_captiveportal_vouchers.php | |
parent | 96ca183a728bd20a8f2453289a9590e2b5a04a1b (diff) | |
parent | eecfac71cfb1a27869a92b14314d5c2ecc1b9fa1 (diff) | |
download | pfsense-0ae266afd3a2130398855ec2a5eddb71631defd0.zip pfsense-0ae266afd3a2130398855ec2a5eddb71631defd0.tar.gz |
Merge pull request #3131 from PiBa-NL/20160906-generic-xmlrpc_client
Diffstat (limited to 'src/usr/local/www/services_captiveportal_vouchers.php')
-rw-r--r-- | src/usr/local/www/services_captiveportal_vouchers.php | 61 |
1 files changed, 12 insertions, 49 deletions
diff --git a/src/usr/local/www/services_captiveportal_vouchers.php b/src/usr/local/www/services_captiveportal_vouchers.php index 4e76793..5bb2b3d 100644 --- a/src/usr/local/www/services_captiveportal_vouchers.php +++ b/src/usr/local/www/services_captiveportal_vouchers.php @@ -290,65 +290,28 @@ if ($_POST) { } if ($newvoucher['vouchersyncpass'] && $newvoucher['vouchersyncusername'] && $newvoucher['vouchersyncport'] && $newvoucher['vouchersyncdbip']) { - // Synchronize the voucher DB from the master node - require_once("XML/RPC2/Client.php"); - - $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']}"; - } - $url .= ":{$newvoucher['vouchersyncport']}/xmlrpc.php"; + // Synchronize the voucher DB from the master node $execcmd = <<<EOF + global \$config; \$toreturn = array(); \$toreturn['voucher'] = \$config['voucher']['$cpzone']; unset(\$toreturn['vouchersyncport'], \$toreturn['vouchersyncpass'], \$toreturn['vouchersyncusername'], \$toreturn['vouchersyncdbip']); EOF; - - $options = array( - 'prefix' => 'pfsense.', - 'sslverify' => false, - 'connectionTimeout' => 240 - ); - - log_error(sprintf(gettext("voucher XMLRPC sync data %s"), $url)); - $cli = XML_RPC2_Client::create($url, $options); - if (!is_object($cli)) { - $error = sprintf(gettext("A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with %s (pfsense.exec_php)."), $url); - log_error($error); - file_notice("sync_settings", $error, "Settings Sync", ""); - $input_errors[] = $error; - } else { - try { - $resp = $cli->exec_php($newvoucher['vouchersyncusername'], $newvoucher['vouchersyncpass'], $execcmd); - } catch (XML_RPC2_FaultException $e) { - // The XMLRPC server returns a XMLRPC error - $error = 'Exception calling XMLRPC method exec_php #' . $e->getFaultCode() . ' : ' . $e->getFaultString(); - log_error($error); - file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", ""); - $input_errors[] = $error; - } catch (Exception $e) { - // Other errors (HTTP or networking problems...) - $error = 'Exception calling XMLRPC method exec_php #' . $e->getMessage(); - log_error($error); - file_notice("CaptivePortalVoucherSync", $error, gettext("Error code received"), ""); - $input_errors[] = $error; - } + require_once("xmlrpc_client.inc"); + $rpc_client = new pfsense_xmlrpc_client(); + $rpc_client->setConnectionData( + $newvoucher['vouchersyncdbip'], $newvoucher['vouchersyncport'], + $newvoucher['vouchersyncusername'], $newvoucher['vouchersyncpass']); + $rpc_client->set_noticefile("CaptivePortalVoucherSync"); + $resp = $rpc_client->xmlrpc_exec_php($execcmd); + if ($resp == null) { + $input_errors[] = $rpc_client->get_error(); } if (!$input_errors) { - if (!is_array($resp)) { - if ($resp == "Authentication failed") { - $input_errors[] = gettext("Could not synchronize the voucher database: Authentication Failed."); - } - } else { + if (is_array($resp)) { log_error(sprintf(gettext("The Captive Portal voucher database has been synchronized with %s (pfsense.exec_php)."), $url)); // If we received back the voucher roll and other information then store it. if ($resp['voucher']['roll']) { |