#!/usr/bin/perl -w use strict; # This is a RIDUCULOUSLY simple script which I often use # with ISP's that prohibit telnet access. It simply runs # an arbitrary UNIX command and captures its output to a # web page. # I won't debate whether or not it belongs here; that's for # exalted others to decide; I merely present something I # have found to be useful. # Be Warned: this appends sh redirection (of stderr to # stdout: '2>&1') to the command entered, so arbitrary # redirection entered as part of any command may not # work as expected! # DISCLAIMER: Do NOT leave this script in an accessible # location on any active web server!! It is VERY insecure! # At least chmod the 'x' bit off when not in use! use CGI qw( :standard *table *Tr *pre ); use CGI::Carp qw( fatalsToBrowser ); use File::Basename; my $title = 'UNIX Command'; my $command = param('command'); # get command entered # append command name, if any, to title $title .= ': '. basename( (split /\s/, $command)[0] ) if $command; # display control panel print join( "\n", header, start_html($title), strong(h1($title)), start_form({ -method=>'get' }), start_table({-width=>'100%',-borders=>0}), start_Tr, td( 'Command:' ), td( textfield({-size=>100,-name=>'command'}) ), td( submit('run')), end_Tr, end_table, end_form ), "\n"; # if command was entered, run it in a pipe and display its output if ($command) { open( CMD, "$command 2>&1|" ) or die "$!: running command: '$command'"; print start_pre, "\n"; print while (); print end_pre, "\n"; close CMD; } print join( "\n", end_html ),"\n";