| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
Elgg admin panel |
|---|
| 6 |
Main library |
|---|
| 7 |
|
|---|
| 8 |
*/ |
|---|
| 9 |
|
|---|
| 10 |
// We want to load the config file whenever we can |
|---|
| 11 |
require_once("config.php"); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
function elggadmin_init() { |
|---|
| 15 |
global $CFG, $ADMINCFG, $messages; |
|---|
| 16 |
|
|---|
| 17 |
if (file_exists($ADMINCFG->admin->elggdir . $ADMINCFG->admin->configfile)) { |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
// Load Elgg configuration |
|---|
| 22 |
global $CFG; |
|---|
| 23 |
require_once($ADMINCFG->admin->elggdir . $ADMINCFG->admin->configfile); |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
session_name("elggadmin"); |
|---|
| 27 |
session_start(); |
|---|
| 28 |
|
|---|
| 29 |
if (isset($_SESSION['messages'])) { |
|---|
| 30 |
$messages = $_SESSION['messages']; |
|---|
| 31 |
$_SESSION['messages'] = ""; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
if (empty($CFG->templatesroot)) { |
|---|
| 36 |
$CFG->templatesroot = $CFG->dirroot . "mod/template/templates/"; |
|---|
| 37 |
} |
|---|
| 38 |
if (!isset($CFG->profilelocation)) { |
|---|
| 39 |
$CFG->profilelocation = $CFG->dirroot . "mod/profile/"; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
elggadmin_actions(); |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
if (!elggadmin_isloggedin()) { |
|---|
| 47 |
|
|---|
| 48 |
elggadmin_header(); |
|---|
| 49 |
elggadmin_begin_content(); |
|---|
| 50 |
elggadmin_loginbox(); |
|---|
| 51 |
elggadmin_end_content(); |
|---|
| 52 |
elggadmin_footer(); |
|---|
| 53 |
exit; |
|---|
| 54 |
|
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
} else { |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
// Load Elgg configuration |
|---|
| 61 |
global $CFG, $messages; |
|---|
| 62 |
require_once($ADMINCFG->admin->elggdir . "config-dist.php"); |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
session_name("elggadmin"); |
|---|
| 66 |
session_start(); |
|---|
| 67 |
|
|---|
| 68 |
if (isset($_SESSION['messages'])) { |
|---|
| 69 |
$messages = $_SESSION['messages']; |
|---|
| 70 |
$_SESSION['messages'] = ""; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
if (empty($CFG->dirroot)) { |
|---|
| 75 |
$CFG->dirroot = str_replace("//","/",str_replace("_elggadmin","",str_replace("\\","/",dirname(__FILE__)))); |
|---|
| 76 |
} |
|---|
| 77 |
if (empty($CFG->wwwroot) || $CFG->wwwroot == "http://") { |
|---|
| 78 |
$CFG->wwwroot = "http://" . str_replace("index.php","",str_replace("_elggadmin/","",$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'])); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
if (!isset($CFG->templatesroot)) { |
|---|
| 83 |
$CFG->templatesroot = $CFG->dirroot . "mod/template/templates/"; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
if (!isset($CFG->profilelocation)) { |
|---|
| 87 |
$CFG->profilelocation = $CFG->dirroot . "mod/profile/"; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
elggadmin_actions(); |
|---|
| 92 |
|
|---|
| 93 |
$messages[] = <<< END |
|---|
| 94 |
|
|---|
| 95 |
<h2>Welcome to the Elgg installer!</h2> |
|---|
| 96 |
<p>Fill in the details below, click 'Save' at the bottom, and your Elgg installation will be ready to go. |
|---|
| 97 |
Don't worry if you don't know all the details: the really important settings (the ones Elgg won't work without) |
|---|
| 98 |
are highlighted in red for you, and you can come back at any time by visiting {$CFG->wwwroot}_elggadmin.</p> |
|---|
| 99 |
<p>It's possible this installer hasn't been given permission to save files to your Elgg installation directory |
|---|
| 100 |
by the server. If that's the case, we'll give you a copy of the config.php file, and you'll need to upload it |
|---|
| 101 |
to your installation directory by hand.</p> |
|---|
| 102 |
<p>Of course, if you like to get your hands dirty, you can also set these values by copying config-dist.php to config.php |
|---|
| 103 |
in your Elgg installation folder and editing it by hand in your text editor of choice.</p> |
|---|
| 104 |
|
|---|
| 105 |
END; |
|---|
| 106 |
|
|---|
| 107 |
} |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
function elggadmin_actions() { |
|---|
| 111 |
|
|---|
| 112 |
global $CFG, $ADMINCFG, $messages; |
|---|
| 113 |
|
|---|
| 114 |
if (isset($_REQUEST['action'])) { |
|---|
| 115 |
$action = $_REQUEST['action']; |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
switch($action) { |
|---|
| 119 |
|
|---|
| 120 |
case "admin:login": |
|---|
| 121 |
elggadmin_checklogins(); |
|---|
| 122 |
break; |
|---|
| 123 |
case "config:save": |
|---|
| 124 |
elggadmin_config_save(); |
|---|
| 125 |
break; |
|---|
| 126 |
case "theme:save": |
|---|
| 127 |
elggadmin_save_template(); |
|---|
| 128 |
break; |
|---|
| 129 |
case "frontpage:save": |
|---|
| 130 |
elggadmin_save_frontpage(); |
|---|
| 131 |
break; |
|---|
| 132 |
case "theme:backup:save": |
|---|
| 133 |
elggadmin_make_backup(); |
|---|
| 134 |
$_SESSION['messages'] = $messages; |
|---|
| 135 |
header("Location: theme.php"); |
|---|
| 136 |
exit; |
|---|
| 137 |
break; |
|---|
| 138 |
case "theme:backup:restore": |
|---|
| 139 |
elggadmin_restore_backup(); |
|---|
| 140 |
$_SESSION['messages'] = $messages; |
|---|
| 141 |
header("Location: theme.php"); |
|---|
| 142 |
exit; |
|---|
| 143 |
break; |
|---|
| 144 |
|
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
function elggadmin_checklogins() { |
|---|
| 150 |
|
|---|
| 151 |
global $CFG, $ADMINCFG, $messages; |
|---|
| 152 |
|
|---|
| 153 |
$username = ""; |
|---|
| 154 |
$password = ""; |
|---|
| 155 |
|
|---|
| 156 |
if (isset($_REQUEST['adminuser'])) { |
|---|
| 157 |
$username = $_REQUEST['adminuser']; |
|---|
| 158 |
} |
|---|
| 159 |
if (isset($_REQUEST['adminpassword'])) { |
|---|
| 160 |
$password = $_REQUEST['adminpassword']; |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
if (!empty($username) && !empty($password) |
|---|
| 164 |
&& !empty($CFG->adminuser) && !empty($CFG->adminpassword) ) { |
|---|
| 165 |
|
|---|
| 166 |
if ($username == $CFG->adminuser |
|---|
| 167 |
&& $password = $CFG->adminpassword) { |
|---|
| 168 |
|
|---|
| 169 |
$_SESSION['adminid'] = 1; |
|---|
| 170 |
$_SESSION['admincode'] = md5($CFG->adminuser . $CFG->adminpassword); |
|---|
| 171 |
$messages[] = ("You logged in."); |
|---|
| 172 |
$_SESSION['messages'] = $messages; |
|---|
| 173 |
header("Location: index.php"); |
|---|
| 174 |
exit; |
|---|
| 175 |
|
|---|
| 176 |
} else { |
|---|
| 177 |
$messages[] = ("The username and password you specified did not match the admin details for this system."); |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
function elggadmin_config_init() { |
|---|
| 187 |
|
|---|
| 188 |
global $CFG, $PARSEDCFG, $ADMINCFG, $DEFCFG, $messages; |
|---|
| 189 |
|
|---|
| 190 |
if (!isset($PARSEDCFG)) { |
|---|
| 191 |
|
|---|
| 192 |
$PARSEDCFG = new stdClass(); |
|---|
| 193 |
|
|---|
| 194 |
foreach(get_object_vars($CFG) as $key => $value) { |
|---|
| 195 |
$PARSEDCFG->$key = addslashes($value); |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
include("configdef.php"); |
|---|
| 201 |
$ADMINCFG->config = $DEFCFG->config; |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
function elggadmin_config_main() { |
|---|
| 208 |
|
|---|
| 209 |
global $CFG, $PARSEDCFG, $ADMINCFG, $messages, $DEFCFG; |
|---|
| 210 |
|
|---|
| 211 |
require_once("configdef.php"); |
|---|
| 212 |
|
|---|
| 213 |
echo "<form action=\"\" method=\"post\">"; |
|---|
| 214 |
foreach(($DEFCFG->config) as $name => $value) { |
|---|
| 215 |
if (!in_array($name,$ADMINCFG->admin->noedit)) { |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
if (isset($DEFCFG->config[$name]->important) && $DEFCFG->config[$name]->important == true) { |
|---|
| 220 |
echo "<div class=\"important\">"; |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
echo "<p>"; |
|---|
| 224 |
if (isset($ADMINCFG->config[$name]->name)) { |
|---|
| 225 |
echo "<b>" . $ADMINCFG->config[$name]->name . "</b>"; |
|---|
| 226 |
} |
|---|
| 227 |
if (isset($ADMINCFG->config[$name]->description)) { |
|---|
| 228 |
echo "<br /><i>" . $ADMINCFG->config[$name]->description . "</i>"; |
|---|
| 229 |
} |
|---|
| 230 |
echo "</p>\n"; |
|---|
| 231 |
echo "<p>"; |
|---|
| 232 |
|
|---|
| 233 |
if (isset($ADMINCFG->config[$name]->type)) { |
|---|
| 234 |
switch($ADMINCFG->config[$name]->type) { |
|---|
| 235 |
|
|---|
| 236 |
case "requiredstring": |
|---|
| 237 |
case "integer": echo "<input type=\"text\" name=\"$name\" value=\"" . (string) htmlspecialchars($CFG->$name) . "\" />"; |
|---|
| 238 |
break; |
|---|
| 239 |
case "access": |
|---|
| 240 |
$selected = array(); |
|---|
| 241 |
$selected[$CFG->$name] = "selected=\"selected\""; |
|---|
| 242 |
echo "<select name=\"$name\">"; |
|---|
| 243 |
echo "<option value=\"PUBLIC\" {$selected['PUBLIC']}>" . ("Public") . "</option>"; |
|---|
| 244 |
echo "<option value=\"LOGGED_IN\" {$selected['LOGGED_IN']} >" . ("Logged in users only") . "</option>"; |
|---|
| 245 |
echo "<option value=\"PRIVATE\" {$selected['PRIVATE']} >" . ("Private") . "</option>"; |
|---|
| 246 |
echo "</select>"; |
|---|
| 247 |
break; |
|---|
| 248 |
case "boolean": |
|---|
| 249 |
$value = (int) $CFG->$name; |
|---|
| 250 |
$selected = array(); |
|---|
| 251 |
if ($value == "1") { |
|---|
| 252 |
$selected['yes'] = "selected=\"selected\""; |
|---|
| 253 |
} else { |
|---|
| 254 |
$selected['no'] = "selected=\"selected\""; |
|---|
| 255 |
} |
|---|
| 256 |
echo "<select name=\"$name\">"; |
|---|
| 257 |
echo "<option value=\"0\" {$selected['no']}>" . ("No") . "</option>"; |
|---|
| 258 |
echo "<option value=\"1\" {$selected['yes']} >" . ("Yes") . "</option>"; |
|---|
| 259 |
echo "</select>"; |
|---|
| 260 |
break; |
|---|
| 261 |
|
|---|
| 262 |
} |
|---|
| 263 |
} else { |
|---|
| 264 |
echo "<input type=\"text\" name=\"$name\" value=\"" . htmlspecialchars($CFG->$name) . "\" />"; |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
echo "</p>\n"; |
|---|
| 268 |
|
|---|
| 269 |
if (isset($DEFCFG->config[$name]->important) && $DEFCFG->config[$name]->important == true) { |
|---|
| 270 |
echo "</div>"; |
|---|
| 271 |
} |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
echo "<p> </p><p><i>" . ("Click below to save your settings.") . "</i></p>"; |
|---|
| 277 |
echo "<p><input type=\"hidden\" value=\"config:save\" name=\"action\" /><input type=\"submit\" value=\"" . ("Save") . "\" /></p>"; |
|---|
| 278 |
echo "</form>"; |
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
function elggadmin_config_save() { |
|---|
| 283 |
|
|---|
| 284 |
global $CFG, $ADMINCFG, $PARSEDCFG, $DEFCFG, $messages; |
|---|
| 285 |
|
|---|
| 286 |
$oktosave = 1; |
|---|
| 287 |
require_once("configdef.php"); |
|---|
| 288 |
|
|---|
| 289 |
foreach($DEFCFG->config as $name => $value) { |
|---|
| 290 |
|
|---|
| 291 |
if (!in_array($name,$ADMINCFG->admin->noedit)) { |
|---|
| 292 |
if (isset($_REQUEST[$name])) { |
|---|
| 293 |
|
|---|
| 294 |
$CFG->$name = substr($_REQUEST[$name],0,128); |
|---|
| 295 |
if(ini_get("magic_quotes_gpc")) { |
|---|
| 296 |
$CFG->$name = stripslashes($CFG->$name); |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
} |
|---|
| 300 |
} |
|---|
| 301 |
if (isset($DEFCFG->config[$name]->type)) { |
|---|
| 302 |
|
|---|
| 303 |
switch ($DEFCFG->config[$name]->type) { |
|---|
| 304 |
|
|---|
| 305 |
case "int": |
|---|
| 306 |
if (empty($CFG->$name)) { |
|---|
| 307 |
$CFG->$name = "0"; |
|---|
| 308 |
} |
|---|
| 309 |
$CFG->$name = (int) $CFG->$name; |
|---|
| 310 |
break; |
|---|
| 311 |
case "boolean": |
|---|
| 312 |
if (!isset($CFG->$name)) { |
|---|
| 313 |
$CFG->$name = "0"; |
|---|
| 314 |
} |
|---|
| 315 |
$CFG->$name = (int) $CFG->$name; |
|---|
| 316 |
if ($CFG->$name > 1) { |
|---|
| 317 |
$CFG->$name = "1"; |
|---|
| 318 |
} |
|---|
| 319 |
|
|---|
| 320 |
break; |
|---|
| 321 |
case "requiredstring": |
|---|
| 322 |
if (empty($CFG->$name)) { |
|---|
| 323 |
$oktosave = 0; |
|---|
| 324 |
$messages[] = sprintf(("You cannot leave '%s' blank!"),$DEFCFG->config[$name]->name); |
|---|
| 325 |
} |
|---|
| 326 |
break; |
|---|
| 327 |
case "access": |
|---|
| 328 |
if (!in_array($CFG->$name, array("PUBLIC","LOGGED_IN","PRIVATE"))) { |
|---|
| 329 |
$CFG->$name = "PRIVATE"; |
|---|
| 330 |
} |
|---|
| 331 |
break; |
|---|
| 332 |
|
|---|
| 333 |
} |
|---|
| 334 |
} |
|---|
| 335 |
|
|---|
| 336 |
$PARSEDCFG->$name = addslashes($CFG->$name); |
|---|
| 337 |
|
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
if ($oktosave) { |
|---|
| 341 |
|
|---|
| 342 |
$newconfigfile = elggadmin_configstring(); |
|---|
| 343 |
if (!@file_put_contents($ADMINCFG->admin->elggdir . $ADMINCFG->admin->configfile, $newconfigfile)) { |
|---|
| 344 |
$messages[] = sprintf(("We couldn't write your new configuration to your configuration file at %s. Therefore, please copy everything from the textbox below and paste it into a new file called %s in the root of your Elgg installation."),$ADMINCFG->admin->elggdir . $ADMINCFG->admin->configfile,$ADMINCFG->admin->configfile) . "<br />" . "<textarea cols=\"40\" rows=\"6\">" . $newconfigfile . "</textarea>"; |
|---|
| 345 |
} else { |
|---|
| 346 |
$messages[] = ("Your new configuration was saved."); |
|---|
| 347 |
} |
|---|
| 348 |
|
|---|
| 349 |
} |
|---|
| 350 |
|
|---|
| 351 |
$_SESSION['messages'] = $messages; |
|---|
| 352 |
header("Location: index.php"); |
|---|
| 353 |
exit; |
|---|
| 354 |
|
|---|
| 355 |
} |
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
function elggadmin_config_create() { |
|---|
| 359 |
} |
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
// (Essentially a filled-in version of config-dist.php) |
|---|
| 363 |
function elggadmin_configstring() { |
|---|
| 364 |
|
|---|
| 365 |
global $CFG, $PARSEDCFG; |
|---|
| 366 |
|
|---|
| 367 |
include("config-template.php"); |
|---|
| 368 |
|
|---|
| 369 |
$config = str_replace("\\\"","\"",$config); |
|---|
| 370 |
|
|---|
| 371 |
return $config; |
|---|
| 372 |
|
|---|
| 373 |
} |
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
function elggadmin_theme_init() { |
|---|
| 377 |
|
|---|
| 378 |
global $CFG, $messages; |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
if (!is_writable($CFG->templatesroot . "Default_Template/pageshell") |
|---|
| 382 |
|| !is_writable($CFG->templatesroot . "Default_Template/css")) { |
|---|
| 383 |
$messages[] = sprintf(("The administration panel can't write to the theme. You will need to edit your theme files directly or specify that %s is world-writable."),$CFG->templatesroot . "Default_Template/"); |
|---|
| 384 |
} |
|---|
| 385 |
|
|---|
| 386 |
if (file_exists($CFG->dataroot) && |
|---|
| 387 |
(!file_exists($CFG->dataroot . "backuppageshell") || !file_exists($CFG->dataroot . "backupcss")) |
|---|
| 388 |
) { |
|---|
| 389 |
elggadmin_make_backup(); |
|---|
| 390 |
} |
|---|
| 391 |
|
|---|
| 392 |
} |
|---|
| 393 |
|
|---|
| 394 |
|
|---|
| 395 |
function elggadmin_frontpage_init() { |
|---|
| 396 |
|
|---|
| 397 |
global $CFG, $messages; |
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
if (!is_writable($CFG->templatesroot . "Default_Template/frontpage_loggedin") |
|---|
| 401 |
|| !is_writable($CFG->templatesroot . "Default_Template/frontpage_loggedout")) { |
|---|
| 402 |
$messages[] = sprintf(("The administration panel can't write to the front page template. You will need to edit your front page files directly or specify that %s is world-writable."),$CFG->templatesroot . "Default_Template/"); |
|---|
| 403 |
} |
|---|
| 404 |
|
|---|
| 405 |
} |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
function elggadmin_make_backup() { |
|---|
| 409 |
|
|---|
| 410 |
global $CFG, $messages; |
|---|
| 411 |
|
|---|
| 412 |
if (!@copy($CFG->templatesroot . "Default_Template/pageshell", $CFG->dataroot . "backuppageshell")) { |
|---|
| 413 |
$messages[] = ("Could not backup pageshell."); |
|---|
| 414 |
} |
|---|
| 415 |
if (!@copy($CFG->templatesroot . "Default_Template/css", $CFG->dataroot . "backupcss")) { |
|---|
| 416 |
$messages[] = ("Could not backup css."); |
|---|
| 417 |
} |
|---|
| 418 |
|
|---|
| 419 |
} |
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
function elggadmin_restore_backup() { |
|---|
| 423 |
|
|---|
| 424 |
global $CFG, $messages; |
|---|
| 425 |
|
|---|
| 426 |
if (!@copy($CFG->dataroot . "backuppageshell", $CFG->templatesroot . "Default_Template/pageshell")) { |
|---|
| 427 |
$messages[] = ("Could not restore pageshell backup."); |
|---|
| 428 |
} |
|---|
| 429 |
if (!@copy($CFG->dataroot . "backupcss", $CFG->templatesroot . "Default_Template/css")) { |
|---|
| 430 |
$messages[] = ("Could not restore css backup."); |
|---|
| 431 |
} |
|---|
| 432 |
|
|---|
| 433 |
} |
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
function elggadmin_save_template() { |
|---|
| 437 |
|
|---|
| 438 |
global $CFG, $ADMINCFG, $messages; |
|---|
| 439 |
if (isset($_REQUEST['pageshell']) && isset($_REQUEST['css'])) { |
|---|
| 440 |
|
|---|
| 441 |
if (is_writable($CFG->templatesroot . "Default_Template/pageshell") |
|---|
| 442 |
&& is_writable($CFG->templatesroot . "Default_Template/css")) { |
|---|
| 443 |
|
|---|
| 444 |
|
|---|