0: #!/usr/bin/perl -w
1:
2: use strict;
3:
4: # This is a RIDUCULOUSLY simple script which I often use
5: # with ISP's that prohibit telnet access. It simply runs
6: # an arbitrary UNIX command and captures its output to a
7: # web page.
8:
9: # I won't debate whether or not it belongs here; that's for
10: # exalted others to decide; I merely present something I
11: # have found to be useful.
12:
13: # Be Warned: this appends sh redirection (of stderr to
14: # stdout: '2>&1') to the command entered, so arbitrary
15: # redirection entered as part of any command may not
16: # work as expected!
17:
18: # DISCLAIMER: Do NOT leave this script in an accessible
19: # location on any active web server!! It is VERY insecure!
20: # At least chmod the 'x' bit off when not in use!
21:
22: use CGI qw( :standard *table *Tr *pre );
23: use CGI::Carp qw( fatalsToBrowser );
24: use File::Basename;
25:
26: my $title = 'UNIX Command';
27:
28: my $command = param('command'); # get command entered
29: # append command name, if any, to title
30: $title .= ': '. basename( (split /\s/, $command)[0] ) if $command;
31:
32: # display control panel
33: print join( "\n", header,
34: start_html($title),
35: strong(h1($title)),
36: start_form({ -method=>'get' }),
37: start_table({-width=>'100%',-borders=>0}),
38: start_Tr,
39: td( 'Command:' ),
40: td( textfield({-size=>100,-name=>'command'}) ),
41: td( submit('run')),
42: end_Tr,
43: end_table,
44: end_form ), "\n";
45:
46: # if command was entered, run it in a pipe and display its output
47: if ($command) {
48: open( CMD, "$command 2>&1|" ) or die "$!: running command: '$command'";
49: print start_pre, "\n";
50: print while (<CMD>);
51: print end_pre, "\n";
52: close CMD;
53: }
54:
55: print join( "\n",
56: end_html ),"\n";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.