ipfwgen 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 ipfw update script to stdout',
  8. '--resolve' => 'render IPs list of loaded domains',
  9. '--generate' => 'generate ipfw update script on filesystem',
  10. '--tableupdate' => 'updates ipfw table with domains IPs',
  11. '--help' => 'show small help'
  12. );
  13. $option = $argv[1];
  14. if (isset($allowedOptions[$option])) {
  15. switch ($option) {
  16. case '--preview':
  17. print($tech->getIpfwScript());
  18. break;
  19. case '--resolve':
  20. print($tech->renderDomainsIps());
  21. break;
  22. case '--generate':
  23. $generationResult = $tech->saveIpfwScript();
  24. if (!empty($generationResult)) {
  25. print('ipfw update script file ' . $generationResult . ' saved' . PHP_EOL);
  26. } else {
  27. print('ipfw script generation skipped because IPFW_SCRIPT_PATH option empty' . PHP_EOL);
  28. }
  29. break;
  30. case '--tableupdate':
  31. print($tech->ipfwTableUpdate());
  32. break;
  33. case '--help':
  34. print('Usage: php cli/ipfwgen --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/ipfwgen --option' . PHP_EOL);
  50. print('For example: php cli/ipfwgen --help' . PHP_EOL);
  51. }