network screen write side writtn, need to write new CGI
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 9 Mar 2011 23:45:41 +0000 (23:45 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 9 Mar 2011 23:45:41 +0000 (23:45 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@281 01035d8c-6547-0410-b346-abe4f91aad63

mini-asterisk-gui2/README.txt
mini-asterisk-gui2/cgi-bin/setline.cgi
mini-asterisk-gui2/cgi-bin/smokeping.cgi [deleted file]
mini-asterisk-gui2/network.html
mini-asterisk-gui2/network.js

index 43518a6b570d4531c325e6538452777c99d22096..711038ecbd74398e3d47392b7b32cf8f1c12d45c 100644 (file)
@@ -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
index 610b997ea79bf2d7483b4e17e495d6811af5ae46..eaaf47acb28f049110267d0ae03ee6979c854e4f 100755 (executable)
@@ -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
 Content-type: text/html
@@ -15,9 +20,19 @@ Content-type: text/html
 <body>
 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 <<EOF
 </body>
 </html>
diff --git a/mini-asterisk-gui2/cgi-bin/smokeping.cgi b/mini-asterisk-gui2/cgi-bin/smokeping.cgi
deleted file mode 100755 (executable)
index 6cac240..0000000
+++ /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<smokeping.cgi> going, you need a webserver which allows you to run
-cgi scripts. The system must be setup so that the B<smokeping.cgi> is
-allowed to write to the image caching area as defined in the config file.
-
-This script runs with normal perl. B<BUT> 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<rrdtool> 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 E<lt>tobi@oetiker.chE<gt>
-
-=cut
index bdb347be8177c27ee520130ccd0691c103003e3e..7275ed3423a3ad236a5d8f9347e5b170a458218a 100644 (file)
@@ -30,8 +30,8 @@
       <table align="center" width=600 border=0>
         <tr><td colspan="2" align="left" valign="top"><h2>Network</h2></td></tr>
         <tr>
-          <td><input type="radio" name="static" value="no" onClick="doStatic()">Static</td>
-          <td><input type="radio" name="dhcp" value="yes" onClick="doDHCP()">DHCP</td>
+          <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" onBlur="isIP(this)"></td></tr>
         <tr><td>Netmask:</td><td><input type="text" name="netmask" onBlur="isIP(this)"></td></tr>
          <td>Internet Connection:</td>
          <td><div id="internet"></div></td>
         </tr>
-        <tr><td><input type="submit" value="Apply"></td></tr>
+        <tr><td></td><td><input type="button" style="width:20%" value="Apply" onClick="onClickApply()"></td></tr>
       </table>
     </form>
-
   </tr>
 
   </table>
index f1a2ed9ae378ee584bc7b2f903e94db7779fd8a1..bcb683cd3e6f7c4403573a8e5b2afac84ec97bfc 100644 (file)
@@ -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);
+    }
+}