pdnsdgen 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 records CLI output for PDNSD config to stdout',
  8. '--generate' => 'generate records CLI output for PDNSD config to a file',
  9. '--help' => 'show small help'
  10. );
  11. $option = $argv[1];
  12. if (isset($allowedOptions[$option])) {
  13. switch ($option) {
  14. case '--preview':
  15. print($tech->getPDNSDScript());
  16. break;
  17. case '--generate':
  18. $generationResult = $tech->savePDNSDScript();
  19. if (!empty($generationResult)) {
  20. print('PDNSD script file ' . $generationResult . ' saved' . PHP_EOL);
  21. } else {
  22. print('PDNSD script generation skipped because PDNSD_SCRIPT_PATH option empty' . PHP_EOL);
  23. }
  24. break;
  25. case '--help':
  26. print('Usage: php cli/pdnsdgen --option' . PHP_EOL);
  27. print('Available options:' . PHP_EOL);
  28. if (!empty($allowedOptions)) {
  29. foreach ($allowedOptions as $optionName => $optionDesc) {
  30. print($optionName . ' - ' . $optionDesc . PHP_EOL);
  31. }
  32. }
  33. break;
  34. }
  35. } else {
  36. print('Unknown command line option: ' . $option . PHP_EOL);
  37. }
  38. } else {
  39. //option requirement notification
  40. print('At least one option required.' . PHP_EOL);
  41. print('Usage: php cli/pdnsdgen --option' . PHP_EOL);
  42. print('For example: php cli/pdnsdgen --help' . PHP_EOL);
  43. }
  44. ?>