<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 8.0.00
// Randem Systems: https://randemsystems.support
// BotBanish User Information Validation
// Date: 04/30/2026
//
// Function: Check for valid user information
//
// Input is an array that can contain any of the following:
//
//	$userinfo = array(
//					'first' => '',
//					'last' => '',
//					'email' => '',
//					'phone' => '',
//					'ip' => '',
//				);
//
///////////////////////////////////////////////////////////////////////////////////////////////////////

function BotBanishUserVerify($userinfo = array()) {

	//-----------------------------------------------------------------
	// This area is for user processing of the BOT/USER
	// Check the local database for IP
	// If we are checking or setting username / email lockouts, we skip the IP check
	// because we may need to record the username/email combination.
	//-----------------------------------------------------------------

	global $BotBanishSettings;

	$userinfo['ip'] = isset($userinfo['ip']) && !empty($userinfo['ip']) ? $userinfo['ip'] : BotBanishGetIP();

	$action = BotBanishValidateUser($userinfo);
	$lockout = false;

	BotBanishProcessAction($userinfo, $action);

	if ($action['terminate'])
		$lockout = $BotBanishSettings['BOTBANISH_USER_LOCKOUT'];

	return $lockout;
}

function BotBanishProcessAction($userinfo, $action) {

	if (isset($action['terminate']) && $action['terminate'])

		BotBanishRejectUserMessage($userinfo, $action);
	else
		BotBanishUserLogMessages($action, 'Good User', 'User', true);
}

function BotBanishUserLogMessages($userinfo, $error, $filetype = '', $logit = false) {

	BotBanishTraceIt($error, $userinfo, true);

	if (!$logit)	return;

	if (BotBanishLimitLogs($userinfo['ip'])) return;

	$msg = var_export($userinfo, true) . PHP_EOL . str_repeat('-', 80) . PHP_EOL;
	$msg = str_ireplace(array('<br>', '<br/>','</br>'), PHP_EOL, $msg);

	$filetype = empty($filetype) ? 'User' : $filetype;
	$filename = BotBanishSetLogFilename($filetype);
	$str = PHP_EOL . PHP_EOL . str_repeat('=', 80) . PHP_EOL;
	$date = BotBanishGetCorrectDateTime();

	global $BotBanishSettings;

	$str = $date . ' - ' . $str . $BotBanishSettings['BOTBANISH_FONT_RED_START'] . BotBanishGetCorrectDateTime() . ' - ' . $error . ' - IP: ' . $userinfo['ip'] . $BotBanishSettings['BOTBANISH_FONT_RED_END'] . PHP_EOL . PHP_EOL . $msg;

//	BotBanishWriteFile($filename, $str, true);
	BotBanishTraceIt('BotBanishUserLogMessages - End - $str ', $str, true);
}

function BotBanishUserLockOut($userinfo) {

	global $BotBanishSettings, $BotBanishSession;

	$useragent = BotBanishGetUserAgent($_SERVER);
	$useragent = BotBanishFixUserAgent($useragent); // Try to convert and remove extraneous information
	$date = BotBanishGetCorrectDateTimeB();

	$row = array();
	$row['bot_ip'] = $userinfo['ip'];
	$row['user_agent'] = $useragent;
	$row['forcelockout'] = $BotBanishSettings['BOTBANISH_USER_LOCKOUT'];
	$row['domain_name'] = BotBanishGetDomainName($_SERVER);
	$row['domain'] = BotBanishGetDomainOrigin($userinfo['ip']);

	BotBanishHTACCESSUpdate($row, 'ip');
	BotBanishInsertLocal($row);		// Update local IP Database

	$BotBanishSession->setSessionKey('locked', $BotBanishSettings['BOTBANISH_USER_LOCKOUT']);
}

 function BotBanishRejectUserMessage($userinfo, $action, $row){

	global $BotBanishSettings;

	BotBanishUserLogMessages(array($userinfo, $row), $action['error'], 'Reject', true);
	BotBanishUserLockOut($userinfo);
}
?>