Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace GeoIp2\Model;
6
 
7
use GeoIp2\Util;
8
 
9
/**
10
 * This class provides the GeoIP2 Anonymous IP model.
11
 */
12
class AnonymousIp implements \JsonSerializable
13
{
14
    /**
15
     * @var bool this is true if the IP address belongs to
16
     *           any sort of anonymous network
17
     */
18
    public readonly bool $isAnonymous;
19
 
20
    /**
21
     * @var bool This is true if the IP address is
22
     *           registered to an anonymous VPN provider. If a VPN provider does not
23
     *           register subnets under names associated with them, we will likely only
24
     *           flag their IP ranges using the isHostingProvider property.
25
     */
26
    public readonly bool $isAnonymousVpn;
27
 
28
    /**
29
     * @var bool this is true if the IP address belongs
30
     *           to a hosting or VPN provider (see description of isAnonymousVpn property)
31
     */
32
    public readonly bool $isHostingProvider;
33
 
34
    /**
35
     * @var bool this is true if the IP address belongs to
36
     *           a public proxy
37
     */
38
    public readonly bool $isPublicProxy;
39
 
40
    /**
41
     * @var bool this is true if the IP address is
42
     *           on a suspected anonymizing network and belongs to a residential ISP
43
     */
44
    public readonly bool $isResidentialProxy;
45
 
46
    /**
47
     * @var bool this is true if the IP address is a Tor
48
     *           exit node
49
     */
50
    public readonly bool $isTorExitNode;
51
 
52
    /**
53
     * @var string the IP address that the data in the model is
54
     *             for
55
     */
56
    public readonly string $ipAddress;
57
 
58
    /**
59
     * @var string The network in CIDR notation associated with
60
     *             the record. In particular, this is the largest network where all of the
61
     *             fields besides $ipAddress have the same value.
62
     */
63
    public readonly string $network;
64
 
65
    /**
66
     * @ignore
67
     *
68
     * @param array<string, mixed> $raw
69
     */
70
    public function __construct(array $raw)
71
    {
72
        $this->isAnonymous = $raw['is_anonymous'] ?? false;
73
        $this->isAnonymousVpn = $raw['is_anonymous_vpn'] ?? false;
74
        $this->isHostingProvider = $raw['is_hosting_provider'] ?? false;
75
        $this->isPublicProxy = $raw['is_public_proxy'] ?? false;
76
        $this->isResidentialProxy = $raw['is_residential_proxy'] ?? false;
77
        $this->isTorExitNode = $raw['is_tor_exit_node'] ?? false;
78
        $ipAddress = $raw['ip_address'];
79
        $this->ipAddress = $ipAddress;
80
        $this->network = Util::cidr($ipAddress, $raw['prefix_len']);
81
    }
82
 
83
    /**
84
     * @return array<string, mixed>|null
85
     */
86
    public function jsonSerialize(): ?array
87
    {
88
        $js = [];
89
        $js['is_anonymous'] = $this->isAnonymous;
90
        $js['is_anonymous_vpn'] = $this->isAnonymousVpn;
91
        $js['is_hosting_provider'] = $this->isHostingProvider;
92
        $js['is_public_proxy'] = $this->isPublicProxy;
93
        $js['is_residential_proxy'] = $this->isResidentialProxy;
94
        $js['is_tor_exit_node'] = $this->isTorExitNode;
95
        $js['ip_address'] = $this->ipAddress;
96
        $js['network'] = $this->network;
97
 
98
        return $js;
99
    }
100
}