Improve counting users by separating bots/throttled.
This commit is contained in:
parent
97e2a04c1f
commit
d8d2509ed2
|
@ -5,7 +5,6 @@ header("Cache-Control: max-age=100");
|
|||
header("Pragma: cache");
|
||||
|
||||
include "config.inc.php";
|
||||
include "auth.inc";
|
||||
include "$file_newsportal";
|
||||
|
||||
$logfile = $logdir . '/newsportal.log';
|
||||
|
@ -99,11 +98,6 @@ if (! $message) {
|
|||
$title .= ' - ' . $group . ' - ' . $subject;
|
||||
}
|
||||
include "head.inc";
|
||||
throttle_hits($client_device);
|
||||
if ($client_device != "bot") {
|
||||
$_SESSION['rsactive'] = true;
|
||||
}
|
||||
write_access_log();
|
||||
|
||||
echo '<h1 class="np_thread_headline">';
|
||||
echo '<a href="' . $file_index . '" target=' . $frame['menu'] . '>' . basename(getcwd()) . '</a> / ';
|
||||
|
|
|
@ -1,40 +1,18 @@
|
|||
<?php
|
||||
|
||||
$client_device = get_client_user_agent_info();
|
||||
if ($client_device != "bot") {
|
||||
$_SESSION['rsactive'] = true;
|
||||
}
|
||||
throttle_hits($client_device);
|
||||
write_access_log();
|
||||
|
||||
echo '<html><head>';
|
||||
echo '<title>' . htmlspecialchars($title) . '</title>';
|
||||
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
|
||||
echo '<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=<?=$www_charset?>">';
|
||||
include "config.inc.php";
|
||||
|
||||
// Try to get browser info to use for extra formatting of page
|
||||
$ua = strtolower($_SERVER["HTTP_USER_AGENT"]);
|
||||
$devices = array(
|
||||
"bot",
|
||||
"spider",
|
||||
"mobile",
|
||||
"lynx",
|
||||
"w3m",
|
||||
"links",
|
||||
"ipad",
|
||||
"tablet"
|
||||
);
|
||||
$client_device = "desktop";
|
||||
foreach ($devices as $device) {
|
||||
if (strpos($ua, $device) !== false) {
|
||||
$client_device = $device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($client_device == "spider") {
|
||||
$client_device = "bot";
|
||||
}
|
||||
// Log client device if enabled by semaphore
|
||||
if (file_exists($config_dir . '/devicelog.enable')) {
|
||||
$client_ip = getenv("REMOTE_ADDR");
|
||||
$logfile = $logdir . '/device.log';
|
||||
file_put_contents($logfile, "\n" . date('M d H:i:s') . " " . $config_name . " Client: " . $client_ip . " browser: " . $client_device, FILE_APPEND);
|
||||
file_put_contents($logfile, "\nFull UA: ".$ua, FILE_APPEND);
|
||||
}
|
||||
|
||||
if (file_exists($config_dir . '/googleanalytics.conf')) {
|
||||
include $config_dir . '/googleanalytics.conf';
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ session_start();
|
|||
$_SESSION['isframed'] = 1;
|
||||
|
||||
include "config.inc.php";
|
||||
include "auth.inc";
|
||||
include ("$file_newsportal");
|
||||
if (isset($frames_on) && $frames_on === true) {
|
||||
?>
|
||||
<script>
|
||||
|
@ -20,6 +20,7 @@ if (isset($frames_on) && $frames_on === true) {
|
|||
}
|
||||
$title .= ' - ' . basename(getcwd());
|
||||
include "head.inc";
|
||||
|
||||
echo '<h1 class="np_thread_headline">' . basename(getcwd()) . '</h1>';
|
||||
echo '<table cellpadding="0" cellspacing="0" class="np_buttonbar"><tr>';
|
||||
// View Latest button
|
||||
|
@ -40,7 +41,6 @@ echo '</form>';
|
|||
echo '</td>';
|
||||
echo '<td width=100%></td></tr></table>';
|
||||
|
||||
include ("$file_newsportal");
|
||||
flush();
|
||||
if (isset($_GET['unsub'])) {
|
||||
if (isset($_COOKIE['mail_name'])) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/*
|
||||
* rslight NNTP<->HTTP Gateway
|
||||
* Download: https://news.novabbs.com/getrslight
|
||||
* NNTP<->HTTP Gateway
|
||||
* Download: https://news.novabbs.com/get
|
||||
*
|
||||
* Based on Newsportal by Florian Amrhein
|
||||
*
|
||||
|
@ -598,7 +598,6 @@ function groups_show($gruppen)
|
|||
return;
|
||||
global $file_thread, $text_groups;
|
||||
$logfile = $logdir . '/debug.log';
|
||||
write_access_log();
|
||||
$c = count($gruppen);
|
||||
$acttype = "keins";
|
||||
echo '<table class="np_groups_table" cellspacing="0"><tr class="np_thread_head"><td width="45px" class="np_thread_head">';
|
||||
|
@ -911,11 +910,11 @@ function parse_header($hdr, $number = "")
|
|||
break;
|
||||
case "x-newsreader:":
|
||||
case "x-mailer:":
|
||||
case "x-rslight-to:":
|
||||
$header->rslight_to = trim($value);
|
||||
case "x--to:":
|
||||
$header->_to = trim($value);
|
||||
break;
|
||||
case "x-rslight-site:":
|
||||
$header->rslight_site = trim($value);
|
||||
case "x--site:":
|
||||
$header->_site = trim($value);
|
||||
break;
|
||||
case "user-agent:":
|
||||
$header->user_agent = trim($value);
|
||||
|
@ -1099,7 +1098,7 @@ function message_cancel($subject, $from, $newsgroups, $ref, $body, $id)
|
|||
return $message;
|
||||
}
|
||||
|
||||
function rslight_encrypt($data, $key)
|
||||
function _encrypt($data, $key)
|
||||
{
|
||||
$encryption_key = base64_decode($key);
|
||||
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
||||
|
@ -1119,7 +1118,7 @@ function _rawurldecode($string)
|
|||
return $string;
|
||||
}
|
||||
|
||||
function rslight_decrypt($data, $key)
|
||||
function _decrypt($data, $key)
|
||||
{
|
||||
$encryption_key = base64_decode($key);
|
||||
list ($encrypted_data, $iv) = explode('::', base64_decode($data), 2);
|
||||
|
@ -1157,7 +1156,7 @@ function check_bbs_auth($username, $password)
|
|||
|
||||
// Create accounts for $anonymous and $CONFIG['server_auth_user'] if not exist
|
||||
if ($username == strtolower($CONFIG['anonusername'])) {
|
||||
if (filemtime($config_dir . "rslight.inc.php") > filemtime($userFilename)) {
|
||||
if (filemtime($config_dir . ".inc.php") > filemtime($userFilename)) {
|
||||
if ($userFileHandle = fopen($userFilename, 'w+')) {
|
||||
fwrite($userFileHandle, password_hash($CONFIG['anonuserpass'], PASSWORD_DEFAULT));
|
||||
fclose($userFileHandle);
|
||||
|
@ -1165,7 +1164,7 @@ function check_bbs_auth($username, $password)
|
|||
}
|
||||
}
|
||||
if ($username == strtolower($CONFIG['server_auth_user'])) {
|
||||
if (filemtime($config_dir . "rslight.inc.php") > filemtime($userFilename)) {
|
||||
if (filemtime($config_dir . ".inc.php") > filemtime($userFilename)) {
|
||||
if ($userFileHandle = fopen($userFilename, 'w+')) {
|
||||
fwrite($userFileHandle, password_hash($CONFIG['server_auth_pass'], PASSWORD_DEFAULT));
|
||||
fclose($userFileHandle);
|
||||
|
@ -1717,14 +1716,12 @@ function get_config_value($configfile, $request)
|
|||
|
||||
function disable_page_by_user_agent($client_device, $useragent, $script = "Page")
|
||||
{
|
||||
global $logdir, $config_name, $count_bots;
|
||||
global $logdir, $config_name;
|
||||
if ($client_device == $useragent) {
|
||||
$logfile = $logdir . '/device.log';
|
||||
file_put_contents($logfile, "\n" . date('M d H:i:s') . " " . $config_name . " " . $script . " disabled for '" . $useragent . "' Exiting...", FILE_APPEND);
|
||||
if ($client_device == "bot") {
|
||||
if (isset($_SESSION['rsactive'])) {
|
||||
unset($_SESSION['rsactive']);
|
||||
}
|
||||
$_SESSION['bot'] = true;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
@ -1732,9 +1729,11 @@ function disable_page_by_user_agent($client_device, $useragent, $script = "Page"
|
|||
}
|
||||
}
|
||||
|
||||
function throttle_hits()
|
||||
function throttle_hits($client_device)
|
||||
{
|
||||
global $CONFIG, $logdir, $client_device;
|
||||
global $CONFIG, $logdir;
|
||||
$client_device = get_client_user_agent_info();
|
||||
$_SESSION['rsactive'] = true;
|
||||
if ($client_device == "bot") {
|
||||
$_SESSION['bot'] = 'true';
|
||||
}
|
||||
|
@ -1752,12 +1751,44 @@ function throttle_hits()
|
|||
if (! isset($_SESSION['throttled'])) {
|
||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Too many requests from " . $_SERVER['REMOTE_ADDR'] . " throttling", FILE_APPEND);
|
||||
$_SESSION['throttled'] = true;
|
||||
if (isset($_SESSION['rsactive'])) {
|
||||
unset($_SESSION['rsactive']);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
unset($_SESSION['throttled']);
|
||||
}
|
||||
|
||||
function get_client_user_agent_info()
|
||||
{
|
||||
// Try to get browser info to use for extra formatting of page
|
||||
$ua = strtolower($_SERVER["HTTP_USER_AGENT"]);
|
||||
$devices = array(
|
||||
"bot",
|
||||
"spider",
|
||||
"mobile",
|
||||
"lynx",
|
||||
"w3m",
|
||||
"links",
|
||||
"ipad",
|
||||
"tablet"
|
||||
);
|
||||
$client_device = "desktop";
|
||||
foreach ($devices as $device) {
|
||||
if (strpos($ua, $device) !== false) {
|
||||
$client_device = $device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($client_device == "spider") {
|
||||
$client_device = "bot";
|
||||
}
|
||||
// Log client device if enabled by semaphore
|
||||
if (file_exists($config_dir . '/devicelog.enable')) {
|
||||
$client_ip = getenv("REMOTE_ADDR");
|
||||
$logfile = $logdir . '/device.log';
|
||||
file_put_contents($logfile, "\n" . date('M d H:i:s') . " " . $config_name . " Client: " . $client_ip . " browser: " . $client_device, FILE_APPEND);
|
||||
file_put_contents($logfile, "\nFull UA: " . $ua, FILE_APPEND);
|
||||
}
|
||||
return $client_device;
|
||||
}
|
||||
|
||||
function get_user_mail_auth_data($user)
|
||||
|
|
|
@ -56,13 +56,11 @@ 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 "<center>Page Disabled</center>";
|
||||
include "tail.inc";
|
||||
exit();
|
||||
}
|
||||
write_access_log();
|
||||
|
||||
$CONFIG = include ($config_file);
|
||||
$logfile = $logdir . '/overboard.log';
|
||||
|
|
|
@ -18,7 +18,6 @@ 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 "<center>Page Disabled</center>";
|
||||
include "tail.inc";
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
session_start();
|
||||
|
||||
$_SESSION['group'] = $_SERVER['REQUEST_URI'];
|
||||
$_SESSION['rsactive'] = true;
|
||||
|
||||
include "config.inc.php";
|
||||
include ("$file_newsportal");
|
||||
|
@ -37,10 +36,8 @@ 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();
|
||||
|
||||
$logfile = $logdir . '/newsportal.log';
|
||||
$CONFIG = include ($config_file);
|
||||
|
||||
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))) {
|
||||
|
|
|
@ -28,6 +28,7 @@ function count_users()
|
|||
$session_files = scandir($session_dir);
|
||||
$count = 0;
|
||||
$bot_count = 0;
|
||||
$throttled_count = 0;
|
||||
foreach ($session_files as $session_file) {
|
||||
if (filemtime($session_dir . '/' . $session_file) < time() - $session_age) {
|
||||
continue;
|
||||
|
@ -36,9 +37,12 @@ function count_users()
|
|||
$contents = file_get_contents($session_dir . '/' . $session_file);
|
||||
if (strpos($contents, 'rsactive') !== false) {
|
||||
$count ++;
|
||||
}
|
||||
if (strpos($contents, 'bot') !== false) {
|
||||
$bot_count ++;
|
||||
if (strpos($contents, 'bot') !== false) {
|
||||
$bot_count ++;
|
||||
}
|
||||
if (strpos($contents, 'throttled') !== false) {
|
||||
$throttled_count ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,13 +54,12 @@ function count_users()
|
|||
$users = 'users';
|
||||
}
|
||||
if ($bot_count == 1) {
|
||||
$bot_are = 'is';
|
||||
$bot_users = 'bot';
|
||||
} else {
|
||||
$bot_are = 'are';
|
||||
$bot_users = 'bots';
|
||||
}
|
||||
$session_info = '<h1 class="np_thread_headline">There ' . $are . ' currently ' . $count . ' ' . $users . ' online / plus ' . $bot_count . ' ' . $bot_users . '<br />Total messages: ' . number_format(count_articles()) . '</h1>' . "\r\n";
|
||||
$throttled_users = 'throttled';
|
||||
$session_info = '<h1 class="np_thread_headline">There ' . $are . ' currently ' . $count . ' ' . $users . ' online (including ' . $bot_count . ' ' . $bot_users . ' and ' . $throttled_count . ' ' . $throttled_users . ')<br />Total messages: ' . number_format(count_articles()) . '</h1>' . "\r\n";
|
||||
file_put_contents($session_save_file, $session_info);
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue