From d205bfa6a4c7c60879fbcc2503d37dacd4f9493f Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Mon, 4 Sep 2023 07:07:06 -0700 Subject: [PATCH] Display number of bots separately from number of users online. --- Rocksolid_Light/rocksolid/article-flat.php | 5 +- Rocksolid_Light/rocksolid/article.php | 3 +- Rocksolid_Light/rocksolid/newsportal.php | 5 +- Rocksolid_Light/rocksolid/overboard.php | 10 ++- Rocksolid_Light/rocksolid/search.php | 3 +- Rocksolid_Light/rocksolid/thread.php | 7 +- .../rslight/scripts/count_users.php | 85 +++++++++++-------- 7 files changed, 68 insertions(+), 50 deletions(-) mode change 100755 => 100644 Rocksolid_Light/rocksolid/overboard.php mode change 100755 => 100644 Rocksolid_Light/rslight/scripts/count_users.php diff --git a/Rocksolid_Light/rocksolid/article-flat.php b/Rocksolid_Light/rocksolid/article-flat.php index 6ca31f4..ee3b9be 100644 --- a/Rocksolid_Light/rocksolid/article-flat.php +++ b/Rocksolid_Light/rocksolid/article-flat.php @@ -9,8 +9,6 @@ include "auth.inc"; include "$file_newsportal"; $logfile = $logdir . '/newsportal.log'; -throttle_hits(); -write_access_log(); if (isset($_COOKIE['mail_name'])) { if ($userdata = get_user_mail_auth_data($_COOKIE['mail_name'])) { $userfile = $spooldir . '/' . strtolower($_COOKIE['mail_name']) . '-articleviews.dat'; @@ -101,10 +99,11 @@ if (! $message) { $title .= ' - ' . $group . ' - ' . $subject; } include "head.inc"; - +throttle_hits($client_device); if ($client_device != "bot") { $_SESSION['rsactive'] = true; } +write_access_log(); echo '

'; echo '' . basename(getcwd()) . ' / '; diff --git a/Rocksolid_Light/rocksolid/article.php b/Rocksolid_Light/rocksolid/article.php index 9cbd093..a0aecda 100644 --- a/Rocksolid_Light/rocksolid/article.php +++ b/Rocksolid_Light/rocksolid/article.php @@ -6,8 +6,6 @@ include "config.inc.php"; include "auth.inc"; include "$file_newsportal"; -throttle_hits(); - // register parameters $id = $_REQUEST["id"]; $group = _rawurldecode($_REQUEST["group"]); @@ -47,6 +45,7 @@ if (! $message) { $title .= ' - ' . $group . ' - ' . $subject; } include "head.inc"; +throttle_hits($client_device); // has the user read-rights on this article? if ((function_exists("npreg_group_has_read_access") && ! npreg_group_has_read_access($group)) || (function_exists("npreg_group_is_visible") && ! npreg_group_is_visible($group))) { diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php index d69edb3..30d7497 100644 --- a/Rocksolid_Light/rocksolid/newsportal.php +++ b/Rocksolid_Light/rocksolid/newsportal.php @@ -1734,7 +1734,10 @@ function disable_page_by_user_agent($client_device, $useragent, $script = "Page" function throttle_hits() { - global $CONFIG, $logdir; + global $CONFIG, $logdir, $client_device; + if ($client_device == "bot") { + $_SESSION['bot'] = 'true'; + } $logfile = $logdir . '/newsportal.log'; if (! isset($_SESSION['starttime'])) { $_SESSION['starttime'] = time(); diff --git a/Rocksolid_Light/rocksolid/overboard.php b/Rocksolid_Light/rocksolid/overboard.php old mode 100755 new mode 100644 index 886080b..18d1d27 --- a/Rocksolid_Light/rocksolid/overboard.php +++ b/Rocksolid_Light/rocksolid/overboard.php @@ -31,8 +31,6 @@ include "config.inc.php"; include "auth.inc"; include "$file_newsportal"; -throttle_hits(); -write_access_log(); if (isset($_COOKIE['mail_name'])) { if ($userdata = get_user_mail_auth_data($_COOKIE['mail_name'])) { $userfile = $spooldir . '/' . strtolower($_COOKIE['mail_name']) . '-articleviews.dat'; @@ -58,6 +56,14 @@ if (isset($_GET['thisgroup'])) { $title .= " - " . $config_name . " - overboard"; } include "head.inc"; +throttle_hits($client_device); +if (disable_page_by_user_agent($client_device, "bot", "Overboard")) { + echo "
Page Disabled
"; + include "tail.inc"; + exit(); +} +write_access_log(); + $CONFIG = include ($config_file); $logfile = $logdir . '/overboard.log'; diff --git a/Rocksolid_Light/rocksolid/search.php b/Rocksolid_Light/rocksolid/search.php index ae14191..e9fbfed 100644 --- a/Rocksolid_Light/rocksolid/search.php +++ b/Rocksolid_Light/rocksolid/search.php @@ -9,8 +9,6 @@ header("Pragma: cache"); include "config.inc.php"; include "newsportal.php"; -throttle_hits(); - $snippet_size = 100; if (isset($_REQUEST['data']) && $_REQUEST['data'] == '') { @@ -20,6 +18,7 @@ if (isset($_REQUEST['data']) && $_REQUEST['data'] == '') { if ((! isset($_POST['key']) || ! password_verify($CONFIG['thissitekey'], $_POST['key'])) || ((strlen(trim($_REQUEST['terms'])) < 2) && ! $_REQUEST['data'])) { include "head.inc"; + throttle_hits($client_device); if (disable_page_by_user_agent($client_device, "bot", "Search")) { echo "
Page Disabled
"; include "tail.inc"; diff --git a/Rocksolid_Light/rocksolid/thread.php b/Rocksolid_Light/rocksolid/thread.php index 4d8da5e..02aceef 100644 --- a/Rocksolid_Light/rocksolid/thread.php +++ b/Rocksolid_Light/rocksolid/thread.php @@ -8,10 +8,6 @@ include "config.inc.php"; include ("$file_newsportal"); include "auth.inc"; -$logfile = $logdir . '/newsportal.log'; -throttle_hits(); -write_access_log(); - // register parameters $group = _rawurldecode($_REQUEST["group"]); if (isset($_REQUEST["first"])) @@ -41,6 +37,9 @@ if (isset($_COOKIE['mail_name'])) { $thread_show["latest"] = true; $title .= ' - ' . $group; include "head.inc"; +$logfile = $logdir . '/newsportal.log'; +throttle_hits($client_device); +write_access_log(); $CONFIG = include ($config_file); diff --git a/Rocksolid_Light/rslight/scripts/count_users.php b/Rocksolid_Light/rslight/scripts/count_users.php old mode 100755 new mode 100644 index 5cd100b..4c49ccf --- a/Rocksolid_Light/rslight/scripts/count_users.php +++ b/Rocksolid_Light/rslight/scripts/count_users.php @@ -1,49 +1,62 @@ query('SELECT COUNT(DISTINCT msgid) FROM overview')->fetchColumn(); - $dbh = null; - return $count; +function count_articles() +{ + GLOBAL $CONFIG, $spooldir; + $database = $spooldir . '/articles-overview.db3'; + $dbh = overview_db_open($database); + $count = $dbh->query('SELECT COUNT(DISTINCT msgid) FROM overview')->fetchColumn(); + $dbh = null; + return $count; } -function count_users() { - GLOBAL $CONFIG, $spooldir; - $session_age = 600; - $session_save_file = $spooldir.'/sessions.dat'; +function count_users() +{ + GLOBAL $CONFIG, $spooldir; + $session_age = 600; + $session_save_file = $spooldir . '/sessions.dat'; $session_dir = $CONFIG['tac']; $session_files = scandir($session_dir); $count = 0; - foreach($session_files as $session_file) { - if(filemtime($session_dir.'/'.$session_file) < time() - $session_age) { - continue; - } - if(strpos($session_file, 'sess_') === 0) { - $contents = file_get_contents($session_dir.'/'.$session_file); - if(strpos($contents, 'rsactive') !== false) { - $count++; + $bot_count = 0; + foreach ($session_files as $session_file) { + if (filemtime($session_dir . '/' . $session_file) < time() - $session_age) { + continue; + } + if (strpos($session_file, 'sess_') === 0) { + $contents = file_get_contents($session_dir . '/' . $session_file); + if (strpos($contents, 'rsactive') !== false) { + $count ++; + } + if (strpos($contents, 'bot') !== false) { + $bot_count ++; } } } - if($count == 1) { - $are = 'is'; - $users = 'user'; - } else { - $are = 'are'; - $users = 'users'; - } - $session_info = '

There '.$are.' currently '.$count.' '. $users.' online
Total messages: '.number_format(count_articles()).'

'."\r\n"; - file_put_contents($session_save_file, $session_info); + if ($count == 1) { + $are = 'is'; + $users = 'user'; + } else { + $are = 'are'; + $users = 'users'; + } + if ($bot_count == 1) { + $bot_are = 'is'; + $bot_users = 'spider'; + } else { + $bot_are = 'are'; + $bot_users = 'spiders'; + } + $session_info = '

There ' . $are . ' currently ' . $count . ' ' . $users . ' online / plus ' . $bot_count . ' ' . $bot_users . '
Total messages: ' . number_format(count_articles()) . '

' . "\r\n"; + file_put_contents($session_save_file, $session_info); } ?>