You are here

function systeminfo_display_information in System Information 6

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

Menu callback of page 'System information'.

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

File

./systeminfo.module, line 97
Displays information about the Drupal installation and system environment.

Code

function systeminfo_display_information() {
  global $base_url, $db_url, $db_prefix;
  $output = '';
  drupal_add_css(drupal_get_path('module', 'systeminfo') . '/systeminfo.css');

  // Drupal
  $output_fieldset = '';
  $output_fieldset .= '<p>' . t('More information about the Drupal installation can be found <a href="@drupal" title="Display information about the Drupal installation.">here</a>.', array(
    '@drupal' => url('admin/reports/systeminfo/drupal'),
  )) . '</p>';
  $rows = array();
  $rows[] = array(
    t('Version'),
    VERSION,
  );
  $rows[] = array(
    t('Configuration file'),
    conf_path() . '/settings.php',
  );
  $cron_last = variable_get('cron_last', NULL);
  $rows[] = array(
    t('Cron'),
    isset($cron_last) ? t('Last run !time ago', array(
      '!time' => format_interval(time() - $cron_last),
    )) : t('Not run yet'),
  );
  $rows[] = array(
    t('File system path'),
    file_directory_path(),
  );
  $output_fieldset .= theme('table', NULL, $rows, array(
    'class' => 'systeminfo systeminfo_width50',
  ));
  $output_fieldset .= '<h4>' . t('Content') . '</h4>';
  $rows = array();
  $rows[] = array(
    t('Total'),
    t('!nodes', array(
      '!nodes' => format_plural(db_result(db_query("SELECT COUNT(nid) FROM {node}")), '1 node', '@count nodes'),
    )),
  );
  $types = array();
  $result = db_query("SELECT n.type, nt.name, COUNT(n.nid) AS count FROM {node} n LEFT JOIN {node_type} nt ON n.type = nt.type GROUP BY n.type, nt.name");
  while ($type = db_fetch_object($result)) {
    $key = $type->name ? $type->name : $type->type;
    $name = $type->name ? $type->name : $type->type;
    $types[$key] = array(
      array(
        'data' => check_plain($name),
        'class' => 'text1',
      ),
      t('!nodes', array(
        '!nodes' => format_plural($type->count, '1 node', '@count nodes'),
      )),
    );
  }
  ksort($types);
  if (!empty($types)) {
    $rows[] = array(
      array(
        'data' => t('Content types'),
        'class' => 'title1',
        'colspan' => '2',
      ),
    );
    $rows += $types;
  }
  $output_fieldset .= theme('table', NULL, $rows, array(
    'class' => 'systeminfo systeminfo_width50',
  ));
  $output_fieldset .= '<h4>' . t('Users') . '</h4>';
  $rows = array();
  $rows[] = array(
    t('Total'),
    t('!accounts', array(
      '!accounts' => format_plural(db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid <> 0")), '1 account', '@count accounts'),
    )),
  );
  $rows[] = array(
    array(
      'data' => t('Status'),
      'class' => 'title1',
      'colspan' => '2',
    ),
  );
  $rows[] = array(
    array(
      'data' => t('Active'),
      'class' => 'text1',
    ),
    t('!accounts', array(
      '!accounts' => format_plural(db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid <> 0 AND status = 1")), '1 account', '@count accounts'),
    )),
  );
  $rows[] = array(
    array(
      'data' => t('Blocked'),
      'class' => 'text1',
    ),
    t('!accounts', array(
      '!accounts' => format_plural(db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid <> 0 AND status = 0")), '1 account', '@count accounts'),
    )),
  );
  $output_fieldset .= theme('table', NULL, $rows, array(
    'class' => 'systeminfo systeminfo_width50',
  ));
  $output_fieldset .= '<h4>' . t('Modules') . '</h4>';
  $rows = array();
  foreach (module_list() as $module) {
    $file = db_fetch_object(db_query("SELECT info FROM {system} WHERE type = 'module' AND name = '%s'", $module));
    $file->info = unserialize($file->info);
    $rows[$file->info['name']] = array(
      $file->info['name'],
      $file->info['version'],
    );
  }
  ksort($rows);
  $output_fieldset .= theme('table', NULL, $rows, array(
    'class' => 'systeminfo systeminfo_width50',
  ));
  $output_fieldset .= '<h4>' . t('Themes') . '</h4>';
  $rows = array();
  foreach (list_themes() as $theme) {
    if ($theme->status) {
      $rows[$theme->name] = array(
        $theme->info['name'],
        $theme->info['version'],
      );
    }
  }
  ksort($rows);
  $output_fieldset .= theme('table', NULL, $rows, array(
    'class' => 'systeminfo systeminfo_width50',
  ));
  $fieldset = array(
    '#type' => 'fieldset',
    '#title' => 'Drupal',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#value' => $output_fieldset,
  );
  $output .= theme('fieldset', $fieldset);

  // Web server
  $output_fieldset = '';
  if (preg_match('/Apache\\/?([0-9|\\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $version)) {
    $webserver_type = 'apache';
    $webserver_name = 'Apache';
    $webserver_version = !empty($version[1]) ? $version[1] : t('Unknown');
    if (function_exists('apache_get_modules')) {
      $apache_modules = apache_get_modules();
    }
  }
  elseif (preg_match('/lighttpd\\/?([0-9|\\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $version)) {
    $webserver_type = 'lighttpd';
    $webserver_name = 'LightTPD';
    $webserver_version = !empty($version[1]) ? $version[1] : t('Unknown');
  }
  elseif (preg_match('/IIS\\/?([0-9|\\.]*)/i', $_SERVER['SERVER_SOFTWARE'], $version)) {
    $webserver_type = 'iis';
    $webserver_name = 'Microsoft IIS';
    $webserver_version = !empty($version[1]) ? $version[1] : t('Unknown');
  }
  else {
    $webserver_type = 'unknown';
    $webserver_name = t('Unknown');
    $webserver_version = $_SERVER['SERVER_SOFTWARE'];
  }
  $rows = array();
  $rows[] = array(
    t('Type'),
    $webserver_name,
  );
  $rows[] = array(
    t('Version'),
    $webserver_version,
  );
  $rows[] = array(
    t('IP address'),
    $_SERVER['SERVER_ADDR'],
  );
  $rows[] = array(
    t('Operating system'),
    php_uname('s'),
  );
  if ($webserver_type == 'apache') {
    $rows[] = array(
      t('PHP interface'),
      php_sapi_name(),
    );
  }
  $rows[] = array(
    t('URL'),
    $base_url,
  );
  $output_fieldset .= theme('table', NULL, $rows, array(
    'class' => 'systeminfo systeminfo_width50',
  ));
  if (isset($apache_modules)) {
    $output_fieldset .= '<h4>' . t('Apache modules') . '</h4>';
    $rows = array();
    $rows[] = array(
      t('Info'),
      in_array('mod_info', $apache_modules) ? t('Loaded') : t('Not loaded'),
    );
    $rows[] = array(
      t('Rewrite'),
      in_array('mod_rewrite', $apache_modules) ? t('Loaded') : t('Not loaded'),
    );
    $rows[] = array(
      t('SSL'),
      in_array('mod_ssl', $apache_modules) ? t('Loaded') : t('Not loaded'),
    );
    $rows[] = array(
      t('Status'),
      in_array('mod_status', $apache_modules) ? t('Loaded') : t('Not loaded'),
    );
    $output_fieldset .= theme('table', NULL, $rows, array(
      'class' => 'systeminfo systeminfo_width50',
    ));
  }
  $fieldset = array(
    '#type' => 'fieldset',
    '#title' => t('Web server'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#value' => $output_fieldset,
  );
  $output .= theme('fieldset', $fieldset);

  // PHP
  $output_fieldset = '';
  $output_fieldset .= '<p>' . t('More information about the current state of PHP can be found <a href="@php" title="Display current state of PHP." >here</a>.', array(
    '@php' => url('admin/reports/systeminfo/php'),
  )) . '</p>';
  $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('Max execution time'),
    ini_get('max_execution_time'),
  );
  $rows[] = array(
    t('Max input time'),
    ini_get('max_input_time'),
  );
  $rows[] = array(
    t('Memory limit'),
    ini_get('memory_limit'),
  );
  $rows[] = array(
    t('Post max size'),
    ini_get('post_max_size'),
  );
  $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'),
  );
  $cookie_params = session_get_cookie_params();
  $rows[] = array(
    t('Session cookie domain'),
    !empty($cookie_params['domain']) ? $cookie_params['domain'] : theme('placeholder', t('no value')),
  );
  $rows[] = array(
    t('Session name'),
    session_name(),
  );
  $rows[] = array(
    t('Session save handler'),
    ini_get('session.save_handler'),
  );
  $rows[] = array(
    t('Upload max filesize'),
    ini_get('upload_max_filesize'),
  );
  $output_fieldset .= theme('table', NULL, $rows, array(
    'class' => 'systeminfo systeminfo_width50',
  ));
  $output_fieldset .= '<h4>' . t('PHP extensions') . '</h4>';
  $rows = array();
  if (extension_loaded('curl')) {
    $curl = curl_version();
    $rows[] = array(
      t('cURL version'),
      $curl['version'],
    );
  }
  else {
    $rows[] = array(
      t('cURL support'),
      t('Disabled'),
    );
  }
  if (extension_loaded('gd')) {
    $gd = gd_info();
    $rows[] = array(
      t('GD version'),
      $gd['GD Version'],
    );
    $rows[] = array(
      array(
        'data' => t('FreeType support'),
        'class' => 'text1',
      ),
      $gd['FreeType Support'] ? t('Enabled') : t('Disabled'),
    );
    $rows[] = array(
      array(
        'data' => t('JPG support'),
        'class' => 'text1',
      ),
      $gd['JPG Support'] ? t('Enabled') : t('Disabled'),
    );
    $rows[] = array(
      array(
        'data' => t('PNG support'),
        'class' => 'text1',
      ),
      $gd['PNG Support'] ? t('Enabled') : t('Disabled'),
    );
  }
  else {
    $rows[] = array(
      t('GD support'),
      t('Disabled'),
    );
  }
  $rows[] = array(
    t('Multibyte support'),
    extension_loaded('mbstring') ? t('Enabled') : t('Disabled'),
  );
  $rows[] = array(
    t('XML support'),
    extension_loaded('xml') ? t('Enabled') : t('Disabled'),
  );
  $rows[] = array(
    t('Zip support'),
    extension_loaded('zip') ? t('Enabled') : t('Disabled'),
  );
  $rows[] = array(
    t('Zlib support'),
    extension_loaded('zlib') ? t('Enabled') : t('Disabled'),
  );
  $output_fieldset .= theme('table', NULL, $rows, array(
    'class' => 'systeminfo systeminfo_width50',
  ));
  $fieldset = array(
    '#type' => 'fieldset',
    '#title' => 'PHP',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#value' => $output_fieldset,
  );
  $output .= theme('fieldset', $fieldset);

  // Database server
  $output_fieldset = '';
  $output_fieldset .= '<p>' . t('More information about the database server can be found <a href="@database" title="Display information about the database server.">here</a>.', array(
    '@database' => url('admin/reports/systeminfo/database'),
  )) . '</p>';
  $databases = !is_array($db_url) ? array(
    'default' => $db_url,
  ) : $db_url;
  foreach ($databases as $connection => $database) {
    db_set_active($connection);
    $db = parse_url($database);
    if ('mysql' == $db['scheme']) {
      $database_type = 'MySQL';
      $database_version = db_version();
      $database_port = isset($db['port']) ? $db['port'] : '3306';
      $storage_engine = db_fetch_object(db_query("SHOW VARIABLES LIKE 'storage_engine'"));
      $database_storage_engine = $storage_engine->Value;
      $uptime = db_fetch_object(db_query("SHOW STATUS LIKE 'Uptime'"));
      $database_uptime = $uptime->Value;
    }
    elseif ('mysqli' == $db['scheme']) {
      $database_type = 'MySQLi';
      $database_version = db_version();
      $database_port = isset($db['port']) ? $db['port'] : '3306';
      $storage_engine = db_fetch_object(db_query("SHOW VARIABLES LIKE 'storage_engine'"));
      $database_storage_engine = $storage_engine->Value;
      $uptime = db_fetch_object(db_query("SHOW STATUS LIKE 'Uptime'"));
      $database_uptime = $uptime->Value;
    }
    elseif ('pgsql' == $db['scheme']) {
      $database_type = 'PostgreSQL';
      $database_version = db_version();
      $database_port = isset($db['port']) ? $db['port'] : '5432';
      $database_storage_engine = NULL;
      $database_uptime = NULL;
    }
    else {
      $database_type = t('Unknown');
      $database_version = t('Unknown');
      $database_port = t('Unknown');
      $database_uptime = NULL;
      $database_storage_engine = NULL;
    }
    $database_name = substr($db['path'], 1);
    $database_host = $db['host'];
    $output_fieldset .= '<h4>' . t('Database connection: %connection', array(
      '%connection' => $connection,
    )) . '</h4>';
    $rows = array();
    $rows[] = array(
      t('Name'),
      $database_name,
    );
    $rows[] = array(
      t('Type'),
      $database_type,
    );
    $rows[] = array(
      t('Version'),
      $database_version,
    );
    $rows[] = array(
      t('Host'),
      $database_host,
    );
    $rows[] = array(
      t('Port'),
      $database_port,
    );
    if ('mysql' == $db['scheme'] && version_compare($database_version, '4.1.0', '>=') || 'mysqli' == $db['scheme']) {
      $rows[] = array(
        t('Charset'),
        db_result(db_query("SELECT CHARSET(USER())")),
      );
      $rows[] = array(
        t('Collation'),
        db_result(db_query("SELECT COLLATION(USER())")),
      );
    }
    if ($database_storage_engine) {
      $rows[] = array(
        t('Storage engine'),
        $database_storage_engine,
      );
    }
    if ($database_uptime) {
      $rows[] = array(
        t('Uptime'),
        format_interval($database_uptime),
      );
    }
    if ('mysql' == $db['scheme'] || 'mysqli' == $db['scheme']) {
      $result = db_query("SHOW GRANTS");
      while ($grants = current(db_fetch_array($result))) {
        if (preg_match('/(ALL PRIVILEGES|SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER|INDEX|DROP|CREATE TEMPORARY TABLES|LOCK TABLES)/i', $grants)) {
          $rows[] = array(
            array(
              'data' => t('Permissions'),
              'class' => 'title1',
              'colspan' => '2',
            ),
          );
          $rows[] = array(
            array(
              'data' => 'SELECT',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|SELECT)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'INSERT',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|INSERT)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'UPDATE',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|UPDATE)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'DELETE',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|DELETE)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'CREATE',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|CREATE)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'ALTER',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|ALTER)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'INDEX',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|INDEX)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'DROP',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|DROP)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'CREATE TEMPORARY TABLES',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|CREATE TEMPORARY TABLES)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          $rows[] = array(
            array(
              'data' => 'LOCK TABLES',
              'class' => 'text1',
            ),
            preg_match('/(ALL PRIVILEGES|LOCK TABLES)/i', $grants) ? t('Allowed') : t('Disallowed'),
          );
          break;
        }
      }
    }
    $rows[] = array(
      array(
        'data' => t('Table prefixes'),
        'class' => 'title1',
        'colspan' => '2',
      ),
    );
    $prefixes = !is_array($db_prefix) ? array(
      'default' => $db_prefix,
    ) : $db_prefix;
    foreach ($prefixes as $table => $databasename_prefix) {
      $databasename = NULL;
      $prefix = NULL;
      if (!empty($databasename_prefix)) {
        list($databasename, $prefix) = explode('.', $databasename_prefix);
      }
      if (empty($databasename) || $databasename == $database_name) {
        $rows[] = array(
          array(
            'data' => $table,
            'class' => 'text1',
          ),
          !empty($prefix) ? $prefix : theme('placeholder', t('no value')),
        );
      }
    }
    $output_fieldset .= theme('table', NULL, $rows, array(
      'class' => 'systeminfo systeminfo_width50',
    ));
  }
  db_set_active();
  $fieldset = array(
    '#type' => 'fieldset',
    '#title' => t('Database server'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#value' => $output_fieldset,
  );
  $output .= theme('fieldset', $fieldset);
  return $output;
}