|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* eduVPN - End-user friendly VPN. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright: 2016-2017, The Commons Conservancy eduVPN Programme |
|
7
|
|
|
* SPDX-License-Identifier: AGPL-3.0+ |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace SURFnet\VPN\Server\Api; |
|
11
|
|
|
|
|
12
|
|
|
use SURFnet\VPN\Common\Config; |
|
13
|
|
|
use SURFnet\VPN\Common\Http\ApiResponse; |
|
14
|
|
|
use SURFnet\VPN\Common\Http\AuthUtils; |
|
15
|
|
|
use SURFnet\VPN\Common\Http\Request; |
|
16
|
|
|
use SURFnet\VPN\Common\Http\Service; |
|
17
|
|
|
use SURFnet\VPN\Common\Http\ServiceModuleInterface; |
|
18
|
|
|
use SURFnet\VPN\Common\ProfileConfig; |
|
19
|
|
|
|
|
20
|
|
|
class InfoModule implements ServiceModuleInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var \SURFnet\VPN\Common\Config */ |
|
23
|
|
|
private $config; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct(Config $config) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->config = $config; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function init(Service $service) |
|
31
|
|
|
{ |
|
32
|
|
|
/* INFO */ |
|
33
|
|
|
$service->get( |
|
34
|
|
|
'/instance_number', |
|
35
|
|
|
function (Request $request, array $hookData) { |
|
36
|
|
|
AuthUtils::requireUser($hookData, ['vpn-server-node']); |
|
37
|
|
|
|
|
38
|
|
|
return new ApiResponse('instance_number', $this->config->getItem('instanceNumber')); |
|
39
|
|
|
} |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$service->get( |
|
43
|
|
|
'/profile_list', |
|
44
|
|
|
function (Request $request, array $hookData) { |
|
45
|
|
|
AuthUtils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal', 'vpn-server-node']); |
|
46
|
|
|
|
|
47
|
|
|
$profileList = []; |
|
48
|
|
|
foreach ($this->config->getSection('vpnProfiles')->toArray() as $profileId => $profileData) { |
|
49
|
|
|
$profileConfig = new ProfileConfig($profileData); |
|
50
|
|
|
$profileList[$profileId] = $profileConfig->toArray(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return new ApiResponse('profile_list', $profileList); |
|
54
|
|
|
} |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|