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: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562:
<?php
if (!defined('SMF'))
die('No direct access...');
function getServerVersions($checkFor)
{
global $txt, $db_connection, $_PHPA, $smcFunc, $cache_accelerator, $cache_memcached, $cacheAPI, $modSettings;
loadLanguage('Admin');
$versions = array();
if (in_array('gd', $checkFor) && function_exists('gd_info'))
{
$temp = gd_info();
$versions['gd'] = array('title' => $txt['support_versions_gd'], 'version' => $temp['GD Version']);
}
if (in_array('imagemagick', $checkFor) && (class_exists('Imagick') || function_exists('MagickGetVersionString')))
{
if (class_exists('Imagick'))
{
$temp = New Imagick;
$temp2 = $temp->getVersion();
$im_version = $temp2['versionString'];
$extension_version = 'Imagick ' . phpversion('Imagick');
}
else
{
$im_version = MagickGetVersionString();
$extension_version = 'MagickWand ' . phpversion('MagickWand');
}
$im_version = str_replace(array('ImageMagick ', ' https://www.imagemagick.org'), '', $im_version);
$versions['imagemagick'] = array('title' => $txt['support_versions_imagemagick'], 'version' => $im_version . ' (' . $extension_version . ')');
}
if (in_array('db_server', $checkFor))
{
db_extend();
if (!isset($db_connection) || $db_connection === false)
trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
else
{
$versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => '');
$versions['db_engine']['version'] = $smcFunc['db_get_vendor']();
$versions['db_server'] = array('title' => sprintf($txt['support_versions_db'], $smcFunc['db_title']), 'version' => '');
$versions['db_server']['version'] = $smcFunc['db_get_version']();
}
}
$memcache_version = '???';
if (!empty($cache_accelerator) && ($cache_accelerator == 'memcached' || $cache_accelerator == 'memcache') && !empty($cache_memcached) && !empty($cacheAPI))
$memcache_version = $cacheAPI->getVersion();
if (in_array('phpa', $checkFor) && isset($_PHPA))
$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
if (in_array('apc', $checkFor) && extension_loaded('apc'))
$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
if (in_array('memcache', $checkFor) && function_exists('memcache_set'))
$versions['memcache'] = array('title' => 'Memcached', 'version' => $memcache_version);
if (in_array('xcache', $checkFor) && function_exists('xcache_set'))
$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
if (in_array('php', $checkFor))
$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
if (in_array('server', $checkFor))
$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
return $versions;
}
function getFileVersions(&$versionOptions)
{
global $boarddir, $sourcedir, $settings, $tasksdir;
$lang_dir = $settings['default_theme_dir'] . '/languages';
$version_info = array(
'file_versions' => array(),
'default_template_versions' => array(),
'template_versions' => array(),
'default_language_versions' => array(),
'tasks_versions' => array(),
);
if (!empty($versionOptions['include_ssi']) && file_exists($boarddir . '/SSI.php'))
{
$fp = fopen($boarddir . '/SSI.php', 'rb');
$header = fread($fp, 4096);
fclose($fp);
if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
$version_info['file_versions']['SSI.php'] = $match[1];
else
$version_info['file_versions']['SSI.php'] = '??';
}
if (!empty($versionOptions['include_subscriptions']) && file_exists($boarddir . '/subscriptions.php'))
{
$fp = fopen($boarddir . '/subscriptions.php', 'rb');
$header = fread($fp, 4096);
fclose($fp);
if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
$version_info['file_versions']['subscriptions.php'] = $match[1];
else
$version_info['file_versions']['subscriptions.php'] = '??';
}
$sources_dir = dir($sourcedir);
while ($entry = $sources_dir->read())
{
if (substr($entry, -4) === '.php' && !is_dir($sourcedir . '/' . $entry) && $entry !== 'index.php')
{
$fp = fopen($sourcedir . '/' . $entry, 'rb');
$header = fread($fp, 4096);
fclose($fp);
if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
$version_info['file_versions'][$entry] = $match[1];
else
$version_info['file_versions'][$entry] = '??';
}
}
$sources_dir->close();
if (!empty($versionOptions['include_tasks']))
{
$tasks_dir = dir($tasksdir);
while ($entry = $tasks_dir->read())
{
if (substr($entry, -4) === '.php' && !is_dir($tasksdir . '/' . $entry) && $entry !== 'index.php')
{
$fp = fopen($tasksdir . '/' . $entry, 'rb');
$header = fread($fp, 4096);
fclose($fp);
if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
$version_info['tasks_versions'][$entry] = $match[1];
else
$version_info['tasks_versions'][$entry] = '??';
}
}
$tasks_dir->close();
}
$directories = array('default_template_versions' => $settings['default_theme_dir']);
if ($settings['theme_id'] != 1)
$directories += array('template_versions' => $settings['theme_dir']);
foreach ($directories as $type => $dirname)
{
$this_dir = dir($dirname);
while ($entry = $this_dir->read())
{
if (substr($entry, -12) == 'template.php' && !is_dir($dirname . '/' . $entry))
{
$fp = fopen($dirname . '/' . $entry, 'rb');
$header = fread($fp, 768);
fclose($fp);
if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
$version_info[$type][$entry] = $match[1];
else
$version_info[$type][$entry] = '??';
}
}
$this_dir->close();
}
$this_dir = dir($lang_dir);
while ($entry = $this_dir->read())
{
if (substr($entry, -4) == '.php' && $entry != 'index.php' && !is_dir($lang_dir . '/' . $entry))
{
$fp = fopen($lang_dir . '/' . $entry, 'rb');
$header = fread($fp, 768);
fclose($fp);
list ($name, $language) = explode('.', $entry);
if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1)
$version_info['default_language_versions'][$language][$name] = $match[1];
else
$version_info['default_language_versions'][$language][$name] = '??';
}
}
$this_dir->close();
if (!empty($versionOptions['sort_results']))
{
ksort($version_info['file_versions']);
ksort($version_info['default_template_versions']);
ksort($version_info['template_versions']);
ksort($version_info['default_language_versions']);
ksort($version_info['tasks_versions']);
foreach ($version_info['default_language_versions'] as $language => $dummy)
ksort($version_info['default_language_versions'][$language]);
}
return $version_info;
}
function updateSettingsFile($config_vars)
{
global $boarddir, $cachedir, $context;
if (count($config_vars) === 1 && isset($config_vars['db_last_error']))
{
updateDbLastError($config_vars['db_last_error']);
return;
}
$last_settings_change = filemtime($boarddir . '/Settings.php');
$settingsArray = trim(file_get_contents($boarddir . '/Settings.php'));
if (strpos($settingsArray, "\n") !== false)
$settingsArray = explode("\n", $settingsArray);
elseif (strpos($settingsArray, "\r") !== false)
$settingsArray = explode("\r", $settingsArray);
else
return;
if (count($settingsArray) < 10)
return;
foreach ($settingsArray as $k => $dummy)
$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
{
if (substr($settingsArray[$i], 0, 1) != '$')
continue;
$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
foreach ($config_vars as $var => $val)
{
if ($var === 'db_last_error')
{
updateDbLastError($val);
unset($config_vars[$var]);
}
elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
{
$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
unset($config_vars[$var]);
}
}
if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
$end = $i;
}
if (empty($end) || $end < 10)
$end = count($settingsArray) - 1;
if (!empty($config_vars))
{
if (trim($settingsArray[$end]) == '?' . '>')
$settingsArray[$end++] = '';
else
$end++;
foreach ($config_vars as $var => $val)
$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
$settingsArray[$end] = '?' . '>';
}
else
$settingsArray[$end] = trim($settingsArray[$end]);
if (count($settingsArray) < 12)
return;
if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
$cachedir = $boarddir . '/cache';
$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
if ($test_fp)
{
fclose($test_fp);
$written_bytes = file_put_contents($cachedir . '/settings_update.tmp', 'test', LOCK_EX);
@unlink($cachedir . '/settings_update.tmp');
if ($written_bytes !== 4)
{
return;
}
}
clearstatcache();
if (filemtime($boarddir . '/Settings.php') === $last_settings_change)
{
$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
$settings_backup_fail = !$settings_backup_fail ? (!file_exists($boarddir . '/Settings_bak.php') || filesize($boarddir . '/Settings_bak.php') === 0) : $settings_backup_fail;
$write_settings = implode('', $settingsArray);
$written_bytes = file_put_contents($boarddir . '/Settings.php', $write_settings, LOCK_EX);
if ($written_bytes !== strlen($write_settings) && !$settings_backup_fail)
{
$context['settings_message'] = 'settings_error';
if (file_exists($boarddir . '/Settings_bak.php'))
@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
}
}
if (function_exists('opcache_invalidate'))
opcache_invalidate($boarddir . '/Settings.php', true);
}
function updateDbLastError($time)
{
global $boarddir, $cachedir;
file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = ' . $time . ';' . "\n" . '?' . '>', LOCK_EX);
@touch($boarddir . '/' . 'Settings.php');
}
function updateAdminPreferences()
{
global $options, $context, $smcFunc, $settings, $user_info;
if (!isset($context['admin_preferences']))
return false;
$options['admin_preferences'] = $smcFunc['json_encode']($context['admin_preferences']);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}themes
WHERE id_theme != {int:default_theme}
AND variable = {string:admin_preferences}',
array(
'default_theme' => 1,
'admin_preferences' => 'admin_preferences',
)
);
$smcFunc['db_insert']('replace',
'{db_prefix}themes',
array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
array($user_info['id'], 1, 'admin_preferences', $options['admin_preferences']),
array('id_member', 'id_theme', 'variable')
);
cache_put_data('theme_settings-' . $settings['theme_id'] . ':' . $user_info['id'], null, 0);
}
function emailAdmins($template, $replacements = array(), $additional_recipients = array())
{
global $smcFunc, $sourcedir, $language, $modSettings;
require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/Subs-Members.php');
$members = membersAllowedTo('admin_forum');
require_once($sourcedir . '/Subs-Notify.php');
$prefs = getNotifyPrefs($members, 'announcements', true);
$request = $smcFunc['db_query']('', '
SELECT id_member, member_name, real_name, lngfile, email_address
FROM {db_prefix}members
WHERE id_member IN({array_int:members})',
array(
'members' => $members,
)
);
$emails_sent = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (empty($prefs[$row['id_member']]['announcements']))
continue;
$replacements['IDMEMBER'] = $row['id_member'];
$replacements['REALNAME'] = $row['member_name'];
$replacements['USERNAME'] = $row['real_name'];
$emaildata = loadEmailTemplate($template, $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, $template, $emaildata['is_html'], 1);
$emails_sent[] = $row['email_address'];
}
$smcFunc['db_free_result']($request);
if (!empty($additional_recipients))
foreach ($additional_recipients as $recipient)
{
if (in_array($recipient['email'], $emails_sent))
continue;
$replacements['IDMEMBER'] = $recipient['id'];
$replacements['REALNAME'] = $recipient['name'];
$replacements['USERNAME'] = $recipient['name'];
$emaildata = loadEmailTemplate($template, $replacements, empty($recipient['lang']) || empty($modSettings['userLanguage']) ? $language : $recipient['lang']);
sendmail($recipient['email'], $emaildata['subject'], $emaildata['body'], null, $template, $emaildata['is_html'], 1);
}
}
?>