set_network working, needs more testing
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 3 Jan 2010 22:59:50 +0000 (22:59 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 3 Jan 2010 22:59:50 +0000 (22:59 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@85 01035d8c-6547-0410-b346-abe4f91aad63

easy-asterisk-gui/easy.js
easy-asterisk-gui/set_network.sh
easy-asterisk-gui/test.sh

index 6f9690d0d71d8c307b0c16c44a00e933c06ea9af..262005811adcb5ff4399bcc41911f6b5362989e0 100644 (file)
@@ -37,20 +37,14 @@ function isIP(obj) {
     return ip;
 }
 
-function validateForm(thisForm) {
-    var valid = true;
-
-    with (thisForm) {
-       valid = isISP(ipaddress);
-    }
-
-    return !valid;
-}
-
 function localInit() {
 
     if (init_dhcp == "yes") {
        $('dhcp').checked = true;
+       $('ipaddress').disabled = 1;
+       $('netmask').disabled = 1;
+       $('gateway').disabled = 1;
+       $('dns').disabled = 1;
     }
     else {
        $('static').checked = true;
index 95a6b7611294a71cac4254a65016ba1f42ceac62..011630340167910b40ce7ad1c33dd1a8af786940 100755 (executable)
@@ -1,24 +1,17 @@
 #!/bin/sh
 # set_network.sh
 #
-# A system call from AJAM/Asterisk sets the network parameters of an IP0X using
-# this script
-#
-# ./set_network yes|no [ipaddress] [netmask] [gateway] [dns]
-
-echo `date` " set_network.sh $1 $2 $3 $4 $5" >> /tmp/easy_gui.log
+# CGI to set network parameters of an IP0X.
 
-cat << EOF
-<html>
-EOF
-env
-cat <<EOF
-</html>
-EOF
+dhcp=`echo "$QUERY_STRING" | grep -oe "dhcp=[^&]*" | sed -n "s/dhcp=//p"`
+ipaddress=`echo "$QUERY_STRING" | grep -oe "ipaddress=[^&]*" | sed -n "s/ipaddress=//p"`
+netmask=`echo "$QUERY_STRING" | grep -oe "netmask=[^&]*" | sed -n "s/netmask=//p"`
+gateway=`echo "$QUERY_STRING" | grep -oe "gateway=[^&]*" | sed -n "s/gateway=//p"`
+dns=`echo "$QUERY_STRING" | grep -oe "dns=[^&]*" | sed -n "s/dns=//p"`
 
-exit
+echo `date` " set_network.sh $dhcp $ipaddress $netmask $gateway $dns" >> /tmp/easy_gui.log
 
-if [ $1 == "yes" ]; then
+if [ $dhcp == "yes" ]; then
 
   # DHCP
 
@@ -34,16 +27,10 @@ if [ $1 == "yes" ]; then
   fi
 fi
 
-if [ $1 == "no" ]; then
+if [ $dhcp == "no" ]; then
   
   # Static IP
 
-  # check correct number of arguments
-
-  if [ $# -le 4 ]; then
-    exit
-  fi
-
   if [ -f /etc/rc.d/S10network ]; then
     /etc/init.d/network stop
     /etc/init.d/network disable
@@ -51,12 +38,20 @@ if [ $1 == "no" ]; then
   fi
   
   sed -i "s/DHCPD=.*/DHCPD=no/g" /etc/init.d/network-static
-  sed -i "s/IPADDRESS=.*/IPADDRESS=\"$2\"/g" /etc/init.d/network-static
-  sed -i "s/NETMASK=.*/NETMASK=\"$3\"/g" /etc/init.d/network-static
-  sed -i "s/GATEWAY=.*/GATEWAY=\"$4\"/g" /etc/init.d/network-static
-  sed -i "s/DNS=.*/DNS=\"$5\"/g" /etc/init.d/network-static
+  sed -i "s/IPADDRESS=.*/IPADDRESS=\"$ipaddress\"/g" /etc/init.d/network-static
+  sed -i "s/NETMASK=.*/NETMASK=\"$netmask\"/g" /etc/init.d/network-static
+  sed -i "s/GATEWAY=.*/GATEWAY=\"$gateway\"/g" /etc/init.d/network-static
+  sed -i "s/DNS=.*/DNS=\"$dns\"/g" /etc/init.d/network-static
   /etc/init.d/network-static stop
   /etc/init.d/network-static start
-  exit
 fi
 
+cat <<EOF
+<html>
+<head>
+<title>set_network.sh</title>
+<meta http-equiv="REFRESH" content="0;url=http:test.sh">
+</head>
+</html>
+
+EOF
\ No newline at end of file
index 7a63348bb5ce85d7f766ff25970a2decf071b19d..bed3e7ae9cbba48a3ded4c182bf43224fe3a7e8b 100644 (file)
@@ -43,10 +43,10 @@ cat << EOF
      <td><input type="radio" id="static" name="dhcp" value="no" onClick="doStatic()">Static</td>
      <td><input type="radio" id="dhcp"   name="dhcp" value="yes" onClick="doDHCP()">DHCP</td>
   </tr>
-  <tr><td>IP Address:</td><td><input type="text" name="ipaddress" id="ipaddress" onBlur="isIP(this)" disabled=1></td></tr>
-  <tr><td>Netmask:</td><td><input type="text" name="netmask" id="netmask" onBlur="isIP(this)" disabled=1></td></tr>
-  <tr><td>Gateway:</td><td><input type="text" name="gateway" id="gateway" onBlur="isIP(this)" disabled=1></td></tr>
-  <tr><td>DNS:</td><td><input type="text" name="dns" id="dns" onBlur="isIP(this)" disabled=1></td></tr>
+  <tr><td>IP Address:</td><td><input type="text" name="ipaddress" id="ipaddress" onBlur="isIP(this)"></td></tr>
+  <tr><td>Netmask:</td><td><input type="text" name="netmask" id="netmask" onBlur="isIP(this)"></td></tr>
+  <tr><td>Gateway:</td><td><input type="text" name="gateway" id="gateway" onBlur="isIP(this)"></td></tr>
+  <tr><td>DNS:</td><td><input type="text" name="dns" id="dns" onBlur="isIP(this)"></td></tr>
   <tr><td><input id="networkapply" type="submit" value="Apply"></td></tr>
 </tr>
 </table>