[ Index ]

PHP Cross Reference of MyBB 1.8.37

title

Body

[close]

/inc/ -> functions_serverstats.php (source)

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


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref