mtgen 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 address list update script to stdout',
  8. '--resolve' => 'render IPs list of loaded domains',
  9. '--generate' => 'generate Mikrotik address list update script on filesystem',
  10. '--listmk' => 'preview mikrotik per domain address list to stdout',
  11. '--help' => 'show small help'
  12. );
  13. $option = $argv[1];
  14. if (isset($allowedOptions[$option])) {
  15. switch ($option) {
  16. case '--preview':
  17. print($tech->getMikrotikScript());
  18. break;
  19. case '--resolve':
  20. print($tech->renderDomainsIps());
  21. break;
  22. case '--generate':
  23. $generationResult = $tech->saveMikrotikScript();
  24. if (!empty($generationResult)) {
  25. print('Mikrotik update script file ' . $generationResult . ' saved' . PHP_EOL);
  26. } else {
  27. print('Mikrotik script generation skipped because MT_SCRIPT_PATH option empty' . PHP_EOL);
  28. }
  29. break;
  30. case '--listmk':
  31. print($tech->getMikrotikScriptDomains());
  32. break;
  33. case '--help':
  34. print('Usage: php cli/mtgen --option' . PHP_EOL);
  35. print('Available options:' . PHP_EOL);
  36. if (!empty($allowedOptions)) {
  37. foreach ($allowedOptions as $optionName => $optionDesc) {
  38. print($optionName . ' - ' . $optionDesc . PHP_EOL);
  39. }
  40. }
  41. break;
  42. }
  43. } else {
  44. print('Unknown command line option: ' . $option . PHP_EOL);
  45. }
  46. } else {
  47. //option requirement notification
  48. print('At least one option required.' . PHP_EOL);
  49. print('Usage: php cli/mtgen --option' . PHP_EOL);
  50. print('For example: php cli/mtgen --help' . PHP_EOL);
  51. }
  52. ?>