Projet

Général

Profil

Télécharger (3,01 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / filebrowser / browser.php @ 6d631b8e

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

    
133
	$fqpn = "{$path}/{$file}";
134

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

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