1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- include ('api.1984tech.php');
- $tech = new OrwellWorld();
- //need at least 1 command line argument
- if ($argc >= 2) {
- $allowedOptions = array(
- '--preview' => 'preview Mikrotik address list update script to stdout',
- '--resolve' => 'render IPs list of loaded domains',
- '--generate' => 'generate Mikrotik address list update script on filesystem',
- '--listmk' => 'preview mikrotik per domain address list to stdout',
- '--help' => 'show small help'
- );
- $option = $argv[1];
- if (isset($allowedOptions[$option])) {
- switch ($option) {
- case '--preview':
- print($tech->getMikrotikScript());
- break;
- case '--resolve':
- print($tech->renderDomainsIps());
- break;
- case '--generate':
- $generationResult = $tech->saveMikrotikScript();
- if (!empty($generationResult)) {
- print('Mikrotik update script file ' . $generationResult . ' saved' . PHP_EOL);
- } else {
- print('Mikrotik script generation skipped because MT_SCRIPT_PATH option empty' . PHP_EOL);
- }
- break;
- case '--listmk':
- print($tech->getMikrotikScriptDomains());
- break;
- case '--help':
- print('Usage: php cli/mtgen --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/mtgen --option' . PHP_EOL);
- print('For example: php cli/mtgen --help' . PHP_EOL);
- }
- ?>
|