From a25238e0c16ba238136475bb1dcc17472fedfffa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 24 Feb 2011 23:51:42 +0100 Subject: [ticket/9874] view_log() performs unneeded count query over all log entries. PHPBB3-9874 --- phpBB/includes/functions_admin.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 2aa12adb2e..cb0cf34e69 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2506,6 +2506,7 @@ function cache_moderators() /** * View log +* If $log_count is set to false, we will skip counting all entries in the database. */ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '') { @@ -2761,16 +2762,19 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id } } - $sql = 'SELECT COUNT(l.log_id) AS total_entries - FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u - WHERE l.log_type = $log_type - AND l.user_id = u.user_id - AND l.log_time >= $limit_days - $sql_keywords - $sql_forum"; - $result = $db->sql_query($sql); - $log_count = (int) $db->sql_fetchfield('total_entries'); - $db->sql_freeresult($result); + if ($log_count !== false) + { + $sql = 'SELECT COUNT(l.log_id) AS total_entries + FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u + WHERE l.log_type = $log_type + AND l.user_id = u.user_id + AND l.log_time >= $limit_days + $sql_keywords + $sql_forum"; + $result = $db->sql_query($sql); + $log_count = (int) $db->sql_fetchfield('total_entries'); + $db->sql_freeresult($result); + } return; } -- cgit v1.2.1 From 8ebc8ec18277aea45079da3972e1ae0a3eb139ef Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 14 Jul 2011 04:05:20 +0200 Subject: [ticket/5506] Do not display an empty last page after deleting logs. The fix is copied from view_inactive_users(). Also add keywords and sort parameters to url for deleting logs and inactive users. And finally save some queries if there are no logs/users to display anyway --- phpBB/includes/functions_admin.php | 47 ++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index cb0cf34e69..f7e19f3e7d 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2595,6 +2595,31 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id $sql_keywords .= 'LOWER(l.log_data) ' . implode(' OR LOWER(l.log_data) ', $keywords) . ')'; } + if ($log_count !== false) + { + $sql = 'SELECT COUNT(l.log_id) AS total_entries + FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u + WHERE l.log_type = $log_type + AND l.user_id = u.user_id + AND l.log_time >= $limit_days + $sql_keywords + $sql_forum"; + $result = $db->sql_query($sql); + $log_count = (int) $db->sql_fetchfield('total_entries'); + $db->sql_freeresult($result); + } + + if ($log_count == 0) + { + // Save the queries, because there are no logs to display + return 0; + } + + if ($offset >= $log_count) + { + $offset = ($offset - $limit < 0) ? 0 : $offset - $limit; + } + $sql = "SELECT l.*, u.username, u.username_clean, u.user_colour FROM " . LOG_TABLE . " l, " . USERS_TABLE . " u WHERE l.log_type = $log_type @@ -2762,21 +2787,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id } } - if ($log_count !== false) - { - $sql = 'SELECT COUNT(l.log_id) AS total_entries - FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u - WHERE l.log_type = $log_type - AND l.user_id = u.user_id - AND l.log_time >= $limit_days - $sql_keywords - $sql_forum"; - $result = $db->sql_query($sql); - $log_count = (int) $db->sql_fetchfield('total_entries'); - $db->sql_freeresult($result); - } - - return; + return $offset; } /** @@ -2908,6 +2919,12 @@ function view_inactive_users(&$users, &$user_count, $limit = 0, $offset = 0, $li $user_count = (int) $db->sql_fetchfield('user_count'); $db->sql_freeresult($result); + if ($user_count == 0) + { + // Save the queries, because there are no users to display + return 0; + } + if ($offset >= $user_count) { $offset = ($offset - $limit < 0) ? 0 : $offset - $limit; -- cgit v1.2.1 From 2ffdf56bfe8ad35ac648a22a838b1ef01905b2d4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 25 Aug 2011 20:14:49 +0200 Subject: [ticket/10278] Also set timeout on stream in get_remote_file(). From the PHP manual for fsockopen(): If you need to set a timeout for reading/writing data over the socket, use stream_set_timeout(), as the timeout parameter to fsockopen() only applies while connecting the socket. http://www.php.net/manual/en/function.fsockopen.php PHPBB3-10278 --- phpBB/includes/functions_admin.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index f7e19f3e7d..ee146ca214 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3140,6 +3140,8 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port @fputs($fsock, "HOST: $host\r\n"); @fputs($fsock, "Connection: close\r\n\r\n"); + stream_set_timeout($fsock, $timeout); + $file_info = ''; $get_info = false; -- cgit v1.2.1 From 29a23ae217efed86e6b5afff4c9a0b1271eb20f4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 25 Aug 2011 20:34:01 +0200 Subject: [ticket/10278] Return with a timeout error when fread() or fgets() time out. PHPBB3-10278 --- phpBB/includes/functions_admin.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index ee146ca214..8b9b80b23d 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3164,6 +3164,14 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port return false; } } + + $stream_meta_data = stream_get_meta_data($fsock); + + if (!empty($stream_meta_data['timed_out'])) + { + $errstr = $user->lang['FSOCK_TIMEOUT']; + return false; + } } @fclose($fsock); } -- cgit v1.2.1 From c0507c6a9e26ba250596530f501bf6843250ed36 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 25 Aug 2011 20:38:53 +0200 Subject: [ticket/10278] Decrease default timeout of get_remote_file() to 6 seconds. PHPBB3-10278 --- phpBB/includes/functions_admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 8b9b80b23d..bcd477d855 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3130,7 +3130,7 @@ function get_database_size() /** * Retrieve contents from remotely stored file */ -function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port = 80, $timeout = 10) +function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port = 80, $timeout = 6) { global $user; -- cgit v1.2.1 From 26e84b12e817dd5e86a82c379a03a67f9f1bacd1 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Wed, 28 Sep 2011 01:52:08 -0500 Subject: [ticket/10349] Use new schema comment function in installer This is what now runs in the unit tests. The COMMENTS field in the dbms data is no longer needed, so it has been removed. PHPBB3-10349 --- phpBB/includes/functions_admin.php | 35 ----------------------------------- 1 file changed, 35 deletions(-) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index f7e19f3e7d..0c83674054 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2293,41 +2293,6 @@ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_fr return; } -/** -* remove_comments will strip the sql comment lines out of an uploaded sql file -* specifically for mssql and postgres type files in the install.... -*/ -function remove_comments(&$output) -{ - $lines = explode("\n", $output); - $output = ''; - - // try to keep mem. use down - $linecount = sizeof($lines); - - $in_comment = false; - for ($i = 0; $i < $linecount; $i++) - { - if (trim($lines[$i]) == '/*') - { - $in_comment = true; - } - - if (!$in_comment) - { - $output .= $lines[$i] . "\n"; - } - - if (trim($lines[$i]) == '*/') - { - $in_comment = false; - } - } - - unset($lines); - return $output; -} - /** * Cache moderators, called whenever permissions are changed via admin_permissions. Changes of username * and group names must be carried through for the moderators table -- cgit v1.2.1 From 091119605abe794aa508c76b7e5199517fc256e3 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 13 Oct 2011 18:03:02 +0200 Subject: [ticket/10278] Also timeout when receiving data over a slow connection. PHPBB3-10278 --- phpBB/includes/functions_admin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index bcd477d855..513b7a68b2 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3140,6 +3140,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port @fputs($fsock, "HOST: $host\r\n"); @fputs($fsock, "Connection: close\r\n\r\n"); + $timer_stop = time() + $timeout; stream_set_timeout($fsock, $timeout); $file_info = ''; @@ -3167,7 +3168,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port $stream_meta_data = stream_get_meta_data($fsock); - if (!empty($stream_meta_data['timed_out'])) + if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop) { $errstr = $user->lang['FSOCK_TIMEOUT']; return false; -- cgit v1.2.1 From 6f40960071129aafc2218ec23264c90af75fbad4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Nov 2011 22:56:24 +0100 Subject: [ticket/10461] Correct $log_count check in view_log() so we show logs again. We pass $log_count as false now when we do not need to know how many log entries there are. However when $log_count is false, $log_count == 0 will be true as well and thus we will return early with 0. PHPBB3-9874 PHPBB3-10461 --- phpBB/includes/functions_admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 513b7a68b2..3916e769ac 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2609,7 +2609,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id $db->sql_freeresult($result); } - if ($log_count == 0) + if ($log_count === 0) { // Save the queries, because there are no logs to display return 0; -- cgit v1.2.1 From a72ea2bc98bd75bf02414e6e5c7723c9ec47a97d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 23 Nov 2011 18:09:33 -0500 Subject: [ticket/10461] Add a comment explaining the logic here. PHPBB3-10461 --- phpBB/includes/functions_admin.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 3916e769ac..526bc16ff0 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2609,6 +2609,10 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id $db->sql_freeresult($result); } + // $log_count may be false here if false was passed in for it, + // because in this case we did not run the COUNT() query above. + // If we ran the COUNT() query and it returned zero rows, return; + // otherwise query for logs below. if ($log_count === 0) { // Save the queries, because there are no logs to display -- cgit v1.2.1 From 9ab5ad2986a836554bbf137d577c38155540c0a8 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 31 May 2012 11:48:56 +0200 Subject: [ticket/10751] Use sql_lower_text() in view_log(). log_data is a text column. PHPBB3-10751 --- phpBB/includes/functions_admin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 0e1a11b4aa..204fa9a43d 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2557,7 +2557,8 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id { $sql_keywords .= $db->sql_in_set('l.log_operation', $operations) . ' OR '; } - $sql_keywords .= 'LOWER(l.log_data) ' . implode(' OR LOWER(l.log_data) ', $keywords) . ')'; + $sql_lower = $db->sql_lower_text('l.log_data'); + $sql_keywords .= "$sql_lower " . implode(" OR $sql_lower ", $keywords) . ')'; } if ($log_count !== false) -- cgit v1.2.1