Beispiel #1
0
/**
 * Collect system stats for display on the "About this system" page
 *
 * @return array
 */
function get_system_stats()
{
    global $evo_charset, $DB, $Settings, $cache_path;
    static $system_stats = array();
    if (!empty($system_stats)) {
        return $system_stats;
    }
    // b2evo config choices:
    $system_stats['mediadir_status'] = system_check_dir('media');
    // If error, then the host is potentially borked
    $system_stats['install_removed'] = system_check_install_removed();
    $system_stats['evo_charset'] = $evo_charset;
    $system_stats['evo_blog_count'] = count(system_get_blog_IDs(false));
    // Caching:
    $system_stats['cachedir_status'] = system_check_dir('cache');
    // If error, then the host is potentially borked
    $system_stats['cachedir_size'] = get_dirsize_recursive($cache_path);
    $system_stats['general_pagecache_enabled'] = $Settings->get('general_cache_enabled');
    $system_stats['blog_pagecaches_enabled'] = count(system_get_blog_IDs(true));
    // Database:
    $system_stats['db_version'] = $DB->get_version();
    // MySQL version
    $system_stats['db_utf8'] = system_check_db_utf8();
    // PHP:
    list($uid, $uname) = system_check_process_user();
    $system_stats['php_uid'] = $uid;
    $system_stats['php_uname'] = $uname;
    // Potential unsecure hosts will use names like 'nobody', 'www-data'
    list($gid, $gname) = system_check_process_group();
    $system_stats['php_gid'] = $gid;
    $system_stats['php_gname'] = $gname;
    // Potential unsecure hosts will use names like 'nobody', 'www-data'
    $system_stats['php_version'] = PHP_VERSION;
    $system_stats['php_reg_globals'] = ini_get('register_globals');
    $system_stats['php_allow_url_include'] = ini_get('allow_url_include');
    $system_stats['php_allow_url_fopen'] = ini_get('allow_url_fopen');
    // TODO php_magic quotes
    $system_stats['php_upload_max'] = system_check_upload_max_filesize();
    $system_stats['php_post_max'] = system_check_post_max_size();
    $system_stats['php_memory'] = system_check_memory_limit();
    // how much room does b2evo have to move?
    $system_stats['php_mbstring'] = extension_loaded('mbstring');
    $system_stats['php_xml'] = extension_loaded('xml');
    $system_stats['php_imap'] = extension_loaded('imap');
    $system_stats['php_opcode_cache'] = get_active_opcode_cache();
    // GD:
    $system_stats['gd_version'] = system_check_gd_version();
    return $system_stats;
}
Beispiel #2
0
// Max upload size:
$upload_max_filesize = system_check_upload_max_filesize();
init_system_check('PHP upload_max_filesize', ini_get('upload_max_filesize'));
disp_system_check('ok');
// Max post size:
$post_max_size = system_check_post_max_size();
init_system_check('PHP post_max_size', ini_get('post_max_size'));
if ($post_max_size > $upload_max_filesize) {
    disp_system_check('ok');
} elseif ($post_max_size == $upload_max_filesize) {
    disp_system_check('warning', T_('post_max_size should be larger than upload_max_filesize'));
} else {
    disp_system_check('error', T_('post_max_size should be larger than upload_max_filesize'));
}
// Memory limit:
$memory_limit = system_check_memory_limit();
if (empty($memory_limit)) {
    init_system_check('PHP memory_limit', T_('n.a.'));
    disp_system_check('note');
} else {
    init_system_check('PHP memory_limit', ini_get('memory_limit'));
    if ($memory_limit < get_php_bytes_size('256M')) {
        disp_system_check('error', T_('The memory_limit is too low. Some features like image manipulation will fail to work.'));
    } elseif ($memory_limit < get_php_bytes_size('384M')) {
        disp_system_check('warning', T_('The memory_limit is low. Some features like image manipulation of large files may fail to work.'));
    } else {
        disp_system_check('ok');
    }
}
// Maximum execution time of each script
$max_execution_time = system_check_max_execution_time();
Beispiel #3
0
/**
 * Load an image from a file into memory
 *
 * @param string pathname of image file
 * @param string
 * @return array resource image handle or NULL
 */
