1
|
<?php
|
2
|
/*
|
3
|
services_captiveportal_mac_edit.php
|
4
|
part of m0n0wall (http://m0n0.ch/wall)
|
5
|
|
6
|
Copyright (C) 2004 Dinesh Nair <dinesh@alphaque.com>
|
7
|
All rights reserved.
|
8
|
|
9
|
Redistribution and use in source and binary forms, with or without
|
10
|
modification, are permitted provided that the following conditions are met:
|
11
|
|
12
|
1. Redistributions of source code must retain the above copyright notice,
|
13
|
this list of conditions and the following disclaimer.
|
14
|
|
15
|
2. Redistributions in binary form must reproduce the above copyright
|
16
|
notice, this list of conditions and the following disclaimer in the
|
17
|
documentation and/or other materials provided with the distribution.
|
18
|
|
19
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
POSSIBILITY OF SUCH DAMAGE.
|
29
|
*/
|
30
|
/*
|
31
|
pfSense_MODULE: captiveportal
|
32
|
*/
|
33
|
|
34
|
##|+PRIV
|
35
|
##|*IDENT=page-services-captiveportal-editmacaddresses
|
36
|
##|*NAME=Services: Captive portal: Edit MAC Addresses page
|
37
|
##|*DESCR=Allow access to the 'Services: Captive portal: Edit MAC Addresses' page.
|
38
|
##|*MATCH=services_captiveportal_mac_edit.php*
|
39
|
##|-PRIV
|
40
|
|
41
|
function passthrumacscmp($a, $b) {
|
42
|
return strcmp($a['mac'], $b['mac']);
|
43
|
}
|
44
|
|
45
|
function passthrumacs_sort() {
|
46
|
global $config, $cpzone;
|
47
|
|
48
|
usort($config['captiveportal'][$cpzone]['passthrumac'],"passthrumacscmp");
|
49
|
}
|
50
|
|
51
|
require("guiconfig.inc");
|
52
|
require("functions.inc");
|
53
|
require_once("filter.inc");
|
54
|
require("shaper.inc");
|
55
|
require("captiveportal.inc");
|
56
|
|
57
|
global $cpzone;
|
58
|
global $cpzoneid;
|
59
|
|
60
|
$pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit MAC address rules"));
|
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($a_cp[$cpzone]['passthrumac']))
|
82
|
$a_cp[$cpzone]['passthrumac'] = array();
|
83
|
$a_passthrumacs = &$a_cp[$cpzone]['passthrumac'];
|
84
|
|
85
|
if (isset($id) && $a_passthrumacs[$id]) {
|
86
|
$pconfig['action'] = $a_passthrumacs[$id]['action'];
|
87
|
$pconfig['mac'] = $a_passthrumacs[$id]['mac'];
|
88
|
$pconfig['bw_up'] = $a_passthrumacs[$id]['bw_up'];
|
89
|
$pconfig['bw_down'] = $a_passthrumacs[$id]['bw_down'];
|
90
|
$pconfig['descr'] = $a_passthrumacs[$id]['descr'];
|
91
|
$pconfig['username'] = $a_passthrumacs[$id]['username'];
|
92
|
}
|
93
|
|
94
|
if ($_POST) {
|
95
|
|
96
|
unset($input_errors);
|
97
|
$pconfig = $_POST;
|
98
|
|
99
|
/* input validation */
|
100
|
$reqdfields = explode(" ", "action mac");
|
101
|
$reqdfieldsn = array(gettext("Action"), gettext("MAC address"));
|
102
|
|
103
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
104
|
|
105
|
$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
|
106
|
|
107
|
if ($_POST['mac']) {
|
108
|
if (is_macaddr($_POST['mac'])) {
|
109
|
$iflist = get_interface_list();
|
110
|
foreach ($iflist as $if) {
|
111
|
if ($_POST['mac'] == strtolower($if['mac'])) {
|
112
|
$input_errors[] = sprintf(gettext("The MAC address %s belongs to a local interface, you cannot use it here."), $_POST['mac']);
|
113
|
break;
|
114
|
}
|
115
|
}
|
116
|
} else {
|
117
|
$input_errors[] = sprintf("%s. [%s]", gettext("A valid MAC address must be specified"), $_POST['mac']);
|
118
|
}
|
119
|
}
|
120
|
if ($_POST['bw_up'] && !is_numeric($_POST['bw_up']))
|
121
|
$input_errors[] = gettext("Upload speed needs to be an integer");
|
122
|
if ($_POST['bw_down'] && !is_numeric($_POST['bw_down']))
|
123
|
$input_errors[] = gettext("Download speed needs to be an integer");
|
124
|
|
125
|
foreach ($a_passthrumacs as $macent) {
|
126
|
if (isset($id) && ($a_passthrumacs[$id]) && ($a_passthrumacs[$id] === $macent))
|
127
|
continue;
|
128
|
|
129
|
if ($macent['mac'] == $_POST['mac']){
|
130
|
$input_errors[] = sprintf("[%s] %s.", $_POST['mac'], gettext("already exists"));
|
131
|
break;
|
132
|
}
|
133
|
}
|
134
|
|
135
|
if (!$input_errors) {
|
136
|
$mac = array();
|
137
|
$mac['action'] = $_POST['action'];
|
138
|
$mac['mac'] = $_POST['mac'];
|
139
|
if ($_POST['bw_up'])
|
140
|
$mac['bw_up'] = $_POST['bw_up'];
|
141
|
if ($_POST['bw_down'])
|
142
|
$mac['bw_down'] = $_POST['bw_down'];
|
143
|
if ($_POST['username'])
|
144
|
$mac['username'] = $_POST['username'];
|
145
|
|
146
|
$mac['descr'] = $_POST['descr'];
|
147
|
|
148
|
if (isset($id) && $a_passthrumacs[$id]) {
|
149
|
$oldmac = $a_passthrumacs[$id];
|
150
|
$a_passthrumacs[$id] = $mac;
|
151
|
} else {
|
152
|
$oldmac = $mac;
|
153
|
$a_passthrumacs[] = $mac;
|
154
|
}
|
155
|
passthrumacs_sort();
|
156
|
|
157
|
write_config();
|
158
|
|
159
|
if (isset($config['captiveportal'][$cpzone]['enable'])) {
|
160
|
$cpzoneid = $config['captiveportal'][$cpzone]['zoneid'];
|
161
|
$rules = captiveportal_passthrumac_delete_entry($oldmac);
|
162
|
$rules .= captiveportal_passthrumac_configure_entry($mac);
|
163
|
$uniqid = uniqid("{$cpzone}_macedit");
|
164
|
file_put_contents("{$g['tmp_path']}/{$uniqid}_tmp", $rules);
|
165
|
mwexec("/sbin/ipfw -x {$cpzoneid} -q {$g['tmp_path']}/{$uniqid}_tmp");
|
166
|
@unlink("{$g['tmp_path']}/{$uniqid}_tmp");
|
167
|
unset($cpzoneid);
|
168
|
}
|
169
|
|
170
|
header("Location: services_captiveportal_mac.php?zone={$cpzone}");
|
171
|
exit;
|
172
|
}
|
173
|
}
|
174
|
include("head.inc");
|
175
|
?>
|
176
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
177
|
<?php include("fbegin.inc"); ?>
|
178
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
179
|
<form action="services_captiveportal_mac_edit.php" method="post" name="iform" id="iform">
|
180
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="captiveportal mac edit">
|
181
|
<tr>
|
182
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit MAC address rules");?></td>
|
183
|
</tr>
|
184
|
<tr>
|
185
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Action"); ?></td>
|
186
|
<td width="78%" class="vtable">
|
187
|
<select name="action" class="formselect">
|
188
|
<?php
|
189
|
$actions = explode(" ", "Pass Block");
|
190
|
foreach ($actions as $action):
|
191
|
?>
|
192
|
<option value="<?=strtolower($action);?>"<?php if (strtolower($action) == strtolower($pconfig['action'])) echo "selected=\"selected\""; ?>>
|
193
|
<?=htmlspecialchars($action);?>
|
194
|
</option>
|
195
|
<?php
|
196
|
endforeach;
|
197
|
?>
|
198
|
</select>
|
199
|
<br />
|
200
|
<span class="vexpl"><?=gettext("Choose what to do with packets coming from this MAC address"); ?>.</span>
|
201
|
</td>
|
202
|
</tr>
|
203
|
<tr>
|
204
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address"); ?></td>
|
205
|
<td width="78%" class="vtable">
|
206
|
<?=$mandfldhtml;?><input name="mac" type="text" class="formfld unknown" id="mac" size="17" value="<?=htmlspecialchars($pconfig['mac']);?>" />
|
207
|
<?php
|
208
|
$ip = getenv('REMOTE_ADDR');
|
209
|
$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
|
210
|
$mac = str_replace("\n","",$mac);
|
211
|
?>
|
212
|
<a onclick="document.forms[0].mac.value='<?=$mac?>';" href="#"><?=gettext("Copy my MAC address");?></a>
|
213
|
<br />
|
214
|
<span class="vexpl"><?=gettext("MAC address (6 hex octets separated by colons)"); ?></span></td>
|
215
|
</tr>
|
216
|
<tr>
|
217
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
|
218
|
<td width="78%" class="vtable">
|
219
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
|
220
|
<br />
|
221
|
<span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span>
|
222
|
</td>
|
223
|
</tr>
|
224
|
<tr>
|
225
|
<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth up"); ?></td>
|
226
|
<td width="78%" class="vtable">
|
227
|
<input name="bw_up" type="text" class="formfld unknown" id="bw_up" size="10" value="<?=htmlspecialchars($pconfig['bw_up']);?>" />
|
228
|
<br />
|
229
|
<span class="vexpl"><?=gettext("Enter a upload limit to be enforced on this MAC address in Kbit/s"); ?></span>
|
230
|
</td>
|
231
|
</tr>
|
232
|
<tr>
|
233
|
<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth down"); ?></td>
|
234
|
<td width="78%" class="vtable">
|
235
|
<input name="bw_down" type="text" class="formfld unknown" id="bw_down" size="10" value="<?=htmlspecialchars($pconfig['bw_down']);?>" />
|
236
|
<br />
|
237
|
<span class="vexpl"><?=gettext("Enter a download limit to be enforced on this MAC address in Kbit/s"); ?></span>
|
238
|
</td>
|
239
|
</tr>
|
240
|
<tr>
|
241
|
<td width="22%" valign="top"> </td>
|
242
|
<td width="78%">
|
243
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
|
244
|
<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>" />
|
245
|
<?php if (isset($id) && $a_passthrumacs[$id]): ?>
|
246
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
247
|
<?php endif; ?>
|
248
|
<?php if (isset($pconfig['username']) && $pconfig['username']): ?>
|
249
|
<input name="username" type="hidden" value="<?=htmlspecialchars($pconfig['username']);?>" />
|
250
|
<?php endif; ?>
|
251
|
</td>
|
252
|
</tr>
|
253
|
</table>
|
254
|
</form>
|
255
|
<?php include("fend.inc"); ?>
|
256
|
</body>
|
257
|
</html>
|