Projet

Général

Profil

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

univnautes / usr / local / www / services_captiveportal_mac_edit.php @ 6b71ebb7

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
$pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit pass-through MAC address"));
58
$shortcut_section = "captiveportal";
59

    
60
$cpzone = $_GET['zone'];
61
if (isset($_POST['zone']))
62
        $cpzone = $_POST['zone'];
63

    
64
if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
65
        header("Location: services_captiveportal_zones.php");
66
        exit;
67
}
68

    
69
if (!is_array($config['captiveportal']))
70
        $config['captiveportal'] = array();
71
$a_cp =& $config['captiveportal'];
72

    
73
if (is_numericint($_GET['id']))
74
	$id = $_GET['id'];
75
if (isset($_POST['id']) && is_numericint($_POST['id']))
76
	$id = $_POST['id'];
77

    
78
if (!is_array($a_cp[$cpzone]['passthrumac']))
79
	$a_cp[$cpzone]['passthrumac'] = array();
80
$a_passthrumacs = &$a_cp[$cpzone]['passthrumac'];
81

    
82
if (isset($id) && $a_passthrumacs[$id]) {
83
	$pconfig['mac'] = $a_passthrumacs[$id]['mac'];
84
	$pconfig['bw_up'] = $a_passthrumacs[$id]['bw_up'];
85
	$pconfig['bw_down'] = $a_passthrumacs[$id]['bw_down'];
86
	$pconfig['descr'] = $a_passthrumacs[$id]['descr'];
87
	$pconfig['username'] = $a_passthrumacs[$id]['username'];
88
}
89

    
90
if ($_POST) {
91

    
92
	unset($input_errors);
93
	$pconfig = $_POST;
94

    
95
	/* input validation */
96
	$reqdfields = explode(" ", "mac");
97
	$reqdfieldsn = array(gettext("MAC address"));
98
	
99
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
100
	
101
	$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
102
	
103
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
104
		$input_errors[] = sprintf("%s. [%s]", gettext("A valid MAC address must be specified"), $_POST['mac']);
105
	}
106
	if ($_POST['bw_up'] && !is_numeric($_POST['bw_up']))
107
		$input_errors[] = gettext("Upload speed needs to be an integer");
108
	if ($_POST['bw_down'] && !is_numeric($_POST['bw_down']))
109
		$input_errors[] = gettext("Download speed needs to be an integer");
110

    
111
	foreach ($a_passthrumacs as $macent) {
112
		if (isset($id) && ($a_passthrumacs[$id]) && ($a_passthrumacs[$id] === $macent))
113
			continue;
114
		
115
		if ($macent['mac'] == $_POST['mac']){
116
			$input_errors[] = sprintf("[%s] %s.", $_POST['mac'], gettext("already allowed"));
117
			break;
118
		}	
119
	}
