[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/inc/ -> functions_serverstats.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  function build_server_stats($is_install=1, $prev_version='', $current_version='', $charset='')
  13  {
  14      $info = array();
  15  
  16      // Is this an upgrade or an install?
  17      if($is_install == 1)
  18      {
  19          $info['is_install'] = 1;
  20      }
  21      else
  22      {
  23          $info['is_install'] = 0;
  24      }
  25  
  26      // If we are upgrading....
  27      if($info['is_install'] == 0)
  28      {
  29          // What was the previous version?
  30          $info['prev_version'] = $prev_version;
  31      }
  32  
  33      // What's our current version?
  34      $info['current_version'] = $current_version;
  35  
  36      // What is our current charset?
  37      $info['charset'] = $charset;
  38  
  39      // Parse phpinfo into array
  40      $phpinfo = parse_php_info();
  41  
  42      // PHP Version
  43      $info['phpversion'] = phpversion();
  44  
  45      // MySQL Version
  46      $info['mysql'] = 0;
  47      if(array_key_exists('mysql', $phpinfo))
  48      {
  49          $info['mysql'] = $phpinfo['mysql']['Client API version'];
  50      }
  51  
  52      // PostgreSQL Version
  53      $info['pgsql'] = 0;
  54      if(array_key_exists('pgsql', $phpinfo))
  55      {
  56          $info['pgsql'] = $phpinfo['pgsql']['PostgreSQL(libpq) Version'];
  57      }
  58  
  59      // SQLite Version
  60      $info['sqlite'] = 0;
  61      if(array_key_exists('sqlite', $phpinfo))
  62      {
  63          $info['sqlite'] = $phpinfo['sqlite']['SQLite Library'];
  64      }
  65  
  66      // Iconv Library Extension Version
  67      $info['iconvlib'] = 0;
  68      if(array_key_exists('iconv', $phpinfo))
  69      {
  70          $info['iconvlib'] = html_entity_decode($phpinfo['iconv']['iconv implementation'])."|".$phpinfo['iconv']['iconv library version'];
  71      }
  72  
  73      // Check GD & Version
  74      $info['gd'] = 0;
  75      if(array_key_exists('gd', $phpinfo))
  76      {
  77          $info['gd'] = $phpinfo['gd']['GD Version'];
  78      }
  79  
  80      // CGI Mode
  81      $sapi_type = php_sapi_name();
  82  
  83      $info['cgimode'] = 0;
  84      if(strpos($sapi_type, 'cgi') !== false)
  85      {
  86          $info['cgimode'] = 1;
  87      }
  88  
  89      // Server Software
  90      $info['server_software'] = $_SERVER['SERVER_SOFTWARE'];
  91  
  92      // Allow url fopen php.ini setting
  93      $info['allow_url_fopen'] = 0;
  94      if(ini_get('safe_mode') == 0 && ini_get('allow_url_fopen'))
  95      {
  96          $info['allow_url_fopen'] = 1;
  97      }
  98  
  99      // Check classes, extensions, php info, functions, and php ini settings
 100      $check = array(
 101          'classes' => array(
 102              'dom' => array('bitwise' => 1, 'title' => 'DOMElement'),
 103              'soap' => array('bitwise' => 2, 'title' => 'SoapClient'),
 104              'xmlwriter' => array('bitwise' => 4, 'title' => 'XMLWriter'),
 105              'imagemagick' => array('bitwise' => 8, 'title' => 'Imagick'),
 106          ),
 107  
 108          'extensions' => array(
 109              'zendopt' => array('bitwise' => 1, 'title' => 'Zend Optimizer'),
 110              'xcache' => array('bitwise' => 2, 'title' => 'XCache'),
 111              'eaccelerator' => array('bitwise' => 4, 'title' => 'eAccelerator'),
 112              'ioncube' => array('bitwise' => 8, 'title' => 'ionCube Loader'),
 113              'PDO' => array('bitwise' => 16, 'title' => 'PDO'),
 114              'pdo_mysql' => array('bitwise' => 32, 'title' => 'pdo_mysql'),
 115              'pdo_pgsql' => array('bitwise' => 64, 'title' => 'pdo_pgsql'),
 116              'pdo_sqlite' => array('bitwise' => 128, 'title' => 'pdo_sqlite'),
 117              'pdo_oci' => array('bitwise' => 256, 'title' => 'pdo_oci'),
 118              'pdo_odbc' => array('bitwise' => 512, 'title' => 'pdo_odbc'),
 119          ),
 120  
 121          'phpinfo' => array(
 122              'zlib' => array('bitwise' => 1, 'title' => 'zlib'),
 123              'mbstring' => array('bitwise' => 2, 'title' => 'mbstring'),
 124              'exif' => array('bitwise' => 4, 'title' => 'exif'),
 125              'zlib' => array('bitwise' => 8, 'title' => 'zlib'),
 126  
 127          ),
 128  
 129          'functions' => array(
 130              'sockets' => array('bitwise' => 1, 'title' => 'fsockopen'),
 131              'mcrypt' => array('bitwise' => 2, 'title' => 'mcrypt_encrypt'),
 132              'simplexml' => array('bitwise' => 4, 'title' => 'simplexml_load_string'),
 133              'ldap' => array('bitwise' => 8, 'title' => 'ldap_connect'),
 134              'mysqli' => array('bitwise' => 16, 'title' => 'mysqli_connect'),
 135              'imap' => array('bitwise' => 32, 'title' => 'imap_open'),
 136              'ftp' => array('bitwise' => 64, 'title' => 'ftp_login'),
 137              'pspell' => array('bitwise' => 128, 'title' => 'pspell_new'),
 138              'apc' => array('bitwise' => 256, 'title' => 'apc_cache_info'),
 139              'curl' => array('bitwise' => 512, 'title' => 'curl_init'),
 140              'iconv' => array('bitwise' => 1024, 'title' => 'iconv'),
 141          ),
 142  
 143          'php_ini' => array(
 144              'post_max_size' => 'post_max_size',
 145              'upload_max_filesize' => 'upload_max_filesize',
 146              'safe_mode' => 'safe_mode',
 147          ),
 148      );
 149  
 150      foreach($check as $cat_name => $category)
 151      {
 152          foreach($category as $name => $what)
 153          {
 154              switch($cat_name)
 155              {
 156                  case "classes":
 157                      if(class_exists($what['title']))
 158                      {
 159                          $info[$cat_name] |= $what['bitwise'];
 160                      }
 161                      break;
 162                  case "extensions":
 163                      if(extension_loaded($what['title']))
 164                      {
 165                          $info[$cat_name] |= $what['bitwise'];
 166                      }
 167                      break;
 168                  case "phpinfo":
 169                      if(array_key_exists($what['title'], $phpinfo))
 170                      {
 171                          $info[$cat_name] |= $what['bitwise'];
 172                      }
 173                      break;
 174                  case "functions":
 175                      if(function_exists($what['title']))
 176                      {
 177                          $info[$cat_name] |= $what['bitwise'];
 178                      }
 179                      break;
 180                  case "php_ini":
 181                      if(ini_get($what) != 0)
 182                      {
 183                          $info[$name] = ini_get($what);
 184                      }
 185                      else
 186                      {
 187                          $info[$name] = 0;
 188                      }
 189                      break;
 190              }
 191          }
 192      }
 193  
 194      // Host URL & hostname
 195      $info['hosturl'] = $info['hostname'] = "unknown/local";
 196      if($_SERVER['HTTP_HOST'] == 'localhost')
 197      {
 198          $info['hosturl'] = $info['hostname'] = "localhost";
 199      }
 200  
 201      // Check the hosting company
 202      if(strpos($_SERVER['HTTP_HOST'], ".") !== false)
 203      {
 204          $host_url = "http://www.whoishostingthis.com/".str_replace(array('http://', 'www.'), '', $_SERVER['HTTP_HOST']);
 205  
 206          $hosting = fetch_remote_file($host_url);
 207  
 208          if($hosting)
 209          {
 210              preg_match('#We believe \<a href\="http:\/\/www.whoishostingthis.com\/linkout\/\?t\=[0-9]&url\=?([^"]*)" (title="([^"]*)" )target\=\_blank\>([^<]*)\<\/a\>#ism', $hosting, $matches);
 211  
 212              $info['hosturl'] = "unknown/no-url";
 213              if(isset($matches[1]) && strlen(trim($matches[1])) != 0 && strpos($matches[1], '.') !== false)
 214              {
 215                  $info['hosturl'] = strtolower($matches[1]);
 216              }
 217              else if(isset($matches[3]) && strlen(trim($matches[3])) != 0 && strpos($matches[3], '.') !== false)
 218              {
 219                  $info['hosturl'] = strtolower($matches[3]);
 220              }
 221  
 222              if(isset($matches[4]) && strlen(trim($matches[4])) != 0)
 223              {
 224                  $info['hostname'] = $matches[4];
 225              }
 226              elseif(isset($matches[3]) && strlen(trim($matches[3])) != 0)
 227              {
 228                  $info['hostname'] = $matches[3];
 229              }
 230              elseif(isset($matches[2]) && strlen(trim($matches[2])) != 0)
 231              {
 232                  $info['hostname'] = str_replace(array('title=', '"'), '', $matches[2][0]);
 233              }
 234              elseif(strlen(trim($info['hosturl'])) != 0 && $info['hosturl'] != "unknown/no-url")
 235              {
 236                  $info['hostname'] = $info['hosturl'];
 237              }
 238              else
 239              {
 240                  $info['hostname'] = "unknown/no-name";
 241              }
 242          }
 243      }
 244  
 245      if(isset($_SERVER['HTTP_USER_AGENT']))
 246      {
 247          $info['useragent'] = $_SERVER['HTTP_USER_AGENT'];
 248      }
 249  
 250      // We need a unique ID for the host so hash it to keep it private and send it over
 251      $id = $_SERVER['HTTP_HOST'].time();
 252  
 253      if(function_exists('sha1'))
 254      {
 255          $info['id'] = sha1($id);
 256      }
 257      else
 258      {
 259          $info['id'] = md5($id);
 260      }
 261  
 262      $string = "";
 263      $amp = "";
 264      foreach($info as $key => $value)
 265      {
 266          $string .= $amp.$key."=".urlencode($value);
 267          $amp = "&amp;";
 268      }
 269  
 270      $server_stats_url = 'http://www.mybb.com/stats.php?'.$string;
 271  
 272      $return = array();
 273      $return['info_sent_success'] = false;
 274      if(fetch_remote_file($url) !== false)
 275      {
 276          $return['info_sent_success'] = true;
 277      }
 278      $return['info_image'] = "<img src='http://www.mybb.com/stats.php?{$string}&amp;img=1' />";
 279      $return['info_get_string'] = $string;
 280  
 281      return $return;
 282  }
 283  
 284  /**
 285  * parser_php_info
 286  * Function to get and parse the list of PHP info into a usuable array
 287  *
 288  * @return Array An array of all the extensions installed in PHP
 289  */
 290  function parse_php_info()
 291  {
 292      ob_start();
 293      phpinfo(INFO_MODULES);
 294      $phpinfo_html = ob_get_contents();
 295      ob_end_clean();
 296  
 297      $phpinfo_html = strip_tags($phpinfo_html, "<h2><th><td>");
 298      $phpinfo_html = preg_replace("#<th[^>]*>([^<]+)<\/th>#", "<info>$1</info>", $phpinfo_html);
 299      $phpinfo_html = preg_replace("#<td[^>]*>([^<]+)<\/td>#", "<info>$1</info>", $phpinfo_html);
 300      $phpinfo_html = preg_split("#(<h2[^>]*>[^<]+<\/h2>)#", $phpinfo_html, -1, PREG_SPLIT_DELIM_CAPTURE);
 301      $modules = array();
 302  
 303      for($i=1; $i < count($phpinfo_html); $i++)
 304      {
 305          if(preg_match("#<h2[^>]*>([^<]+)<\/h2>#", $phpinfo_html[$i], $match))
 306          {
 307              $name = trim($match[1]);
 308              $tmp2 = explode("\n", $phpinfo_html[$i+1]);
 309              foreach($tmp2 as $one)
 310              {
 311                  $pat = '<info>([^<]+)<\/info>';
 312                  $pat3 = "/$pat\s*$pat\s*$pat/";
 313                  $pat2 = "/$pat\s*$pat/";
 314  
 315                  // 3 columns
 316                  if(preg_match($pat3, $one, $match))
 317                  {
 318                      $modules[$name][trim($match[1])] = array(trim($match[2]), trim($match[3]));
 319                  }
 320                  // 2 columns
 321                  else if(preg_match($pat2, $one, $match))
 322                  {
 323                      $modules[$name][trim($match[1])] = trim($match[2]);
 324                  }
 325              }
 326          }
 327      }
 328      return $modules;
 329  }
 330  
 331  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1