working on voip lines screen
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 12 Jan 2010 00:14:47 +0000 (00:14 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 12 Jan 2010 00:14:47 +0000 (00:14 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@107 01035d8c-6547-0410-b346-abe4f91aad63

easy-asterisk-gui/Makefile
easy-asterisk-gui/set_ring.sh
easy-asterisk-gui/set_voipline.sh [new file with mode: 0644]
easy-asterisk-gui/set_voiplines.pl [new file with mode: 0755]
easy-asterisk-gui/voipline.sh [deleted file]
easy-asterisk-gui/voiplines.pl
easy-asterisk-gui/voiplines.sh [new file with mode: 0644]

index ed9f60d02edf2c434ad760a6e40927d84d95569f..386bfe52c6709f4074d8acfbb62adaaccbfbe04e 100644 (file)
@@ -8,5 +8,5 @@
 #        make TESTIP=boris test
 
 test:
-       rcp voiplines.sh voiplines.pl set_ring.sh prototype.js admin.sh index.html faq.sh faq.html about.sh at-530.html ipphones.pl ipphones.sh ipphones.js voipline.jpg anphone.png phoneline.jpg ipphone.png phones.pl tooltips.html phones.sh phones.js tick.png cross.png banner.html menu.html check_loggedin.sh logout.sh login.sh network.sh network.js set_network.sh tooltip.js tooltip.css root@$(TESTIP):/www
+       rcp set_voiplines.pl voiplines.sh voiplines.pl set_ring.sh prototype.js admin.sh index.html faq.sh faq.html about.sh at-530.html ipphones.pl ipphones.sh ipphones.js voipline.jpg anphone.png phoneline.jpg ipphone.png phones.pl tooltips.html phones.sh phones.js tick.png cross.png banner.html menu.html check_loggedin.sh logout.sh login.sh network.sh network.js set_network.sh tooltip.js tooltip.css root@$(TESTIP):/www
        rcp sip.conf extensions.conf root@$(TESTIP):/etc/asterisk
index 17d928d82d1002a57472719cceddacf9f4b91495..c7b559c496c885e3d02c7ac6900957e7afa74e4b 100644 (file)
@@ -12,7 +12,7 @@ if [ $? -eq 1 ]; then
     echo '<meta http-equiv="REFRESH" content="0;url=http:login.sh">'
     echo "</head>"
     echo "</html>"
-#    exit
+    exit
 fi
 
 # extract extensions to ring and reload extensions.conf
diff --git a/easy-asterisk-gui/set_voipline.sh b/easy-asterisk-gui/set_voipline.sh
new file mode 100644 (file)
index 0000000..21b7844
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+# set_voipline.sh
+# # David Rowe 12 Jan 2010
+#
+# CGI to set voip line parameters in sip.conf.
+
+cat <<EOF
+<html>
+<head>
+<title>set_network.sh</title>
+<meta http-equiv="REFRESH" content="0;url=http:network.sh">
+<body>
+Please wait a few seconds.....
+</body>
+</head>
+</html>
+EOF
+
+user=`echo "$QUERY_STRING" | grep -oe "user=[^&?]*" | sed -n "s/user=//p"`
+pass=`echo "$QUERY_STRING" | grep -oe "pass=[^&?]*" | sed -n "s/pass=//p"`
+host=`echo "$QUERY_STRING" | grep -oe "host=[^&?]*" | sed -n "s/host=//p"`
+
+./set_voipline.pl $user $pass $host > /etc/asterisk/sip.conf
+
+cat <<EOF
+<html>
+<head>
+<title>set_voiplines.sh</title>
+<meta http-equiv="REFRESH" content="0;url=http:voiplines.sh">
+<body>
+Please wait a few seconds.....
+</body>
+</head>
+</html>
+EOF
\ No newline at end of file
diff --git a/easy-asterisk-gui/set_voiplines.pl b/easy-asterisk-gui/set_voiplines.pl
new file mode 100755 (executable)
index 0000000..44e9f15
--- /dev/null
@@ -0,0 +1,61 @@
+#!/sbin/microperl
+# set_voiplines.pl
+# David Rowe 12 Jan 2010
+#
+# Replaces fields in sip.conf, outputs new sip.conf contents to stdout
+
+$user = $ARGV[0];
+$pass = $ARGV[1];
+$host = $ARGV[2];
+
+# slurp up voip trunk details --------------------------------
+
+open SIP, "/etc/asterisk/sip.conf";
+$state = "looking for [voip]";
+
+while (<SIP>) { 
+    $next_state = $state;
+
+    if ($state eq "looking for [voip]") {
+       
+       if (/^\[voip\]/) {
+           $next_state="inside [voip]";
+           #print "$state $next_state\n";
+       }
+
+       print $_;
+    }
+
+    if ($state eq "inside [voip]") {
+
+       if (/^\[/) {
+           $next_state = "finished";
+       }
+
+       if (/user=/) {
+           print "user=$user\n";
+       }
+       elsif (/secret=/) {
+           print "secret=$pass\n";
+       }
+       elsif (/host=/) {
+           print "host=$host\n";
+       }
+       else {
+           print $_;
+       }
+    }
+
+    if ($state eq "finished") {
+       print $_;
+    }
+
+    $state = $next_state;
+}
+close SIP;
+
+# generate form fields -------------------------------------------
+
+print "<tr><td>User:</td><td><input type=\"text\" name=\"user\" value=\"$user\"></td></tr>\n";
+print "<tr><td>Password:</td><td><input type=\"password\" name=\"pass\" value=\"$pass\"></td></tr>";
+print "<tr><td>Host:</td><td><input type=\"text\" name=\"host\" value=\"$host\"></td></tr>";
diff --git a/easy-asterisk-gui/voipline.sh b/easy-asterisk-gui/voipline.sh
deleted file mode 100644 (file)
index 2b2df31..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-# voipline.sh
-# David Rowe 12 Jan 2010
-# VOIP Line screen for Easy Asterisk GUI
-
-# check we are logged in
-
-echo $HTTP_COOKIE | grep "loggedin" > /dev/null
-if [ $? -eq 1 ]; then
-    echo "<html>"
-    echo "<head>"
-    echo '<meta http-equiv="REFRESH" content="0;url=http:login.sh">'
-    echo "</head>"
-    echo "</html>"
-    exit
-fi
-
-# Construct the web page -------------------------------
-
-cat <<EOF
-<script src="prototype.js"></script>
-<link href="astman.css" media="all" rel="Stylesheet" type="text/css" />
-<script type="text/javascript" src="tooltip.js"></script>
-<link rel="stylesheet" href="tooltip.css" type="text/css" />
-EOF
-
-cat << EOF
-<html>
-<title>Easy Asterisk - VOIP Line</title>
-EOF
-
-cat tooltips.html
-echo '<table align="center" width=800>'
-cat banner.html
-echo "    <tr>"
-cat menu.html    
-cat <<EOF
-
-    <td valign="top">
-
-    <table align="right" width=600>
-      <tr><td>&nbsp</td></tr>
-      <form action="voipline.sh" method="get">
-      <tr><td align="left" valign="top"><h2>VOIP Line</h2></td></tr>
-
-      <tr><td>&nbsp</td></tr>
-EOF
-./voipline.pl
-
-cat <<EOF
-      <tr><td>&nbsp</td></tr>
-      <tr><td><input type="submit" value="OK"></td></tr>
-
-      </form>
-
-    </table>
-    </form>
-
-    </td>
-
-    </tr>
-
-</table>
-</body>
-</html>
-EOF
-
index bed92342a22bb8c5a155496f6dcc5d5030c3c216..bbb1ca66b55cccf59288716403e5212e56382fea 100755 (executable)
@@ -10,17 +10,22 @@ open SIP, "/etc/asterisk/sip.conf";
 $state = "looking for [voip]";
 
 while (<SIP>) { 
+    $next_state = $state;
+
     if ($state eq "looking for [voip]") {
 
        if (/^\[voip\]/) {
-           $state="inside [voip]";
+           $next_state="inside [voip]";
+           #print "$state $next_state\n";
        }
 
     }
 
-    if (($state eq "inside [voip]") {
+    if ($state eq "inside [voip]") {
+       #print $_;
        if (/^\[/) {
-           $state = "finished";
+           $next_state = "finished";
+           #print "$next_state\n";
        }
 
        if (/user=(.*)/) {
@@ -33,11 +38,13 @@ while (<SIP>) {
            $host = $1;
        }
     }
+
+    $state = $next_state;
 }
 close SIP;
 
-# generate form ---------------------------------------------
+# generate form fields -------------------------------------------
 
 print "<tr><td>User:</td><td><input type=\"text\" name=\"user\" value=\"$user\"></td></tr>\n";
-print "<tr><td>Password:</td><td><input type=\"password\" name=\"pass\" value=\"$pass"></td></tr>";
-print "<tr><td>Host:</td><td><input type=\"text\" name=\"host\" value=\"$host"></td></tr>";
+print "<tr><td>Password:</td><td><input type=\"password\" name=\"pass\" value=\"$pass\"></td></tr>";
+print "<tr><td>Host:</td><td><input type=\"text\" name=\"host\" value=\"$host\"></td></tr>";
diff --git a/easy-asterisk-gui/voiplines.sh b/easy-asterisk-gui/voiplines.sh
new file mode 100644 (file)
index 0000000..0bf0bcb
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/sh
+# voiplines.sh
+# David Rowe 12 Jan 2010
+# VOIP Line screen for Easy Asterisk GUI
+
+# check we are logged in
+
+echo $HTTP_COOKIE | grep "loggedin" > /dev/null
+if [ $? -eq 1 ]; then
+    echo "<html>"
+    echo "<head>"
+    echo '<meta http-equiv="REFRESH" content="0;url=http:login.sh">'
+    echo "</head>"
+    echo "</html>"
+    exit
+fi
+
+# Construct the web page -------------------------------
+
+cat <<EOF
+<script src="prototype.js"></script>
+<link href="astman.css" media="all" rel="Stylesheet" type="text/css" />
+<script type="text/javascript" src="tooltip.js"></script>
+<link rel="stylesheet" href="tooltip.css" type="text/css" />
+EOF
+
+cat << EOF
+<html>
+<title>Easy Asterisk - VOIP Line</title>
+EOF
+
+cat tooltips.html
+echo '<table align="center" width=800>'
+cat banner.html
+echo "    <tr>"
+cat menu.html    
+cat <<EOF
+
+    <td valign="top">
+
+    <table align="right" width=600>
+      <tr><td>&nbsp</td></tr>
+      <form action="set_voiplines.sh" method="get">
+      <tr><td align="left" valign="top"><h2>VOIP Line</h2></td></tr>
+
+      <tr><td>&nbsp</td></tr>
+EOF
+
+./voiplines.pl
+
+cat <<EOF
+      <tr><td>&nbsp</td></tr>
+      <tr><td><input type="submit" value="OK"></td></tr>
+
+      </form>
+
+    </table>
+    </form>
+
+    </td>
+
+    </tr>
+
+</table>
+</body>
+</html>
+EOF
+