diff --git a/config.php b/config.php index e8ef669..c409694 100644 --- a/config.php +++ b/config.php @@ -1,5 +1,4 @@ + html, body + { + font-family: verdana, lucidia, sans-serif; + font-size: 14px; + background-color: #F0F0F0; + color: #000000; + } + a + { + color: #000000; + text-decoration: none; + } + hr + { + color: #000020; + background-color: #000020; + border: none; + width: 75%; + height: 1px; + } + h3 + { + text-align: center; + color: #000000; + } + td + { + font-family: verdana, lucidia, sans-serif; + font-size: 14px; + color: #000000; + border: 1px solid #7F8FA9; + } + tr + { + background: #F2F6FC; + color: #000020; + } + .small + { + font-size: 11px; + color: #000000; + } + '; + //debug code here: print_r('post array: ' . $request->post_array() . ', strings: ' . count($strings) . ', numbers: ' . count($numbers)); if ($request->post_array() >= count($strings) + count($numbers)) { - $directories = array('base_dir', 'icon_path', 'flag_path', 'assets_path', 'template'); + $directories = array('base_dir', 'icon_path', 'flag_path', 'assets_path', 'template_path', 'template'); $output = "post_array() >= count($strings) + count($numbers)) { die(simple_display('Required setting ' . htmlentities($setting) . ' not set.')); } + if ($request->is_empty_post($setting)) { $output .= "$setting\tfalse\n"; continue; } + $request->recursive_set_var($setting, str_replace('\\', '/', $request->post($setting)), false); if (in_array($setting, $directories) && !preg_match('#/$#', $request->post($setting))) //make sure there is a slash at the end of directories @@ -69,22 +131,26 @@ if ($request->post_array() >= count($strings) + count($numbers)) } $output .= "$setting\t{$request->post($setting)}\n"; } - $_POST[$setting] = $request->post($setting); + + $_POST[$setting] = $request->post($setting); foreach ($checkboxes as $setting) { $output .= "$setting\t" . ($request->is_post($setting) ? 'true' : 'false') . "\n"; } + foreach ($numbers as $setting) { if ($request->is_not_set_post($setting)) { die(simple_display('Required setting ' . htmlentities($setting) . ' not set.')); } + if ($request->is_empty_post($setting)) { $output .= "$setting\t0\n"; continue; } + if ($request->post($setting) < 0) { die(simple_display('The setting ' . htmlentities($setting) . ' should not be a negative number.')); @@ -100,21 +166,29 @@ if ($request->post_array() >= count($strings) + count($numbers)) { die(simple_display('It seems you are using an absolute path for the Base Directory.' . '
This means you must check the "Pipe downloaded files though the PHP script" box.')); } + if ((int)$request->post('bandwidth_limit') !== 0) { die(simple_display('For the Bandwidth Limit feature to work, the "force download" feature needs to be on.' . '
This means you must check the "Pipe downloaded files though the PHP script" box.')); } } + if ($request->is_set_post('must_login_to_download') && $request->is_not_set_post('use_login_system')) { die(simple_display('To enable must_login_to_download, the ' . 'use_login_system option must also be turned on.')); } - foreach (array('base_dir', 'template') as $valid) + + foreach (array('base_dir', 'template') as $setting) { - if (!@is_dir($request->post($valid))) + $valid = $request->post($setting); + if (!opendir($valid)) { - //die(simple_display(htmlentities($valid) . ' setting is not a valid directory.')); + die(simple_display(htmlentities($valid) . ' for ' . htmlentities($setting) . ' setting is not a valid directory.')); } + else + { + closedir($valid); + } } if (@is_file(CONFIG_STORED)) @@ -123,7 +197,7 @@ if ($request->post_array() >= count($strings) + count($numbers)) $temp_name = CONFIG_STORED . '.bak'; for ($i = 1; @file_exists($temp_name); $i++) { - $temp_name = CONFIG_STORED . '.bak' . (string)$i; + $temp_name = CONFIG_STORED . '.bak' . (string) $i; } @copy(CONFIG_STORED, $temp_name); } @@ -137,464 +211,563 @@ if ($request->post_array() >= count($strings) + count($numbers)) die($output); } else - //the file was opened successfully, so write to it + //the .php file was opened successfully, so we write to it { fwrite($h, $output); - fclose($h); + fclose($h); - //begin display of "configuration complete" page - echo ''; - ?> - - - - AutoIndex Configuration: Complete! - - - - - - - -
-

Write successful!
AutoIndex configuration is finished.

-

Continue.

-
- - - + + + + + + + + + + + + + + + + + + + + + AutoIndex Configuration: Complete! + '.$install_header_css.' + + ; + + + + + +
+

Write successful!
AutoIndex configuration is finished.

+

Continue.

+
+ + '; die(); } } -//list of default settings -$settings = array( - 'base_dir' => './', - 'assets_path' => 'assets/', - 'icon_path' => 'index_icons/winvista/', - 'flag_path' => 'flags/language/', - 'language' => 'en', - 'template' => './templates/default/', - 'log_file' => 'access.log', - 'description_file' => 'description_file', - 'user_list' => '.htpasswd.autoindex', - 'download_count' => 'download_count', - 'hidden_files' => 'hidden_files', - 'banned_list' => 'banned_users', - 'show_dir_size' => 'true', - 'use_login_system' => 'true', - 'force_download' => 'false', - 'search_enabled' => 'true', - 'anti_leech' => 'false', - 'must_login_to_download' => 'false', - 'archive' => 'false', - 'days_new' => '7', - 'entries_per_page' => '300', - 'thumbnail_height' => '100', - 'bandwidth_limit' => '0', - 'md5_show' => '20', - 'parse_htaccess' => 'true' -); + +/** if we're reconfiguring the script, use the current settings: +*/ +$settings = !isset($settings) ? array() : $settings; global $config; -if (isset($config)) //if we're reconfiguring the script, use the current settings + +/** +* now we need to include either the stored settings, or the config generator: +**/ +if (!isset($config)) { - foreach ($settings as $key => $data) + if (is_file(CONFIG_STORED)) { - $settings[$key] = $config->__get($key); + if (!is_readable(CONFIG_STORED)) + { + print("This is fresh install so the script will attempt to write a file named " . CONFIG_STORED . " to the " . ROOT_PATH . " directory."); + } + $config = new ConfigData(CONFIG_STORED); } } + +/** +* Go through each config setting, and set a constant with each setting's + * name to either true or false depending on if the config setting is enabled. + **/ +if (isset($config)) +{ + foreach ($config as $key => $item) + { + //For security poposes var $config is a private variable so this will not work: + $settings[$key] = $config->__get($key); + } + //So we list the default settings one by one + $settings = array( + 'base_dir' => $config->__get('base_dir'), + 'assets_path' => $config->__get('assets_path'), + 'icon_path' => $config->__get('icon_path'), + 'flag_path' => $config->__get('flag_path'), + 'language' => $config->__get('language'), + 'template' => $config->__get('template'), + 'template_path' => $config->__get('template_path'), + 'log_file' => $config->__get('log_file'), + 'description_file' => $config->__get('user_list'), + 'user_list' => $config->__get('user_list'), + 'download_count' => $config->__get('download_count'), + 'hidden_files' => $config->__get('hidden_files'), + 'banned_list' => $config->__get('banned_list'), + 'show_dir_size' => $config->__get('show_dir_size'), + 'use_login_system' => $config->__get('use_login_system'), + 'force_download' => $config->__get('force_download'), + 'search_enabled' => $config->__get('search_enabled'), + 'anti_leech' => $config->__get('anti_leech'), + 'must_login_to_download' => $config->__get('must_login_to_download'), + 'archive' => $config->__get('archive'), + 'days_new' => $config->__get('days_new'), + 'entries_per_page' => $config->__get('entries_per_page'), + 'thumbnail_height' => $config->__get('thumbnail_height'), + 'bandwidth_limit' => $config->__get('bandwidth_limit'), + 'md5_show' => $config->__get('md5_show'), + 'parse_htaccess' => $config->__get('parse_htaccess') + ); +} + +/** doble check the directories +**/ +//overwrite the base dir path +if(!empty($settings['base_dir']) && !is_file(@realpath($settings['base_dir'])) && !is_link(@realpath($settings['base_dir'])) && $settings['base_dir'] != "." && $settings['base_dir'] != ".." && $settings['base_dir'] != "CVS" ) +{ + $CONFIG_PATH = $settings['base_dir']; +} +//overwrite the template base dir path +if(!empty($settings['template_path']) && !is_file(@realpath($settings['template_path'])) && !is_link(@realpath($settings['template_path'])) && $settings['template_path'] != "." && $settings['template_path'] != ".." && $settings['template_path'] != "CVS" ) +{ + @define('PATH_TO_TEMPLATES', $settings['template_path']); +} +// overwrite the classes dir path +if( !is_file(@realpath($CONFIG_PATH . 'classes/')) && !is_link(@realpath($CONFIG_PATH . 'classes/')) && $CONFIG_PATH . 'classes/' != "." && $CONFIG_PATH . 'classes/' != ".." && $CONFIG_PATH . 'classes/' != "CVS" ) +{ + @define('PATH_TO_CLASSES', $CONFIG_PATH . 'classes/'); +} +// overwrite the languages dir path +if( !is_file(@realpath($CONFIG_PATH . 'languages/')) && !is_link(@realpath($CONFIG_PATH . 'languages/')) && $CONFIG_PATH . 'languages/' != "." && $CONFIG_PATH . 'languages/' != ".." && $CONFIG_PATH . 'languages/' != "CVS" ) +{ + @define('PATH_TO_LANGUAGES', $CONFIG_PATH . 'languages/'); +} +// overwrite the flags dir path +if( !is_file(@realpath($CONFIG_PATH . 'flags/')) && !is_link(@realpath($CONFIG_PATH . 'flags/')) && $CONFIG_PATH . 'flags/' != "." && $CONFIG_PATH . 'flags/' != ".." && $CONFIG_PATH . 'flags/' != "CVS" ) +{ + @define('PATH_TO_FLAGS', $CONFIG_PATH . 'flags/'); +} +// overwrite the index_icons dir path +if( !is_file(@realpath($CONFIG_PATH . 'index_icons/')) && !is_link(@realpath($CONFIG_PATH . 'index_icons/')) && $CONFIG_PATH . 'index_icons/' != "." && $CONFIG_PATH . 'index_icons/' != ".." && $CONFIG_PATH . 'index_icons/' != "CVS" ) +{ + @define('PATH_TO_ICONS', $CONFIG_PATH . 'index_icons/'); +} +// overwrite the assets dir path +if( !is_file(@realpath($CONFIG_PATH . 'assets/')) && !is_link(@realpath($CONFIG_PATH . 'assets/')) && $CONFIG_PATH . 'assets/' != "." && $CONFIG_PATH . 'assets/' != ".." && $CONFIG_PATH . 'assets/' != "CVS" ) +{ + @define('PATH_TO_ASSETS', $CONFIG_PATH . 'assets/'); +} + +//List Templates GNU GPL v. 2.0 / Borrowed from github.com/Mx-Publisher/mxpcms +$installable_themes = array(); +$current_template_name = isset($settings['template']) ? $settings['template'] : $default_template_name; + +$lang_select = ' Default Language: '; + +// i.e. ./templates/SwiftBlueBeitDina/ +$template = empty($settings['template']) ? PATH_TO_TEMPLATES . $current_template_name : $settings['template']; +$template_data = str_replace('/', '', explode(dirname($template), $template)); +$template_name = !empty($template_data[1]) ? $template_data[1] : $default_template_name; + +if ($dir = @opendir(PATH_TO_TEMPLATES)) +{ + while($sub_dir = @readdir($dir)) + { + // get the sub-template path + if( !is_file(@realpath(PATH_TO_TEMPLATES .$sub_dir)) && !is_link(@realpath(PATH_TO_TEMPLATES .$sub_dir)) && $sub_dir != "." && $sub_dir != ".." && $sub_dir != "CVS" ) + { + if( @file_exists(realpath(PATH_TO_TEMPLATES . $sub_dir . "/$sub_dir.css")) || @file_exists(realpath(PATH_TO_TEMPLATES . $sub_dir . "/default.css")) ) + { + $installable_themes[] = array('template' => PATH_TO_TEMPLATES . $sub_dir . '/', 'template_name' => $sub_dir); + } + } + } + + $style_select = ' Template Directory: Style: '; +} +else +{ + $style_select = ''; +} +closedir($dir); + +//list of default settings +$settings = array( + 'base_dir' => empty($settings['base_dir']) ? $CONFIG_PATH : $settings['base_dir'], + 'assets_path' => empty($settings['assets_path']) ? PATH_TO_ASSETS : $settings['assets_path'], + 'icon_path' => empty($settings['icon_path']) ? PATH_TO_ICONS . 'winvista/' : $settings['icon_path'], //To do: A list alike for languages + 'flag_path' => empty($settings['flag_path']) ? PATH_TO_FLAGS . 'language/' : $settings['flag_path'], //is 'language' or 'country' icons + 'language' => empty($settings['language']) ? 'en' : $settings['language'], + 'template_path' => empty($settings['template_path']) ? PATH_TO_TEMPLATES : $settings['template_path'], + 'template' => empty($settings['template']) ? $template : $settings['template'], + 'log_file' => empty($settings['log_file']) ? $access_log_file_name : $settings['log_file'], + 'description_file' => empty($settings['description_file']) ? $description_file : $settings['description_file'], + 'user_list' => empty($settings['user_list']) ? $user_list_file : $settings['user_list'], + 'download_count' => empty($settings['download_count']) ? $download_count_file : $settings['download_count'], + 'hidden_files' => empty($settings['hidden_files']) ? $hidden_files_file : $settings['hidden_files'], + 'banned_list' => empty($settings['banned_list']) ? $banned_list_file : $settings['banned_list'], + 'show_dir_size' => empty($settings['show_dir_size']) ? 'true' : $settings['show_dir_size'], + 'use_login_system' => empty($settings['use_login_system']) ? 'true' : $settings['use_login_system'], + 'force_download' => empty($settings['force_download']) ? 'false' : $settings['force_download'], + 'search_enabled' => empty($settings['search_enabled']) ? 'true' : $settings['search_enabled'], + 'anti_leech' => empty($settings['anti_leech']) ? 'false' : $settings['anti_leech'], + 'must_login_to_download' => empty($settings['must_login_to_download']) ? 'false' : $settings['must_login_to_download'], + 'archive' => empty($settings['archive']) ? 'false' : $settings['archive'], + 'days_new' => empty($settings['days_new']) ? '7' : $settings['days_new'], + 'entries_per_page' => empty($settings['entries_per_page']) ? '300' : $settings['entries_per_page'], + 'thumbnail_height' => empty($settings['thumbnail_height']) ? '100' : $settings['thumbnail_height'], + 'bandwidth_limit' => empty($settings['bandwidth_limit']) ? '0' : $settings['bandwidth_limit'], + 'md5_show' => empty($settings['md5_show']) ? '20' : $settings['md5_show'], + 'parse_htaccess' => empty($settings['parse_htaccess']) ? 'true' : $settings['parse_htaccess'] +); + //begin display of main configuration page: -echo ''; -?> - - - -AutoIndex Configuration Generator - - - -
+$page_header = ' + + + + + -

- AutoIndex PHP Script -
Configuration -

-

- The default options are currently selected, so just press the configure button at the bottom to use them. -

- -
- -

- - - - -
- Base Directory: -

- This is the folder that will be the root of the directory listing. -
This will be the starting point for the script. Nothing above this directory can be viewed, but its subfolders can. -
Make sure to use a path relative to this index.php file if you can. -

-
-

- - - - -
Assets Path: -

- This is the path to the assets files (the path web browsers will access them from). -
The included assets are cookie consent, ion icons, font awesome, and jquery. -

-
-

- - - - -
- Icon Path: -

- This is the path to the icon image files (the path web browsers will access them from). -
The included icon sets are apache, kde, osx, and winxp. -
You can leave it blank to not show icons. + + + + + + + + + + + + + + + AutoIndex Configuration Generator + '.$install_header_css.' + + + '; + $install_form = ' + +

+ The AutoIndex PHP Script special edition by Beit Dina Institute +
Configuration +

+

+ The default options are currently selected, so just press the configure button at the bottom to use them.

-
-

- - +
+

+

Return to the Main Index.

'; + $install_form .= ' +
+ + + +
+ Base Directory: '; + + $install_form .= '

This is the folder that will be the root of the directory listing. +
This will be the starting point for the script. Nothing above this directory can be viewed, but its subfolders can. +
Make sure to use a path relative to this index.php file if you can. +

+
+

'; + $install_form .= ' + + + +
Assets Path: '; + $install_form .= '

+ This is the path to the assets files (the path web browsers will access them from). +
The included assets are cookie consent, ion icons, font awesome, and jquery. +

+
+

'; + $install_form .= ' + - -
- Flag Path: + Icon Path: '; + $install_form .= '

- This is the path to the flag image files (the path web browsers will access them from). -
The included icon sets are country, language. + This is the path to the icon image files (the path web browsers will access them from). +
The included icon sets are apache, kde, osx, and winxp.
You can leave it blank to not show icons.

-

- - - - -
- /> Show Directory Size -

- If this box is checked, the total size of directories will be shown under size (all the folder's contents will be added up). -
Otherwise, it will display "[dir]" under size. -
NOTE: If you are trying to index many files (meaning a few thousand), you will notice a speed improvement with this turned off. -

-
-

- - - - -
- /> Enable Searching -

- If this box is checked, people will be able to search for a file or folder by its filename. -
It will search the folder you are currently in, and all subfolders. -
Searching is not case sensitive. -

-
-

- - - - -
- Template Directory: -

- This is the path where the *.tpl template files are located (relative to this index.php file). -

-
-

- - - - -
- /> Enable Login System -
/> Users must login to view/download -
User List: -

- User List contains the path to the text file where the usernames and encrypted passwords are stored. -
Make sure the file is chmod'ed so PHP can read and write to it. -
(User List is only needed if the login system is enabled.) -
-
The default accounts are: -
username: admin -
password: admin -
-
username: user -
password: user -
-
Be sure to create new accounts, then delete these default ones if you enable the login system! -

-
-

- - - - -
- Age for "New" Icon: days -

- This contains the number of days old a file can be and still have [New] written next to it. -
If it is set to 0, this feature will be disabled. -

-
-

- - - - -
- Number of file entires per page: -

- This contains the number of files or folders to display on a single page. - If there are more files or folders, the display will be separated into different - pages with Previous and Next buttons. -
If it is set to 0, everything will be displayed on one page. -

-
-

- - - - -
- Image Thumbnail Height: pixels -

- This is a feature that will show thumbnails next to images. (NOTE: GDlib 2.0.1 or higher is required) -
Setting it to 0 will disable this feature, and setting it to any other number will set the size of the thumbnail. -
(100 is a good setting to start with.) -

-
-

- + +
+

'; + $install_form .= ' + + + +
+ Flag Path: '; + $install_form .= ' +

+ This is the path to the flag image files (the path web browsers will access them from). +
The included icon sets are country, language. +
You can leave it blank to not show icons. +

+
+

'; + $install_form .= ' + + + +
+ Otherwise, it will display "[dir]" under size. +
NOTE: If you are trying to index many files (meaning a few thousand), you will notice a speed improvement with this turned off. +

+
+

'; + $install_form .= ' + + +
- /> Pipe downloaded files though the PHP script -

Bandwidth Limit: KB/s

+ + This is the path where the *.tpl template files are located (relative to this index.php file). +

+
+

'; + $install_form .= ' + + + +
+ (User List is only needed if the login system is enabled.) +
+
The default accounts are: +
username: admin +
password: admin +
+
username: user +
password: user +
+
Be sure to create new accounts, then delete these default ones if you enable the login system! +

+
+

'; + $install_form .= ' + + + +
+ Age for "New" Icon: days +

+ This contains the number of days old a file can be and still have [New] written next to it. +
If it is set to 0, this feature will be disabled. +

+
+

'; + $install_form .= ' + + + +
+ Number of file entires per page: +

+ This contains the number of files or folders to display on a single page. + If there are more files or folders, the display will be separated into different + pages with Previous and Next buttons. +
If it is set to 0, everything will be displayed on one page. +

+
+

'; + $install_form .= ' + + + +
+ Image Thumbnail Height: pixels +

+ This is a feature that will show thumbnails next to images. (NOTE: GDlib 2.0.1 or higher is required) +
Setting it to 0 will disable this feature, and setting it to any other number will set the size of the thumbnail. +
(100 is a good setting to start with.) +

+
+

'; + $install_form .= ' + - -
-

/> Anti-Leech

+ Since some people turn off referrer sending in their browser, this option is not recommended. + This contains the max download speed for files. The above checkbox needs to be checked for this to work. +
If it is set to 0, the script will not limit download speed.

-

- - - +
-

- The following items contain the path and filename to the file where the data for that feature will be stored. -
Leave it blank to turn off that feature. -

-

Hidden Files List: -
- Any file or folder matched to an item in this list will be kept hidden. -
The contents of the list are editable when you login as an admin. -
-

+
+

'; + $install_form .= ' + + + +
+

Since some people turn off referrer sending in their browser, this option is not recommended. +

+
+

'; + $install_form .= ' + + - -
+

+ The following items contain the path and filename to the file where the data for that feature will be stored. +
Leave it blank to turn off that feature. +

+

Hidden Files List: +
+ Any file or folder matched to an item in this list will be kept hidden. +
The contents of the list are editable when you login as an admin. +
+

-

Access Log File: -
- The file to write the access log. -
If this is enabled, you will be able to view the contents of the logfile -
and generate statistics when you login as an admin. -

+

Access Log File: +
+ The file to write the access log. +
If this is enabled, you will be able to view the contents of the logfile +
and generate statistics when you login as an admin. +

-

File/Folder Description File: -
- The file to write the file descriptions to. -
File/Folder descriptions are editable when you login as an admin. -

+

File/Folder Description File: +
+ The file to write the file descriptions to. +
File/Folder descriptions are editable when you login as an admin. +

-

Download Count File: -
- The file to write the file download counts to. -
The count is automatically increased when a file is downloaded. -

+

Download Count File: +
+ The file to write the file download counts to. +
The count is automatically increased when a file is downloaded. +

-

Banned User List: -
- The file to write IP addresses and hostnames that are blocked from accessing this script. -
The contents of the list are editable when you login as an admin. -

-
-

- - - - -
- /> Allow folder archive downloading -

- If this box is checked, users will be able to download the folder's contents as a tar archive file. -

-
-

- - - - -
- /> Parse .htaccess files -

- If this box is checked, .htaccess files will be parsed and used by AutoIndex. -

-
-

- - - - -
-

MD5 calculation max size: MB

-

- Setting this to 0 will disable this feature, and setting it to any other number will set the maximum size of a file to allow users to find the md5sum of (in megabytes). -
(10 is a good setting to start with.) -

-
-

- - - - -
- Default Language: -

- The user's browser's default language is used, unless that language is - not available in AutoIndex. In that case, the language selected here is - used. -

-
-

-


-

-

- -

-

- When you press Configure, the script will attempt to write the config data to the file. -
If it cannot (for example if it does not have write permission in the directory) the config file will be downloaded, and you will have to upload it to your server. -
(It should be named and put in the same folder as index.php) -

-
- - +

Banned User List: +
+ The file to write IP addresses and hostnames that are blocked from accessing this script. +
The contents of the list are editable when you login as an admin. +

+ + + +

'; + $install_form .= ' + + + +
+ +
+

'; + $install_form .= ' + + + +
+ + The user\'s browser\'s default language is used, unless that language is + not available in AutoIndex. In that case, the language selected here is + used. +

+
+

+


+

'; + $install_form .= '

+ +

+

+ When you press Configure, the script will attempt to write the config data to the file. +
If it cannot (for example if it does not have write permission in the directory) the config file will be downloaded, and you will have to upload it to your server. +
(It should be named '. CONFIG_STORED . ' and put in the same folder as index.php) +

+ + + +'; +print ($page_header . $install_form); +?>