Projet

Général

Profil

Télécharger (31,2 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_captiveportal_vouchers.php @ 62424bdb

1
<?php 
2
/*
3
	Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>
4
	All rights reserved. 
5
	
6
	Redistribution and use in source and binary forms, with or without
7
	modification, are permitted provided that the following conditions are met:
8
	
9
	1. Redistributions of source code must retain the above copyright notice,
10
	   this list of conditions and the following disclaimer.
11
	
12
	2. Redistributions in binary form must reproduce the above copyright
13
	   notice, this list of conditions and the following disclaimer in the
14
	   documentation and/or other materials provided with the distribution.
15
	
16
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
20
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
	POSSIBILITY OF SUCH DAMAGE.
26
*/
27
/*
28
	pfSense_BUILDER_BINARIES:	/usr/local/bin/voucher	/usr/bin/openssl
29
	pfSense_MODULE:	captiveportal
30
*/
31

    
32
##|+PRIV
33
##|*IDENT=page-services-captiveportal-vouchers
34
##|*NAME=Services: Captive portal Vouchers page
35
##|*DESCR=Allow access to the 'Services: Captive portal Vouchers' page.
36
##|*MATCH=services_captiveportal_vouchers.php*
37
##|-PRIV
38

    
39
if ($_POST['postafterlogin'])
40
	$nocsrf= true;
41

    
42
require("guiconfig.inc");
43
require("functions.inc");
44
require_once("filter.inc");
45
require("shaper.inc");
46
require("captiveportal.inc");
47
require_once("voucher.inc");
48

    
49
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_captiveportal_vouchers.php');
50

    
51
$cpzone = $_GET['zone'];
52
if (isset($_POST['zone']))
53
        $cpzone = $_POST['zone'];
54

    
55
if (empty($cpzone)) {
56
        header("Location: services_captiveportal_zones.php");
57
        exit;
58
}
59

    
60
if($_REQUEST['generatekey']) {
61
	exec("/usr/bin/openssl genrsa 64 > /tmp/key64.private");
62
	exec("/usr/bin/openssl rsa -pubout < /tmp/key64.private > /tmp/key64.public");
63
	$privatekey = str_replace("\n", "\\n", file_get_contents("/tmp/key64.private"));
64
	$publickey = str_replace("\n", "\\n", file_get_contents("/tmp/key64.public"));
65
	exec("rm /tmp/key64.private /tmp/key64.public");
66
	$alertmessage = gettext("You will need to recreate any existing Voucher Rolls due to the public and private key changes. Click cancel if you do not wish to recreate the vouchers.");
67
	echo <<<EOF
68
		jQuery('#publickey').val('{$publickey}');
69
		jQuery('#privatekey').val('{$privatekey}');
70
		alert('{$alertmessage}');
71
		jQuery('#publickey').effect('highlight');
72
		jQuery('#privatekey').effect('highlight');
73
EOF;
74
	exit;
75
}
76

    
77
if (!is_array($config['captiveportal']))
78
        $config['captiveportal'] = array();
79
$a_cp =& $config['captiveportal'];
80

    
81
if (!is_array($config['voucher'])) 
82
	$config['voucher'] = array();
83

    
84
if (empty($a_cp[$cpzone])) {
85
	log_error("Submission on captiveportal page with unknown zone parameter: " . htmlspecialchars($cpzone));
86
	header("Location: services_captiveportal_zones.php");
87
	exit;
88
}
89

    
90

    
91
$pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Vouchers"), $a_cp[$cpzone]['zone']);
92
$shortcut_section = "captiveportal-vouchers";
93

    
94
if (!is_array($config['voucher'][$cpzone]['roll'])) 
95
	$config['voucher'][$cpzone]['roll'] = array();
96
if (!isset($config['voucher'][$cpzone]['charset'])) 
97
	$config['voucher'][$cpzone]['charset'] = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
98
if (!isset($config['voucher'][$cpzone]['rollbits'])) 
99
	$config['voucher'][$cpzone]['rollbits'] = 16;
100
if (!isset($config['voucher'][$cpzone]['ticketbits'])) 
101
	$config['voucher'][$cpzone]['ticketbits'] = 10;
102
if (!isset($config['voucher'][$cpzone]['checksumbits'])) 
103
	$config['voucher'][$cpzone]['checksumbits'] = 5;
104
if (!isset($config['voucher'][$cpzone]['magic'])) 
105
	$config['voucher'][$cpzone]['magic'] = rand();   // anything slightly random will do
106
if (!isset($config['voucher'][$cpzone]['exponent'])) {
107
	while (true) {
108
		while (($exponent = rand()) % 30000 < 5000)
109
			continue;
110
		$exponent = ($exponent * 2) + 1; // Make it odd number
111
		if ($exponent <= 65537)
112
			break;
113
	}
114
	$config['voucher'][$cpzone]['exponent'] = $exponent;
115
	unset($exponent);
116
}
117

    
118
if (!isset($config['voucher'][$cpzone]['publickey'])) {
119
	/* generate a random 64 bit RSA key pair using the voucher binary */
120
	$fd = popen("/usr/local/bin/voucher -g 64 -e " . $config['voucher'][$cpzone]['exponent'], "r");
121
	if ($fd !== false) {
122
		$output = fread($fd, 16384);
123
		pclose($fd);
124
		list($privkey, $pubkey) = explode("\0", $output);
125
		$config['voucher'][$cpzone]['publickey'] = base64_encode($pubkey);
126
		$config['voucher'][$cpzone]['privatekey'] = base64_encode($privkey);
127
	}
128
}
129

    
130
// Check for invalid or expired vouchers
131
if (!isset($config['voucher'][$cpzone]['descrmsgnoaccess'])) 
132
	$config['voucher'][$cpzone]['descrmsgnoaccess'] = gettext("Voucher invalid");
133
if (!isset($config['voucher'][$cpzone]['descrmsgexpired'])) 
134
	$config['voucher'][$cpzone]['descrmsgexpired'] = gettext("Voucher expired");
135

    
136
$a_roll = &$config['voucher'][$cpzone]['roll'];
137

    
138
if ($_GET['act'] == "del") {
139
    $id = $_GET['id'];
140
    if ($a_roll[$id]) {
141
		$roll = $a_roll[$id]['number']; 
142
		$voucherlck = lock("voucher{$cpzone}");
143
		unset($a_roll[$id]);
144
		voucher_unlink_db($roll);
145
		unlock($voucherlck);
146
		write_config();
147
    }
148
	header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
149
	exit;
150
}
151
/* print all vouchers of the selected roll */
152
else if ($_GET['act'] == "csv") {
153
	$privkey = base64_decode($config['voucher'][$cpzone]['privatekey']);
154
	if (strstr($privkey,"BEGIN RSA PRIVATE KEY")) {
155
		$fd = fopen("{$g['varetc_path']}/voucher_{$cpzone}.private","w");
156
		if (!$fd) {
157
			$input_errors[] = gettext("Cannot write private key file") . ".\n";
158
		} else {
159
			chmod("{$g['varetc_path']}/voucher_{$cpzone}.private", 0600);
160
			fwrite($fd, $privkey);
161
			fclose($fd);
162
			$a_voucher = &$config['voucher'][$cpzone]['roll'];
163
			$id = $_GET['id'];
164
			if (isset($id) && $a_voucher[$id]) {
165
				$number = $a_voucher[$id]['number'];
166
				$count = $a_voucher[$id]['count'];
167
				header("Content-Type: application/octet-stream");
168
				header("Content-Disposition: attachment; filename=vouchers_{$cpzone}_roll{$number}.csv");
169
				if (file_exists("{$g['varetc_path']}/voucher_{$cpzone}.cfg"))
170
					system("/usr/local/bin/voucher -c {$g['varetc_path']}/voucher_{$cpzone}.cfg -p {$g['varetc_path']}/voucher_{$cpzone}.private $number $count");
171
				@unlink("{$g['varetc_path']}/voucher_{$cpzone}.private");
172
			} else
173
				header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
174
			exit;
175
		}
176
	} else {
177
		$input_errors[] = gettext("Need private RSA key to print vouchers") . "\n";
178
	}
179
}
180

    
181
$pconfig['enable'] = isset($config['voucher'][$cpzone]['enable']);
182
$pconfig['charset'] = $config['voucher'][$cpzone]['charset'];
183
$pconfig['rollbits'] = $config['voucher'][$cpzone]['rollbits'];
184
$pconfig['ticketbits'] = $config['voucher'][$cpzone]['ticketbits'];
185
$pconfig['checksumbits'] = $config['voucher'][$cpzone]['checksumbits'];
186
$pconfig['magic'] = $config['voucher'][$cpzone]['magic'];
187
$pconfig['exponent'] = $config['voucher'][$cpzone]['exponent'];
188
$pconfig['publickey'] = base64_decode($config['voucher'][$cpzone]['publickey']);
189
$pconfig['privatekey'] = base64_decode($config['voucher'][$cpzone]['privatekey']);
190
$pconfig['msgnoaccess'] = $config['voucher'][$cpzone]['descrmsgnoaccess'];
191
$pconfig['msgexpired'] = $config['voucher'][$cpzone]['descrmsgexpired'];
192
$pconfig['vouchersyncdbip'] = $config['voucher'][$cpzone]['vouchersyncdbip'];
193
$pconfig['vouchersyncport'] = $config['voucher'][$cpzone]['vouchersyncport'];
194
$pconfig['vouchersyncpass'] = $config['voucher'][$cpzone]['vouchersyncpass'];
195
$pconfig['vouchersyncusername'] = $config['voucher'][$cpzone]['vouchersyncusername'];
196

    
197
if ($_POST) {
198

    
199
	unset($input_errors);
200

    
201
	if ($_POST['postafterlogin']) {
202
		voucher_expire($_POST['voucher_expire']);
203
		exit;
204
	}
205

    
206
	$pconfig = $_POST;
207

    
208
	/* input validation */
209
	if ($_POST['enable'] == "yes") {
210
		if (!$_POST['vouchersyncusername']) { 
211
			$reqdfields = explode(" ", "charset rollbits ticketbits checksumbits publickey magic");
212
			$reqdfieldsn = array(gettext("charset"),gettext("rollbits"),gettext("ticketbits"),gettext("checksumbits"),gettext("publickey"),gettext("magic"));
213
		} else {
214
			$reqdfields = explode(" ", "vouchersyncdbip vouchersyncport vouchersyncpass vouchersyncusername");
215
			$reqdfieldsn = array(gettext("Synchronize Voucher Database IP"),gettext("Sync port"),gettext("Sync password"),gettext("Sync username"));
216
		}
217
		
218
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
219
	}
220
	
221
	if (!$_POST['vouchersyncusername']) { 
222
		// Check for form errors
223
		if ($_POST['charset'] && (strlen($_POST['charset'] < 2))) 
224
			$input_errors[] = gettext("Need at least 2 characters to create vouchers.");
225
		if ($_POST['charset'] && (strpos($_POST['charset'],"\"")>0)) 
226
			$input_errors[] = gettext("Double quotes aren't allowed.");
227
		if ($_POST['charset'] && (strpos($_POST['charset'],",")>0)) 
228
			$input_errors[] = "',' " . gettext("aren't allowed.");
229
		if ($_POST['rollbits'] && (!is_numeric($_POST['rollbits']) || ($_POST['rollbits'] < 1) || ($_POST['rollbits'] > 31))) 
230
			$input_errors[] = gettext("# of Bits to store Roll Id needs to be between 1..31.");
231
		if ($_POST['ticketbits'] && (!is_numeric($_POST['ticketbits']) || ($_POST['ticketbits'] < 1) || ($_POST['ticketbits'] > 16))) 
232
			$input_errors[] = gettext("# of Bits to store Ticket Id needs to be between 1..16.");
233
		if ($_POST['checksumbits'] && (!is_numeric($_POST['checksumbits']) || ($_POST['checksumbits'] < 1) || ($_POST['checksumbits'] > 31))) 
234
			$input_errors[] = gettext("# of Bits to store checksum needs to be between 1..31.");
235
		if ($_POST['publickey'] && (!strstr($_POST['publickey'],"BEGIN PUBLIC KEY"))) 
236
			$input_errors[] = gettext("This doesn't look like an RSA Public key.");
237
		if ($_POST['privatekey'] && (!strstr($_POST['privatekey'],"BEGIN RSA PRIVATE KEY"))) 
238
			$input_errors[] = gettext("This doesn't look like an RSA Private key.");
239
		if ($_POST['vouchersyncdbip'] && (is_ipaddr_configured($_POST['vouchersyncdbip']))) 
240
			$input_errors[] = gettext("You cannot sync the voucher database to this host (itself).");
241
	}
242

    
243
	if (!$input_errors) {
244
		if (empty($config['voucher'][$cpzone]))
245
                        $newvoucher = array();
246
                else
247
                        $newvoucher = $config['voucher'][$cpzone];
248
		if ($_POST['enable'] == "yes")
249
			$newvoucher['enable'] = true;
250
		else
251
			unset($newvoucher['enable']);
252
		if (empty($_POST['vouchersyncusername'])) {
253
			unset($newvoucher['vouchersyncdbip']);
254
			unset($newvoucher['vouchersyncport']);
255
			unset($newvoucher['vouchersyncusername']);
256
			unset($newvoucher['vouchersyncpass']);
257
			$newvoucher['charset'] = $_POST['charset'];
258
			$newvoucher['rollbits'] = $_POST['rollbits'];
259
			$newvoucher['ticketbits'] = $_POST['ticketbits'];
260
			$newvoucher['checksumbits'] = $_POST['checksumbits'];
261
			$newvoucher['magic'] = $_POST['magic'];
262
			$newvoucher['exponent'] = $_POST['exponent'];
263
			$newvoucher['publickey'] = base64_encode($_POST['publickey']);
264
			$newvoucher['privatekey'] = base64_encode($_POST['privatekey']);
265
			$newvoucher['descrmsgnoaccess'] = $_POST['msgnoaccess'];
266
			$newvoucher['descrmsgexpired'] = $_POST['msgexpired'];
267
			$config['voucher'][$cpzone] = $newvoucher;
268
			write_config();
269
			voucher_configure_zone();
270
		} else {
271
			$newvoucher['vouchersyncdbip'] = $_POST['vouchersyncdbip'];
272
			$newvoucher['vouchersyncport'] = $_POST['vouchersyncport'];
273
			$newvoucher['vouchersyncusername'] = $_POST['vouchersyncusername'];
274
			$newvoucher['vouchersyncpass'] = $_POST['vouchersyncpass'];
275
			if($newvoucher['vouchersyncpass'] && $newvoucher['vouchersyncusername'] && 
276
			   $newvoucher['vouchersyncport'] && $newvoucher['vouchersyncdbip']) {
277
				// Synchronize the voucher DB from the master node
278
				require_once("xmlrpc.inc");
279

    
280
				$protocol = "http";
281
				if (is_array($config['system']) && is_array($config['system']['webgui']) && !empty($config['system']['webgui']['protocol']) &&
282
				    $config['system']['webgui']['protocol'] == "https")
283
					$protocol = "https";
284
				if ($protocol == "https" || $newvoucher['vouchersyncport'] == "443")
285
					$url = "https://{$newvoucher['vouchersyncdbip']}";
286
				else 
287
					$url = "http://{$newvoucher['vouchersyncdbip']}";
288

    
289
				$execcmd  = <<<EOF
290
				\$toreturn = array();
291
				\$toreturn['voucher'] = \$config['voucher']['$cpzone'];
292
				unset(\$toreturn['vouchersyncport'], \$toreturn['vouchersyncpass'], \$toreturn['vouchersyncusername'], \$toreturn['vouchersyncdbip']);
293

    
294
EOF;
295

    
296
				/* assemble xmlrpc payload */
297
				$params = array(
298
					XML_RPC_encode($newvoucher['vouchersyncpass']),
299
					XML_RPC_encode($execcmd)
300
				);
301
				$port = $newvoucher['vouchersyncport'];
302
				log_error("voucher XMLRPC sync data {$url}:{$port}.");
303
				$msg = new XML_RPC_Message('pfsense.exec_php', $params);
304
				$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
305
				$cli->setCredentials($newvoucher['vouchersyncusername'], $newvoucher['vouchersyncpass']);
306
				$resp = $cli->send($msg, "250");
307
				if(!is_object($resp)) {
308
					$error = "A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} (pfsense.exec_php).";
309
					log_error($error);
310
					file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", "");
311
					$input_errors[] = $error;
312
				} elseif($resp->faultCode()) {
313
					$cli->setDebug(1);
314
					$resp = $cli->send($msg, "250");
315
					$error = "An error code was received while attempting CaptivePortalVoucherSync XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
316
					log_error($error);
317
					file_notice("CaptivePortalVoucherSync", $error, "Error code received", "");
318
					$input_errors[] = $error;
319
				} else {
320
					log_error("The Captive Portal voucher database has been synchronized with {$url}:{$port} (pfsense.exec_php).");
321
				}
322
				if (!$input_errors) {
323
					$toreturn =  XML_RPC_Decode($resp->value());
324
					if(!is_array($toreturn)) {
325
						if($toreturn == "Authentication failed") 
326
							$input_errors[] = "Could not synchronize the voucher database: Authentication Failed.";
327
					} else {				
328
						// If we received back the voucher roll and other information then store it.
329
						if($toreturn['voucher']['roll'])
330
							$newvoucher['roll'] = $toreturn['voucher']['roll'];
331
						if($toreturn['voucher']['rollbits'])
332
							$newvoucher['rollbits'] = $toreturn['voucher']['rollbits'];
333
						if($toreturn['voucher']['ticketbits'])
334
							$newvoucher['ticketbits'] = $toreturn['voucher']['ticketbits'];
335
						if($toreturn['voucher']['checksumbits'])
336
							$newvoucher['checksumbits'] = $toreturn['voucher']['checksumbits'];
337
						if($toreturn['voucher']['magic'])
338
							$newvoucher['magic'] = $toreturn['voucher']['magic'];
339
						if($toreturn['voucher']['exponent'])
340
							$newvoucher['exponent'] = $toreturn['voucher']['exponent'];
341
						if($toreturn['voucher']['publickey'])
342
							$newvoucher['publickey'] = $toreturn['voucher']['publickey'];
343
						if($toreturn['voucher']['privatekey'])
344
							$newvoucher['privatekey'] = $toreturn['voucher']['privatekey'];
345
						if($toreturn['voucher']['descrmsgnoaccess'])
346
							$newvoucher['descrmsgnoaccess'] = $toreturn['voucher']['descrmsgnoaccess'];
347
						if($toreturn['voucher']['descrmsgexpired'])
348
							$newvoucher['descrmsgexpired'] = $toreturn['voucher']['descrmsgexpired'];
349
						$savemsg = gettext("Voucher database has been synchronized from {$url}:{$port}");
350

    
351
						$config['voucher'][$cpzone] = $newvoucher;
352
						write_config();
353
						voucher_configure_zone(true);
354
					}
355
				}
356
			}
357
		}
358
		if (!$input_errors) {
359
			header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
360
			exit;
361
		}
362
	}
363
}
364
$closehead = false;
365
include("head.inc");
366
?>
367
<script type="text/javascript">
368
//<![CDATA[
369
function generatenewkey() {
370
	jQuery('#publickey').val('One moment please...');
371
	jQuery('#privatekey').val('One moment please...');
372
	jQuery.ajax("services_captiveportal_vouchers.php?zone=<?php echo($cpzone); ?>&generatekey=true", {
373
		type: 'get',
374
		success: function(data) {	
375
			eval(data);
376
		}
377
	});		
378
}
379
function before_save() {
380
	document.iform.charset.disabled = false;
381
	document.iform.rollbits.disabled = false;
382
	document.iform.ticketbits.disabled = false;
383
	document.iform.checksumbits.disabled = false;
384
	document.iform.magic.disabled = false;
385
	document.iform.publickey.disabled = false;
386
	document.iform.privatekey.disabled = false;
387
	document.iform.msgnoaccess.disabled = false;
388
	document.iform.msgexpired.disabled = false;
389
	for(var x=0; x < <?php echo count($a_roll); ?>; x++)
390
		jQuery('#addeditdelete' + x).show();
391
	jQuery('#addnewroll').show();
392
}
393
function enable_change(enable_change) {
394
	var endis;
395
	endis = !(document.iform.enable.checked || enable_change);	
396
	document.iform.charset.disabled = endis;
397
	document.iform.rollbits.disabled = endis;
398
	document.iform.ticketbits.disabled = endis;
399
	document.iform.checksumbits.disabled = endis;
400
	document.iform.magic.disabled = endis;
401
	document.iform.publickey.disabled = endis;
402
	document.iform.privatekey.disabled = endis;
403
	document.iform.msgnoaccess.disabled = endis;
404
	document.iform.msgexpired.disabled = endis;
405
	document.iform.vouchersyncdbip.disabled = endis;
406
	document.iform.vouchersyncport.disabled = endis;
407
	document.iform.vouchersyncpass.disabled = endis;
408
	document.iform.vouchersyncusername.disabled = endis;
409
	if(document.iform.vouchersyncusername.value != "") {
410
		document.iform.charset.disabled = true;
411
		document.iform.rollbits.disabled = true;
412
		document.iform.ticketbits.disabled = true;
413
		document.iform.checksumbits.disabled = true;
414
		document.iform.magic.disabled = true;
415
		document.iform.publickey.disabled = true;
416
		document.iform.privatekey.disabled = true;
417
		document.iform.msgnoaccess.disabled = true;
418
		document.iform.msgexpired.disabled = true;
419
		for(var x=0; x < <?php echo count($a_roll); ?>; x++)
420
			jQuery('#addeditdelete' + x).hide();
421
		jQuery('#addnewroll').hide();
422
	} else {
423
		for(var x=0; x < <?php echo count($a_roll); ?>; x++)
424
			jQuery('#addeditdelete' + x).show();
425
		jQuery('#addnewroll').show();
426
	}
427
}
428
//]]>
429
</script>
430
</head>
431
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
432
<?php include("fbegin.inc"); ?>
433
<?php if ($input_errors) print_input_errors($input_errors); ?>
434
<?php if ($savemsg) print_info_box($savemsg); ?>
435
<form action="services_captiveportal_vouchers.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
436
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tab pane">
437
	<tr>
438
		<td class="tabnavtbl">
439
<?php 
440
	$tab_array = array();
441
	$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
442
	$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
443
	$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
444
	$tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}");
445
	$tab_array[] = array(gettext("Vouchers"), true, "services_captiveportal_vouchers.php?zone={$cpzone}");
446
	$tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}");
447
	display_top_tabs($tab_array, true);
448
?> 
449
		</td>
450
	</tr>
451
	<tr>
452
		<td class="tabcont">
453
			<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="checkbox pane">
454
				<tr> 
455
					<td width="22%" valign="top" class="vtable">&nbsp;</td>
456
					<td width="78%" class="vtable">
457
						<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\""; ?> onclick="enable_change(false)" />
458
						<strong><?=gettext("Enable Vouchers"); ?></strong>
459
					</td>
460
				</tr>
461
				<tr>
462
					<td valign="top" class="vncell">
463
						<?=gettext("Voucher Rolls"); ?>
464
						<?php 
465
							if($pconfig['vouchersyncdbip']) 
466
								echo "<br />(Synchronized from {$pconfig['vouchersyncdbip']})";
467
						?>
468
					</td>
469
					<td class="vtable">
470
						<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="content pane">
471
							<tr>
472
								<td width="10%" class="listhdrr"><?=gettext("Roll"); ?> #</td>
473
								<td width="20%" class="listhdrr"><?=gettext("Minutes/Ticket"); ?></td>
474
								<td width="20%" class="listhdrr"># <?=gettext("of Tickets"); ?></td>
475
								<td width="35%" class="listhdr"><?=gettext("Comment"); ?></td>
476
								<td width="15%" class="list"></td>
477
							</tr>
478
							<?php $i = 0; foreach($a_roll as $rollent): ?>
479
								<tr>
480
									<td class="listlr">
481
									<?=htmlspecialchars($rollent['number']); ?>&nbsp;
482
								</td>
483
								<td class="listr">
484
									<?=htmlspecialchars($rollent['minutes']);?>&nbsp;
485
								</td>
486
								<td class="listr">
487
									<?=htmlspecialchars($rollent['count']);?>&nbsp;
488
								</td>
489
								<td class="listr">
490
									<?=htmlspecialchars($rollent['descr']); ?>&nbsp;
491
								</td>
492
								<td valign="middle" class="list nowrap"> 
493
									<div id='addeditdelete<?=$i?>'>
494
										<?php if ($pconfig['enable']): ?> 
495
											<a href="services_captiveportal_vouchers_edit.php?zone=<?=$cpzone;?>&amp;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>
496
											<a href="services_captiveportal_vouchers.php?zone=<?=$cpzone;?>&amp;act=del&amp;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>
497
											<a href="services_captiveportal_vouchers.php?zone=<?=$cpzone;?>&amp;act=csv&amp;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>
498
                    					<?php endif;?>
499
									</div>
500
								</td>
501
							</tr>
502
							<?php $i++; endforeach; ?>
503
							<tr> 
504
								<td class="list" colspan="4"></td>
505
								<?php
506
								if ($pconfig['enable']) 
507
									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>";
508
								?>
509
							</tr>
510
						</table>     
511
						<?php if ($pconfig['enable']): ?> 
512
							<?=gettext("Create, generate and activate Rolls with Vouchers that allow access through the " .
513
							"captive portal for the configured time. Once a voucher is activated, " .
514
								"its clock is started and runs uninterrupted until it expires. During that " .
515
								"time, the voucher can be re-used from the same or a different computer. If the voucher " .
516
								"is used again from another computer, the previous session is stopped."); ?>
517
						<?php else: ?>
518
							<?=gettext("Enable Voucher support first using the checkbox above and hit Save at the bottom."); ?>
519
						<?php endif;?>
520
						</td>
521
					</tr>
522
					<tr>
523
						<td valign="top" class="vncellreq">
524
							<?=gettext("Voucher public key"); ?>
525
						</td>
526
						<td class="vtable">
527
							<textarea name="publickey" cols="65" rows="4" id="publickey" class="formpre"><?=htmlspecialchars($pconfig['publickey']);?></textarea>
528
							<br />
529
								<?=gettext("Paste an RSA public key (64 Bit or smaller) in PEM format here. This key is used to decrypt vouchers."); ?> <a href='#' onclick='generatenewkey();'><?=gettext('Generate');?></a> <?=gettext('new key');?>.</td>
530
						</tr>
531
						<tr>
532
							<td valign="top" class="vncell"><?=gettext("Voucher private key"); ?></td>
533
							<td class="vtable">
534
								<textarea name="privatekey" cols="65" rows="5" id="privatekey" class="formpre"><?=htmlspecialchars($pconfig['privatekey']);?></textarea>
535
								<br />
536
								<?=gettext("Paste an RSA private key (64 Bit or smaller) in PEM format here. This key is only used to generate encrypted vouchers and doesn't need to be available if the vouchers have been generated offline."); ?> <a href='#' onclick='generatenewkey();'> <?=gettext('Generate');?></a> <?=gettext('new key');?>.</td>
537
						</tr>
538
						<tr> 
539
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Character set"); ?></td>
540
							<td width="78%" class="vtable">
541
								<input name="charset" type="text" class="formfld" id="charset" size="80" value="<?=htmlspecialchars($pconfig['charset']);?>" />
542
								<br />
543
								<?=gettext("Tickets are generated with the specified character set. It should contain printable characters (numbers, lower case and upper case letters) that are hard to confuse with others. Avoid e.g. 0/O and l/1."); ?>
544
							</td>
545
						</tr>
546
						<tr> 
547
							<td width="22%" valign="top" class="vncellreq"># <?=gettext("of Roll Bits"); ?></td>
548
							<td width="78%" class="vtable">
549
								<input name="rollbits" type="text" class="formfld" id="rollbits" size="2" value="<?=htmlspecialchars($pconfig['rollbits']);?>" />
550
								<br />
551
								<?=gettext("Reserves a range in each voucher to store the Roll # it belongs to. Allowed range: 1..31. Sum of Roll+Ticket+Checksum bits must be one Bit less than the RSA key size."); ?>
552
							</td>
553
						</tr>
554
						<tr> 
555
							<td width="22%" valign="top" class="vncellreq"># <?=gettext("of Ticket Bits"); ?></td>
556
							<td width="78%" class="vtable">
557
								<input name="ticketbits" type="text" class="formfld" id="ticketbits" size="2" value="<?=htmlspecialchars($pconfig['ticketbits']);?>" />
558
								<br />
559
								<?=gettext("Reserves a range in each voucher to store the Ticket# it belongs to. Allowed range: 1..16. Using 16 bits allows a roll to have up to 65535 vouchers. A bit array, stored in RAM and in the config, is used to mark if a voucher has been used. A bit array for 65535 vouchers requires 8 KB of storage."); ?>
560
							</td>
561
						</tr>
562
						<tr> 
563
							<td width="22%" valign="top" class="vncellreq"># <?=gettext("of Checksum Bits"); ?></td>
564
							<td width="78%" class="vtable">
565
								<input name="checksumbits" type="text" class="formfld" id="checksumbits" size="2" value="<?=htmlspecialchars($pconfig['checksumbits']);?>" />
566
								<br />
567
								<?=gettext("Reserves a range in each voucher to store a simple checksum over Roll # and Ticket#. Allowed range is 0..31."); ?>
568
							</td>
569
						</tr>
570
						<tr> 
571
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Magic Number"); ?></td>
572
							<td width="78%" class="vtable">
573
								<input name="magic" type="text" class="formfld" id="magic" size="20" value="<?=htmlspecialchars($pconfig['magic']);?>" />
574
								<br />
575
								<?=gettext("Magic number stored in every voucher. Verified during voucher check. Size depends on how many bits are left by Roll+Ticket+Checksum bits. If all bits are used, no magic number will be used and checked."); ?>
576
							</td>
577
						</tr>
578
						<tr> 
579
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Invalid Voucher Message"); ?></td>
580
							<td width="78%" class="vtable">
581
								<input name="msgnoaccess" type="text" class="formfld" id="msgnoaccess" size="80" value="<?=htmlspecialchars($pconfig['msgnoaccess']);?>" />
