From 6446aff623fc766c577c6931ffd5db63f246a663 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Wed, 9 Mar 2011 23:45:41 +0000 Subject: [PATCH] network screen write side writtn, need to write new CGI git-svn-id: https://svn.code.sf.net/p/freetel/code@281 01035d8c-6547-0410-b346-abe4f91aad63 --- mini-asterisk-gui2/README.txt | 2 +- mini-asterisk-gui2/cgi-bin/setline.cgi | 25 ++++++-- mini-asterisk-gui2/cgi-bin/smokeping.cgi | 81 ------------------------ mini-asterisk-gui2/network.html | 7 +- mini-asterisk-gui2/network.js | 79 +++++++++++++++++++++-- 5 files changed, 98 insertions(+), 96 deletions(-) delete mode 100755 mini-asterisk-gui2/cgi-bin/smokeping.cgi diff --git a/mini-asterisk-gui2/README.txt b/mini-asterisk-gui2/README.txt index 43518a6b..711038ec 100644 --- a/mini-asterisk-gui2/README.txt +++ b/mini-asterisk-gui2/README.txt @@ -12,4 +12,4 @@ TODO + cf server side, CGIs + keep CGIs really small, very productive + BASIC style string processing versus regexp - + + CGI wring, regexp, sed is painfully slow, so minimise it diff --git a/mini-asterisk-gui2/cgi-bin/setline.cgi b/mini-asterisk-gui2/cgi-bin/setline.cgi index 610b997e..eaaf47ac 100755 --- a/mini-asterisk-gui2/cgi-bin/setline.cgi +++ b/mini-asterisk-gui2/cgi-bin/setline.cgi @@ -1,8 +1,13 @@ #!/bin/sh # setline.cgi -# David Rowe 12 Dec 2010 +# David Rowe 9 March 2011 +# +# CGI to set the text in "file" from "this" to "that" +# +# Test on host with: +# +# $ export QUERY_STRING='file=test.txt&this=IPADDRESS=&that="192.168.1.31"'; ./setline.cgi # -# CGI to set the text on a particular line cat < EOF -LINE=`echo "$QUERY_STRING" | sed -n "s/.*line=//p"` -echo $LINE - +file=`echo $QUERY_STRING | grep -oe "file=[^&?]*" | sed -n "s/file=//p"` +this=`echo $QUERY_STRING | grep -oe "this=[^&?]*" | sed -n "s/this=//p" | sed "s/%22/\"/g"` +that=`echo $QUERY_STRING | grep -oe "that=[^&?]*" | sed -n "s/that=//p" | sed "s/%22/\"/g"` +echo $QUERY_STRING +echo $file +echo $this +echo $that +if [ -f $file ]; then + sed -i "s/$this.*/$this$that/g" $file +else + echo "$file does not exist" +fi + cat < diff --git a/mini-asterisk-gui2/cgi-bin/smokeping.cgi b/mini-asterisk-gui2/cgi-bin/smokeping.cgi deleted file mode 100755 index 6cac2404..00000000 --- a/mini-asterisk-gui2/cgi-bin/smokeping.cgi +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/speedy -w -# -*-perl-*- - -use lib qw(/usr/share/perl5/smokeping); -use CGI::Carp qw(fatalsToBrowser); - -use Smokeping 2.003006; - -Smokeping::cgi("/etc/smokeping/config"); - -=head1 NAME - -smokeping.cgi - SmokePing webfrontend - -=head1 OVERVIEW - -This script acts as a 'website' for your SmokePing monitoring operation. It -presents the targets you are looking at in a tree structure and draws graphs -as they are required by people looking at the pages. - -=head1 DESCRIPTION - -To get B going, you need a webserver which allows you to run -cgi scripts. The system must be setup so that the B is -allowed to write to the image caching area as defined in the config file. - -This script runs with normal perl. B it will appear to be very slow, -because it does a lot of things when starting up. So if the script has to be -started a fresh on every click, this is both slow and a tough thing for your -webserver. I therefore strongly recomment using SpeedyCGI. - -Please refer to the installation document for detailed setup instructions. - -=head1 SETUP - -When installing SmokePing, this file has to be adjusted to fit your -local system. Three paths have to be entered. - - use lib qw(/usr/pack/rrdtool-1.0.33-to/lib/perl); - -One pointing to your B installation - - use lib qw(/home/oetiker/public_html/smokeping/lib); - -One pointing to the place where you have installed the SmokePing libraries - - use Smokeping; - - Smokeping::cgi("/home/oetiker/.smokeping/config"); - -The third path is the argument to the Smokeping::cgi command. It points to -the SmokePing configuration file. - -=head1 COPYRIGHT - -Copyright (c) 2001 by Tobias Oetiker. All right reserved. - -=head1 LICENSE - -This program is free software; you can redistribute it -and/or modify it under the terms of the GNU General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be -useful, but WITHOUT ANY WARRANTY; without even the implied -warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public -License along with this program; if not, write to the Free -Software Foundation, Inc., 675 Mass Ave, Cambridge, MA -02139, USA. - -=head1 AUTHOR - -Tobias Oetiker Etobi@oetiker.chE - -=cut diff --git a/mini-asterisk-gui2/network.html b/mini-asterisk-gui2/network.html index bdb347be..7275ed34 100644 --- a/mini-asterisk-gui2/network.html +++ b/mini-asterisk-gui2/network.html @@ -30,8 +30,8 @@ - - + + @@ -44,10 +44,9 @@ - +

