/
tree.php
546 lines (518 loc) · 16.8 KB
/
tree.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
<?php
/**
* @author Gustavo Novaro <gnovaro@gmail.com>
* @version 1.74
* URL: http://gustavonovaro.com.ar
* File: tree.php
* Purpose: View and listing files and directory
*/
error_reporting(E_ALL);
require('./config.php');
//require('./error_handler.php');
require('./function.php');
$sLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
//echo $sLang;
$sPath = './languages/'.$sLang.'.php';
if (file_exists($sPath)){
require($sPath);
}else{
//defualt lang english
require('./languages/en.php');
}//if
//Security check
session_start();
if(!isset($_SESSION['login']))
redirect('index.php');
//security
if (phpnum()==5)
date_default_timezone_set($config['TIME_ZONE']);
$sMessage = '';
$cantFiles = 0;
$sPath = '';
if (!isset($_SESSION["path"]) ){
$sRootPath = getcwd(); //Obtiene el directorio actual de trabajo.
$_SESSION["path"] = $sRootPath;
$sPath = $sRootPath;
// echo "session path ".$_SESSION["path"];
}
else
{
$sPath = $_SESSION["path"];
// echo "Path: ".$sPath; //debug
if ( isset($_REQUEST["dir"]) ){
$sDir = $_REQUEST["dir"];
//comprueba que lo que se pasa sea un directorio
if( is_dir($sPath.DIRECTORY_SEPARATOR.$sDir)){
$sPath = $sPath.DIRECTORY_SEPARATOR.$sDir;
$_SESSION["path"] = $sPath;
}//if
}//if
chdir($sPath); //Cambio de directorio
}//if
$order = 0;
function compress_gz($sFile)
{
// abrir el archivo para escritura con maxima compresion
$zp = gzopen($sFile.'.gz', "w9");
$fp = fopen($sFile,"rb"); //windows rb
while(!feof($fp)){
// escribir la cadena en el archivo
$s = fread($fp,2000);
gzwrite($zp, $s);
}
fclose($fp);
// cerrar el archivo
gzclose($zp);
}//compress_gz
function format_size($size){
switch (true){
case ($size > 1099511627776):
$size /= 1099511627776;
$suffix = 'TB';
break;
case ($size > 1073741824):
$size /= 1073741824;
$suffix = 'GB';
break;
case ($size > 1048576):
$size /= 1048576;
$suffix = 'MB';
break;
case ($size > 1024):
$size /= 1024;
$suffix = 'KB';
break;
default:
$suffix = 'B';
}
return round($size, 2)." ".$suffix;
}
if (isset($_POST["H_ACTION"])){
$sAction = $_POST["H_ACTION"];
switch($sAction){
case 'NEW_FOLDER':
$sDirName = $_POST["H_NAME"];
if(mkdir($sDirName, 0700))
{
$sMessage = $CONTENT["CREATE_DIR_SUCESS"];
} else {
$sMessage = $CONTENT["CREATE_DIR_FAIL"];
}
break;
case 'NEW_FILE':
$sName = $_POST["H_NAME"];
if (!file_exists($sName)){
fopen($sName,'w');
$sMessage = $CONTENT["FILE_SUCESS"];//"File created sucess"
}else{
$sMessage = $CONTENT["FILE_FAIL"];
}//if
break;
case 'DELETE':
$sName = $_POST["H_NAME"];
if(is_dir($sName)){
if (rmdir($sName)== true)
$sMessage = $CONTENT["DELETE_DIR_SUCESS"];
else
$sMessage = $CONTENT["DELETE_DIR_FAIL"];
}
else
if(file_exists($sName))
if ( unlink($sName) ){
$sMessage = $CONTENT["DELETE_FILE_SUCESS"];
} else{
$sMessage = $CONTENT["DELETE_FILE_FAIL"];
}//if
break;
case 'RENAME':
$sName = $_POST["H_NAME"];
$sExtra = $_POST["H_EXTRA"];
if(file_exists($sName))
{
if(rename($sName,$sExtra))
$sMessage = $CONTENT["RENAME_FILE_SUCESS"];
else
$sMessage = $CONTENT["RENAME_FILE_FAIL"];
}//if
break;
case 'COMPRESS':
$sName = $_POST["H_NAME"];
if(file_exists($sName))
compress_gz($sName);
break;
}//switch
}//if action
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $CONTENT["TITLE"];?></title>
<link rel="stylesheet" type="text/css" href="<?php echo URL;?>/assets/css/fileexplorer.css" />
<meta name="robots" content="NOINDEX, NOFOLLOW, NOCACHE, NOARCHIVE" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.validate/1.6/jquery.validate.min.js"></script>
<script type="text/javascript">
function showhide_with_image(targetDiv,actionImage){
var image = document.getElementById(actionImage);
if($("#"+targetDiv).css("display") == "none"){
$("#"+targetDiv).slideDown("slow");
image.src = "<?php echo URL?>/assets/images/up.jpg";
} else {
$("#"+targetDiv).slideUp("slow");
image.src = "<?php echo URL?>/assets/images/down.jpg";
}
}//showhide_with_image
function rename(sName){
var resp;
resp = prompt("<?php echo $CONTENT["RENAME_FILE"];?> " + sName + "?",sName);
if (resp != null){
document.getElementById("H_ACTION").value = "RENAME";
document.getElementById("H_NAME").value = sName;
document.getElementById("H_EXTRA").value = resp;
document.getElementById("frmMain").submit();
}//if
}//rename
function delete_file(sName){
var resp;
resp = confirm("<?php echo $CONTENT["DELETE_FILE"];?> '" + sName + "' ?");
if (resp != null){
document.getElementById("H_ACTION").value = "DELETE";
document.getElementById("H_NAME").value = sName;
document.getElementById("frmMain").submit();
}//if
}//delete_file
function new_folder(){
folder = prompt("<?php echo $CONTENT["NEW_FOLDER"];?>");
if (folder !="" && folder != null){
//Validar charAt " " != espacio
document.getElementById("H_ACTION").value = "NEW_FOLDER";
document.getElementById("H_NAME").value = folder;
document.getElementById("frmMain").submit();
}//if
}//new_folder
function new_file(){
sFile = prompt("<?php echo $CONTENT["NEW_FILE"];?>");
if (sFile !="" && sFile != null){
//Validar charAt " " != espacio
document.getElementById("H_ACTION").value = "NEW_FILE";
document.getElementById("H_NAME").value = sFile;
document.getElementById("frmMain").submit();
}//if
}//new_file
function close_admin(){
sclose = confirm("<?php echo $CONTENT["EXIT"];?>");
if (sclose){
window.location = "index.php";
}
}//close_admin
function edit(sFile){
window.location = "edit.php?file=" + sFile;
}//edit
function go_path(){
sPath = document.getElementById("txtPath").value;
if(sPath == "")
alert("Por favor complete la direccion");
else
document.getElementById("frmMain").submit();
}//go_path
function download_file(sFile){
window.location = "get_file.php?file=" + sFile;
}//download_file
function compress(sFile)
{
document.getElementById("H_NAME").value = sFile;
document.getElementById("H_ACTION").value = "COMPRESS";
document.getElementById("frmMain").submit();
}
function show_pop(id)
{
$("#"+id).show();
}
function close_pop(id)
{
$("#"+id).hide();
}
</script>
</head>
<body>
<?php
if(!empty($sMessage)):
?>
<div id="divMessage" class="box radius">
<div style="float:right"><a href="#" onclick="close_pop('divMessage');"><img src="<?php echo URL;?>/assets/images/close.png" alt="close" /></a></div>
<img src="<?php echo URL;?>/assets/images/info.png" alt="Info" /> <strong><?php echo $sMessage;?></strong>
</div>
<?php
endif;
?>
<div id="divHelp" class="box" style="display:none;">
<div style="float:right"><a href="#" onclick="$('#divHelp').hide();"><img src="<?php echo URL;?>/assets/images/close.png" alt="close" /></a></div>
<a href="http://fileexplorerxp.googlecode.com/" target="_blank">File Explorer XP</a><br />
PHP Web File Manager<br />
Author: <a href="mailto:gnovaro@gmail.com">Gustavo Novaro</a><br />
Version: <?php echo $config['VERSION'];?><br />
</div><!--divHelp-->
<form name="frmMain" id="frmMain" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div id="header-bar">
<div id="header-bar-title"> <?php echo $CONTENT['TITLE'];?></div>
<div id="header-bar-button">
<a href="#" onclick="close_admin();">
<img src="<?php echo URL;?>/assets/images/close.png" alt="close" title="<?php echo $CONTENT['EXIT'];?>" /></a>
</div>
</div><!--header-bar-->
<div id="address-bar">
<span>
<?php echo $CONTENT["PATH"];?>
<input type="text" name="dir" id="txtPath" style="width:650px;" value="<?php echo realpath($sPath);?>"/>
</span>
<a href="#" onclick="go_path();"><img src="<?php echo URL;?>/assets/images/arrow_go.jpg" alt="<?php echo $CONTENT["GO"];?>" style="border:none;" /></a>
<?php echo $CONTENT["GO"];?>
<a href="#" onclick="show_pop('divHelp');"><img src="<?php echo URL;?>/assets/images/help.gif" alt="<?php echo $CONTENT["HELP"];?>" /></a>
</div><!--address-bar-->
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="180" bgcolor="#6B85DC" style="vertical-align:top;">
<br />
<!--file-task-->
<div id="file-task">
<div class="box-title">
<div class="textoAzul"> <?php echo $CONTENT['FILE_TASK'];?></div>
<div class="arrow"><a href="javascript:showhide_with_image('task','img_arrow_task');"><img src="<?php echo URL;?>/assets/images/up.jpg" id="img_arrow_task" style="border:none" /></a></div>
</div>
<div id="task">
<ul>
<li><img src="<?php echo URL;?>/assets/images/file.gif" alt="" /> <a href="javascript:new_file();" class="menuLeftBar"><?php echo $CONTENT["NEW_FILE"];?></a></li>
<li><img src="<?php echo URL;?>/assets/images/new_folder.jpg" alt="" /> <a href="javascript:new_folder();" class="menuLeftBar"><?php echo $CONTENT["NEW_FOLDER"];?></a></li>
<li> <img src="<?php echo URL;?>/assets/images/upload.jpg" alt="" /> <a href="<?php echo URL;?>/upload.php" class="menuLeftBar"><?php echo $CONTENT["UPLOAD_FILE"];?></a></li>
<li> <img src="<?php echo URL;?>/assets/images/control_panel.jpg" alt="" /> <a href="<?php echo URL;?>/control_panel.php" class="menuLeftBar"><?php echo $CONTENT["CONTROL_PANEL"];?></a></li>
</ul>
</div><!--task-->
</div><!--file-task-->
<!-- Detail Panel-->
<div id="details">
<!--box-title-->
<div class="box-title">
<div class="textoAzul"> <?php echo $CONTENT['DETAILS'];?></div>
<div class="arrow">
<a href="javascript:showhide_with_image('details-box','img_arrow_detail');"><img src="<?php echo URL;?>/assets/images/up.jpg" id="img_arrow_detail" style="border:none" alt="" /></a>
</div>
</div>
<!--box-title-->
<div id="details-box">
<?php
// $df contiene el numero total de bytes disponible en "/"
$df = disk_free_space(".");
$df = format_size($df);
?>
<?php echo $CONTENT['SPACE_FREE'];?>:<br />
<?php echo $df;?>
<br />
<br />
<?php
// $df contiene el numero total de bytes disponible en "/"
$dt = disk_total_space(".");
$dt = format_size($dt);
?>
<?php echo $CONTENT['SPACE_TOTAL'];?>:<br />
<?php echo $dt;?>
</div><!--details-->
</div>
<!-- --> </td>
<td width="778" style="vertical-align:top;">
<!-- Listado Archivos -->
<div style="top: 66px; left: 191px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#EFEFE9">
<td width="10px"> </td>
<td width="270px"> <?php echo $CONTENT['NAME'];?> </td>
<td width="80px"><span class="barra">|</span><?php echo $CONTENT['SIZE'];?></td>
<td><span class="barra">|</span><?php echo $CONTENT['LAST_MODIFY'];?></td>
<td><span class="barra">|</span><?php echo $CONTENT['OWNER'];?></td>
<td><span class="barra">|</span><?php echo $CONTENT['GROUP'];?></td>
<td><span class="barra">|</span><?php echo $CONTENT['PERMISSIONS'];?></td>
<td colspan="5"> </td>
</tr>
<?php
//Poner en un include
//Lista los archivos y directorios ubicados en la ruta especificada en un array
$dh = @opendir($sPath)or die("No se puede abrir el $sPath");
$i = 0;
while (false !== ($file_name = readdir($dh))) {
$types[] = filetype($file_name);
$files[] = $file_name;
$i++;
}//while
array_multisort($types,SORT_ASC,$files,SORT_ASC); //sort by type, name
foreach($files as $file) {
?>
<tr>
<td>
<?php if($file!='.' && $file!='..'):?>
<input type="checkbox" name="[]" id="" />
<?php endif;?>
</td>
<td bgcolor="#F7F7F7">
<?php
if(is_dir($file)&& $file!='.'):
?>
<img src='<?php echo URL?>/assets/images/folder.jpg' alt="" /> <a href="tree.php?dir=<?php echo $file;?>" class="menuLeftBar"><?php echo $file;?></a>
<?php
else:
//is file
$path_parts = pathinfo($file);
if (isset($path_parts['extension'])){
$ext = $path_parts['extension'];
$sPathIcon = URL."/icons/".$ext.".png";
}
else //load a generic icon
$sPathIcon = URL."/icons/file.png";
if($file!='.'){
?>
<img src="<?php echo $sPathIcon;?>" alt="" /> <?php echo$file;?>
<?php
}//if
endif;
?>
</td>
<td>
<?php
//File Size
if ($file!= "." && $file != ".."){
$tam = filesize($file);
if( $tam > 1024 ){
$tam = round($tam / 1024);
echo $tam.' Kb';
}
else
{
echo $tam.' bytes';
}//if
}//if
?>
</td>
<?php
if($file!="." && $file != ".."){
?>
<td> <?php echo date ("d F Y H:i:s", filemtime($file));?></td>
<td>
<?php
if(strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
{
$uid = fileowner($file); //return uid owner file
$sUser = posix_getpwuid($uid); //return array asoc uid with name...
echo $sUser['name'];
}
?>
</td>
<td> <?php
if(strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' )
{
$gid = filegroup($file); //return file group id
$sGroup = posix_getgrgid($gid);
echo $sGroup['name'];
}
?>
</td>
<td>
<?php
/* function show_perm_complete($sFile){
//$perms = fileperms($sFile); //get octal value of permison
return fileperms($sFile) & 511;
/*
if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Enlace Simbolico
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Bloque especial
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directorio
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Caracter especial
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// Pipe FIFO
$info = 'p';
} else {
// Desconocido
$info = 'u';
}
// Duenyo
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
return $info;*/
/*}//show_perm_complete
echo show_perm_complete($files[$i]);
clearstatcache();*/
if (fileperms($file))
echo substr(sprintf('%o', fileperms($file)), -4);
?>
</td>
<?php
if(is_file($file)){
?>
<td><a href="javascript:edit('<?php echo $file?>');"><img src="<?php echo URL?>/assets/images/b_edit.png" alt="<?php echo $CONTENT["EDIT"];?>" title="<?php echo $CONTENT["EDIT"];?>" /></a></td>
<?php
}//if
else
echo "<td> </td>";
?>
<td><a href="javascript:rename('<?php echo $file;?>');"><img src="<?php echo URL?>/assets/images/rename.jpg" title="<?php echo $CONTENT["RENAME"];?>" alt="<?php echo $CONTENT["RENAME"];?>" /></a></td>
<td><a href="javascript:delete_file('<?php echo $file;?>');"><img src="<?php echo URL?>/assets/images/delete.gif" title="<?php echo $CONTENT["DELETE"];?>" alt="<?php echo $CONTENT["DELETE"];?>" /></a></td>
<?php
if(is_file($file)){
?>
<td><a href="javascript:compress('<?php echo $file;?>');"><img src="<?php echo URL?>/assets/images/zip.gif" alt="<?php echo $CONTENT["COMPRESS"];?>" title="<?php echo $CONTENT["COMPRESS"];?>" /></a></td>
<td><a href="javascript:download_file('<?php echo $file?>');"><img src="<?php echo URL?>/assets/images/download.gif" alt="<?php echo $CONTENT["DOWNLOAD"];?>" title="<?php echo $CONTENT["DOWNLOAD"];?>" /></a></td>
<?php
}//if
?>
<?php
}//if
?>
</tr>
<?php
}//foreach
?>
</table>
</div>
<!-- -->
</td>
</tr>
</table>
<!--status-bar-->
<div id="status-bar">
<div id="objects"> <?php echo $i-2;?> <?php echo $CONTENT['OBJECTS'];?> </div>
<div id="about"><a href="http://gustavonovaro.com.ar" target="_blank">Blog de Tavo</a> - <a href="http://fileexplorerxp.googlecode.com/" target="_blank">File Explorer XP</a> | Version: <?php echo $config['VERSION'];?> </div>
</div>
<!--status-bar-->
<input type="hidden" name="H_NAME" id="H_NAME" value="" />
<input type="hidden" name="H_ACTION" id="H_ACTION" value="" />
<input type="hidden" name="H_EXTRA" id="H_EXTRA" value="" />
</form>
</div>
</body>
</html>