You are here

systeminfo.module in System Information 5

Displays information of the drupal install and system environment.

File

systeminfo.module
View source
<?php

// $Name$

/**
 * @file
 *   Displays information of the drupal install and system environment.
 */

/**
 * Implementation of hook_help().
 */
function systeminfo_help($section) {
  switch ($section) {
    case 'admin/help#systeminfo':
      $output = '<p>' . t('This module displays information of the drupal install and system environment.') . '</p>';
      $output .= '<h3>' . t('System requirements') . '</h3>';
      $output .= '<ol>';
      $output .= '<li>' . t('Web Server') . '<ul>';
      $output .= '<li>' . t('<a href="http://httpd.apache.org/">Apache</a>, version 1.3.x or newer. (Recommended)') . '<ul>';
      $output .= '<li>' . t('Module mod_rewrite and the ability to use local .htaccess files for clean URLs.') . '</li></ul></li>';
      $output .= '<li>' . t('<a href="http://www.microsoft.com/iis">IIS</a>, version 5 or newer.') . '</li>';
      $output .= '</ul></li>';
      $output .= '<li>' . t('<a href="http://www.php.net/">PHP</a>') . '<ul>';
      $output .= '<li>' . t('Version 4.3.3 or newer.') . '</li>';
      $output .= '<li>' . t('Memory of 8MB for the core install but for additional contributed modules it\'s recommended to raise it.') . '</li>';
      $output .= '<li>' . t('Configuration directives') . '<ul>';
      $output .= '<li>' . t('session.save_handler: user') . '</li>';
      $output .= '<li>' . t('session.cache_limiter: none (Recommended)') . '</li></ul></li>';
      $output .= '<li>' . t('XML extension for bloggerapi, drupal, jabber, and ping modules.') . '</li>';
      $output .= '</ul></li>';
      $output .= '<li>' . t('Database') . '<ul>';
      $output .= '<li>' . t('<a href="http://www.mysql.com/">MySQL</a>, version 3.23.17 or newer. (Recommended)') . '<ul>';
      $output .= '<li>' . t('Grant to create temporary tables for search module.') . '</li>';
      $output .= '<li>' . t('Grant to lock tables.') . '</li></ul></li>';
      $output .= '<li>' . t('<a href="http://www.postgresql.org/">PostgreSQL</a>, version 7.3 or newer.') . '</li>';
      $output .= '</ul></li></ol>';
      $output .= '<p>' . t('<strong>Note:</strong> <a href="http://drupal.org/node/270">More information</a> can be found in the <a href="http://drupal.org/handbooks">Drupal handbook</a> on <a href="http://drupal.org">drupal.org</a>.') . '</p>';
      return $output;
    case 'admin/logs/systeminfo':
      return '<p>' . t('Information of the drupal install and system environment.') . '</p>';
  }
}

/**
 * Implementation of hook_menu().
 */
function systeminfo_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/logs/systeminfo',
      'title' => t('System info'),
      'description' => t('Displays information of the drupal install and system environment.'),
      'callback' => 'systeminfo_display_information',
      'access' => user_access('access system info'),
    );
  }
  return $items;
}

/**
 * Implementation of hook_perm().
 */
function systeminfo_perm() {
  return array(
    'access system info',
  );
}

/**
 * Menu callback of page 'system info'.
 */
