Results 1 to 8 of 8
i know that exec function in php used to execute commands , i have a problem:i try to use exec function to execute iptables command but i failed.please help me.
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-30-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 38
exec function
i know that exec function in php used to execute commands , i have a problem:i try to use exec function to execute iptables command but i failed.please help me.
this is the code
<?php
$output = shell_exec('iptables -L ');
echo "<pre>$output</pre>";
?>
- 04-30-2008 #2
First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 04-30-2008 #3Just Joined!
- Join Date
- Apr 2008
- Posts
- 38
exec function 2
i try this code but i failed also
<?php
$output = shell_exec('/sbin/iptables -L');
echo "<pre>$output</pre>";
?>
thanks for help.
- 04-30-2008 #4
Hi shyma,
You can reply this thread - Don't need to create new thread like you did here.
http://www.linuxforums.org/forum/lin...ction-2-a.html
[quote]
i try this code but i failed also
<?php
$output = shell_exec('/sbin/iptables -L');
echo "<pre>$output</pre>";
?>
thanks for help.
[\quote]
Are you trying to run php from web browser?
anyway first check that code runs from command line or not.
if it's not running from command line post it's output as well as post the output of command
whereis iptablesFirst they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 04-30-2008 #5Just Joined!
- Join Date
- Apr 2008
- Posts
- 38
yes i try to run php from web browser and the command run in command line, but i didn't know what is the problem.
thanks.
- 04-30-2008 #6
You are logged in as root -- right? and
you are getting desired output from command line-right?
And you are not getting result from browser - right?
Then try and replace the command iptables with simple command like ls
/bin/ls
If 'ls' command gives you output then i think problem lies with permissions.
Try with ls command and let me know the resultsFirst they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 04-30-2008 #7Just Joined!
- Join Date
- Apr 2008
- Posts
- 38
simple commands can be executed. and iptables commands can not.
how i can get permissions to execute iptables commands through php interface?
please help me.
- 05-05-2008 #8
So root user commands are not executed.

If i'm not wrong - i think you need to give permission in /etc/sudoers -you can give sudo privileges to apache's user, and then use it on php [also check out httpd.conf if ur server is apache & php.ini ]
Try google from here on about "executing root commands under php using browser"
All the best
First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org


Reply With Quote

