Projet

Général

Profil

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

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

1
<?php 
2
/*
3
	services_captiveportal_hostname_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-editallowedhostnames
39
##|*NAME=Services: Captive portal: Edit Allowed Hostnames page
40
##|*DESCR=Allow access to the 'Services: Captive portal: Edit Allowed Hostnames' page.
41
##|*MATCH=services_captiveportal_hostname_edit.php*
42
##|-PRIV
43

    
44
function allowedhostnamescmp($a, $b) {
45
	return strcmp($a['hostname'], $b['hostname']);
46
}
47

    
48
function allowedhostnames_sort() {
49
	global $g, $config, $cpzone;
50
	usort($config['captiveportal'][$cpzone]['allowedhostname'],"allowedhostnamescmp");
51
}
52

    
53
require("guiconfig.inc");
54
require("functions.inc");
55
require_once("filter.inc");
56
require("shaper.inc");
57
require("captiveportal.inc");
58

    
59
$pgtitle = array(gettext("Services"),gettext("Captive portal"),gettext("Edit allowed Hostname"));
60
$shortcut_section = "captiveportal";
61

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

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

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

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

    
80
if (!is_array($a_cp[$cpzone]['allowedhostname']))
81
	$a_cp[$cpzone]['allowedhostname'] = array();
82
$a_allowedhostnames = &$a_cp[$cpzone]['allowedhostname'];
83

    
84
if (isset($id) && $a_allowedhostnames[$id]) {
85
	$pconfig['zone'] = $a_allowedhostnames[$id]['zone'];
86
	$pconfig['hostname'] = $a_allowedhostnames[$id]['hostname'];
87
	$pconfig['sn'] = $a_allowedhostnames[$id]['sn'];
88
	$pconfig['dir'] = $a_allowedhostnames[$id]['dir'];
89
	$pconfig['bw_up'] = $a_allowedhostnames[$id]['bw_up'];
90
	$pconfig['bw_down'] = $a_allowedhostnames[$id]['bw_down'];
91
	$pconfig['descr'] = $a_allowedhostnames[$id]['descr'];
92
}
93

    
94
if ($_POST) {
95

    
96
	unset($input_errors);
97
	$pconfig = $_POST;
98

    
99
	/* input validation */
100
	$reqdfields = explode(" ", "hostname");
101
	$reqdfieldsn = array(gettext("Allowed Hostname"));
102
	
103
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
104
	
105
	if (($_POST['hostname'] && !is_hostname($_POST['hostname']))) 
106
		$input_errors[] = sprintf(gettext("A valid Hostname must be specified. [%s]"), $_POST['hostname']);
107

    
108
	if ($_POST['bw_up'] && !is_numeric($_POST['bw_up']))
109
		$input_errors[] = gettext("Upload speed needs to be an integer");
110
	if ($_POST['bw_down'] && !is_numeric($_POST['bw_down']))
111
		$input_errors[] = gettext("Download speed needs to be an integer");
112

    
113
	foreach ($a_allowedhostnames as $ipent) {
114
		if (isset($id) && ($a_allowedhostnames[$id]) && ($a_allowedhostnames[$id] === $ipent))
115
			continue;
116
		
117
		if ($ipent['hostname'] == $_POST['hostname']){
118
			$input_errors[] = sprintf("[%s] %s.", $_POST['hostname'], gettext("already allowed")) ;
119
			break ;
120
		}	
121
	}
122

    
123
	if (!$input_errors) {
124
		$ip = array();
125
		$ip['hostname'] = $_POST['hostname'];
126
		$ip['sn'] = $_POST['sn'];
127
		$ip['dir'] = $_POST['dir'];
128
		$ip['descr'] = $_POST['descr'];
129
		if ($_POST['bw_up'])
130
			$ip['bw_up'] = $_POST['bw_up'];
131
		if ($_POST['bw_down'])
132
			$ip['bw_down'] = $_POST['bw_down'];
133
		if (isset($id) && $a_allowedhostnames[$id])
134
			$a_allowedhostnames[$id] = $ip;
135
		else
136
			$a_allowedhostnames[] = $ip;
137

    
138
		allowedhostnames_sort();
139
		
140
		write_config();
141

    
142
		$rules = captiveportal_allowedhostname_configure();
143
		@file_put_contents("{$g['tmp_path']}/hostname_rules", $rules);
144
		$cpzoneid = $a_cp[$cpzone]['zoneid'];
145
		mwexec("/sbin/ipfw -x {$cpzoneid} {$g['tmp_path']}/hostname_rules");
146
		unset($rules);
147
		
148
		header("Location: services_captiveportal_hostname.php?zone={$cpzone}");
149
		exit;
150
	}
151
}
152

    
153
include("head.inc");
154

    
155
?>
156
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
157
<?php include("fbegin.inc"); ?>
158
<?php if ($input_errors) print_input_errors($input_errors); ?>
159
		<form action="services_captiveportal_hostname_edit.php" method="post" name="iform" id="iform">
160
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="captiveportal hostname edit">
161
		<tr>
162
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Direction"); ?></td>
163
			<td width="78%" class="vtable"> 
164
			<select name="dir" class="formfld">
165
		<?php 
166
			$dirs = array(gettext("Both"),gettext("From"),gettext("To")) ;
167
			foreach ($dirs as $dir): ?>
168
				<option value="<?=strtolower($dir);?>" <?php if (strtolower($dir) == strtolower($pconfig['dir'])) echo "selected=\"selected\"";?> >
169
				<?=htmlspecialchars($dir);?>
170
				</option>
171
		<?php endforeach; ?>
172
			</select>
173
			<br /> 
174
			<span class="vexpl"><?=gettext("Use"); ?> <em><?=gettext("From"); ?></em> <?=gettext("to always allow an Hostname through the captive portal (without authentication)"); ?>. 
175
				<?=gettext("Use"); ?> <em><?=gettext("To"); ?></em> <?=gettext("to allow access from all clients (even non-authenticated ones) behind the portal to this Hostname"); ?>.</span></td>
176
		</tr>
177
		<tr>
178
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname"); ?></td>
179
			<td width="78%" class="vtable"> 
180
				<?=$mandfldhtml;?><input name="hostname" type="text" class="formfld unknown" id="hostname" size="17" value="<?=htmlspecialchars($pconfig['hostname']);?>" />
181
			<br /> 
182
			<span class="vexpl"><?=gettext("Hostname");?>.</span></td>
183
		</tr>
184
		<tr>
185
			<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
186
			<td width="78%" class="vtable"> 
187
			<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
188
			<br /> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span></td>
189
			</tr>
190
		<tr>
191
			<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth up"); ?></td>
192
			<td width="78%" class="vtable">
193
			<input name="bw_up" type="text" class="formfld unknown" id="bw_up" size="10" value="<?=htmlspecialchars($pconfig['bw_up']);?>" />
194
			<br /> <span class="vexpl"><?=gettext("Enter a upload limit to be enforced on this Hostname in Kbit/s"); ?></span></td>
195
		</tr>
196
		<tr>
197
			<td width="22%" valign="top" class="vncell"><?=gettext("Bandwidth down"); ?></td>
198
			<td width="78%" class="vtable">
199
			<input name="bw_down" type="text" class="formfld unknown" id="bw_down" size="10" value="<?=htmlspecialchars($pconfig['bw_down']);?>" />
200
			<br /> <span class="vexpl"><?=gettext("Enter a download limit to be enforced on this Hostname in Kbit/s"); ?></span></td>
201
		</tr>
202
		<tr>
203
			<td width="22%" valign="top">&nbsp;</td>
204
			<td width="78%"> 
205
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
206
				<input name="zone" type="hidden" value="<?=htmlspecialchars($cpzone);?>" />
207
				<?php if (isset($id) && $a_allowedhostnames[$id]): ?>
208
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
209
				<?php endif; ?>
210
			</td>
211
		</tr>
212
	</table>
213
</form>
214
<?php include("fend.inc"); ?>
215
</body>
216
</html>
(140-140/255)