Esempio n. 1
0
function getServerVersions($checkFor)
{
    global $txt, $db_connection, $_PHPA, $smcFunc, $memcached, $modSettings;
    loadLanguage('Admin');
    $versions = array();
    // Is GD available?  If it is, we should show version information for it too.
    if (in_array('gd', $checkFor) && function_exists('gd_info')) {
        $temp = gd_info();
        $versions['gd'] = array('title' => $txt['support_versions_gd'], 'version' => $temp['GD Version']);
    }
    // Now lets check for the Database.
    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_server'] = array('title' => sprintf($txt['support_versions_db'], $smcFunc['db_title']), 'version' => '');
            $versions['db_server']['version'] = $smcFunc['db_get_version']();
        }
    }
    // If we're using memcache we need the server info.
    if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
        get_memcached_server();
    }
    // Check to see if we have any accelerators installed...
    if (in_array('mmcache', $checkFor) && defined('MMCACHE_VERSION')) {
        $versions['mmcache'] = array('title' => 'Turck MMCache', 'version' => MMCACHE_VERSION);
    }
    if (in_array('eaccelerator', $checkFor) && defined('EACCELERATOR_VERSION')) {
        $versions['eaccelerator'] = array('title' => 'eAccelerator', 'version' => EACCELERATOR_VERSION);
    }
    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' => empty($memcached) ? '???' : memcache_get_version($memcached));
    }
    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);
    }
    if (in_array('server', $checkFor)) {
        $versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
    }
    return $versions;
}
Esempio n. 2
0
function get_memcached_server($level = 3)
{
    global $modSettings, $memcached, $db_persist;
    $servers = explode(',', $modSettings['cache_memcached']);
    $server = explode(':', trim($servers[array_rand($servers)]));
    // Don't try more times than we have servers!
    $level = min(count($servers), $level);
    // Don't wait too long: yes, we want the server, but we might be able to run the query faster!
    if (empty($db_persist)) {
        $memcached = memcache_connect($server[0], empty($server[1]) ? 11211 : $server[1]);
    } else {
        $memcached = memcache_pconnect($server[0], empty($server[1]) ? 11211 : $server[1]);
    }
    if (!$memcached && $level > 0) {
        get_memcached_server($level - 1);
    }
}
Esempio n. 3
0
/**
 * Empty out the cache in use as best it can
 *
 * It may only remove the files of a certain type (if the $type parameter is given)
 * Type can be user, data or left blank
 *  - user clears out user data
 *  - data clears out system / opcode data
 *  - If no type is specified will perfom a complete cache clearing
 * For cache engines that do not distinguish on types, a full cache flush will be done
 *
 * @param string $type = ''
 */
