diff --git a/Web/Models/Repositories/CurrentUser.php b/Web/Models/Repositories/CurrentUser.php index c71a5ac7..c6cb942b 100644 --- a/Web/Models/Repositories/CurrentUser.php +++ b/Web/Models/Repositories/CurrentUser.php @@ -6,16 +6,24 @@ class CurrentUser { private static $instance = null; private $user; + private $ip; + private $useragent; - public function __construct(?User $user = NULL) + public function __construct(?User $user = NULL, ?string $ip = NULL, ?string $useragent = NULL) { if ($user) $this->user = $user; + + if ($ip) + $this->ip = $ip; + + if ($useragent) + $this->useragent = $useragent; } - public static function get($user) + public static function get($user, $ip, $useragent) { - if (self::$instance === null) self::$instance = new self($user); + if (self::$instance === null) self::$instance = new self($user, $ip, $useragent); return self::$instance; } @@ -24,6 +32,16 @@ class CurrentUser return $this->user; } + public function getIP(): string + { + return $this->ip; + } + + public function getUserAgent(): string + { + return $this->useragent; + } + public static function i() { return self::$instance; diff --git a/Web/Models/Repositories/IPs.php b/Web/Models/Repositories/IPs.php index c4485b73..59fc6570 100644 --- a/Web/Models/Repositories/IPs.php +++ b/Web/Models/Repositories/IPs.php @@ -24,7 +24,7 @@ class IPs if(!$res) { $res = new IP; $res->setIp($ip); - $res->save(); + $res->save(false); return $res; } diff --git a/Web/Models/Repositories/Logs.php b/Web/Models/Repositories/Logs.php index 96ceba0a..6f7d3937 100644 --- a/Web/Models/Repositories/Logs.php +++ b/Web/Models/Repositories/Logs.php @@ -65,7 +65,9 @@ class Logs $log->setXdiff_Old(json_encode($nobject)); $log->setXdiff_New(json_encode($_changes)); $log->setTs(time()); - $log->save(false); + $log->setIp(CurrentUser::i()->getIP()); + $log->setUserAgent(CurrentUser::i()->getUserAgent()); + $log->save(); } } diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 0cf67444..b4444bda 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -211,7 +211,7 @@ abstract class OpenVKPresenter extends SimplePresenter $this->user->id = $this->user->identity->getId(); $this->template->thisUser = $this->user->identity; $this->template->userTainted = $user->isTainted(); - CurrentUser::get($this->user->identity); + CurrentUser::get($this->user->identity, $_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_USER_AGENT"]); if($this->user->identity->isDeleted() && !$this->deactivationTolerant) { if($this->user->identity->isDeactivated()) { diff --git a/install/00038-logs.sql b/install/sqls/00038-logs.sql similarity index 79% rename from install/00038-logs.sql rename to install/sqls/00038-logs.sql index 3943f629..e136c83f 100644 --- a/install/00038-logs.sql +++ b/install/sqls/00038-logs.sql @@ -8,7 +8,9 @@ CREATE TABLE `logs` `object_id` bigint(20) UNSIGNED NOT NULL, `xdiff_old` longtext COLLATE utf8mb4_unicode_ci NOT NULL, `xdiff_new` longtext COLLATE utf8mb4_unicode_ci NOT NULL, - `ts` bigint(20) NOT NULL + `ts` bigint(20) NOT NULL, + `ip` tinytext NOT NULL, + `useragent` longtext NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ALTER TABLE `logs`