From 89fef2ce13a183c7b963032274f455a09a05f325 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 21 Feb 2016 22:14:58 +0100 Subject: [ticket/14492] Send statistics via ajax request Flooding ajax requests will try to be prevented and sending stats without JS will also properly work. PHPBB3-14492 --- phpBB/includes/acp/acp_help_phpbb.php | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'phpBB/includes/acp') diff --git a/phpBB/includes/acp/acp_help_phpbb.php b/phpBB/includes/acp/acp_help_phpbb.php index fa4de60456..cc353376cd 100644 --- a/phpBB/includes/acp/acp_help_phpbb.php +++ b/phpBB/includes/acp/acp_help_phpbb.php @@ -84,23 +84,17 @@ class acp_help_phpbb if ($submit) { $config->set('help_send_statistics', $request->variable('help_send_statistics', false)); + $response = $request->variable('send_statistics_response', ''); - if ($config['help_send_statistics']) + if (!empty($response)) { - $client = new \GuzzleHttp\Client([ - 'timeout' => 6, - 'connect_timeout' => 6, - ]); - - $response = $client->post($collect_url, [ - 'body' => [ - 'systemdata' => $collector->get_data_for_form(), - ] - ]); - $response_status = $response->getStatusCode(); - - if ($response_status >= 200 && $response_status < 300) + if ((strpos($response, 'Thank you') !== false || strpos($response, 'Flood protection') !== false)) { + // Update time when statistics were actually sent + if (strpos($response, 'Thank you') !== false) + { + $config->set('help_send_statistics_time', time()); + } trigger_error($user->lang('THANKS_SEND_STATISTICS') . adm_back_link($this->u_action)); } else @@ -108,14 +102,18 @@ class acp_help_phpbb trigger_error($user->lang('FAIL_SEND_STATISTICS') . adm_back_link($this->u_action)); } } + + trigger_error($user->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); } $template->assign_vars(array( - 'U_COLLECT_STATS' => $collect_url, - 'S_COLLECT_STATS' => (!empty($config['help_send_statistics'])) ? true : false, - 'RAW_DATA' => $collector->get_data_for_form(), - 'U_ACP_MAIN' => append_sid("{$phpbb_admin_path}index.$phpEx"), - 'U_ACTION' => $this->u_action, + 'U_COLLECT_STATS' => $collect_url, + 'S_COLLECT_STATS' => (!empty($config['help_send_statistics'])) ? true : false, + 'RAW_DATA' => $collector->get_data_for_form(), + 'U_ACP_MAIN' => append_sid("{$phpbb_admin_path}index.$phpEx"), + 'U_ACTION' => $this->u_action, + // Pass earliest time we should try to send stats again + 'COLLECT_STATS_TIME' => intval($config['help_send_statistics_time']) + 86400, )); $raw = $collector->get_data_raw(); -- cgit v1.2.1