From 68955361dd404a1eb0fdca648f14ed1aefee29d9 Mon Sep 17 00:00:00 2001 From: thomasb Date: Tue, 19 Feb 2008 22:28:28 +0000 Subject: First steps to implement an installer git-svn-id: https://svn.roundcube.net/trunk@1118 208e9e7b-5314-0410-a742-e7e81cd9613c --- roundcubemail/installer/rcube_install.php | 199 ++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 roundcubemail/installer/rcube_install.php (limited to 'roundcubemail/installer/rcube_install.php') diff --git a/roundcubemail/installer/rcube_install.php b/roundcubemail/installer/rcube_install.php new file mode 100644 index 000000000..eee0fb732 --- /dev/null +++ b/roundcubemail/installer/rcube_install.php @@ -0,0 +1,199 @@ +step = intval($_REQUEST['_step']); + $this->get_defaults(); + } + + + /** + * Read the default config file and store properties + */ + function get_defaults() + { + $suffix = is_readable('../config/main.inc.php.dist') ? '.dist' : ''; + + include '../config/main.inc.php' . $suffix; + if (is_array($rcmail_config)) { + $this->defaults = $rcmail_config; + } + + include '../config/db.inc.php'. $suffix; + if (is_array($rcmail_config)) { + $this->defaults += $rcmail_config; + } + } + + + /** + * Getter for a certain config property + * + * @param string Property name + * @return string The property value + */ + function getprop($name) + { + $value = isset($_REQUEST["_$name"]) ? $_REQUEST["_$name"] : $this->defaults[$name]; + + if ($name == 'des_key' && !isset($_REQUEST["_$name"])) + $value = self::random_key(24); + + return $value; + } + + + /** + * Take the default config file and replace the parameters + * with the submitted form data + * + * @param string Which config file (either 'main' or 'db') + * @return string The complete config file content + */ + function create_config($which) + { + $out = file_get_contents("../config/{$which}.inc.php.dist"); + + if (!$out) + return '[Warning: could not read the template file]'; + + foreach ($this->defaults 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; + foreach ($value as $i => $dbgval) + $val += intval($dbgval); + $value = $val; + } + else if (is_bool($default)) + $value = is_numeric($value) ? (bool)$value : $value; + + // replace the matching line in config file + $out = preg_replace( + '/(\$rcmail_config\[\''.preg_quote($prop).'\'\])\s+=\s+(.+);/Uie', + "'\\1 = ' . var_export(\$value, true) . ';'", + $out); + } + + return $out; + } + + + /** + * Display OK status + * + * @param string Test name + * @param string Confirm message + */ + function pass($name, $message = '') + { + echo Q($name) . ':  OK'; + if ($message) + echo '' . Q($name) . ''; + } + + + /** + * Display an error status and increase failure count + * + * @param string Test name + * @param string Error message + * @param string URL for details + */ + function fail($name, $message = '', $url = '') + { + $this->failures++; + + echo Q($name) . ':  NOT OK'; + if ($message) + echo '' . Q($name) . ''; + if ($url) + echo '(See ' . Q($url) . ')'; + } + + + /** + * Display warning status + * + * @param string Test name + * @param string Warning message + * @param string URL for details + */ + function warning($name, $message = '', $url = '') + { + echo Q($name) . ':  NOT AVAILABLE'; + if ($message) + echo '' . Q($name) . ''; + if ($url) + echo '(See ' . Q($url) . ')'; + } + + + /** + * Generarte a ramdom string to be used as encryption key + * + * @param int Key length + * @return string The generated random string + * @static + */ + function random_key($length) + { + $alpha = 'ABCDEFGHIJKLMNOPQERSTUVXYZabcdefghijklmnopqrtsuvwxyz0123456789+*%&?!$-_='; + $out = ''; + + for ($i=0; $i < $length; $i++) + $out .= $alpha{rand(0, strlen($alpha)-1)}; + + return $out; + } + +} + + +/** + * Shortcut function for htmlentities() + * + * @param string String to quote + * @return string The html-encoded string + */ +function Q($string) +{ + return htmlentities($string); +} + -- cgit v1.2.3