mtstaticdnsgen 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 Mikrotik static DNS records CLI output to stdout',
  8. '--generate' => 'generate Mikrotik static DNS records CLI output to a file',
  9. '--splitchunks' => 'split domains list to file chunks with size under 4096 Kb for processing with internal Mikrotik script',
  10. '--help' => 'show small help'
  11. );
  12. $option = $argv[1];
  13. if (isset($allowedOptions[$option])) {
  14. switch ($option) {
  15. case '--preview':
  16. print($tech->getMTStaticDNSScript());
  17. break;
  18. case '--generate':
  19. $generationResult = $tech->saveMTStaticDNSScript();
  20. if (!empty($generationResult)) {
  21. print('Mikrotik update script file ' . $generationResult . ' saved' . PHP_EOL);
  22. } else {
  23. print('Mikrotik script generation skipped because MT_DNSSTATIC_SCRIPT_PATH option empty' . PHP_EOL);
  24. }
  25. break;
  26. case '--splitchunks':
  27. $chunksCount = $tech->splitDNsListToChunksForMT();
  28. if (!empty($chunksCount)) {
  29. print('Mikrotik chunk files created count: ' . $chunksCount . '.' . PHP_EOL
  30. . 'Look for created "mt_dnsstatic_chunk_.1984t" files in "/tmp" (default path)' . PHP_EOL);
  31. } else {
  32. print('Mikrotik chunk files generation failed: either the domains list is empty or some unknown error occurred' . PHP_EOL);
  33. }
  34. break;
  35. case '--help':
  36. print('Usage: php cli/mtstaticdnsgen --option' . PHP_EOL);
  37. print('Available options:' . PHP_EOL);
  38. if (!empty($allowedOptions)) {
  39. foreach ($allowedOptions as $optionName => $optionDesc) {
  40. print($optionName . ' - ' . $optionDesc . PHP_EOL);
  41. }
  42. }
  43. break;
  44. }
  45. } else {
  46. print('Unknown command line option: ' . $option . PHP_EOL);
  47. }
  48. } else {
  49. //option requirement notification
  50. print('At least one option required.' . PHP_EOL);
  51. print('Usage: php cli/mtstaticdnsgen --option' . PHP_EOL);
  52. print('For example: php cli/mtstaticdnsgen --help' . PHP_EOL);
  53. }
  54. ?>