'input_validation_failure', 'event_id' => $event_id, 'variable' => is_scalar($variable) ? (string) $variable : gettype($variable), 'source_address' => $source_address === false ? '' : (string) $source_address, 'request_method' => isset($_SERVER['REQUEST_METHOD']) ? (string) $_SERVER['REQUEST_METHOD'] : PHP_SAPI, 'script' => isset($_SERVER['SCRIPT_NAME']) ? basename((string) $_SERVER['SCRIPT_NAME']) : '' ]; cacti_log(json_encode($event, JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE), false, 'SECURITY'); return $event_id; } /** * Terminates the script execution and outputs an error message for HTML input validation errors. * * @param mixed $variable - The name of the variable that caused the validation error. * @param mixed $value - The value of the variable that caused the validation error. * @param string $message - An optional custom error message. * * @return void */ function die_html_input_error(mixed $variable = null, mixed $value = null, string $message = '') : void { $event_id = security_log_input_validation_failure($variable); $func = CACTI_CLI ? 'trim' : 'htmle'; $variable = ($variable !== null ? ', Variable:' . $func($variable) : ''); $value = ($value !== null ? ', Value:' . $func($value) : ''); if ($message == '') { $message = __esc('Validation error for variable %s with a value of %s. See backtrace below for more details.', $variable, $value); } elseif (!CACTI_CLI) { $message = htmle($message); } $isWeb = CACTI_WEB || isrv('json'); cacti_debug_backtrace('Validation Error, Event: ' . $event_id . $variable . $value, $isWeb); if (!$isWeb) { print $message . PHP_EOL; exit(1); } if (isrv('json')) { cacti_debug_backtrace('Validation Error, Event: ' . $event_id . $variable . $value . ', Source: ' . get_client_addr() . ', Request: ' . json_encode($_REQUEST), false); print json_encode( [ 'status' => '500', 'statusText' => __('Validation Error'), 'responseText' => $message ] ); } else { cacti_debug_backtrace('Validation Error, Event: ' . $event_id . $variable . $value . ', Source: ' . get_client_addr() . ', Request: ' . json_encode($_REQUEST), true); print "
| $message |