Projet

Général

Profil

Télécharger (8,75 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_captiveportal_vouchers_edit.php @ fab1cd2f

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_MODULE:	captiveportal
29
*/
30

    
31
##|+PRIV
32
##|*IDENT=page-services-captiveportal-voucher-edit
33
##|*NAME=Services: Captive portal Voucher Rolls page
34
##|*DESCR=Allow access to the 'Services: Captive portal Edit Voucher Rolls' page.
35
##|*MATCH=services_captiveportal_vouchers_edit.php*
36
##|-PRIV
37

    
38
require("guiconfig.inc");
39
require("functions.inc");
40
require_once("filter.inc");
41
require("shaper.inc");
42
require("captiveportal.inc");
43
require_once("voucher.inc");
44

    
45
$pgtitle = array(gettext("Services"), gettext("Captive portal"), gettext("Edit Voucher Rolls"));
46
$shortcut_section = "captiveportal-vouchers";
47

    
48
$cpzone = $_GET['zone'];
49
if (isset($_POST['zone']))
50
        $cpzone = $_POST['zone'];
51

    
52
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
53
        header("Location: services_captiveportal_zones.php");
54
        exit;
55
}
56

    
57
if (!is_array($config['captiveportal']))
58
        $config['captiveportal'] = array();
59
$a_cp =& $config['captiveportal'];
60

    
61
if (!is_array($config['voucher'])) {
62
    $config['voucher'] = array();
63
}
64

    
65
if (!is_array($config['voucher'][$cpzone]['roll'])) {
66
	$config['voucher'][$cpzone]['roll'] = array();
67
}
68
$a_roll = &$config['voucher'][$cpzone]['roll'];
69

    
70
if (is_numericint($_GET['id']))
71
	$id = $_GET['id'];
72
if (isset($_POST['id']) && is_numericint($_POST['id']))
73
	$id = $_POST['id'];
74

    
75
if (isset($id) && $a_roll[$id]) {
76
	$pconfig['zone'] = $a_roll[$id]['zone'];
77
	$pconfig['number'] = $a_roll[$id]['number'];
78
	$pconfig['count'] = $a_roll[$id]['count'];
79
	$pconfig['minutes'] = $a_roll[$id]['minutes'];
80
	$pconfig['descr'] = $a_roll[$id]['descr'];
81
}
82

    
83
$maxnumber = (1<<$config['voucher'][$cpzone]['rollbits']) -1;    // Highest Roll#
84
$maxcount = (1<<$config['voucher'][$cpzone]['ticketbits']) -1;   // Highest Ticket#
85

    
86
if ($_POST) {
87
	
88
	unset($input_errors);
89
	$pconfig = $_POST;
90

    
91
    /* input validation */
92
    $reqdfields = explode(" ", "number count minutes");
93
    $reqdfieldsn = array(gettext("Number"),gettext("Count"),gettext("minutes"));
94

    
95
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
96

    
97
	// Look for duplicate roll #
98
	foreach($a_roll as $re) {
99
		if($re['number'] == $_POST['number']) {
100
			$input_errors[] = sprintf(gettext("Roll number %s already exists."), $_POST['number']);
101
			break;
102
		}
103
	}
104
	
105
    if (!is_numeric($_POST['number']) || $_POST['number'] >= $maxnumber) 
106
        $input_errors[] = sprintf(gettext("Roll number must be numeric and less than %s"), $maxnumber);
107

    
108
    if (!is_numeric($_POST['count']) || $_POST['count'] < 1 || $_POST['count'] > $maxcount)
109
        $input_errors[] = sprintf(gettext("A roll has at least one voucher and less than %s."), $maxcount);
110

    
111
    if (!is_numeric($_POST['minutes']) || $_POST['minutes'] < 1)
112
        $input_errors[] = gettext("Each voucher must be good for at least 1 minute.");
113

    
114
    if (!$input_errors) {
115

    
116
        if (isset($id) && $a_roll[$id])
117
            $rollent = $a_roll[$id];
118

    
119
        $rollent['zone']  = $_POST['zone'];
120
        $rollent['number']  = $_POST['number'];
121
        $rollent['minutes'] = $_POST['minutes'];
122
        $rollent['descr'] = $_POST['descr'];
123

    
124
        /* New Roll or modified voucher count: create bitmask */
125
	$voucherlck = lock("voucher{$cpzone}");
126
        if ($_POST['count'] != $rollent['count']) {
127
            $rollent['count'] = $_POST['count'];
128
            $len = ($rollent['count']>>3) + 1;   // count / 8 +1
129
            $rollent['used'] = base64_encode(str_repeat("\000",$len)); // 4 bitmask
130
            $rollent['active'] = array();
131
            voucher_write_used_db($rollent['number'], $rollent['used']);
132
            voucher_write_active_db($rollent['number'], array());   // create empty DB
133
            voucher_log(LOG_INFO,sprintf(gettext('All %1$s vouchers from Roll %2$s marked unused'), $rollent['count'], $rollent['number']));
134
        } else {
135
            // existing roll has been modified but without changing the count
136
            // read active and used DB from ramdisk and store it in XML config
137
            $rollent['used'] = base64_encode(voucher_read_used_db($rollent['number']));
138
            $activent = array();
139
            $db = array();
140
            $active_vouchers = voucher_read_active_db($rollent['number'], $rollent['minutes']);
141
            foreach($active_vouchers as $voucher => $line) {
142
                list($timestamp, $minutes) = explode(",", $line);
143
                $activent['voucher'] = $voucher;
144
                $activent['timestamp'] = $timestamp;
145
                $activent['minutes'] = $minutes;
146
                $db[] = $activent;
147
            }
148
            $rollent['active'] = $db;
149
        }
150
	unlock($voucherlck);
151

    
152
        if (isset($id) && $a_roll[$id])
153
            $a_roll[$id] = $rollent;
154
        else
155
            $a_roll[] = $rollent;
156

    
157
        write_config();
158

    
159
        header("Location: services_captiveportal_vouchers.php?zone={$cpzone}");
160
        exit;
161
    }
162
}
163

    
164
include("head.inc");
165
?>
166
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
167
<?php include("fbegin.inc"); ?>
168
<?php if ($input_errors) print_input_errors($input_errors); ?>
169
<?php if ($savemsg) print_info_box($savemsg); ?>
170
<form action="services_captiveportal_vouchers_edit.php" method="post" name="iform" id="iform">
171
  <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="content pane">
172
	<tr> 
173
	  <td width="22%" valign="top" class="vncellreq"><?=gettext("Roll"); ?>#</td>
174
	  <td width="78%" class="vtable"> 
175
		<?=$mandfldhtml;?><input name="number" type="text" class="formfld" id="number" size="10" value="<?=htmlspecialchars($pconfig['number']);?>" /> 
176
        <br />
177
        <span class="vexpl"><?=gettext("Enter the Roll"); ?># (0..<?=htmlspecialchars($maxnumber);?>) <?=gettext("found on top of the generated/printed vouchers"); ?>.</span>
178
		</td>
179
	</tr>
180
	<tr> 
181
	  <td width="22%" valign="top" class="vncellreq"><?=gettext("Minutes per Ticket"); ?></td>
182
	  <td width="78%" class="vtable"> 
183
		<?=$mandfldhtml;?><input name="minutes" type="text" class="formfld" id="minutes" size="10" value="<?=htmlspecialchars($pconfig['minutes']);?>" /> 
184
        <br />
185
        <span class="vexpl"><?=gettext("Defines the time in minutes that a user is allowed access. The clock starts ticking the first time a voucher is used for authentication"); ?>.</span>
186
	   </td>
187
	</tr>
188
	<tr> 
189
	  <td width="22%" valign="top" class="vncellreq"><?=gettext("Count"); ?></td>
190
	  <td width="78%" class="vtable"> 
191
		<?=$mandfldhtml;?><input name="count" type="text" class="formfld" id="count" size="10" value="<?=htmlspecialchars($pconfig['count']);?>" /> 
192
        <br />
193
        <span class="vexpl"><?=gettext("Enter the number of vouchers"); ?> (1..<?=htmlspecialchars($maxcount);?>) <?=gettext("found on top of the generated/printed vouchers. WARNING: Changing this number for an existing Roll will mark all vouchers as unused again"); ?>.</span>
194
		</td>
195
	</tr>
196
	<tr> 
197
	  <td width="22%" valign="top" class="vncell"><?=gettext("Comment"); ?></td>
198
	  <td width="78%" class="vtable"> 
199
		<?=$mandfldhtml;?><input name="descr" type="text" class="formfld" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>" /> 
200
        <br />
201
        <span class="vexpl"><?=gettext("Can be used to further identify this roll. Ignored by the system"); ?>.</span>
202
		</td>
203
	</tr>
204
	<tr> 
205
	  <td width="22%" valign="top">&nbsp;</td>
206
	  <td width="78%"> 
207
		<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /> 
208
		<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>" />
209
		<?php if (isset($id) && $a_roll[$id]): ?>
210
		<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
211
		<?php endif; ?>
212
	  </td>
213
	</tr>
214
  </table>
215
 </form>
216
<?php include("fend.inc"); ?>
217
</body>
218
</html>
(146-146/255)