|
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\Server\Api; |
|
20
|
|
|
|
|
21
|
|
|
use SURFnet\VPN\Common\Http\ApiResponse; |
|
22
|
|
|
use SURFnet\VPN\Common\Http\AuthUtils; |
|
23
|
|
|
use SURFnet\VPN\Common\Http\InputValidation; |
|
24
|
|
|
use SURFnet\VPN\Common\Http\Request; |
|
25
|
|
|
use SURFnet\VPN\Common\Http\Service; |
|
26
|
|
|
use SURFnet\VPN\Common\Http\ServiceModuleInterface; |
|
27
|
|
|
use SURFnet\VPN\Server\Storage; |
|
28
|
|
|
|
|
29
|
|
|
class LogModule implements ServiceModuleInterface |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var \SURFnet\VPN\Server\Storage */ |
|
32
|
|
|
private $storage; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct(Storage $storage) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->storage = $storage; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function init(Service $service) |
|
40
|
|
|
{ |
|
41
|
|
|
$service->get( |
|
42
|
|
|
'/log', |
|
43
|
|
|
function (Request $request, array $hookData) { |
|
44
|
|
|
AuthUtils::requireUser($hookData, ['vpn-admin-portal']); |
|
45
|
|
|
|
|
46
|
|
|
$dateTime = InputValidation::dateTime($request->getQueryParameter('date_time')); |
|
47
|
|
|
$ipAddress = InputValidation::ipAddress($request->getQueryParameter('ip_address')); |
|
48
|
|
|
|
|
49
|
|
|
$logData = $this->storage->getLogEntry($dateTime, $ipAddress); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($logData as $k => $v) { |
|
52
|
|
|
$certInfo = $this->storage->getUserCertificateInfo($v['common_name']); |
|
53
|
|
|
$logData[$k] = array_merge($logData[$k], $certInfo); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return new ApiResponse('log', $logData); |
|
57
|
|
|
} |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|