6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
20 * This class collects data which is used to create some usage statistics.
22 * The collected data is - after authorization of the administrator - submitted
23 * to a central server. For privacy reasons we try to collect only data which aren't private
24 * or don't give any information which might help to identify the user.
26 * @author Johannes Schlueter <johannes@php.net>
27 * @copyright (c) 2007-2008 Johannes Schlueter
29 class phpbb_questionnaire_data_collector
40 function phpbb_questionnaire_data_collector($install_id)
42 $this->install_id = $install_id;
43 $this->providers = array();
46 function add_data_provider(&$provider)
48 $this->providers[] = &$provider;
52 * Get data as an array.
54 * @return array All Data
56 function get_data_raw()
66 function get_data_for_form()
68 return base64_encode(serialize($this->get_data_raw()));
72 * Collect info into the data property.
78 foreach (array_keys($this->providers) as $key)
80 $provider = &$this->providers[$key];
81 $this->data[$provider->get_identifier()] = $provider->get_data();
83 $this->data['install_id'] = $this->install_id;
87 /** interface: get_indentifier(), get_data() */
90 * Questionnaire PHP data provider
93 class phpbb_questionnaire_php_data_provider
95 function get_identifier()
101 * Get data about the PHP runtime setup.
108 'version' => PHP_VERSION,
110 'int_size' => defined('PHP_INT_SIZE') ? PHP_INT_SIZE : '',
111 'safe_mode' => (int) @ini_get('safe_mode'),
112 'open_basedir' => (int) @ini_get('open_basedir'),
113 'memory_limit' => @ini_get('memory_limit'),
114 'allow_url_fopen' => (int) @ini_get('allow_url_fopen'),
115 'allow_url_include' => (int) @ini_get('allow_url_include'),
116 'file_uploads' => (int) @ini_get('file_uploads'),
117 'upload_max_filesize' => @ini_get('upload_max_filesize'),
118 'post_max_size' => @ini_get('post_max_size'),
119 'disable_functions' => @ini_get('disable_functions'),
120 'disable_classes' => @ini_get('disable_classes'),
121 'enable_dl' => (int) @ini_get('enable_dl'),
122 'magic_quotes_gpc' => (int) @ini_get('magic_quotes_gpc'),
123 'register_globals' => (int) @ini_get('register_globals'),
124 'filter.default' => @ini_get('filter.default'),
125 'zend.ze1_compatibility_mode' => (int) @ini_get('zend.ze1_compatibility_mode'),
126 'unicode.semantics' => (int) @ini_get('unicode.semantics'),
127 'zend_thread_safty' => (int) function_exists('zend_thread_id'),
128 'extensions' => get_loaded_extensions(),
134 * Questionnaire System data provider
137 class phpbb_questionnaire_system_data_provider
139 function get_identifier()
145 * Get data about the general system information, like OS or IP (shortened).
151 // Start discovering the IPV4 server address, if available
152 $server_address = '0.0.0.0';
154 if (!empty($_SERVER['SERVER_ADDR']))
156 $server_address = $_SERVER['SERVER_ADDR'];
160 if (!empty($_SERVER['LOCAL_ADDR']))
162 $server_address = $_SERVER['LOCAL_ADDR'];
167 'httpd' => $_SERVER['SERVER_SOFTWARE'],
168 // we don't want the real IP address (for privacy policy reasons) but only
169 // a network address to see whether your installation is running on a private or public network.
170 'private_ip' => $this->is_private_ip($server_address),
171 'ipv6' => strpos($server_address, ':') !== false,
176 * Checks whether the given IP is in a private network.
178 * @param string $ip IP in v4 dot-decimal or v6 hex format
179 * @return bool true if the IP is from a private network, else false
181 function is_private_ip($ip)
184 if (strpos($ip, ':') === false)
186 $ip_address_ary = explode('.', $ip);
189 if (!isset($ip_address_ary[0]) || !isset($ip_address_ary[1]))
191 $ip_address_ary = explode('.', '0.0.0.0');
194 // IANA reserved addresses for private networks (RFC 1918) are:
198 if ($ip_address_ary[0] == '10' ||
199 ($ip_address_ary[0] == '172' && intval($ip_address_ary[1]) > 15 && intval($ip_address_ary[1]) < 32) ||
200 ($ip_address_ary[0] == '192' && $ip_address_ary[1] == '168') ||
201 ($ip_address_ary[0] == '192' && $ip_address_ary[1] == '168'))
209 // unique local unicast
210 $prefix = substr($ip, 0, 2);
211 if ($prefix == 'fc' || $prefix == 'fd')
222 * Questionnaire phpBB data provider
225 class phpbb_questionnaire_phpbb_data_provider
233 * @param array $config
235 function phpbb_questionnaire_phpbb_data_provider($config)
237 // generate a unique id if necessary
238 if (empty($config['questionnaire_unique_id']))
240 $this->unique_id = unique_id();
241 set_config('questionnaire_unique_id', $this->unique_id);
245 $this->unique_id = $config['questionnaire_unique_id'];
248 $this->config = $config;
252 * Returns a string identifier for this data provider
254 * @return string "phpBB"
256 function get_identifier()
262 * Get data about this phpBB installation.
264 * @return array Relevant anonymous config options
268 global $phpbb_root_path, $phpEx;
269 include("{$phpbb_root_path}config.$phpEx");
270 unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution
272 // Only send certain config vars
273 $config_vars = array(
274 'active_sessions' => true,
275 'allow_attachments' => true,
276 'allow_autologin' => true,
277 'allow_avatar' => true,
278 'allow_avatar_local' => true,
279 'allow_avatar_remote' => true,
280 'allow_avatar_upload' => true,
281 'allow_bbcode' => true,
282 'allow_birthdays' => true,
283 'allow_bookmarks' => true,
284 'allow_emailreuse' => true,
285 'allow_forum_notify' => true,
286 'allow_mass_pm' => true,
287 'allow_name_chars' => true,
288 'allow_namechange' => true,
289 'allow_nocensors' => true,
290 'allow_pm_attach' => true,
291 'allow_pm_report' => true,
292 'allow_post_flash' => true,
293 'allow_post_links' => true,
294 'allow_privmsg' => true,
295 'allow_quick_reply' => true,
297 'allow_sig_bbcode' => true,
298 'allow_sig_flash' => true,
299 'allow_sig_img' => true,
300 'allow_sig_links' => true,
301 'allow_sig_pm' => true,
302 'allow_sig_smilies' => true,
303 'allow_smilies' => true,
304 'allow_topic_notify' => true,
305 'attachment_quota' => true,
306 'auth_bbcode_pm' => true,
307 'auth_flash_pm' => true,
308 'auth_img_pm' => true,
309 'auth_method' => true,
310 'auth_smilies_pm' => true,
311 'avatar_filesize' => true,
312 'avatar_max_height' => true,
313 'avatar_max_width' => true,
314 'avatar_min_height' => true,
315 'avatar_min_width' => true,
317 'board_email_form' => true,
318 'board_hide_emails' => true,
319 'board_timezone' => true,
320 'browser_check' => true,
321 'bump_interval' => true,
324 'captcha_plugin' => true,
325 'captcha_gd' => true,
326 'captcha_gd_foreground_noise' => true,
327 'captcha_gd_x_grid' => true,
328 'captcha_gd_y_grid' => true,
329 'captcha_gd_wave' => true,
330 'captcha_gd_3d_noise' => true,
331 'captcha_gd_fonts' => true,
332 'confirm_refresh' => true,
333 'check_attachment_content' => true,
334 'check_dnsbl' => true,
335 'chg_passforce' => true,
336 'cookie_secure' => true,
337 'coppa_enable' => true,
338 'database_gc' => true,
339 'dbms_version' => true,
340 'default_dateformat' => true,
341 'default_lang' => true,
342 'display_last_edited' => true,
343 'display_order' => true,
345 'email_check_mx' => true,
346 'email_enable' => true,
347 'email_function_name' => true,
348 'email_package_size' => true,
349 'enable_confirm' => true,
350 'enable_pm_icons' => true,
351 'enable_post_confirm' => true,
352 'feed_enable' => true,
353 'feed_http_auth' => true,
354 'feed_limit_post' => true,
355 'feed_limit_topic' => true,
356 'feed_overall' => true,
357 'feed_overall_forums' => true,
358 'feed_forum' => true,
359 'feed_topic' => true,
360 'feed_topics_new' => true,
361 'feed_topics_active' => true,
362 'feed_item_statistics' => true,
363 'flood_interval' => true,
364 'force_server_vars' => true,
365 'form_token_lifetime' => true,
366 'form_token_mintime' => true,
367 'form_token_sid_guests' => true,
368 'forward_pm' => true,
369 'forwarded_for_check' => true,
370 'full_folder_action' => true,
371 'fulltext_native_common_thres' => true,
372 'fulltext_native_load_upd' => true,
373 'fulltext_native_max_chars' => true,
374 'fulltext_native_min_chars' => true,
375 'gzip_compress' => true,
376 'hot_threshold' => true,
377 'img_create_thumbnail' => true,
378 'img_display_inlined' => true,
379 'img_imagick' => true,
380 'img_link_height' => true,
381 'img_link_width' => true,
382 'img_max_height' => true,
383 'img_max_thumb_width' => true,
384 'img_max_width' => true,
385 'img_min_thumb_filesize' => true,
387 'jab_enable' => true,
388 'jab_package_size' => true,
389 'jab_use_ssl' => true,
390 'limit_load' => true,
391 'limit_search_load' => true,
392 'load_anon_lastread' => true,
393 'load_birthdays' => true,
394 'load_cpf_memberlist' => true,
395 'load_cpf_viewprofile' => true,
396 'load_cpf_viewtopic' => true,
397 'load_db_lastread' => true,
398 'load_db_track' => true,
399 'load_jumpbox' => true,
400 'load_moderators' => true,
401 'load_online' => true,
402 'load_online_guests' => true,
403 'load_online_time' => true,
404 'load_onlinetrack' => true,
405 'load_search' => true,
406 'load_tplcompile' => true,
407 'load_user_activity' => true,
408 'max_attachments' => true,
409 'max_attachments_pm' => true,
410 'max_autologin_time' => true,
411 'max_filesize' => true,
412 'max_filesize_pm' => true,
413 'max_login_attempts' => true,
414 'max_name_chars' => true,
415 'max_num_search_keywords' => true,
416 'max_pass_chars' => true,
417 'max_poll_options' => true,
418 'max_post_chars' => true,
419 'max_post_font_size' => true,
420 'max_post_img_height' => true,
421 'max_post_img_width' => true,
422 'max_post_smilies' => true,
423 'max_post_urls' => true,
424 'max_quote_depth' => true,
425 'max_reg_attempts' => true,
426 'max_sig_chars' => true,
427 'max_sig_font_size' => true,
428 'max_sig_img_height' => true,
429 'max_sig_img_width' => true,
430 'max_sig_smilies' => true,
431 'max_sig_urls' => true,
432 'min_name_chars' => true,
433 'min_pass_chars' => true,
434 'min_post_chars' => true,
435 'min_search_author_chars' => true,
436 'mime_triggers' => true,
437 'new_member_post_limit' => true,
438 'new_member_group_default' => true,
439 'override_user_style' => true,
440 'pass_complex' => true,
441 'pm_edit_time' => true,
442 'pm_max_boxes' => true,
443 'pm_max_msgs' => true,
444 'pm_max_recipients' => true,
445 'posts_per_page' => true,
447 'queue_interval' => true,
448 'require_activation' => true,
449 'referer_validation' => true,
450 'search_block_size' => true,
452 'search_interval' => true,
453 'search_anonymous_interval' => true,
454 'search_type' => true,
455 'search_store_results' => true,
456 'secure_allow_deny' => true,
457 'secure_allow_empty_referer' => true,
458 'secure_downloads' => true,
459 'session_gc' => true,
460 'session_length' => true,
461 'smtp_auth_method' => true,
462 'smtp_delivery' => true,
463 'topics_per_page' => true,
464 'tpl_allow_php' => true,
466 'warnings_expire_days' => true,
467 'warnings_gc' => true,
471 'num_topics' => true,
473 'record_online_users' => true,
477 foreach ($config_vars as $name => $void)
479 if (isset($this->config[$name]))
481 $result['config_' . $name] = $this->config[$name];
487 $result['dbms'] = $dbms;
488 $result['acm_type'] = $acm_type;
489 $result['load_extensions'] = $load_extensions;
490 $result['user_agent'] = 'Unknown';
491 $result['dbms_version'] = $db->sql_server_info(true);
493 // Try to get user agent vendor and version
495 $user_agent = (!empty($_SERVER['HTTP_USER_AGENT'])) ? (string) $_SERVER['HTTP_USER_AGENT'] : '';
496 $agents = array('firefox', 'msie', 'opera', 'chrome', 'safari', 'mozilla', 'seamonkey', 'konqueror', 'netscape', 'gecko', 'navigator', 'mosaic', 'lynx', 'amaya', 'omniweb', 'avant', 'camino', 'flock', 'aol');
498 // We check here 1 by 1 because some strings occur after others (for example Mozilla [...] Firefox/)
499 foreach ($agents as $agent)
501 if (preg_match('#(' . $agent . ')[/ ]?([0-9.]*)#i', $user_agent, $match))
503 $result['user_agent'] = $match[1] . ' ' . $match[2];