Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-10-2006, 07:35 AM
|
#1
|
|
Member
Registered: Apr 2006
Location: Portsmouth
Distribution: CentOS & Ubuntu
Posts: 49
Rep:
|
Executing shell commands through PHP!!!
Hi chaps,
I am trying to generate a script that will execute terminal commands through Apache(PHP).When i got to execute commands i don't have any root permissions to do so. even tho i am logged in as root.
Could someone help me out?
i think there is some sort of command you have to enter into php but i am not sure. . .
Many Thanx
Rich.
|
|
|
|
04-10-2006, 11:10 AM
|
#2
|
|
Member
Registered: Aug 2002
Location: St Louis, MO
Distribution: Slack 10.2, Slack 12, Suse 10.0, DSL 2.2, Xubuntu 7.04
Posts: 920
Rep:
|
I'll put the usual warnings about running a web script which can do things as root here...be very, very careful!
Check the PHP shell_exec manual http://us2.php.net/shell_exec - some of the comments at the bottom are regarding script root access, and may help you out a bit.
|
|
|
|
04-10-2006, 01:15 PM
|
#3
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
Quote:
|
Originally Posted by Richtown
Hi chaps,
I am trying to generate a script that will execute terminal commands through Apache(PHP).When i got to execute commands i don't have any root permissions to do so. even tho i am logged in as root.
Could someone help me out?
i think there is some sort of command you have to enter into php but i am not sure. . .
Many Thanx
Rich.
|
Hi, and welcome to LQ!
What are you trying to achieve, what command are you
invoking, what is the error message you're getting?
Cheers,
Tink
P.S.: I'd suggest that you let me move this to our
programming forum, better exposure there.
|
|
|
|
04-11-2006, 08:48 AM
|
#4
|
|
Member
Registered: Apr 2006
Location: Portsmouth
Distribution: CentOS & Ubuntu
Posts: 49
Original Poster
Rep:
|
HI, i am at university we have a project to build a firewall in linux using iptables, basically all i wanted to do was execute bash commands in php. But i dont have the correct permissions?
WOuld you know how to do this?
Regards
Rich
|
|
|
|
04-11-2006, 01:06 PM
|
#5
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
If I knew which commands you're trying to execute from which
environment, maybe? And you told me what the exact error message
was ... maybe we could assess what the problem is. But with
the things you keep repeating: no.
Are you using PHP from the command-line or from within Apache?
If it's Apache: as what user is the service being run?
...
Do yourself a favour, and take ESRs advice
Cheers,
Tink
|
|
|
|
04-12-2006, 04:00 AM
|
#6
|
|
Senior Member
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284
Rep:
|
Look at using sudo. This will you specify the user Apache runs as, often www-data, to access various commands normally only accesible to the root user. As mentioned before, be careful what commands you allow, and ensure there's some kind of syntax validation within your PHP so that naughty code can't get passed to the shell. There's a host of debates as to what's the right way to do it from a security point of view! Otherwise, pretty easy to execute iptable commands. If you're wanting to do more, then again as mentioned before, tell us a bit more info.
|
|
|
|
04-12-2006, 02:57 PM
|
#7
|
|
Member
Registered: Apr 2006
Location: Portsmouth
Distribution: CentOS & Ubuntu
Posts: 49
Original Poster
Rep:
|
ok,
I'm Running apache 2.0/ logged in as root
Apachectl start
I have a HTML page that will input a variable allow_ip = e.g 19.168.1.1
I have a submit button, when pressed directs to a php page.
which has the following lines:
<?php
echo exec('iptables -A INPUT -s &allow_ip -j DROP')
?>
when i run this on apache it doesnt seem to work?,when i run the command terminal it doenst block the ip.
Kind Regards
Rich
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:56 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|