#!/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/host.cgi # 5-31-03 - version 0.1 use strict; use CGI qw(param header start_html end_html start_form end_form submit textfield popup_menu checkbox br p url); use CGI::Debug; use File::Slurp; our $VERSION = v0.1; my $HOSTUTIL = "/usr/sbin/host"; my @OPTS = qw(-n); my @TYPES = qw(a aaaa ptr mx ns cname soa any md mf mb mg mr null wks hinfo minfo uinfo uid gid unspec); { # view source code local $^W=0; # stop annoying uninitialized string warning in next line source() and exit if ("source" eq param("do")); } unless (defined(param("host_or_ip"))) { # first visit to page print header, start_html("Access to host(1)"), "<CENTER>", start_form, " Host/IP ", textfield("host_or_ip"), " Query Type ", popup_menu("type", \@TYPES, "a"), p, checkbox(-name => "n-opt", -label => " Set -n option (ipv6 nibble form of reverse lookup)"), p, submit, end_form, p, qq(<A href="@{[url]}?do=source">View Source Code</A>), end_html; } else { # if user submitted a query print header, "<PLAINTEXT>"; # don't let bad stuff though like `rm -rf /` print "bad input, must not match /[^\\w.:\\[\\]-]/" and exit if param("host_or_ip") =~ /[^\w.:\[\]-]/; my $host_or_ip = param("host_or_ip"); my $type = param("type"); my $options = param("n-opt") ? "-n" : " "; # print output of command, both stdout/stderr print qx($HOSTUTIL $options -t $type $host_or_ip 2>&1); } sub source { print header, "<PLAINTEXT>", read_file($0); }