12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- include ('api.1984tech.php');
- $tech = new OrwellWorld();
- //need at least 1 command line argument
- if ($argc >= 2) {
- $allowedOptions = array(
- '--preview' => 'preview dns zones file for isc-bind to stdout',
- '--preview-rpz' => 'preview dns RPZ zone file for isc-bind to stdout',
- '--preview-unbound' => 'preview dns zones file to stdout for unbound',
- '--list' => 'list loaded domains',
- '--generate' => 'generate zones file on filesystem for isc-bind',
- '--generate-rpz' => 'generate RPZ zone file on filesystem for isc-bind',
- '--generate-unbound' => 'generate zones file on filesystem for unbound',
- '--help' => 'show small help'
- );
- $option = $argv[1];
- if (isset($allowedOptions[$option])) {
- switch ($option) {
- case '--preview':
- print($tech->getBindZones());
- break;
- case '--preview-rpz':
- print($tech->getBindRpzZone());
- break;
- case '--preview-unbound':
- print($tech->getUnboundZones());
- break;
- case '--list':
- print($tech->renderDomainsRaw());
- break;
- case '--generate':
- $generationResult = $tech->saveBindZones();
- if (!empty($generationResult)) {
- print('Zones file ' . $generationResult . ' saved' . PHP_EOL);
- } else {
- print('Zones generation skipped because DNS_ZONES option empty' . PHP_EOL);
- }
- break;
- case '--generate-rpz':
- print($tech->saveBindRpzZone());
- break;
- case '--generate-unbound':
- $generationResult = $tech->saveUnboundZones();
- if (!empty($generationResult)) {
- print('Zones file ' . $generationResult . ' saved' . PHP_EOL);
- } else {
- print('Zones generation skipped because DNS_ZONES option empty' . PHP_EOL);
- }
- break;
- case '--help':
- print('Usage: php cli/dnsgen --option' . PHP_EOL);
- print('Available options:' . PHP_EOL);
- if (!empty($allowedOptions)) {
- foreach ($allowedOptions as $optionName => $optionDesc) {
- print($optionName . ' - ' . $optionDesc . PHP_EOL);
- }
- }
- break;
- }
- } else {
- print('Unknown command line option: ' . $option . PHP_EOL);
- }
- } else {
- //option requirement notification
- print('At least one option required.' . PHP_EOL);
- print('Usage: php cli/dnsgen --option' . PHP_EOL);
- print('For example: php cli/dnsgen --help' . PHP_EOL);
- }
- ?>
|