| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
global $CFG; |
|---|
| 7 |
|
|---|
| 8 |
dirname(__FILE__).'/lib/config-defaults.php'); |
|---|
| 9 |
|
|---|
| 10 |
$CFG->dirroot.'lib/elgglib.php'); |
|---|
| 11 |
$CFG->dirroot.'mod/gettext/lib.php'); |
|---|
| 12 |
|
|---|
| 13 |
$db, $CFG; |
|---|
| 14 |
|
|---|
| 15 |
$version = '0.9'; |
|---|
| 16 |
$messages = array(); |
|---|
| 17 |
$configs = array(); |
|---|
| 18 |
$config_ready = false; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
if (file_exists($CFG->dirroot.'config.php') && config_check_db()) { |
|---|
| 22 |
$config_ready = true; |
|---|
| 23 |
$messages[] = __gettext('You have already configured Elgg and can safely remove the file <code>install.php</code> from your installation.'); |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
config_init(); |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
if (!function_exists('__gettext')) { |
|---|
| 30 |
__gettext($s) { |
|---|
| 31 |
$s; |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
?> |
|---|
| 35 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 36 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 37 |
<head> |
|---|
| 38 |
<title>Elgg <?php echo $version ?> <?php echo __gettext('installation') ?></title> |
|---|
| 39 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
|---|
| 40 |
<style type="text/css" media="all"> |
|---|
| 41 |
/* globals */ |
|---|
| 42 |
|
|---|
| 43 |
body { |
|---|
| 44 |
padding: 0; |
|---|
| 45 |
margin:0; |
|---|
| 46 |
text-align:center; |
|---|
| 47 |
font-family: "Lucida Grande", verdana, arial, helvetica, sans-serif; |
|---|
| 48 |
color: #666; /*333;*/ |
|---|
| 49 |
background: #eee url(mod/template/images/bg2.gif); |
|---|
| 50 |
width:100%; |
|---|
| 51 |
font-size:90%; |
|---|
| 52 |
line-height:1.6em; |
|---|
| 53 |
margin: 0 auto; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
a { |
|---|
| 57 |
color: #7289AF; |
|---|
| 58 |
font-family: "Lucida Grande", verdana, arial, helvetica, sans-serif; |
|---|
| 59 |
font-size:100%; |
|---|
| 60 |
text-decoration: none; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
a:hover { |
|---|
| 64 |
text-decoration: underline; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
p { |
|---|
| 68 |
font-size: 100%; |
|---|
| 69 |
color: #5e5d5c; |
|---|
| 70 |
margin: 0; |
|---|
| 71 |
padding: 5px; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
h1 { |
|---|
| 75 |
margin:0px 0px 15px 0px; |
|---|
| 76 |
padding:0px; |
|---|
| 77 |
font-size:120%; |
|---|
| 78 |
font-weight:900; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
h2 { |
|---|
| 83 |
margin:0px 0px 5px 0px; |
|---|
| 84 |
padding:0px; |
|---|
| 85 |
font-size:100% |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
h3 { |
|---|
| 90 |
margin:0px 0px 5px 0px; |
|---|
| 91 |
padding:0px; |
|---|
| 92 |
font-size:100% |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
h4 { |
|---|
| 96 |
margin:0px 0px 5px 0px; |
|---|
| 97 |
padding:0px; |
|---|
| 98 |
font-size:100% |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
h5 { |
|---|
| 102 |
margin:0px 0px 5px 0px; |
|---|
| 103 |
padding:0px; |
|---|
| 104 |
color:#1181AA; |
|---|
| 105 |
background:#fff; |
|---|
| 106 |
font-size:100% |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
td p { |
|---|
| 110 |
|
|---|
| 111 |
font-size: 0.8em; |
|---|
| 112 |
margin-top: 15px; |
|---|
| 113 |
padding-top: 15px; |
|---|
| 114 |
|
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
blockquote { |
|---|
| 118 |
padding: 0 1pc 1pc 1pc; |
|---|
| 119 |
border: 1px solid #ddd; |
|---|
| 120 |
background-color: #F0F0F0; |
|---|
| 121 |
color:#000; |
|---|
| 122 |
background-image: url("{$CFG->wwwroot}_templates/double-quotes.png"); |
|---|
| 123 |
background-repeat: no-repeat; |
|---|
| 124 |
background-position: -10px -7px; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
.checkbox { |
|---|
| 128 |
background: #fff; |
|---|
| 129 |
border: none; |
|---|
| 130 |
margin: 0; |
|---|
| 131 |
padding: 0; |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
label { |
|---|
| 135 |
margin: 0; |
|---|
| 136 |
padding: 0; |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
input { |
|---|
| 140 |
width: auto; |
|---|
| 141 |
font-size: 1em; |
|---|
| 142 |
line-height: 1.2em; |
|---|
| 143 |
font-weight:normal; |
|---|
| 144 |
padding: 2px 4px; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
textarea { |
|---|
| 148 |
background-color: #FFF; |
|---|
| 149 |
color: #000; |
|---|
| 150 |
border: 1px solid #CCC; |
|---|
| 151 |
font-size: 1em; |
|---|
| 152 |
padding: 3px; |
|---|
| 153 |
margin: 0 0 5px; |
|---|
| 154 |
width:100%; |
|---|
| 155 |
height:360px; |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
.button { |
|---|
| 159 |
padding:2px; |
|---|
| 160 |
font-size:16px; |
|---|
| 161 |
width:50px; |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
.config-form { |
|---|
| 165 |
border: 1px #ddd dotted; |
|---|
| 166 |
margin: 0 auto; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
.form-item { |
|---|
| 170 |
padding: 10px; |
|---|
| 171 |
border-bottom: 1px #ddd dotted; |
|---|
| 172 |
clear:both; |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
.form-item label { |
|---|
| 176 |
float: left; |
|---|
| 177 |
text-align: right; |
|---|
| 178 |
font-weight: bold; |
|---|
| 179 |
width: 220px; |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
.form-item input { |
|---|
| 183 |
width: 150px; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
.form-error { |
|---|
| 187 |
background: #f7dad8; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
code { |
|---|
| 191 |
font-size: 1.2em; |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
.form-item input, |
|---|
| 195 |
.form-item select { |
|---|
| 196 |
margin-left: 10px; |
|---|
| 197 |
border: 1px #ccc solid; |
|---|
| 198 |
background: #eee; |
|---|
| 199 |
color: #333; |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
.form-item input:focus, |
|---|
| 203 |
.form-tiem select:focus { |
|---|
| 204 |
background: #fff; |
|---|
| 205 |
color: #000; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
.form-item span { |
|---|
| 209 |
display: block; |
|---|
| 210 |
font-size: 0.8em; |
|---|
| 211 |
color: #666; |
|---|
| 212 |
padding-top: 5px; |
|---|
| 213 |
padding-left: 230px; |
|---|
| 214 |
line-height: 1.2em; |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
/* |
|---|
| 218 |
Wraps the entire page |
|---|
| 219 |
*/ |
|---|
| 220 |
|
|---|
| 221 |
#container { |
|---|
| 222 |
width: 780px; |
|---|
| 223 |
min-width: 750px; |
|---|
| 224 |
padding:0px; |
|---|
| 225 |
margin:0px; |
|---|
| 226 |
border:1px solid #ccc; |
|---|
| 227 |
background:#fff; |
|---|
| 228 |
margin: 10px auto; |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
/* |
|---|
| 232 |
HEADER |
|---|
| 233 |
*/ |
|---|
| 234 |
|
|---|
| 235 |
#header { |
|---|
| 236 |
width: 100%; |
|---|
| 237 |
background: #fff url(mod/template/images/newelgg.gif) top left no-repeat; |
|---|
| 238 |
color:#1181AA; |
|---|
| 239 |
padding: 0px; |
|---|
| 240 |
margin: 0px; |
|---|
| 241 |
text-align: center; |
|---|
| 242 |
height:80px; |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
#header h1 { |
|---|
| 246 |
padding: 40px 0 0 0; |
|---|
| 247 |
margin: 0; |
|---|
| 248 |
color:#017FBC; |
|---|
| 249 |
font-size:1.4em; |
|---|
| 250 |
text-align: center; |
|---|
| 251 |
font-weight:bold; |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
/* |
|---|
| 255 |
SITE CONTENT WRAPPER |
|---|
| 256 |
*/ |
|---|
| 257 |
|
|---|
| 258 |
#content { |
|---|
| 259 |
margin: 0; |
|---|
| 260 |
padding: 20px; |
|---|
| 261 |
text-align: left; |
|---|
| 262 |
border: 0px solid #ccc; |
|---|
| 263 |
border-top: none; |
|---|
| 264 |
background-color: #fff; |
|---|
| 265 |
color:#000; |
|---|
| 266 |
font-size:90%; |
|---|
| 267 |
min-height:300px; |
|---|
| 268 |
width: 600px; |
|---|
| 269 |
margin: 0 auto; |
|---|
| 270 |
} |
|---|
| 271 |
|
|---|
| 272 |
#content h1 { |
|---|
| 273 |
border-bottom: 1px solid #666; |
|---|
| 274 |
padding:0px; |
|---|
| 275 |
margin:0px; |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
/* |
|---|
| 279 |
FOOTER |
|---|
| 280 |
*/ |
|---|
| 281 |
|
|---|
| 282 |
#footer { |
|---|
| 283 |
text-align: right; |
|---|
| 284 |
padding: 2px 10px; |
|---|
| 285 |
border-top:1px solid #ccc; |
|---|
| 286 |
border-bottom:1px solid #ddd; |
|---|
| 287 |
font-size:0.8em; |
|---|
| 288 |
color: #555; |
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
#footer a:hover { |
|---|
| 292 |
text-decoration:underline; |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
#footer a:link, #footer a:visited { |
|---|
| 296 |
text-align:right; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
/* |
|---|
| 300 |
Important warning messages |
|---|
| 301 |
*/ |
|---|
| 302 |
|
|---|
| 303 |
.important{ |
|---|
| 304 |
background:#F7DAD8; |
|---|
| 305 |
color:#000; |
|---|
| 306 |
} |
|---|
| 307 |
|
|---|
| 308 |
.important p{ |
|---|
| 309 |
} |
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
/* |
|---|
| 313 |
System messages |
|---|
| 314 |
*/ |
|---|
| 315 |
|
|---|
| 316 |
#messages { |
|---|
| 317 |
text-align:left; |
|---|
| 318 |
background:#E7EDF3; |
|---|
| 319 |
border:1px solid #87B2E1; |
|---|
| 320 |
padding:10px; |
|---|
| 321 |
margin:10px; |
|---|
| 322 |
} |
|---|
| 323 |
|
|---|
| 324 |
#messages ul { |
|---|
| 325 |
margin:0; |
|---|
| 326 |
padding:0; |
|---|
| 327 |
} |
|---|
| 328 |
|
|---|
| 329 |
#messages li { |
|---|
| 330 |
list-style:none; |
|---|
| 331 |
} |
|---|
| 332 |
|
|---|
| 333 |
/* |
|---|
| 334 |
MISC |
|---|
| 335 |
*/ |
|---|
| 336 |
|
|---|
| 337 |
.clearall { |
|---|
| 338 |
padding: 0px; |
|---|
| 339 |
clear: both; |
|---|
| 340 |
font-size: 0px; |
|---|
| 341 |
} |
|---|
| 342 |
|
|---|
| 343 |
.continuebutton { |
|---|
| 344 |
text-align: center; |
|---|
| 345 |
margin-top: 20px; |
|---|
| 346 |
font-size: 1em; |
|---|
| 347 |
} |
|---|
| 348 |
|
|---|
| 349 |
.notifyproblem { |
|---|
| 350 |
color: #900; |
|---|
| 351 |
font-size: 1.2em; |
|---|
| 352 |
} |
|---|
| 353 |
|
|---|
| 354 |
.notifysuccess { |
|---|
| 355 |
color: #0b0; |
|---|
| 356 |
font-size: 1.2em; |
|---|
| 357 |
} |
|---|
| 358 |
|
|---|
| 359 |
.setup { |
|---|
| 360 |
color: #ccc; |
|---|
| 361 |
font-size: 0.8em; |
|---|
| 362 |
} |
|---|
| 363 |
|
|---|
| 364 |
hr { |
|---|
| 365 |
background: #ccc; |
|---|
| 366 |
color: #ccc; |
|---|
| 367 |
height: 1px; |
|---|
| 368 |
margin: 0; |
|---|
| 369 |
border: 0; |
|---|
| 370 |
} |
|---|
| 371 |
</style> |
|---|
| 372 |
</head> |
|---|
| 373 |
<body> |
|---|
| 374 |
<div id="container"> |
|---|
| 375 |
|
|---|
| 376 |
<div id="header"> |
|---|
| 377 |
<h1><?php echo __gettext('Welcome to elgg installation') ?></h1> |
|---|
| 378 |
</div><!-- #header --> |
|---|
| 379 |
|
|---|
| 380 |
<div id="content"> |
|---|
| 381 |
|
|---|
| 382 |
<?php show_messages() ?> |
|---|
| 383 |
|
|---|
| 384 |
<?php |
|---|
| 385 |
if (!$config_ready) { |
|---|
| 386 |
|
|---|
| 387 |
if (config_submitted() && config_validate()) { |
|---|
| 388 |
if (config_write_file()) { |
|---|
| 389 |
config_copy_htaccess(); |
|---|
| 390 |
?> |
|---|
| 391 |
<p><?php echo __gettext('Your configuration file has been saved, you can now proceed with the installation.') ?></p> |
|---|
| 392 |
|
|---|
| 393 |
<?php if (is_writable(dirname(__FILE__))) { ?> |
|---|
| 394 |
<p><?php echo __gettext('Please revert your permissions on your <em>elgg directory</em> for more security.') ?></p> |
|---|
| 395 |
<?php } else { ?> |
|---|
| 396 |
<p><?php echo __gettext('Please revert your permissions on <code>config.php</code> for more security.') ?></p> |
|---|
| 397 |
<?php } ?> |
|---|
| 398 |
<div class="setup"> |
|---|
| 399 |
<?php |
|---|
| 400 |
if (!config_check_db()) { |
|---|
| 401 |
echo '<div style="color:#900;">'; |
|---|
| 402 |
echo __gettext('<strong>Error:</strong> Database connection failed, please edit <code>config.php</code> to include the correct values. '); |
|---|
| 403 |
echo '<br />» ' . __gettext('<a href="install.php">Try again installation wizard</a>.'); |
|---|
| 404 |
echo '</div>'; |
|---|
| 405 |
} else { |
|---|
| 406 |
|
|---|
| 407 |
// |
|---|
| 408 |
// reload config |
|---|
| 409 |
include($CFG->dirroot.'config.php'); |
|---|
| 410 |
|
|---|
| 411 |
require_once($CFG->dirroot.'lib/adodb/adodb.inc.php'); |
|---|
| 412 |
|
|---|
| 413 |
$db = &ADONewConnection($CFG->dbtype); |
|---|
| 414 |
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 415 |
@$db->Connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname); |
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
if ($db->databaseType == 'mysql') { |
|---|
| 419 |
$db->Execute('SET NAMES "utf8"'); |
|---|
| 420 |
$db->Execute('SET CHARSET "utf8"'); |
|---|
| 421 |
} elseif ($db->databaseType == 'postgres7') { |
|---|
| 422 |
$db->Execute('SET NAMES "utf8"'); |
|---|
| 423 |
} |
|---|
| 424 |
|
|---|
| 425 |
$METATABLES = $db->Metatables(); |
|---|
| 426 |
$_SESSION['userid'] = -1; |
|---|
| 427 |
|
|---|
| 428 |
// set initial administrator username & password |
|---|
| 429 |
$CFG->newsinitialusername = $_POST['admin']; |
|---|
| 430 |
$CFG->newsinitialpassword = $_POST['adminpw']; |
|---|
| 431 |
$CFG->sysadminemail = $_POST['adminemail']; |
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
$CFG->debug = 8; |
|---|
| 435 |
|
|---|
| 436 |
require_once($CFG->dirroot.'lib/cache/lib.php'); |
|---|
| 437 |
require_once($CFG->dirroot.'lib/constants.php'); |
|---|
| 438 |
require_once($CFG->dirroot.'lib/elgglib.php'); |
|---|
| 439 |
require_once($CFG->dirroot.'lib/datalib.php'); |
|---|
| 440 |
require_once($CFG->dirroot.'lib/userlib.php'); |
|---|
| 441 |
require_once($CFG->dirroot.'lib/dbsetup.php'); |
|---|
| 442 |
} |
|---|
| 443 |
?> |
|---|
| 444 |
</div> |
|---|
| 445 |
|
|---|
| 446 |
<?php } else { ?> |
|---|
| 447 |
<p><?php echo __gettext('Your configuration file is not writable, please copy the following content and save it as <code>config.php</code> inside your elgg installation.') ?></p> |
|---|
| 448 |
|
|---|
| 449 |
<textarea id="config-file" onclick="this.select()"><?php echo config_file() ?></textarea> |
|---|
| 450 |
|
|---|
| 451 |
<?php |
|---|
| 452 |
} |
|---|
| 453 |
print_continue('index.php'); |
|---|
| 454 |
} else { |
|---|
| 455 |
echo config_form(); |
|---|
| 456 |
} |
|---|
| 457 |
} else { |
|---|
| 458 |
print_continue('index.php'); |
|---|
| 459 |
} |
|---|
| 460 |
?> |
|---|
| 461 |
|
|---|
| 462 |
</div><!-- #content --> |
|---|
| 463 |
|
|---|
| 464 |
<div id="footer"> |
|---|
| 465 |
<p>elgg <?php echo $version ?></p> |
|---|
| 466 |
</div> |
|---|
| 467 |
|
|---|
| 468 |
</div><!-- #container --> |
|---|
| 469 |
</body> |
|---|
| 470 |
</html> |
|---|
| 471 |
<?php |
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
function show_messages() { |
|---|
| 477 |
global $messages; |
|---|
| 478 |
if (!empty($messages)) { |
|---|
| 479 |
echo '<div id="messages">'; |
|---|
| 480 |
echo implode('<br />', $messages); |
|---|
| 481 |
echo '</div>'; |
|---|
| 482 |
} |
|---|
| 483 |
} |
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
function config_init() { |
|---|
| 489 |
global $config_ready; |
|---|
| 490 |
global $configs; |
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
foreach ($_POST as $k => $v) { $_POST[$k] = stripslashes(trim($v)); } |
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
if (!isset($_POST['wwwroot'])) { $_POST['wwwroot'] = "http://" . preg_replace("#install\.php.*#","", $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);} |
|---|
| 497 |
if (!isset($_POST['admin'])) { $_POST['admin'] = 'admin'; } |
|---|
| 498 |
if (!isset($_POST['dbtype'])) { $_POST['dbtype'] = 'mysql'; } |
|---|
| 499 |
if (!isset($_POST['dbhost'])) { $_POST['dbhost'] = 'localhost'; } |
|---|
| 500 |
if (!isset($_POST['dbuser'])) { $_POST['dbuser'] = 'elgg'; } |
|---|
| 501 |
if (!isset($_POST['dbpass'])) { $_POST['dbpass'] = ''; } |
|---|
| 502 |
if (!isset($_POST['dbname'])) { $_POST['dbname'] = 'elgg'; } |
|---|
| 503 |
if (!isset($_POST['prefix'])) { $_POST['prefix'] = 'elgg_'; } |
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
$_POST['admin'] = 'news'; |
|---|
| 507 |
|
|---|
| 508 |
$configs = array(); |
|---|
| 509 |
$configs['wwwroot']->name = __gettext('Web root'); |
|---|
| 510 |
$configs['wwwroot']->desc = __gettext('External URL to the site (eg: http://elgg.boston.edu/). *MUST* have a final slash at end.'); |
|---|
| 511 |
$configs['admin']->name = __gettext('Admin username'); |
|---|
| 512 |
$configs['admin']->desc = __gettext('Initial administrator username'); |
|---|
| 513 |
$configs['adminpw']->name = __gettext('Admin password'); |
|---|
| 514 |
$configs['adminpw']->desc = __gettext('Initial administrator password, at least 6 chars.'); |
|---|
| 515 |
$configs['adminemail']->name = __gettext('System email'); |
|---|
| 516 |
$configs['adminemail']->desc = __gettext('Email address for system notifications.'); |
|---|
| 517 |
$configs['dbtype']->name = __gettext('Database type'); |
|---|
| 518 |
$configs['dbtype']->desc = __gettext('PostgreSQL and MySQL supported. But is highly recommended MySQL'); |
|---|
| 519 |
$configs['dbhost']->name = __gettext('Database host'); |
|---|
| 520 |
$configs['dbuser']->name = __gettext('Database username'); |
|---|
| 521 |
$configs['dbpass']->name = __gettext('Database password'); |
|---|
| 522 |
$configs['dbpass']->not_required = true; |
|---|
| 523 |
$configs['dbname']->name = __gettext('Database name'); |
|---|
| 524 |
$configs['prefix']->name = __gettext('Database table prefix'); |
|---|
| 525 |
|
|---|
| 526 |
if (config_submitted()) { config_validate(); } |
|---|
| 527 |
elseif (!$config_ready) { config_check_requirements(); } |
|---|
| 528 |
} |
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
function config_check_db() { |
|---|
| 536 |
global $db, $CFG; |
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
include($CFG->dirroot.'config.php'); |
|---|
| 540 |
|
|---|
| 541 |
require_once($CFG->dirroot.'lib/adodb/adodb.inc.php'); |
|---|
| 542 |
|
|---|
| 543 |
if (empty($CFG->dbhost) || empty($CFG->dbuser) || empty($CFG->dbname)) { |
|---|
| 544 |
$result = false; |
|---|
| 545 |
} else { |
|---|
| 546 |
$db = &ADONewConnection($CFG->dbtype); |
|---|
| 547 |
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 548 |
|
|---|
| 549 |
$result = @$db->Connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname); |
|---|
| 550 |
|
|---|
| 551 |
if (!$result) { |
|---|
| 552 |
unset($db); |
|---|
| 553 |
} |
|---|
| 554 |
} |
|---|
| 555 |
|
|---|
| 556 |
return $result; |
|---|
| 557 |
} |
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 |
|
|---|
| 564 |
function config_check_requirements() { |
|---|
| 565 |
global $messages, $CFG; |
|---|
| 566 |
|
|---|
| 567 |
if (!extension_loaded('mysql')) { |
|---|
| 568 |
$messages[] = __gettext('<strong>Warning:</strong> Your system does not support <code>mysql</code>.'); |
|---|
| 569 |
} |
|---|
| 570 |
|
|---|
| 571 |
if (!extension_loaded('pgsql')) { |
|---|
| 572 |
$messages[] = __gettext('<strong>Warning:</strong> Your system does not support <code>pgsql</code>.'); |
|---|
| 573 |
} |
|---|
| 574 |
|
|---|
| 575 |
if (file_exists($CFG->dirroot . 'config.php')) { |
|---|
| 576 |
if (!is_writable($CFG->dirroot . 'config.php')) { |
|---|
| 577 |
$messages[] = __gettext("<strong>Error:</strong> please make sure the file <code>{$CFG->dirroot}config.php</code> is writable in order to save your configuration."); |
|---|
| 578 |
} |
|---|
| 579 |
} elseif (!is_writable($CFG->dirroot)) { |
|---|
| 580 |
$messages[] = __gettext("<strong>Error:</strong> please make sure the install directory <code>{$CFG->dirroot}</code> is writable in order to save your configuration."); |
|---|
| 581 |
} |
|---|
| 582 |
|
|---|
| 583 |
if (!is_writable($CFG->dataroot)) { |
|---|
| 584 |
$messages[] = __gettext("<strong>Error:</strong> please make sure the elgg data directory <code>{$CFG->dataroot}</code> is writable."); |
|---|
| 585 |
} |
|---|
| 586 |
|
|---|
| 587 |
if (!empty($messages)) { |
|---|
| 588 |
|
|---|
| 589 |
$messages[] = '» <a href="install.php">Check again</a>'; |
|---|
| 590 |
} |
|---|
| 591 |
} |
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
function config_input($name) { |
|---|
| 601 |
switch ($name) { |
|---|
| 602 |
case 'dbtype': |
|---|
| 603 |
$output = "<select name=\"{$name}\">"; |
|---|
| 604 |
foreach (array('mysql', 'postgres7') as $dbtype) { |
|---|
| 605 |
if ($dbtype == $_POST['dbtype']) $selected = 'selected="selected"'; |
|---|
| 606 |
else $selected = ''; |
|---|
| 607 |
|
|---|
| 608 |
$output .= "<option value=\"{$dbtype}\" {$selected}>{$dbtype}</option>"; |
|---|
| 609 |
} |
|---|
| 610 |
$output .= "</select>"; |
|---|
| 611 |
break; |
|---|
| 612 |
|
|---|
| 613 |
case 'admin': |
|---|
| 614 |
$output = "<input type=\"text\" name=\"{$name}\" value=\"{$_POST[$name]}\" disabled=\"disabled\" />"; |
|---|
| 615 |
break; |
|---|
| 616 |
|
|---|
| 617 |
case 'adminpw': |
|---|
| 618 |
case 'dbpass': |
|---|
| 619 |
$output = "<input type=\"password\" name=\"{$name}\" value=\"\" />"; |
|---|
| 620 |
break; |
|---|
| 621 |
|
|---|
| 622 |
default: |
|---|
| 623 |
$output = "<input type=\"text\" name=\"{$name}\" value=\"{$_POST[$name]}\" />"; |
|---|
| 624 |
break; |
|---|
| 625 |
} |
|---|
| 626 |
|
|---|
| 627 |
return $output; |
|---|
| 628 |
} |
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 |
|
|---|
| 632 |
|
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
function config_form() { |
|---|
| 636 |
global $configs; |
|---|
| 637 |
|
|---|
| 638 |
$output = '<form class="config-form" action="" method="post">'; |
|---|
| 639 |
|
|---|
| 640 |
foreach ($configs as $k => $c) { |
|---|
| 641 |
$label = $c->name . ': '; |
|---|
| 642 |
$label .= empty($c->not_required) ? '*' : ' '; |
|---|
| 643 |
|
|---|
| 644 |
$extraclass = empty($c->error) ? '' : ' form-error'; |
|---|
| 645 |
|
|---|
| 646 |
$output .= "<div class=\"form-item{$extraclass}\">"; |
|---|
| 647 |
$output .= "<label>{$label}</label>"; |
|---|
| 648 |
$output .= config_input($k); |
|---|
| 649 |
$output .= "<span>{$c->desc}</span>"; |
|---|
| 650 |
$output .= '</div>'; |
|---|
| 651 |
} |
|---|
| 652 |
|
|---|
| 653 |
$output .= '<p class="continuebutton"><input type="submit" name="submit" value="' . __gettext('Write config') .'" /></p>'; |
|---|
| 654 |
$output .= '</form>'; |
|---|
| 655 |
|
|---|
| 656 |
return $output; |
|---|
| 657 |
} |
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 |
function config_submitted() { |
|---|
| 664 |
return isset($_POST['submit']); |
|---|
| 665 |
} |
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
function config_validate() { |
|---|
| 672 |
global $messages; |
|---|
| 673 |
global $configs; |
|---|
| 674 |
|
|---|
| 675 |
static $result; |
|---|
| 676 |
|
|---|
| 677 |
if (isset($result)) { |
|---|
| 678 |
return $result; |
|---|
| 679 |
} |
|---|
| 680 |
|
|---|
| 681 |
|
|---|
| 682 |
$urlregex = '#^https?://[\w\.-]+(:\d+)?([\w-_~\./()\#@%;$\+=\\\|&]*)?/$#i'; |
|---|
| 683 |
$hostregex = '#^[\w\.-]+(:\d+)?$#'; |
|---|
| 684 |
|
|---|
| 685 |
if (!preg_match($urlregex, $_POST['wwwroot'])) { |
|---|
| 686 |
$messages[] = __gettext('<strong>Error:</strong> Web root incorrect, please enter a valid url.'); |
|---|
| 687 |
$configs['wwwroot']->error = true; |
|---|
| 688 |
} |
|---|
| 689 |
|
|---|
| 690 |
if (!validate_username($_POST['admin'])) { |
|---|
| 691 |
$messages[] = __gettext('<strong>Error:</strong> Invalid administrator username, please try again.'); |
|---|
| 692 |
$configs['admin']->error = true; |
|---|
| 693 |
} |
|---|
| 694 |
|
|---|
| 695 |
if (empty($_POST['adminpw']) || strlen($_POST['adminpw']) < 6) { |
|---|
| 696 |
$messages[] = __gettext('<strong>Error:</strong> Invalid administrator password. Please enter at least 6 chars.'); |
|---|
| 697 |
$configs['adminpw']->error = true; |
|---|
| 698 |
} |
|---|
| 699 |
|
|---|
| 700 |
if (!validate_email($_POST['adminemail'])) { |
|---|
| 701 |
$messages[] = __gettext('<strong>Error:</strong> Invalid administrator email, please enter a valid email address.'); |
|---|
| 702 |
$configs['adminemail']->error = true; |
|---|
| 703 |
} |
|---|
| 704 |
|
|---|
| 705 |
if (!in_array($_POST['dbtype'], array('mysql', 'postgres7'))) { |
|---|
| 706 |
$messages[] = __gettext('<strong>Error:</strong> Database type unknown.'); |
|---|
| 707 |
$configs['dbtype']->error = true; |
|---|
| 708 |
} elseif (function_exists('extension_loaded')) { |
|---|
| 709 |
if ($_POST['dbtype'] == 'mysql' && !extension_loaded('mysql')) { |
|---|
| 710 |
$messages[] = __gettext('<strong>Error:</strong> Database type <em>(mysql)</em> not supported on your system.'); |
|---|
| 711 |
$configs['dbtype']->error = true; |
|---|
| 712 |
} elseif ($_POST['dbtype'] == 'postgres7' && !extension_loaded('pgsql')) { |
|---|
| 713 |
$messages[] = __gettext('<strong>Error:</strong> Database type <em>(postgresql)</em> not supported on your system.'); |
|---|
| 714 |
$configs['dbtype']->error = true; |
|---|
| 715 |
} |
|---|
| 716 |
} |
|---|
| 717 |
|
|---|
| 718 |
if (!preg_match($hostregex, $_POST['dbhost'])) { |
|---|
| 719 |
$messages[] = __gettext('<strong>Error:</strong> Database host invalid.'); |
|---|
| 720 |
$configs['dbhost']->error = true; |
|---|
| 721< |
|---|