#!/usr/bin/perl -w # This code is Copyright (C) Chris Angell, 2003. All rights reserved. This # code is free software; you can redistribute it and/or modify it under # the same terms as Perl itself. # http://chrisangell.com/cgi-bin/traceroute.cgi # 5-31-03 - version 0.1 use strict; use CGI; our $VERSION = v0.1; my $q = CGI->new; my $TRACEUTIL = "/usr/sbin/traceroute"; my @OPTS = qw(-n -v); $SIG{ALRM} = sub { exit }; { # view source code local $^W=0; # stop annoying uninitialized string warning in next line source() and exit if ("source" eq $q->param("do")); } unless (defined($q->param("host_or_ip"))) { # first visit to page print $q->header, $q->start_html("Access to traceroute utility"), "<CENTER>", $q->start_form, " Host/IP ", $q->textfield("host_or_ip"), $q->p, $q->checkbox(-name => "n-opt", -label => " -n option: Print hop addresses numerically rather than symbolically and numerically"), $q->p, $q->submit, $q->end_form, $q->p, qq(<A href="@{[$q->url]}?do=source">View Source Code</A>), $q->end_html; } else { # if user submitted a query print $q->header, "<PRE>"; # don't let bad stuff though like `rm -rf /` print "bad input, must not match /[^\\w.:-]/" and exit if $q->param("host_or_ip") =~ /[^\w.:-]/; my $host_or_ip = $q->param("host_or_ip"); my $type = $q->param("type"); my $options = $q->param("n-opt") ? "-n " : " "; alarm 60; # set a timeout system("$TRACEUTIL -q 2 -w 2 $options $host_or_ip"); } sub source { require File::Slurp; print $q->header, "<PLAINTEXT>", File::Slurp::read_file($0); }