<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 7.1.06
// Randem Systems: https://randemsystems.support
// BotBanish Option Subroutines
// Date: 04/11/2026
//
///////////////////////////////////////////////////////////////////////////////////////////////////////

function BotBanishGetOptionsArray() {

	global $BotBanishSettings;

	require_once $BotBanishSettings['BOTBANISH_SUBS_DIR'] . 'BotBanish_Subs_Screen.php';
	require_once $BotBanishSettings['BOTBANISH_SUBS_DIR'] . 'BotBanish_Subs_FormInput.php';

	$cols = 60;
	$rows = 8;

	$info = array(

				// Configurations

				'BOTBANISH_ACTIVE' => array('name' => 'BOTBANISH_ACTIVE', 'type' => 'boolval', 'section' => 'Configuration'),
				'BOTBANISH_APIKEY' => array('name' => 'BOTBANISH_APIKEY', 'type' => 'text', 'size' => 40, 'section' => 'Configuration'),
				'BOTBANISH_REDIRECT_ONLY_ACTIVE' => array('name' => 'BOTBANISH_REDIRECT_ONLY_ACTIVE', 'type' => 'boolval', 'section' => 'Configuration'),
				'BOTBANISH_LANGUAGE_SELECT' => array('name' => 'BOTBANISH_LANGUAGE_SELECT', 'type' => 'select', 'items' => 'BOTBANISH_LANGUAGES', 'pct' => 40, 'section' => 'Configuration'),

				'BOTBANISH_GEO_ACTIVE' => array('name' => 'BOTBANISH_GEO_ACTIVE', 'type' => 'boolval', 'section' => 'Configuration'),
				'BOTBANISH_GEO_APIKEY' => array('name' => 'BOTBANISH_GEO_APIKEY', 'type' => 'text', 'size' => 40, 'section' => 'Configuration'),

				'BOTBANISH_WEBMASTER_EMAIL' => array('name' => 'BOTBANISH_WEBMASTER_EMAIL', 'type' => 'text', 'size' => 60, 'section' => 'Configuration'),

				// Blacklist / Whitelist Processing

				'BOTBANISH_BAD_DOMAIN_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_BAD_DOMAIN_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Black/White Lists'),
				'BOTBANISH_URL_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_URL_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Black/White Lists'),
				'BOTBANISH_COUNTRY_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_COUNTRY_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Black/White Lists'),
				'BOTBANISH_IP_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_IP_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Black/White Lists'),

				// Bad Bot Processing

				'BOTBANISH_BAD_BOT_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_BAD_BOT_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Bad Bot Processing'),
				'BOTBANISH_SPOOF_BOT_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_SPOOF_BOT_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Bad Bot Processing'),
				'BOTBANISH_HIDDEN_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_HIDDEN_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Bad Bot Processing'),
				'BOTBANISH_EMPTY_USERAGENT_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_EMPTY_USERAGENT_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Bad Bot Processing'),
				'BOTBANISH_UNKNOWN_BOT_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_UNKNOWN_BOT_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Bad Bot Processing'),

				// Other Prcessing

				'BOTBANISH_INVALID_REQUEST_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_INVALID_REQUEST_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Miscellaneous'),
				'BOTBANISH_HITCOUNT_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_HITCOUNT_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Miscellaneous'),
				'BOTBANISH_ABUSE_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_ABUSE_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Miscellaneous'),
				'BOTBANISH_IP_RANGE_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_IP_RANGE_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Miscellaneous'),
				'BOTBANISH_TRUNCATE_ACTIVE' => array('name' => 'BOTBANISH_TRUNCATE_ACTIVE', 'type' => 'boolval', 'section' => 'Miscellaneous'),
				'BOTBANISH_RETAIN_ACTIVE' => array('name' => 'BOTBANISH_RETAIN_ACTIVE', 'type' => 'boolval', 'section' => 'Miscellaneous'),
				'BOTBANISH_EMAIL_USERNAME_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_EMAIL_USERNAME_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Miscellaneous'),

				// Options

				'BOTBANISH_DELETE_DATA' => array('name' => 'BOTBANISH_DELETE_DATA', 'type' => 'boolval', 'section' => 'Options'),
				'BOTBANISH_SEND_EMAIL_ALERTS' => array('name' => 'BOTBANISH_SEND_EMAIL_ALERTS', 'type' => 'boolval', 'section' => 'Options'),
				'BOTBANISH_ANALYTICS_DOWNLOADS' => array('name' => 'BOTBANISH_ANALYTICS_DOWNLOADS', 'type' => 'boolval', 'section' => 'Options'),
				'BOTBANISH_ANALYTICS_WEBSITE' => array('name' => 'BOTBANISH_ANALYTICS_WEBSITE', 'type' => 'boolval', 'section' => 'Options'),
				'BOTBANISH_PLUGIN_AUDIT_ACTIVE' => array('name' => 'BOTBANISH_PLUGIN_AUDIT_ACTIVE', 'type' => 'boolval', 'section' => 'Options', 'system' => 'WORDPRESS'),
				'BOTBANISH_PLUGIN_AUDIT_DISPLAY_DATETIME' => array('name' => 'BOTBANISH_PLUGIN_AUDIT_DISPLAY_DATETIME', 'type' => 'boolval', 'section' => 'Options', 'system' => 'WORDPRESS'),

				// .htaccess Protection

				'BOTBANISH_XMLRPC_ACTIVE' => array('name' => 'BOTBANISH_XMLRPC_ACTIVE', 'type' => 'boolval', 'section' => '.htaccess Protection', 'system' => 'WORDPRESS'),
				'BOTBANISH_WPCONFIG_ACTIVE' => array('name' => 'BOTBANISH_WPCONFIG_ACTIVE', 'type' => 'boolval', 'section' => '.htaccess Protection', 'system' => 'WORDPRESS'),
				'BOTBANISH_HTACCESS_ACTIVE' => array('name' => 'BOTBANISH_HTACCESS_ACTIVE', 'type' => 'boolval', 'section' => '.htaccess Protection'),
				'BOTBANISH_PROTECT_ROOT_ACTIVE' => array('name' => 'BOTBANISH_PROTECT_ROOT_ACTIVE', 'type' => 'boolval', 'section' => '.htaccess Protection'),

				// Limits

				'BOTBANISH_MAX_HIT_COUNT' => array('name' => 'BOTBANISH_MAX_HIT_COUNT', 'type' => 'number', 'size' => 5, 'min' => 1, 'max' => $BotBanishSettings['BOTBANISH_MAX_HIT_COUNT'], 'section' => 'Limits'),
				'BOTBANISH_MAX_IP_RANGE_COUNT' => array('name' => 'BOTBANISH_MAX_IP_RANGE_COUNT', 'type' => 'number', 'size' => 5, 'min' => 1, 'max' => $BotBanishSettings['BOTBANISH_MAX_IP_RANGE_COUNT'], 'section' => 'Limits'),
				'BOTBANISH_CLIENT_CLEANUP_DAYS_IP' => array('name' => 'BOTBANISH_CLIENT_CLEANUP_DAYS_IP', 'type' => 'number', 'size' => 5, 'min' => 1, 'max' => $BotBanishSettings['BOTBANISH_CLIENT_CLEANUP_DAYS_IP'], 'section' => 'Limits'),
				'BOTBANISH_CLIENT_CLEANUP_DAYS_LOGS' => array('name' => 'BOTBANISH_CLIENT_CLEANUP_DAYS_LOGS', 'type' => 'number', 'size' => 5, 'min' => 1, 'max' => $BotBanishSettings['BOTBANISH_CLIENT_CLEANUP_DAYS_LOGS'], 'section' => 'Limits'),
				'BOTBANISH_PLUGIN_AUDIT_DAYS' => array('name' => 'BOTBANISH_PLUGIN_AUDIT_DAYS', 'type' => 'number', 'size' => 5, 'min' => 1, 'max' => $BotBanishSettings['BOTBANISH_PLUGIN_AUDIT_DAYS'], 'section' => 'Limits', 'system' => 'WORDPRESS'),
				'BOTBANISH_TRUNCATE_DAYS' => array('name' => 'BOTBANISH_TRUNCATE_DAYS', 'type' => 'number', 'size' => 5, 'min' => 1, 'max' => $BotBanishSettings['BOTBANISH_TRUNCATE_DAYS'], 'section' => 'Limits'),
				'BOTBANISH_RETAIN_DAYS' => array('name' => 'BOTBANISH_RETAIN_DAYS', 'type' => 'number', 'size' => 5, 'min' => 1, 'max' => $BotBanishSettings['BOTBANISH_RETAIN_DAYS'], 'section' => 'Limits'),
				'BOTBANISH_TRUNCATE_LAST_DATE' => array('name' => 'BOTBANISH_TRUNCATE_LAST_DATE', 'type' => 'text', 'size' => 25, 'readonly' => true, 'section' => 'Limits'),

				// Page Error Processing

				'BOTBANISH_DOC_ERRORS_MONITOR' => array('name' => 'BOTBANISH_DOC_ERRORS_MONITOR', 'type' => 'boolval', 'section' => 'Page Error Processing'),
				'BOTBANISH_404_EXTENSIONS' => array('name' => 'BOTBANISH_404_EXTENSIONS', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'Page Error Processing'),
				'BOTBANISH_DOC_ERRORS' => array('name' => 'BOTBANISH_DOC_ERRORS', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'Page Error Processing'),

				// Contact Denial

				'BOTBANISH_CONTACT_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_CONTACT_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'Contact Denial'),
				'BOTBANISH_CONTACT_LEARNING_ACTIVE' => array('name' => 'BOTBANISH_CONTACT_LEARNING_ACTIVE', 'type' => 'boolval', 'section' => 'Contact Denial'),
				'BOTBANISH_CONTACT_FORM' => array('name' => 'BOTBANISH_CONTACT_FORM', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'Contact Denial'),
				'BOTBANISH_CONTACT_REQUIRED' => array('name' => 'BOTBANISH_CONTACT_REQUIRED', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'Contact Denial'),
				'BOTBANISH_CONTACT_ELIMINATE' => array('name' => 'BOTBANISH_CONTACT_ELIMINATE', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'Contact Denial'),
				'BOTBANISH_CONTACT_FORBIDDEN' => array('name' => 'BOTBANISH_CONTACT_FORBIDDEN', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'Contact Denial'),
				'BOTBANISH_CONTACT_EXCLUDE' => array('name' => 'BOTBANISH_CONTACT_EXCLUDE', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'Contact Denial'),
				'BOTBANISH_CONTACT_TAGS' => array('name' => 'BOTBANISH_CONTACT_TAGS', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'Contact Denial'),

				// User Denial

				'BOTBANISH_USER_LOCKOUT_ACTIVE' => array('name' => 'BOTBANISH_USER_LOCKOUT_ACTIVE', 'type' => 'boolval', 'section' => 'User Denial'),
				'BOTBANISH_USER_REQUIRED' => array('name' => 'BOTBANISH_USER_REQUIRED', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'User Denial'),
				'BOTBANISH_USER_ELIMINATE' => array('name' => 'BOTBANISH_USER_ELIMINATE', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'User Denial'),
				'BOTBANISH_USER_FORBIDDEN' => array('name' => 'BOTBANISH_USER_FORBIDDEN', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'User Denial'),
				'BOTBANISH_USER_EXCLUDE' => array('name' => 'BOTBANISH_USER_EXCLUDE', 'type' => 'large_text', 'cols' => $cols, 'rows' => $rows, 'section' => 'User Denial'),
			);

	return $info;
}


