You are here

function systeminfo_display_information in System Information 5

Same name and namespace in other branches
  1. 5.2 systeminfo.module \systeminfo_display_information()
  2. 6 systeminfo.module \systeminfo_display_information()
  3. 6.2 systeminfo.module \systeminfo_display_information()

Menu callback of page 'system info'.

1 string reference to 'systeminfo_display_information'
systeminfo_menu in ./systeminfo.module
Implementation of hook_menu().

File

./systeminfo.module, line 77
Displays information of the drupal install and system environment.

Code

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;
}