From: drowe67 Date: Sun, 3 Jan 2010 23:47:03 +0000 (+0000) Subject: added check for Internet connection, working on form validation X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=f1d31e5aeb0489ddf08d52171475d3ad05bace9d;p=freetel-svn-tracking.git added check for Internet connection, working on form validation git-svn-id: https://svn.code.sf.net/p/freetel/code@86 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/easy-asterisk-gui/Makefile b/easy-asterisk-gui/Makefile index 42de4ab8..e06b264e 100644 --- a/easy-asterisk-gui/Makefile +++ b/easy-asterisk-gui/Makefile @@ -9,4 +9,4 @@ TESTIP=192.168.1.150 # rcp index.html root@$(TESTIP):/var/lib/asterisk/static-http/ test: - rcp test.sh test1.sh easy.js easy1.js set_network.sh root@$(TESTIP):/www/cgi-bin + rcp network.sh network.js set_network.sh root@$(TESTIP):/www/cgi-bin diff --git a/easy-asterisk-gui/easy.js b/easy-asterisk-gui/easy.js deleted file mode 100644 index 26200581..00000000 --- a/easy-asterisk-gui/easy.js +++ /dev/null @@ -1,61 +0,0 @@ -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 localInit() { - - if (init_dhcp == "yes") { - $('dhcp').checked = true; - $('ipaddress').disabled = 1; - $('netmask').disabled = 1; - $('gateway').disabled = 1; - $('dns').disabled = 1; - } - 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/network.js b/easy-asterisk-gui/network.js new file mode 100644 index 00000000..6a6663c1 --- /dev/null +++ b/easy-asterisk-gui/network.js @@ -0,0 +1,66 @@ +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 localInit() { + + if (init_dhcp == "yes") { + $('dhcp').checked = true; + $('ipaddress').disabled = 1; + $('netmask').disabled = 1; + $('gateway').disabled = 1; + $('dns').disabled = 1; + } + 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; + $('internet').value = init_internet; +} + +function validate_form(form) +{ + return true; +} diff --git a/easy-asterisk-gui/network.sh b/easy-asterisk-gui/network.sh new file mode 100644 index 00000000..33869237 --- /dev/null +++ b/easy-asterisk-gui/network.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# network.sh +# David Rowe 4 Jan 2010 +# CGI for network GUI + +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 + +# See if we have Internet connectivity + +packet_loss=`ping google.com -c 1 -q | sed -n 's/.*received, \(.*\)% packet loss/\1/p'` +if [ $packet_loss == "0" ]; then + internet="Good"; +else + internet="Not Available"; +fi + +# Construct the web page ------------------------------- + +echo "" +echo "" +echo "" + +cat << EOF + +Easy Asterisk - Network + +
+ + + + + + + + + + + + + +
StaticDHCP
IP Address:
Netmask:
Gateway:
DNS:
Internet Connection:
+
+ +EOF diff --git a/easy-asterisk-gui/set_network.sh b/easy-asterisk-gui/set_network.sh index 01163034..d79fe634 100755 --- a/easy-asterisk-gui/set_network.sh +++ b/easy-asterisk-gui/set_network.sh @@ -50,7 +50,7 @@ cat < set_network.sh - + diff --git a/easy-asterisk-gui/test.sh b/easy-asterisk-gui/test.sh deleted file mode 100644 index bed3e7ae..00000000 --- a/easy-asterisk-gui/test.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/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