This is my first question, CMIIW :
here my sample php script
<form method="GET" action="/var/www/cgi-bin/mode2.sh">
<table align="center" nowrap>
<tr>><td>IP address :</TD><TD><input type="text" name="ip"></td></tr>
<tr><td>netmask :</TD><TD><input type="text" name="ip2"></td></tr>
</tr></table>
<input type="submit" value="Send">
<input type="reset" value="Reset"></p></form>
bash script :
#!/bin/bash -x
echo "IPADDR=$ip" >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "NETMASK=$ip2" >>/etc/sysconfig/network-scripts/ifcfg-eth0
I want input textbox value form web browser for example IP and netmask and send the value to bash and save to ifcfg-eth0 file. i know it sound risky, i just want to learn. any sugestion?
Instead of having action attribute point to shell script you want to run, Make action attribute to point to php file like
<form method="GET" action="UserInputIPAddrPHP.php">
And in the UserInputIPAddrPHP.php you can get the User Inputted IP and Netmask as follows
<html>
<body>
<?php
$IP_Addr = $_GET['ip'];
$NetMask = $_GET['ip2'];
$command="/path/to/mode2.sh ".escapeshellarg($IP_Addr)." ".escapeshellarg($NetMask);
exec ($command,$output=array(),$return_value);
if($return_value!==0) {
#print appropriate message
}
?>
</body>
</html>
$command is actual command that you type to run the script at your shell. So set it accordingly.
Write your script mode2.sh like this (mind the quotes):
#!/bin/sh
command "$1" "$2"; # command is actual command you want to run like cp,mv etc
Render it executable:
me@somewhere$ chmod +x mode2.sh
Hope this might help you
Thanks
You should not use bash as cgi script. But if there is really a need, you can get IP and netmask by manipulating variable $QUERY_STRING
#!/bin/bash
echo Content-type:text/plain
echo ""
read IP MASK <<< $(echo $QUERY_STRING | sed -r 's/&?ip2?=/ /g')