pull down menu feature working with two provider options, fills user/pass/host fields...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 14 Jan 2010 08:50:29 +0000 (08:50 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 14 Jan 2010 08:50:29 +0000 (08:50 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@110 01035d8c-6547-0410-b346-abe4f91aad63

easy-asterisk-gui/Makefile
easy-asterisk-gui/set_voiplines.pl
easy-asterisk-gui/set_voiplines.sh
easy-asterisk-gui/voiplines.js [new file with mode: 0644]
easy-asterisk-gui/voiplines.pl
easy-asterisk-gui/voiplines.sh

index e5bff4e8f4c7edec5c2e8fed8b181ffb16704b9d..bc6998afd38162ef4f12858a42afdea599dceadc 100644 (file)
@@ -8,5 +8,5 @@
 #        make TESTIP=boris test
 
 test:
-       rcp set_voiplines.pl set_voiplines.sh 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 voiplines.js set_voiplines.pl set_voiplines.sh 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 805751189b0ddf8102d26c97d93409c18a67fe15..674be0033eeb32b2d57ae4fbcd5697d72218c02b 100755 (executable)
@@ -7,18 +7,19 @@
 $user = $ARGV[0];
 $pass = $ARGV[1];
 $host = $ARGV[2];
+$provider = $ARGV[3];
 
 # slurp up voip trunk details --------------------------------
 
 open SIP, "/etc/asterisk/sip.conf";
-$state = "looking for [voip]";
+$state = "looking for easy-asterisk";
 
 while (<SIP>) { 
     $next_state = $state;
 
-    if ($state eq "looking for [voip]") {
+    if ($state eq "looking for easy-asterisk") {
        
-       if (/^\[voip\]/) {
+       if (/[voip\]/) {
            $next_state="inside [voip]";
            #print "$state $next_state\n";
        }
index 4820b789b1fa2ff4284b5356f7ea83c7345c016f..968a387017e63cd0ac69a01386171684a179de39 100644 (file)
@@ -19,8 +19,9 @@ fi
 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"`
+provider=`echo "$QUERY_STRING" | grep -oe "provider=[^&?]*" | sed -n "s/provider=//p"`
 
-./set_voiplines.pl $user $pass $host > /etc/asterisk/sip.conf.new
+./set_voiplines.pl $user $pass $host $provider > /etc/asterisk/sip.conf.new
 mv /etc/asterisk/sip.conf /etc/asterisk/sip.conf.bak
 mv /etc/asterisk/sip.conf.new /etc/asterisk/sip.conf
 asterisk -rx "sip reload" 2>/dev/null 1 > /dev/null
diff --git a/easy-asterisk-gui/voiplines.js b/easy-asterisk-gui/voiplines.js
new file mode 100644 (file)
index 0000000..1220125
--- /dev/null
@@ -0,0 +1,6 @@
+function changeProvider() {
+       provider = $('provider').value;
+       $('user').value = users[provider];
+       $('pass').value = passwords[provider];
+       $('host').value = hosts[provider];
+}
index feeac43e42108014dd3f512570cc2fe55a0ea3ae..3c2dfd51ee76adc4d9d0d3c60c13f728736b2973 100755 (executable)
@@ -2,43 +2,56 @@
 # voiplines.pl
 # David Rowe 12 Jan 2010
 #
-# Text processing for the ipphones screen
+# Text processing for the voiplines screen
 
-# slurp up voip trunk details --------------------------------
+# slurp up list of possible voip line providers --------------------------------
+# one of these will be currently selected
 
 open SIP, "/etc/asterisk/sip.conf";
-$state = "looking for [voip]";
+my $provider = ""; # current provider bring parsed in sip.conf
+my @providers=();  # list of all providers
+my %user = ();     # user keyed on provider
+my %pass = ();     # password keyed on provider
+my %host = ();     # host name keyed on provider
 
 while (<SIP>) { 
-    $next_state = $state;
 
-    if ($state eq "looking for [voip]") {
+    # start of any stanza switches off parsing.  It may get switched
+    # back on below if it contains easy-asterisk keyword. This allows
+    # non-easy asterisk SIP devices to be included in sip.conf
 
-       if (/^\[voip\]/) {
-           $next_state="inside [voip]";
-           #print "$state $next_state\n";
-       }
+    if (/^\[/) {
+       $provider = ""; 
+    }
+
+    # currently disabled easy-asterisk provider
+
+    if (/^;\[.* \"(.*)\" easy-asterisk/) {
+       push (@providers, $1);
+       $provider = $1;
+       #print "$1\n";  
+    }
+
+    # current easy-asterisk provider
 
+    if (/^\[.* \"(.*)\" easy-asterisk/) {
+       push (@providers, $1);
+       $provider = $1;
+       $provider_current = $1;
+       #print "$1\n";
     }
 
-    if ($state eq "inside [voip]") {
+    if ($provider ne "") {
        #print $_;
-       if (/^\[/) {
-           $next_state = "finished";
-           #print "$next_state\n";
-       }
-       if (/^;.*\[/) { # commented out next stanza
-           $next_state = "finished";
-       }
 
-       if (/^user=(.*)/) {
-           $user = $1;
+       if (/^;*user=(.*)/) {
+           $user{$provider} = $1;
        }
-       if (/^secret=(.*)/) {
-           $pass = $1;
+       if (/^;*secret=(.*)/) {
+           $pass{$provider} = $1;
        }
-       if (/^host=(.*)/) {
-           $host = $1;
+       if (/^;*host=(.*)/) {
+           $host{$provider} = $1;
        }
     }
 
@@ -46,26 +59,9 @@ while (<SIP>) {
 }
 close SIP;
 
-# Determine list of possible VOIP lines to use
-
-open SIP, "/etc/asterisk/sip.conf";
-
-@voiplines=();
-
-while (<SIP>) { 
-    if (/^;\[.* \"(.*)\" easy-asterisk/) {
-       push (@voiplines, $1);
-       #print "$1\n";
-    }
-    if (/^\[.* \"(.*)\" easy-asterisk/) {
-       push (@voiplines, $1);
-       $voipline_current = $1;
-       #print "$1\n";
-    }
-}
-close SIP;
-
-# Determine if Asterisk can see our Voip Line (SIP trunk) 
+# Determine if Asterisk can see current voip line (SIP trunk) 
+# sipshowpeers.txt needs to be generated before calling this perl
+# script
 
 my %voip = (); # SIP trunks status keyed on sip.conf names 
                # if no entry we can't see SIP trunk
@@ -85,12 +81,25 @@ while (<SIP>) {
 
 close SIP;
 
+# javascript to handle changing providers
+
+print "<script>\n";
+print "var hosts = new Array();\n";
+print "var users = new Array();\n";
+print "var passwords = new Array();\n";
+foreach (@providers) {
+    print "hosts[\'$_\'] = \'$host{$_}\';\n";
+    print "users[\'$_\'] = \'$user{$_}\';\n";
+    print "passwords[\'$_\'] = \'$pass{$_}\';\n";
+}
+print "</script>\n";
+
 # generate form fields -------------------------------------------
 
 print "<tr><td>Provider</td><td>\n";
-print "<select name=\"voiplines\">\n";
-foreach (@voiplines) {
-    if ($_ eq $voipline_current) {
+print "<select name=\"provider\" id=\"provider\" onchange=\"changeProvider()\">\n";
+foreach (@providers) {
+    if ($_ eq $provider_current) {
        print "<option selected=\"yes\">$_</option>\n";
     }
     else {
@@ -99,9 +108,9 @@ foreach (@voiplines) {
 }
 print "</select></td></tr>\n";
 
-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>User:</td><td><input type=\"text\" name=\"user\" id=\"user\" value=\"$user{$provider_current}\"></td></tr>\n";
+print "<tr><td>Password:</td><td><input type=\"password\" name=\"pass\" id=\"pass\" value=\"$pass{$provider_current}\"></td></tr>";
+print "<tr><td>Host:</td><td><input type=\"text\" name=\"host\" id=\"host\" value=\"$host{$provider_current}\"></td></tr>";
 if ($voip{"voip"} eq "OK") {
     $icon = "<img src=\"tick.png\" alt=\"VOIP Line OK\" />";
 }
index dddb8bf154c9eccbfd50ca51eb5a07fa1e75b659..6891eac98f4a1bb0f967949d1e5c673e1ff0af37 100644 (file)
@@ -26,9 +26,13 @@ cat <<EOF
 <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" />
+<script>
 EOF
 
+cat voiplines.js
+
 cat << EOF
+</script>
 <html>
 <title>Easy Asterisk - VOIP Line</title>
 EOF