#!/usr/bin/env php . */ /** * libreNMS CLI utility to purge old ports. * * @author Maximilian Wilhelm * @copyright 2016-2017 LibreNMS, Barbarossa * @license GPL * @package LibreNMS * @subpackage ? * */ chdir(dirname($argv[0])); $init_modules = array(); require realpath(__DIR__ . '/..') . '/includes/init.php'; $opt = getopt('p:f:'); // Single Port-id given on cmdline? $port_id = null; if ($opt['p']) { $port_id = $opt['p']; } // File with port-ids given on cmdline? $port_id_file = null; if ($opt['f']) { $port_id_file = $opt['f']; } if (! $port_id && ! $port_id_file || ($port_id && $port_id_file)) { print $console_color->convert($config['project_name_version'].' Port purge tool -p Purge single port by it\'s port-id -f Purge a list of ports, read port-ids from , one on each line. A filename of - means reading from STDIN. '); } // Purge single port if ($port_id) { delete_port($port_id); } // Delete multiple ports if ($port_id_file) { $fh = null; if ($port_id_file == '-') { $fh = STDIN; } else { $fh = fopen($port_id_file, "r"); if (! $fh) { echo "Failed to open port-id list \"" . $port_id_file . "\": \n"; exit(1); } } while ($port_id = trim(fgets($fh))) { delete_port($port_id); } if ($fh != STDIN) { fclose($fh); } }