write into file in php
i want to write to iptables file (where iptables rules saved) through php code.
i mean that instead of writing iptables rules on the command line i want to design php interface to allow entering iptables rules through this interface .
now i try to use fwrite php function to write rules into /etc/sysconfig/iptables but i failed.please help me.
Does the user has write permission to modify the files.
Originally Posted by shyma
I believe /etc/sysconfig/iptables are root user files.
If want to modify it , add your apache/web server user to /etc/sudoers files
Note : I may be wrong here :mrgreen:
how i can know apache user?
I think it's not apache user - just normal user.
We used a user name called oss and to allow this user to have root access
we added following line in /etc/sudoers file.
Note : I'm just giving some hints ...as i didn't have enough knowledege in web applications
oss ALL=(ALL) NOPASSWD:ALL
May be try and execute your php file from command prompt and check it's results ..
I'd suggest not giving your apache user full sudo access. That leaves you far more exposed to an attack. First of all, I'd make sure your php script can only be run locally (perhaps use an .htaccess file to restrict the web directory in which it resides). Then you could add a line like the following to your sudoers file (might want to double-check my syntax)
apache ALL = NOPASSWD: /usr/sbin/iptables