Project

General

Profile

Download (3.06 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
require_once("guiconfig.inc");
4

    
5
/*
6
	pfSense_MODULE:	shell
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8

    
9
*/
10
// Fetch a list of directories and files inside a given directory
11
function get_content($dir) {
12
	$dirs  = array();
13
	$files = array();
14

    
15
	clearstatcache();
16
	$fd = @opendir($dir);
17

    
18
	while($entry = @readdir($fd)) {
19
		if($entry == ".")                 continue;
20
		if($entry == ".." && $dir == "/") continue;
21

    
22
		if(is_dir("{$dir}/{$entry}"))
23
			array_push($dirs, $entry);
24
		else
25
			array_push($files, $entry);
26
	}
27

    
28
	@closedir($fd);
29

    
30
	natsort($dirs);
31
	natsort($files);
32

    
33
	return array($dirs, $files);
34
}
35

    
36
$path = realpath(strlen($_GET['path']) > 0 ? $_GET['path'] : "/");
37
if(is_file($path))
38
	$path = dirname($path);
39

    
40
// ----- header -----
41
?>
42
<table width="100%">
43
	<tr>
44
		<td class="fbHome" width="25px" align="left">
45
			<img onClick="jQuery('#fbTarget').val('<?=$realDir?>'); fbBrowse('/');" src="/filebrowser/images/icon_home.gif" alt="Home" title="Home" />
46
		</td>
47
		<td><b><?=$path;?></b></td>
48
		<td class="fbClose" align="right">
49
			<img onClick="jQuery('#fbBrowser').fadeOut();" border="0" src="/filebrowser/images/icon_cancel.gif" alt="Close" title="Close" />
50
		</td>
51
	</tr>
52
	<tr>
53
		<td id="fbCurrentDir" colspan="3" class="vexpl" align="left">
54
<?php
55

    
56
// ----- read contents -----
57
if(is_dir($path)) {
58
	list($dirs, $files) = get_content($path);
59
?>
60
			
61
		</td>
62
	</tr>
63
<?php
64
}
65
else {
66
?>
67
			Directory does not exist.
68
		</td>
69
	</tr>
70
</table>
71
<?php
72
	exit;
73
}
74

    
75
// ----- directories -----
76
foreach($dirs as $dir):
77
	$realDir = realpath("{$path}/{$dir}");
78
?>
79
	<tr>
80
		<td></td>
81
		<td class="fbDir vexpl" id="<?=$realDir;?>" align="left">
82
			<div onClick="jQuery('#fbTarget').val('<?=$realDir?>'); fbBrowse('<?=$realDir?>');">
83
				<img src="/filebrowser/images/folder_generic.gif" />
84
				&nbsp;<?=$dir;?>
85
			</div>
86
		</td>
87
		<td></td>
88
	</tr>
89
<?php
90
endforeach;
91

    
92
// ----- files -----
93
foreach($files as $file):
94
	$ext = strrchr($file, ".");
95

    
96
	switch ($ext) {
97
	   case ".css":
98
	   case ".html":
99
	   case ".xml":
100
		$type = "code";
101
		break;
102
	   case ".rrd":
103
		$type = "database";
104
		break;
105
	   case ".gif":
106
	   case ".jpg":
107
	   case ".png":
108
		$type = "image";
109
		break;
110
	   case ".js":
111
		 $type = "js";
112
		break;
113
	   case ".pdf":
114
		$type = "pdf";
115
		break;
116
	   case ".inc":
117
	   case ".php":
118
		$type = "php";
119
		break;
120
	   case ".conf":
121
	   case ".pid":
122
	   case ".sh":
123
		$type = "system";
124
		break;
125
	   case ".bz2":
126
	   case ".gz":
127
	   case ".tgz":
128
	   case ".zip":
129
		$type = "zip";
130
		break;
131
	   default:
132
		$type = "generic";
133
	}
134

    
135
	$fqpn = "{$path}/{$file}";
136

    
137
	if(is_file($fqpn)) {
138
		$fqpn = realpath($fqpn);
139
		$size = sprintf("%.2f KiB", filesize($fqpn) / 1024);
140
	}
141
	else
142
		$size = "";
143

    
144
?>
145
	<tr>
146
		<td></td>
147
		<td class="fbFile vexpl" id="<?=$fqpn;?>" align="left">
148
			<?php $filename = str_replace("//","/", "{$path}/{$file}"); ?>
149
			<div onClick="jQuery('#fbTarget').val('<?=$filename?>'); loadFile(); jQuery('#fbBrowser').fadeOut();">
150
				<img src="/filebrowser/images/file_<?=$type;?>.gif" alt="" title="">
151
				&nbsp;<?=$file;?>
152
			</div>
153
		</td>
154
		<td align="right" class="vexpl">
155
			<?=$size;?>
156
		</td>
157
	</tr>
158
<?php
159
endforeach;
160
?>
161
</table>
(2-2/2)