Network

StaticDHCPStaticDHCP
IP Address:
Netmask:
Internet Connection:
- diff --git a/mini-asterisk-gui2/network.js b/mini-asterisk-gui2/network.js index f1a2ed9a..bcb683cd 100644 --- a/mini-asterisk-gui2/network.js +++ b/mini-asterisk-gui2/network.js @@ -7,6 +7,11 @@ */ var dhcp; +var ipaddress; +var netmask; +var gateway; +var dns; +var backdoor; // Called when we load page @@ -94,31 +99,31 @@ function parseNetwork(line) { if (line.indexOf("IPADDRESS=") != -1) { var s = line.split('"'); - var ipaddress = s[1]; + ipaddress = s[1]; document.network.ipaddress.value = ipaddress; } if (line.indexOf("NETMASK=") != -1) { var s = line.split('"'); - var netmask = s[1]; + netmask = s[1]; document.network.netmask.value = netmask; } if (line.indexOf("GATEWAY=") != -1) { var s = line.split('"'); - var gateway = s[1]; + gateway = s[1]; document.network.gateway.value = gateway; } if (line.indexOf("DNS=") != -1) { var s = line.split('"'); - var dns = s[1]; + dns = s[1]; document.network.dns.value = dns; } if (line.indexOf("BACKDOOR=") != -1) { var s = line.split('"'); - var backdoor = s[1]; + backdoor = s[1]; document.network.backdoor.value = backdoor; } } @@ -147,3 +152,67 @@ function isIP(obj) { return ip; } + + +// called when Apply button pressed + +function onClickApply() { + + // change network type, DHCP or static + + if (document.network.dhcp.value == "yes") { + + if (dhcp = "no") { + // disable network-state service and endable network service + downloadUrl(/cgi-bin/setservice.cgi?action=enabledhcp,null); + } + else { + // dhcp already running, restart service + downloadUrl(/cgi-bin/setservice.cgi?action=restartdhcp,null); + } + } + else { + + if (dhcp = "yes") { + // disable network service and enable network-static service + downloadUrl(/cgi-bin/setservice.cgi?action=enablestatic,null); + } + + // change network-static file variables + + if (document.network.ipaddress.value != ipaddress) { + var new_ipaddress = document.network.ipaddress.value; + var url = '/cgi-bin/setline.cgi?file=/etc/init.d/network-static&this=IPADDRESS=&that="' + new_ipaddress + '"'; + downloadUrl(url,null); + } + + if (document.network.netmask.value != netmask) { + var new_netmask = document.network.netmask.value; + var url = '/cgi-bin/setline.cgi?file=/etc/init.d/network-static&this=NETMASK=&that="' + new_netmask + '"'; + downloadUrl(url,null); + } + + if (document.network.gateway.value != gateway) { + var new_ = document.network.gateway.value; + var url = '/cgi-bin/setline.cgi?file=/etc/init.d/network-static&this=GATEWAY=&that="' + new_gateway + '"'; + downloadUrl(url,null); + } + + if (document.network.dns.value != dns) { + var new_ = document.network.dns.value; + var url = '/cgi-bin/setline.cgi?file=/etc/init.d/network-static&this=DNS=&that="' + new_dns + '"'; + downloadUrl(url,null); + } + + if (document.network.backdoor.value != backdoor) { + var new_ = document.network.backdoor.value; + var url = '/cgi-bin/setline.cgi?file=/etc/init.d/network-backup&this=BACKDOOR=&that="' + new_backdoor + '"'; + downloadUrl(url,null); + downloadUrl(/cgi-bin/setservice.cgi?action=restartbackup,null); + } + + // finally restart network-static service with new parameters + + downloadUrl(/cgi-bin/setservice.cgi?action=restartstatic,null); + } +} -- 2.25.1