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 == ".") {
20
			continue;
21
		}
22
		if ($entry == ".." && $dir == "/") {
23
			continue;
24
		}
25
		if (is_dir("{$dir}/{$entry}")) {
26
			array_push($dirs, $entry);
27
		} else {
28
			array_push($files, $entry);
29
		}
30
	}
31

    
32
	@closedir($fd);
33

    
34
	natsort($dirs);
35
	natsort($files);
36

    
37
	return array($dirs, $files);
38
}
39

    
40
$path = realpath(strlen($_GET['path']) > 0 ? $_GET['path'] : "/");
41
if (is_file($path)) {
42
	$path = dirname($path);
43
}
44

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

    
61
// ----- read contents -----
62
if (is_dir($path)) {
63
	list($dirs, $files) = get_content($path);
64
?>
65

    
66
		</td>
67
	</tr>
68
<?php
69
} else {
70
?>
71
			Directory does not exist.
72
		</td>
73
	</tr>
74
</table>
75
<?php
76
	exit;
77
}
78

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

    
96
// ----- files -----
97
foreach ($files as $file):
98
	$ext = strrchr($file, ".");
99

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

    
139
	$fqpn = "{$path}/{$file}";
140

    
141
	if (is_file($fqpn)) {
142
		$fqpn = realpath($fqpn);
143
		$size = sprintf("%.2f KiB", filesize($fqpn) / 1024);
144
	} else {
145
		$size = "";
146
	}
147

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