1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/questionnaire/questionnaire.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,512 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package phpBB3
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* This class collects data which is used to create some usage statistics.
1.24 +*
1.25 +* The collected data is - after authorization of the administrator - submitted
1.26 +* to a central server. For privacy reasons we try to collect only data which aren't private
1.27 +* or don't give any information which might help to identify the user.
1.28 +*
1.29 +* @author Johannes Schlueter <johannes@php.net>
1.30 +* @copyright (c) 2007-2008 Johannes Schlueter
1.31 +*/
1.32 +class phpbb_questionnaire_data_collector
1.33 +{
1.34 + var $providers;
1.35 + var $data = null;
1.36 + var $install_id = '';
1.37 +
1.38 + /**
1.39 + * Constructor.
1.40 + *
1.41 + * @param string
1.42 + */
1.43 + function phpbb_questionnaire_data_collector($install_id)
1.44 + {
1.45 + $this->install_id = $install_id;
1.46 + $this->providers = array();
1.47 + }
1.48 +
1.49 + function add_data_provider(&$provider)
1.50 + {
1.51 + $this->providers[] = &$provider;
1.52 + }
1.53 +
1.54 + /**
1.55 + * Get data as an array.
1.56 + *
1.57 + * @return array All Data
1.58 + */
1.59 + function get_data_raw()
1.60 + {
1.61 + if (!$this->data)
1.62 + {
1.63 + $this->collect();
1.64 + }
1.65 +
1.66 + return $this->data;
1.67 + }
1.68 +
1.69 + function get_data_for_form()
1.70 + {
1.71 + return base64_encode(serialize($this->get_data_raw()));
1.72 + }
1.73 +
1.74 + /**
1.75 + * Collect info into the data property.
1.76 + *
1.77 + * @return void
1.78 + */
1.79 + function collect()
1.80 + {
1.81 + foreach (array_keys($this->providers) as $key)
1.82 + {
1.83 + $provider = &$this->providers[$key];
1.84 + $this->data[$provider->get_identifier()] = $provider->get_data();
1.85 + }
1.86 + $this->data['install_id'] = $this->install_id;
1.87 + }
1.88 +}
1.89 +
1.90 +/** interface: get_indentifier(), get_data() */
1.91 +
1.92 +/**
1.93 +* Questionnaire PHP data provider
1.94 +* @package phpBB3
1.95 +*/
1.96 +class phpbb_questionnaire_php_data_provider
1.97 +{
1.98 + function get_identifier()
1.99 + {
1.100 + return 'PHP';
1.101 + }
1.102 +
1.103 + /**
1.104 + * Get data about the PHP runtime setup.
1.105 + *
1.106 + * @return array
1.107 + */
1.108 + function get_data()
1.109 + {
1.110 + return array(
1.111 + 'version' => PHP_VERSION,
1.112 + 'sapi' => PHP_SAPI,
1.113 + 'int_size' => defined('PHP_INT_SIZE') ? PHP_INT_SIZE : '',
1.114 + 'safe_mode' => (int) @ini_get('safe_mode'),
1.115 + 'open_basedir' => (int) @ini_get('open_basedir'),
1.116 + 'memory_limit' => @ini_get('memory_limit'),
1.117 + 'allow_url_fopen' => (int) @ini_get('allow_url_fopen'),
1.118 + 'allow_url_include' => (int) @ini_get('allow_url_include'),
1.119 + 'file_uploads' => (int) @ini_get('file_uploads'),
1.120 + 'upload_max_filesize' => @ini_get('upload_max_filesize'),
1.121 + 'post_max_size' => @ini_get('post_max_size'),
1.122 + 'disable_functions' => @ini_get('disable_functions'),
1.123 + 'disable_classes' => @ini_get('disable_classes'),
1.124 + 'enable_dl' => (int) @ini_get('enable_dl'),
1.125 + 'magic_quotes_gpc' => (int) @ini_get('magic_quotes_gpc'),
1.126 + 'register_globals' => (int) @ini_get('register_globals'),
1.127 + 'filter.default' => @ini_get('filter.default'),
1.128 + 'zend.ze1_compatibility_mode' => (int) @ini_get('zend.ze1_compatibility_mode'),
1.129 + 'unicode.semantics' => (int) @ini_get('unicode.semantics'),
1.130 + 'zend_thread_safty' => (int) function_exists('zend_thread_id'),
1.131 + 'extensions' => get_loaded_extensions(),
1.132 + );
1.133 + }
1.134 +}
1.135 +
1.136 +/**
1.137 +* Questionnaire System data provider
1.138 +* @package phpBB3
1.139 +*/
1.140 +class phpbb_questionnaire_system_data_provider
1.141 +{
1.142 + function get_identifier()
1.143 + {
1.144 + return 'System';
1.145 + }
1.146 +
1.147 + /**
1.148 + * Get data about the general system information, like OS or IP (shortened).
1.149 + *
1.150 + * @return array
1.151 + */
1.152 + function get_data()
1.153 + {
1.154 + // Start discovering the IPV4 server address, if available
1.155 + $server_address = '0.0.0.0';
1.156 +
1.157 + if (!empty($_SERVER['SERVER_ADDR']))
1.158 + {
1.159 + $server_address = $_SERVER['SERVER_ADDR'];
1.160 + }
1.161 +
1.162 + // Running on IIS?
1.163 + if (!empty($_SERVER['LOCAL_ADDR']))
1.164 + {
1.165 + $server_address = $_SERVER['LOCAL_ADDR'];
1.166 + }
1.167 +
1.168 + return array(
1.169 + 'os' => PHP_OS,
1.170 + 'httpd' => $_SERVER['SERVER_SOFTWARE'],
1.171 + // we don't want the real IP address (for privacy policy reasons) but only
1.172 + // a network address to see whether your installation is running on a private or public network.
1.173 + 'private_ip' => $this->is_private_ip($server_address),
1.174 + 'ipv6' => strpos($server_address, ':') !== false,
1.175 + );
1.176 + }
1.177 +
1.178 + /**
1.179 + * Checks whether the given IP is in a private network.
1.180 + *
1.181 + * @param string $ip IP in v4 dot-decimal or v6 hex format
1.182 + * @return bool true if the IP is from a private network, else false
1.183 + */
1.184 + function is_private_ip($ip)
1.185 + {
1.186 + // IPv4
1.187 + if (strpos($ip, ':') === false)
1.188 + {
1.189 + $ip_address_ary = explode('.', $ip);
1.190 +
1.191 + // build ip
1.192 + if (!isset($ip_address_ary[0]) || !isset($ip_address_ary[1]))
1.193 + {
1.194 + $ip_address_ary = explode('.', '0.0.0.0');
1.195 + }
1.196 +
1.197 + // IANA reserved addresses for private networks (RFC 1918) are:
1.198 + // - 10.0.0.0/8
1.199 + // - 172.16.0.0/12
1.200 + // - 192.168.0.0/16
1.201 + if ($ip_address_ary[0] == '10' ||
1.202 + ($ip_address_ary[0] == '172' && intval($ip_address_ary[1]) > 15 && intval($ip_address_ary[1]) < 32) ||
1.203 + ($ip_address_ary[0] == '192' && $ip_address_ary[1] == '168') ||
1.204 + ($ip_address_ary[0] == '192' && $ip_address_ary[1] == '168'))
1.205 + {
1.206 + return true;
1.207 + }
1.208 + }
1.209 + // IPv6
1.210 + else
1.211 + {
1.212 + // unique local unicast
1.213 + $prefix = substr($ip, 0, 2);
1.214 + if ($prefix == 'fc' || $prefix == 'fd')
1.215 + {
1.216 + return true;
1.217 + }
1.218 + }
1.219 +
1.220 + return false;
1.221 + }
1.222 +}
1.223 +
1.224 +/**
1.225 +* Questionnaire phpBB data provider
1.226 +* @package phpBB3
1.227 +*/
1.228 +class phpbb_questionnaire_phpbb_data_provider
1.229 +{
1.230 + var $config;
1.231 + var $unique_id;
1.232 +
1.233 + /**
1.234 + * Constructor.
1.235 + *
1.236 + * @param array $config
1.237 + */
1.238 + function phpbb_questionnaire_phpbb_data_provider($config)
1.239 + {
1.240 + // generate a unique id if necessary
1.241 + if (empty($config['questionnaire_unique_id']))
1.242 + {
1.243 + $this->unique_id = unique_id();
1.244 + set_config('questionnaire_unique_id', $this->unique_id);
1.245 + }
1.246 + else
1.247 + {
1.248 + $this->unique_id = $config['questionnaire_unique_id'];
1.249 + }
1.250 +
1.251 + $this->config = $config;
1.252 + }
1.253 +
1.254 + /**
1.255 + * Returns a string identifier for this data provider
1.256 + *
1.257 + * @return string "phpBB"
1.258 + */
1.259 + function get_identifier()
1.260 + {
1.261 + return 'phpBB';
1.262 + }
1.263 +
1.264 + /**
1.265 + * Get data about this phpBB installation.
1.266 + *
1.267 + * @return array Relevant anonymous config options
1.268 + */
1.269 + function get_data()
1.270 + {
1.271 + global $phpbb_root_path, $phpEx;
1.272 + include("{$phpbb_root_path}config.$phpEx");
1.273 + unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution
1.274 +
1.275 + // Only send certain config vars
1.276 + $config_vars = array(
1.277 + 'active_sessions' => true,
1.278 + 'allow_attachments' => true,
1.279 + 'allow_autologin' => true,
1.280 + 'allow_avatar' => true,
1.281 + 'allow_avatar_local' => true,
1.282 + 'allow_avatar_remote' => true,
1.283 + 'allow_avatar_upload' => true,
1.284 + 'allow_bbcode' => true,
1.285 + 'allow_birthdays' => true,
1.286 + 'allow_bookmarks' => true,
1.287 + 'allow_emailreuse' => true,
1.288 + 'allow_forum_notify' => true,
1.289 + 'allow_mass_pm' => true,
1.290 + 'allow_name_chars' => true,
1.291 + 'allow_namechange' => true,
1.292 + 'allow_nocensors' => true,
1.293 + 'allow_pm_attach' => true,
1.294 + 'allow_pm_report' => true,
1.295 + 'allow_post_flash' => true,
1.296 + 'allow_post_links' => true,
1.297 + 'allow_privmsg' => true,
1.298 + 'allow_quick_reply' => true,
1.299 + 'allow_sig' => true,
1.300 + 'allow_sig_bbcode' => true,
1.301 + 'allow_sig_flash' => true,
1.302 + 'allow_sig_img' => true,
1.303 + 'allow_sig_links' => true,
1.304 + 'allow_sig_pm' => true,
1.305 + 'allow_sig_smilies' => true,
1.306 + 'allow_smilies' => true,
1.307 + 'allow_topic_notify' => true,
1.308 + 'attachment_quota' => true,
1.309 + 'auth_bbcode_pm' => true,
1.310 + 'auth_flash_pm' => true,
1.311 + 'auth_img_pm' => true,
1.312 + 'auth_method' => true,
1.313 + 'auth_smilies_pm' => true,
1.314 + 'avatar_filesize' => true,
1.315 + 'avatar_max_height' => true,
1.316 + 'avatar_max_width' => true,
1.317 + 'avatar_min_height' => true,
1.318 + 'avatar_min_width' => true,
1.319 + 'board_dst' => true,
1.320 + 'board_email_form' => true,
1.321 + 'board_hide_emails' => true,
1.322 + 'board_timezone' => true,
1.323 + 'browser_check' => true,
1.324 + 'bump_interval' => true,
1.325 + 'bump_type' => true,
1.326 + 'cache_gc' => true,
1.327 + 'captcha_plugin' => true,
1.328 + 'captcha_gd' => true,
1.329 + 'captcha_gd_foreground_noise' => true,
1.330 + 'captcha_gd_x_grid' => true,
1.331 + 'captcha_gd_y_grid' => true,
1.332 + 'captcha_gd_wave' => true,
1.333 + 'captcha_gd_3d_noise' => true,
1.334 + 'captcha_gd_fonts' => true,
1.335 + 'confirm_refresh' => true,
1.336 + 'check_attachment_content' => true,
1.337 + 'check_dnsbl' => true,
1.338 + 'chg_passforce' => true,
1.339 + 'cookie_secure' => true,
1.340 + 'coppa_enable' => true,
1.341 + 'database_gc' => true,
1.342 + 'dbms_version' => true,
1.343 + 'default_dateformat' => true,
1.344 + 'default_lang' => true,
1.345 + 'display_last_edited' => true,
1.346 + 'display_order' => true,
1.347 + 'edit_time' => true,
1.348 + 'email_check_mx' => true,
1.349 + 'email_enable' => true,
1.350 + 'email_function_name' => true,
1.351 + 'email_package_size' => true,
1.352 + 'enable_confirm' => true,
1.353 + 'enable_pm_icons' => true,
1.354 + 'enable_post_confirm' => true,
1.355 + 'feed_enable' => true,
1.356 + 'feed_http_auth' => true,
1.357 + 'feed_limit_post' => true,
1.358 + 'feed_limit_topic' => true,
1.359 + 'feed_overall' => true,
1.360 + 'feed_overall_forums' => true,
1.361 + 'feed_forum' => true,
1.362 + 'feed_topic' => true,
1.363 + 'feed_topics_new' => true,
1.364 + 'feed_topics_active' => true,
1.365 + 'feed_item_statistics' => true,
1.366 + 'flood_interval' => true,
1.367 + 'force_server_vars' => true,
1.368 + 'form_token_lifetime' => true,
1.369 + 'form_token_mintime' => true,
1.370 + 'form_token_sid_guests' => true,
1.371 + 'forward_pm' => true,
1.372 + 'forwarded_for_check' => true,
1.373 + 'full_folder_action' => true,
1.374 + 'fulltext_native_common_thres' => true,
1.375 + 'fulltext_native_load_upd' => true,
1.376 + 'fulltext_native_max_chars' => true,
1.377 + 'fulltext_native_min_chars' => true,
1.378 + 'gzip_compress' => true,
1.379 + 'hot_threshold' => true,
1.380 + 'img_create_thumbnail' => true,
1.381 + 'img_display_inlined' => true,
1.382 + 'img_imagick' => true,
1.383 + 'img_link_height' => true,
1.384 + 'img_link_width' => true,
1.385 + 'img_max_height' => true,
1.386 + 'img_max_thumb_width' => true,
1.387 + 'img_max_width' => true,
1.388 + 'img_min_thumb_filesize' => true,
1.389 + 'ip_check' => true,
1.390 + 'jab_enable' => true,
1.391 + 'jab_package_size' => true,
1.392 + 'jab_use_ssl' => true,
1.393 + 'limit_load' => true,
1.394 + 'limit_search_load' => true,
1.395 + 'load_anon_lastread' => true,
1.396 + 'load_birthdays' => true,
1.397 + 'load_cpf_memberlist' => true,
1.398 + 'load_cpf_viewprofile' => true,
1.399 + 'load_cpf_viewtopic' => true,
1.400 + 'load_db_lastread' => true,
1.401 + 'load_db_track' => true,
1.402 + 'load_jumpbox' => true,
1.403 + 'load_moderators' => true,
1.404 + 'load_online' => true,
1.405 + 'load_online_guests' => true,
1.406 + 'load_online_time' => true,
1.407 + 'load_onlinetrack' => true,
1.408 + 'load_search' => true,
1.409 + 'load_tplcompile' => true,
1.410 + 'load_user_activity' => true,
1.411 + 'max_attachments' => true,
1.412 + 'max_attachments_pm' => true,
1.413 + 'max_autologin_time' => true,
1.414 + 'max_filesize' => true,
1.415 + 'max_filesize_pm' => true,
1.416 + 'max_login_attempts' => true,
1.417 + 'max_name_chars' => true,
1.418 + 'max_num_search_keywords' => true,
1.419 + 'max_pass_chars' => true,
1.420 + 'max_poll_options' => true,
1.421 + 'max_post_chars' => true,
1.422 + 'max_post_font_size' => true,
1.423 + 'max_post_img_height' => true,
1.424 + 'max_post_img_width' => true,
1.425 + 'max_post_smilies' => true,
1.426 + 'max_post_urls' => true,
1.427 + 'max_quote_depth' => true,
1.428 + 'max_reg_attempts' => true,
1.429 + 'max_sig_chars' => true,
1.430 + 'max_sig_font_size' => true,
1.431 + 'max_sig_img_height' => true,
1.432 + 'max_sig_img_width' => true,
1.433 + 'max_sig_smilies' => true,
1.434 + 'max_sig_urls' => true,
1.435 + 'min_name_chars' => true,
1.436 + 'min_pass_chars' => true,
1.437 + 'min_post_chars' => true,
1.438 + 'min_search_author_chars' => true,
1.439 + 'mime_triggers' => true,
1.440 + 'new_member_post_limit' => true,
1.441 + 'new_member_group_default' => true,
1.442 + 'override_user_style' => true,
1.443 + 'pass_complex' => true,
1.444 + 'pm_edit_time' => true,
1.445 + 'pm_max_boxes' => true,
1.446 + 'pm_max_msgs' => true,
1.447 + 'pm_max_recipients' => true,
1.448 + 'posts_per_page' => true,
1.449 + 'print_pm' => true,
1.450 + 'queue_interval' => true,
1.451 + 'require_activation' => true,
1.452 + 'referer_validation' => true,
1.453 + 'search_block_size' => true,
1.454 + 'search_gc' => true,
1.455 + 'search_interval' => true,
1.456 + 'search_anonymous_interval' => true,
1.457 + 'search_type' => true,
1.458 + 'search_store_results' => true,
1.459 + 'secure_allow_deny' => true,
1.460 + 'secure_allow_empty_referer' => true,
1.461 + 'secure_downloads' => true,
1.462 + 'session_gc' => true,
1.463 + 'session_length' => true,
1.464 + 'smtp_auth_method' => true,
1.465 + 'smtp_delivery' => true,
1.466 + 'topics_per_page' => true,
1.467 + 'tpl_allow_php' => true,
1.468 + 'version' => true,
1.469 + 'warnings_expire_days' => true,
1.470 + 'warnings_gc' => true,
1.471 +
1.472 + 'num_files' => true,
1.473 + 'num_posts' => true,
1.474 + 'num_topics' => true,
1.475 + 'num_users' => true,
1.476 + 'record_online_users' => true,
1.477 + );
1.478 +
1.479 + $result = array();
1.480 + foreach ($config_vars as $name => $void)
1.481 + {
1.482 + if (isset($this->config[$name]))
1.483 + {
1.484 + $result['config_' . $name] = $this->config[$name];
1.485 + }
1.486 + }
1.487 +
1.488 + global $db;
1.489 +
1.490 + $result['dbms'] = $dbms;
1.491 + $result['acm_type'] = $acm_type;
1.492 + $result['load_extensions'] = $load_extensions;
1.493 + $result['user_agent'] = 'Unknown';
1.494 + $result['dbms_version'] = $db->sql_server_info(true);
1.495 +
1.496 + // Try to get user agent vendor and version
1.497 + $match = array();
1.498 + $user_agent = (!empty($_SERVER['HTTP_USER_AGENT'])) ? (string) $_SERVER['HTTP_USER_AGENT'] : '';
1.499 + $agents = array('firefox', 'msie', 'opera', 'chrome', 'safari', 'mozilla', 'seamonkey', 'konqueror', 'netscape', 'gecko', 'navigator', 'mosaic', 'lynx', 'amaya', 'omniweb', 'avant', 'camino', 'flock', 'aol');
1.500 +
1.501 + // We check here 1 by 1 because some strings occur after others (for example Mozilla [...] Firefox/)
1.502 + foreach ($agents as $agent)
1.503 + {
1.504 + if (preg_match('#(' . $agent . ')[/ ]?([0-9.]*)#i', $user_agent, $match))
1.505 + {
1.506 + $result['user_agent'] = $match[1] . ' ' . $match[2];
1.507 + break;
1.508 + }
1.509 + }
1.510 +
1.511 + return $result;
1.512 + }
1.513 +}
1.514 +
1.515 +?>
1.516 \ No newline at end of file