From a0b0b7971f829d4e8c23638fdd1127573819b2bc Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 3 Nov 2010 17:56:54 +1100 Subject: [PATCH] Added a "test installation/configuration" file. --- inc/config.php | 9 +++--- test.php | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 test.php diff --git a/inc/config.php b/inc/config.php index f2d5d309..f0414cda 100644 --- a/inc/config.php +++ b/inc/config.php @@ -69,8 +69,9 @@ define('URL_MATCH', '/^' . (@$_SERVER['HTTPS']?'https':'http').':\/\/'.$_SERVER['HTTP_HOST'] . '(' . preg_quote(ROOT, '/') . '|' . preg_quote(ROOT, '/') . '' . preg_quote(FILE_INDEX, '/') . '|' . preg_quote(ROOT, '/') . '' . str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) . ')$/'); - if(!file_exists(DIR_IMG)) mkdir(DIR_IMG) or error("Couldn't create " . DIR_IMG . ". Install manually."); - if(!file_exists(DIR_THUMB)) mkdir(DIR_THUMB) or error("Couldn't create " . DIR_IMG . ". Install manually."); - if(!file_exists(DIR_RES)) mkdir(DIR_RES) or error("Couldn't create " . DIR_IMG . ". Install manually."); - + if(!defined(IS_INSTALLATION)) { + if(!file_exists(DIR_IMG)) @mkdir(DIR_IMG) or error("Couldn't create " . DIR_IMG . ". Install manually."); + if(!file_exists(DIR_THUMB)) @mkdir(DIR_THUMB) or error("Couldn't create " . DIR_IMG . ". Install manually."); + if(!file_exists(DIR_RES)) @mkdir(DIR_RES) or error("Couldn't create " . DIR_IMG . ". Install manually."); + } ?> \ No newline at end of file diff --git a/test.php b/test.php new file mode 100644 index 00000000..0cab3ac6 --- /dev/null +++ b/test.php @@ -0,0 +1,92 @@ +"; + } + function check($title, $test) { + global $body, $count; + $count[$test]++; + $body .= '' . $title . '' . image($test) . ''; + } + function title($text) { + global $body; + $body .= '' . $text . ''; + } + + $count = Array('ok'=>0, 'warning'=>0, 'error'=>0); + $todo = Array(); + $body = ''; + + // Database + title('Database'); + + if($sql = @mysql_connect(MY_SERVER, MY_USER, MY_PASSWORD)) { + $body .= check('Connection to server.', 'ok'); + if(@mysql_select_db(MY_DATABASE, $sql)) + $body .= check('Select database.', 'ok'); + else { + $body .= check('Select database.', 'error'); + $todo[] = 'config.php: Check database configuration.'; + } + } else { + $body .= check('Connection to server.', 'error'); + $todo[] = 'config.php: Check database configuration.'; + } + + // Configuration + title('Configuration'); + $root = dirname($_SERVER['REQUEST_URI']) . '/'; + if(ROOT != $root) { + $body .= check('Correct document root.', 'error'); + $todo[] = "config.php: Change ROOT to '{$root}'"; + } else + $body .= check('Correct document root.', 'ok'); + + // Permissions + title('Permissions'); + + $directories = Array(DIR_IMG, DIR_THUMB, DIR_RES, '.'); + foreach($directories as $dir) { + if(file_exists($dir)) { + if(is_writable($dir) && is_readable($dir)) { + $body .= check($dir, 'ok'); + } else { + $body .= check($dir, 'error'); + $todo[] = 'CHMOD ' . $dir . ' to allow PHP to read and write.'; + } + } else { + $body .= check($dir, 'error'); + $todo[] = 'Create directory: ' . $dir; + } + } + + // Other + title('Other'); + if(get_magic_quotes_gpc()) { + $body .= check('magic_quotes_gpc', 'warning'); + $todo[] = 'Recommended: Disable magic_quotes_gpc in your PHP configuration.'; + } else + $body .= check('magic_quotes_gpc', 'ok'); + + $body .= '
'; + + if(!empty($todo)) { + $body .= '
';
+		foreach($todo as $do)
+			$body .= "{$do}\n";
+		$body .= '
'; + } + + if(!$count['error']) { + $body .= '

Everything seems okay.

'; + } + + die(Element('page.html', Array('index' => ROOT, 'title'=>'Tinyboard', 'subtitle'=>'Installation', 'body'=>$body))); +?>