mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Сбор IP и UserAgent + фикс логирования в IPs
This commit is contained in:
parent
6b8477ed01
commit
0997ee1ca9
5 changed files with 29 additions and 7 deletions
|
@ -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;
|
||||
|
|
|
@ -24,7 +24,7 @@ class IPs
|
|||
if(!$res) {
|
||||
$res = new IP;
|
||||
$res->setIp($ip);
|
||||
$res->save();
|
||||
$res->save(false);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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`
|
Loading…
Reference in a new issue