|
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
|
|
|
namespace SURFnet\VPN\Server; |
|
19
|
|
|
|
|
20
|
|
|
class PoolConfig extends Config |
|
21
|
|
|
{ |
|
22
|
|
|
private static function defaultValues() |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
|
|
'defaultGateway' => false, |
|
26
|
|
|
'routes' => [], |
|
27
|
|
|
'dns' => [], |
|
28
|
|
|
'useNat' => false, |
|
29
|
|
|
'twoFactor' => false, |
|
30
|
|
|
'clientToClient' => false, |
|
31
|
|
|
'listen' => '0.0.0.0', |
|
32
|
|
|
'enableLog' => false, |
|
33
|
|
|
'enableAcl' => false, |
|
34
|
|
|
'aclGroupList' => [], |
|
35
|
|
|
'blockSmb' => false, |
|
36
|
|
|
'forward6' => true, |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function __construct(array $configData) |
|
41
|
|
|
{ |
|
42
|
|
|
parent::__construct( |
|
43
|
|
|
array_merge(self::defaultValues(), $configData) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Depending on the size of the prefix assigned to this pool, this method |
|
49
|
|
|
* will return the number of OpenVPN processes backing that range, each |
|
50
|
|
|
* pool range is split in #processCount number of OpenVPN processes. |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getProcessCount() |
|
53
|
|
|
{ |
|
54
|
|
|
$range = new IP($this->v('range')); |
|
55
|
|
|
$prefix = $range->getPrefix(); |
|
56
|
|
|
|
|
57
|
|
|
switch ($prefix) { |
|
58
|
|
|
case 32: // 1 IP |
|
59
|
|
|
case 31: // 2 IPs |
|
60
|
|
|
throw new RuntimeException('not enough available IPs in range'); |
|
61
|
|
|
case 30: // 4 IPs (1 usable for client, no splitting) |
|
62
|
|
|
case 29: // 8 IPs (5 usable for clients, no splitting) |
|
63
|
|
|
return 1; |
|
64
|
|
|
case 28: // 16 IPs (12 usable for clients) |
|
|
|
|
|
|
65
|
|
|
case 27: // 32 IPs |
|
66
|
|
|
case 26: // 64 IPs |
|
67
|
|
|
case 25: // 128 IPs |
|
68
|
|
|
return 2; |
|
69
|
|
|
case 24: |
|
70
|
|
|
return 4; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return 8; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.