function BotBanishGetOptionVars($systemType = '') {

	if (empty($systemType)) {

		$system = BotBanishCheckSystem();
		$systemType = $system['system'];
	}

	switch ($systemType) {

		case 'SMF':

			$vars = BotBanish_SMF_Options();
			break;

		case 'WORDPRESS':

			$vars = BotBanish_WORDPRESS_Options();
			break;

		case 'WEBSITE':
		default:

			$vars = BotBanish_WEBSITE_Options();
			break;
	}

	return $vars;
}

function BotBanish_SMF_Options() {

	global $BotBanishSettings, $BotBanishText;

	$options = BotBanishGetOptionsArray();

	$vars = array();
	$last_section = '';

	foreach ($options as $key => $value) {

		if (BotBanishSkipOption('SMF', $key, $value))
		continue;

		if (isset($value['section']) && ($value['section'] != $last_section)) {

			$vars[] = BotBanishDrawLine($value['section']);
			$last_section = $value['section'];
		}

		$disabled = isset($value['readonly']) && $value['readonly'] ? 'true' : '';
		
		switch ($value['type']) {

			case 'boolval':

				$vars[$key] = array('check', $key, 'value' => $BotBanishSettings[$key], 'disabled' => $disabled);
				break;

			case 'number':

				$min = isset($value['min']) ? $value['min'] : 1;
				$max = isset($value['max']) ? $value['max'] : 30;
				$size = isset($value['size']) ? $value['size'] : 5;
				$vars[$key] = array('int', $key, 'value' => $BotBanishSettings[$key], 'size' => $size, 'min' => $min, 'max' => $max, 'disabled' => $disabled);
				break;

			case 'text':

				$size = isset($value['size']) ? $value['size'] : 80;
				$vars[$key] = array('text', $key, 'value' => $BotBanishSettings[$key], 'size' => $size, 'disabled' => $disabled);
				break;

			case 'large_text':

				$cols = isset($value['cols']) ? $value['cols'] : 80;
				$rows = isset($value['rows']) ? $value['rows'] : 2;
				$vars[$key] = array('large_text', $key, 'value' => $BotBanishSettings[$key], 'cols' => $cols, 'rows' => $rows, 'disabled' => $disabled);
				break;

			case 'select':

				$vars[$key] = array('select', $key, $BotBanishSettings[$value['items']], 'value' => $BotBanishSettings[$key], 'disabled' => $disabled);
				break;
		}
	}

	return array('info' => $vars);
}

function BotBanish_WORDPRESS_Options() {

	$options = BotBanishGetOptionsArray();

	$info = array();
	$keys = array();

	foreach ($options as $key => $value) {

		if (BotBanishSkipOption('WORDPRESS', $key, $value))
			continue;

		$name = '_botbanishtext_' . strtolower($key);
		$info[$name] = $value;
		$keys[$name] = $value['type'];
	}

	return array('info' => $info, 'keys' => $keys);
}

function BotBanish_WEBSITE_Options() {

	$options = BotBanishGetOptionsArray();

	return $options;
}

function BotBanishSkipOption($system, $key, $value) {

	global $BotBanishSettings;

	// If the option is not intended for SMF, skip it

	if (isset($value['system'])) {

		if ($value['system'] != $system)
			return true;
	}

	// if the installation is in the root, don't show the option

	if ($key == 'BOTBANISH_PROTECT_ROOT_ACTIVE') {

		if (isset($BotBanishSettings['BOTBANISH_PROTECT_ROOT_ACTIVE_NOSHOW']) && $BotBanishSettings['BOTBANISH_PROTECT_ROOT_ACTIVE_NOSHOW'])
			return true;
	}

	return false;
}
?>