function load_image($path, $mimetype)
{
    // yabs> GD library uses shedloads of memory
    // fp> 256M is way too high to sneak this in here. There should be some checks in the systems page to warn against low memory conditions. Also i'm not sure it makes sense to bump memory just for images. If you allow memory you might as well allow it for anything. Anyways, this is too much to be snuk in.
    // @ini_set('memory_limit', '256M'); // artificially inflate memory if we can
    $err = NULL;
    $imh = NULL;
    $function = NULL;
    $image_info = getimagesize($path);
    if (!$image_info || $image_info['mime'] != $mimetype) {
        $FiletypeCache = get_Cache('FiletypeCache');
        $correct_Filetype = $FiletypeCache->get_by_mimetype($image_info['mime']);
        $correct_extension = array_shift($correct_Filetype->get_extensions());
        $path_info = pathinfo($path);
        $wrong_extension = $path_info['extension'];
        $err = '!' . $correct_extension . ' extension mismatch: use .' . $correct_extension . ' instead of .' . $wrong_extension;
    } else {
        $mime_function = array('image/jpeg' => 'imagecreatefromjpeg', 'image/gif' => 'imagecreatefromgif', 'image/png' => 'imagecreatefrompng');
        if (isset($mime_function[$mimetype])) {
            $function = $mime_function[$mimetype];
        } else {
            // Unrecognized mime type
            $err = '!Unsupported format ' . $mimetype . ' (load_image)';
        }
    }
    //pre_dump( $function );
    if ($function) {
        // Call GD built-in function to load image
        // fp> Note: sometimes this GD call will die and there is no real way to recover :/
        load_funcs('tools/model/_system.funcs.php');
        $memory_limit = system_check_memory_limit();
        $curr_mem_usage = memory_get_usage(true);
        // Calculate the aproximative memory size which would be required to create the image resource
        if ($memory_limit - $curr_mem_usage < 4 * $image_info[0] * $image_info[1]) {
            // Don't try to load the image into the memory because it would cause 'Allowed memory size exhausted' error
            return array("!Cannot resize too large image", false);
        }
        $imh = $function($path);
    }
    if ($imh === false) {
        trigger_error('load_image failed: ' . $path . ' / ' . $mimetype);
        // DEBUG
        // e.g. "imagecreatefromjpeg(): $FILE is not a valid JPEG file"
        $err = '!load_image failed (no valid image?)';
    }
    if ($err) {
        error_log('load_image failed: ' . substr($err, 1) . ' (' . $path . ' / ' . $mimetype . ')');
    }
    return array($err, $imh);
}
Beispiel #4
0
/**
 * Get updates from b2evolution.net
 *
 * @return boolean True if there have been updates.
 */
