2019-09-17 10:16:07 +03:00
< ? php
/**
* Handles all requests by the browser . This is the only file that can be
* accessed directly .
2023-11-13 08:55:20 +02:00
* ş
2019-09-17 10:16:07 +03:00
* @ package AutoIndex
2020-02-04 14:01:17 +02:00
* @ author Justin Hagstrom < JustinHagstrom @ yahoo . com > , FlorinCB < orynider @ users . sourceforge . net >
2023-11-15 12:07:28 +02:00
* @ version 2 ( January 01 , 2019 / 09 , November , 2023 )
* @ version $Id : index . php , v 2.2 . 7 2023 / 11 / 15 08 : 08 : 08 orynider Exp $
2023-11-14 00:26:30 +02:00
* @ copyright Copyright ( C ) 2002 - 2008 Justin Hagstrom
2019-09-17 10:16:07 +03:00
* @ license http :// www . gnu . org / licenses / gpl . html GNU General Public License ( GPL )
*
* @ link http :// autoindex . sourceforge . net
*/
/*
AutoIndex PHP Script 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 .
AutoIndex PHP Script 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
*/
2023-11-13 23:56:21 +02:00
ini_set ( 'display_errors' , '1' );
2020-12-23 03:18:48 +02:00
//@error_reporting(E_ALL & ~E_NOTICE);
2023-11-13 23:56:21 +02:00
session_cache_expire ( 1440 );
2023-11-15 12:07:28 +02:00
@ set_time_limit ( 1500 );
2023-11-13 23:56:21 +02:00
define ( 'ENVIRONMENT' , 'production' );
2020-12-23 03:18:48 +02:00
2019-09-17 10:16:07 +03:00
/**
2023-11-13 23:56:21 +02:00
* OPTIONAL SETTINGS : 'production' or 'development'
2019-09-17 10:16:07 +03:00
*/
2023-11-13 23:56:21 +02:00
if ( ! defined ( 'ENVIRONMENT' ))
{
@ define ( 'ENVIRONMENT' , 'development' );
}
2019-09-17 10:16:07 +03:00
2023-11-27 17:22:26 +02:00
$phpEx = substr ( strrchr ( __FILE__ , '.' ), true );
2019-09-17 10:16:07 +03:00
//filenames and paths for configuration related files
2020-12-23 03:18:48 +02:00
/*EDIT*/ $CONFIG_PATH = './' ;
2023-11-27 17:22:26 +02:00
/*EDIT*/ define ( 'ROOT_PATH' , $CONFIG_PATH );
/*EDIT*/ define ( 'CONFIG_STORED' , $CONFIG_PATH . 'AutoIndex.conf.' . $phpEx );
/*EDIT*/ define ( 'CONFIG_GENERATOR' , $CONFIG_PATH . 'config.' . $phpEx );
2020-12-23 03:18:48 +02:00
2019-09-17 10:16:07 +03:00
//paths for files that will be included
2020-12-23 03:18:48 +02:00
/*EDIT*/ define ( 'PATH_TO_CLASSES' , $CONFIG_PATH . 'classes/' );
/*EDIT*/ define ( 'PATH_TO_LANGUAGES' , $CONFIG_PATH . 'languages/' );
2023-11-27 17:22:26 +02:00
//paths for configurable directories we need at install
/*EDIT* *FLAGS_PATH*/ define ( 'PATH_TO_FLAGS' , $CONFIG_PATH . 'flags/' );
/*EDIT* *ICONS_PATH*/ define ( 'PATH_TO_ICONS' , $CONFIG_PATH . 'index_icons/' );
/*EDIT* *ASSETS_PATH*/ define ( 'PATH_TO_ASSETS' , $CONFIG_PATH . 'assets/' );
/*EDIT* *TEMPLATE_PATH*/ define ( 'PATH_TO_TEMPLATES' , $CONFIG_PATH . 'templates/' );
2019-09-17 10:16:07 +03:00
define ( 'LANGUAGE_FILE_EXT' , '.txt' );
2023-11-27 17:22:26 +02:00
define ( 'TEMPLATE_FILE_EXT' , '.tpl' );
2019-09-17 10:16:07 +03:00
//filenames of template files
2023-11-27 17:22:26 +02:00
define ( 'GLOBAL_HEADER' , 'global_header.' . TEMPLATE_FILE_EXT );
define ( 'GLOBAL_FOOTER' , 'global_footer.' . TEMPLATE_FILE_EXT );
define ( 'TABLE_HEADER' , 'table_header.' . TEMPLATE_FILE_EXT );
define ( 'TABLE_FOOTER' , 'table_footer.' . TEMPLATE_FILE_EXT );
define ( 'EACH_FILE' , 'each_file.' . TEMPLATE_FILE_EXT );
2019-09-17 10:16:07 +03:00
/**
* When ENABLE_CACHE is true , the indexes of directories will be stored in
* files in the folder CACHE_STORAGE_DIR . You will notice a speed improvement
* when viewing folders that contain a few thousand files . However , the contents
* of the indexed folders will not be updated until you delete the cache file .
*/
define ( 'ENABLE_CACHE' , false );
/**
* This is the folder cache data will be stored in . PHP needs write permission
* in this directory . You can use an absolute path or a relative path , just
* make sure there is a slash at the end .
*/
2023-11-13 08:55:20 +02:00
/*EDIT*/
define ( 'CACHE_STORAGE_DIR' , 'cache/' );
2019-09-17 10:16:07 +03:00
/**
* Format to display dates in .
* @ see date ()
*/
define ( 'DATE_FORMAT' , 'Y-M-d' );
/**
* Sets debug mode . Off ( false ) by default .
*/
define ( 'DEBUG' , false );
/* END OPTIONAL SETTINGS */
/** The time this script began to execute. */
define ( 'START_TIME' , microtime ( true ));
/** Level for disabled/banned accounts. */
define ( 'BANNED' , - 1 );
/** Level for Guest users (users who are not logged in). */
define ( 'GUEST' , 0 );
/** Level for regular user accounts. */
define ( 'USER' , 1 );
/** Level for moderator ("super user") accounts. */
define ( 'MODERATOR' , 2 );
/** Level for Admin users. */
define ( 'ADMIN' , 3 );
2020-12-23 03:18:48 +02:00
/**
2019-09-17 10:16:07 +03:00
* Minimum user level allowed to upload files .
* Use the ADMIN , MODERATOR , USER , GUEST constants .
* GUEST will allow non - logged - in users to upload .
*/
2020-12-23 03:18:48 +02:00
/*EDIT*/ define ( 'LEVEL_TO_UPLOAD' , ADMIN );
//define('LEVEL_TO_UPLOAD', USER);
2019-09-17 10:16:07 +03:00
/** The version of AutoIndex PHP Script (the whole release, not based on individual files). */
2023-11-13 08:55:20 +02:00
define ( 'VERSION' , '2.2.7' );
2019-09-17 10:16:07 +03:00
/**
* This must be set to true for other included files to run . Setting it to
* false could be used to temporarily disable the script .
*/
define ( 'IN_AUTOINDEX' , true );
//compensate for compressed output set in php.ini
2020-12-23 03:18:48 +02:00
if ( ini_get ( 'zlib.output_compression' ) == '1' )
2019-09-17 10:16:07 +03:00
{
header ( 'Content-Encoding: gzip' );
}
/*
* Uncomment the following code to turn on strict XHTML 1.1 compliance in
* users ' browsers . If you do this , make sure any changes you make to the
* template do not break XHTML 1.1 compliance .
*/
2023-11-13 23:56:21 +02:00
/*
if ( ! empty ( $_SERVER [ 'HTTP_ACCEPT' ]) && preg_match ( '#application/(xhtml\+xml|\*)#i' , $_SERVER [ 'HTTP_ACCEPT' ]))
2019-09-17 10:16:07 +03:00
{
header ( 'Content-Type: application/xhtml+xml' );
2023-11-13 23:56:21 +02:00
}
*/
2019-09-17 10:16:07 +03:00
session_name ( 'AutoIndex2' );
session_start ();
2020-12-23 03:18:48 +02:00
//echo 'PHP_VERSION: '.PHP_VERSION;
2019-09-17 10:16:07 +03:00
/**
* Formats $text within valid XHTML 1.1 tags and doctype .
*
* @ param string $text
* @ param string $title
* @ return string
*/
2023-11-13 23:56:21 +02:00
function simple_display ( $text , $title = 'Error on Page' , $notify = '' , $return_index = " index.php " )
{
2019-09-17 10:16:07 +03:00
return ' < ? xml version = " 1.0 " encoding = " UTF-8 " ?>
2023-11-13 23:56:21 +02:00
<! DOCTYPE html >
< html dir = " ltr " >
< head >< meta charset = " UTF-8 " />
< meta http - equiv = " X-UA-Compatible " content = " IE=edge " />
< meta name = " viewport " content = " width=device-width, initial-scale=1.0 " />
< meta name = " apple-mobile-web-app-capable " content = " yes " />
< meta name = " apple-mobile-web-app-status-bar-style " content = " blue " /> ' .
'<title>' . $title . '</title>' .
'<style type="text/css">{ margin: 0; padding: 0; } html { font-size: 100%; height: 100%; margin-bottom: 1px; background-color: #E4EDF0; } body { font-family: "Lucida Grande", "Segoe UI", Helvetica, Arial, sans-serif; color: #536482; background: #E4EDF0; font-size: 62.5%; margin: 0; } ' .
'a:link, a:active, a:visited { color: #006688; text-decoration: none; } a:hover { color: #DD6900; text-decoration: underline; } ' .
'#wrap { padding: 0 20px 15px 20px; min-width: 615px; } #page-header { text-align: right; height: 40px; } #page-footer { clear: both; font-size: 1em; text-align: center; } ' .
'.panel { margin: 4px 0; background-color: #FFFFFF; border: solid 1px #A9B8C2; } ' .
'#errorpage #page-header a { font-weight: bold; line-height: 6em; } #errorpage #content { padding: 10px; } #errorpage #content h1 { line-height: 1.2em; margin-bottom: 0; color: #DF075C; } ' .
'#errorpage #content div { margin-top: 20px; margin-bottom: 5px; border-bottom: 1px solid #CCCCCC; padding-bottom: 5px; color: #333333; font: bold 1.2em "Lucida Grande", "Segoe UI", Arial, Helvetica, sans-serif; text-decoration: none; line-height: 120%; text-align: left; } \n' .
'</style>' .
'</head>' .
'<body id="errorpage">' .
'<div id="wrap">' .
' <div id="page-header">' . $return_index . '</div>' .
' <div id="page-body">' .
' <div class="panel">' .
' <div id="content">' .
' <h1>' . $title . '</h1>' .
' <div>' . $text . '</div>' .
$notify .
' </div>' .
' </div>' .
' </div>' .
' <div id="page-footer">Edition by <a href="https://github.com/beitdina/">Beit Dina Institute</a>' ;
' </div>' .
'</div>' .
'</body>' .
' </ html >
<!--
Powered by AutoIndex PHP Script ( version ' . VERSION . ' )
Copyright ( C ) 2002 - 2007 Justin Hagstrom , ( C ) 2019 - 2023 FlorinCB
http :// autoindex . sourceforge . net /
-->
' ;
2019-09-17 10:16:07 +03:00
}
/**
* This function is automatically called by PHP when an undefined class is
* called .
*
* A file with the classname followed by . php is included to load the class .
* The class should start with an upper - case letter with each new word also in
* upper - case . The filename must match the class name ( including case ) .
*
* @ param string $class The name of the undefined class
*/
function __autoload ( $class )
{
if ( $class != 'self' )
{
$file = PATH_TO_CLASSES . $class . '.php' ;
/** Try to load the class file. */
2020-12-23 03:18:48 +02:00
if ( ! include_once ( $file ))
2019-09-17 10:16:07 +03:00
{
2020-12-23 03:18:48 +02:00
die ( simple_display ( 'Error including file <em>' . htmlentities ( $file ) . '</em> - cannot load class.' ));
2019-09-17 10:16:07 +03:00
}
}
}
2020-12-23 03:18:48 +02:00
/*
* Instantiate the mx_request_vars class
* make sure to do before it ' s ever used
*/
$request = new RequestVars ( '' , false );
// this is needed to prevent unicode normalization
$super_globals_disabled = $request -> super_globals_disabled ();
// enable super globals to get literal value
if ( ! $super_globals_disabled )
{
//$request->disable_super_globals();
}
2023-10-31 18:43:23 +02:00
/* To do : Should be switched to i . e . $request -> request ( 'style' , 1 );
2020-12-23 03:18:48 +02:00
*/
$_GET = array_change_key_case ( $_GET , CASE_LOWER );
$_POST = array_change_key_case ( $_POST , CASE_LOWER );
2019-09-17 10:16:07 +03:00
/**
* This is used to report a fatal error that we cannot display with the Display
* class . All Exceptions used in AutoIndex should inherit from this class .
*
* @ package AutoIndex
*/
class ExceptionFatal extends Exception {}
try
{
2023-11-08 08:03:03 +02:00
if ( is_file ( CONFIG_STORED )) //now we need to include either the stored settings, or the config generator:
2019-09-17 10:16:07 +03:00
{
2020-12-23 03:18:48 +02:00
if ( ! is_readable ( CONFIG_STORED ))
2019-09-17 10:16:07 +03:00
{
2020-12-23 03:18:48 +02:00
throw new ExceptionFatal ( 'Make sure PHP has permission to read the file <em>' . Url :: html_output ( CONFIG_STORED ) . '</em>' );
2019-09-17 10:16:07 +03:00
}
$config = new ConfigData ( CONFIG_STORED );
}
2020-12-23 03:18:48 +02:00
else if ( is_file ( CONFIG_GENERATOR ))
2019-09-17 10:16:07 +03:00
{
/** Include the config generator so a new config file can be created. */
2020-12-23 03:18:48 +02:00
if ( ! include_once ( CONFIG_GENERATOR ))
2019-09-17 10:16:07 +03:00
{
2020-12-23 03:18:48 +02:00
throw new ExceptionFatal ( 'Error including file <em>' . Url :: html_output ( CONFIG_GENERATOR ) . '</em>' );
2019-09-17 10:16:07 +03:00
}
2020-12-23 03:18:48 +02:00
exit ();
die ( 'exit.. ?' );
2019-09-17 10:16:07 +03:00
}
else
{
2020-12-23 03:18:48 +02:00
throw new ExceptionFatal ( 'Neither <em>' . Url :: html_output ( CONFIG_GENERATOR ) . '</em> nor <em>' . Url :: html_output ( CONFIG_STORED ) . '</em> could be found.' );
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2023-10-31 18:43:23 +02:00
//find and store the user's IP address and hostname: $ip = (!empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'N/A');
2023-11-15 12:07:28 +02:00
$ip = $request -> server ( 'HTTP_X_FORWARDED_FOR' ) ? htmlspecialchars_decode ( $request -> server ( 'HTTP_X_FORWARDED_FOR' )) : $request -> server ( 'REMOTE_ADDR' );
2023-11-27 17:22:26 +02:00
2023-11-08 08:03:03 +02:00
//localhost.localdomain
2020-12-23 03:18:48 +02:00
if ( ! empty ( $_SESSION [ 'host' ]))
2019-09-17 10:16:07 +03:00
{
2023-11-08 08:03:03 +02:00
$host = ( function_exists ( 'php_uname' )) ? php_uname ( 'n' ) : $_SESSION [ 'host' ];
2019-09-17 10:16:07 +03:00
}
else
{
2023-11-08 08:03:03 +02:00
$_SESSION [ 'host' ] = $host = ( function_exists ( 'php_uname' )) ? php_uname ( 'n' ) : gethostbyaddr ( $ip );
}
2019-09-17 10:16:07 +03:00
//Create a language object:
$words = new Language ();
2020-12-23 03:18:48 +02:00
/*
* Instantiate the Mobile Device Detect class
* make sure to do before it ' s ever used
*/
$mobile_device_detect = new MobileDeviceDetect ();
$status = $mobile_device_detect -> mobile_device_detect ();
2023-11-08 08:03:03 +02:00
2019-09-17 10:16:07 +03:00
//Create a logging object:
2023-11-08 08:03:03 +02:00
$log = new Logging ( $config -> __get ( 'log_file' ));
2019-09-17 10:16:07 +03:00
2020-12-23 03:18:48 +02:00
/**
* Go through each config setting , and set a constant with each setting ' s
2019-09-17 10:16:07 +03:00
* name to either true or false depending on if the config setting is
* enabled .
*/
2020-12-23 03:18:48 +02:00
foreach ( $config as $key => $item )
2019-09-17 10:16:07 +03:00
{
$key = strtoupper ( $key );
if ( defined ( $key ))
{
2023-11-15 12:07:28 +02:00
throw new ExceptionFatal ( Url :: html_output ( $key ) . ' is already defined in <em>' . basename ( Url :: html_output ( $request -> server ( 'PHP_SELF' ))) . '</em>, and should not be in the config file.' );
2019-09-17 10:16:07 +03:00
}
2023-11-08 08:03:03 +02:00
@ define ( $key , ( $item != 'false' && $item != '0' ));
2023-11-27 17:22:26 +02:00
}
2019-09-17 10:16:07 +03:00
//make sure all required settings are set in the config file
2023-11-27 17:22:26 +02:00
foreach ( array ( 'base_dir' , 'icon_path' , 'flag_path' , 'language' , 'assets_path' , 'template' , 'template_path' , 'log_file' , 'description_file' , 'user_list' , 'download_count' , 'hidden_files' , 'banned_list' , 'show_dir_size' , 'use_login_system' , 'force_download' , 'search_enabled' , 'anti_leech' , 'entries_per_page' , 'must_login_to_download' , 'archive' , 'days_new' , 'thumbnail_height' , 'bandwidth_limit' , 'md5_show' , 'parse_htaccess' ) as $set )
2019-09-17 10:16:07 +03:00
{
if ( ! defined ( strtoupper ( $set )))
{
throw new ExceptionFatal ( 'Required setting <em>' . $set . '</em> is not set in <em>' . Url :: html_output ( CONFIG_STORED ) . '</em>' );
}
}
2023-11-08 08:03:03 +02:00
2020-12-23 03:18:48 +02:00
/**
2023-11-13 08:55:20 +02:00
* From this point on , we can throw ExceptionDisplay rather than
2019-09-17 10:16:07 +03:00
* Exception since all the configuration is done .
2023-11-27 17:22:26 +02:00
*/
2019-09-17 10:16:07 +03:00
$b_list = $only_these_ips = $banned_ips = array ();
2023-11-13 08:55:20 +02:00
if ( BANNED_LIST && is_file ( $config -> __get ( 'banned_list' ))) //make sure the user is not banned
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$b_list = file ( $config -> __get ( 'banned_list' ));
2019-09-17 10:16:07 +03:00
if ( $b_list === false )
{
throw new ExceptionDisplay ( 'Error reading from banned_list file.' );
}
for ( $i = 0 ; $i < count ( $b_list ); $i ++ )
{
$b_list [ $i ] = rtrim ( $b_list [ $i ], " \r \n " );
if ( ConfigData :: line_is_comment ( $b_list [ $i ]))
{
continue ;
}
if ( $b_list [ $i ]{ 0 } === ':' )
{
$only_these_ips [] = substr ( $b_list [ $i ], 1 );
}
else
{
$banned_ips [] = $b_list [ $i ];
}
}
if ( count ( $only_these_ips ) > 0 )
{
2020-12-23 03:18:48 +02:00
if ( ! ( DirectoryList :: match_in_array ( $ip , $only_these_ips ) || DirectoryList :: match_in_array ( $host , $only_these_ips )))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
throw new ExceptionDisplay ( $words -> __get ( 'the administrator has blocked your ip address or hostname' ) . '.' );
2019-09-17 10:16:07 +03:00
}
}
2020-12-23 03:18:48 +02:00
else if ( DirectoryList :: match_in_array ( $ip , $banned_ips ) || DirectoryList :: match_in_array ( $host , $banned_ips ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
throw new ExceptionDisplay ( $words -> __get ( 'the administrator has blocked your ip address or hostname' ) . '.' );
2019-09-17 10:16:07 +03:00
}
}
$show_only_these_files = $hidden_files = array ();
2023-11-13 08:55:20 +02:00
if ( HIDDEN_FILES && is_file ( $config -> __get ( 'hidden_files' ))) //store the hidden file list in $hidden_list
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$hidden_list = file ( $config -> __get ( 'hidden_files' ));
2019-09-17 10:16:07 +03:00
if ( $hidden_list === false )
{
throw new ExceptionDisplay ( 'Error reading from "hidden_files" file.' );
}
for ( $i = 0 ; $i < count ( $hidden_list ); $i ++ )
{
$hidden_list [ $i ] = rtrim ( $hidden_list [ $i ], " \r \n " );
if ( ConfigData :: line_is_comment ( $hidden_list [ $i ]))
{
continue ;
}
if ( $hidden_list [ $i ]{ 0 } === ':' )
{
$show_only_these_files [] = substr ( $hidden_list [ $i ], 1 );
}
else
{
$hidden_files [] = $hidden_list [ $i ];
}
}
}
2023-11-13 23:56:21 +02:00
2019-09-17 10:16:07 +03:00
//size of the "chunks" that are read at a time from the file (when $force_download is on)
2023-11-13 08:55:20 +02:00
$speed = ( BANDWIDTH_LIMIT ? $config -> __get ( 'bandwidth_limit' ) : 8 );
2019-09-17 10:16:07 +03:00
if ( DOWNLOAD_COUNT )
{
2023-11-13 08:55:20 +02:00
if ( ! is_file ( $config -> __get ( 'download_count' )))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$h = fopen ( $config -> __get ( 'download_count' ), 'wb' );
2019-09-17 10:16:07 +03:00
if ( $h === false )
{
2020-12-23 03:18:48 +02:00
throw new ExceptionDisplay ( 'Could not open download count file for writing.' . ' Make sure PHP has write permission to this file.' );
2019-09-17 10:16:07 +03:00
}
fclose ( $h );
}
2023-11-13 08:55:20 +02:00
$downloads = new ConfigData ( $config -> __get ( 'download_count' ));
2019-09-17 10:16:07 +03:00
}
//create a user object:
$log_login = false ;
2023-11-13 23:56:21 +02:00
if ( USE_LOGIN_SYSTEM && $request -> is_set_post ( 'username' ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 23:56:21 +02:00
$you = new UserLoggedIn ( $request -> post ( 'username' ), sha1 ( $request -> post ( 'password' )));
2023-11-14 00:26:30 +02:00
$log_login = true ; $password_var = 'password' ;
2023-11-13 23:56:21 +02:00
$_SESSION [ 'password' ] = sha1 ( $request -> post ( 'password' ));
2023-11-14 00:26:30 +02:00
$request -> recursive_set_var ( $password_var , null , true ); //similar to unset($_POST['password']);
2023-11-13 23:56:21 +02:00
$_SESSION [ 'username' ] = $request -> post ( 'username' );
2019-09-17 10:16:07 +03:00
}
2020-12-23 03:18:48 +02:00
else if ( USE_LOGIN_SYSTEM && ! empty ( $_SESSION [ 'username' ]))
2019-09-17 10:16:07 +03:00
{
$you = new UserLoggedIn ( $_SESSION [ 'username' ], $_SESSION [ 'password' ]);
}
else
{
$you = new User ();
if ( MUST_LOGIN_TO_DOWNLOAD && USE_LOGIN_SYSTEM )
{
$str = '<p>You must login to view and download files.</p>'
. '<table border="0" cellpadding="8" cellspacing="0">'
. '<tr class="paragraph"><td class="autoindex_td">'
2023-11-15 12:07:28 +02:00
. $you -> login_box () . '</td></tr></table>' ;
2019-09-17 10:16:07 +03:00
echo new Display ( $str );
die ();
}
}
//set the logged in user's home directory:
2023-11-08 08:03:03 +02:00
$dir = Item :: make_sure_slash ((( $you -> home_dir == '' ) ? $config -> __get ( 'base_dir' ) : $you -> home_dir ));
2023-11-13 08:55:20 +02:00
$config -> set ( 'base_dir' , $dir );
2019-09-17 10:16:07 +03:00
$subdir = '' ;
2023-11-13 08:55:20 +02:00
if ( $request -> is_get ( 'dir' ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$dir .= Url :: clean_input ( $request -> get ( 'dir' ));
2019-09-17 10:16:07 +03:00
$dir = Item :: make_sure_slash ( $dir );
2023-11-27 17:22:26 +02:00
2020-12-23 03:18:48 +02:00
if ( ! is_dir ( $dir ))
2019-09-17 10:16:07 +03:00
{
header ( 'HTTP/1.0 404 Not Found' );
2023-11-13 08:55:20 +02:00
$request -> recursive_set_var ( 'dir' , '' , TYPE_GET_VARS ); //so the "continue" link will work
2020-12-23 03:18:48 +02:00
throw new ExceptionDisplay ( 'The directory <em>' . Url :: html_output ( $dir ) . '</em> does not exist.' );
2019-09-17 10:16:07 +03:00
}
2023-11-27 17:22:26 +02:00
$subdir = substr ( $dir , strlen ( $config -> __get ( 'base_dir' )));
2023-11-13 08:55:20 +02:00
if ( $request -> is_set_get ( 'file' ) && ( $file = $request -> get ( 'file' )))
2019-09-17 10:16:07 +03:00
{
2023-11-08 08:03:03 +02:00
while ( preg_match ( '#\\\\|/$#' , $file )) //remove all slashes from the end of the name
2019-09-17 10:16:07 +03:00
{
$file = substr ( $file , 0 , - 1 );
}
$file = Url :: clean_input ( $file );
2020-12-23 03:18:48 +02:00
if ( ! is_file ( $dir . $file ))
2019-09-17 10:16:07 +03:00
{
header ( 'HTTP/1.0 404 Not Found' );
2020-12-23 03:18:48 +02:00
throw new ExceptionDisplay ( 'The file <em>' . Url :: html_output ( $file ) . '</em> does not exist.' );
2019-09-17 10:16:07 +03:00
}
2023-11-15 12:07:28 +02:00
if ( ANTI_LEECH && !! empty ( $_SESSION [ 'ref' ]) && ( !! $request -> server ( 'HTTP_REFERER' ) || stripos ( $request -> server ( 'HTTP_REFERER' ), $request -> server ( 'SERVER_NAME' )) === false ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$log -> add_entry ( 'Leech Attempt' );
$self = $request -> server ( 'SERVER_NAME' ) . Url :: html_output ( $request -> server ( 'PHP_SELF' )) . '?dir=' . Url :: translate_uri ( $subdir );
2020-12-23 03:18:48 +02:00
throw new ExceptionDisplay ( '<h3>This PHP Script has an Anti-Leech feature turned on.</h3>' . ' <p>Make sure you are accessing this file directly from <a class="autoindex_a" href="http://' . $self . '">http://' . $self . '</a></p>' );
2019-09-17 10:16:07 +03:00
}
2023-11-13 08:55:20 +02:00
$log -> add_entry ( $file );
2019-09-17 10:16:07 +03:00
if ( DOWNLOAD_COUNT )
{
2023-11-13 08:55:20 +02:00
$downloads -> add_one ( $dir . $file );
2019-09-17 10:16:07 +03:00
}
$url = new Url ( $dir . $file , true );
2023-11-13 08:55:20 +02:00
$url -> download ();
2019-09-17 10:16:07 +03:00
}
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2019-09-17 10:16:07 +03:00
if ( $log_login )
{
2023-11-13 08:55:20 +02:00
$log -> add_entry ( 'Successful login (Username: ' . $_SESSION [ 'username' ] . ')' );
2019-09-17 10:16:07 +03:00
}
2023-11-27 17:22:26 +02:00
2019-09-17 10:16:07 +03:00
if ( DESCRIPTION_FILE )
{
2023-11-13 08:55:20 +02:00
$descriptions = new ConfigData (( is_file ( $config -> __get ( 'description_file' )) ? $config -> __get ( 'description_file' ) : false ));
2019-09-17 10:16:07 +03:00
}
2023-11-27 17:22:26 +02:00
2023-11-08 08:03:03 +02:00
if ( PARSE_HTACCESS ) //parse .htaccess file(s)
{
2019-09-17 10:16:07 +03:00
new Htaccess ( $dir , '.htaccess' );
}
2023-11-27 17:22:26 +02:00
2023-11-13 08:55:20 +02:00
if ( MD5_SHOW && $request -> is_set_get ( 'md5' ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$file = $dir . Url :: clean_input ( $request -> get ( 'md5' ));
2020-12-23 03:18:48 +02:00
if ( ! is_file ( $file ))
2019-09-17 10:16:07 +03:00
{
header ( 'HTTP/1.0 404 Not Found' );
2020-12-23 03:18:48 +02:00
throw new ExceptionDisplay ( 'Cannot calculate md5sum: the file <em>' . Url :: html_output ( $file ) . '</em> does not exist.' );
2019-09-17 10:16:07 +03:00
}
2020-12-23 03:18:48 +02:00
$size = ( int ) filesize ( $file );
2023-11-13 08:55:20 +02:00
if ( $size <= 0 || $size / 1048576 > $config -> __get ( 'md5_show' ))
2019-09-17 10:16:07 +03:00
{
2020-12-23 03:18:48 +02:00
throw new ExceptionDisplay ( 'Empty file, or file too big to calculate the' . 'md5sum of (according to the $md5_show variable).' );
2019-09-17 10:16:07 +03:00
}
2020-12-23 03:18:48 +02:00
die ( simple_display ( md5_file ( $file ), 'md5sum of ' . Url :: html_output ( $file )));
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2023-11-13 08:55:20 +02:00
if ( THUMBNAIL_HEIGHT && $request -> is_set_get ( 'thumbnail' ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$fn = Url :: clean_input ( $request -> get ( 'thumbnail' ));
2019-09-17 10:16:07 +03:00
if ( $fn == '' )
{
die ();
}
echo new Image ( $fn );
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2023-11-13 08:55:20 +02:00
if ( ARCHIVE && $request -> is_set_get ( 'archive' ))
2019-09-17 10:16:07 +03:00
{
2023-11-15 12:07:28 +02:00
$log -> add_entry ( 'Directory archived' );
2019-09-17 10:16:07 +03:00
$outfile = Item :: get_basename ( $subdir );
if ( $outfile == '' || $outfile == '.' )
{
$outfile = 'base_dir' ;
}
$mime = new MimeType ( '.tar' );
2023-11-13 08:55:20 +02:00
header ( 'Content-Type: ' . $mime -> __toString ());
2020-12-23 03:18:48 +02:00
header ( 'Content-Disposition: attachment; filename="' . $outfile . '.tar"' );
set_time_limit ( 0 );
2019-09-17 10:16:07 +03:00
$list = new DirectoryList ( $dir );
$tar = new Tar ( $list , $outfile , strlen ( $dir ));
die ();
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2023-11-13 08:55:20 +02:00
if ( THUMBNAIL_HEIGHT && $request -> is_set_get ( 'thm' ))
2020-12-23 03:18:48 +02:00
{
2023-11-13 08:55:20 +02:00
$fn = Url :: clean_input ( $request -> get ( 'thm' ));
2020-12-23 03:18:48 +02:00
if ( $fn == '' )
{
die ();
}
echo new Stream ( $fn );
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2019-09-17 10:16:07 +03:00
//set the sorting mode:
2023-11-13 08:55:20 +02:00
if ( $request -> is_set_get ( 'sort' ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$_SESSION [ 'sort' ] = $request -> get ( 'sort' );
2019-09-17 10:16:07 +03:00
}
2020-12-23 03:18:48 +02:00
else if ( !! empty ( $_SESSION [ 'sort' ]))
2019-09-17 10:16:07 +03:00
{
$_SESSION [ 'sort' ] = 'filename' ; //default sort mode
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2019-09-17 10:16:07 +03:00
//set the sorting order:
2023-11-13 08:55:20 +02:00
if ( $request -> is_set_get ( 'sort_mode' ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
if ( $request -> get ( 'sort_mode' ) == 'a' || $request -> get ( 'sort_mode' ) == 'd' )
{
$_SESSION [ 'sort_mode' ] = $request -> get ( 'sort_mode' );
}
2019-09-17 10:16:07 +03:00
}
2020-12-23 03:18:48 +02:00
else if ( !! empty ( $_SESSION [ 'sort_mode' ]))
2019-09-17 10:16:07 +03:00
{
$_SESSION [ 'sort_mode' ] = 'a' ; //default sort order
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2023-11-08 08:03:03 +02:00
if ( count ( $_FILES ) > 0 ) //deal with any request to upload files:
2019-09-17 10:16:07 +03:00
{
$upload = new Upload ( $you ); //the constructor checks if you have permission to upload
2023-11-15 12:07:28 +02:00
$upload -> do_upload ();
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2019-09-17 10:16:07 +03:00
if ( USE_LOGIN_SYSTEM )
{
2023-11-13 08:55:20 +02:00
if ( $request -> is_set_get ( 'logout' ))
2019-09-17 10:16:07 +03:00
{
2023-11-08 08:03:03 +02:00
$you -> logout ();
2019-09-17 10:16:07 +03:00
}
2023-11-13 08:55:20 +02:00
else if ( $request -> is_set_get ( 'action' ))
2019-09-17 10:16:07 +03:00
{
$admin = new Admin ( $you ); //the constructor checks if you really are an admin
2023-11-27 17:22:26 +02:00
2023-11-13 08:55:20 +02:00
$admin -> action ( $request -> get ( 'action' ));
2019-09-17 10:16:07 +03:00
}
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2020-12-23 03:18:48 +02:00
if ( ANTI_LEECH && !! empty ( $_SESSION [ 'ref' ]))
2019-09-17 10:16:07 +03:00
{
$_SESSION [ 'ref' ] = true ;
2023-11-08 08:03:03 +02:00
}
2023-11-27 17:22:26 +02:00
2019-09-17 10:16:07 +03:00
$search_log = '' ;
2023-11-13 08:55:20 +02:00
if ( SEARCH_ENABLED && $request -> is_set_get ( 'search' ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
$s = Url :: clean_input ( $request -> get ( 'search' ));
$dir_list = new Search ( $s , $dir , $request -> get ( 'search_mode' ));
2019-09-17 10:16:07 +03:00
$search_log = " Search: $s " ;
}
else if ( ENABLE_CACHE )
{
$cache = CACHE_STORAGE_DIR . strtr ( $dir , '\/:' , '---' ); //path to cache file
2020-12-23 03:18:48 +02:00
if ( is_file ( $cache ))
2019-09-17 10:16:07 +03:00
{
2020-12-23 03:18:48 +02:00
$contents = file_get_contents ( $cache );
2019-09-17 10:16:07 +03:00
if ( $contents === false )
{
throw new ExceptionDisplay ( 'Cannot open cache file for reading. Make sure PHP has read permission for these files.' );
}
$dir_list = unserialize ( $contents );
}
else
{
$dir_list = new DirectoryListDetailed ( $dir );
2020-12-23 03:18:48 +02:00
if ( ! is_dir ( CACHE_STORAGE_DIR ))
2019-09-17 10:16:07 +03:00
{
2023-11-13 08:55:20 +02:00
if ( ! Admin :: mkdir_recursive ( CACHE_STORAGE_DIR )) //Attempt to create the directory. If it fails, tell the user to manually make the folder.
2019-09-17 10:16:07 +03:00
{
2020-12-23 03:18:48 +02:00
throw new ExceptionDisplay ( 'Please create the directory <em>' . Url :: html_output ( CACHE_STORAGE_DIR ) . '</em> so cache files can be written.' );
2019-09-17 10:16:07 +03:00
}
}
2020-12-23 03:18:48 +02:00
$h = fopen ( $cache , 'wb' );
2019-09-17 10:16:07 +03:00
if ( $h === false )
{
throw new ExceptionDisplay ( 'Cannot write to cache file. Make sure PHP has write permission in the cache directory.' );
}
fwrite ( $h , serialize ( $dir_list ));
fclose ( $h );
}
}
else
{
2023-11-13 08:55:20 +02:00
$page = (( ENTRIES_PER_PAGE && $request -> is_set_get ( 'page' )) ? ( int ) $request -> get ( 'page' ) : 1 );
2019-09-17 10:16:07 +03:00
$dir_list = new DirectoryListDetailed ( $dir , $page );
2023-11-08 08:03:03 +02:00
$max_page = ( ENTRIES_PER_PAGE ? ( ceil ( $dir_list -> total_items () / $config -> __get ( 'entries_per_page' ))) : 1 );
2019-09-17 10:16:07 +03:00
}
2023-11-15 12:07:28 +02:00
$log -> add_entry ( $search_log );
2023-11-08 08:03:03 +02:00
$str = $dir_list -> __toString ();
2019-09-17 10:16:07 +03:00
echo new Display ( $str );
2023-10-31 21:42:15 +02:00
//echo $mobile_device_detect->detect()->getInfo();
2019-09-17 10:16:07 +03:00
}
2023-11-08 08:03:03 +02:00
2019-09-17 10:16:07 +03:00
catch ( ExceptionDisplay $e )
{
echo $e ;
}
catch ( Exception $e )
{
2023-11-08 08:03:03 +02:00
echo simple_display ( $e -> getMessage ());
2019-09-17 10:16:07 +03:00
}
2023-11-08 08:03:03 +02:00
2023-08-31 22:40:19 +03:00
?>