123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- include ('api.1984tech.php');
- $tech = new OrwellWorld();
- //need at least 1 command line argument
- if ($argc >= 2) {
- $allowedOptions = array(
- '--preview' => 'preview ipfw update script to stdout',
- '--resolve' => 'render IPs list of loaded domains',
- '--generate' => 'generate ipfw update script on filesystem',
- '--tableupdate' => 'updates ipfw table with domains IPs',
- '--help' => 'show small help'
- );
- $option = $argv[1];
- if (isset($allowedOptions[$option])) {
- switch ($option) {
- case '--preview':
- print($tech->getIpfwScript());
- break;
- case '--resolve':
- print($tech->renderDomainsIps());
- break;
- case '--generate':
- $generationResult = $tech->saveIpfwScript();
- if (!empty($generationResult)) {
- print('ipfw update script file ' . $generationResult . ' saved' . PHP_EOL);
- } else {
- print('ipfw script generation skipped because IPFW_SCRIPT_PATH option empty' . PHP_EOL);
- }
- break;
- case '--tableupdate':
- print($tech->ipfwTableUpdate());
- break;
- case '--help':
- print('Usage: php cli/ipfwgen --option' . PHP_EOL);
- print('Available options:' . PHP_EOL);
- if (!empty($allowedOptions)) {
- foreach ($allowedOptions as $optionName => $optionDesc) {
- print($optionName . ' - ' . $optionDesc . PHP_EOL);
- }
- }
- break;
- }
- } else {
- print('Unknown command line option: ' . $option . PHP_EOL);
- }
- } else {
- //option requirement notification
- print('At least one option required.' . PHP_EOL);
- print('Usage: php cli/ipfwgen --option' . PHP_EOL);
- print('For example: php cli/ipfwgen --help' . PHP_EOL);
- }
|