-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Storage.php
110 lines (93 loc) · 2.38 KB
/
Storage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\ExcludeByDDNS;
use Piwik\Common;
use Piwik\Option;
use Piwik\Tracker\Cache;
class Storage
{
private $username;
private $hostname = null;
private $ip = null;
private $lastUpdated = null;
public function __construct($username)
{
$this->username = $username;
$this->load();
}
public function setHostname($hostname)
{
$this->hostname = $hostname;
$this->save();
}
public function getHostname()
{
return $this->hostname;
}
public function getIp()
{
return $this->ip;
}
public function getLastUpdated()
{
return $this->lastUpdated;
}
public function setIp($ip)
{
$this->ip = $ip;
$this->lastUpdated = time();
$this->save();
}
protected function load()
{
$data = Option::get('ExcludeByDDNS.' . $this->username);
if (!$data) {
return;
}
$data = (array)@Common::safe_unserialize($data);
if (isset($data['hostname'])) {
$this->hostname = $data['hostname'];
}
if (isset($data['ip'])) {
$this->ip = $data['ip'];
}
if (isset($data['lastUpdated'])) {
$this->lastUpdated = $data['lastUpdated'];
}
}
protected function save()
{
$data = [
'hostname' => $this->hostname,
'ip' => $this->ip,
'lastUpdated' => $this->lastUpdated,
];
Option::set('ExcludeByDDNS.' . $this->username, serialize($data));
Cache::clearCacheGeneral();
}
public static function getAllUsersWithConfig()
{
$options = (array)Option::getLike('ExcludeByDDNS.%');
return array_filter(
array_map(function ($elem) {
return substr($elem, 14);
}, array_keys($options))
);
}
public static function getAllExcludedIps()
{
$options = (array)Option::getLike('ExcludeByDDNS.%');
return array_filter(
array_map(function ($elem) {
$elem = Common::safe_unserialize($elem);
return $elem['ip'];
}, array_values($options))
);
}
}