LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-08-2009, 01:42 AM   #1
ashes_sheldon
LQ Newbie
 
Registered: May 2009
Posts: 14

Rep: Reputation: 0
Unhappy executing linux commands from web page and outputing it back to the web page


hi fellas
I wanted to know if i can execute commands on linux console through a web page and redirect it back to my web page !

For example :
if i send a query "ls"
it should execute this command on my linux console and also redirect the list of the files to the web page from which i give the command !

please help me out ..

regards,
ashes_sheldon
 
Old 05-08-2009, 02:26 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,775

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
You can use cgi script to have the output written to the web page, but I don't think you can easily make it output to the console -the webpage has no way of knowing which console or terminal you are on.
 
Old 05-08-2009, 02:34 AM   #3
ashes_sheldon
LQ Newbie
 
Registered: May 2009
Posts: 14

Original Poster
Rep: Reputation: 0
thnks ..
but does the cgi script queries execute commands given from web page in console ?

i can easily redirect the console o/p by

command >> test.html
but how do i format my contents .. the display is in single line
 
Old 05-08-2009, 02:37 AM   #4
ashes_sheldon
LQ Newbie
 
Registered: May 2009
Posts: 14

Original Poster
Rep: Reputation: 0
plz tell me how do i do the cgi thing .
 
Old 05-08-2009, 04:39 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,775

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
Here's a small example which shows the output of two commands and refreshes itself.
Code:
#!/bin/bash --
echo -en "Content-type: text/html\n\n<META HTTP-EQUIV="REFRESH" CONTENT="10\;URL=http://localhost/httpd/html/bash-cgi/combo.cgi">\n"
echo "<html><head><title>OS Version</title></head><body><H1>"; /usr/bin/uname -r
echo "</H1>"
echo "<hl>"
echo "<H2>"; /usr/bin/date
echo "</H2>"
echo "</body></html>"
It's important to note that the commands will be executed by the httpd server you are running, so they will run with the same username and group as the server itself. You have to be careful about what commands you let be run...
You can use it by placing it in your cgi-bin dir and making it executable, or you can change the name of it and open it directly in your browser.
 
Old 05-08-2009, 12:15 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by ashes_sheldon View Post
hi fellas
I wanted to know if i can execute commands on linux console through a web page and redirect it back to my web page !

For example :
if i send a query "ls"
it should execute this command on my linux console and also redirect the list of the files to the web page from which i give the command !

please help me out ..

regards,
ashes_sheldon
What you are suggesting is probably the worst possible security hole imaginable. What happens when the command that gets issued is
Code:
rm -rf / 
There is probably a list of blackhats trying to figure out how to access your server right now.
--- rod.

Last edited by theNbomr; 05-08-2009 at 12:18 PM.
 
Old 05-08-2009, 02:04 PM   #7
j0hnsmith
LQ Newbie
 
Registered: Apr 2009
Posts: 23

Rep: Reputation: 0
If you want to run a specific command to output to the page each time it's called you can use SSI, see http://httpd.apache.org/docs/1.3/how...cutingcommands

This doesn't let the user of the page choose the command to enter.
 
Old 05-09-2009, 02:33 AM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Here an existing php program that implements an entire web-terminal: PHP Shell Terminal.
 
Old 05-09-2009, 07:19 AM   #9
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by theNbomr View Post
What you are suggesting is probably the worst possible security hole imaginable. What happens when the command that gets issued is
Code:
rm -rf / 
There is probably a list of blackhats trying to figure out how to access your server right now.
--- rod.

http://en.wikipedia.org/wiki/Chroot
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Web query to execute commands and output it to a web page ! ashes_sheldon Linux - Newbie 1 05-08-2009 03:45 AM
Can ping web page from telnet, but can't open it in web browser a.ilic Linux - Networking 1 04-01-2008 11:29 AM
web page database access per page or per session? b0uncer Programming 6 01-13-2007 01:09 PM
Execute bash commands from web page solomage Linux - Software 1 10-07-2004 11:54 AM
Jerky mouse when web browsers download web page stodge Linux - Software 1 07-08-2003 11:29 PM


All times are GMT -5. The time now is 03:01 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration