Projet

Général

Profil

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

univnautes / usr / local / www / services_captiveportal_vouchers.php @ 5c770630

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
$cpzone = $_GET['zone'];
50
if (isset($_POST['zone']))
51
        $cpzone = $_POST['zone'];
52

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

    
58
if($_REQUEST['generatekey']) {
59
	exec("/usr/bin/openssl genrsa 64 > /tmp/key64.private");
60
	exec("/usr/bin/openssl rsa -pubout < /tmp/key64.private > /tmp/key64.public");
61
	$privatekey = str_replace("\n", "\\n", file_get_contents("/tmp/key64.private"));
62
	$publickey = str_replace("\n", "\\n", file_get_contents("/tmp/key64.public"));
63
	exec("rm /tmp/key64.private /tmp/key64.public");
64
	$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.");
65
	echo <<<EOF
66
		jQuery('#publickey').val('{$publickey}');
67
		jQuery('#privatekey').val('{$privatekey}');
68
		alert('{$alertmessage}');
69
		jQuery('#publickey').effect('highlight');
70
		jQuery('#privatekey').effect('highlight');
71
EOF;
72
	exit;
73
}
74

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

    
79
if (!is_array($config['voucher'])) 
80
	$config['voucher'] = array();
81

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

    
88

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

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

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

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

    
134
$a_roll = &$config['voucher'][$cpzone]['roll'];
135

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

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

    
195
if ($_POST) {
196

    
197
	unset($input_errors);
198

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

    
204
	$pconfig = $_POST;
205

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

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

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

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

    
292
EOF;
293

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

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