120

    
121
	if (!$input_errors) {
122
		$mac = array();
123
		$mac['mac'] = $_POST['mac'];
124
		if ($_POST['bw_up'])
125
			$mac['bw_up'] = $_POST['bw_up'];
126
		if ($_POST['bw_down'])
127
			$mac['bw_down'] = $_POST['bw_down'];
128
		if ($_POST['username'])
129
			$mac['username'] = $_POST['username'];
130
		
131
		$mac['descr'] = $_POST['descr'];
132

    
133
		if (isset($id) && $a_passthrumacs[$id]) {
134
			$oldmac = $a_passthrumacs[$id]['mac'];
135
			$a_passthrumacs[$id] = $mac;
136
		} else {
137
			$oldmac = $mac['mac'];
138
			$a_passthrumacs[] = $mac;
139
		}
140
		passthrumacs_sort();
141
		
142
		write_config();
143

    
144
		if (isset($config['captiveportal'][$cpzone]['enable'])) {
145
			$ruleno = captiveportal_get_ipfw_passthru_ruleno($oldmac);
146
			if ($ruleno) {
147
				captiveportal_free_ipfw_ruleno($ruleno);
148
				$pipeno = captiveportal_get_dn_passthru_ruleno($oldmac);
149
				if ($pipeno) {
150
					captiveportal_free_dn_ruleno($pipeno);
151
					$rules .= "pipe delete {$pipeno}\n";
152
					++$pipeno;
153
					$rules .= "pipe delete {$pipeno}\n";
154
				}
155
				$rules = "delete {$ruleno}\n";
156
				$rules .= "delete " . ++$ruleno . "\n";
157
			}
158
			
159
			$rules .= captiveportal_passthrumac_configure_entry($mac);
160
			$uniqid = uniqid("{$cpzone}_macedit");
161
			file_put_contents("{$g['tmp_path']}/{$uniqid}_tmp", $rules);
162
			mwexec("/sbin/ipfw -x {$cpzone} -q {$g['tmp_path']}/{$uniqid}_tmp");
163
			@unlink("{$g['tmp_path']}/{$uniqid}_tmp");
164
		}
165

    
166
		header("Location: services_captiveportal_mac.php?zone={$cpzone}");
167
		exit;
168
	}
169
}
170
include("head.inc");
171
?>
172
<?php include("fbegin.inc"); ?>
173
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
174
<?php if ($input_errors) print_input_errors($input_errors); ?>
175
            <form action="services_captiveportal_mac_edit.php" method="post" name="iform" id="iform">
176
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
177
		<tr>
178
                        <td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Pass-through MAC address");?></td>
179
                </tr>
180
		<tr>
181
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address"); ?></td>
182
                  <td width="78%" class="vtable"> 
183
                    <?=$mandfldhtml;?><input name="mac" type="text" class="formfld unknown" id="mac" size="17" value="<?=htmlspecialchars($pconfig['mac']);?>">
184
                    <?php
185
                        $ip = getenv('REMOTE_ADDR');
186
                        $mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
187
                        $mac = str_replace("\n","",$mac);
188
                    ?>
189
                    <a OnClick="document.forms[0].mac.value='<?=$mac?>';" href="#"><?=gettext("Copy my MAC address");?></a>
190
                    <br> 
191
                    <span class="vexpl"><?=gettext("MAC address (6 hex octets separated by colons)"); ?></span></td>
192
                </tr>
193
		<tr>
194
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
195
                  <td width="78%" class="vtable"> 
196
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
197
                    <br> <span class="vexpl"><?=gettext("You may enter a description here " .
198
                    "for your reference (not parsed)"); ?>.</span></td>
199
                </tr>
200
		<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> <span class="vexpl"><?=gettext("Enter a upload limit to be enforced on this MAC address in Kbit/s"); ?></span></td>
205
                </tr>
206
		<tr>
207
                  <td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth down"); ?></td>
208
                  <td width="78%" class="vtable"> 
209
                    <input name="bw_down" type="text" class="formfld unknown" id="bw_down" size="10" value="<?=htmlspecialchars($pconfig['bw_down']);?>">
210
                    <br> <span class="vexpl"><?=gettext("Enter a download limit to be enforced on this MAC address in Kbit/s"); ?></span></td>
211
                </tr>
212
                <tr>
213
                  <td width="22%" valign="top">&nbsp;</td>
214
                  <td width="78%"> 
215
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">
216
                    <input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>">
217
                    <?php if (isset($id) && $a_passthrumacs[$id]): ?>
218
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
219
                    <?php endif; ?>
220
		    <?php if (isset($pconfig['username']) && $pconfig['username']): ?>
221
                    <input name="username" type="hidden" value="<?=htmlspecialchars($pconfig['username']);?>">
222
                    <?php endif; ?>
223
                  </td>
224
                </tr>
225
              </table>
226
</form>
227
<?php include("fend.inc"); ?>
228
</body>
229
</html>
(143-143/246)