|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2016 SURFnet. |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
7
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
8
|
|
|
* License, or (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU Affero General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace SURFnet\VPN\Common\HttpClient; |
|
20
|
|
|
|
|
21
|
|
|
class ServerClient extends BaseClient |
|
22
|
|
|
{ |
|
23
|
|
|
public function __construct(HttpClientInterface $httpClient, $baseUri) |
|
24
|
|
|
{ |
|
25
|
|
|
parent::__construct($httpClient, $baseUri); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function clientConnections() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->get('client_connections'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function log($dateTime, $ipAddress) |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->get( |
|
36
|
|
|
'log', |
|
37
|
|
|
[ |
|
38
|
|
|
'date_time' => $dateTime, |
|
39
|
|
|
'ip_address' => $ipAddress, |
|
40
|
|
|
] |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function stats() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->get('stats'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function addClientCertificate($userId, $displayName) |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->post( |
|
52
|
|
|
'add_client_certificate', |
|
53
|
|
|
[ |
|
54
|
|
|
'user_id' => $userId, |
|
55
|
|
|
'display_name' => $displayName, |
|
56
|
|
|
] |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function addServerCertificate($commonName) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->post( |
|
63
|
|
|
'add_server_certificate', |
|
64
|
|
|
[ |
|
65
|
|
|
'common_name' => $commonName, |
|
66
|
|
|
] |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function listClientCertificates($userId) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->get('list_client_certificates', ['user_id' => $userId]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function clientCertificateInfo($commonName) |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->get('client_certificate_info', ['common_name' => $commonName]); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function enableUser($userId) |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->post('enable_user', ['user_id' => $userId]); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function userList() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->get('user_list'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function disableUser($userId) |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->post('disable_user', ['user_id' => $userId]); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function isDisabledUser($userId) |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->get('is_disabled_user', ['user_id' => $userId]); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function disableClientCertificate($commonName) |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->post('disable_client_certificate', ['common_name' => $commonName]); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function enableClientCertificate($commonName) |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->post('enable_client_certificate', ['common_name' => $commonName]); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function killClient($commonName) |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->post('kill_client', ['common_name' => $commonName]); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function instanceNumber() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->get('instance_number'); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function profileList() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->get('profile_list'); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function hasTotpSecret($userId) |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->get('has_totp_secret', ['user_id' => $userId]); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function hasVootToken($userId) |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->get('has_voot_token', ['user_id' => $userId]); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function userGroups($userId) |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->get('user_groups', ['user_id' => $userId]); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function motd() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->get('motd'); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function setMotd($motdMessage) |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->post('set_motd', ['motd_message' => $motdMessage]); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function deleteMotd() |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->post('delete_motd', []); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function setVootToken($userId, $vootToken) |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->post( |
|
158
|
|
|
'set_voot_token', |
|
159
|
|
|
[ |
|
160
|
|
|
'user_id' => $userId, |
|
161
|
|
|
'voot_token' => $vootToken, |
|
162
|
|
|
] |
|
163
|
|
|
); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function deleteTotpSecret($userId) |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->post('delete_totp_secret', ['user_id' => $userId]); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function setTotpSecret($userId, $totpSecret, $totpKey) |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->post( |
|
174
|
|
|
'set_totp_secret', |
|
175
|
|
|
[ |
|
176
|
|
|
'user_id' => $userId, |
|
177
|
|
|
'totp_secret' => $totpSecret, |
|
178
|
|
|
'totp_key' => $totpKey, |
|
179
|
|
|
] |
|
180
|
|
|
); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function verifyTotpKey($userId, $totpKey) |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->post( |
|
186
|
|
|
'verify_totp_key', |
|
187
|
|
|
[ |
|
188
|
|
|
'user_id' => $userId, |
|
189
|
|
|
'totp_key' => $totpKey, |
|
190
|
|
|
] |
|
191
|
|
|
); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function connect($profileId, $commonName, $ip4, $ip6, $connectedAt) |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->post( |
|
197
|
|
|
'connect', |
|
198
|
|
|
[ |
|
199
|
|
|
'profile_id' => $profileId, |
|
200
|
|
|
'common_name' => $commonName, |
|
201
|
|
|
'ip4' => $ip4, |
|
202
|
|
|
'ip6' => $ip6, |
|
203
|
|
|
'connected_at' => $connectedAt, |
|
204
|
|
|
] |
|
205
|
|
|
); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function disconnect($profileId, $commonName, $ip4, $ip6, $connectedAt, $disconnectedAt, $bytesTransferred) |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->post( |
|
211
|
|
|
'disconnect', |
|
212
|
|
|
[ |
|
213
|
|
|
'profile_id' => $profileId, |
|
214
|
|
|
'common_name' => $commonName, |
|
215
|
|
|
'ip4' => $ip4, |
|
216
|
|
|
'ip6' => $ip6, |
|
217
|
|
|
'connected_at' => $connectedAt, |
|
218
|
|
|
'disconnected_at' => $disconnectedAt, |
|
219
|
|
|
'bytes_transferred' => $bytesTransferred, |
|
220
|
|
|
] |
|
221
|
|
|
); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
public function verifyOtp($commonName, $otpType, $otpKey) |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->post( |
|
227
|
|
|
'verify_otp', |
|
228
|
|
|
[ |
|
229
|
|
|
'common_name' => $commonName, |
|
230
|
|
|
'otp_type' => $otpType, |
|
231
|
|
|
'otp_key' => $otpKey, |
|
232
|
|
|
] |
|
233
|
|
|
); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|