Makes the old code work with the new Log plugin
parent
a004602ce2
commit
242b63317b
|
@ -28,7 +28,10 @@ class RateLimiter {
|
|||
} else {
|
||||
$this->db = $database->getConnection();
|
||||
}
|
||||
// Initialize logger via Log wrapper
|
||||
require_once __DIR__ . '/log.php';
|
||||
$this->log = new Log($database);
|
||||
// Initialize database tables
|
||||
$this->createTablesIfNotExist();
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ class User {
|
|||
*/
|
||||
public function login($username, $password, $twoFactorCode = null) {
|
||||
// Get user's IP address
|
||||
require_once __DIR__ . '/../helpers/logs.php';
|
||||
$ipAddress = getUserIP();
|
||||
|
||||
// Check rate limiting first
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../helpers/security.php';
|
||||
require_once __DIR__ . '/../helpers/logs.php';
|
||||
|
||||
function applyCsrfMiddleware() {
|
||||
global $logObject;
|
||||
global $logObject, $user_IP;
|
||||
$security = SecurityHelper::getInstance();
|
||||
|
||||
// Skip CSRF check for GET requests
|
||||
|
@ -34,7 +33,7 @@ function applyCsrfMiddleware() {
|
|||
$token = $_POST['csrf_token'] ?? $_SERVER['HTTP_X_CSRF_TOKEN'] ?? '';
|
||||
if (!$security->verifyCsrfToken($token)) {
|
||||
// Log CSRF attempt
|
||||
$ipAddress = getUserIP();
|
||||
$ipAddress = $user_IP;
|
||||
$logMessage = sprintf(
|
||||
"CSRF attempt detected - IP: %s, Page: %s, User: %s",
|
||||
$ipAddress,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../classes/ratelimiter.php';
|
||||
require_once __DIR__ . '/../helpers/logs.php';
|
||||
|
||||
/**
|
||||
* Rate limit middleware for page requests
|
||||
|
@ -13,10 +12,10 @@ require_once __DIR__ . '/../helpers/logs.php';
|
|||
* @return bool True if request is allowed, false if rate limited
|
||||
*/
|
||||
function checkRateLimit($database, $endpoint, $userId = null, $existingRateLimiter = null) {
|
||||
global $app_root;
|
||||
global $app_root, $user_IP;
|
||||
$isTest = defined('PHPUNIT_RUNNING');
|
||||
$rateLimiter = $existingRateLimiter ?? new RateLimiter($database);
|
||||
$ipAddress = getUserIP();
|
||||
$ipAddress = $user_IP;
|
||||
|
||||
// Check if request is allowed
|
||||
if (!$rateLimiter->isPageRequestAllowed($ipAddress, $endpoint, $userId)) {
|
||||
|
|
|
@ -14,7 +14,6 @@ require '../app/classes/api_response.php';
|
|||
|
||||
// Initialize required objects
|
||||
$userObject = new User($dbWeb);
|
||||
$logObject = new Log($dbWeb);
|
||||
$configObject = new Config();
|
||||
|
||||
// For AJAX requests
|
||||
|
|
|
@ -24,8 +24,8 @@ try {
|
|||
// Initialize RateLimiter
|
||||
require_once '../app/classes/ratelimiter.php';
|
||||
$rateLimiter = new RateLimiter($db);
|
||||
|
||||
// Get user IP
|
||||
require_once '../app/helpers/ip_helper.php';
|
||||
$user_IP = getUserIP();
|
||||
|
||||
$action = $_REQUEST['action'] ?? '';
|
||||
|
|
Loading…
Reference in New Issue