1
|
<?php
|
2
|
|
3
|
require_once("guiconfig.inc");
|
4
|
|
5
|
/*
|
6
|
pfSense_MODULE: shell
|
7
|
*/
|
8
|
// Fetch a list of directories and files inside a given directory
|
9
|
function get_content($dir) {
|
10
|
$dirs = array();
|
11
|
$files = array();
|
12
|
|
13
|
clearstatcache();
|
14
|
$fd = @opendir($dir);
|
15
|
|
16
|
while($entry = @readdir($fd)) {
|
17
|
if($entry == ".") continue;
|
18
|
if($entry == ".." && $dir == "/") continue;
|
19
|
|
20
|
if(is_dir("{$dir}/{$entry}"))
|
21
|
array_push($dirs, $entry);
|
22
|
else
|
23
|
array_push($files, $entry);
|
24
|
}
|
25
|
|
26
|
@closedir($fd);
|
27
|
|
28
|
natsort($dirs);
|
29
|
natsort($files);
|
30
|
|
31
|
return array($dirs, $files);
|
32
|
}
|
33
|
|
34
|
$path = realpath(strlen($_GET['path']) > 0 ? $_GET['path'] : "/");
|
35
|
if(is_file($path))
|
36
|
$path = dirname($path);
|
37
|
|
38
|
// ----- header -----
|
39
|
?>
|
40
|
<table width="100%">
|
41
|
<tr>
|
42
|
<td class="fbHome" width="25px" align="left">
|
43
|
<img onClick="jQuery('#fbTarget').val('<?=$realDir?>'); fbBrowse('/');" src="/filebrowser/images/icon_home.gif" alt="Home" title="Home" />
|
44
|
</td>
|
45
|
<td><b><?=$path;?></b></td>
|
46
|
<td class="fbClose" align="right">
|
47
|
<img onClick="jQuery('#fbBrowser').fadeOut();" border="0" src="/filebrowser/images/icon_cancel.gif" alt="Close" title="Close" />
|
48
|
</td>
|
49
|
</tr>
|
50
|
<tr>
|
51
|
<td id="fbCurrentDir" colspan="3" class="vexpl" align="left">
|
52
|
<?php
|
53
|
|
54
|
// ----- read contents -----
|
55
|
if(is_dir($path)) {
|
56
|
list($dirs, $files) = get_content($path);
|
57
|
?>
|
58
|
|
59
|
</td>
|
60
|
</tr>
|
61
|
<?php
|
62
|
}
|
63
|
else {
|
64
|
?>
|
65
|
Directory does not exist.
|
66
|
</td>
|
67
|
</tr>
|
68
|
</table>
|
69
|
<?php
|
70
|
exit;
|
71
|
}
|
72
|
|
73
|
// ----- directories -----
|
74
|
foreach($dirs as $dir):
|
75
|
$realDir = realpath("{$path}/{$dir}");
|
76
|
?>
|
77
|
<tr>
|
78
|
<td></td>
|
79
|
<td class="fbDir vexpl" id="<?=$realDir;?>" align="left">
|
80
|
<div onClick="jQuery('#fbTarget').val('<?=$realDir?>'); fbBrowse('<?=$realDir?>');">
|
81
|
<img src="/filebrowser/images/folder_generic.gif" />
|
82
|
<?=$dir;?>
|
83
|
</div>
|
84
|
</td>
|
85
|
<td></td>
|
86
|
</tr>
|
87
|
<?php
|
88
|
endforeach;
|
89
|
|
90
|
// ----- files -----
|
91
|
foreach($files as $file):
|
92
|
$ext = strrchr($file, ".");
|
93
|
|
94
|
if($ext == ".css" ) $type = "code";
|
95
|
elseif($ext == ".html") $type = "code";
|
96
|
elseif($ext == ".xml" ) $type = "code";
|
97
|
elseif($ext == ".rrd" ) $type = "database";
|
98
|
elseif($ext == ".gif" ) $type = "image";
|
99
|
elseif($ext == ".jpg" ) $type = "image";
|
100
|
elseif($ext == ".png" ) $type = "image";
|
101
|
elseif($ext == ".js" ) $type = "js";
|
102
|
elseif($ext == ".pdf" ) $type = "pdf";
|
103
|
elseif($ext == ".inc" ) $type = "php";
|
104
|
elseif($ext == ".php" ) $type = "php";
|
105
|
elseif($ext == ".conf") $type = "system";
|
106
|
elseif($ext == ".pid" ) $type = "system";
|
107
|
elseif($ext == ".sh" ) $type = "system";
|
108
|
elseif($ext == ".bz2" ) $type = "zip";
|
109
|
elseif($ext == ".gz" ) $type = "zip";
|
110
|
elseif($ext == ".tgz" ) $type = "zip";
|
111
|
elseif($ext == ".zip" ) $type = "zip";
|
112
|
else $type = "generic";
|
113
|
|
114
|
$fqpn = "{$path}/{$file}";
|
115
|
|
116
|
if(is_file($fqpn)) {
|
117
|
$fqpn = realpath($fqpn);
|
118
|
$size = sprintf("%.2f KiB", filesize($fqpn) / 1024);
|
119
|
}
|
120
|
else
|
121
|
$size = "";
|
122
|
|
123
|
?>
|
124
|
<tr>
|
125
|
<td></td>
|
126
|
<td class="fbFile vexpl" id="<?=$fqpn;?>" align="left">
|
127
|
<?php $filename = str_replace("//","/", "{$path}/{$file}"); ?>
|
128
|
<div onClick="jQuery('#fbTarget').val('<?=$filename?>'); loadFile(); jQuery('#fbBrowser').fadeOut();">
|
129
|
<img src="/filebrowser/images/file_<?=$type;?>.gif" alt="" title="">
|
130
|
<?=$file;?>
|
131
|
</div>
|
132
|
</td>
|
133
|
<td align="right" class="vexpl">
|
134
|
<?=$size;?>
|
135
|
</td>
|
136
|
</tr>
|
137
|
<?php
|
138
|
endforeach;
|
139
|
?>
|
140
|
</table>
|