GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 65058f...8a6e2f )
by François
02:41
created

generate-firewall.php ➔ showHelp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 11

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
1
#!/usr/bin/php
2
<?php
3
/**
4
 *  Copyright (C) 2016 SURFnet.
5
 *
6
 *  This program is free software: you can redistribute it and/or modify
7
 *  it under the terms of the GNU Affero General Public License as
8
 *  published by the Free Software Foundation, either version 3 of the
9
 *  License, or (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU Affero General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU Affero General Public License
17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
require_once sprintf('%s/vendor/autoload.php', dirname(__DIR__));
20
21
use SURFnet\VPN\Server\Config\Firewall;
22
use SURFnet\VPN\Server\InstanceConfig;
23
use SURFnet\VPN\Common\FileIO;
24
use SURFnet\VPN\Server\CliParser;
25
26
try {
27
    $p = new CliParser(
28
        'Generate firewall rules for all instances',
29
        [
30
            'install' => ['install the firewall', false, false],
31
        ]
32
    );
33
34
    $opt = $p->parse($argv);
35
    if ($opt->e('help')) {
36
        echo $p->help();
37
        exit(0);
38
    }
39
40
    // detect all instances
41
    $configList = [];
42
    $configDir = sprintf('%s/config', dirname(__DIR__));
43
    foreach (glob(sprintf('%s/*', $configDir), GLOB_ONLYDIR | GLOB_ERR) as $instanceDir) {
44
        $instanceId = basename($instanceDir);
45
        $configList[$instanceId] = InstanceConfig::fromFile(sprintf('%s/%s/config.yaml', $configDir, $instanceId));
46
    }
47
48
    $firewall = Firewall::getFirewall4($configList);
49
    $firewall6 = Firewall::getFirewall6($configList);
50
51
    if ($opt->e('install')) {
52
        FileIO::writeFile('/etc/sysconfig/iptables', $firewall);
53
        FileIO::writeFile('/etc/sysconfig/ip6tables', $firewall6);
54
    } else {
55
        echo '##########################################'.PHP_EOL;
56
        echo '# IPv4'.PHP_EOL;
57
        echo '##########################################'.PHP_EOL;
58
        echo $firewall;
59
60
        echo '##########################################'.PHP_EOL;
61
        echo '# IPv6'.PHP_EOL;
62
        echo '##########################################'.PHP_EOL;
63
        echo $firewall6;
64
    }
65
} catch (Exception $e) {
66
    echo sprintf('ERROR: %s', $e->getMessage()).PHP_EOL;
67
    exit(1);
68
}
69