You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by amit khatri <am...@hotmail.com> on 2002/02/28 14:14:36 UTC

Running perl script to execute system commands ( script included )

Hi

    This is the perl script to run a system command(on linux) .

The commands are send from an html page whose code is also included.

U can save the code and try running it.

( I log in as root user )

----------------------------------------------------------------------
Problem :
          Commands that run are

                                            ls,
        				    dir,
					    date,
					    pwd
					    ifconfig


          Commands that don't run are

                                  ll
                                  ipchains -n -L
              			  netconf
                                  mount /dev/fd0

         it also doesn't show any error for invalid commands.

I want all commands to be executed.

I have not used any module in perl code,is that the reason.
If that is the reason which module should be used and how to install
that module on linux machine


#------------------  Perl Code (first.pl) --------------------------

#!/usr/bin/perl
print "Content-type: text/html\n\n";

read(STDIN,$in,$ENV{'CONTENT_LENGTH'});   #reads the input in var 'in'

@in=split(/&/,$in);    #split the name value pairs

($name1, $val1)=split(/=/,$in[0],2);  #save the first name and value
($name2, $val2)=split(/=/,$in[1],2);  #save  the second name and value


$val2=~ s/\+/" "/ge;   #replace the '+' sign with spaces

# The following 4 lines appends the second value to first , to form a   
complete command

$space="%20";
$temp=$val1.$space;
$temp=~ s/%(..)/pack("c",hex($1))/ge;

# the appended command is stored in the command variable

@command=$temp.$val2;

# by including the `command` var in backquotes it is executed.

# u can directly try @ans=`ls`;

@ans=`@command`;

# The output is send in html format in new window

print "<HTML>";
print "<body bgcolor='brown'>";

print "<hr>";
print "<h1>";

foreach $i(0 .. $#ans)
{
print "$ans[$i] <br> ";
}

print "</h1>";

print "</body>";
print "</HTML>";

#--------------------------Perl Code Ends---------------------------



--------------------------  HTML CODE-------------------------------

<html>
<body>

<form method="post" name="form" target="new"
  action="http://127.0.0.1/cgi-bin/first.pl">

<h2> Command <input type="text" name="command">
<h2> Parameter <input type="text" name="parameter">
<input type="submit">

</form>
</body>
</html>


------------------------- HTML Code Ends  --------------------------

PL try running it and reply me the solution to it.





cheers

Amit Khatri









>From: Pietro Cagnoni <pc...@mclink.net>
>Reply-To: users@httpd.apache.org
>To: users@httpd.apache.org
>Subject: Re: running system commands using perl script on linux
>Date: Wed, 27 Feb 2002 14:37:10 +0100
>
>amit khatri wrote:
> >
> > I am running as a root and even the simple commands like "ll"
> > don't work.
> > At least it should give me the error messages for invalid commands.
>
>hm, ll usually is not a single command but a shell alias... what if you
>try ls?
>
>is there anything in the error log? do you get any message in the
>browser?
>
>in case of despair, post the script.
>
>pietro.
>
>---------------------------------------------------------------------
>The official User-To-User support forum of the Apache HTTP Server Project.
>See <URL:http://httpd.apache.org/userslist.html> for more info.
>To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>For additional commands, e-mail: users-help@httpd.apache.org
>




_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Running perl script to execute system commands ( script included )

Posted by Pietro Cagnoni <pc...@mclink.net>.
amit khatri wrote:
> 
> Hi
> 
>     This is the perl script to run a system command(on linux) .
> 
> The commands are send from an html page whose code is also included.
> 
> U can save the code and try running it.
> 
> ( I log in as root user )

if you change

@ans=`@command`;

to

@ans=`@command 2>&1`;

you'll see the error messages (they are hidden in the apache error log
now), then you'll find more problems, and you'll probably have to learn
to use CGI.pm .

don't get scared, and enjoy the trip :-)

pietro.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Running perl script to execute system commands ( script included )

