Пример #1
0
function GetServerCapabilities()
{
    // Handle recursion issues with CGI version of PHP
    if (getenv('PHP_REPEAT')) {
        return;
    }
    putenv('PHP_REPEAT=TRUE');
    $server = array('safe_mode' => TRUE, 'allow_exec' => FALSE, 'have_gd' => extension_loaded('gd'), 'have_magick' => FALSE, 'have_imager' => FALSE, 'php_cli' => null, 'mysql' => null, 'mysqldump' => null, 'convert' => null, 'composite' => null, 'dig' => null);
    restore_error_handler();
    // Check for safe mode
    ob_start();
    $safe_mode = ini_get('safe_mode');
    $buffer = ob_get_contents();
    ob_end_clean();
    if (!$safe_mode && empty($buffer)) {
        $server['safe_mode'] = FALSE;
    }
    if (!$server['safe_mode']) {
        $open_basedir = ini_get('open_basedir');
        // Check if shell_exec is available
        ob_start();
        shell_exec('ls -l');
        $buffer = ob_get_contents();
        ob_end_clean();
        if (empty($buffer)) {
            $server['allow_exec'] = TRUE;
        }
        if ($server['allow_exec']) {
            // Check for cli version of PHP
            $server['php_cli'] = LocateExecutable('php', '-v', '(cli)', $open_basedir);
            if (!$server['php_cli']) {
                $server['php_cli'] = LocateExecutable('php-cli', '-v', '(cli)', $open_basedir);
            }
            // Check for mysql executables
            $server['mysql'] = LocateExecutable('mysql', null, null, $open_basedir);
            $server['mysqldump'] = LocateExecutable('mysqldump', null, null, $open_basedir);
            // Check for imagemagick executables
            $server['convert'] = LocateExecutable('convert', null, null, $open_basedir);
            $server['composite'] = LocateExecutable('composite', null, null, $open_basedir);
            // Check for dig
            $server['dig'] = LocateExecutable('dig', null, null, $open_basedir);
            if ($server['convert'] && $server['composite']) {
                $server['have_magick'] = TRUE;
                $server['magick6'] = FALSE;
                // Get version
                $output = shell_exec("{$server['convert']} -version");
                if (preg_match('~ImageMagick ([^ ]+)~i', $output, $matches)) {
                    if (preg_match('~^6\\.~', $matches[1])) {
                        $server['magick6'] = TRUE;
                    }
                }
            }
        }
    }
    set_error_handler('Error');
    $server['have_imager'] = $server['have_magick'] || $server['have_gd'];
    if ($server['safe_mode']) {
        $server['cant_exec_reason'] = 'PHP appears to be running in safe mode or a restricted operating mode';
    } else {
        if (!$server['allow_exec']) {
            $server['cant_exec_reason'] = 'the PHP shell_exec() function has been disabled by your server administrator';
        } else {
            if (empty($server['php_cli'])) {
                $server['cant_exec_reason'] = 'the CLI version of PHP could not be found on your server';
            }
        }
    }
    return $server;
}
Пример #2
0
function GetServerCapabilities()
{
    // Handle recursion issues with CGI version of PHP
    if (getenv('PHP_REPEAT')) {
        return;
    }
    putenv('PHP_REPEAT=TRUE');
    $GLOBALS['LAST_ERROR'] = null;
    $server = array('safe_mode' => TRUE, 'shell_exec' => FALSE, 'have_gd' => extension_loaded('gd'), 'have_magick' => FALSE, 'magick6' => FALSE, 'have_imager' => FALSE, 'php_cli' => null, 'mysql' => null, 'mysqldump' => null, 'convert' => null, 'composite' => null, 'dig' => null, 'tar' => null, 'gzip' => null, 'message' => array(), 'php_cli_safe_mode' => FALSE, 'php_cli_zend_optimizer' => TRUE);
    set_error_handler('GetServerCapabilitiesError');
    error_reporting(E_ALL);
    $server['safe_mode'] = @ini_get('safe_mode');
    if ($server['safe_mode'] === null || isset($GLOBALS['LAST_ERROR'])) {
        $server['safe_mode'] = TRUE;
        $server['message'][] = "The ini_get() PHP function appears to be disabled on your server\nPHP says: " . $GLOBALS['LAST_ERROR'];
    } else {
        if ($server['safe_mode']) {
            $server['message'][] = "Your server is running PHP with safe_mode enabled";
            // Do tests on safe_mode_exec_dir
        } else {
            $server['safe_mode'] = FALSE;
            $GLOBALS['LAST_ERROR'] = null;
            $open_basedir = ini_get('open_basedir');
            // See if shell_exec is available on the server
            @shell_exec('ls -l');
            if (isset($GLOBALS['LAST_ERROR'])) {
                $server['shell_exec'] = FALSE;
                $server['message'][] = "The shell_exec() PHP function appears to be disabled on your server\nPHP says: " . $GLOBALS['LAST_ERROR'];
            } else {
                $server['shell_exec'] = TRUE;
            }
            if ($server['shell_exec']) {
                // Check for cli version of PHP
                $server['php_cli'] = LocateExecutable('php', '-v', '(cli)', $open_basedir, 'SCRIPT_FILENAME=/dev/null');
                if (!$server['php_cli']) {
                    $server['php_cli'] = LocateExecutable('php-cli', '-v', '(cli)', $open_basedir, 'SCRIPT_FILENAME=/dev/null');
                }
                // Check for Zend Optimizer and safe_mode
                if ($server['php_cli']) {
                    $cli_settings = shell_exec("{$env} {$server['php_cli']} -r \"echo serialize(array('safe_mode' => ini_get('safe_mode'), 'zend_optimizer' => extension_loaded('Zend Optimizer')));\" 2>/dev/null");
                    $cli_settings = unserialize($cli_settings);
                    if ($cli_settings !== FALSE) {
                        if ($cli_settings['safe_mode']) {
                            $server['php_cli_safe_mode'] = TRUE;
                        }
                        if (!$cli_settings['zend_optimizer']) {
                            $server['php_cli_zend_optimizer'] = FALSE;
                        }
                    }
                }
                // Check for mysql executables
                $server['mysql'] = LocateExecutable('mysql', null, null, $open_basedir);
                $server['mysqldump'] = LocateExecutable('mysqldump', null, null, $open_basedir);
                // Check for imagemagick executables
                $server['convert'] = LocateExecutable('convert', null, null, $open_basedir);
                $server['composite'] = LocateExecutable('composite', null, null, $open_basedir);
                // Check for dig
                $server['dig'] = LocateExecutable('dig', null, null, $open_basedir);
                // Check for archiving executables
                $server['tar'] = LocateExecutable('tar', null, null, $open_basedir);
                $server['gzip'] = LocateExecutable('gzip', null, null, $open_basedir);
                if ($server['convert'] && $server['composite']) {
                    $server['have_magick'] = TRUE;
                    $server['magick6'] = FALSE;
                    // Get version
                    $output = shell_exec("{$server['convert']} -version");
                    if (preg_match('~ImageMagick 6\\.~i', $output)) {
                        $server['magick6'] = TRUE;
                    }
                }
            }
        }
    }
    $server['have_imager'] = $server['have_magick'] || $server['have_gd'];
    error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
    restore_error_handler();
    return $server;
}
Пример #3
0
function GetServerCapabilities()
{
    // Handle recursion issues with CGI version of PHP
    if (getenv('PHP_REPEAT')) {
        return;
    }
    putenv('PHP_REPEAT=TRUE');
    $server = array('safe_mode' => TRUE, 'allow_exec' => FALSE, 'have_gd' => extension_loaded('gd'), 'have_magick' => FALSE, 'have_imager' => FALSE, 'php_cli' => null, 'mysql' => null, 'mysqldump' => null, 'convert' => null, 'composite' => null);
    // Check for safe mode
    ob_start();
    $safe_mode = ini_get('safe_mode');
    $buffer = ob_get_contents();
    ob_end_clean();
    if (!$safe_mode && empty($buffer)) {
        $server['safe_mode'] = FALSE;
    }
    if (!$server['safe_mode']) {
        // Check if exec is available
        ob_start();
        shell_exec('ls -l');
        $buffer = ob_get_contents();
        ob_end_clean();
        if (empty($buffer)) {
            $server['allow_exec'] = TRUE;
        }
        if ($server['allow_exec']) {
            // Check for cli version of PHP
            $server['php_cli'] = LocateExecutable('php', 'php -v', '(cli)');
            // Check for mysql executables
            $server['mysql'] = LocateExecutable('mysql');
            $server['mysqldump'] = LocateExecutable('mysqldump');
            // Check for imagemagick executables
            $server['convert'] = LocateExecutable('convert');
            $server['composite'] = LocateExecutable('composite');
            if ($server['convert'] && $server['composite']) {
                $server['have_magick'] = TRUE;
            }
        }
    }
    $server['have_imager'] = $server['have_magick'] | $server['have_gd'];
    $server['can_exec'] = !$server['safe_mode'] && $server['allow_exec'];
    if ($server['safe_mode']) {
        $server['cant_exec_reason'] = 'PHP appears to be running in safe mode or a restricted operating mode';
    } else {
        if (!$server['allow_exec']) {
            $server['cant_exec_reason'] = 'the PHP shell_exec() function has been disabled by your server administrator';
        } else {
            $server['cant_exec_reason'] = 'The CLI version of PHP could not be found on your server';
        }
    }
    return $server;
}