commit | author | age
|
354978
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| rcube_install.php | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail package | |
|
8 |
| Copyright (C) 2008, RoundCube Dev. - Switzerland | |
|
9 |
| Licensed under the GNU Public License | |
|
10 |
+-----------------------------------------------------------------------+ |
|
11 |
|
|
12 |
$Id: $ |
|
13 |
|
|
14 |
*/ |
|
15 |
|
|
16 |
|
|
17 |
/** |
|
18 |
* Class to control the installation process of the RoundCube Webmail package |
|
19 |
* |
|
20 |
* @category Install |
|
21 |
* @package RoundCube |
|
22 |
* @author Thomas Bruederli |
|
23 |
*/ |
|
24 |
class rcube_install |
|
25 |
{ |
|
26 |
var $step; |
|
27 |
var $failures = 0; |
|
28 |
var $defaults = array(); |
|
29 |
|
|
30 |
/** |
|
31 |
* Constructor |
|
32 |
*/ |
|
33 |
function rcube_install() |
|
34 |
{ |
|
35 |
$this->step = intval($_REQUEST['_step']); |
|
36 |
$this->get_defaults(); |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
/** |
|
41 |
* Read the default config file and store properties |
|
42 |
*/ |
|
43 |
function get_defaults() |
|
44 |
{ |
|
45 |
$suffix = is_readable('../config/main.inc.php.dist') ? '.dist' : ''; |
|
46 |
|
|
47 |
include '../config/main.inc.php' . $suffix; |
|
48 |
if (is_array($rcmail_config)) { |
|
49 |
$this->defaults = $rcmail_config; |
|
50 |
} |
|
51 |
|
|
52 |
include '../config/db.inc.php'. $suffix; |
|
53 |
if (is_array($rcmail_config)) { |
|
54 |
$this->defaults += $rcmail_config; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
|
|
59 |
/** |
|
60 |
* Getter for a certain config property |
|
61 |
* |
|
62 |
* @param string Property name |
|
63 |
* @return string The property value |
|
64 |
*/ |
|
65 |
function getprop($name) |
|
66 |
{ |
|
67 |
$value = isset($_REQUEST["_$name"]) ? $_REQUEST["_$name"] : $this->defaults[$name]; |
|
68 |
|
|
69 |
if ($name == 'des_key' && !isset($_REQUEST["_$name"])) |
|
70 |
$value = self::random_key(24); |
|
71 |
|
|
72 |
return $value; |
|
73 |
} |
|
74 |
|
|
75 |
|
|
76 |
/** |
|
77 |
* Take the default config file and replace the parameters |
|
78 |
* with the submitted form data |
|
79 |
* |
|
80 |
* @param string Which config file (either 'main' or 'db') |
|
81 |
* @return string The complete config file content |
|
82 |
*/ |
|
83 |
function create_config($which) |
|
84 |
{ |
|
85 |
$out = file_get_contents("../config/{$which}.inc.php.dist"); |
|
86 |
|
|
87 |
if (!$out) |
|
88 |
return '[Warning: could not read the template file]'; |
|
89 |
|
|
90 |
foreach ($this->defaults as $prop => $default) { |
|
91 |
$value = $_POST["_$prop"] ? $_POST["_$prop"] : $default; |
|
92 |
|
|
93 |
// skip this property |
|
94 |
if (!isset($_POST["_$prop"]) || $value == $default) |
|
95 |
continue; |
|
96 |
|
|
97 |
// convert some form data |
|
98 |
if ($prop == 'debug_level' && is_array($value)) { |
|
99 |
$val = 0; |
|
100 |
foreach ($value as $i => $dbgval) |
|
101 |
$val += intval($dbgval); |
|
102 |
$value = $val; |
|
103 |
} |
|
104 |
else if (is_bool($default)) |
|
105 |
$value = is_numeric($value) ? (bool)$value : $value; |
|
106 |
|
|
107 |
// replace the matching line in config file |
|
108 |
$out = preg_replace( |
|
109 |
'/(\$rcmail_config\[\''.preg_quote($prop).'\'\])\s+=\s+(.+);/Uie', |
|
110 |
"'\\1 = ' . var_export(\$value, true) . ';'", |
|
111 |
$out); |
|
112 |
} |
|
113 |
|
|
114 |
return $out; |
|
115 |
} |
|
116 |
|
|
117 |
|
|
118 |
/** |
|
119 |
* Display OK status |
|
120 |
* |
|
121 |
* @param string Test name |
|
122 |
* @param string Confirm message |
|
123 |
*/ |
|
124 |
function pass($name, $message = '') |
|
125 |
{ |
|
126 |
echo Q($name) . ': <span class="success">OK</span>'; |
6557d3
|
127 |
$this->_showhint($message); |
354978
|
128 |
} |
T |
129 |
|
|
130 |
|
|
131 |
/** |
|
132 |
* Display an error status and increase failure count |
|
133 |
* |
|
134 |
* @param string Test name |
|
135 |
* @param string Error message |
|
136 |
* @param string URL for details |
|
137 |
*/ |
|
138 |
function fail($name, $message = '', $url = '') |
|
139 |
{ |
|
140 |
$this->failures++; |
|
141 |
|
|
142 |
echo Q($name) . ': <span class="fail">NOT OK</span>'; |
6557d3
|
143 |
$this->_showhint($message, $url); |
354978
|
144 |
} |
T |
145 |
|
|
146 |
|
|
147 |
/** |
|
148 |
* Display warning status |
|
149 |
* |
|
150 |
* @param string Test name |
|
151 |
* @param string Warning message |
|
152 |
* @param string URL for details |
|
153 |
*/ |
6557d3
|
154 |
function na($name, $message = '', $url = '') |
354978
|
155 |
{ |
6557d3
|
156 |
echo Q($name) . ': <span class="na">NOT AVAILABLE</span>'; |
T |
157 |
$this->_showhint($message, $url); |
|
158 |
} |
|
159 |
|
|
160 |
|
|
161 |
function _showhint($message, $url = '') |
|
162 |
{ |
|
163 |
$hint = Q($message); |
|
164 |
|
354978
|
165 |
if ($url) |
6557d3
|
166 |
$hint .= ($hint ? '; ' : '') . 'See <a href="' . Q($url) . '" target="_blank">' . Q($url) . '</a>'; |
T |
167 |
|
|
168 |
if ($hint) |
|
169 |
echo '<span class="indent">(' . $hint . ')</span>'; |
354978
|
170 |
} |
T |
171 |
|
|
172 |
|
|
173 |
/** |
|
174 |
* Generarte a ramdom string to be used as encryption key |
|
175 |
* |
|
176 |
* @param int Key length |
|
177 |
* @return string The generated random string |
|
178 |
* @static |
|
179 |
*/ |
|
180 |
function random_key($length) |
|
181 |
{ |
|
182 |
$alpha = 'ABCDEFGHIJKLMNOPQERSTUVXYZabcdefghijklmnopqrtsuvwxyz0123456789+*%&?!$-_='; |
|
183 |
$out = ''; |
|
184 |
|
|
185 |
for ($i=0; $i < $length; $i++) |
|
186 |
$out .= $alpha{rand(0, strlen($alpha)-1)}; |
|
187 |
|
|
188 |
return $out; |
|
189 |
} |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
|
|
194 |
/** |
|
195 |
* Shortcut function for htmlentities() |
|
196 |
* |
|
197 |
* @param string String to quote |
|
198 |
* @return string The html-encoded string |
|
199 |
*/ |
|
200 |
function Q($string) |
|
201 |
{ |
|
202 |
return htmlentities($string); |
|
203 |
} |
|
204 |
|