function b2evonet_get_updates()
{
    global $DB, $debug, $evonetsrv_host, $evonetsrv_port, $evonetsrv_uri, $servertimenow, $evo_charset;
    global $Messages, $Settings, $baseurl, $instance_name, $app_name, $app_version, $app_date;
    $update_every = 3600 * 12;
    // 12 hours
    $attempt_every = 3600 * 4;
    // 4 hours
    /* DEBUG: *
    	$update_every = 10;
    	$attempt_every = 5;
    	*/
    $servertime_last_update = $Settings->get('evonet_last_update');
    if ($servertime_last_update > $servertimenow - $update_every) {
        // The previous update was less than 12 hours ago, skip this
        // echo 'recent update';
        return false;
    }
    $servertime_last_attempt = $Settings->get('evonet_last_attempt');
    if ($servertime_last_attempt > $servertimenow - $attempt_every) {
        // The previous update attempt was less than 4 hours ago, skip this
        // This is so all b2evo's don't go crazy if the server ever is down
        // echo 'recent attempt';
        return false;
    }
    if ($debug) {
        $Messages->add(T_('Getting updates from ') . $evonetsrv_host, 'notes');
    }
    $Settings->set('evonet_last_attempt', $servertimenow);
    $Settings->dbupdate();
    // Construct XML-RPC client:
    load_funcs('xmlrpc/model/_xmlrpc.funcs.php');
    $client = new xmlrpc_client($evonetsrv_uri, $evonetsrv_host, $evonetsrv_port);
    // $client->debug = $debug;
    // Run system checks:
    load_funcs('tools/model/_system.funcs.php');
    list($mediadir_status) = system_check_media_dir();
    list($uid, $uname) = system_check_process_user();
    list($gid, $gname) = system_check_process_group();
    // Construct XML-RPC message:
    $message = new xmlrpcmsg('b2evo.getupdates', array(new xmlrpcval($baseurl, 'string'), new xmlrpcval($instance_name, 'string'), new xmlrpcval($app_name, 'string'), new xmlrpcval($app_version, 'string'), new xmlrpcval($app_date, 'string'), new xmlrpcval(array('this_update' => new xmlrpcval($servertimenow, 'string'), 'last_update' => new xmlrpcval($servertime_last_update, 'string'), 'db_version' => new xmlrpcval($DB->get_version(), 'string'), 'db_utf8' => new xmlrpcval(system_check_db_utf8() ? 1 : 0, 'int'), 'evo_charset' => new xmlrpcval($evo_charset, 'string'), 'php_version' => new xmlrpcval(PHP_VERSION, 'string'), 'php_xml' => new xmlrpcval(extension_loaded('xml') ? 1 : 0, 'int'), 'php_mbstring' => new xmlrpcval(extension_loaded('mbstring') ? 1 : 0, 'int'), 'php_memory' => new xmlrpcval(system_check_memory_limit(), 'int'), 'php_upload_max' => new xmlrpcval(system_check_upload_max_filesize(), 'int'), 'php_post_max' => new xmlrpcval(system_check_post_max_size(), 'int'), 'mediadir_status' => new xmlrpcval($mediadir_status, 'string'), 'install_removed' => new xmlrpcval(system_check_install_removed() ? 1 : 0, 'int'), 'php_uid' => new xmlrpcval($uid, 'int'), 'php_uname' => new xmlrpcval($uname, 'string'), 'php_gid' => new xmlrpcval($gid, 'int'), 'php_gname' => new xmlrpcval($gname, 'string'), 'php_reg_globals' => new xmlrpcval(ini_get('register_globals') ? 1 : 0, 'int'), 'gd_version' => new xmlrpcval(system_check_gd_version(), 'string')), 'struct')));
    $result = $client->send($message);
    if ($ret = xmlrpc_logresult($result, $Messages, false)) {
        // Response is not an error, let's process it:
        $response = $result->value();
        if ($response->kindOf() == 'struct') {
            // Decode struct:
            $response = xmlrpc_decode_recurse($response);
            /**
             * @var AbstractSettings
             */
            global $global_Cache;
            if (isset($response['evo_links'])) {
                // Extract evo links into its own var:
                $evo_links = $response['evo_links'];
                unset($response['evo_links']);
                if (is_array($evo_links)) {
                    // Save creds:
                    $global_Cache->set('evo_links', serialize($evo_links));
                }
            }
            if (isset($response['creds'])) {
                // Extract creds into its own var:
                $creds = $response['creds'];
                unset($response['creds']);
                if (is_array($creds)) {
                    // Save creds:
                    $global_Cache->set('creds', serialize($creds));
                }
            }
            // Save other info:
            $global_Cache->set('evonet_updates', serialize($response));
            $global_Cache->dbupdate();
            $Settings->set('evonet_last_update', $servertimenow);
            $Settings->dbupdate();
            return true;
        } else {
            $Messages->add(T_('Invalid updates received'), 'error');
        }
    }
    return false;
}
Beispiel #5
0
//load_funcs('items/model/_item.funcs.php');
//load_funcs('users/model/_user.funcs.php');
//load_funcs( '_core/ui/forms/_form.funcs.php' );
load_class('_core/model/_timer.class.php', 'Timer');
//load_class( 'plugins/model/_plugins.class.php', 'Plugins' );
load_funcs('_core/_url.funcs.php');
load_funcs('tools/model/_system.funcs.php');
require_once dirname(__FILE__) . '/_functions_install.php';
$Timer = new Timer('main');
// Let the modules load/register what they need:
modules_call_method('init');
// Init charset variables based on the $evo_charset value
$current_charset = $evo_charset;
init_charsets($current_charset);
// Check minimum memory limit for successful using:
if (system_check_memory_limit() < get_php_bytes_size('48M')) {
    // Deny to use on server with small memory limit size:
    $install_memory_limit_allow = false;
    if ($action != 'localeinfo') {
        // Restrict all actions except of action to switch a language and view page of more languages:
        $action = 'start';
    }
} else {
    // Allow to use installer when memory limit is enough:
    $install_memory_limit_allow = true;
}
// Display mode:
// - 'normal' - Normal mode; Used for normal installation.
// - 'compact' - Compact mode; Hide header, footer and progress bar; Used for automated installation.
param('display', 'string', 'normal');
// check if we should try to connect to db if config is not done
Beispiel #6
0
 function get_content()
 {
     $temp = fopen($_FILES['qqfile']['tmp_name'], "rb");
     fseek($temp, 0, SEEK_SET);
     $contents = '';
     load_funcs('tools/model/_system.funcs.php');
     $memory_limit = system_check_memory_limit();
     while (!feof($temp)) {
         $curr_mem_usage = memory_get_usage(true);
         if ($memory_limit - $curr_mem_usage < 8192) {
             // Don't try to load the next portion of image into the memory because it would cause 'Allowed memory size exhausted' error
             fclose($temp);
             return false;
         }
         $contents .= fread($temp, 8192);
     }
     fclose($temp);
     return $contents;
 }