Files
controls-web/lasuca/growers/1902/dtrlist.php
2026-02-17 09:29:34 -06:00

361 lines
12 KiB
PHP

<?PHP
/*
+-----------------------------------------------------------------------------------+
| |
| dirLIST - PHP Directory Lister Version 0.1.1 |
| Copyright © 2007 Hamdiya |
| Support:hamdiya.dev@gmail.com |
| |
| dirLIST is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation; either version 2 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software |
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| |
+-----------------------------------------------------------------------------------+
*/
//= = = = = = = = = = = = = = = = = = = = = = = = = =
//U S E R C O N F I G U R A T I O N
//= = = = = = = = = = = = = = = = = = = = = = = = = =
//You can start by placing this file in the folder you wish to browse and you should be all set. If you want, you can change a few settings in the 'config.php' file for further customization. Good luck :)
require("../../inc/dtrlistconfig.php");
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//U S E R C O N F I G U R A T I O N - D O N E
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
require("../../inc/dtrlistfunctions.php");
//Start load time
if($load_time == 1)
{
$starttime = explode(" ",microtime());
$starttime = $starttime[1] + $starttime[0];
}
//Start load time -done
$folder = trim(base64_decode($_GET['folder']));
//remove trailing slashes from $folder if present
while(substr($folder, -1, 1)== "/")
$folder = substr_replace($folder,"",-1);
//remove trailing slashes from $folder if present -done
$dir_to_browse_original = $dir_to_browse;
if(!empty($folder))
$dir_to_browse = $dir_to_browse.$folder."/";
?>
<!-- Output basic HTML code -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?PHP
if($folder == "")
echo "Index of: Main/";
else
echo "Index of: home/".$folder."/"; ?></title>
<body>
<!-- Output basic HTML code -done -->
<?PHP
//If listing mode is FTP, open connection stream
if($listing_mode == 1)
{
$ftp_stream = @ftp_connect($ftp_host) or die(display_error_message("<b>Could not connect to FTP host</b>"));
$ftp_login = @ftp_login($ftp_stream, $ftp_username, $ftp_password) or die(display_error_message("<b>Could not login to FTP host.</b>"));
}
//If listing mode is FTP, open connection stream -done
//Check if directory exists
$folder_exists = 1;
if($listing_mode == 0 && !is_dir($dir_to_browse)) //HTTP
$folder_exists = 0;
if($listing_mode == 1 && !is_dir("ftp://$ftp_username:$ftp_password@$ftp_host/$dir_to_browse")) //FTP
$folder_exists = 0;
if($folder_exists == 0)
{
echo display_error_message("<b>Error:</b> Folder specified does not exist. This could be because you manually entered the folder name in the URL or you don't have permission to access this folder");
exit;
}
//Chcek if directory is valid -done
//This is a VERY important security feature. It prevents people from browsing directories above $dir_to_browse and the excluded folders. Edit this part at your own risk
if(count(explode("../",$folder)) > 1 || in_array(basename($folder), $exclude))
{
echo display_error_message("<b>Access Denied.</b>");
exit;
}
if(strlen($folder) == 2 && $folder == "..")
{
echo display_error_message("<b>Access Denied.</b>");
exit;
}
//Seurity feature -done
//Breadcrumbs
$this_file_name = substr(strrchr($_SERVER['PHP_SELF'], "/"),1);
$folders_in_URL = explode("/",rawurldecode($folder));
foreach($folders_in_URL as $key => $val)
{
$_temp = $_temp."/".$val;
$folders_in_URL_array[$key] = $_temp;
if($key == 0)
{
$_temp = $folders_in_URL[0];
$folders_in_URL_array[0] = $folders_in_URL[0];
}
}
$nav_links = "<a href=\"$this_file_name\">home</a>/";
for($i=0;$i<count($folders_in_URL);$i++)
{
if(!empty($folder))
$nav_links = $nav_links."<a href=\"$this_file_name?folder=".rawurlencode($folders_in_URL_array[$i])."\">$folders_in_URL[$i]</a>/";
else
$nav_links = $nav_links."<a href=\"$this_file_name?folder=".rawurlencode($folders_in_URL_array[$i])."\">$folders_in_URL[$i]</a>";
}
echo "Index of: ".$nav_links."<br><br>";
//Breadcrumbs -done
//Change excluded extensions to lower case if $case_sensative_ext is disabled
foreach($exclude_ext as $key => $val)
{
$exclude_ext[$key] = strtolower($val);
}
//Initialize arrays
$folders_array = array();
$folders_size_array = array();
$folders_cdate_array = array();
$folders_link_array = array();
$files_array = array();
$files_size_array = array();
$files_cdate_array = array();
$files_link_array = array();
//initialize arrays -done
//Get directory content seperatiung files and folders into 2 arrays and filtering them to remove those exlcluded
if($listing_mode == 0) //HTTP
{
$dir_content = get_dir_content($dir_to_browse);
$folders_total_size = 0;
$files_total_size = 0;
foreach($dir_content as $key => $val)
{
if(!in_array($val, $exclude))
{
$path = $dir_to_browse.$val;
if(is_dir($path))
{
$folders_array[] = $val;
if($show_folder_size_http == 1)
{
$folder_size = folder_size($path);
$folders_size_array[] = letter_size($folder_size);
}
$folders_total_size += $folder_size;
if($folder == "")
$folders_link_array[] = $val;
else
$folders_link_array[] = $folder."/".$val;
$folders_cdate_array[] = date("d F Y", filectime($path));
}
else
{
$this_file_size = filesize($this_file_name);
if($path != $this_file_name && $this_file_size != filesize($path))
{
$file_ext = strrchr($val, ".");
if($case_sensative_ext == 0)
$file_ext = strtolower($file_ext);
if(!in_array($file_ext, $exclude_ext))
{
$files_array[] = $val;
$file_size = filesize($path);
$files_size_array[] = letter_size($file_size);
$files_total_size += $file_size;
$files_link_array[] = $path;
$files_cdate_array[] = date("d F Y", filectime($path));
}
}
}
}
}
}
elseif($listing_mode == 1) //FTP
{
$dir_content = ftp_rawlist($ftp_stream, $dir_to_browse);
$folders_total_size = 0;
$files_total_size = 0;
foreach($dir_content as $key => $val)
{
$current = parse_rawurl($val);
if(!in_array($current[8], $exclude))
{
if(substr($current[0], 0, 1) == "d")
{
$folders_array[] = $current[8];
if($show_folder_size_ftp == 1)
{
$folder_size = folder_size($dir_to_browse.$current[8]);
$folders_size_array[] = letter_size($folder_size);
}
$folders_total_size += $folder_size;
if($folder == "")
$folders_link_array[] = $current[8];
else
$folders_link_array[] = $folder."/".$current[8];
$folders_cdate_array[] = $current[6]." ".$current[5]." ".$current[7];
}
else
{
$this_file_size = filesize($this_file_name);
if($path != $this_file_name && $this_file_size != $current[4])
{
$file_ext = strrchr($current[8], ".");
if($case_sensative_ext == 0)
$file_ext = strtolower($file_ext);
if(!in_array($file_ext, $exclude_ext))
{
$files_array[] = $current[8];
$file_size = $current[4];
$files_size_array[] = letter_size($file_size);
$files_total_size += $file_size;
$files_link_array[] = 'dirLIST_files/ftp_download.php?ftpf='.base64_encode($dir_to_browse.$current[8]);
$files_cdate_array[] = $current[6]." ".$current[5]." ".$current[7];
}
}
}
}
}
}
//Sort the folders and files array alpahbatically
if(!empty($folders_array)) natcasesort($folders_array);
if(!empty($files_array)) natcasesort($files_array);
//Sort the folders and files array alpahbatically -done
if(!empty($folders_array) || !empty($files_array))
{
//Palce the content into a table
if($legend == 1)
echo "
<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" class=\"table_border\">
<tr>
<td width=\"100\" bgcolor=\"#666666\"><font color=\"#FFFFFF\"><strong>KEY</strong></font></td>
<td width=\"33\">Folder</td>
<td width=\"24\"><table width=\"24\" height=\"24\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">
<tr>
<td colspan=\"4\" bgcolor=\"$folder_color\">&nbsp;</td>
</tr>
</table></td>
<td width=\"17\">File</td>
<td width=\"24\"><table width=\"24\" height=\"4\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">
<tr>
<td colspan=\"4\" bgcolor=\"$color_1\">&nbsp;</td>
</tr>
</table> </td>
<td width=\"5\">|</td>
<td><table width=\"24\" height=\"24\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">
<tr>
<td colspan=\"4\" bgcolor=\"$color_2\">&nbsp;</td>
</tr>
</table></td>
</tr>
</table><br>";
if($statistics == 1)
{
echo'
<a href="javascript:;" onMouseDown="if(document.getElementById(\'mydiv\').style.display == \'none\'){ document.getElementById(\'mydiv\').style.display = \'block\'; }else{ document.getElementById(\'mydiv\').style.display = \'none\'; }">Show/hide statistics<br></a>
<div id="mydiv" style="display:none">
<table width="100%" border="0" cellpadding="5" class="table_border">';
echo'<tr>
<td width="60%" bgcolor="#666666"><font color="#FFFFFF"><strong>Folders count </strong></font></td>
<td>'.count($folders_array).', consuming: '.letter_size($folders_total_size).'</td>
</tr>';
echo'
<tr>
<td width="20%" bgcolor="#666666"><strong><font color="#FFFFFF">Files count </font></strong></td>
<td>'.count($files_array).', consuming: '.letter_size($files_total_size).'</td>
</tr>';
echo'<tr>
<td width="20%" bgcolor="#666666"><strong><font color="#FFFFFF">Total count </font></strong></td>
<td>'.(count($folders_array)+count($files_array)).', consuming: '.letter_size(($files_total_size+$folders_total_size)).'</td>
</tr>';
echo '</table></div>';
}
echo"
<br><table width=\100%\" border=\"0\" cellspacing=\"$cell_spacing\" cellpadding=\"$cell_padding\">
<tr>
<td width=\"$width_of_files_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">Daily Transaction Report</span></td>
<td width=\"$width_of_sizes_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">Size</span></td>
<td width=\"$width_of_dates_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">Date uploaded</span></td>
</tr>";
foreach($folders_array as $key => $val)
{
echo"<tr>
<td width=\"$width_of_files_column\" bgcolor=\"#000000\"><a href=\"$this_file_name?folder=".base64_encode($folders_link_array[$key])."\">$val<a></td>
<td width=\"$width_of_sizes_column\" bgcolor=\"#000000\">$folders_size_array[$key]</td>
<td width=\"$width_of_dates_column\" bgcolor=\"#000000\">$folders_cdate_array[$key]</td></tr>";
}
$count = 0;
foreach($files_array as $key => $val)
{
if($count%2 == 0) $color = $color_1; else $color = $color_2;
echo"<tr>
<td width=\"$width_of_files_column\" bgcolor=\"#000000\"><a href=\"$files_link_array[$key]\">$val</a></td>
<td width=\"$width_of_sizes_column\" bgcolor=\"#000000\">$files_size_array[$key]</td>
<td width=\"$width_of_dates_column\" bgcolor=\"#000000\">$files_cdate_array[$key]</td></tr>";
$count++;
}
echo "</table>";
//Palce the content into a table -done
}
//Output if the directory is empty
if(empty($folders_array) && empty($files_array))
echo display_error_message("No files or folders in this directory: <span class=\"path_font\"><b>$folder</b></span>");
//Output if the directory is empty -done
//Display load time
if($load_time == 1)
{
$endtime = explode(" ",microtime());
echo "<br>This page loaded in ".sprintf("%.3f", $endtime[1] + $endtime[0] - $starttime)." seconds";
}
//Display load time -done
?>
<!-- Output basic HTMl code -->
<br /><br />
</body>
</html>
<!-- Output basic HTMl code -done -->