mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
Rewrite netcmd and ripe whois tools (#9724)
* Port RIPE whois to Laravel * remove netcmd.php and port to laravel. Escape CLI and set it to stream output live. * fix browser buffer bust on a few browsers.
This commit is contained in:
parent
003f3bdce0
commit
ce6fae8dd1
42
LibreNMS/Exceptions/ApiException.php
Normal file
42
LibreNMS/Exceptions/ApiException.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* ApiException.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Exceptions;
|
||||
|
||||
class ApiException extends \Exception
|
||||
{
|
||||
private $output;
|
||||
|
||||
public function __construct($message = "", $output = [])
|
||||
{
|
||||
parent::__construct($message, 0, null);
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
}
|
54
LibreNMS/Util/Validate.php
Normal file
54
LibreNMS/Util/Validate.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Validate.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
class Validate
|
||||
{
|
||||
/**
|
||||
* Checks if the give string is a valid hostname
|
||||
* @param string $hostname
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hostname($hostname)
|
||||
{
|
||||
// The Internet standards (Request for Comments) for protocols mandate that
|
||||
// component hostname labels may contain only the ASCII letters 'a' through 'z'
|
||||
// (in a case-insensitive manner), the digits '0' through '9', and the hyphen
|
||||
// ('-'). The original specification of hostnames in RFC 952, mandated that
|
||||
// labels could not start with a digit or with a hyphen, and must not end with
|
||||
// a hyphen. However, a subsequent specification (RFC 1123) permitted hostname
|
||||
// labels to start with digits. No other symbols, punctuation characters, or
|
||||
// white space are permitted. While a hostname may not contain other characters,
|
||||
// such as the underscore character (_), other DNS names may contain the underscore
|
||||
// maximum length is 253 characters, maximum segment size is 63
|
||||
|
||||
return (
|
||||
preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*\.?$/i", $hostname) //valid chars check
|
||||
&& preg_match("/^.{1,253}$/", $hostname) //overall length check
|
||||
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*\.?$/", $hostname)
|
||||
);
|
||||
}
|
||||
}
|
97
app/ApiClients/RipeApi.php
Normal file
97
app/ApiClients/RipeApi.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* RipeWhoisApi.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\ApiClients;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use LibreNMS\Exceptions\ApiException;
|
||||
|
||||
class RipeApi extends BaseApi
|
||||
{
|
||||
protected $base_uri = 'https://stat.ripe.net';
|
||||
|
||||
protected $whois_uri = '/data/whois/data.json';
|
||||
protected $abuse_uri = '/data/abuse-contact-finder/data.json';
|
||||
|
||||
/**
|
||||
* Get whois info
|
||||
*
|
||||
* @param string $resource ASN/IPv4/IPv6
|
||||
* @return array
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function getWhois($resource)
|
||||
{
|
||||
return $this->makeApiCall($this->whois_uri, [
|
||||
'query' => [
|
||||
'resource' => $resource
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Abuse contact
|
||||
*
|
||||
* @param string $resource prefix, single IP address or ASN
|
||||
* @return array|mixed
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function getAbuseContact($resource)
|
||||
{
|
||||
return $this->makeApiCall($this->abuse_uri, [
|
||||
'query' => [
|
||||
'resource' => $resource
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uri
|
||||
* @param $options
|
||||
* @return array|mixed
|
||||
* @throws ApiException
|
||||
*/
|
||||
private function makeApiCall($uri, $options)
|
||||
{
|
||||
try {
|
||||
$response = $this->getClient()->get($uri, $options);
|
||||
$response_data = json_decode($response->getBody(), true);
|
||||
if (isset($response_data['status']) && $response_data['status'] == 'ok') {
|
||||
return $response_data;
|
||||
} else {
|
||||
dd($response->getBody());
|
||||
throw new ApiException("RIPE API call failed", $response_data);
|
||||
}
|
||||
} catch (RequestException $e) {
|
||||
$message = 'RIPE API call to ' . $e->getRequest()->getUri() . ' failed: ';
|
||||
$message .= $e->getResponse()->getReasonPhrase() . ' ' . $e->getResponse()->getStatusCode();
|
||||
|
||||
throw new ApiException(
|
||||
$message,
|
||||
json_decode($e->getResponse()->getBody(), true)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
95
app/Http/Controllers/Ajax/NetCommand.php
Normal file
95
app/Http/Controllers/Ajax/NetCommand.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* NetCommand.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Ajax;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Config;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class NetCommand extends Controller
|
||||
{
|
||||
public function run(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'cmd' => 'in:whois,ping,tracert,nmap',
|
||||
'query' => 'ip_or_hostname',
|
||||
]);
|
||||
|
||||
ini_set('allow_url_fopen', 0);
|
||||
|
||||
switch ($request->get('cmd')) {
|
||||
case 'whois':
|
||||
$cmd = [Config::get('whois', 'whois'), $request->get('query')];
|
||||
break;
|
||||
case 'ping':
|
||||
$cmd = [Config::get('ping', 'ping'), '-c', '5', $request->get('query')];
|
||||
break;
|
||||
case 'tracert':
|
||||
$cmd = [Config::get('mtr', 'mtr'), '-r', '-c', '5', $request->get('query')];
|
||||
break;
|
||||
case 'nmap':
|
||||
if (!$request->user()->isAdmin()) {
|
||||
return response('Insufficient privileges');
|
||||
} else {
|
||||
$cmd = [Config::get('nmap', 'nmap'), $request->get('query')];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return response('Invalid command');
|
||||
}
|
||||
|
||||
$proc = new Process($cmd);
|
||||
$proc->setTimeout(240);
|
||||
|
||||
//stream output
|
||||
return (new StreamedResponse(
|
||||
function () use ($proc, $request) {
|
||||
// a bit dirty, bust browser initial cache
|
||||
$ua = $request->header('User-Agent');
|
||||
if (str_contains($ua, ['Chrome', 'Trident'])) {
|
||||
$char = "\f"; // line feed
|
||||
} else {
|
||||
$char = "";
|
||||
}
|
||||
echo str_repeat($char, 4096);
|
||||
echo PHP_EOL; // avoid first line mess ups due to line feed
|
||||
|
||||
$proc->run(function ($type, $buffer) {
|
||||
echo $buffer;
|
||||
ob_flush();
|
||||
flush();
|
||||
});
|
||||
},
|
||||
200,
|
||||
[
|
||||
'Content-Type' => 'text/plain; charset=utf-8',
|
||||
'X-Accel-Buffering' => 'no',
|
||||
]
|
||||
))->send();
|
||||
}
|
||||
}
|
54
app/Http/Controllers/Ajax/ResolutionController.php
Normal file
54
app/Http/Controllers/Ajax/ResolutionController.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* ResolutionController.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Ajax;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ResolutionController extends Controller
|
||||
{
|
||||
public function set(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'width' => 'required|numeric',
|
||||
'height' => 'required|numeric'
|
||||
]);
|
||||
|
||||
// legacy session
|
||||
session_start();
|
||||
$_SESSION['screen_width'] = $request->width;
|
||||
$_SESSION['screen_height'] = $request->height;
|
||||
session_write_close();
|
||||
|
||||
// laravel session
|
||||
session([
|
||||
'screen_width' => $request->width,
|
||||
'screen_height' => $request->height
|
||||
]);
|
||||
|
||||
return $request->width . 'x' . $request->height;
|
||||
}
|
||||
}
|
71
app/Http/Controllers/Ajax/RipeNccApiController.php
Normal file
71
app/Http/Controllers/Ajax/RipeNccApiController.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* RipeNccApiController.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Ajax;
|
||||
|
||||
use App\ApiClients\RipeApi;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use LibreNMS\Exceptions\ApiException;
|
||||
|
||||
class RipeNccApiController extends Controller
|
||||
{
|
||||
public function raw(Request $request, RipeApi $api)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'data_param' => 'required|in:whois,abuse-contact-finder',
|
||||
'query_param' => 'required|ip_or_hostname',
|
||||
]);
|
||||
|
||||
$is_whois = $request->get('data_param') == 'whois';
|
||||
|
||||
try {
|
||||
$resource = $request->get('query_param');
|
||||
$output = $is_whois ? $api->getWhois($resource) : $api->getAbuseContact($resource);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'ok',
|
||||
'message' => 'Queried',
|
||||
'output' => $output,
|
||||
]);
|
||||
} catch (ApiException $e) {
|
||||
$response = $e->getOutput();
|
||||
$message = $e->getMessage();
|
||||
|
||||
if (isset($response['messages'])) {
|
||||
$message .= ': ' . collect($response['messages'])
|
||||
->flatten()
|
||||
->reject('error')
|
||||
->implode(', ');
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => $message,
|
||||
'output' => $response,
|
||||
], 503);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ResolutionController extends Controller
|
||||
{
|
||||
public function set(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'width' => 'required|numeric',
|
||||
'height' => 'required|numeric'
|
||||
]);
|
||||
|
||||
// legacy session
|
||||
session_start();
|
||||
$_SESSION['screen_width'] = $request->width;
|
||||
$_SESSION['screen_height'] = $request->height;
|
||||
session_write_close();
|
||||
|
||||
// laravel session
|
||||
session([
|
||||
'screen_width' => $request->width,
|
||||
'screen_height' => $request->height
|
||||
]);
|
||||
|
||||
return $request->width . 'x' . $request->height;
|
||||
}
|
||||
}
|
@ -6,9 +6,13 @@ use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Validation\Rule;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Exceptions\DatabaseConnectException;
|
||||
use LibreNMS\Util\IP;
|
||||
use LibreNMS\Util\Validate;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
include_once __DIR__ . '/../../includes/dbFacile.php';
|
||||
|
||||
@ -48,6 +52,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
return "<?php endif; ?>";
|
||||
});
|
||||
|
||||
$this->bootCustomValidators();
|
||||
$this->configureMorphAliases();
|
||||
|
||||
// Development service providers
|
||||
@ -108,4 +113,12 @@ class AppServiceProvider extends ServiceProvider
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function bootCustomValidators()
|
||||
{
|
||||
Validator::extend('ip_or_hostname', function ($attribute, $value, $parameters, $validator) {
|
||||
$ip = substr($value, 0, strpos($value, '/') ?: strlen($value)); // allow prefixes too
|
||||
return IP::isValid($ip) || Validate::hostname($value);
|
||||
}, __('The :attribute must a valid IP address/network or hostname.'));
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2015 Søren Friis Rosiak <sorenrosiak@gmail.com>
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
header('Content-type: application/json');
|
||||
|
||||
$status = 'error';
|
||||
$message = 'unknown error';
|
||||
$data_param = mres($_POST['data_param']);
|
||||
$query_param = mres($_POST['query_param']);
|
||||
if (isset($data_param) && isset($query_param)) {
|
||||
$status = 'ok';
|
||||
$message = 'Queried';
|
||||
$output = get_ripe_api_whois_data_json($data_param, $query_param);
|
||||
} else {
|
||||
$status = 'error';
|
||||
$message = 'ERROR: Could not query';
|
||||
}
|
||||
die(display(json_encode(array(
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'data_param' => $data_param,
|
||||
'query_param' => $query_param,
|
||||
'output' => $output,
|
||||
))));
|
@ -1224,12 +1224,6 @@ function generate_dynamic_config_panel($title, $config_groups, $items = array(),
|
||||
return $output;
|
||||
}//end generate_dynamic_config_panel()
|
||||
|
||||
function get_ripe_api_whois_data_json($ripe_data_param, $ripe_query_param)
|
||||
{
|
||||
$ripe_whois_url = 'https://stat.ripe.net/data/' . $ripe_data_param . '/data.json?resource=' . $ripe_query_param;
|
||||
return json_decode(file_get_contents($ripe_whois_url), true);
|
||||
}//end get_ripe_api_whois_data_json()
|
||||
|
||||
/**
|
||||
* Return the rows from 'ports' for all ports of a certain type as parsed by port_descr_parser.
|
||||
* One or an array of strings can be provided as an argument; if an array is passed, all ports matching
|
||||
|
@ -36,13 +36,13 @@ if ($port['ifAlias']) {
|
||||
unset($break);
|
||||
if ($port_details) {
|
||||
foreach (dbFetchRows('SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?', array($port['port_id'])) as $ip) {
|
||||
echo "$break <a class=interface-desc href=\"javascript:popUp('netcmd.php?cmd=whois&query=".$ip['ipv4_address']."')\">".$ip['ipv4_address'].'/'.$ip['ipv4_prefixlen'].'</a>';
|
||||
echo "$break <a class=interface-desc href=\"javascript:popUp('ajax/netcmd?cmd=whois&query=".$ip['ipv4_address']."')\">".$ip['ipv4_address'].'/'.$ip['ipv4_prefixlen'].'</a>';
|
||||
$break = ',';
|
||||
}
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?', array($port['port_id'])) as $ip6) {
|
||||
;
|
||||
echo "$break <a class=interface-desc href=\"javascript:popUp('netcmd.php?cmd=whois&query=".$ip6['ipv6_address']."')\">".IP::parse($ip6['ipv6_address'], true).'/'.$ip6['ipv6_prefixlen'].'</a>';
|
||||
echo "$break <a class=interface-desc href=\"javascript:popUp('ajax/netcmd?cmd=whois&query=".$ip6['ipv6_address']."')\">".IP::parse($ip6['ipv6_address'], true).'/'.$ip6['ipv6_prefixlen'].'</a>';
|
||||
$break = ',';
|
||||
}
|
||||
}
|
||||
|
@ -60,12 +60,12 @@ unset($break);
|
||||
|
||||
if ($port_details) {
|
||||
foreach (dbFetchRows('SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?', array($port['port_id'])) as $ip) {
|
||||
echo "$break <a class=interface-desc href=\"javascript:popUp('netcmd.php?cmd=whois&query=$ip[ipv4_address]')\">".$ip['ipv4_address'].'/'.$ip['ipv4_prefixlen'].'</a>';
|
||||
echo "$break <a class=interface-desc href=\"javascript:popUp('ajax/netcmd?cmd=whois&query=$ip[ipv4_address]')\">".$ip['ipv4_address'].'/'.$ip['ipv4_prefixlen'].'</a>';
|
||||
$break = '<br />';
|
||||
}
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?', array($port['port_id'])) as $ip6) {
|
||||
echo "$break <a class=interface-desc href=\"javascript:popUp('netcmd.php?cmd=whois&query=".$ip6['ipv6_address']."')\">".IP::parse($ip6['ipv6_address'], true).'/'.$ip6['ipv6_prefixlen'].'</a>';
|
||||
echo "$break <a class=interface-desc href=\"javascript:popUp('ajax/netcmd?cmd=whois&query=".$ip6['ipv6_address']."')\">".IP::parse($ip6['ipv6_address'], true).'/'.$ip6['ipv6_prefixlen'].'</a>';
|
||||
$break = '<br />';
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* This file is part of LibreNMS.
|
||||
*
|
||||
* @package librenms
|
||||
* @subpackage webinterface
|
||||
* @copyright (C) 2006 - 2012 Adam Armstrong
|
||||
*/
|
||||
|
||||
use LibreNMS\Authentication\LegacyAuth;
|
||||
|
||||
ini_set('allow_url_fopen', 0);
|
||||
|
||||
$init_modules = array('web', 'auth');
|
||||
require realpath(__DIR__ . '/..') . '/includes/init.php';
|
||||
|
||||
set_debug($_GET['debug']);
|
||||
|
||||
if (!LegacyAuth::check()) {
|
||||
echo 'unauthenticated';
|
||||
exit;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
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)) {
|
||||
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 (!LegacyAuth::user()->isAdmin()) {
|
||||
echo 'insufficient privileges';
|
||||
} else {
|
||||
$cmd = $config['nmap']." $host";
|
||||
}
|
||||
break;
|
||||
}//end switch
|
||||
|
||||
if (!empty($cmd)) {
|
||||
$output = `$cmd`;
|
||||
}
|
||||
}//end if
|
||||
}//end if
|
||||
|
||||
$output = htmlentities(trim($output), ENT_QUOTES);
|
||||
echo "<pre>$output</pre>";
|
@ -10,6 +10,8 @@
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
$pagetitle[] = 'RIPE NCC - API Tools';
|
||||
$no_refresh = true;
|
||||
|
||||
?>
|
||||
<h3> RIPE NCC API Tools </h3>
|
||||
<hr>
|
||||
@ -29,26 +31,28 @@ $pagetitle[] = 'RIPE NCC - API Tools';
|
||||
</div>
|
||||
</form>
|
||||
<br />
|
||||
<div id="ripe-output" class="alert alert-success" style="display: none;"></div>
|
||||
<div class="alert alert-success" style="display: none;">
|
||||
<pre id="ripe-output"></pre>
|
||||
</div>
|
||||
<br />
|
||||
<script>
|
||||
$("[name='btn-query']").on('click', function(event) {
|
||||
event.preventDefault();
|
||||
var $this = $(this);
|
||||
var data_param = $('input[name=data_radio]:checked').val();
|
||||
var query_param = $("#input-parameter").val();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax_form.php',
|
||||
url: 'ajax/ripe/raw',
|
||||
data: {
|
||||
type: "query-ripenccapi",
|
||||
data_param: data_param,
|
||||
query_param: query_param
|
||||
},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
$('#ripe-output').empty();
|
||||
$("#ripe-output").show();
|
||||
var output = $('#ripe-output');
|
||||
output.empty();
|
||||
output.parent().show();
|
||||
|
||||
if (data.output.data.records)
|
||||
$.each(data.output.data.records[0], function(row, value) {
|
||||
$('#ripe-output').append(value['key'] + ' = ' + value['value'] + '<br />');
|
||||
@ -58,8 +62,18 @@ $pagetitle[] = 'RIPE NCC - API Tools';
|
||||
$('#ripe-output').append(value['description'] + ' = ' + value['email'] + '<br />');
|
||||
});
|
||||
},
|
||||
error: function() {
|
||||
toastr.error('Error');
|
||||
error: function(data) {
|
||||
if (data.status === 422) {
|
||||
var json = data.responseJSON;
|
||||
var errors = [];
|
||||
for (var attrib in json) {
|
||||
errors.push(json[attrib]);
|
||||
}
|
||||
|
||||
toastr.error('Error: ' + errors.join("<br />"));
|
||||
} else {
|
||||
toastr.error(data.responseJSON.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -651,22 +651,7 @@ function format_number($value, $base = '1000', $round = 2, $sf = 3)
|
||||
|
||||
function is_valid_hostname($hostname)
|
||||
{
|
||||
// The Internet standards (Request for Comments) for protocols mandate that
|
||||
// component hostname labels may contain only the ASCII letters 'a' through 'z'
|
||||
// (in a case-insensitive manner), the digits '0' through '9', and the hyphen
|
||||
// ('-'). The original specification of hostnames in RFC 952, mandated that
|
||||
// labels could not start with a digit or with a hyphen, and must not end with
|
||||
// a hyphen. However, a subsequent specification (RFC 1123) permitted hostname
|
||||
// labels to start with digits. No other symbols, punctuation characters, or
|
||||
// white space are permitted. While a hostname may not contain other characters,
|
||||
// such as the underscore character (_), other DNS names may contain the underscore
|
||||
// maximum length is 253 characters, maximum segment size is 63
|
||||
|
||||
return (
|
||||
preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*\.?$/i", $hostname) //valid chars check
|
||||
&& preg_match("/^.{1,253}$/", $hostname) //overall length check
|
||||
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*\.?$/", $hostname)
|
||||
);
|
||||
return \LibreNMS\Util\Validate::hostname($hostname);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -17,8 +17,8 @@ access_points:
|
||||
- { Field: interference, Type: 'tinyint(3) unsigned', 'Null': false, Extra: '' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [accesspoint_id], Unique: true, Type: BTREE }
|
||||
name: { Name: name, Columns: [name, radio_number], Unique: false, Type: BTREE }
|
||||
deleted: { Name: deleted, Columns: [deleted], Unique: false, Type: BTREE }
|
||||
name: { Name: name, Columns: [name, radio_number], Unique: false, Type: BTREE }
|
||||
alerts:
|
||||
Columns:
|
||||
- { Field: id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
|
||||
@ -33,8 +33,8 @@ alerts:
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
|
||||
unique_alert: { Name: unique_alert, Columns: [device_id, rule_id], Unique: true, Type: BTREE }
|
||||
device_id: { Name: device_id, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
rule_id: { Name: rule_id, Columns: [rule_id], Unique: false, Type: BTREE }
|
||||
device_id: { Name: device_id, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
alert_device_map:
|
||||
Columns:
|
||||
- { Field: id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
|
||||
@ -86,8 +86,8 @@ alert_schedulables:
|
||||
- { Field: alert_schedulable_type, Type: varchar(255), 'Null': false, Extra: '' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [item_id], Unique: true, Type: BTREE }
|
||||
schedulable_morph_index: { Name: schedulable_morph_index, Columns: [alert_schedulable_type, alert_schedulable_id], Unique: false, Type: BTREE }
|
||||
schedule_id: { Name: schedule_id, Columns: [schedule_id], Unique: false, Type: BTREE }
|
||||
schedulable_morph_index: { Name: schedulable_morph_index, Columns: [alert_schedulable_type, alert_schedulable_id], Unique: false, Type: BTREE }
|
||||
alert_schedule:
|
||||
Columns:
|
||||
- { Field: schedule_id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
|
||||
@ -484,10 +484,10 @@ devices:
|
||||
- { Field: max_depth, Type: int(11), 'Null': false, Extra: '', Default: '0' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [device_id], Unique: true, Type: BTREE }
|
||||
status: { Name: status, Columns: [status], Unique: false, Type: BTREE }
|
||||
hostname: { Name: hostname, Columns: [hostname], Unique: false, Type: BTREE }
|
||||
sysName: { Name: sysName, Columns: [sysName], Unique: false, Type: BTREE }
|
||||
os: { Name: os, Columns: [os], Unique: false, Type: BTREE }
|
||||
status: { Name: status, Columns: [status], Unique: false, Type: BTREE }
|
||||
last_polled: { Name: last_polled, Columns: [last_polled], Unique: false, Type: BTREE }
|
||||
last_poll_attempted: { Name: last_poll_attempted, Columns: [last_poll_attempted], Unique: false, Type: BTREE }
|
||||
devices_attribs:
|
||||
@ -639,8 +639,8 @@ eventlog:
|
||||
- { Field: severity, Type: tinyint(4), 'Null': false, Extra: '', Default: '2' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [event_id], Unique: true, Type: BTREE }
|
||||
device_id: { Name: device_id, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
datetime: { Name: datetime, Columns: [datetime], Unique: false, Type: BTREE }
|
||||
device_id: { Name: device_id, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
graph_types:
|
||||
Columns:
|
||||
- { Field: graph_type, Type: varchar(32), 'Null': false, Extra: '' }
|
||||
@ -750,9 +750,9 @@ links:
|
||||
- { Field: remote_version, Type: varchar(256), 'Null': false, Extra: '' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
|
||||
local_device_id: { Name: local_device_id, Columns: [local_device_id, remote_device_id], Unique: false, Type: BTREE }
|
||||
src_if: { Name: src_if, Columns: [local_port_id], Unique: false, Type: BTREE }
|
||||
dst_if: { Name: dst_if, Columns: [remote_port_id], Unique: false, Type: BTREE }
|
||||
local_device_id: { Name: local_device_id, Columns: [local_device_id, remote_device_id], Unique: false, Type: BTREE }
|
||||
loadbalancer_rservers:
|
||||
Columns:
|
||||
- { Field: rserver_id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
|
||||
@ -1243,10 +1243,10 @@ ports_fdb:
|
||||
- { Field: device_id, Type: 'int(10) unsigned', 'Null': false, Extra: '' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [ports_fdb_id], Unique: true, Type: BTREE }
|
||||
ports_fdb_port_id_index: { Name: ports_fdb_port_id_index, Columns: [port_id], Unique: false, Type: BTREE }
|
||||
mac_address: { Name: mac_address, Columns: [mac_address], Unique: false, Type: BTREE }
|
||||
ports_fdb_vlan_id_index: { Name: ports_fdb_vlan_id_index, Columns: [vlan_id], Unique: false, Type: BTREE }
|
||||
ports_fdb_port_id_index: { Name: ports_fdb_port_id_index, Columns: [port_id], Unique: false, Type: BTREE }
|
||||
ports_fdb_device_id_index: { Name: ports_fdb_device_id_index, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
ports_fdb_vlan_id_index: { Name: ports_fdb_vlan_id_index, Columns: [vlan_id], Unique: false, Type: BTREE }
|
||||
ports_nac:
|
||||
Columns:
|
||||
- { Field: ports_nac_id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
|
||||
@ -1268,8 +1268,8 @@ ports_nac:
|
||||
- { Field: time_elapsed, Type: varchar(50), 'Null': true, Extra: '' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [ports_nac_id], Unique: true, Type: BTREE }
|
||||
ports_nac_port_id_mac_address_index: { Name: ports_nac_port_id_mac_address_index, Columns: [port_id, mac_address], Unique: false, Type: BTREE }
|
||||
ports_nac_device_id_index: { Name: ports_nac_device_id_index, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
ports_nac_port_id_mac_address_index: { Name: ports_nac_port_id_mac_address_index, Columns: [port_id, mac_address], Unique: false, Type: BTREE }
|
||||
ports_perms:
|
||||
Columns:
|
||||
- { Field: user_id, Type: 'int(10) unsigned', 'Null': false, Extra: '' }
|
||||
@ -1459,8 +1459,8 @@ sensors:
|
||||
- { Field: user_func, Type: varchar(100), 'Null': true, Extra: '' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [sensor_id], Unique: true, Type: BTREE }
|
||||
sensor_class: { Name: sensor_class, Columns: [sensor_class], Unique: false, Type: BTREE }
|
||||
sensor_host: { Name: sensor_host, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
sensor_class: { Name: sensor_class, Columns: [sensor_class], Unique: false, Type: BTREE }
|
||||
sensor_type: { Name: sensor_type, Columns: [sensor_type], Unique: false, Type: BTREE }
|
||||
Constraints:
|
||||
sensors_device_id_foreign: { name: sensors_device_id_foreign, foreign_key: device_id, table: devices, key: device_id, extra: 'ON DELETE CASCADE' }
|
||||
@ -1593,11 +1593,11 @@ syslog:
|
||||
- { Field: seq, Type: 'bigint(20) unsigned', 'Null': false, Extra: auto_increment }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [seq], Unique: true, Type: BTREE }
|
||||
datetime: { Name: datetime, Columns: [timestamp], Unique: false, Type: BTREE }
|
||||
device_id: { Name: device_id, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
program: { Name: program, Columns: [program], Unique: false, Type: BTREE }
|
||||
priority_level: { Name: priority_level, Columns: [priority, level], Unique: false, Type: BTREE }
|
||||
device_id-timestamp: { Name: device_id-timestamp, Columns: [device_id, timestamp], Unique: false, Type: BTREE }
|
||||
device_id: { Name: device_id, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
datetime: { Name: datetime, Columns: [timestamp], Unique: false, Type: BTREE }
|
||||
program: { Name: program, Columns: [program], Unique: false, Type: BTREE }
|
||||
tnmsneinfo:
|
||||
Columns:
|
||||
- { Field: id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
|
||||
@ -1729,10 +1729,10 @@ vrf_lite_cisco:
|
||||
- { Field: vrf_name, Type: varchar(128), 'Null': true, Extra: '', Default: Default }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [vrf_lite_cisco_id], Unique: true, Type: BTREE }
|
||||
mix: { Name: mix, Columns: [device_id, context_name, vrf_name], Unique: false, Type: BTREE }
|
||||
device: { Name: device, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
context: { Name: context, Columns: [context_name], Unique: false, Type: BTREE }
|
||||
vrf: { Name: vrf, Columns: [vrf_name], Unique: false, Type: BTREE }
|
||||
context: { Name: context, Columns: [context_name], Unique: false, Type: BTREE }
|
||||
device: { Name: device, Columns: [device_id], Unique: false, Type: BTREE }
|
||||
mix: { Name: mix, Columns: [device_id, context_name, vrf_name], Unique: false, Type: BTREE }
|
||||
widgets:
|
||||
Columns:
|
||||
- { Field: widget_id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
|
||||
|
@ -21,6 +21,7 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () {
|
||||
return view('laravel');
|
||||
});
|
||||
|
||||
// pages
|
||||
Route::get('locations', 'LocationController@index');
|
||||
|
||||
// old route redirects
|
||||
@ -37,13 +38,22 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () {
|
||||
|
||||
// Ajax routes
|
||||
Route::group(['prefix' => 'ajax'], function () {
|
||||
Route::post('set_resolution', 'ResolutionController@set');
|
||||
// page ajax controllers
|
||||
Route::resource('location', 'LocationController', ['only' => ['update', 'destroy']]);
|
||||
|
||||
// misc ajax controllers
|
||||
Route::group(['namespace' => 'Ajax'], function () {
|
||||
Route::post('set_resolution', 'ResolutionController@set');
|
||||
Route::get('netcmd', 'NetCommand@run');
|
||||
Route::post('ripe/raw', 'RipeNccApiController@raw');
|
||||
});
|
||||
|
||||
// form ajax handlers, perhaps should just be page controllers
|
||||
Route::group(['prefix' => 'form', 'namespace' => 'Form'], function () {
|
||||
Route::resource('widget-settings', 'WidgetSettingsController');
|
||||
});
|
||||
|
||||
// js select2 data controllers
|
||||
Route::group(['prefix' => 'select', 'namespace' => 'Select'], function () {
|
||||
Route::get('application', 'ApplicationController');
|
||||
Route::get('bill', 'BillController');
|
||||
@ -59,6 +69,7 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () {
|
||||
Route::get('port-field', 'PortFieldController');
|
||||
});
|
||||
|
||||
// jquery bootgrid data controllers
|
||||
Route::group(['prefix' => 'table', 'namespace' => 'Table'], function () {
|
||||
Route::post('customers', 'CustomersController');
|
||||
Route::post('eventlog', 'EventlogController');
|
||||
@ -69,6 +80,7 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () {
|
||||
Route::post('syslog', 'SyslogController');
|
||||
});
|
||||
|
||||
// dashboard widgets
|
||||
Route::group(['prefix' => 'dash', 'namespace' => 'Widgets'], function () {
|
||||
Route::post('alerts', 'AlertsController');
|
||||
Route::post('availability-map', 'AvailabilityMapController');
|
||||
|
Loading…
Reference in New Issue
Block a user