Posted by Owen Boyle <ob...@bourse.ch>.
amit khatri wrote:
> 
> Hi
> 
>     This is the perl script to run a system command(on linux) .
> 
> The commands are send from an html page whose code is also included.
> 
> U can save the code and try running it.
> 
> ( I log in as root user )

You have already had these questions answered...

- the commands are executed as the apache user, regardless of what you
login as. This user can't run /usr/sbin commands so ll, ipchains etc
won't work.

- backticks only traps STDOUT but errors go to STDERR. That's why you
don't see them.

Rgds,

owen Boyle. 

> 
> ----------------------------------------------------------------------
> Problem :
>           Commands that run are
> 
>                                             ls,
>                                             dir,
>                                             date,
>                                             pwd
>                                             ifconfig
> 
>           Commands that don't run are
> 
>                                   ll
>                                   ipchains -n -L
>                                   netconf
>                                   mount /dev/fd0
> 
>          it also doesn't show any error for invalid commands.
> 
> I want all commands to be executed.
> 
> I have not used any module in perl code,is that the reason.
> If that is the reason which module should be used and how to install
> that module on linux machine
> 
> #------------------  Perl Code (first.pl) --------------------------
> 
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> 
> read(STDIN,$in,$ENV{'CONTENT_LENGTH'});   #reads the input in var 'in'
> 
> @in=split(/&/,$in);    #split the name value pairs
> 
> ($name1, $val1)=split(/=/,$in[0],2);  #save the first name and value
> ($name2, $val2)=split(/=/,$in[1],2);  #save  the second name and value
> 
> $val2=~ s/\+/" "/ge;   #replace the '+' sign with spaces
> 
> # The following 4 lines appends the second value to first , to form a
> complete command
> 
> $space="%20";
> $temp=$val1.$space;
> $temp=~ s/%(..)/pack("c",hex($1))/ge;
> 
> # the appended command is stored in the command variable
> 
> @command=$temp.$val2;
> 
> # by including the `command` var in backquotes it is executed.
> 
> # u can directly try @ans=`ls`;
> 
> @ans=`@command`;
> 
> # The output is send in html format in new window
> 
> print "<HTML>";
> print "<body bgcolor='brown'>";
> 
> print "<hr>";
> print "<h1>";
> 
> foreach $i(0 .. $#ans)
> {
> print "$ans[$i] <br> ";
> }
> 
> print "</h1>";
> 
> print "</body>";
> print "</HTML>";
> 
> #--------------------------Perl Code Ends---------------------------
> 
> --------------------------  HTML CODE-------------------------------
> 
> <html>
> <body>
> 
> <form method="post" name="form" target="new"
>   action="http://127.0.0.1/cgi-bin/first.pl">
> 
> <h2> Command <input type="text" name="command">
> <h2> Parameter <input type="text" name="parameter">
> <input type="submit">
> 
> </form>
> </body>
> </html>
> 
> ------------------------- HTML Code Ends  --------------------------
> 
> PL try running it and reply me the solution to it.
> 
> cheers
> 
> Amit Khatri
> 
> >From: Pietro Cagnoni <pc...@mclink.net>
> >Reply-To: users@httpd.apache.org
> >To: users@httpd.apache.org
> >Subject: Re: running system commands using perl script on linux
> >Date: Wed, 27 Feb 2002 14:37:10 +0100
> >
> >amit khatri wrote:
> > >
> > > I am running as a root and even the simple commands like "ll"
> > > don't work.
> > > At least it should give me the error messages for invalid commands.
> >
> >hm, ll usually is not a single command but a shell alias... what if you
> >try ls?
> >
> >is there anything in the error log? do you get any message in the
> >browser?
> >
> >in case of despair, post the script.
> >
> >pietro.
> >
> >---------------------------------------------------------------------
> >The official User-To-User support forum of the Apache HTTP Server Project.
> >See <URL:http://httpd.apache.org/userslist.html> for more info.
> >To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> >For additional commands, e-mail: users-help@httpd.apache.org
> >
> 
> _________________________________________________________________
> Join the world?s largest e-mail service with MSN Hotmail.
> http://www.hotmail.com
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org