Files
librenms-librenms/html/netcmd.php

61 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2015-07-13 20:10:26 +02:00
/*
2016-08-20 12:16:55 +01:00
* LibreNMS
*
2016-08-20 12:16:55 +01:00
* This file is part of LibreNMS.
*
2016-08-20 12:16:55 +01:00
* @package librenms
2013-10-29 05:38:12 +10:00
* @subpackage webinterface
* @copyright (C) 2006 - 2012 Adam Armstrong
*/
use LibreNMS\Authentication\Auth;
ini_set('allow_url_fopen', 0);
$init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
set_debug($_GET['debug']);
if (!Auth::check()) {
2015-07-13 20:10:26 +02:00
echo 'unauthenticated';
exit;
}
2014-02-23 15:08:06 +10:00
$output = '';
2015-07-13 20:10:26 +02:00
if ($_GET['query'] && $_GET['cmd']) {
$host = clean($_GET['query']);
if (filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) || filter_var('http://'.$host, FILTER_VALIDATE_URL)) {
2015-07-13 20:10:26 +02:00
switch ($_GET['cmd']) {
case 'whois':
$cmd = $config['whois']." $host | grep -v \%";
break;
case 'ping':
$cmd = $config['ping']." -c 5 $host";
break;
case 'tracert':
$cmd = $config['mtr']." -r -c 5 $host";
break;
case 'nmap':
if (!Auth::user()->isAdmin()) {
echo 'insufficient privileges';
} else {
$cmd = $config['nmap']." $host";
}
break;
2015-07-13 20:10:26 +02:00
}//end switch
if (!empty($cmd)) {
$output = `$cmd`;
}
}//end if
}//end if
2016-06-02 06:56:45 +00:00
$output = htmlentities(trim($output), ENT_QUOTES);
2015-07-13 20:10:26 +02:00
echo "<pre>$output</pre>";