-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnsapi.php
More file actions
executable file
·130 lines (122 loc) · 4.95 KB
/
dnsapi.php
File metadata and controls
executable file
·130 lines (122 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/php
<?php
/**
* The main entry point for this CLI app.
* Make executable to run the CLI with your systems default PHP version or run as input file for your favorite PHP binary
*/
if (php_sapi_name() !== 'cli') {
exit;
}
require 'vendor/autoload.php';
require 'lib/functions.php';
require 'lib/defines.php';
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;
use core\CONSOLE;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
/**
* Class DNSAPI
*
* Registers all available options for the CLI application and calls functions of this application dependent on
* provieded CLI commands and parameters
*/
class DNSAPI extends CLI
{
/**
* Register available command- and parameterstructure of the CLI
*
* @param Options $options
*/
protected function setup(Options $options)
{
$options->setHelp('A helper tool to sync DNSSEC information from ISPConfig to INWX domain registry');
$options->registerOption('version', 'print version', 'v');
$options->registerCommand('isp', 'Load DNSSEC keys from ISPConfig API');
$options->registerOption('export', 'Export DNSSEC keys from ISPConfig DNS Zones', 'e', false, 'isp');
$options->registerCommand('inwx', 'Perform Requests on INWX API. Specify at least one option.');
$options->registerOption('summary', 'Print summary of published keys', 's', false, 'inwx');
$options->registerOption('report', 'Print detailed report of published keys', 'r', false, 'inwx');
$options->registerOption('list', 'Print list of domains known in ISPConfig and INWX', 'l', false, 'inwx');
$options->registerOption('keylist', 'Print key data of a specific origin domain', 'k', 'origin', 'inwx');
$options->registerOption('publish', 'Push all keys from ISPConfig that are not yet published to INWX', 'p', false, 'inwx');
$options->registerOption('clean', 'Clean corrupted and orphaned keys for a specific domain', 'c', 'origin', 'inwx');
$options->registerOption('cleanorphans', 'Delete INWX keys that are not known in ISPConfig', false, false, 'inwx');
$options->registerOption('cleancorrupt', 'Delete INWX keys that are known in ISPConfig but differ in record details', false, false, 'inwx');
$options->registerArgument('origin', 'Origin Domain of DNS Zone (e.g. domain.tld.)', false, 'inwx');
}
/**
* Main function of the CLI application
*
* This is where the entered commands, parameters and arguments are evaluated and corresponding library methods are called
*
* @param Options $options
* @throws ErrorException
*/
protected function main(Options $options)
{
if($options->getCmd() == 'isp') {
$DnssecApi = \isp\ISPDnssec::instance();
$DnssecApi->loadKeys();
if($options->getOpt('export')){
$DnssecApi->exportKeys();
}
} elseif($options->getCmd() == 'inwx') {
$DnssecApi = \inwx\DnssecApiInwx::instance();
$this->executeProviderAction($options, $DnssecApi);
}
elseif ($options->getOpt('version')) {
$jsonstring = file_get_contents('composer.json');
$jsondata = json_decode($jsonstring, true);
$this->info($jsondata['version']);
} else {
echo $options->help();
}
}
/**
* Execute the provider-specific action that was requested from CLI
* @param Options $options
* @param \core\DnssecApi $api Instance of a Provider API class extended from DnssecApi
*/
private function executeProviderAction(Options $options, \core\DnssecApi $api){
if(count($options->getOpt()) === 0){
CONSOLE::warning("Please pass options to perform INWX actions");
echo $options->help();
return;
}
// loop all options and perform API actions in requested order
foreach($options->getOpt() as $opt => $optval){
switch($opt){
case 'summary':
$api->printSummary();
break;
case 'report':
$api->printReport();
break;
case 'list':
$api->printDomainList();
break;
case 'publish':
$api->publishUnpublishedKeys();
break;
case 'clean':
$api->cleanCorruptedKeys($optval);
$api->cleanOrphanedKeys($optval);
break;
case 'cleanorphans':
$api->cleanOrphanedKeys();
break;
case 'cleancorrupt':
$api->cleanCorruptedKeys();
break;
case 'keylist':
$api->printZoneKeys($optval);
break;
}
}
}
}
// execute it
$cli = new DNSAPI();
CONSOLE::registerCli($cli);
$cli->run();