From: ivan Date: Mon, 14 Sep 2009 23:52:01 +0000 (+0000) Subject: ping tool, RT#5845 X-Git-Tag: root_of_svc_elec_features~865 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=9ecb64360568b205334ae23e1051249cb56491b6 ping tool, RT#5845 --- diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index f71db208e..1918d9d36 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -52,6 +52,7 @@ Initializes the Mason environment, loads all Freeside and RT libraries, etc. use Date::Format; use Date::Parse; use Time::Local; + use Time::HiRes; use Time::Duration; use DateTime; use DateTime::Format::Strptime; @@ -77,6 +78,17 @@ Initializes the Mason environment, loads all Freeside and RT libraries, etc. use Spreadsheet::WriteExcel; use Business::CreditCard 0.30; #for mask-aware cardtype() use NetAddr::IP; + use Net::Ping; + use Net::Ping::External; + #if CPAN #7815 ever gets fixed# if ( $Net::Ping::External::VERSION <= 0.12 ) { + eval 'sub Net::Ping::External::_ping_linux { + my %args = @_; + my $command = "ping -s $args{size} -c $args{count} -w $args{timeout} $args{host}"; + return Net::Ping::External::_ping_system($command, 0); + } + '; + die $@ if $@; + #} use String::Approx qw(amatch); use Chart::LinesPoints; use Chart::Mountain; diff --git a/httemplate/elements/popup_link-ping.html b/httemplate/elements/popup_link-ping.html new file mode 100644 index 000000000..9e5f143d5 --- /dev/null +++ b/httemplate/elements/popup_link-ping.html @@ -0,0 +1,30 @@ +<%doc> + +Example: + + include('/elements/init_overlib.html') + + include( '/elements/popup_link-ping.html', { #hashref or a list, either way + 'ip' => '10.9.8.7', + }) + + +<% include('/elements/popup_link.html', $params ) %>\ +<%init> + +my $params = { 'closetext' => 'Close' }; + +if (ref($_[0]) eq 'HASH') { + $params = { %$params, %{ $_[0] } }; +} else { + $params = { %$params, @_ }; +} + +$params->{'label'} ||= 'ping'; +$params->{'actionlabel'} ||= 'Ping '. $params->{'ip'}; +$params->{'width'} ||= 350; +$params->{'height'} ||= 220; + +$params->{'action'} = $p. 'misc/ping.html?'. $params->{'ip'}; + + diff --git a/httemplate/misc/ping.html b/httemplate/misc/ping.html new file mode 100644 index 000000000..4f0360e8b --- /dev/null +++ b/httemplate/misc/ping.html @@ -0,0 +1,102 @@ +<% include('/elements/header-popup.html', "Ping $ip" ) %> + +<% include('/elements/xmlhttp.html', + 'url' => $p. 'misc/xmlhttp-ping.html', + 'subs' => [ 'ping' ], + ) +%> + +%# + + +<%ntable("#cccccc", 2)%> + + + Status + Checking... + + + Packet loss + + + + Latency + + + + Packets + + + + + +
+
+ +
+ + + +<%init> + +my($query) = $cgi->keywords; +$query =~ /^([\d\.]+)$/ or die 'Illegal IP'; +my $ip = $1; + + diff --git a/httemplate/misc/xmlhttp-ping.html b/httemplate/misc/xmlhttp-ping.html new file mode 100644 index 000000000..e99303207 --- /dev/null +++ b/httemplate/misc/xmlhttp-ping.html @@ -0,0 +1,20 @@ +<% objToJson($return) %> +<%init> + +my $conf = new FS::Conf; + +my $sub = $cgi->param('sub'); + +die "$sub not supported" unless $sub eq 'ping'; + +my $ip = $cgi->param('arg'); + +my $ping = new Net::Ping('external', 5); +$ping->hires(1); +#my $a=time; warn "pinging\n"; +my ($ret, $duration, $ip2) = $ping->ping($ip); +#warn "done pinging (". int(time-$a). "s)\n"; + +my $return = [ $ret, $duration ]; + + diff --git a/httemplate/view/cust_main/packages/services.html b/httemplate/view/cust_main/packages/services.html index 37cd615eb..0fe7931d8 100644 --- a/httemplate/view/cust_main/packages/services.html +++ b/httemplate/view/cust_main/packages/services.html @@ -41,15 +41,20 @@ +% my $ip_addr = $cust_svc->svc_x->ip_addr; + +% if ( $part_svc->svcdb eq 'svc_broadband' ) { + ( <% include('/elements/popup_link-ping.html', 'ip'=> $ip_addr ) %> ) + +% } + % my $manage_link = $opt{'svc_broadband-manage_link'}; % if ( $manage_link && $part_svc->svcdb eq 'svc_broadband' ) { -% my $ip_addr = $cust_svc->svc_x->ip_addr; % my $svc_manage_link = eval(qq("$manage_link")); Manage Device ) % } - % if ( $curuser->access_right('Unprovision customer service') ) { ( <%svc_unprovision_link($cust_svc)%> ) % } diff --git a/httemplate/view/svc_broadband.cgi b/httemplate/view/svc_broadband.cgi index 0e9656b15..1463925b4 100644 --- a/httemplate/view/svc_broadband.cgi +++ b/httemplate/view/svc_broadband.cgi @@ -8,7 +8,9 @@ )) %> -Edit this information +<% include('/elements/init_overlib.html') %> + +Edit this information
<%ntable("#cccccc")%> @@ -42,7 +44,10 @@ % if ( $ip_addr ) { IP Address - <%$ip_addr%> + + <%$ip_addr%> + (<% include('/elements/popup_link-ping.html', 'ip'=>$ip_addr ) %>) + IP Netmask