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
-
-
-
-
+
+
+';
+print ($page_header . $install_form);
+?>