|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2015 François Kooman <[email protected]>. |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
namespace fkooman\VPN\Server; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Manage all OpenVPN servers controlled by this service using each instance's |
|
21
|
|
|
* ServerApi. |
|
22
|
|
|
*/ |
|
23
|
|
|
class ServerManager |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var array */ |
|
26
|
|
|
private $servers; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->servers = array(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function addServer(ServerApi $serverApi) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->servers[] = $serverApi; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function version() |
|
39
|
|
|
{ |
|
40
|
|
|
$serverVersions = array(); |
|
41
|
|
|
foreach ($this->servers as $server) { |
|
42
|
|
|
$serverVersions[] = $server->version(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return array('items' => $serverVersions); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get the connection information about connected clients. |
|
50
|
|
|
* |
|
51
|
|
|
* @return array per server connection information |
|
52
|
|
|
*/ |
|
53
|
|
|
public function status() |
|
54
|
|
|
{ |
|
55
|
|
|
$serverConnections = array(); |
|
56
|
|
|
foreach ($this->servers as $server) { |
|
57
|
|
|
$serverConnections[] = $server->status(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return array('items' => $serverConnections); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get server information. |
|
65
|
|
|
* |
|
66
|
|
|
* @return array per server status information |
|
67
|
|
|
*/ |
|
68
|
|
|
public function loadStats() |
|
69
|
|
|
{ |
|
70
|
|
|
$loadStats = array(); |
|
71
|
|
|
foreach ($this->servers as $server) { |
|
72
|
|
|
$loadStats[] = $server->loadStats(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return array('items' => $loadStats); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Disconnect all clients with this CN from all servers managed by this |
|
80
|
|
|
* service. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $commonName the CN to kill |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool true if >= 1 client was killed, otherwise false |
|
85
|
|
|
*/ |
|
86
|
|
|
public function kill($commonName) |
|
87
|
|
|
{ |
|
88
|
|
|
$killStats = array(); |
|
89
|
|
|
foreach ($this->servers as $server) { |
|
90
|
|
|
$killStats[] = $server->kill($commonName); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return array('items' => $killStats); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|