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