function clean_cache($type = '')
{
    global $cache_accelerator, $cache_uid, $cache_password, $cache_memcached, $memcached;
    switch ($cache_accelerator) {
        case 'memcached':
            if ((function_exists('memcache_flush') || function_exists('memcached_flush')) && !empty($cache_memcached)) {
                // Not connected yet?
                if (empty($memcached)) {
                    get_memcached_server();
                }
                if (!$memcached) {
                    return;
                }
                // Clear it out, really invalidate whats there
                if (function_exists('memcache_flush')) {
                    memcache_flush($memcached);
                } else {
                    memcached_flush($memcached);
                }
            }
            break;
        case 'eaccelerator':
            if (function_exists('eaccelerator_clear') && function_exists('eaccelerator_clean')) {
                // Clean out the already expired items
                @eaccelerator_clean();
                // Remove all unused scripts and data from shared memory and disk cache,
                // e.g. all data that isn't used in the current requests.
                @eaccelerator_clear();
            }
        case 'mmcache':
            if (function_exists('mmcache_gc')) {
                // Removes all expired keys from shared memory, this is not a complete cache flush :(
                // @todo there is no clear function, should we try to find all of the keys and delete those? with mmcache_rm
                mmcache_gc();
            }
            break;
        case 'apc':
        case 'apcu':
            if (function_exists('apc_clear_cache')) {
                // If passed a type, clear that type out
                if ($type === '' || $type === 'data') {
                    apc_clear_cache('user');
                    apc_clear_cache('system');
                } elseif ($type === 'user') {
                    apc_clear_cache('user');
                }
            }
            break;
        case 'zend':
            if (function_exists('zend_shm_cache_clear')) {
                zend_shm_cache_clear('ELK');
            }
            break;
        case 'xcache':
            if (function_exists('xcache_clear_cache') && function_exists('xcache_count')) {
                // Xcache may need auth credentials, depending on how its been set up
                if (!empty($cache_uid) && !empty($cache_password)) {
                    $_SERVER['PHP_AUTH_USER'] = $cache_uid;
                    $_SERVER['PHP_AUTH_PW'] = $cache_password;
                }
                // Get the counts so we clear each instance
                $pcnt = xcache_count(XC_TYPE_PHP);
                $vcnt = xcache_count(XC_TYPE_VAR);
                // Time to clear the user vars and/or the opcache
                if ($type === '' || $type === 'user') {
                    for ($i = 0; $i < $vcnt; $i++) {
                        xcache_clear_cache(XC_TYPE_VAR, $i);
                    }
                }
                if ($type === '' || $type === 'data') {
                    for ($i = 0; $i < $pcnt; $i++) {
                        xcache_clear_cache(XC_TYPE_PHP, $i);
                    }
                }
            }
            break;
    }
    // To be complete, we also clear out the cache dir so we get any js/css hive files
    if (is_dir(CACHEDIR)) {
        // Remove the cache files in our disk cache directory
        $dh = opendir(CACHEDIR);
        while ($file = readdir($dh)) {
            if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) {
                @unlink(CACHEDIR . '/' . $file);
            }
        }
        closedir($dh);
    }
    // Invalidate cache, to be sure!
    // ... as long as Load.php can be modified, anyway.
    @touch(SOURCEDIR . '/Load.php');
    // Give addons a way to trigger cache cleaning.
    call_integration_hook('integrate_clean_cache');
    clearstatcache();
}
Esempio n. 4
0
/**
 * Get a list of versions that are currently installed on the server.
 *
 * @package Admin
 * @param string[] $checkFor
 */
function getServerVersions($checkFor)
{
    global $txt, $memcached, $modSettings;
    $db = database();
    loadLanguage('Admin');
    $versions = array();
    // Is GD available?  If it is, we should show version information for it too.
    if (in_array('gd', $checkFor) && function_exists('gd_info')) {
        $temp = gd_info();
        $versions['gd'] = array('title' => $txt['support_versions_gd'], 'version' => $temp['GD Version']);
    }
    // Why not have a look at ImageMagick? If it is, we should show version information for it too.
    if (in_array('imagick', $checkFor) && class_exists('Imagick')) {
        $temp = new Imagick();
        $temp2 = $temp->getVersion();
        $versions['imagick'] = array('title' => $txt['support_versions_imagick'], 'version' => $temp2['versionString']);
    }
    // Now lets check for the Database.
    if (in_array('db_server', $checkFor)) {
        $conn = $db->connection();
        if (empty($conn)) {
            trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
        } else {
            $versions['db_server'] = array('title' => sprintf($txt['support_versions_db'], $db->db_title()), 'version' => '');
            $versions['db_server']['version'] = $db->db_server_version();
        }
    }
    // If we're using memcache we need the server info.
    if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
        require_once SUBSDIR . '/Cache.subs.php';
        get_memcached_server();
    } else {
        if (($key = array_search('memcache', $checkFor)) !== false) {
            unset($checkFor[$key]);
        }
    }
    // Check to see if we have any accelerators installed...
    if (in_array('mmcache', $checkFor) && defined('MMCACHE_VERSION')) {
        $versions['mmcache'] = array('title' => 'Turck MMCache', 'version' => MMCACHE_VERSION);
    }
    if (in_array('eaccelerator', $checkFor) && defined('EACCELERATOR_VERSION')) {
        $versions['eaccelerator'] = array('title' => 'eAccelerator', 'version' => EACCELERATOR_VERSION);
    }
    if (in_array('zend', $checkFor) && function_exists('zend_shm_cache_store')) {
        $versions['zend'] = array('title' => 'Zend SHM Accelerator', 'version' => zend_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' => empty($memcached) ? '???' : memcache_get_version($memcached));
    }
    if (in_array('xcache', $checkFor) && function_exists('xcache_set')) {
        $versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
    }
    if (in_array('opcache', $checkFor) && extension_loaded('Zend OPcache')) {
        $opcache_config = @opcache_get_configuration();
        if (!empty($opcache_config['directives']['opcache.enable'])) {
            $versions['opcache'] = array('title' => $opcache_config['version']['opcache_product_name'], 'version' => $opcache_config['version']['version']);
        }
    }
    // PHP Version
    if (in_array('php', $checkFor)) {
        $versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION . ' (' . php_sapi_name() . ')', 'more' => '?action=admin;area=serversettings;sa=phpinfo');
    }
    // Server info
    if (in_array('server', $checkFor)) {
        $req = request();
        $versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $req->server_software());
        // Compute some system info, if we can
        $versions['server_name'] = array('title' => $txt['support_versions'], 'version' => php_uname());
        $loading = detectServerLoad();
        if ($loading !== false) {
            $versions['server_load'] = array('title' => $txt['load_balancing_settings'], 'version' => $loading);
        }
    }
    return $versions;
}
Esempio n. 5
0
function get_server_versions($checkFor)
{
    global $txt, $db_connection, $_PHPA, $smcFunc, $memcached, $modSettings;
    loadLanguage('Admin');
    $versions = array();
    // Is GD available?  If it is, we should show version information for it too.
    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 we're using memcache we need the server info.
    if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
        get_memcached_server();
    }
    // Check to see if we have any accelerators installed...
    if (in_array('mmcache', $checkFor) && defined('MMCACHE_VERSION')) {
        $versions['mmcache'] = array('title' => 'Turck MMCache', 'version' => MMCACHE_VERSION);
    }
    if (in_array('eaccelerator', $checkFor) && defined('EACCELERATOR_VERSION')) {
        $versions['eaccelerator'] = array('title' => 'eAccelerator', 'version' => EACCELERATOR_VERSION);
    }
    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' => empty($memcached) ? '???' : memcache_get_version($memcached));
    }
    return $versions;
}
Esempio n. 6
0
function Admin()
{
    global $sourcedir, $db_prefix, $forum_version, $txt, $scripturl, $context, $modSettings;
    global $user_info, $_PHPA, $boardurl, $memcached;
    if (isset($_GET['area']) && $_GET['area'] == 'copyright') {
        return ManageCopyright();
    }
    // You have to be able to do at least one of the below to see this page.
    isAllowedTo(array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'));
    // Load the common admin stuff... select 'index'.
    adminIndex(isset($_GET['credits']) ? 'credits' : 'index');
    // Find all of this forum's administrators.
    $request = db_query("\n\t\tSELECT ID_MEMBER, realName\n\t\tFROM {$db_prefix}members\n\t\tWHERE ID_GROUP = 1 OR FIND_IN_SET(1, additionalGroups)\n\t\tLIMIT 33", __FILE__, __LINE__);
    $context['administrators'] = array();
    while ($row = mysql_fetch_assoc($request)) {
        $context['administrators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';
    }
    mysql_free_result($request);
    // If there are more than 32 admins show a more link and direct the admin to the memberlist with admin filter.
    if (count($context['administrators']) > 32) {
        // Quicker to get one too many than to count first...
        unset($context['administrators'][32]);
        $context['more_admins_link'] = '<a href="' . $scripturl . '?action=mlist;sa=search;fields=group;search=administrator">' . $txt['more'] . '</a>';
    }
    // Some stuff.... :P.
    $context['credits'] = '
<i>Simple Machines wants to thank everyone who helped make SMF 1.1 what it is today; shaping and directing our project, all through the thick and the thin. It wouldn\'t have been possible without you.</i><br />
<div style="margin-top: 1ex;"><i>This includes our users and especially Charter Members - thanks for installing and using our software as well as providing valuable feedback, bug reports, and opinions.</i></div>
<div style="margin-top: 2ex;"><b>Project Managers:</b> Amacythe, David Recordon, Joseph Fung, and Jeff Lewis.</div>
<div style="margin-top: 1ex;"><b>Developers:</b> Hendrik Jan &quot;Compuart&quot; Visser, Matt &quot;Grudge&quot; Wolf, Michael &quot;Thantos&quot; Miller, Theodore &quot;Orstio&quot; Hildebrandt, and Unknown W. &quot;[Unknown]&quot; Brackets</div>
<div style="margin-top: 1ex;"><b>Support Specialists:</b> Ben Scott, Michael &quot;Oldiesmann&quot; Eshom, Jan-Olof &quot;Owdy&quot; Eriksson, A&auml;ron van Geffen, Alexandre &quot;Ap2&quot; Patenaude, Andrea Hubacher, Chris Cromer, [darksteel], dtm.exe, Nick &quot;Fizzy&quot; Dyer, Horseman, Huw Ayling-Miller, jerm, Justyne, kegobeer, Kindred, Matthew &quot;Mattitude&quot; Hall, Mediman, Metho, Omar Bazavilvazo, Pitti, redone, Tomer &quot;Lamper&quot; Dean, Tony, and xenovanis.</div>
<div style="margin-top: 1ex;"><b>Mod Developers:</b> snork13, Cristi&aacute;n &quot;Anguz&quot; L&aacute;vaque, Goosemoose, Jack.R.Abbit, James &quot;Cheschire&quot; Yarbro, Jesse &quot;Gobalopper&quot; Reid, Juan &quot;JayBachatero&quot; Hernandez, Kirby, vbgamer45, and winrules.</div>
<div style="margin-top: 1ex;"><b>Documentation Writers:</b> akabugeyes, eldacar, Gary M. &quot;AwwLilMaggie&quot; Gadsdon, Jerry, and Nave.</div>
<div style="margin-top: 1ex;"><b>Language Coordinators:</b> Daniel Diehl and Adam &quot;Bostasp&quot; Southall.</div>
<div style="margin-top: 1ex;"><b>Graphic Designers:</b> Bjoern &quot;Bloc&quot; Kristiansen, Alienine (Adrian), A.M.A, babylonking, BlackouT, Burpee, diplomat, Eren &quot;forsakenlad&quot; Yasarkurt, Hyper Piranha, Killer Possum, Mystica, Nico &quot;aliencowfarm&quot; Boer, Philip &quot;Meriadoc&quot; Renich and Tippmaster.</div>
<div style="margin-top: 1ex;"><b>Site team:</b> dschwab9 and Tim.</div>
<div style="margin-top: 1ex;"><b>Marketing:</b> Douglas &quot;The Bear&quot; Hazard, RickC and Trekkie101.</div>
<div style="margin-top: 1ex;">And for anyone we may have missed, thank you!</div>';
    // Copyright?
    if (!empty($modSettings['copy_settings']) || !empty($modSettings['copyright_key'])) {
        if (empty($modSettings['copy_settings'])) {
            $modSettings['copy_settings'] = 'a,0';
        }
        // Not done it yet...
        if (empty($_SESSION['copy_expire'])) {
            list($key, $expires) = explode(',', $modSettings['copy_settings']);
            // Get the expired date.
            require_once $sourcedir . '/Subs-Package.php';
            $return_data = fetch_web_data($url = 'http://www.simplemachines.org/smf/copyright/check_copyright.php?site=' . base64_encode($boardurl) . '&key=' . $key . '&version=' . base64_encode($forum_version));
            // Get the expire date.
            $return_data = substr($return_data, strpos($return_data, 'STARTCOPY') + 9);
            $return_data = trim(substr($return_data, 0, strpos($return_data, 'ENDCOPY')));
            if ($return_data != 'void') {
                list($_SESSION['copy_expire'], $copyright_key) = explode('|', $return_data);
                $_SESSION['copy_key'] = $key;
                $copy_settings = $key . ',' . (int) $_SESSION['copy_expire'];
                updateSettings(array('copy_settings' => $copy_settings, 'copyright_key' => $copyright_key));
            } else {
                $_SESSION['copy_expire'] = '';
                db_query("\n\t\t\t\t\tDELETE FROM {$db_prefix}settings\n\t\t\t\t\tWHERE variable = 'copy_settings'\n\t\t\t\t\t\tOR variable = 'copyright_key'", __FILE__, __LINE__);
            }
        }
        if (isset($_SESSION['copy_expire']) && $_SESSION['copy_expire'] > time()) {
            $context['copyright_expires'] = (int) (($_SESSION['copy_expire'] - time()) / 3600 / 24);
            $context['copyright_key'] = $_SESSION['copy_key'];
        }
    }
    // This makes it easier to get the latest news with your time format.
    $context['time_format'] = urlencode($user_info['time_format']);
    $context['current_versions'] = array('php' => array('title' => $txt['support_versions_php'], 'version' => PHP_VERSION), 'mysql' => array('title' => $txt['support_versions_mysql'], 'version' => ''), 'server' => array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']));
    $context['forum_version'] = $forum_version;
    // Is GD available?  If it is, we should show version information for it too.
    if (function_exists('gd_info')) {
        $temp = gd_info();
        $context['current_versions']['gd'] = array('title' => $txt['support_versions_gd'], 'version' => $temp['GD Version']);
    }
    $request = db_query("\n\t\tSELECT VERSION()", __FILE__, __LINE__);
    list($context['current_versions']['mysql']['version']) = mysql_fetch_row($request);
    mysql_free_result($request);
    // If we're using memcache we need the server info.
    if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
        get_memcached_server();
    }
    // Check to see if we have any accelerators installed...
    if (defined('MMCACHE_VERSION')) {
        $context['current_versions']['mmcache'] = array('title' => 'Turck MMCache', 'version' => MMCACHE_VERSION);
    }
    if (defined('EACCELERATOR_VERSION')) {
        $context['current_versions']['eaccelerator'] = array('title' => 'eAccelerator', 'version' => EACCELERATOR_VERSION);
    }
    if (isset($_PHPA)) {
        $context['current_versions']['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
    }
    if (extension_loaded('apc')) {
        $context['current_versions']['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
    }
    if (function_exists('memcache_set')) {
        $context['current_versions']['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached));
    }
    $context['can_admin'] = allowedTo('admin_forum');
    $context['sub_template'] = isset($_GET['credits']) ? 'credits' : 'admin';
    $context['page_title'] = isset($_GET['credits']) ? $txt['support_credits_title'] : $txt[208];
    // The format of this array is: permission, action, title, description.
    $quick_admin_tasks = array(array('', 'admin;credits', 'support_credits_title', 'support_credits_info'), array('admin_forum', 'featuresettings', 'modSettings_title', 'modSettings_info'), array('admin_forum', 'maintain', 'maintain_title', 'maintain_info'), array('manage_permissions', 'permissions', 'edit_permissions', 'edit_permissions_info'), array('admin_forum', 'theme;sa=admin;sesc=' . $context['session_id'], 'theme_admin', 'theme_admin_info'), array('admin_forum', 'packages', 'package1', 'package_info'), array('manage_smileys', 'smileys', 'smileys_manage', 'smileys_manage_info'), array('moderate_forum', 'viewmembers', '5', 'member_center_info'));
    $context['quick_admin_tasks'] = array();
    foreach ($quick_admin_tasks as $task) {
        if (!empty($task[0]) && !allowedTo($task[0])) {
            continue;
        }
        $context['quick_admin_tasks'][] = array('href' => $scripturl . '?action=' . $task[1], 'link' => '<a href="' . $scripturl . '?action=' . $task[1] . '">' . $txt[$task[2]] . '</a>', 'title' => $txt[$task[2]], 'description' => $txt[$task[3]], 'is_last' => false);
    }
    if (count($context['quick_admin_tasks']) % 2 == 1) {
        $context['quick_admin_tasks'][] = array('href' => '', 'link' => '', 'title' => '', 'description' => '', 'is_last' => true);
        $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 2]['is_last'] = true;
    } elseif (count($context['quick_admin_tasks']) != 0) {
        $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 1]['is_last'] = true;
        $context['quick_admin_tasks'][count($context['quick_admin_tasks']) - 2]['is_last'] = true;
    }
}