function systeminfo_display_information() {
  global $base_url, $db_prefix, $db_url;

  // Extract database data
  $database_url = is_array($db_url) ? $db_url : array(
    'default' => $db_url,
  );
  foreach ($database_url as $key => $value) {
    $db[$key] = parse_url($value);
    $db[$key]['scheme'] = urldecode($db[$key]['scheme']);
    $db[$key]['user'] = urldecode($db[$key]['user']);
    $db[$key]['host'] = urldecode($db[$key]['host']);
    $db[$key]['path'] = urldecode($db[$key]['path']);
  }

  // Include CSS for formatting
  $path = drupal_get_path('module', 'systeminfo');
  drupal_add_css($path . '/systeminfo.css');

  // Drupal
  $header = array(
    array(
      'data' => t('Drupal'),
      'colspan' => '2',
    ),
  );
  $rows = array();
  $rows[] = array(
    t('Version'),
    defined('VERSION') ? VERSION : t('Not found'),
  );
  $rows[] = array(
    t('Sites directory'),
    substr(conf_path(), 6),
  );
  $rows[] = array(
    t('Url'),
    $base_url,
  );
  if (is_array($db_prefix) && !empty($db_prefix)) {
    $rows[] = array(
      array(
        'data' => t('Database prefix'),
        'class' => 'subheader',
        'colspan' => '2',
      ),
    );
    foreach ($db_prefix as $table => $prefix) {
      $rows[] = array(
        array(
          'data' => $table,
          'class' => 'subitem',
        ),
        $prefix,
      );
    }
  }
  else {
    $rows[] = array(
      t('Database prefix'),
      $db_prefix,
    );
  }
  $drupal = array(
    '#type' => 'item',
    '#value' => theme('table', $header, $rows, array(
      'class' => 'systeminfo',
    )),
  );
  $output = drupal_render($drupal);

  // Web server
  $header = array(
    array(
      'data' => t('Web Server'),
      'colspan' => '2',
    ),
  );
  $rows = array();
  if (preg_match('/Apache\\/?([0-9|\\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $webserver_version)) {

    // Apache
    $rows[] = array(
      t('Type'),
      t('Apache'),
    );
    $rows[] = array(
      t('Version'),
      !empty($webserver_version[1]) ? $webserver_version[1] : t('Not found'),
    );
    $rows[] = array(
      t('PHP Interface'),
      FALSE !== stristr(php_sapi_name(), 'cgi') ? t('CGI') : t('Module'),
    );
    if (function_exists('apache_get_modules')) {
      $rows[] = array(
        array(
          'data' => t('Modules'),
          'class' => 'subheader',
          'colspan' => '2',
        ),
      );
      $rows[] = array(
        array(
          'data' => t('mod_rewrite'),
          'class' => 'subitem',
        ),
        in_array('mod_rewrite', apache_get_modules()) ? t('Loaded') : t('Not loaded'),
      );
    }
  }
  elseif (preg_match('/IIS\\/?([0-9|\\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $webserver_version)) {

    // Microsoft IIS
    $rows[] = array(
      t('Type'),
      t('Microsoft IIS'),
    );
    $rows[] = array(
      t('Version'),
      !empty($webserver_version[1]) ? $webserver_version[1] : t('Not found'),
    );
  }
  elseif (preg_match('/lighttpd\\/?([0-9|\\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $webserver_version)) {

    // LightTPD
    $rows[] = array(
      t('Type'),
      t('LightTPD'),
    );
    $rows[] = array(
      t('Version'),
      !empty($webserver_version[1]) ? $webserver_version[1] : t('Not found'),
    );
  }
  else {

    // Unknown
    $rows[] = array(
      t('Type'),
      t('Unknown'),
    );
    $rows[] = array(
      t('SERVER_SOFTWARE'),
      $_SERVER['SERVER_SOFTWARE'],
    );
  }
  $webserver = array(
    '#type' => 'item',
    '#value' => theme('table', $header, $rows, array(
      'class' => 'systeminfo',
    )),
  );
  $output .= drupal_render($webserver);

  // PHP
  $header = array(
    array(
      'data' => t('PHP'),
      'colspan' => '2',
    ),
  );
  $rows = array();
  $rows[] = array(
    t('Version'),
    phpversion(),
  );
  $rows[] = array(
    t('Magic Quotes GPC'),
    ini_get('magic_quotes_gpc') ? t('On') : t('Off'),
  );
  $rows[] = array(
    t('Magic Quotes Runtime'),
    ini_get('magic_quotes_runtime') ? t('On') : t('Off'),
  );
  $rows[] = array(
    t('Memory Limit'),
    ini_get('memory_limit'),
  );
  $rows[] = array(
    t('Register Globals'),
    ini_get('register_globals') ? t('On') : t('Off'),
  );
  $rows[] = array(
    t('Safe Mode'),
    ini_get('safe_mode') ? t('On') : t('Off'),
  );
  $rows[] = array(
    t('Session Cache Limiter'),
    ini_get('session.cache_limiter'),
  );
  $rows[] = array(
    t('Session Save Handler'),
    ini_get('session.save_handler'),
  );
  $rows[] = array(
    t('Upload Max Filesize'),
    ini_get('upload_max_filesize'),
  );

  // PHP extension
  $rows[] = array(
    array(
      'data' => t('Extensions'),
      'class' => 'subheader',
      'colspan' => '2',
    ),
  );
  $rows[] = array(
    array(
      'data' => t('CURL Support'),
      'class' => 'subitem',
    ),
    extension_loaded('curl') ? t('Enabled') : t('Disabled'),
  );
  if (extension_loaded('gd')) {
    $gd = gd_info();
    $rows[] = array(
      array(
        'data' => t('GD Version'),
        'class' => 'subitem',
      ),
      $gd['GD Version'],
    );
    $rows[] = array(
      array(
        'data' => t('FreeType Support'),
        'class' => 'subitem',
      ),
      $gd['FreeType Support'] ? t('Enabled') : t('Disabled'),
    );
  }
  else {
    $rows[] = array(
      array(
        'data' => t('GD Support'),
        'class' => 'subitem',
      ),
      t('Disabled'),
    );
  }
  $rows[] = array(
    array(
      'data' => t('XML Support'),
      'class' => 'subitem',
    ),
    extension_loaded('xml') ? t('Enabled') : t('Disabled'),
  );
  $rows[] = array(
    array(
      'data' => t('Zip Support'),
      'class' => 'subitem',
    ),
    extension_loaded('zip') ? t('Enabled') : t('Disabled'),
  );
  $rows[] = array(
    array(
      'data' => t('Zlib Support'),
      'class' => 'subitem',
    ),
    extension_loaded('zlib') ? t('Enabled') : t('Disabled'),
  );
  $php = array(
    '#type' => 'item',
    '#value' => theme('table', $header, $rows, array(
      'class' => 'systeminfo',
    )),
  );
  $output .= drupal_render($php);

  // Database
  $header = array(
    array(
      'data' => t('Database'),
      'colspan' => '2',
    ),
  );
  $rows = array();
  foreach ($db as $db_key => $db_value) {
    db_set_active($db_key);
    if (is_array($db_url)) {
      $rows[] = array(
        array(
          'data' => $db_key,
          'class' => 'subheader',
          'colspan' => '2',
        ),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Name'),
          'class' => 'subitem',
        ) : t('Name'),
        substr($db_value['path'], 1),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Host'),
          'class' => 'subitem',
        ) : t('Host'),
        $db_value['host'],
      );
    }
    if ('mysql' == $db_value['scheme']) {

      // MySQL
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Type'),
          'class' => 'subitem',
        ) : t('Type'),
        t('MySQL'),
      );
      $db_version = db_result(db_query('SELECT VERSION()'));
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Version'),
          'class' => 'subitem',
        ) : t('Version'),
        $db_version,
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Charset'),
          'class' => 'subitem',
        ) : t('Charset'),
        version_compare($db_version, '4.1.0', '>=') ? db_result(db_query('SELECT CHARSET(USER())')) : t('First from version 4.1'),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Collation'),
          'class' => 'subitem',
        ) : t('Collation'),
        version_compare($db_version, '4.1.0', '>=') ? db_result(db_query('SELECT COLLATION(USER())')) : t('First from version 4.1'),
      );
      $result = db_query('SHOW GRANTS');
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Create Temporary Tables'),
          'class' => 'subitem',
        ) : t('Create Temporary Tables'),
        preg_match('/(ALL PRIVILEGES|CREATE TEMPORARY TABLES)/i', db_result($result, db_num_rows($result) - 1)) ? t('Allowed') : t('Disallowed'),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Lock Tables'),
          'class' => 'subitem',
        ) : t('Lock Tables'),
        preg_match('/(ALL PRIVILEGES|LOCK TABLES)/i', db_result($result, db_num_rows($result) - 1)) ? t('Allowed') : t('Disallowed'),
      );
    }
    elseif ('mysqli' == $db_value['scheme']) {

      // MySQLi
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Type'),
          'class' => 'subitem',
        ) : t('Type'),
        t('MySQLi'),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Version'),
          'class' => 'subitem',
        ) : t('Version'),
        db_result(db_query('SELECT VERSION()')),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Charset'),
          'class' => 'subitem',
        ) : t('Charset'),
        db_result(db_query('SELECT CHARSET(USER())')),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Collation'),
          'class' => 'subitem',
        ) : t('Collation'),
        db_result(db_query('SELECT COLLATION(USER())')),
      );
      $result = db_query('SHOW GRANTS');
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Create Temporary Tables'),
          'class' => 'subitem',
        ) : t('Create Temporary Tables'),
        preg_match('/(ALL PRIVILEGES|CREATE TEMPORARY TABLES)/i', db_result($result, db_num_rows($result) - 1)) ? t('Allowed') : t('Disallowed'),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Lock Tables'),
          'class' => 'subitem',
        ) : t('Lock Tables'),
        preg_match('/(ALL PRIVILEGES|LOCK TABLES)/i', db_result($result, db_num_rows($result) - 1)) ? t('Allowed') : t('Disallowed'),
      );
    }
    elseif ('pgsql' == $db_value['scheme']) {

      // PostgreSQL
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Type'),
          'class' => 'subitem',
        ) : t('Type'),
        t('PostgreSQL'),
      );
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Version'),
          'class' => 'subitem',
        ) : t('Version'),
        db_result(db_query('SELECT VERSION()')),
      );
    }
    else {

      // Unknown
      $rows[] = array(
        is_array($db_url) ? array(
          'data' => t('Type'),
          'class' => 'subitem',
        ) : t('Type'),
        t('Unknown'),
      );
    }
  }
  $database = array(
    '#type' => 'item',
    '#value' => theme('table', $header, $rows, array(
      'class' => 'systeminfo',
    )),
  );
  $output .= drupal_render($database);
  return $output;
}

Functions

Namesort descending Description
systeminfo_display_information Menu callback of page 'system info'.
systeminfo_help Implementation of hook_help().
systeminfo_menu Implementation of hook_menu().
systeminfo_perm Implementation of hook_perm().