PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/includes/questionnaire/questionnaire.php

https://github.com/bantu/phpbb
PHP | 502 lines | 372 code | 34 blank | 96 comment | 20 complexity | 1d5be2989dba5743f0bd176648e6b80c MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. if (!defined('IN_PHPBB'))
  17. {
  18. exit;
  19. }
  20. /**
  21. * This class collects data which is used to create some usage statistics.
  22. *
  23. * The collected data is - after authorization of the administrator - submitted
  24. * to a central server. For privacy reasons we try to collect only data which aren't private
  25. * or don't give any information which might help to identify the user.
  26. *
  27. * @author Johannes Schlueter <johannes@php.net>
  28. * @copyright (c) 2007-2008 Johannes Schlueter
  29. */
  30. class phpbb_questionnaire_data_collector
  31. {
  32. var $providers;
  33. var $data = null;
  34. var $install_id = '';
  35. /**
  36. * Constructor.
  37. *
  38. * @param string
  39. */
  40. function phpbb_questionnaire_data_collector($install_id)
  41. {
  42. $this->install_id = $install_id;
  43. $this->providers = array();
  44. }
  45. function add_data_provider(&$provider)
  46. {
  47. $this->providers[] = &$provider;
  48. }
  49. /**
  50. * Get data as an array.
  51. *
  52. * @return array All Data
  53. */
  54. function get_data_raw()
  55. {
  56. if (!$this->data)
  57. {
  58. $this->collect();
  59. }
  60. return $this->data;
  61. }
  62. function get_data_for_form()
  63. {
  64. return base64_encode(serialize($this->get_data_raw()));
  65. }
  66. /**
  67. * Collect info into the data property.
  68. *
  69. * @return null
  70. */
  71. function collect()
  72. {
  73. foreach (array_keys($this->providers) as $key)
  74. {
  75. $provider = &$this->providers[$key];
  76. $this->data[$provider->get_identifier()] = $provider->get_data();
  77. }
  78. $this->data['install_id'] = $this->install_id;
  79. }
  80. }
  81. /** interface: get_indentifier(), get_data() */
  82. /**
  83. * Questionnaire PHP data provider
  84. */
  85. class phpbb_questionnaire_php_data_provider
  86. {
  87. function get_identifier()
  88. {
  89. return 'PHP';
  90. }
  91. /**
  92. * Get data about the PHP runtime setup.
  93. *
  94. * @return array
  95. */
  96. function get_data()
  97. {
  98. return array(
  99. 'version' => PHP_VERSION,
  100. 'sapi' => PHP_SAPI,
  101. 'int_size' => defined('PHP_INT_SIZE') ? PHP_INT_SIZE : '',
  102. 'safe_mode' => (int) @ini_get('safe_mode'),
  103. 'open_basedir' => (int) @ini_get('open_basedir'),
  104. 'memory_limit' => @ini_get('memory_limit'),
  105. 'allow_url_fopen' => (int) @ini_get('allow_url_fopen'),
  106. 'allow_url_include' => (int) @ini_get('allow_url_include'),
  107. 'file_uploads' => (int) @ini_get('file_uploads'),
  108. 'upload_max_filesize' => @ini_get('upload_max_filesize'),
  109. 'post_max_size' => @ini_get('post_max_size'),
  110. 'disable_functions' => @ini_get('disable_functions'),
  111. 'disable_classes' => @ini_get('disable_classes'),
  112. 'enable_dl' => (int) @ini_get('enable_dl'),
  113. 'magic_quotes_gpc' => (int) @ini_get('magic_quotes_gpc'),
  114. 'register_globals' => (int) @ini_get('register_globals'),
  115. 'filter.default' => @ini_get('filter.default'),
  116. 'zend.ze1_compatibility_mode' => (int) @ini_get('zend.ze1_compatibility_mode'),
  117. 'unicode.semantics' => (int) @ini_get('unicode.semantics'),
  118. 'zend_thread_safty' => (int) function_exists('zend_thread_id'),
  119. 'extensions' => get_loaded_extensions(),
  120. );
  121. }
  122. }
  123. /**
  124. * Questionnaire System data provider
  125. */
  126. class phpbb_questionnaire_system_data_provider
  127. {
  128. function get_identifier()
  129. {
  130. return 'System';
  131. }
  132. /**
  133. * Get data about the general system information, like OS or IP (shortened).
  134. *
  135. * @return array
  136. */
  137. function get_data()
  138. {
  139. global $request;
  140. // Start discovering the IPV4 server address, if available
  141. // Try apache, IIS, fall back to 0.0.0.0
  142. $server_address = htmlspecialchars_decode($request->server('SERVER_ADDR', $request->server('LOCAL_ADDR', '0.0.0.0')));
  143. return array(
  144. 'os' => PHP_OS,
  145. 'httpd' => htmlspecialchars_decode($request->server('SERVER_SOFTWARE')),
  146. // we don't want the real IP address (for privacy policy reasons) but only
  147. // a network address to see whether your installation is running on a private or public network.
  148. 'private_ip' => $this->is_private_ip($server_address),
  149. 'ipv6' => strpos($server_address, ':') !== false,
  150. );
  151. }
  152. /**
  153. * Checks whether the given IP is in a private network.
  154. *
  155. * @param string $ip IP in v4 dot-decimal or v6 hex format
  156. * @return bool true if the IP is from a private network, else false
  157. */
  158. function is_private_ip($ip)
  159. {
  160. // IPv4
  161. if (strpos($ip, ':') === false)
  162. {
  163. $ip_address_ary = explode('.', $ip);
  164. // build ip
  165. if (!isset($ip_address_ary[0]) || !isset($ip_address_ary[1]))
  166. {
  167. $ip_address_ary = explode('.', '0.0.0.0');
  168. }
  169. // IANA reserved addresses for private networks (RFC 1918) are:
  170. // - 10.0.0.0/8
  171. // - 172.16.0.0/12
  172. // - 192.168.0.0/16
  173. if ($ip_address_ary[0] == '10' ||
  174. ($ip_address_ary[0] == '172' && intval($ip_address_ary[1]) > 15 && intval($ip_address_ary[1]) < 32) ||
  175. ($ip_address_ary[0] == '192' && $ip_address_ary[1] == '168'))
  176. {
  177. return true;
  178. }
  179. }
  180. // IPv6
  181. else
  182. {
  183. // unique local unicast
  184. $prefix = substr($ip, 0, 2);
  185. if ($prefix == 'fc' || $prefix == 'fd')
  186. {
  187. return true;
  188. }
  189. }
  190. return false;
  191. }
  192. }
  193. /**
  194. * Questionnaire phpBB data provider
  195. */
  196. class phpbb_questionnaire_phpbb_data_provider
  197. {
  198. var $config;
  199. var $unique_id;
  200. /**
  201. * Constructor.
  202. *
  203. * @param array $config
  204. */
  205. function phpbb_questionnaire_phpbb_data_provider($config)
  206. {
  207. // generate a unique id if necessary
  208. if (empty($config['questionnaire_unique_id']))
  209. {
  210. $this->unique_id = unique_id();
  211. $config->set('questionnaire_unique_id', $this->unique_id);
  212. }
  213. else
  214. {
  215. $this->unique_id = $config['questionnaire_unique_id'];
  216. }
  217. $this->config = $config;
  218. }
  219. /**
  220. * Returns a string identifier for this data provider
  221. *
  222. * @return string "phpBB"
  223. */
  224. function get_identifier()
  225. {
  226. return 'phpBB';
  227. }
  228. /**
  229. * Get data about this phpBB installation.
  230. *
  231. * @return array Relevant anonymous config options
  232. */
  233. function get_data()
  234. {
  235. global $phpbb_config_php_file;
  236. extract($phpbb_config_php_file->get_all());
  237. unset($dbhost, $dbport, $dbname, $dbuser, $dbpasswd); // Just a precaution
  238. $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms);
  239. // Only send certain config vars
  240. $config_vars = array(
  241. 'active_sessions' => true,
  242. 'allow_attachments' => true,
  243. 'allow_autologin' => true,
  244. 'allow_avatar' => true,
  245. 'allow_avatar_local' => true,
  246. 'allow_avatar_remote' => true,
  247. 'allow_avatar_upload' => true,
  248. 'allow_bbcode' => true,
  249. 'allow_birthdays' => true,
  250. 'allow_bookmarks' => true,
  251. 'allow_emailreuse' => true,
  252. 'allow_forum_notify' => true,
  253. 'allow_mass_pm' => true,
  254. 'allow_name_chars' => true,
  255. 'allow_namechange' => true,
  256. 'allow_nocensors' => true,
  257. 'allow_pm_attach' => true,
  258. 'allow_pm_report' => true,
  259. 'allow_post_flash' => true,
  260. 'allow_post_links' => true,
  261. 'allow_privmsg' => true,
  262. 'allow_quick_reply' => true,
  263. 'allow_sig' => true,
  264. 'allow_sig_bbcode' => true,
  265. 'allow_sig_flash' => true,
  266. 'allow_sig_img' => true,
  267. 'allow_sig_links' => true,
  268. 'allow_sig_pm' => true,
  269. 'allow_sig_smilies' => true,
  270. 'allow_smilies' => true,
  271. 'allow_topic_notify' => true,
  272. 'attachment_quota' => true,
  273. 'auth_bbcode_pm' => true,
  274. 'auth_flash_pm' => true,
  275. 'auth_img_pm' => true,
  276. 'auth_method' => true,
  277. 'auth_smilies_pm' => true,
  278. 'avatar_filesize' => true,
  279. 'avatar_max_height' => true,
  280. 'avatar_max_width' => true,
  281. 'avatar_min_height' => true,
  282. 'avatar_min_width' => true,
  283. 'board_email_form' => true,
  284. 'board_hide_emails' => true,
  285. 'board_timezone' => true,
  286. 'browser_check' => true,
  287. 'bump_interval' => true,
  288. 'bump_type' => true,
  289. 'cache_gc' => true,
  290. 'captcha_plugin' => true,
  291. 'captcha_gd' => true,
  292. 'captcha_gd_foreground_noise' => true,
  293. 'captcha_gd_x_grid' => true,
  294. 'captcha_gd_y_grid' => true,
  295. 'captcha_gd_wave' => true,
  296. 'captcha_gd_3d_noise' => true,
  297. 'captcha_gd_fonts' => true,
  298. 'confirm_refresh' => true,
  299. 'check_attachment_content' => true,
  300. 'check_dnsbl' => true,
  301. 'chg_passforce' => true,
  302. 'cookie_secure' => true,
  303. 'coppa_enable' => true,
  304. 'database_gc' => true,
  305. 'dbms_version' => true,
  306. 'default_dateformat' => true,
  307. 'default_lang' => true,
  308. 'display_last_edited' => true,
  309. 'display_order' => true,
  310. 'edit_time' => true,
  311. 'email_check_mx' => true,
  312. 'email_enable' => true,
  313. 'email_function_name' => true,
  314. 'email_package_size' => true,
  315. 'enable_confirm' => true,
  316. 'enable_pm_icons' => true,
  317. 'enable_post_confirm' => true,
  318. 'feed_enable' => true,
  319. 'feed_http_auth' => true,
  320. 'feed_limit_post' => true,
  321. 'feed_limit_topic' => true,
  322. 'feed_overall' => true,
  323. 'feed_overall_forums' => true,
  324. 'feed_forum' => true,
  325. 'feed_topic' => true,
  326. 'feed_topics_new' => true,
  327. 'feed_topics_active' => true,
  328. 'feed_item_statistics' => true,
  329. 'flood_interval' => true,
  330. 'force_server_vars' => true,
  331. 'form_token_lifetime' => true,
  332. 'form_token_mintime' => true,
  333. 'form_token_sid_guests' => true,
  334. 'forward_pm' => true,
  335. 'forwarded_for_check' => true,
  336. 'full_folder_action' => true,
  337. 'fulltext_native_common_thres' => true,
  338. 'fulltext_native_load_upd' => true,
  339. 'fulltext_native_max_chars' => true,
  340. 'fulltext_native_min_chars' => true,
  341. 'gzip_compress' => true,
  342. 'hot_threshold' => true,
  343. 'img_create_thumbnail' => true,
  344. 'img_display_inlined' => true,
  345. 'img_imagick' => true,
  346. 'img_link_height' => true,
  347. 'img_link_width' => true,
  348. 'img_max_height' => true,
  349. 'img_max_thumb_width' => true,
  350. 'img_max_width' => true,
  351. 'img_min_thumb_filesize' => true,
  352. 'ip_check' => true,
  353. 'jab_enable' => true,
  354. 'jab_package_size' => true,
  355. 'jab_use_ssl' => true,
  356. 'limit_load' => true,
  357. 'limit_search_load' => true,
  358. 'load_anon_lastread' => true,
  359. 'load_birthdays' => true,
  360. 'load_cpf_memberlist' => true,
  361. 'load_cpf_viewprofile' => true,
  362. 'load_cpf_viewtopic' => true,
  363. 'load_db_lastread' => true,
  364. 'load_db_track' => true,
  365. 'load_jumpbox' => true,
  366. 'load_moderators' => true,
  367. 'load_online' => true,
  368. 'load_online_guests' => true,
  369. 'load_online_time' => true,
  370. 'load_onlinetrack' => true,
  371. 'load_search' => true,
  372. 'load_tplcompile' => true,
  373. 'load_user_activity' => true,
  374. 'max_attachments' => true,
  375. 'max_attachments_pm' => true,
  376. 'max_autologin_time' => true,
  377. 'max_filesize' => true,
  378. 'max_filesize_pm' => true,
  379. 'max_login_attempts' => true,
  380. 'max_name_chars' => true,
  381. 'max_num_search_keywords' => true,
  382. 'max_pass_chars' => true,
  383. 'max_poll_options' => true,
  384. 'max_post_chars' => true,
  385. 'max_post_font_size' => true,
  386. 'max_post_img_height' => true,
  387. 'max_post_img_width' => true,
  388. 'max_post_smilies' => true,
  389. 'max_post_urls' => true,
  390. 'max_quote_depth' => true,
  391. 'max_reg_attempts' => true,
  392. 'max_sig_chars' => true,
  393. 'max_sig_font_size' => true,
  394. 'max_sig_img_height' => true,
  395. 'max_sig_img_width' => true,
  396. 'max_sig_smilies' => true,
  397. 'max_sig_urls' => true,
  398. 'min_name_chars' => true,
  399. 'min_pass_chars' => true,
  400. 'min_post_chars' => true,
  401. 'min_search_author_chars' => true,
  402. 'mime_triggers' => true,
  403. 'new_member_post_limit' => true,
  404. 'new_member_group_default' => true,
  405. 'override_user_style' => true,
  406. 'pass_complex' => true,
  407. 'pm_edit_time' => true,
  408. 'pm_max_boxes' => true,
  409. 'pm_max_msgs' => true,
  410. 'pm_max_recipients' => true,
  411. 'posts_per_page' => true,
  412. 'print_pm' => true,
  413. 'queue_interval' => true,
  414. 'require_activation' => true,
  415. 'referer_validation' => true,
  416. 'search_block_size' => true,
  417. 'search_gc' => true,
  418. 'search_interval' => true,
  419. 'search_anonymous_interval' => true,
  420. 'search_type' => true,
  421. 'search_store_results' => true,
  422. 'secure_allow_deny' => true,
  423. 'secure_allow_empty_referer' => true,
  424. 'secure_downloads' => true,
  425. 'session_gc' => true,
  426. 'session_length' => true,
  427. 'smtp_auth_method' => true,
  428. 'smtp_delivery' => true,
  429. 'topics_per_page' => true,
  430. 'tpl_allow_php' => true,
  431. 'version' => true,
  432. 'warnings_expire_days' => true,
  433. 'warnings_gc' => true,
  434. 'num_files' => true,
  435. 'num_posts' => true,
  436. 'num_topics' => true,
  437. 'num_users' => true,
  438. 'record_online_users' => true,
  439. );
  440. $result = array();
  441. foreach ($config_vars as $name => $void)
  442. {
  443. if (isset($this->config[$name]))
  444. {
  445. $result['config_' . $name] = $this->config[$name];
  446. }
  447. }
  448. global $db, $request;
  449. $result['dbms'] = $dbms;
  450. $result['acm_type'] = $acm_type;
  451. $result['user_agent'] = 'Unknown';
  452. $result['dbms_version'] = $db->sql_server_info(true);
  453. // Try to get user agent vendor and version
  454. $match = array();
  455. $user_agent = $request->header('User-Agent');
  456. $agents = array('firefox', 'msie', 'opera', 'chrome', 'safari', 'mozilla', 'seamonkey', 'konqueror', 'netscape', 'gecko', 'navigator', 'mosaic', 'lynx', 'amaya', 'omniweb', 'avant', 'camino', 'flock', 'aol');
  457. // We check here 1 by 1 because some strings occur after others (for example Mozilla [...] Firefox/)
  458. foreach ($agents as $agent)
  459. {
  460. if (preg_match('#(' . $agent . ')[/ ]?([0-9.]*)#i', $user_agent, $match))
  461. {
  462. $result['user_agent'] = $match[1] . ' ' . $match[2];
  463. break;
  464. }
  465. }
  466. return $result;
  467. }
  468. }