dnsgen 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. include ('api.1984tech.php');
  3. $tech = new OrwellWorld();
  4. //need at least 1 command line argument
  5. if ($argc >= 2) {
  6. $allowedOptions = array(
  7. '--preview' => 'preview dns zones file for isc-bind to stdout',
  8. '--preview-rpz' => 'preview dns RPZ zone file for isc-bind to stdout',
  9. '--preview-unbound' => 'preview dns zones file to stdout for unbound',
  10. '--list' => 'list loaded domains',
  11. '--generate' => 'generate zones file on filesystem for isc-bind',
  12. '--generate-rpz' => 'generate RPZ zone file on filesystem for isc-bind',
  13. '--generate-unbound' => 'generate zones file on filesystem for unbound',
  14. '--help' => 'show small help'
  15. );
  16. $option = $argv[1];
  17. if (isset($allowedOptions[$option])) {
  18. switch ($option) {
  19. case '--preview':
  20. print($tech->getBindZones());
  21. break;
  22. case '--preview-rpz':
  23. print($tech->getBindRpzZone());
  24. break;
  25. case '--preview-unbound':
  26. print($tech->getUnboundZones());
  27. break;
  28. case '--list':
  29. print($tech->renderDomainsRaw());
  30. break;
  31. case '--generate':
  32. $generationResult = $tech->saveBindZones();
  33. if (!empty($generationResult)) {
  34. print('Zones file ' . $generationResult . ' saved' . PHP_EOL);
  35. } else {
  36. print('Zones generation skipped because DNS_ZONES option empty' . PHP_EOL);
  37. }
  38. break;
  39. case '--generate-rpz':
  40. print($tech->saveBindRpzZone());
  41. break;
  42. case '--generate-unbound':
  43. $generationResult = $tech->saveUnboundZones();
  44. if (!empty($generationResult)) {
  45. print('Zones file ' . $generationResult . ' saved' . PHP_EOL);
  46. } else {
  47. print('Zones generation skipped because DNS_ZONES option empty' . PHP_EOL);
  48. }
  49. break;
  50. case '--help':
  51. print('Usage: php cli/dnsgen --option' . PHP_EOL);
  52. print('Available options:' . PHP_EOL);
  53. if (!empty($allowedOptions)) {
  54. foreach ($allowedOptions as $optionName => $optionDesc) {
  55. print($optionName . ' - ' . $optionDesc . PHP_EOL);
  56. }
  57. }
  58. break;
  59. }
  60. } else {
  61. print('Unknown command line option: ' . $option . PHP_EOL);
  62. }
  63. } else {
  64. //option requirement notification
  65. print('At least one option required.' . PHP_EOL);
  66. print('Usage: php cli/dnsgen --option' . PHP_EOL);
  67. print('For example: php cli/dnsgen --help' . PHP_EOL);
  68. }
  69. ?>