Revision cfd88fbc
Added by Renato Botelho almost 12 years ago
usr/local/www/services_captiveportal_mac.php | ||
---|---|---|
2 | 2 |
/* |
3 | 3 |
services_captiveportal_mac.php |
4 | 4 |
part of m0n0wall (http://m0n0.ch/wall) |
5 |
|
|
5 |
|
|
6 | 6 |
Copyright (C) 2004 Dinesh Nair <dinesh@alphaque.com> |
7 | 7 |
All rights reserved. |
8 |
|
|
8 |
|
|
9 | 9 |
Redistribution and use in source and binary forms, with or without |
10 | 10 |
modification, are permitted provided that the following conditions are met: |
11 |
|
|
11 |
|
|
12 | 12 |
1. Redistributions of source code must retain the above copyright notice, |
13 | 13 |
this list of conditions and the following disclaimer. |
14 |
|
|
14 |
|
|
15 | 15 |
2. Redistributions in binary form must reproduce the above copyright |
16 | 16 |
notice, this list of conditions and the following disclaimer in the |
17 | 17 |
documentation and/or other materials provided with the distribution. |
18 |
|
|
18 |
|
|
19 | 19 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
20 | 20 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
21 | 21 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
... | ... | |
46 | 46 |
|
47 | 47 |
$cpzone = $_GET['zone']; |
48 | 48 |
if (isset($_POST['zone'])) |
49 |
$cpzone = $_POST['zone'];
|
|
49 |
$cpzone = $_POST['zone'];
|
|
50 | 50 |
|
51 | 51 |
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) { |
52 |
header("Location: services_captiveportal_zones.php");
|
|
53 |
exit;
|
|
52 |
header("Location: services_captiveportal_zones.php");
|
|
53 |
exit;
|
|
54 | 54 |
} |
55 | 55 |
|
56 | 56 |
if (!is_array($config['captiveportal'])) |
57 |
$config['captiveportal'] = array();
|
|
57 |
$config['captiveportal'] = array();
|
|
58 | 58 |
$a_cp =& $config['captiveportal']; |
59 | 59 |
|
60 | 60 |
$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']); |
... | ... | |
89 | 89 |
if ($_POST['username']) { |
90 | 90 |
$mac = captiveportal_passthrumac_findbyname($_POST['username']); |
91 | 91 |
if (!empty($mac)) |
92 |
$_POST['delmac'] = $mac['mac'];
|
|
92 |
$_POST['delmac'] = $mac['mac']; |
|
93 | 93 |
else |
94 | 94 |
echo gettext("No entry exists for this username:") . " " . $_POST['username'] . "\n"; |
95 | 95 |
} |
... | ... | |
156 | 156 |
<?php print_info_box_np(gettext("The captive portal MAC address configuration has been changed.<br>You must apply the changes in order for them to take effect."));?><br> |
157 | 157 |
<?php endif; ?> |
158 | 158 |
<table width="100%" border="0" cellpadding="0" cellspacing="0"> |
159 |
<tr><td class="tabnavtbl">
|
|
159 |
<tr><td class="tabnavtbl">
|
|
160 | 160 |
<?php |
161 | 161 |
$tab_array = array(); |
162 | 162 |
$tab_array[] = array(gettext("Captive portal"), false, "services_captiveportal.php?zone={$cpzone}"); |
... | ... | |
167 | 167 |
$tab_array[] = array(gettext("File Manager"), false, "services_captiveportal_filemanager.php?zone={$cpzone}"); |
168 | 168 |
display_top_tabs($tab_array, true); |
169 | 169 |
?> |
170 |
</td></tr> |
|
171 |
<tr> |
|
172 |
<td class="tabcont"> |
|
173 |
<table width="100%" border="0" cellpadding="0" cellspacing="0"> |
|
170 |
</td></tr> |
|
174 | 171 |
<tr> |
175 |
<td width="40%" class="listhdrr"><?=gettext("MAC address"); ?></td> |
|
176 |
<td width="50%" class="listhdr"><?=gettext("Description"); ?></td> |
|
177 |
<td width="10%" class="list"></td> |
|
178 |
</tr> |
|
179 |
<?php if (is_array($a_cp[$cpzone]['passthrumac'])): |
|
180 |
$i = 0; foreach ($a_cp[$cpzone]['passthrumac'] as $mac): ?> |
|
181 |
<tr ondblclick="document.location='services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>'"> |
|
182 |
<td class="listlr"> |
|
183 |
<?=strtolower($mac['mac']);?> |
|
184 |
</td> |
|
185 |
<td class="listbg"> |
|
186 |
<?=htmlspecialchars($mac['descr']);?> |
|
187 |
</td> |
|
188 |
<td valign="middle" nowrap class="list"> <a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit host"); ?>" width="17" height="17" border="0"></a> |
|
189 |
<a href="services_captiveportal_mac.php?zone=<?=$cpzone;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this host?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete host"); ?>" width="17" height="17" border="0"></a></td> |
|
190 |
</tr> |
|
191 |
<?php $i++; endforeach; endif; ?> |
|
192 |
<tr> |
|
193 |
<td class="list" colspan="2"> </td> |
|
194 |
<td class="list"> <a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add host"); ?>" width="17" height="17" border="0"></a></td> |
|
195 |
</tr> |
|
196 |
<tr> |
|
197 |
<td colspan="2" class="list"><span class="vexpl"><span class="red"><strong> |
|
198 |
<?=gettext("Note:"); ?><br> |
|
199 |
</strong></span> |
|
200 |
<?=gettext("Adding MAC addresses as pass-through MACs allows them access through the captive portal automatically without being taken to the portal page."); ?> </span></td> |
|
201 |
<td class="list"> </td> |
|
172 |
<td class="tabcont"> |
|
173 |
<table width="100%" border="0" cellpadding="0" cellspacing="0"> |
|
174 |
<tr> |
|
175 |
<td width="40%" class="listhdrr"><?=gettext("MAC address"); ?></td> |
|
176 |
<td width="50%" class="listhdr"><?=gettext("Description"); ?></td> |
|
177 |
<td width="10%" class="list"></td> |
|
178 |
</tr> |
|
179 |
<?php |
|
180 |
if (is_array($a_cp[$cpzone]['passthrumac'])): |
|
181 |
$i = 0; |
|
182 |
foreach ($a_cp[$cpzone]['passthrumac'] as $mac): |
|
183 |
?> |
|
184 |
<tr ondblclick="document.location='services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>'"> |
|
185 |
<td class="listlr"> |
|
186 |
<?=strtolower($mac['mac']);?> |
|
187 |
</td> |
|
188 |
<td class="listbg"> |
|
189 |
<?=htmlspecialchars($mac['descr']);?> |
|
190 |
</td> |
|
191 |
<td valign="middle" nowrap class="list"> |
|
192 |
<a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>&id=<?=$i;?>"> |
|
193 |
<img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif" title="<?=gettext("edit host"); ?>" width="17" height="17" border="0"> |
|
194 |
</a> |
|
195 |
|
|
196 |
<a href="services_captiveportal_mac.php?zone=<?=$cpzone;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this host?"); ?>')"> |
|
197 |
<img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete host"); ?>" width="17" height="17" border="0"> |
|
198 |
</a> |
|
199 |
</td> |
|
200 |
</tr> |
|
201 |
<?php |
|
202 |
$i++; |
|
203 |
endforeach; |
|
204 |
endif; |
|
205 |
?> |
|
206 |
<tr> |
|
207 |
<td class="list" colspan="2"> </td> |
|
208 |
<td class="list"> |
|
209 |
<a href="services_captiveportal_mac_edit.php?zone=<?=$cpzone;?>"> |
|
210 |
<img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add host"); ?>" width="17" height="17" border="0"> |
|
211 |
</a> |
|
212 |
</td> |
|
213 |
</tr> |
|
214 |
<tr> |
|
215 |
<td colspan="2" class="list"> |
|
216 |
<span class="vexpl"> |
|
217 |
<span class="red"><strong><?=gettext("Note:"); ?><br></strong></span> |
|
218 |
<?=gettext("Adding MAC addresses as pass-through MACs allows them access through the captive portal automatically without being taken to the portal page."); ?> |
|
219 |
</span> |
|
220 |
</td> |
|
221 |
<td class="list"> </td> |
|
222 |
</tr> |
|
223 |
</table> |
|
224 |
</td> |
|
202 | 225 |
</tr> |
203 |
</table> |
|
204 |
</td> |
|
205 |
</tr> |
|
206 |
</table> |
|
226 |
</table> |
|
207 | 227 |
</form> |
208 | 228 |
<?php include("fend.inc"); ?> |
209 | 229 |
</body> |
usr/local/www/services_captiveportal_mac_edit.php | ||
---|---|---|
1 |
<?php
|
|
1 |
<?php |
|
2 | 2 |
/* |
3 | 3 |
services_captiveportal_mac_edit.php |
4 | 4 |
part of m0n0wall (http://m0n0.ch/wall) |
5 |
|
|
5 |
|
|
6 | 6 |
Copyright (C) 2004 Dinesh Nair <dinesh@alphaque.com> |
7 | 7 |
All rights reserved. |
8 |
|
|
8 |
|
|
9 | 9 |
Redistribution and use in source and binary forms, with or without |
10 | 10 |
modification, are permitted provided that the following conditions are met: |
11 |
|
|
11 |
|
|
12 | 12 |
1. Redistributions of source code must retain the above copyright notice, |
13 | 13 |
this list of conditions and the following disclaimer. |
14 |
|
|
14 |
|
|
15 | 15 |
2. Redistributions in binary form must reproduce the above copyright |
16 | 16 |
notice, this list of conditions and the following disclaimer in the |
17 | 17 |
documentation and/or other materials provided with the distribution. |
18 |
|
|
18 |
|
|
19 | 19 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
20 | 20 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
21 | 21 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
... | ... | |
43 | 43 |
} |
44 | 44 |
|
45 | 45 |
function passthrumacs_sort() { |
46 |
global $config, $cpzone;
|
|
46 |
global $config, $cpzone;
|
|
47 | 47 |
|
48 |
usort($config['captiveportal'][$cpzone]['passthrumac'],"passthrumacscmp");
|
|
48 |
usort($config['captiveportal'][$cpzone]['passthrumac'],"passthrumacscmp");
|
|
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
require("guiconfig.inc"); |
... | ... | |
59 | 59 |
|
60 | 60 |
$cpzone = $_GET['zone']; |
61 | 61 |
if (isset($_POST['zone'])) |
62 |
$cpzone = $_POST['zone'];
|
|
62 |
$cpzone = $_POST['zone'];
|
|
63 | 63 |
|
64 | 64 |
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) { |
65 |
header("Location: services_captiveportal_zones.php");
|
|
66 |
exit;
|
|
65 |
header("Location: services_captiveportal_zones.php");
|
|
66 |
exit;
|
|
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
if (!is_array($config['captiveportal'])) |
70 |
$config['captiveportal'] = array();
|
|
70 |
$config['captiveportal'] = array();
|
|
71 | 71 |
$a_cp =& $config['captiveportal']; |
72 | 72 |
|
73 | 73 |
$id = $_GET['id']; |
... | ... | |
94 | 94 |
/* input validation */ |
95 | 95 |
$reqdfields = explode(" ", "mac"); |
96 | 96 |
$reqdfieldsn = array(gettext("MAC address")); |
97 |
|
|
97 |
|
|
98 | 98 |
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); |
99 |
|
|
99 |
|
|
100 | 100 |
$_POST['mac'] = str_replace("-", ":", $_POST['mac']); |
101 |
|
|
101 |
|
|
102 | 102 |
if (($_POST['mac'] && !is_macaddr($_POST['mac']))) { |
103 | 103 |
$input_errors[] = sprintf("%s. [%s]", gettext("A valid MAC address must be specified"), $_POST['mac']); |
104 | 104 |
} |
... | ... | |
110 | 110 |
foreach ($a_passthrumacs as $macent) { |
111 | 111 |
if (isset($id) && ($a_passthrumacs[$id]) && ($a_passthrumacs[$id] === $macent)) |
112 | 112 |
continue; |
113 |
|
|
113 |
|
|
114 | 114 |
if ($macent['mac'] == $_POST['mac']){ |
115 | 115 |
$input_errors[] = sprintf("[%s] %s.", $_POST['mac'], gettext("already allowed")); |
116 | 116 |
break; |
117 |
}
|
|
117 |
} |
|
118 | 118 |
} |
119 | 119 |
|
120 | 120 |
if (!$input_errors) { |
... | ... | |
126 | 126 |
$mac['bw_down'] = $_POST['bw_down']; |
127 | 127 |
if ($_POST['username']) |
128 | 128 |
$mac['username'] = $_POST['username']; |
129 |
|
|
129 |
|
|
130 | 130 |
$mac['descr'] = $_POST['descr']; |
131 | 131 |
|
132 | 132 |
if (isset($id) && $a_passthrumacs[$id]) { |
... | ... | |
137 | 137 |
$a_passthrumacs[] = $mac; |
138 | 138 |
} |
139 | 139 |
passthrumacs_sort(); |
140 |
|
|
140 |
|
|
141 | 141 |
write_config(); |
142 | 142 |
|
143 | 143 |
if (isset($config['captiveportal'][$cpzone]['enable'])) { |
... | ... | |
154 | 154 |
$rules = "delete {$ruleno}\n"; |
155 | 155 |
$rules .= "delete " . ++$ruleno . "\n"; |
156 | 156 |
} |
157 |
|
|
157 |
|
|
158 | 158 |
$rules .= captiveportal_passthrumac_configure_entry($mac); |
159 | 159 |
$uniqid = uniqid("{$cpzone}_macedit"); |
160 | 160 |
file_put_contents("{$g['tmp_path']}/{$uniqid}_tmp", $rules); |
... | ... | |
171 | 171 |
<?php include("fbegin.inc"); ?> |
172 | 172 |
<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> |
173 | 173 |
<?php if ($input_errors) print_input_errors($input_errors); ?> |
174 |
<form action="services_captiveportal_mac_edit.php" method="post" name="iform" id="iform"> |
|
175 |
<table width="100%" border="0" cellpadding="6" cellspacing="0"> |
|
174 |
<form action="services_captiveportal_mac_edit.php" method="post" name="iform" id="iform"> |
|
175 |
<table width="100%" border="0" cellpadding="6" cellspacing="0"> |
|
176 |
<tr> |
|
177 |
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Pass-through MAC address");?></td> |
|
178 |
</tr> |
|
176 | 179 |
<tr> |
177 |
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Pass-through MAC address");?></td> |
|
178 |
</tr> |
|
180 |
<td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address"); ?></td> |
|
181 |
<td width="78%" class="vtable"> |
|
182 |
<?=$mandfldhtml;?><input name="mac" type="text" class="formfld unknown" id="mac" size="17" value="<?=htmlspecialchars($pconfig['mac']);?>"> |
|
183 |
<?php |
|
184 |
$ip = getenv('REMOTE_ADDR'); |
|
185 |
$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`; |
|
186 |
$mac = str_replace("\n","",$mac); |
|
187 |
?> |
|
188 |
<a OnClick="document.forms[0].mac.value='<?=$mac?>';" href="#"><?=gettext("Copy my MAC address");?></a> |
|
189 |
<br> |
|
190 |
<span class="vexpl"><?=gettext("MAC address (6 hex octets separated by colons)"); ?></span></td> |
|
191 |
</tr> |
|
179 | 192 |
<tr> |
180 |
<td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address"); ?></td> |
|
181 |
<td width="78%" class="vtable"> |
|
182 |
<?=$mandfldhtml;?><input name="mac" type="text" class="formfld unknown" id="mac" size="17" value="<?=htmlspecialchars($pconfig['mac']);?>"> |
|
183 |
<?php |
|
184 |
$ip = getenv('REMOTE_ADDR'); |
|
185 |
$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`; |
|
186 |
$mac = str_replace("\n","",$mac); |
|
187 |
?> |
|
188 |
<a OnClick="document.forms[0].mac.value='<?=$mac?>';" href="#"><?=gettext("Copy my MAC address");?></a> |
|
189 |
<br> |
|
190 |
<span class="vexpl"><?=gettext("MAC address (6 hex octets separated by colons)"); ?></span></td> |
|
191 |
</tr> |
|
193 |
<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td> |
|
194 |
<td width="78%" class="vtable"> |
|
195 |
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>"> |
|
196 |
<br> |
|
197 |
<span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span> |
|
198 |
</td> |
|
199 |
</tr> |
|
192 | 200 |
<tr> |
193 |
<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td> |
|
194 |
<td width="78%" class="vtable"> |
|
195 |
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>"> |
|
196 |
<br> <span class="vexpl"><?=gettext("You may enter a description here " . |
|
197 |
"for your reference (not parsed)"); ?>.</span></td> |
|
198 |
</tr> |
|
201 |
<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth up"); ?></td> |
|
202 |
<td width="78%" class="vtable"> |
|
203 |
<input name="bw_up" type="text" class="formfld unknown" id="bw_up" size="10" value="<?=htmlspecialchars($pconfig['bw_up']);?>"> |
|
204 |
<br> |
|
205 |
<span class="vexpl"><?=gettext("Enter a upload limit to be enforced on this MAC address in Kbit/s"); ?></span> |
|
206 |
</td> |
|
207 |
</tr> |
|
199 | 208 |
<tr> |
200 |
<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth up"); ?></td> |
|
201 |
<td width="78%" class="vtable"> |
|
202 |
<input name="bw_up" type="text" class="formfld unknown" id="bw_up" size="10" value="<?=htmlspecialchars($pconfig['bw_up']);?>"> |
|
203 |
<br> <span class="vexpl"><?=gettext("Enter a upload limit to be enforced on this MAC address in Kbit/s"); ?></span></td> |
|
204 |
</tr> |
|
209 |
<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth down"); ?></td> |
|
210 |
<td width="78%" class="vtable"> |
|
211 |
<input name="bw_down" type="text" class="formfld unknown" id="bw_down" size="10" value="<?=htmlspecialchars($pconfig['bw_down']);?>"> |
|
212 |
<br> |
|
213 |
<span class="vexpl"><?=gettext("Enter a download limit to be enforced on this MAC address in Kbit/s"); ?></span> |
|
214 |
</td> |
|
215 |
</tr> |
|
205 | 216 |
<tr> |
206 |
<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth down"); ?></td> |
|
207 |
<td width="78%" class="vtable"> |
|
208 |
<input name="bw_down" type="text" class="formfld unknown" id="bw_down" size="10" value="<?=htmlspecialchars($pconfig['bw_down']);?>"> |
|
209 |
<br> <span class="vexpl"><?=gettext("Enter a download limit to be enforced on this MAC address in Kbit/s"); ?></span></td> |
|
210 |
</tr> |
|
211 |
<tr> |
|
212 |
<td width="22%" valign="top"> </td> |
|
213 |
<td width="78%"> |
|
214 |
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> |
|
215 |
<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>"> |
|
216 |
<?php if (isset($id) && $a_passthrumacs[$id]): ?> |
|
217 |
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>"> |
|
218 |
<?php endif; ?> |
|
219 |
<?php if (isset($pconfig['username']) && $pconfig['username']): ?> |
|
220 |
<input name="username" type="hidden" value="<?=htmlspecialchars($pconfig['username']);?>"> |
|
221 |
<?php endif; ?> |
|
222 |
</td> |
|
223 |
</tr> |
|
224 |
</table> |
|
217 |
<td width="22%" valign="top"> </td> |
|
218 |
<td width="78%"> |
|
219 |
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"> |
|
220 |
<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>"> |
|
221 |
<?php if (isset($id) && $a_passthrumacs[$id]): ?> |
|
222 |
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>"> |
|
223 |
<?php endif; ?> |
|
224 |
<?php if (isset($pconfig['username']) && $pconfig['username']): ?> |
|
225 |
<input name="username" type="hidden" value="<?=htmlspecialchars($pconfig['username']);?>"> |
|
226 |
<?php endif; ?> |
|
227 |
</td> |
|
228 |
</tr> |
|
229 |
</table> |
|
225 | 230 |
</form> |
226 | 231 |
<?php include("fend.inc"); ?> |
227 | 232 |
</body> |
Also available in: Unified diff
Fix indent and whitespaces