582
								<br /><?=gettext("Error message displayed for invalid vouchers on captive portal error page"); ?> ($PORTAL_MESSAGE$).
583
							</td>
584
						</tr>
585
						<tr> 
586
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Expired Voucher Message"); ?></td>
587
							<td width="78%" class="vtable">
588
								<input name="msgexpired" type="text" class="formfld" id="msgexpired" size="80" value="<?=htmlspecialchars($pconfig['msgexpired']);?>" />
589
								<br /><?=gettext("Error message displayed for expired vouchers on captive portal error page"); ?> ($PORTAL_MESSAGE$).
590
							</td>
591
						</tr>
592
						<tr>
593
							<td width="22%" valign="top">&nbsp;</td>
594
							<td width="78%">
595
								&nbsp;
596
							</td>
597
						</tr>
598
						<tr>
599
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Voucher database synchronization"); ?></td>
600
						</tr>
601
						<tr> 
602
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Synchronize Voucher Database IP"); ?></td>
603
							<td width="78%" class="vtable">
604
								<input name="vouchersyncdbip" type="text" class="formfld" id="vouchersyncdbip" size="17" value="<?=htmlspecialchars($pconfig['vouchersyncdbip']);?>" />
605
								<br /><?=gettext("IP address of master nodes webConfigurator to synchronize voucher database and used vouchers from."); ?>
606
								<br /><?=gettext("NOTE: this should be setup on the slave nodes and not the primary node!"); ?>
607
							</td>
608
						</tr>
609
						<tr> 
610
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Voucher sync port"); ?></td>
611
							<td width="78%" class="vtable">
612
								<input name="vouchersyncport" type="text" class="formfld" id="vouchersyncport" size="7" value="<?=htmlspecialchars($pconfig['vouchersyncport']);?>" />
613
								<br /><?=gettext("This is the port of the master voucher nodes webConfigurator.  Example: 443"); ?>
614
							</td>
615
						</tr>
616
						<tr> 
617
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Voucher sync username"); ?></td>
618
							<td width="78%" class="vtable">
619
								<input name="vouchersyncusername" type="text" class="formfld" id="vouchersyncusername" size="25" value="<?=htmlspecialchars($pconfig['vouchersyncusername']);?>" autocomplete="off" />
620
								<br /><?=gettext("This is the username of the master voucher nodes webConfigurator."); ?>
621
							</td>
622
						</tr>
623
						<tr> 
624
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Voucher sync password"); ?></td>
625
							<td width="78%" class="vtable">
626
								<input name="vouchersyncpass" type="password" class="formfld" id="vouchersyncpass" size="25" value="<?=htmlspecialchars($pconfig['vouchersyncpass']);?>" autocomplete="off" />
627
								<br /><?=gettext("This is the password of the master voucher nodes webConfigurator."); ?>
628
							</td>
629
						</tr>
630
						<tr>
631
							<td width="22%" valign="top">&nbsp;</td>
632
							<td width="78%">
633
								<input type="hidden" name="zone" id="zone" value="<?=htmlspecialchars($cpzone);?>" />
634
								<input type="hidden" name="exponent" id="exponent" value="<?=$pconfig['exponent'];?>" />
635
								<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="enable_change(true); before_save();" />
636
								<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
637
							</td>
638
						</tr>
639
						<tr>
640
							<td colspan="2" class="list"><p class="vexpl">
641
								<span class="red"><strong> <?=gettext("Note:"); ?><br />   </strong></span>
642
							<?=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."); ?>
643
							<br />
644
							<?=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."); ?>
645
						</p>
646
					</td>
647
				</tr>
648
			</table>
649
		</td>
650
	</tr>
651
</table>
652
</form>
653
<script type="text/javascript">
654
//<![CDATA[
655
enable_change(false);
656
//]]>
657
</script>
658
<?php include("fend.inc"); ?>
659
</body>
660
</html>
(146-146/256)