HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/heifetz/heifetz-app/models/LogAuth.php
<?php

declare(strict_types=1);

namespace Models;

use Core\DbLib\DbModel;
use Core\Models\CoreHelper;
use Core\Models\OldUser;
use Helpers\Data;
use Traits\ModelGetQuery;
use Traits\ModelSaveWithLogTrait;

/**
 * Class LogAuth
 *
 * @property int $user_id
 * @property string $created_at
 * @property string $ip
 * @property string $location
 * @property string $user_agent
 * @property string $agent
 * @property string $cookie
 * @property int $id
 * @property int $company_id
 */
class LogAuth extends DbModel
{

    use ModelGetQuery;
    use ModelSaveWithLogTrait;

    static string $tableName = 'logs_auth';

    protected static bool $hasCompanyRelation = true;

    public static function log($userId)
    {
        $ip = $_SERVER['REMOTE_ADDR'];
        $agentInfo = parse_user_agent();

        $cookie = $_COOKIE['rtvahtaAuth'] ?? '';

        if (is_null($cookie)) {
            $cookie = Data::strRand();
            setcookie('rtvahtaAuth', $cookie);
        }

        self::create(
            [
                'user_id' => $userId,
                'created_at' => date('Y-m-d H:i:s'),
                'ip' => $ip,
                'agent' => $agentInfo['platform'] . ': ' . $agentInfo['browser'] . ' ' . $agentInfo['version'],
                'user_agent' => $_SERVER['HTTP_USER_AGENT'],
                'cookie' => $cookie,
                'company_id' => CoreHelper::$companyId,
            ], false
        );
    }

    public static function getUsersIds(): array
    {
        return self::getQuery(['la.user_id'], 'la')
            ->join(OldUser::$tableName . ' u', 'la.user_id = u.id')
            ->group('la.user_id, u.username')
            ->order('u.username')
            ->fetchCol();
    }

    public static function getIps(): array
    {
        return self::getQuery(['ip'])->group('ip')->fetchCol();
    }

    public static function getWithEmptyLocation()
    {
        return self::getQuery()
            ->where('location IS NULL OR location = ?', '')
            ->fetchAll();
    }

    public static function getWithEmptyLocationCount()
    {
        return self::getQuery()
            ->where('location IS NULL OR location = ?', '')
            ->totalCount();
    }

}