Revision fa3ab36a
Added by Scott Ullrich almost 15 years ago
etc/inc/voucher.inc | ||
---|---|---|
33 | 33 |
|
34 | 34 |
/* include all configuration functions */ |
35 | 35 |
|
36 |
function xmlrpc_sync_rolls() { |
|
37 |
global $g, $config; |
|
38 |
if($config['voucher']['vouchersyncpass'] && $config['voucher']['vouchersyncusername'] && |
|
39 |
$config['voucher']['vouchersyncport'] && $config['voucher']['vouchersyncdbip']) { |
|
40 |
// Synchronize the voucher DB from the master node |
|
41 |
require_once("xmlrpc.inc"); |
|
42 |
if($config['voucher']['vouchersyncport'] == "443") |
|
43 |
$url = "https://{$config['voucher']['vouchersyncdbip']}:{$config['voucher']['vouchersyncport']}"; |
|
44 |
else |
|
45 |
$url = "http://{$config['voucher']['vouchersyncdbip']}:{$config['voucher']['vouchersyncport']}"; |
|
46 |
$execcmd = <<<EOF |
|
47 |
\$toreturn['voucher']['roll'] = \$config['voucher']['roll']; |
|
48 |
|
|
49 |
EOF; |
|
50 |
/* assemble xmlrpc payload */ |
|
51 |
$params = array( |
|
52 |
XML_RPC_encode($config['voucher']['vouchersyncpass']), |
|
53 |
XML_RPC_encode($execcmd) |
|
54 |
); |
|
55 |
$msg = new XML_RPC_Message('pfsense.exec_php', $params); |
|
56 |
$cli = new XML_RPC_Client('/xmlrpc.php', $url, $config['voucher']['vouchersyncport']); |
|
57 |
$cli->setCredentials($config['voucher']['vouchersyncusername'], $config['voucher']['vouchersyncpass']); |
|
58 |
$resp = $cli->send($msg, "250"); |
|
59 |
if(!$resp) { |
|
60 |
$error = "A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} (pfsense.exec_php)."; |
|
61 |
log_error($error); |
|
62 |
file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", ""); |
|
63 |
$input_errors[] = $error; |
|
64 |
} elseif($resp->faultCode()) { |
|
65 |
$cli->setDebug(1); |
|
66 |
$resp = $cli->send($msg, "250"); |
|
67 |
$error = "An error code was received while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString(); |
|
68 |
log_error($error); |
|
69 |
file_notice("CaptivePortalVoucherSync", $error, "Error code received", ""); |
|
70 |
$input_errors[] = $error; |
|
71 |
} |
|
72 |
$toreturn = XML_RPC_Decode($resp->value()); |
|
73 |
if(is_array($toreturn) && $toreturn['voucher'] && $config['voucher']['roll']) { |
|
74 |
// If we received back the voucher roll and the local roll count differs then sync |
|
75 |
if(count($toreturn['voucher']['roll']) <> count($config['voucher']['roll'])) { |
|
76 |
$config['voucher']['roll'] = $toreturn['voucher']['roll']; |
|
77 |
write_config("Captive Portal voucher database synchronized with {$url}"); |
|
78 |
voucher_configure(); |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
36 | 84 |
/* |
37 | 85 |
*Authenticate a voucher and return the remaining time credit in minutes |
38 | 86 |
* if $test is set, don't mark the voucher as used nor add it to the list |
... | ... | |
47 | 95 |
|
48 | 96 |
$voucherlck = lock('voucher'); |
49 | 97 |
|
98 |
// If defined check to see if the roll count needs to be sycnrhonized |
|
99 |
xmlrpc_sync_rolls(); |
|
100 |
|
|
50 | 101 |
// read rolls into assoc array with rollid as key and minutes as value |
51 | 102 |
$a_roll = &$config['voucher']['roll']; |
52 | 103 |
foreach ($a_roll as $rollent) { |
Also available in: Unified diff
Sync rolls if needed. This might be required if the operator removed/added or changed the rolls on the master node