1
|
<?php
|
2
|
/*
|
3
|
services_captiveportal_ip_edit.php
|
4
|
Copyright (C) 2011 Scott Ullrich <sullrich@gmail.com>
|
5
|
All rights reserved.
|
6
|
|
7
|
Originally part of m0n0wall (http://m0n0.ch/wall)
|
8
|
Copyright (C) 2004 Dinesh Nair <dinesh@alphaque.com>
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_BUILDER_BINARIES: /sbin/ipfw
|
34
|
pfSense_MODULE: captiveportal
|
35
|
*/
|
36
|
|
37
|
##|+PRIV
|
38
|
##|*IDENT=page-services-captiveportal-editallowedips
|
39
|
##|*NAME=Services: Captive portal: Edit Allowed IPs page
|
40
|
##|*DESCR=Allow access to the 'Services: Captive portal: Edit Allowed IPs' page.
|
41
|
##|*MATCH=services_captiveportal_ip_edit.php*
|
42
|
##|-PRIV
|
43
|
|
44
|
function allowedipscmp($a, $b) {
|
45
|
return strcmp($a['ip'], $b['ip']);
|
46
|
}
|
47
|
|
48
|
function allowedips_sort() {
|
49
|
global $g, $config, $cpzone;
|
50
|
|
51
|
usort($config['captiveportal'][$cpzone]['allowedip'],"allowedipscmp");
|
52
|
}
|
53
|
|
54
|
require("guiconfig.inc");
|
55
|
require("functions.inc");
|
56
|
require_once("filter.inc");
|
57
|
require("shaper.inc");
|
58
|
require("captiveportal.inc");
|
59
|
|
60
|
$pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit allowed IP address"));
|
61
|
$shortcut_section = "captiveportal";
|
62
|
|
63
|
$cpzone = $_GET['zone'];
|
64
|
if (isset($_POST['zone']))
|
65
|
$cpzone = $_POST['zone'];
|
66
|
|
67
|
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
|
68
|
header("Location: services_captiveportal_zones.php");
|
69
|
exit;
|
70
|
}
|
71
|
|
72
|
if (!is_array($config['captiveportal']))
|
73
|
$config['captiveportal'] = array();
|
74
|
$a_cp =& $config['captiveportal'];
|
75
|
|
76
|
if (is_numericint($_GET['id']))
|
77
|
$id = $_GET['id'];
|
78
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
79
|
$id = $_POST['id'];
|
80
|
|
81
|
if (!is_array($config['captiveportal'][$cpzone]['allowedip']))
|
82
|
$config['captiveportal'][$cpzone]['allowedip'] = array();
|
83
|
$a_allowedips =& $config['captiveportal'][$cpzone]['allowedip'];
|
84
|
|
85
|
if (isset($id) && $a_allowedips[$id]) {
|
86
|
$pconfig['ip'] = $a_allowedips[$id]['ip'];
|
87
|
$pconfig['sn'] = $a_allowedips[$id]['sn'];
|
88
|
$pconfig['bw_up'] = $a_allowedips[$id]['bw_up'];
|
89
|
$pconfig['bw_down'] = $a_allowedips[$id]['bw_down'];
|
90
|
$pconfig['descr'] = $a_allowedips[$id]['descr'];
|
91
|
}
|
92
|
|
93
|
if ($_POST) {
|
94
|
|
95
|
unset($input_errors);
|
96
|
$pconfig = $_POST;
|
97
|
|
98
|
/* input validation */
|
99
|
$reqdfields = explode(" ", "ip sn");
|
100
|
$reqdfieldsn = array(gettext("Allowed IP address"), gettext("Subnet mask"));
|
101
|
|
102
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
103
|
|
104
|
if ($_POST['ip'] && !is_ipaddr($_POST['ip']))
|
105
|
$input_errors[] = sprintf(gettext("A valid IP address must be specified. [%s]"), $_POST['ip']);
|
106
|
|
107
|
if ($_POST['sn'] && (!is_numeric($_POST['sn']) || ($_POST['sn'] < 1) || ($_POST['sn'] > 32)))
|
108
|
$input_errors[] = gettext("A valid subnet mask must be specified");
|
109
|
|
110
|
if ($_POST['bw_up'] && !is_numeric($_POST['bw_up']))
|
111
|
$input_errors[] = gettext("Upload speed needs to be an integer");
|
112
|
|
113
|
if ($_POST['bw_down'] && !is_numeric($_POST['bw_down']))
|
114
|
$input_errors[] = gettext("Download speed needs to be an integer");
|
115
|
|
116
|
foreach ($a_allowedips as $ipent) {
|
117
|
if (isset($id) && ($a_allowedips[$id]) && ($a_allowedips[$id] === $ipent))
|
118
|
continue;
|
119
|
|
120
|
if ($ipent['ip'] == $_POST['ip']){
|
121
|
$input_errors[] = sprintf("[%s] %s.", $_POST['ip'], gettext("already allowed")) ;
|
122
|
break ;
|
123
|
}
|
124
|
}
|
125
|
|
126
|
if (!$input_errors) {
|
127
|
$ip = array();
|
128
|
$ip['ip'] = $_POST['ip'];
|
129
|
$ip['sn'] = $_POST['sn'];
|
130
|
$ip['descr'] = $_POST['descr'];
|
131
|
if ($_POST['bw_up'])
|
132
|
$ip['bw_up'] = $_POST['bw_up'];
|
133
|
if ($_POST['bw_down'])
|
134
|
$ip['bw_down'] = $_POST['bw_down'];
|
135
|
if (isset($id) && $a_allowedips[$id]) {
|
136
|
$oldip = $a_allowedips[$id]['ip'];
|
137
|
if (!empty($a_allowedips[$id]['sn']))
|
138
|
$oldmask = $a_allowedips[$id]['sn'];
|
139
|
else
|
140
|
$oldmask = 32;
|
141
|
$a_allowedips[$id] = $ip;
|
142
|
} else {
|
143
|
$a_allowedips[] = $ip;
|
144
|
}
|
145
|
allowedips_sort();
|
146
|
|
147
|
write_config();
|
148
|
|
149
|
if (isset($a_cp[$cpzone]['enable']) && is_module_loaded("ipfw.ko")) {
|
150
|
$rules = "";
|
151
|
$cpzoneid = $a_cp[$cpzone]['zoneid'];
|
152
|
unset($ipfw);
|
153
|
if (isset($oldip) && isset($oldmask)) {
|
154
|
$ipfw = pfSense_ipfw_getTablestats($cpzoneid, 3, $oldip, $oldmask);
|
155
|
$rules .= "table 3 delete {$oldip}/{$oldmask}\n";
|
156
|
$rules .= "table 4 delete {$oldip}/{$oldmask}\n";
|
157
|
if (is_array($ipfw)) {
|
158
|
$rules .= "pipe delete {$ipfw['dnpipe']}\n";
|
159
|
$rules .= "pipe delete " . ($ipfw['dnpipe']+1 . "\n");
|
160
|
}
|
161
|
}
|
162
|
$rules .= captiveportal_allowedip_configure_entry($ip);
|
163
|
if (is_array($ipfw)) {
|
164
|
captiveportal_free_dn_ruleno($ipfw['dnpipe']);
|
165
|
}
|
166
|
$uniqid = uniqid("{$cpzone}_allowed");
|
167
|
@file_put_contents("{$g['tmp_path']}/{$uniqid}_tmp", $rules);
|
168
|
mwexec("/sbin/ipfw -x {$cpzoneid} -q {$g['tmp_path']}/{$uniqid}_tmp");
|
169
|
@unlink("{$g['tmp_path']}/{$uniqid}_tmp");
|
170
|
}
|
171
|
|
172
|
header("Location: services_captiveportal_ip.php?zone={$cpzone}");
|
173
|
exit;
|
174
|
}
|
175
|
}
|
176
|
|
177
|
include("head.inc");
|
178
|
|
179
|
?>
|
180
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
181
|
<?php include("fbegin.inc"); ?>
|
182
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
183
|
<form action="services_captiveportal_ip_edit.php" method="post" name="iform" id="iform">
|
184
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="captiveportal allow ip edit">
|
185
|
<tr>
|
186
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit allowed ip rule");?></td>
|
187
|
</tr>
|
188
|
<tr>
|
189
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("IP address"); ?></td>
|
190
|
<td width="78%" class="vtable">
|
191
|
<?=$mandfldhtml;?><input name="ip" type="text" class="formfld unknown" id="ip" size="17" value="<?=htmlspecialchars($pconfig['ip']);?>" />
|
192
|
/<select name='sn' class="formselect" id='sn'>
|
193
|
<?php for ($i = 32; $i >= 1; $i--): ?>
|
194
|
<option value="<?=$i;?>" <?php if ($i == $pconfig['sn']) echo "selected=\"selected\""; ?>><?=$i;?></option>
|
195
|
<?php endfor; ?>
|
196
|
</select>
|
197
|
<br />
|
198
|
<span class="vexpl"><?=gettext("IP address and subnet mask. Use /32 for a single IP");?>.</span>
|
199
|
</td>
|
200
|
</tr>
|
201
|
<tr>
|
202
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
|
203
|
<td width="78%" class="vtable">
|
204
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
|
205
|
<br /> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span>
|
206
|
</td>
|
207
|
</tr>
|
208
|
<tr>
|
209
|
<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth up"); ?></td>
|
210
|
<td width="78%" class="vtable">
|
211
|
<input name="bw_up" type="text" class="formfld unknown" id="bw_up" size="10" value="<?=htmlspecialchars($pconfig['bw_up']);?>" />
|
212
|
<br /> <span class="vexpl"><?=gettext("Enter a upload limit to be enforced on this IP address in Kbit/s"); ?></span>
|
213
|
</td>
|
214
|
</tr>
|
215
|
<tr>
|
216
|
<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth down"); ?></td>
|
217
|
<td width="78%" class="vtable">
|
218
|
<input name="bw_down" type="text" class="formfld unknown" id="bw_down" size="10" value="<?=htmlspecialchars($pconfig['bw_down']);?>" />
|
219
|
<br /> <span class="vexpl"><?=gettext("Enter a download limit to be enforced on this IP address in Kbit/s"); ?></span>
|
220
|
</td>
|
221
|
</tr>
|
222
|
<tr>
|
223
|
<td width="22%" valign="top"> </td>
|
224
|
<td width="78%">
|
225
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
|
226
|
<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>" />
|
227
|
<?php if (isset($id) && $a_allowedips[$id]): ?>
|
228
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
229
|
<?php endif; ?>
|
230
|
</td>
|
231
|
</tr>
|
232
|
</table>
|
233
|
</form>
|
234
|
<?php include("fend.inc"); ?>
|
235
|
</body>
|
236
|
</html>
|