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