httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Owen Boyle <...@bourse.ch>
Subject Re: Running perl script to execute system commands ( script included )
Date Thu, 28 Feb 2002 13:23:45 GMT
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 <pcagnoni@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


Mime
View raw message