Commit 17d42b3c authored by Olav Kvittem's avatar Olav Kvittem

mtr does not allow -i for noenroot - dropped. Use local json-file mp_list.json...

mtr does not allow -i for noenroot - dropped. Use local json-file mp_list.json for name compeltion. mp_list.sh should be in cron
parent 3a120ccf
......@@ -15,7 +15,7 @@
<script type="text/javascript" src="/js/jquery-ui-1.10.3/jquery-1.9.1.js"></script>
<script>
var mp_url="https://kind.uninett.no/autoregister/utstyr_mp.json";
var mp_url="mp_list.json";
function make_select( elm, url){
// var html='<button id=traceroute onclick="traceroute( $(\'#tr_host\').val(), $(\'#tr_times\').val(), $(\'#tr_size\').val(), $(\'#tr_interval\').val() )">Trace route</button> to ';
......
This diff is collapsed.
#! /usr/bin/perl
#
# run mtr and produce json document
# usage : traceroute.json?host=host_name_or_address&count=repetitions
# returns json-document with mtr output
# Olav Kvittem ( Olav.Kvittem@uninett.no )
#
# use CGI;
use CGI qw/:standard -debug/;
use JSON;
my $q = CGI->new;
print $q->header('application/json');
$feilmelding = "<h3><font color=red>%s</font></h3>\n";
if ( $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp" ){
my %msg;
$msg{error}="Access to iperf denied : unauthorized";
push(@mtr, %msg);
print STDERR "Error: ";
my %headers = map { $_ => $q->http($_) } $q->http();
print STDERR "Wrong secret : Got the following headers:\n";
for my $header ( keys %headers ) {
print STDERR "$header: $headers{$header}\n";
}
print encode_json \%msg;
} else {
# print STDERR 'host', $q->param('host'), $q->param('nobs'), $q->param('psize');
my $host = $q->param('host'); # && ( $host =~ m/^[a-zA-Z0-9\.\/\-_\:]+$/);
my $nobs = $q->param('nobs'); # && ( $nobs =~ m/^[0-9]+$/ );
my $psize = $q->param('psize'); # && ( psize =~ m/^[0-9]+$/ );
my $parallel = $q->param('parallel'); # && ( psize =~ m/^[0-9]+$/ );
my $port = $q->param('port'); # && ( psize =~ m/^[0-9]+$/ );
my $interval = $q->param('interval'); # && ( psize =~ m/^[0-9]+$/ );
my $direction = $q->param('direction');
$host =~ s/[^a-zA-Z0-9\.\/\-_\:]+/_/g; # protect
$nobs =~ s/[^0-9]+/_/g;
$psize =~ s/[^0-9]+/_/g;
$port =~ s/[^0-9]+/_/g;
$parallel =~ s/[^0-9]+/_/g;
$direction =~ s/[^a-zA-Z0-9\.\/\-_]+/_/g;
$host = $q->remote_host if $host eq "";
$nobs = 3 if $nobs < 1;
$psize = 64 if $psize < 1;
$parallel = 1 if $port < 1;
$port = 5001 if $port < 1;
$interval= 0.1 if $interval <= 0;
if ($direction eq "from"){
$dirparm="-R";
} else {
$dirparm="";
}
my $cmd= "/usr/local/bin/iperf3 -i $interval -t $nobs -c $host -P $parallel -p $port --json $dirparm";
# open MTR, $cmd || die "Could not open : $cmd : $!";
my $mtr = `$cmd`;
if ( $? != 0){
$mtr = '{ "error": "' . $! . ' : Error running iperf"}';
# print STDERR "Error: $cmd";
}
print $mtr;
}
exit(0);
var mp_url="https://kind.uninett.no/autoregister/utstyr_mp.json";
var mp_url='mp_list.json';
var mp_list=[];
function make_select( elm, url){
// var html='<button id=traceroute onclick="traceroute( $(\'#tr_host\').val(), $(\'#tr_times\').val(), $(\'#tr_size\').val(), $(\'#tr_interval\').val() )">Trace route</button> to ';
......
#!/bin/sh
# get list om measurement beacons
wget -q -O mp_list.new https://kind.uninett.no/autoregister/utstyr_mp.json
if test -s mp_list.new ; then
mv mp_list.new mp_list.json
fi
var mp_url="https://kind.uninett.no/autoregister/utstyr_mp.json";
var mp_url='../mp_list.json';
var x_name=[]; // the name of hops in tooltip
var graf_no=0;
......@@ -31,7 +31,7 @@ function traceroute(host, nobs, psize, interval){
if ( ! host) host="";
var html='<table cellpadding="0" cellspacing="0" border="0" class="display" id="tracetable">';
html+='<caption>Route report at ' + new Date().toLocaleTimeString() + '</caption><thead>';
// html+='<caption>Route report at ' + new Date().toLocaleTimeString() + '</caption><thead>';
var title=true;
$("#busy").show();
......@@ -44,7 +44,7 @@ function traceroute(host, nobs, psize, interval){
// var UWAP = require("/_/js/require.js");
var request = $.ajax( { url: url, dataType: 'json',
headers: { "X_TOKEN": "virre-virre-vapp" } } );
headers: { "X-TOKEN": "virre-virre-vapp" } } );
request.fail( function( jqXHR, status, error){
alert('Traceroute failed from '+ url + ' : ' + status + ', ' + error );
});
......@@ -55,12 +55,16 @@ function traceroute(host, nobs, psize, interval){
alert( mtr_rows[0] + ' : ' + mtr_rows[1] );
$("#busy").hide();
} else { // normally ok data
// row 0 is date and row 1 contains headers
$.each(mtr_rows, function(tr) {
if (tr == 1){ html+= '</thead><tbody>'};
if (tr == 0){ // header line
html+='<caption>Route report at ' + mtr_rows[tr][1] + '</caption><thead>';
} else {
if (tr == 2){ html+= '</thead><tbody>'};
html+='<tr>';
$.each(mtr_rows[tr], function(td) {
if (tr == 0){
if (tr == 1){
html+='<th align=left>' + mtr_rows[tr][td];
} else {
var a='';
......@@ -72,7 +76,7 @@ function traceroute(host, nobs, psize, interval){
}
// console.log(mtr_rows[tr]);
});
if ( tr > 0 ){
if ( tr > 1 ){
x_name.push( mtr_rows[tr][1] );
loss.push( parseFloat( mtr_rows[tr][2] ) );
avg.push( parseFloat( mtr_rows[tr][5] ) );
......@@ -80,6 +84,7 @@ function traceroute(host, nobs, psize, interval){
wrst.push( parseFloat( mtr_rows[tr][7] ) );
stdev.push( parseFloat( mtr_rows[tr][8] ) );
}
}
});
}
......@@ -94,7 +99,8 @@ function traceroute(host, nobs, psize, interval){
{ name: 'Best', data: best, type: 'scatter'},
{ name: 'Loss', data: loss, type: 'scatter', yAxis: 1},
];
tegn_graf('graf', 'Latency graph ', 'To ' + $('#tr_host').val() + ' at ' + new Date().toLocaleTimeString(), series, '', graf_no++,
tegn_graf('graf', 'Latency graph ', 'To ' + $('#tr_host').val() +
' at ' + new Date().toLocaleTimeString(), series, '', graf_no++,
$('#tracetablecontainer').width());
$('#traces').tabs( "enable", 0);
$('#traces').tabs( "enable", 1);
......@@ -120,14 +126,14 @@ function make_select( elm, url){
// html+= '<select name="tr_opt" id="tr_opt">';
// html+= '<option value="">My host</option>';
var html='<form name="traceroute_form" id="traceroute_form"';
html+= 'action="javascript:traceroute( $(\'#tr_host\').val(), $(\'#tr_times\').val(), $(\'#tr_size\').val(), $(\'#tr_interval\').val() )">';
html+= 'action="javascript:traceroute( $(\'#tr_host\').val(), $(\'#tr_times\').val(), $(\'#tr_size\').val(), 1 /* $(\'#tr_interval\').val()*/ )">';
html+='<table><tr><td>';
html+='<input type="submit" value="Trace route" class="btn btn-primary btn-lg" /> to ';
html+='<input id=tr_host value="" placeholder="my host" title="Automatisk utfylling av mleplenavn"></input>';
var html2=' <td> &nbsp;';
html2='<input id=tr_times value=3 style="width:3em;text-align:right"> times</input>';
html2+=', using <input id=tr_size value=64 style="width:3em;text-align:right"> bytes packets</input>';
html2+=', every <input id=tr_interval value=0.1 style="width:3em;text-align:right"> seconds.';
html2+=', using <input id=tr_size value=64 style="width:3em;text-align:right"> bytes packets.</input>';
//ok html2+=', every <input id=tr_interval value=0.1 style="width:3em;text-align:right"> seconds.';
html2+='</table>';
html2+='</form>';
......
......@@ -39,19 +39,26 @@ if ( $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp"){
$nobs = 3 if $nobs < 1;
$psize = 64 if $psize < 1;
$interval= 0.1 if $interval <= 0;
my $cmd= "/usr/bin/mtr -c $nobs -s $psize -i $interval --report --report-wide $host";
# my $cmd= "/usr/bin/mtr -c $nobs -s $psize -i $interval --report --report-wide $host";
# mtr does not like interval less than 1sek from nonroot and therefore purposeless
my $cmd= "/usr/bin/mtr -c $nobs -s $psize --report --report-wide $host";
# open MTR, $cmd || die "Could not open : $cmd : $!";
my $mtr = `$cmd`;
if ( $? != 0){
push(@mtr, "Error" , $! || "Might be unknown host");
print STDERR "Error: $cmd";
$error=$!;
push(@mtr, "Error" , $error || "Might be unknown host");
printf STDERR "Error: $cmd : $error \n";
} else { # ok
# print STDERR "Kode $? : $cmd";
#while(<MTR>){
foreach ( split(/\n/, $mtr) ){
if (/^(Start): (.*)/){ # header line
push( @mtr, [$1, $2]);
} else {
s/^\s+//; # leading blanks
@F = split( /\s+/ );
if ($F[0] = /(\d+)[^\d]+/){
......@@ -60,6 +67,7 @@ if ( $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp"){
push( @mtr, [@F] );
}
}
}
}
print STDERR "mtr result: ".@mtr;
print encode_json \@mtr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment