|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PiHole; |
|
4
|
|
|
|
|
5
|
|
|
use PiHole\Interfaces\QueryInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Single entry point for all classes |
|
9
|
|
|
* |
|
10
|
|
|
* @package PiHole |
|
11
|
|
|
*/ |
|
12
|
|
|
class Client implements QueryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use HttpTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Type of query |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $type = 'get'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Endpoint of query |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $endpoint = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* If auth is required |
|
32
|
|
|
* |
|
33
|
|
|
* @var bool |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $auth = false; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Parameters of query |
|
39
|
|
|
* |
|
40
|
|
|
* @var mixed |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $params; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected static $variables = []; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Client constructor. |
|
51
|
|
|
* |
|
52
|
|
|
* @param \PiHole\Config $config |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct(Config $config) |
|
55
|
|
|
{ |
|
56
|
|
|
// Save config into local variable |
|
57
|
|
|
$this->config = $config; |
|
58
|
|
|
|
|
59
|
|
|
// Store the client object |
|
60
|
|
|
$this->client = new \GuzzleHttp\Client($config->guzzle()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get detailed statistic of system |
|
65
|
|
|
* |
|
66
|
|
|
* @return \PiHole\Interfaces\QueryInterface |
|
67
|
|
|
*/ |
|
68
|
|
|
public function statistics(): QueryInterface |
|
69
|
|
|
{ |
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get version of Pi Hole |
|
75
|
|
|
* |
|
76
|
|
|
* @return \PiHole\Interfaces\QueryInterface |
|
77
|
|
|
* @link ?version |
|
78
|
|
|
*/ |
|
79
|
|
|
public function version(): QueryInterface |
|
80
|
|
|
{ |
|
81
|
|
|
$this->endpoint = ['version' => null]; |
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Enable pihole (should be authorized) |
|
87
|
|
|
* |
|
88
|
|
|
* @return \PiHole\Interfaces\QueryInterface |
|
89
|
|
|
* @link ?enable&auth=webpassword |
|
90
|
|
|
*/ |
|
91
|
|
|
public function enable(): QueryInterface |
|
92
|
|
|
{ |
|
93
|
|
|
$this->endpoint = ['enable' => null]; |
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Disable pihole (should be authorized) |
|
99
|
|
|
* |
|
100
|
|
|
* @return \PiHole\Interfaces\QueryInterface |
|
101
|
|
|
* @link ?disable&auth=webpassword |
|
102
|
|
|
*/ |
|
103
|
|
|
public function disable(): QueryInterface |
|
104
|
|
|
{ |
|
105
|
|
|
$this->endpoint = ['disable' => null]; |
|
106
|
|
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Logout from pihole (should be authorized) |
|
111
|
|
|
* |
|
112
|
|
|
* @return \PiHole\Interfaces\QueryInterface |
|
113
|
|
|
* @link ?logout&auth=webpassword |
|
114
|
|
|
*/ |
|
115
|
|
|
public function logout(): QueryInterface |
|
116
|
|
|
{ |
|
117
|
|
|
$this->endpoint = ['logout' => null]; |
|
118
|
|
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|