1 |
0bd34ed6
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
services_captiveportal_filemanager.php
|
4 |
|
|
part of m0n0wall (http://m0n0.ch/wall)
|
5 |
|
|
|
6 |
|
|
Copyright (C) 2005-2006 Jonathan De Graeve (jonathan.de.graeve@imelda.be)
|
7 |
|
|
and Paul Taylor (paultaylor@winn-dixie.com).
|
8 |
|
|
All rights reserved.
|
9 |
|
|
|
10 |
|
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
5e541497
|
Scott Ullrich
|
|
13 |
0bd34ed6
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
5e541497
|
Scott Ullrich
|
|
16 |
0bd34ed6
|
Scott Ullrich
|
2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
documentation and/or other materials provided with the distribution.
|
19 |
5e541497
|
Scott Ullrich
|
|
20 |
0bd34ed6
|
Scott Ullrich
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
|
|
*/
|
31 |
1d333258
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_MODULE: captiveportal
|
33 |
|
|
*/
|
34 |
0bd34ed6
|
Scott Ullrich
|
|
35 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
36 |
|
|
##|*IDENT=page-services-captiveportal-filemanager
|
37 |
|
|
##|*NAME=Services: Captive portal: File Manager page
|
38 |
|
|
##|*DESCR=Allow access to the 'Services: Captive portal: File Manager' page.
|
39 |
|
|
##|*MATCH=services_captiveportal_filemanager.php*
|
40 |
|
|
##|-PRIV
|
41 |
|
|
|
42 |
4504a769
|
Ermal Lu?i
|
function cpelementscmp($a, $b) {
|
43 |
|
|
return strcasecmp($a['name'], $b['name']);
|
44 |
|
|
}
|
45 |
0d64af59
|
Ermal Lu?i
|
|
46 |
4504a769
|
Ermal Lu?i
|
function cpelements_sort() {
|
47 |
b4792bf8
|
Ermal
|
global $config, $cpzone;
|
48 |
0d64af59
|
Ermal Lu?i
|
|
49 |
b4792bf8
|
Ermal
|
usort($config['captiveportal'][$cpzone]['element'],"cpelementscmp");
|
50 |
0d64af59
|
Ermal Lu?i
|
}
|
51 |
6b07c15a
|
Matthew Grooms
|
|
52 |
7ab2b688
|
Scott Ullrich
|
require("guiconfig.inc");
|
53 |
|
|
require("functions.inc");
|
54 |
f6339216
|
jim-p
|
require_once("filter.inc");
|
55 |
7ab2b688
|
Scott Ullrich
|
require("shaper.inc");
|
56 |
|
|
require("captiveportal.inc");
|
57 |
0bd34ed6
|
Scott Ullrich
|
|
58 |
b4792bf8
|
Ermal
|
$cpzone = $_GET['zone'];
|
59 |
|
|
if (isset($_POST['zone']))
|
60 |
|
|
$cpzone = $_POST['zone'];
|
61 |
|
|
|
62 |
|
|
if (empty($cpzone)) {
|
63 |
|
|
header("Location: services_captiveportal_zones.php");
|
64 |
|
|
exit;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
if (!is_array($config['captiveportal']))
|
68 |
|
|
$config['captiveportal'] = array();
|
69 |
|
|
$a_cp =& $config['captiveportal'];
|
70 |
355ea0c2
|
Carlos Eduardo Ramos
|
|
71 |
b4792bf8
|
Ermal
|
$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']);
|
72 |
b32dd0a6
|
jim-p
|
$shortcut_section = "captiveportal";
|
73 |
0bd34ed6
|
Scott Ullrich
|
|
74 |
b4792bf8
|
Ermal
|
if (!is_array($a_cp[$cpzone]['element']))
|
75 |
|
|
$a_cp[$cpzone]['element'] = array();
|
76 |
|
|
$a_element =& $a_cp[$cpzone]['element'];
|
77 |
0bd34ed6
|
Scott Ullrich
|
|
78 |
|
|
// Calculate total size of all files
|
79 |
|
|
$total_size = 0;
|
80 |
|
|
foreach ($a_element as $element) {
|
81 |
|
|
$total_size += $element['size'];
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
if ($_POST) {
|
85 |
|
|
unset($input_errors);
|
86 |
5e541497
|
Scott Ullrich
|
|
87 |
0bd34ed6
|
Scott Ullrich
|
if (is_uploaded_file($_FILES['new']['tmp_name'])) {
|
88 |
5e541497
|
Scott Ullrich
|
|
89 |
|
|
if(!stristr($_FILES['new']['name'], "captiveportal-"))
|
90 |
|
|
$name = "captiveportal-" . $_FILES['new']['name'];
|
91 |
|
|
else
|
92 |
|
|
$name = $_FILES['new']['name'];
|
93 |
0bd34ed6
|
Scott Ullrich
|
$size = filesize($_FILES['new']['tmp_name']);
|
94 |
5e541497
|
Scott Ullrich
|
|
95 |
0bd34ed6
|
Scott Ullrich
|
// is there already a file with that name?
|
96 |
|
|
foreach ($a_element as $element) {
|
97 |
|
|
if ($element['name'] == $name) {
|
98 |
355ea0c2
|
Carlos Eduardo Ramos
|
$input_errors[] = sprintf(gettext("A file with the name '%s' already exists."), $name);
|
99 |
0bd34ed6
|
Scott Ullrich
|
break;
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
5e541497
|
Scott Ullrich
|
|
103 |
0bd34ed6
|
Scott Ullrich
|
// check total file size
|
104 |
|
|
if (($total_size + $size) > $g['captiveportal_element_sizelimit']) {
|
105 |
355ea0c2
|
Carlos Eduardo Ramos
|
$input_errors[] = gettext("The total size of all files uploaded may not exceed ") .
|
106 |
0bd34ed6
|
Scott Ullrich
|
format_bytes($g['captiveportal_element_sizelimit']) . ".";
|
107 |
|
|
}
|
108 |
5e541497
|
Scott Ullrich
|
|
109 |
0bd34ed6
|
Scott Ullrich
|
if (!$input_errors) {
|
110 |
|
|
$element = array();
|
111 |
|
|
$element['name'] = $name;
|
112 |
|
|
$element['size'] = $size;
|
113 |
|
|
$element['content'] = base64_encode(file_get_contents($_FILES['new']['tmp_name']));
|
114 |
5e541497
|
Scott Ullrich
|
|
115 |
0bd34ed6
|
Scott Ullrich
|
$a_element[] = $element;
|
116 |
0e3aa71c
|
Erik Fonnesbeck
|
cpelements_sort();
|
117 |
5e541497
|
Scott Ullrich
|
|
118 |
0bd34ed6
|
Scott Ullrich
|
write_config();
|
119 |
|
|
captiveportal_write_elements();
|
120 |
b4792bf8
|
Ermal
|
header("Location: services_captiveportal_filemanager.php?zone={$cpzone}");
|
121 |
0bd34ed6
|
Scott Ullrich
|
exit;
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
b4792bf8
|
Ermal
|
} else if (($_GET['act'] == "del") && !empty($cpzone) && $a_element[$_GET['id']]) {
|
125 |
|
|
conf_mount_rw();
|
126 |
bdba4fa7
|
Ermal
|
@unlink("{$g['captiveportal_element_path']}/" . $a_element[$_GET['id']]['name']);
|
127 |
|
|
@unlink("{$g['captiveportal_path']}/" . $a_element[$_GET['id']]['name']);
|
128 |
|
|
conf_mount_ro();
|
129 |
b4792bf8
|
Ermal
|
unset($a_element[$_GET['id']]);
|
130 |
|
|
write_config();
|
131 |
|
|
header("Location: services_captiveportal_filemanager.php?zone={$cpzone}");
|
132 |
|
|
exit;
|
133 |
0bd34ed6
|
Scott Ullrich
|
}
|
134 |
|
|
|
135 |
|
|
include("head.inc");
|
136 |
|
|
|
137 |
|
|
?>
|
138 |
93588e1a
|
Scott Dale
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
139 |
ad7af00b
|
Colin Fleming
|
<?php include("fbegin.inc"); ?>
|
140 |
0bd34ed6
|
Scott Ullrich
|
<form action="services_captiveportal_filemanager.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
|
141 |
e41ec584
|
Renato Botelho
|
<input type="hidden" name="zone" id="zone" value="<?=htmlspecialchars($cpzone);?>" />
|
142 |
0bd34ed6
|
Scott Ullrich
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
143 |
ad7af00b
|
Colin Fleming
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="captiveportal file manager">
|
144 |
0bd34ed6
|
Scott Ullrich
|
<tr><td class="tabnavtbl">
|
145 |
|
|
<?php
|
146 |
|
|
$tab_array = array();
|
147 |
736c36c6
|
Renato Botelho
|
$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
|
148 |
ed8899b5
|
Renato Botelho
|
$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
|
149 |
b4792bf8
|
Ermal
|
$tab_array[] = array(gettext("Allowed IP addresses"), false, "services_captiveportal_ip.php?zone={$cpzone}");
|
150 |
|
|
$tab_array[] = array(gettext("Allowed Hostnames"), false, "services_captiveportal_hostname.php?zone={$cpzone}");
|
151 |
|
|
$tab_array[] = array(gettext("Vouchers"), false, "services_captiveportal_vouchers.php?zone={$cpzone}");
|
152 |
|
|
$tab_array[] = array(gettext("File Manager"), true, "services_captiveportal_filemanager.php?zone={$cpzone}");
|
153 |
9592c132
|
Scott Ullrich
|
display_top_tabs($tab_array, true);
|
154 |
0bd34ed6
|
Scott Ullrich
|
?> </td></tr>
|
155 |
|
|
<tr>
|
156 |
|
|
<td class="tabcont">
|
157 |
ad7af00b
|
Colin Fleming
|
<table width="80%" border="0" cellpadding="0" cellspacing="0" summary="main">
|
158 |
0bd34ed6
|
Scott Ullrich
|
<tr>
|
159 |
355ea0c2
|
Carlos Eduardo Ramos
|
<td width="70%" class="listhdrr"><?=gettext("Name"); ?></td>
|
160 |
|
|
<td width="20%" class="listhdr"><?=gettext("Size"); ?></td>
|
161 |
d415d821
|
Seth Mos
|
<td width="10%" class="list">
|
162 |
ad7af00b
|
Colin Fleming
|
<table border="0" cellspacing="0" cellpadding="1" summary="icons">
|
163 |
d415d821
|
Seth Mos
|
<tr>
|
164 |
3b2395ae
|
Colin Fleming
|
<td width="17" height="17"></td>
|
165 |
ad7af00b
|
Colin Fleming
|
<td><a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&act=add"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add file"); ?>" width="17" height="17" border="0" alt="add" /></a></td>
|
166 |
d415d821
|
Seth Mos
|
</tr>
|
167 |
|
|
</table>
|
168 |
|
|
</td>
|
169 |
0bd34ed6
|
Scott Ullrich
|
</tr>
|
170 |
b4792bf8
|
Ermal
|
<?php if (is_array($a_cp[$cpzone]['element'])):
|
171 |
|
|
$i = 0; foreach ($a_cp[$cpzone]['element'] as $element): ?>
|
172 |
0bd34ed6
|
Scott Ullrich
|
<tr>
|
173 |
|
|
<td class="listlr"><?=htmlspecialchars($element['name']);?></td>
|
174 |
|
|
<td class="listr" align="right"><?=format_bytes($element['size']);?></td>
|
175 |
428c3e9d
|
Colin Fleming
|
<td valign="middle" class="list nowrap">
|
176 |
ad7af00b
|
Colin Fleming
|
<a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this file?"); ?>')"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete file"); ?>" width="17" height="17" border="0" alt="delete" /></a>
|
177 |
0bd34ed6
|
Scott Ullrich
|
</td>
|
178 |
|
|
</tr>
|
179 |
b4792bf8
|
Ermal
|
<?php $i++; endforeach; endif; ?>
|
180 |
5e541497
|
Scott Ullrich
|
|
181 |
b4792bf8
|
Ermal
|
<?php if ($total_size > 0): ?>
|
182 |
0bd34ed6
|
Scott Ullrich
|
<tr>
|
183 |
355ea0c2
|
Carlos Eduardo Ramos
|
<td class="listlr" style="background-color: #eee"><strong><?=gettext("TOTAL"); ?></strong></td>
|
184 |
0bd34ed6
|
Scott Ullrich
|
<td class="listr" style="background-color: #eee" align="right"><strong><?=format_bytes($total_size);?></strong></td>
|
185 |
ad7af00b
|
Colin Fleming
|
<td valign="middle" class="list nowrap"></td>
|
186 |
0bd34ed6
|
Scott Ullrich
|
</tr>
|
187 |
|
|
<?php endif; ?>
|
188 |
5e541497
|
Scott Ullrich
|
|
189 |
0bd34ed6
|
Scott Ullrich
|
<?php if ($_GET['act'] == 'add'): ?>
|
190 |
|
|
<tr>
|
191 |
ad7af00b
|
Colin Fleming
|
<td class="listlr" colspan="2"><input type="file" name="new" class="formfld file" size="40" id="new" />
|
192 |
|
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Upload"); ?>" /></td>
|
193 |
|
|
<td valign="middle" class="list nowrap">
|
194 |
|
|
<a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("cancel"); ?>" width="17" height="17" border="0" alt="delete" /></a>
|
195 |
0bd34ed6
|
Scott Ullrich
|
</td>
|
196 |
|
|
</tr>
|
197 |
|
|
<?php else: ?>
|
198 |
|
|
<tr>
|
199 |
|
|
<td class="list" colspan="2"></td>
|
200 |
d415d821
|
Seth Mos
|
<td class="list">
|
201 |
ad7af00b
|
Colin Fleming
|
<table border="0" cellspacing="0" cellpadding="1" summary="add">
|
202 |
d415d821
|
Seth Mos
|
<tr>
|
203 |
3b2395ae
|
Colin Fleming
|
<td width="17" height="17"></td>
|
204 |
ad7af00b
|
Colin Fleming
|
<td><a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&act=add"><img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add file"); ?>" width="17" height="17" border="0" alt="add" /></a></td>
|
205 |
d415d821
|
Seth Mos
|
</tr>
|
206 |
|
|
</table>
|
207 |
|
|
</td>
|
208 |
0bd34ed6
|
Scott Ullrich
|
</tr>
|
209 |
|
|
<?php endif; ?>
|
210 |
|
|
</table>
|
211 |
|
|
<span class="vexpl"><span class="red"><strong>
|
212 |
8cd558b6
|
ayvis
|
<?=gettext("Note:"); ?><br />
|
213 |
0bd34ed6
|
Scott Ullrich
|
</strong></span>
|
214 |
355ea0c2
|
Carlos Eduardo Ramos
|
<?=gettext("Any files that you upload here with the filename prefix of captiveportal- will " .
|
215 |
|
|
"be made available in the root directory of the captive portal HTTP(S) server. " .
|
216 |
|
|
"You may reference them directly from your portal page HTML code using relative paths. " .
|
217 |
|
|
"Example: you've uploaded an image with the name 'captiveportal-test.jpg' using the " .
|
218 |
8cd558b6
|
ayvis
|
"file manager. Then you can include it in your portal page like this:"); ?><br /><br />
|
219 |
8e0ca2b9
|
Scott Ullrich
|
<tt><img src="captiveportal-test.jpg" width=... height=...></tt>
|
220 |
8cd558b6
|
ayvis
|
<br /><br />
|
221 |
355ea0c2
|
Carlos Eduardo Ramos
|
<?=gettext("In addition, you can also upload .php files for execution. You can pass the filename " .
|
222 |
16457bdd
|
Renato Botelho
|
"to your custom page from the initial page by using text similar to:"); ?>
|
223 |
8cd558b6
|
ayvis
|
<br /><br />
|
224 |
93fb6094
|
Colin Fleming
|
<tt><a href="/captiveportal-aup.php?zone=$PORTAL_ZONE$&redirurl=$PORTAL_REDIRURL$"><?=gettext("Acceptable usage policy"); ?></a></tt>
|
225 |
8cd558b6
|
ayvis
|
<br /><br />
|
226 |
3b7f0f53
|
Erik Fonnesbeck
|
<?php printf(gettext("The total size limit for all files is %s."), format_bytes($g['captiveportal_element_sizelimit']));?></span>
|
227 |
0bd34ed6
|
Scott Ullrich
|
</td>
|
228 |
|
|
</tr>
|
229 |
|
|
</table>
|
230 |
|
|
</form>
|
231 |
5e541497
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
232 |
93588e1a
|
Scott Dale
|
</body>
|
233 |
|
|
</html>
|