dear list,
i've just write a simple php script to add user to my iptables, but some times it works and it dosn't work,, here's my script for my adduser.php
<?php
exec('/var/www/html/backup.sh');
$hash = "# $_POST[username]\n";
$ip = "-A INPUT -p tcp -m tcp -s $_POST[ipaddress] -d 10.10.105.18 --dport 8080 -j ACCEPT\n";
$myFile = "/etc/sysconfig/iptables.ok";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "$_POST[username]\n";
$stringData = "$_POST[ipaddress]\n";
fwrite($fh, $hash);
fwrite($fh, $ip);
fclose($fh);
exec('/var/www/html/restore.sh');
?>
here's my bash script
backup.sh
#!/bin/bash
set -x
dir=/etc/sysconfig/
#file=/etc/sysconfig/iptables
#backup=/etc/sysconfig/iptables.bak
#ok=/etc/sysconfig/iptables.ok
cd $dir
cp iptables iptables.bak
sed -e :a -e '$d;N;2,21ba' -e 'P;D' iptables > iptables.ok
chmod 646 iptables.ok
exit
and
restore.sh
#!/bin/bash
dir=/etc/sysconfig/
file=/etc/sysconfig/iptables
backup=/etc/sysconfig/iptables.bak
ok=/etc/sysconfig/iptables.ok
mv $ok $file
chmod 644 $file
cat /var/www/html/footer.txt >> $file
rm -rf $ok
exit
if i try my script form my bash shell, it's working well,, i do have gave apache permission to acces both my bash script. pls help me to find out the solution,,
rgds,
Ridwanfi