Commit 6ae47831 authored by Olav Kvittem's avatar Olav Kvittem

iperf added

parent 5bdffdfa
iperf-x.html
\ No newline at end of file
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"){
push(@mtr, "Error" , "Access to traceroute denied : unauthorized");
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";
}
} 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 $interval = $q->param('interval'); # && ( psize =~ m/^[0-9]+$/ );
$host =~ s/[^a-zA-Z0-9\.\/\-_]+/_/g; # protect
$nobs =~ s/[^0-9]+/_/g;
$psize =~ s/[^0-9]+/_/g;
$host = $q->remote_host if $host eq "";
$nobs = 3 if $nobs < 1;
$psize = 64 if $psize < 1;
$interval= 0.1 if $interval <= 0;
my $cmd= "/usr/bin/iperf -i $interval -t $nobs -c $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";
} else { # ok
# print STDERR "Kode $? : $cmd";
#while(<MTR>){
foreach ( split(/\n/, $mtr) ){
s/^\s+//; # leading blanks
s/\[\s+/[/; s/-\s+/-/;
@F = split( /\s+/ );
push( @mtr, [@F] );
}
}
}
print encode_json \@mtr;
exit(0);
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