From c5042d468e605a7ec9bb6883ba721c8fd222b4ec Mon Sep 17 00:00:00 2001
From: thomascube
Date: Mon, 25 Feb 2008 23:03:54 +0000
Subject: More installer stuff
---
installer/check.php | 29 ++++-
installer/client.js | 36 ++++++
installer/config.php | 295 +++++++++++++++++++++++++++++++++++++++-----
installer/images/add.png | Bin 0 -> 733 bytes
installer/images/delete.png | Bin 0 -> 715 bytes
installer/index.php | 7 +-
installer/rcube_install.php | 119 +++++++++++++++---
installer/styles.css | 23 +++-
installer/test.php | 116 ++++++++++++++++-
9 files changed, 571 insertions(+), 54 deletions(-)
create mode 100644 installer/client.js
create mode 100755 installer/images/add.png
create mode 100755 installer/images/delete.png
diff --git a/installer/check.php b/installer/check.php
index 33264a0e2..9f54d8f8f 100644
--- a/installer/check.php
+++ b/installer/check.php
@@ -1,9 +1,5 @@
'pcre', 'Session' => 'session', 'Sockets' => 'sockets');
$optional_php_exts = array('FileInfo' => 'fileinfo', 'Libiconv' => 'iconv', 'Multibyte' => 'mbstring', 'OpenSSL' => 'openssl');
@@ -14,6 +10,10 @@ $required_libs = array('PEAR' => 'PEAR.php', 'DB' => 'DB.php', 'MDB2' => 'MDB2.p
$supported_dbs = array('MySQL' => 'mysql', 'MySQLi' => 'mysqli',
'PostgreSQL' => 'pgsql', 'SQLite (v2)' => 'sqlite');
+$ini_checks = array('file_uploads' => 1, 'session.auto_start' => 0,
+ 'magic_quotes_gpc' => 0, 'magic_quotes_sybase' => 0,
+ 'zlib.output_compression' => 0);
+
$source_urls = array(
'Sockets' => 'http://www.php.net/manual/en/ref.sockets.php',
'Session' => 'http://www.php.net/manual/en/ref.session.php',
@@ -122,6 +122,27 @@ foreach ($required_libs as $classname => $file) {
echo " ";
}
+
+?>
+
+Checking php.ini/.htaccess settings
+
+ $val) {
+ $status = ini_get($var);
+ if ($status == $val) {
+ $RCI->pass($var);
+ }
+ else {
+ $RCI->fail($var, "is '$status', should be '$val'");
+ }
+ echo ' ';
+}
+?>
+
+failures)
echo 'Sorry but your webserver does not meet the requirements for RoundCube!
Please install the missing modules according to the above check results.
';
diff --git a/installer/client.js b/installer/client.js
new file mode 100644
index 000000000..3121b2693
--- /dev/null
+++ b/installer/client.js
@@ -0,0 +1,36 @@
+
+function toggleblock(id, link)
+{
+ var block = document.getElementById(id);
+
+ return false;
+}
+
+
+function addhostfield()
+{
+ var container = document.getElementById('defaulthostlist');
+ var row = document.createElement('div');
+ var input = document.createElement('input');
+ var link = document.createElement('a');
+
+ input.name = '_default_host[]';
+ input.size = '30';
+ link.href = '#';
+ link.onclick = function() { removehostfield(this.parentNode); return false };
+ link.className = 'removelink';
+ link.innerHTML = 'remove';
+
+ row.appendChild(input);
+ row.appendChild(link);
+ container.appendChild(row);
+}
+
+
+function removehostfield(row)
+{
+ var container = document.getElementById('defaulthostlist');
+ container.removeChild(row);
+}
+
+
diff --git a/installer/config.php b/installer/config.php
index f99c0497e..63031b6b1 100644
--- a/installer/config.php
+++ b/installer/config.php
@@ -3,14 +3,35 @@
get_defaults();
+
+if (!empty($_POST['submit'])) {
+
+ echo 'Copy the following configurations and save them in two files (names above the text box)';
+ echo ' within the config/ directory of your RoundCube installation.
';
+
+ $textbox = new textarea(array('rows' => 16, 'cols' => 60, 'class' => "configfile"));
+
+ echo 'main.inc.php
';
+ echo $textbox->show($RCI->create_config('main'));
+
+ echo 'db.inc.php
';
+ echo $textbox->show($RCI->create_config('db'));
+
+ echo '
';
+
+ // echo '';
+ echo "\n \n";
+}
?>
General configuration
-
+
+smtp_log
+
+ '_smtp_log', 'id' => "cfgsmtplog"));
+echo $check_smtplog->show(intval($RCI->getprop('smtp_log')), array('value' => 1));
+
+?>
+Log sent messages in logs/sendmail
+
+
+
Display settings
-
+
locale_string
@@ -173,23 +430,5 @@ echo $input_locale->show($RCI->getprop('locale_string'));
echo ' failures ? 'disabled' : '') . ' />
';
-
-if (!empty($_POST['submit'])) {
- echo " \n";
-
- echo 'Copy the following configurations and save them in two files (names above the text box)';
- echo ' within the config/ directory of your RoundCube installation.
';
-
- $textbox = new textarea(array('rows' => 20, 'cols' => 60, 'class' => "configfile"));
-
- echo 'main.inc.php
';
- echo $textbox->show($RCI->create_config('main'));
-
- echo 'db.inc.php
';
- echo $textbox->show($RCI->create_config('db'));
-
- echo '
';
-}
-
?>
diff --git a/installer/images/add.png b/installer/images/add.png
new file mode 100755
index 000000000..6332fefea
Binary files /dev/null and b/installer/images/add.png differ
diff --git a/installer/images/delete.png b/installer/images/delete.png
new file mode 100755
index 000000000..08f249365
Binary files /dev/null and b/installer/images/delete.png differ
diff --git a/installer/index.php b/installer/index.php
index a7959e48c..d62f6cb9d 100644
--- a/installer/index.php
+++ b/installer/index.php
@@ -5,6 +5,7 @@
RoundCube Webmail Installer
+
@@ -27,8 +28,12 @@
ini_set('display_errors', 1);
+ $docroot = realpath(dirname(__FILE__) . '/../');
+ $include_path = $docroot . '/program/lib' . PATH_SEPARATOR . $docroot . '/program' . PATH_SEPARATOR . ini_get('include_path');
+ set_include_path($include_path);
+
require_once 'rcube_install.php';
- $RCI = new rcube_install();
+ $RCI = rcube_install::get_instance();
?>
diff --git a/installer/rcube_install.php b/installer/rcube_install.php
index 2e1df00cf..136fdd006 100644
--- a/installer/rcube_install.php
+++ b/installer/rcube_install.php
@@ -25,7 +25,8 @@ class rcube_install
{
var $step;
var $failures = 0;
- var $defaults = array();
+ var $config = array();
+ var $last_error = null;
/**
* Constructor
@@ -33,25 +34,52 @@ class rcube_install
function rcube_install()
{
$this->step = intval($_REQUEST['_step']);
- $this->get_defaults();
}
+ /**
+ * Singleton getter
+ */
+ function get_instance()
+ {
+ static $inst;
+
+ if (!$inst)
+ $inst = new rcube_install();
+
+ return $inst;
+ }
/**
- * Read the default config file and store properties
+ * Read the default config files and store properties
*/
function get_defaults()
{
- $suffix = is_readable('../config/main.inc.php.dist') ? '.dist' : '';
-
- include '../config/main.inc.php' . $suffix;
+ $this->_load_config('.php.dist');
+ }
+
+
+ /**
+ * Read the local config files and store properties
+ */
+ function load_config()
+ {
+ $this->_load_config('.php');
+ }
+
+ /**
+ * Read the default config file and store properties
+ * @access private
+ */
+ function _load_config($suffix)
+ {
+ include '../config/main.inc' . $suffix;
if (is_array($rcmail_config)) {
- $this->defaults = $rcmail_config;
+ $this->config = $rcmail_config;
}
- include '../config/db.inc.php'. $suffix;
+ @include '../config/db.inc'. $suffix;
if (is_array($rcmail_config)) {
- $this->defaults += $rcmail_config;
+ $this->config += $rcmail_config;
}
}
@@ -64,7 +92,7 @@ class rcube_install
*/
function getprop($name)
{
- $value = isset($_REQUEST["_$name"]) ? $_REQUEST["_$name"] : $this->defaults[$name];
+ $value = isset($_REQUEST["_$name"]) ? $_REQUEST["_$name"] : $this->config[$name];
if ($name == 'des_key' && !isset($_REQUEST["_$name"]))
$value = self::random_key(24);
@@ -87,13 +115,9 @@ class rcube_install
if (!$out)
return '[Warning: could not read the template file]';
- foreach ($this->defaults as $prop => $default) {
+ foreach ($this->config as $prop => $default) {
$value = $_POST["_$prop"] ? $_POST["_$prop"] : $default;
- // skip this property
- if (!isset($_POST["_$prop"]) || $value == $default)
- continue;
-
// convert some form data
if ($prop == 'debug_level' && is_array($value)) {
$val = 0;
@@ -101,8 +125,30 @@ class rcube_install
$val += intval($dbgval);
$value = $val;
}
- else if (is_bool($default))
+ else if ($prop == 'db_dsnw' && !empty($_POST['_dbtype'])) {
+ $value = sprintf('%s://%s:%s@%s/%s', $_POST['_dbtype'], $_POST['_dbuser'], $_POST['_dbpass'], $_POST['_dbhost'], $_POST['_dbname']);
+ }
+ else if ($prop == 'smtp_auth_type' && $value == '0') {
+ $value = '';
+ }
+ else if ($prop == 'default_host' && is_array($value)) {
+ $value = self::_clean_array($value);
+ if (count($value) <= 1)
+ $value = $value[0];
+ }
+ else if ($prop == 'smtp_user' && !empty($_POST['_smtp_user_u'])) {
+ $value = '%u';
+ }
+ else if ($prop == 'smtp_pass' && !empty($_POST['_smtp_user_u'])) {
+ $value = '%p';
+ }
+ else if (is_bool($default)) {
$value = is_numeric($value) ? (bool)$value : $value;
+ }
+
+ // skip this property
+ if ($value == $default)
+ continue;
// replace the matching line in config file
$out = preg_replace(
@@ -115,6 +161,17 @@ class rcube_install
}
+ /**
+ * Getter for the last error message
+ *
+ * @return string Error message or null if none exists
+ */
+ function get_error()
+ {
+ return $this->last_error['message'];
+ }
+
+
/**
* Display OK status
*
@@ -170,6 +227,26 @@ class rcube_install
}
+ function _clean_array($arr)
+ {
+ $out = array();
+
+ foreach (array_unique($arr) as $i => $val)
+ if (!empty($val))
+ $out[] = $val;
+
+ return $out;
+ }
+
+ /**
+ * Handler for RoundCube errors
+ */
+ function raise_error($p)
+ {
+ $this->last_error = $p;
+ }
+
+
/**
* Generarte a ramdom string to be used as encryption key
*
@@ -202,3 +279,13 @@ function Q($string)
return htmlentities($string);
}
+
+/**
+ * Fake rinternal error handler to catch errors
+ */
+function raise_error($p)
+{
+ $rci = rcube_install::get_instance();
+ $rci->raise_error($p);
+}
+
diff --git a/installer/styles.css b/installer/styles.css
index 4045f9db1..de4a9ca4d 100644
--- a/installer/styles.css
+++ b/installer/styles.css
@@ -104,7 +104,7 @@ body, td, th, div, p {
}
fieldset {
- margin-bottom: 2em;
+ margin-bottom: 1.5em;
border: 1px solid #aaa;
background-color: #f9f9f9;
}
@@ -163,6 +163,27 @@ h4 {
margin-bottom: 0.2em;
}
+a.blocktoggle {
+ color: #666;
+ text-decoration: none;
+}
+
+a.addlink {
+ color: #999;
+ font-size: 0.9em;
+ padding: 1px 0 1px 20px;
+ background: url('images/add.png') top left no-repeat;
+ text-decoration: none;
+}
+
+a.removelink {
+ color: #999;
+ font-size: 0.9em;
+ padding: 1px 0 1px 24px;
+ background: url('images/delete.png') 4px 0 no-repeat;
+ text-decoration: none;
+}
+
.hint {
color: #666;
font-size: 0.95em;
diff --git a/installer/test.php b/installer/test.php
index 254144e04..783cf3c1b 100644
--- a/installer/test.php
+++ b/installer/test.php
@@ -1,12 +1,120 @@
-
';
+// load local config files
+$RCI->load_config();
+
+$read_main = is_readable('../config/main.inc.php');
+$read_db = is_readable('../config/db.inc.php');
+
+if ($read_main && !empty($RCI->config)) {
+ $RCI->pass('main.inc.php');
+}
+else if ($read_main) {
+ $RCI->fail('main.inc.php', 'Syntax error');
+}
+else if (!$read_main) {
+ $RCI->fail('main.inc.php', 'Unable to read file. Did you create the config files?');
+}
+echo ' ';
-echo ' ';
+if ($read_db && !empty($RCI->config['db_table_users'])) {
+ $RCI->pass('db.inc.php');
+}
+else if ($read_db) {
+ $RCI->fail('db.inc.php', 'Syntax error');
+}
+else if (!$read_db) {
+ $RCI->fail('db.inc.php', 'Unable to read file. Did you create the config files?');
+}
?>
+
+Check configured database settings
+config)) {
+ if (!empty($RCI->config['db_backend']) && !empty($RCI->config['db_dsnw'])) {
+
+ echo 'Backend: ';
+ echo 'PEAR::' . strtoupper($RCI->config['db_backend']) . ' ';
+
+ $_class = 'rcube_' . strtolower($RCI->config['db_backend']);
+ require_once 'include/' . $_class . '.inc';
+
+ $DB = new $_class($RCI->config['db_dsnw'], '', false);
+ $DB->db_connect('w');
+ if (!($db_error_msg = $DB->is_error())) {
+ $RCI->pass('DSN (write)');
+ $db_working = true;
+ }
+ else {
+ $RCI->fail('DSN (write)', "Error: $db_error_msg");
+ }
+ echo ' ';
+ }
+ else {
+ $RCI->fail('DSN (write)', 'not set');
+ }
+}
+else {
+ $RCI->fail('Config', 'Could not read config files');
+}
+
+// initialize db with schema found in /SQL/*
+if ($db_working && $_POST['initdb']) {
+ $engine = preg_match('/^([a-z]+):/i', $RCI->config['db_dsnw'], $regs) ? $regs[1] : 'mysql';
+ $fname = '../SQL/' . ($engine == 'pgsql' ? 'postgres' : $engine) . '.initial.sql';
+ if ($sql = @file_get_contents($fname)) {
+ $DB->query($sql);
+ }
+ else {
+ $RCI->fail('DB Schema', "Cannot read the schema file: $fname");
+ }
+
+ if ($err = $RCI->get_error()) {
+ $RCI->fail('DB Schema', "Error creating database schema: $err");
+ $db_working = false;
+ echo 'Please try to inizialize the database manually as described in the INSTALL guide.
';
+ echo ' ';
+ }
+}
+
+if ($db_working) {
+ $success = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}");
+ if (!$success) {
+ $RCI->fail('DB Schema', "Database not initialized");
+ echo '
';
+ }
+ else {
+ $RCI->pass('DB Schema');
+ }
+ echo ' ';
+
+ $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db';
+ $tz_db = $DB->query($tz_db);
+ $tz_db = $DB->fetch_assoc($tz_db);
+ $tz_db = (int) $tz_db['tz_db'];
+ $tz_local = (int) time();
+ $tz_diff = $tz_local - $tz_db;
+
+ // sometimes db and web servers are on separate hosts, so allow a 30 minutes delta
+ if (abs($tz_diff) > 1800) {
+ $RCI->fail('DB Time', "Database time differs {$td_ziff}s from PHP time");
+ } else {
+ $RCI->pass('DB Time');
+ }
+
+}
+
+
+?>
+
+[@todo Add tests for IMAP and SMTP settings]
+
--
cgit v1.2.3