Projet

Général

Profil

Télécharger (9,42 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_captiveportal_filemanager.php @ 428c3e9d

1
<?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

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	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

    
20
	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
/*
32
	pfSense_MODULE:	captiveportal
33
*/
34

    
35
##|+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
function cpelementscmp($a, $b) {
43
	return strcasecmp($a['name'], $b['name']);
44
}
45

    
46
function cpelements_sort() {
47
        global $config, $cpzone;
48

    
49
        usort($config['captiveportal'][$cpzone]['element'],"cpelementscmp");
50
}
51

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

    
58
$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

    
71
$pgtitle = array(gettext("Services"),gettext("Captive portal"), $a_cp[$cpzone]['zone']);
72
$shortcut_section = "captiveportal";
73

    
74
if (!is_array($a_cp[$cpzone]['element']))
75
	$a_cp[$cpzone]['element'] = array();
76
$a_element =& $a_cp[$cpzone]['element'];
77

    
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

    
87
    if (is_uploaded_file($_FILES['new']['tmp_name'])) {
88

    
89
    	if(!stristr($_FILES['new']['name'], "captiveportal-"))
90
    		$name = "captiveportal-" . $_FILES['new']['name'];
91
    	else
92
    		$name = $_FILES['new']['name'];
93
    	$size = filesize($_FILES['new']['tmp_name']);
94

    
95
    	// is there already a file with that name?
96
    	foreach ($a_element as $element) {
97
			if ($element['name'] == $name) {
98
				$input_errors[] = sprintf(gettext("A file with the name '%s' already exists."), $name);
99
				break;
100
			}
101
		}
102

    
103
		// check total file size
104
		if (($total_size + $size) > $g['captiveportal_element_sizelimit']) {
105
			$input_errors[] = gettext("The total size of all files uploaded may not exceed ") .
106
				format_bytes($g['captiveportal_element_sizelimit']) . ".";
107
		}
108

    
109
		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

    
115
			$a_element[] = $element;
116
			cpelements_sort();
117

    
118
			write_config();
119
			captiveportal_write_elements();
120
			header("Location: services_captiveportal_filemanager.php?zone={$cpzone}");
121
			exit;
122
		}
123
    }
124
} else if (($_GET['act'] == "del") && !empty($cpzone) && $a_element[$_GET['id']]) {
125
	conf_mount_rw();
126
	@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
	unset($a_element[$_GET['id']]);
130
	write_config();
131
	header("Location: services_captiveportal_filemanager.php?zone={$cpzone}");
132
	exit;
133
}
134

    
135
include("head.inc");
136

    
137
?>
138
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
139
<?php include("fbegin.inc"); ?>
140
<form action="services_captiveportal_filemanager.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
141
<input type="hidden" name="zone" id="zone" value="<?=htmlspecialchars($cpzone);?>" />
142
<?php if ($input_errors) print_input_errors($input_errors); ?>
143
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="captiveportal file manager">
144
  <tr><td class="tabnavtbl">
145
<?php
146
	$tab_array = array();
147
	$tab_array[] = array(gettext("Captive portal(s)"), false, "services_captiveportal.php?zone={$cpzone}");
148
	$tab_array[] = array(gettext("MAC"), false, "services_captiveportal_mac.php?zone={$cpzone}");
149
	$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
	display_top_tabs($tab_array, true);
154
?>  </td></tr>
155
  <tr>
156
    <td class="tabcont">
157
	<table width="80%" border="0" cellpadding="0" cellspacing="0" summary="main">
158
      <tr>
159
        <td width="70%" class="listhdrr"><?=gettext("Name"); ?></td>
160
        <td width="20%" class="listhdr"><?=gettext("Size"); ?></td>
161
        <td width="10%" class="list">
162
		<table border="0" cellspacing="0" cellpadding="1" summary="icons">
163
		    <tr>
164
			<td width="17" height="17"></td>
165
			<td><a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&amp;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
		    </tr>
167
		</table>
168
	</td>
169
      </tr>
170
<?php if (is_array($a_cp[$cpzone]['element'])):
171
	$i = 0; foreach ($a_cp[$cpzone]['element'] as $element): ?>
172
  	  <tr>
173
		<td class="listlr"><?=htmlspecialchars($element['name']);?></td>
174
		<td class="listr" align="right"><?=format_bytes($element['size']);?></td>
175
		<td valign="middle" class="list nowrap">
176
		<a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&amp;act=del&amp;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
		</td>
178
	  </tr>
179
  <?php $i++; endforeach; endif; ?>
180

    
181
  <?php if ($total_size > 0): ?>
182
  	  <tr>
183
		<td class="listlr" style="background-color: #eee"><strong><?=gettext("TOTAL"); ?></strong></td>
184
		<td class="listr" style="background-color: #eee" align="right"><strong><?=format_bytes($total_size);?></strong></td>
185
		<td valign="middle" class="list nowrap"></td>
186
	  </tr>
187
  <?php endif; ?>
188

    
189
  <?php if ($_GET['act'] == 'add'): ?>
190
	  <tr>
191
		<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
		</td>
196
	  </tr>
197
  <?php else: ?>
198
	  <tr>
199
		<td class="list" colspan="2"></td>
200
		<td class="list">
201
			<table border="0" cellspacing="0" cellpadding="1" summary="add">
202
			    <tr>
203
				<td width="17" height="17"></td>
204
				<td><a href="services_captiveportal_filemanager.php?zone=<?=$cpzone;?>&amp;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
			    </tr>
206
			</table>
207
		</td>
208
	  </tr>
209
  <?php endif; ?>
210
	</table>
211
	<span class="vexpl"><span class="red"><strong>
212
	<?=gettext("Note:"); ?><br />
213
	</strong></span>
214
	<?=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
	"file manager. Then you can include it in your portal page like this:"); ?><br /><br />
219
	<tt>&lt;img src=&quot;captiveportal-test.jpg&quot; width=... height=...&gt;</tt>
220
	<br /><br />
221
	<?=gettext("In addition, you can also upload .php files for execution.  You can pass the filename " .
222
	"to your custom page from the initial page by using text similar to:"); ?>
223
	<br /><br />
224
	<tt>&lt;a href="/captiveportal-aup.php?zone=$PORTAL_ZONE$&amp;redirurl=$PORTAL_REDIRURL$"&gt;<?=gettext("Acceptable usage policy"); ?>&lt;/a&gt;</tt>
225
	<br /><br />
226
	<?php printf(gettext("The total size limit for all files is %s."), format_bytes($g['captiveportal_element_sizelimit']));?></span>
227
</td>
228
</tr>
229
</table>
230
</form>
231
<?php include("fend.inc"); ?>
232
</body>
233
</html>
(137-137/254)