. * * @package LibreNMS * @link http://librenms.org * @copyright 2016 Tony Murray * @author Tony Murray */ if (!is_admin()) { echo("Insufficient Privileges"); exit(); } $hostname = escapeshellcmd($_REQUEST['hostname']); $type = $_REQUEST['type']; switch ($type) { case 'poller': $cmd = "php ${config['install_dir']}/poller.php -h $hostname -r -f -d"; $filename = "poller-$hostname.txt"; break; case 'snmpwalk': $device = device_by_name(mres($hostname)); $cmd = gen_snmpwalk_cmd($device, '.', ' -OUneb'); if ($debug) { $cmd .= ' 2>&1'; } $filename = $device['os'] . '-' . $device['hostname'] . '.snmpwalk'; break; case 'discovery': $cmd = "php ${config['install_dir']}/discovery.php -h $hostname -d"; $filename = "discovery-$hostname.txt"; break; default: echo 'You must specify a valid type'; exit(); } // ---- Output ---- if ($_GET['format'] == 'text') { header("Content-type: text/plain"); header('X-Accel-Buffering: no'); if (($fp = popen($cmd, "r"))) { while (!feof($fp)) { $line = stream_get_line($fp, 1024, PHP_EOL); echo preg_replace('/\033\[[\d;]+m/', '', $line) . PHP_EOL; ob_flush(); flush(); // you have to flush buffer } fclose($fp); } } elseif ($_GET['format'] == 'download') { ob_start(); $output = shell_exec($cmd); ob_end_clean(); $output = preg_replace('/\033\[[\d;]+m/', '', $output); file_download($filename, $output); }