1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460:
<?php
function reconfigureAction($mandatory) {
list($diff, $needs) = checkSignature($mandatory);
$diffkeys = array_keys($diff);
if (($mandatory || in_array('ZENPHOTO', $diffkeys) || in_array('FOLDER', $diffkeys))) {
if (isset($_GET['rss'])) {
if (file_exists(SERVERPATH . '/' . DATA_FOLDER . '/rss-closed.xml')) {
$xml = file_get_contents(SERVERPATH . '/' . DATA_FOLDER . '/rss-closed.xml');
$xml = preg_replace('~<pubDate>(.*)</pubDate>~', '<pubDate>' . date("r", time()) . '</pubDate>', $xml);
echo $xml;
}
exit();
}
if (in_array('ZENPHOTO', $diffkeys) || empty($needs)) {
$dir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
$p = strpos($dir, ZENFOLDER);
if ($p !== false) {
$dir = substr($dir, 0, $p);
}
if (OFFSET_PATH) {
$where = 'admin';
} else {
$where = 'gallery';
}
$dir = rtrim($dir, '/');
if (!defined('PROTOCOL')) {
if (secureServer()) {
define('PROTOCOL', 'https');
} else {
define('PROTOCOL', 'http');
}
}
$setup_autorun = $show_errorpage = false;
switch ($mandatory) {
case 1:
$setup_autorun = true;
debuglog(gettext('ZenphotoCMS config file is missing.') . ' ' . gettext('Setup run required.'));
break;
case 2:
$show_errorpage = true;
debuglog(gettext('ZenphotoCMS database credentials are missing.') . ' ' . gettext('Check your config file settings and re-run setup.'));
break;
case 3:
$show_errorpage = true;
debuglog(gettext('ZenphotoCMS database credentials are incomplete or wrong.') . ' ' . gettext('Check your config file settings and re-run setup.'));
break;
}
if ($setup_autorun) {
unprotectSetupFiles();
$location = PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . $dir . "/" . ZENFOLDER . "/setup/index.php?autorun=$where";
redirectURL($location);
} else {
if ($show_errorpage) {
printReconfigureError($mandatory);
} else {
if (zp_loggedin()) {
addReconfigureNote();
}
}
}
} else {
printReconfigureNote($diff, $needs, $mandatory);
}
} else if (!empty($diff)) {
debuglog(gettext('Install signature change detected.') . gettext('Setup run recommended.'));
addReconfigureNote();
}
}
function checkSignature($auto) {
global $_configMutex, $_zp_DB_connection;
if (function_exists('query_full_array') && $_zp_DB_connection) {
$old = @unserialize(getOption('zenphoto_install'));
$new = installSignature();
} else {
$old = NULL;
$new = array();
}
if (!is_array($old)) {
$old = array('ZENPHOTO' => gettext('an unknown release'));
}
$diff = array();
$keys = array_unique(array_merge(array_keys($new), array_keys($old)));
foreach ($keys as $key) {
if (!array_key_exists($key, $new) || !array_key_exists($key, $old) || $old[$key] != $new[$key]) {
$diff[$key] = array('old' => @$old[$key], 'new' => @$new[$key]);
}
}
$package = file_get_contents(SERVERPATH . '/' . ZENFOLDER . '/Zenphoto.package');
preg_match_all('|' . ZENFOLDER . '/setup/(.*)|', $package, $matches);
$needs = array();
foreach ($matches[1] as $need) {
$needs[] = rtrim(trim($need), ":*");
}
$_configMutex->lock();
if (file_exists(SERVERPATH . '/' . ZENFOLDER . '/setup/')) {
$found = isSetupProtected();
if (!empty($found) && $auto && (defined('ADMIN_RIGHTS') && zp_loggedin(ADMIN_RIGHTS))) {
unprotectSetupFiles();
}
$found = safe_glob('*.*');
$needs = array_diff($needs, $found);
}
$_configMutex->unlock();
return array($diff, $needs);
}
function signatureChange($tab = NULL, $subtab = NULL) {
list($diff, $needs) = checkSignature(false);
printReconfigureNote($diff, $needs, 0);
return $tab;
}
function addReconfigureNote() {
if (function_exists('zp_register_filter')) {
zp_register_filter('admin_head', 'reconfigureCSS');
zp_register_filter('admin_note', 'signatureChange');
zp_register_filter('theme_head', 'reconfigureCSS');
zp_register_filter('theme_body_open', 'signatureChange');
}
}
function printReconfigureNote($diff, $needs, $mandatory) {
$notice = getReconfigureNote($diff, $needs, $mandatory);
if (!zp_loggedin()) {
debuglog("Reconfignote hidden on frontend as not loggedin");
debuglogReconfigureNote($notice);
return;
}
?>
<div class="reconfigbox">
<h1><?php echo $notice['headline']; ?></h1>
<div class="reconfig_errors">
<ul>
<?php
foreach ($notice['notes'] as $note) {
?>
<li><?php echo $note; ?></li>
<?php
}
?>
</ul>
</div>
<p>
<?php echo $notice['note_level']; ?>
</p>
<?php
if (zp_loggedin(ADMIN_RIGHTS)) {
if (OFFSET_PATH) {
$where = 'admin';
} else {
$where = 'gallery';
}
$runsetup_link = WEBPATH . '/' . ZENFOLDER . '/setup.php?autorun=' . $where . '&xsrfToken=' . getXSRFToken('setup');
$ignore_link = WEBPATH . '/' . ZENFOLDER . '/admin.php?ignore_setup=1&XSRFToken=' . getXSRFToken('ignore_setup');
?>
<p class="reconfig_links">
<a class="reconfig_link reconfig_link-runsetup" href="<?php echo $runsetup_link; ?>"><?php echo gettext('Run setup'); ?></a>
<a class="reconfig_link reconfig_link-ignore" href="<?php echo $ignore_link; ?>"> <?php echo gettext('Ignore, I know what I am doing!'); ?></a>
</p>
<script>
$(document).ready(function () {
$('.reconfig_link-ignore').click(function (event) {
event.preventDefault();
var link = $('.reconfig_link-ignore').attr('href');
$.ajax(link, {
success: function (data) {
$('.reconfigbox').remove();
}
});
});
});
</script>
<?php
} else {
?>
<p><strong><?php echo gettext("You don't have the rights to run setup. Please contact your site's administrator or login with your administrator user account."); ?></strong></p>
<?php
}
?>
</div>
<?php
}
function getReconfigureNote($diff, $needs, $mandatory) {
$notice['headline'] = gettext('Zenphoto has detected a change in your installation.');
$notice['notes'] = array();
foreach ($diff as $thing => $rslt) {
switch ($thing) {
case 'SERVER_SOFTWARE':
$notice['notes'][] = sprintf(gettext('Your server software has changed from %1$s to %2$s.'), $rslt['old'], $rslt['new']);
break;
case 'DATABASE':
$notice['notes'][] = sprintf(gettext('Your database software has changed from %1$s to %2$s.'), $rslt['old'], $rslt['new']);
break;
case 'ZENPHOTO':
$notice['notes'][] .= sprintf(gettext('Zenphoto %1$s has been copied over %2$s.'), ZENPHOTO_VERSION, $rslt['old']);
break;
case 'FOLDER':
$notice['notes'][] = sprintf(gettext('Your installation has moved from %1$s to %2$s.'), $rslt['old'], $rslt['new']);
break;
default:
$notice['notes'][] = sprintf(gettext('The script <code>%1$s</code> has changed.'), $thing);
break;
}
}
if (array_key_exists('ZENPHOTO', $diff) || array_key_exists('FOLDER', $diff)) {
$notice['note_level'] = gettext('The change detected is critical. You <strong>must</strong> run setup for your site to function.');
} else {
$notice['note_level'] = gettext('The change detected may not be critical but you should run setup at your earliest convenience.');
}
return $notice;
}
function printReconfigureError($mandatory) {
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service Temporarily Unavailable");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title><?php echo gettext('A configuration error occurred.'); ?></title>
<style>
.siterror {
font-family: sans-serif;
max-width: 500px;
padding: 20px;
border: 1px solid red;
margin: 0 auto;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="siterror">
<p><strong><?php echo gettext('A configuration error occurred.'); ?></strong></p>
<p><?php echo gettext('Please return later.'); ?></p>
</div>
</body>
</html>
<?php
exit();
}
function debuglogReconfigureNote($notice) {
debuglog($notice['headline']);
foreach ($notice['notes'] as $note) {
debuglog($note);
}
debuglog($notice['note_level']);
}
function ignoreSetupRunRequest() {
if (isset($_GET['ignore_setup']) && zp_loggedin(ADMIN_RIGHTS)) {
XSRFdefender('ignore_setup');
purgeOption('zenphoto_install');
setOption('zenphoto_install', serialize(installSignature()));
zp_apply_filter('log_setup', true, 'ignore_setup', gettext('Setup re-run ignored by admin request.'));
exitZP();
}
}
function isSetupProtected() {
if (file_exists(SERVERPATH . '/' . ZENFOLDER . '/setup/')) {
chdir(SERVERPATH . '/' . ZENFOLDER . '/setup/');
$found = safe_glob('*.xxx');
return $found;
}
return array();
}
function unprotectSetupFiles() {
$found = isSetupProtected();
if ($found) {
foreach ($found as $script) {
if (!defined('FILE_MOD')) {
define('FILE_MOD', 0666);
}
chmod($script, 0777);
if (@rename($script, stripSuffix($script))) {
chmod(stripSuffix($script), FILE_MOD);
} else {
chmod($script, FILE_MOD);
}
}
}
}
function protectSetupFiles() {
chdir(SERVERPATH . '/' . ZENFOLDER . '/setup/');
$list = safe_glob('*.php');
if (!empty($list)) {
$rslt = array();
foreach ($list as $component) {
@chmod(SERVERPATH . '/' . ZENFOLDER . '/setup/' . $component, 0777);
if (@rename(SERVERPATH . '/' . ZENFOLDER . '/setup/' . $component, SERVERPATH . '/' . ZENFOLDER . '/setup/' . $component . '.xxx')) {
@chmod(SERVERPATH . '/' . ZENFOLDER . '/setup/' . $component . '.xxx', FILE_MOD);
} else {
@chmod(SERVERPATH . '/' . ZENFOLDER . '/setup/' . $component, FILE_MOD);
$rslt[] = '../setup/' . $component;
}
}
zp_apply_filter('log_setup', true, 'protect', gettext('protected'));
}
}
function reconfigureCSS() {
?>
<style type="text/css">
.reconfigbox {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 5px 10px 5px 10px;
background-color:
border-width: 1px 1px 2px 1px;
border-color:
border-style: solid;
margin-bottom: 10px;
font-size: 1em;
line-height: 1.6em;
-moz-border-radius: 5px;
-khtml-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
text-align: left;
}
.successbox {
background-color: green;
}
.reconfigbox h1,.notebox strong {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
color:
font-size: 1.6em;
font-weight: bold;
margin-bottom: 1em;
}
.reconfigbox code {
font-weight: bold;
}
.reconfig_links:after {
content: " " !important;
display: table !important;
clear: both !important;
}
.reconfigbox .reconfig_link {
display: inline-block;
padding: 5px 8px 5px 8px;
border: 0;
background: white;
margin: 0 10px 0px 0;
}
.reconfig_link-runsetup {
font-weight: bold;
border: 1px solid darkgray !important;
}
.reconfig_link-ignore {
display: block;
float: right;
}
list-style-type: square;
}
</style>
<?php
}