Project

General

Profile

« Previous | Next » 

Revision 90df43c6

Added by Ermal LUÇI over 12 years ago

Avoid possible deadlock during voucher xmlrpc sync and correct url generation for xmlrpc

View differences:

etc/inc/voucher.inc
40 40
function xmlrpc_sync_voucher_expire($vouchers, $syncip, $port, $password, $username) {
41 41
	global $g, $config, $cpzone;
42 42
	require_once("xmlrpc.inc");
43
	if($port == "443") 
43
	if ($port == "443") 
44 44
		$url = "https://{$syncip}";
45
	else 
45
	else if ($port == "80")
46 46
		$url = "http://{$syncip}";
47
	else
48
		$url = "http://{$syncip}:{$port}";
47 49

  
48 50
	/* Construct code that is run on remote machine */
49 51
	$method = 'pfsense.exec_php';
......
88 90
function xmlrpc_sync_voucher_disconnect($dbent, $syncip, $port, $password, $username, $term_cause = 1, $stop_time = null) {
89 91
	global $g, $config, $cpzone;
90 92
	require_once("xmlrpc.inc");
91
	if($port == "443") 
93
	if ($port == "443") 
92 94
		$url = "https://{$syncip}";
93
	else 
95
	else if ($port == "80")
94 96
		$url = "http://{$syncip}";
97
	else
98
		$url = "http://{$syncip}:{$port}";
95 99

  
96 100
	/* Construct code that is run on remote machine */
97 101
	$dbent_str = serialize($dbent);
......
140 144
function xmlrpc_sync_used_voucher($voucher_received, $syncip, $port, $password, $username) {
141 145
	global $g, $config, $cpzone;
142 146
	require_once("xmlrpc.inc");
143
	if($port == "443") 
147
	if ($port == "443") 
144 148
		$url = "https://{$syncip}";
145
	else 
149
	else if ($port == "80")
146 150
		$url = "http://{$syncip}";
151
	else
152
		$url = "http://{$syncip}:{$port}";
147 153

  
148 154
	/* Construct code that is run on remote machine */
149 155
	$method = 'pfsense.exec_php';
......
153 159
	\$timeleft = voucher_auth("$voucher_received");
154 160
	\$toreturn = array();
155 161
	\$toreturn['timeleft'] = \$timeleft;
162
	\$toreturn['voucher'] = array();
156 163
	\$toreturn['voucher']['roll'] = \$config['voucher'][\$cpzone]['roll'];
157 164

  
158 165
EOF;
......
182 189
		log_error("CaptivePortalVoucherSync XMLRPC reload data success with {$url}:{$port} (pfsense.exec_php).");
183 190
	}
184 191
	$toreturn =  XML_RPC_Decode($resp->value());
192
	if (!is_array($config['voucher']))
193
		$config['voucher'] = array();
185 194
	if (is_array($toreturn['voucher']) && (count($toreturn['voucher'][$cpzone]['roll']) <> count($config['voucher'][$cpzone]['roll']))) {
186 195
		$config['voucher'][$cpzone]['roll'] = $toreturn['voucher']['roll'];
187 196
		write_config("Captive Portal Voucher database synchronized with {$url}");
......
194 203
function voucher_expire($voucher_received) {
195 204
	global $g, $config, $cpzone;
196 205

  
197
	$voucherlck = lock("voucher{$cpzone}", LOCK_EX);
198

  
199 206
	// XMLRPC Call over to the master Voucher node
200 207
	if(!empty($config['voucher'][$cpzone]['vouchersyncdbip'])) {
201 208
		$syncip   = $config['voucher'][$cpzone]['vouchersyncdbip'];
......
205 212
		xmlrpc_sync_voucher_expire($voucher_received, $syncip, $syncport, $syncpass, $vouchersyncusername);
206 213
	}
207 214

  
215
	$voucherlck = lock("voucher{$cpzone}", LOCK_EX);
216

  
208 217
	// read rolls into assoc array with rollid as key and minutes as value
209 218
	$tickets_per_roll = array();
210 219
	$minutes_per_roll = array();
......
307 316
	if (!isset($config['voucher'][$cpzone]['enable']))
308 317
		return 0;
309 318

  
310
	$voucherlck = lock("voucher{$cpzone}", LOCK_EX);
311

  
312 319
	// XMLRPC Call over to the master Voucher node
313 320
	if(!empty($config['voucher'][$cpzone]['vouchersyncdbip'])) {
314 321
		$syncip   = $config['voucher'][$cpzone]['vouchersyncdbip'];
......
318 325
		$remote_time_used = xmlrpc_sync_used_voucher($voucher_received, $syncip, $syncport, $syncpass, $vouchersyncusername);
319 326
	}
320 327

  
328
	$voucherlck = lock("voucher{$cpzone}", LOCK_EX);
329

  
321 330
	// read rolls into assoc array with rollid as key and minutes as value
322 331
	$tickets_per_roll = array();
323 332
	$minutes_per_roll = array();

Also available in: Unified diff