Сбор IP и UserAgent + фикс логирования в IPs

This commit is contained in:
n1rwana 2023-08-08 21:14:43 +03:00
parent 6b8477ed01
commit 0997ee1ca9
No known key found for this signature in database
GPG key ID: 1D319A83686EC843
5 changed files with 29 additions and 7 deletions

View file

@ -6,16 +6,24 @@ class CurrentUser
{ {
private static $instance = null; private static $instance = null;
private $user; 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) if ($user)
$this->user = $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; return self::$instance;
} }
@ -24,6 +32,16 @@ class CurrentUser
return $this->user; return $this->user;
} }
public function getIP(): string
{
return $this->ip;
}
public function getUserAgent(): string
{
return $this->useragent;
}
public static function i() public static function i()
{ {
return self::$instance; return self::$instance;

View file

@ -24,7 +24,7 @@ class IPs
if(!$res) { if(!$res) {
$res = new IP; $res = new IP;
$res->setIp($ip); $res->setIp($ip);
$res->save(); $res->save(false);
return $res; return $res;
} }

View file

@ -65,7 +65,9 @@ class Logs
$log->setXdiff_Old(json_encode($nobject)); $log->setXdiff_Old(json_encode($nobject));
$log->setXdiff_New(json_encode($_changes)); $log->setXdiff_New(json_encode($_changes));
$log->setTs(time()); $log->setTs(time());
$log->save(false); $log->setIp(CurrentUser::i()->getIP());
$log->setUserAgent(CurrentUser::i()->getUserAgent());
$log->save();
} }
} }

View file

@ -211,7 +211,7 @@ abstract class OpenVKPresenter extends SimplePresenter
$this->user->id = $this->user->identity->getId(); $this->user->id = $this->user->identity->getId();
$this->template->thisUser = $this->user->identity; $this->template->thisUser = $this->user->identity;
$this->template->userTainted = $user->isTainted(); $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->isDeleted() && !$this->deactivationTolerant) {
if($this->user->identity->isDeactivated()) { if($this->user->identity->isDeactivated()) {

View file

@ -8,7 +8,9 @@ CREATE TABLE `logs`
`object_id` bigint(20) UNSIGNED NOT NULL, `object_id` bigint(20) UNSIGNED NOT NULL,
`xdiff_old` longtext COLLATE utf8mb4_unicode_ci NOT NULL, `xdiff_old` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`xdiff_new` 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; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `logs` ALTER TABLE `logs`