From ff14929c000ff72459b7e68f17cae7657a22df4f Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sun, 3 Jan 2010 22:01:41 +0000 Subject: [PATCH] part way thru implementing ip network screen, field validation works git-svn-id: https://svn.code.sf.net/p/freetel/code@84 01035d8c-6547-0410-b346-abe4f91aad63 --- easy-asterisk-gui/Makefile | 7 +- .../{index.html => ajamindex.html} | 0 easy-asterisk-gui/easy.js | 67 +++++++++++++++++++ easy-asterisk-gui/set_network.sh | 12 +++- easy-asterisk-gui/test.sh | 55 +++++++++++++++ 5 files changed, 138 insertions(+), 3 deletions(-) rename easy-asterisk-gui/{index.html => ajamindex.html} (100%) create mode 100644 easy-asterisk-gui/easy.js create mode 100644 easy-asterisk-gui/test.sh diff --git a/easy-asterisk-gui/Makefile b/easy-asterisk-gui/Makefile index 8219ea80..42de4ab8 100644 --- a/easy-asterisk-gui/Makefile +++ b/easy-asterisk-gui/Makefile @@ -4,6 +4,9 @@ TESTIP=192.168.1.150 +#test: +# rcp set_network.sh get_network.sh root@$(TESTIP):/var/lib/asterisk/scripts +# rcp index.html root@$(TESTIP):/var/lib/asterisk/static-http/ + test: - rcp set_network.sh get_network.sh root@$(TESTIP):/var/lib/asterisk/scripts - rcp index.html root@$(TESTIP):/var/lib/asterisk/static-http/ + rcp test.sh test1.sh easy.js easy1.js set_network.sh root@$(TESTIP):/www/cgi-bin diff --git a/easy-asterisk-gui/index.html b/easy-asterisk-gui/ajamindex.html similarity index 100% rename from easy-asterisk-gui/index.html rename to easy-asterisk-gui/ajamindex.html diff --git a/easy-asterisk-gui/easy.js b/easy-asterisk-gui/easy.js new file mode 100644 index 00000000..6f9690d0 --- /dev/null +++ b/easy-asterisk-gui/easy.js @@ -0,0 +1,67 @@ +var script_path = "cgi-bin/"; + +function doStatic() { + $('ipaddress').disabled = 0; + $('netmask').disabled = 0; + $('gateway').disabled = 0; + $('dns').disabled = 0; +} + +function doDHCP() { + $('ipaddress').disabled = 1; + $('netmask').disabled = 1; + $('gateway').disabled = 1; + $('dns').disabled = 1; +} + +// http://moblog.bradleyit.com/2009/06/javascript-ip-address-validation.html + +function isIP(obj) { + var ary = obj.value.split("."); + var ip = true; + + for (var i=0; i<4; i++) { + ip = (!ary[i].match(/^\d{1,3}$/) || (Number(ary[i]) > 255)) ? false : ip; + } + + if (ip) + ip = (ary.length == 4); + + if (!ip) { + // the value is NOT a valid IP address + obj.style.background = "red"; + obj.select(); + } + else { obj.style.background = ""; } // the value IS a valid IP address + + return ip; +} + +function validateForm(thisForm) { + var valid = true; + + with (thisForm) { + valid = isISP(ipaddress); + } + + return !valid; +} + +function localInit() { + + if (init_dhcp == "yes") { + $('dhcp').checked = true; + } + else { + $('static').checked = true; + $('ipaddress').disabled = 0; + $('netmask').disabled = 0; + $('gateway').disabled = 0; + $('dns').disabled = 0; + } + $('ipaddress').value = init_ipaddress; + $('netmask').value = init_netmask; + $('gateway').value = init_gateway; + $('dns').value = init_dns; + $('networkapply').disabled = 0; +} diff --git a/easy-asterisk-gui/set_network.sh b/easy-asterisk-gui/set_network.sh index 53a74e83..95a6b761 100755 --- a/easy-asterisk-gui/set_network.sh +++ b/easy-asterisk-gui/set_network.sh @@ -1,4 +1,4 @@ -#!/bin/sh -x +#!/bin/sh # set_network.sh # # A system call from AJAM/Asterisk sets the network parameters of an IP0X using @@ -8,6 +8,16 @@ echo `date` " set_network.sh $1 $2 $3 $4 $5" >> /tmp/easy_gui.log +cat << EOF + +EOF +env +cat < +EOF + +exit + if [ $1 == "yes" ]; then # DHCP diff --git a/easy-asterisk-gui/test.sh b/easy-asterisk-gui/test.sh new file mode 100644 index 00000000..7a63348b --- /dev/null +++ b/easy-asterisk-gui/test.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +echo `date` " get_network.sh" >> /tmp/easy_gui.log + +if [ -f /etc/rc.d/S10network ]; then + dhcp=yes + ipaddress=`ifconfig eth0 | sed -n 's/.*inet addr:\(.*\) Bcast.*/\1/p'` + netmask=`ifconfig eth0 | sed -n 's/.*Mask:\(.*\)\s*/\1/p'` + gateway=`route -n | awk '/^0.0.0.0/ {print $2}'` + dns=`cat /etc/resolv.conf | awk '/^nameserver/ {print $2}'` +fi + +if [ -f /etc/rc.d/S10network-static ] +then + dhcp=no + ipaddress=`sed -n 's/IPADDRESS="\(.*\)"/\1/p' /etc/init.d/network-static` + netmask=`sed -n 's/NETMASK="\(.*\)"/\1/p' /etc/init.d/network-static` + gateway=`sed -n 's/GATEWAY="\(.*\)"/\1/p' /etc/init.d/network-static` + dns=`sed -n 's/DNS="\(.*\)"/\1/p' /etc/init.d/network-static` +fi + +# Construct the web page ------------------------------- + +echo "" +echo "" +echo "" + +cat << EOF + +Easy Asterisk GUI + +
+ + + + + + + + + + + + +
StaticDHCP
IP Address:
Netmask:
Gateway:
DNS:
+
+ +EOF -- 2.25.1