Project

General

Profile

Download (3.17 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	pfSense_MODULE:	shell
4
*/
5
// Fetch a list of directories and files inside a given directory
6
function get_content($dir) {
7
	$dirs  = array();
8
	$files = array();
9

    
10
	clearstatcache();
11
	$fd = @opendir($dir);
12

    
13
	while($entry = @readdir($fd)) {
14
		if($entry == ".")                 continue;
15
		if($entry == ".." && $dir == "/") continue;
16

    
17
		if(is_dir("{$dir}/{$entry}"))
18
			array_push($dirs, $entry);
19
		else
20
			array_push($files, $entry);
21
	}
22

    
23
	@closedir($fd);
24

    
25
	natsort($dirs);
26
	natsort($files);
27

    
28
	return array($dirs, $files);
29
}
30

    
31
$path = realpath(strlen($_GET['path']) > 0 ? $_GET['path'] : "/");
32
if(is_file($path))
33
	$path = dirname($path);
34

    
35
// ----- header -----
36
?>
37
<table width="100%">
38
	<tr>
39
		<td class="fbHome" width="25px" align="left">
40
			<img onClick="$('fbTarget').value='<?=$realDir?>'; fbBrowse('/');" src="/filebrowser/images/icon_home.gif" alt="Home" title="Home" />
41
		</td>
42
		<td><b><?=$path;?></b></td>
43
		<td class="fbClose" align="right">
44
			<img onClick="new Effect.Fade($('fbBrowser'));" border="0" src="/filebrowser/images/icon_cancel.gif" alt="Close" title="Close" />
45
		</td>
46
	</tr>
47
	<tr>
48
		<td id="fbCurrentDir" colspan="3" class="vexpl" align="left">
49
<?php
50

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

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

    
87
// ----- files -----
88
foreach($files as $file):
89
	$ext = strrchr($file, ".");
90

    
91
	    if($ext == ".css" ) $type = "code";
92
	elseif($ext == ".html") $type = "code";
93
	elseif($ext == ".xml" ) $type = "code";
94
	elseif($ext == ".rrd" ) $type = "database";
95
	elseif($ext == ".gif" ) $type = "image";
96
	elseif($ext == ".jpg" ) $type = "image";
97
	elseif($ext == ".png" ) $type = "image";
98
	elseif($ext == ".js"  ) $type = "js";
99
	elseif($ext == ".pdf" ) $type = "pdf";
100
	elseif($ext == ".inc" ) $type = "php";
101
	elseif($ext == ".php" ) $type = "php";
102
	elseif($ext == ".conf") $type = "system";
103
	elseif($ext == ".pid" ) $type = "system";
104
	elseif($ext == ".sh"  ) $type = "system";
105
	elseif($ext == ".bz2" ) $type = "zip";
106
	elseif($ext == ".gz"  ) $type = "zip";
107
	elseif($ext == ".tgz" ) $type = "zip";
108
	elseif($ext == ".zip" ) $type = "zip";
109
	else                    $type = "generic";
110

    
111
	$fqpn = "{$path}/{$file}";
112

    
113
	if(is_file($fqpn)) {
114
		$fqpn = realpath($fqpn);
115
		$size = sprintf("%.2f KiB", filesize($fqpn) / 1024);
116
	}
117
	else
118
		$size = "";
119

    
120
?>
121
	<tr>
122
		<td></td>
123
		<td class="fbFile vexpl" id="<?=$fqpn;?>" align="left">
124
			<?php $filename = str_replace("//","/", "{$path}/{$file}"); ?>
125
			<div onClick="$('fbTarget').value='<?=$filename?>'; loadFile(); new Effect.Fade($('fbBrowser'));">
126
				<img src="/filebrowser/images/file_<?=$type;?>.gif" alt="" title="">
127
				&nbsp;<?=$file;?>
128
			</div>
129
		</td>
130
		<td align="right" class="vexpl">
131
			<?=$size;?>
132
		</td>
133
	</tr>
134
<?php
135
endforeach;
136
?>
137
</table>
(2-2/2)