Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
    0: #!/usr/bin/perl -w
    2: use strict;
    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.
    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.
    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!
    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!
    22: use CGI qw( :standard *table *Tr *pre );
    23: use CGI::Carp qw( fatalsToBrowser );
    24: use File::Basename;
    26: my $title = 'UNIX Command';
    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;
    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";
    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: }
    55: print join( "\n",
    56:             end_html ),"\n";

In reply to Run arbitrary UNIX commands on webserver without telnet by dmmiller2k

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (3)
    As of 2018-06-24 07:19 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.