register => in sip.conf entries now being edited sucessfully
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 14 Jan 2010 23:12:35 +0000 (23:12 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 14 Jan 2010 23:12:35 +0000 (23:12 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@112 01035d8c-6547-0410-b346-abe4f91aad63

easy-asterisk-gui/set_voiplines.pl
easy-asterisk-gui/set_voiplines.sh
easy-asterisk-gui/sip.conf
easy-asterisk-gui/voiplines.js
easy-asterisk-gui/voiplines.pl

index b38112bf1b33d20ea6bb26a4861b3e9b8f97fe78..30a76be520692630b8c6fc4c910afea8d41291a4 100755 (executable)
@@ -7,7 +7,7 @@
 $user = $ARGV[0];
 $pass = $ARGV[1];
 $host = $ARGV[2];
-$provider_new = $ARGV[3];
+$stanza_new = $ARGV[3];
 
 # We need to slurp up the easy asterisk provider and spit them
 # back out.  All must be commented out except for the one that
@@ -20,27 +20,47 @@ while (<SIP>) {
 
     # start of any new 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
+    # keyword. This allows non-easy asterisk SIP stanzas to be
     # included in sip.conf
 
     if (/\[/) {
-       $provider = ""; 
+       $stanza = "";   
     }
 
     # look for commented or uncommented easy asterisk provider stanza
 
-    if (/\[.* \"(.*)\" easy-asterisk/) {
-       $provider = $1;
+    if (/\[(.*)\] .* easy-asterisk/) {
+       $stanza = $1;
     }
 
-    if ($provider ne "") {
+    if ($stanza eq "") {
+       # we are not in an easy-asterisk provider stanza
+       
+       if (/;*register => (\S*)@(\S*).*;.*(easy-asterisk.*)/) {
+           # an easy-asterisk register line
+
+           #print "XX stanza_new='$stanza_new' '$1' '$2' '$3'\n";
+                   
+           if ($2 eq $stanza_new) {
+               print "register => $user\@$stanza_new; $3\n";
+           }
+           else {
+               print ";register => $1\@$2 ; $3\n";
+           }
+       }
+       else {
+           # OK so this is a regular sip.conf line, just echo to stdout
+           print $_;
+       }
+    }
+    else {
        # OK, we are in an easy-asterisk stanza
 
        # strip off any leading ";"
 
        $_ =~ s/^\;//;
        
-       if ($provider eq $provider_new) {
+       if ($stanza eq $stanza_new) {
 
            # this stanza should be uncommented
 
@@ -61,6 +81,7 @@ while (<SIP>) {
            }
        }
        else {
+           # comment out unused easy-asterisk stanzas
            print ";$_";
        }
     }
index 968a387017e63cd0ac69a01386171684a179de39..696d4f40eccfd9e41a601a2aab821924ef8f33e7 100644 (file)
@@ -19,11 +19,17 @@ 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"`
+stanza=`echo "$QUERY_STRING" | grep -oe "stanza=[^&?]*" | sed -n "s/stanza=//p"`
 
-./set_voiplines.pl $user $pass $host $provider > /etc/asterisk/sip.conf.new
+# create new sip.conf with selected provider uncommented
+
+echo "set_voiplines.sh" $user $pass $host $stanza >> /tmp/log.txt
+./set_voiplines.pl $user $pass $host $stanza > /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
+
+# get asterisk to load changes
+
 asterisk -rx "sip reload" 2>/dev/null 1 > /dev/null
 
 cat <<EOF
index c315f8673b337d8f8a4602cfa5a5d59e33ef9a25..ec78ce78f5d0169361cf0ca61d1d5f9eb3ac6ff5 100644 (file)
@@ -151,6 +151,11 @@ srvlookup=yes                      ; Enable DNS SRV lookups on outbound calls
                                ; Default is 0 tries, continue forever
 ;callevents=no                 ; generate manager events when sip ua performs events (e.g. hold)
 
+; register easy-asterisk voip line providers here
+
+;register => user@voip ; easy-asterisk - do not change this comment
+;register => user@oeg ; easy-asterisk - do not change this comment
+
 ;----------------------------------------- NAT SUPPORT ------------------------
 ; The externip, externhost and localnet settings are used if you use Asterisk
 ; behind a NAT device to communicate with services on the outside.
@@ -531,7 +536,7 @@ callerid=6018
 disallow=all
 allow=ulaw,g729
 
-; Pre-configured SIP trunks
+; Pre-configured easy-asterisk SIP trunks
 
 [voip] ; "Generic" easy-asterisk do not remove this comment
 type=friend
index 12201255d5ea005661dcff9aade7048eec9578d0..083838afa866487016a281c4fb982139b64a1523 100644 (file)
@@ -3,4 +3,5 @@ function changeProvider() {
        $('user').value = users[provider];
        $('pass').value = passwords[provider];
        $('host').value = hosts[provider];
+       $('stanza').value = stanzas[provider];
 }
index e2478e7d7318de70ef4c0797dbf05de8307430c8..1da1338de0a4d777053047fa83d910e831e3fed0 100755 (executable)
@@ -10,6 +10,7 @@
 open SIP, "/etc/asterisk/sip.conf";
 my $provider = ""; # current provider bring parsed in sip.conf
 my @providers=();  # list of all providers
+my %stanza = ();   # stanza name keyed on provider
 my %user = ();     # user keyed on provider
 my %pass = ();     # password keyed on provider
 my %host = ();     # host name keyed on provider
@@ -26,19 +27,21 @@ while (<SIP>) {
 
     # currently disabled easy-asterisk provider
 
-    if (/^;\[.* \"(.*)\" easy-asterisk/) {
-       push (@providers, $1);
-       $provider = $1;
-       #print "$1\n";  
+    if (/^;\[(.*)\].* \"(.*)\" easy-asterisk/) {
+       push (@providers, $2);
+       $provider = $2;
+       $stanza{$2} = $1;
+       #print "'$1' '$2'\n";   
     }
 
     # current easy-asterisk provider
 
-    if (/^\[.* \"(.*)\" easy-asterisk/) {
-       push (@providers, $1);
-       $provider = $1;
-       $provider_current = $1;
-       #print "$1\n";
+    if (/^\[(.*)\].* \"(.*)\" easy-asterisk/) {
+       push (@providers, $2);
+       $provider = $2;
+       $provider_current = $2;
+       $stanza{$2} = $1;
+       #print "'$1' '$2'\n";
     }
 
     if ($provider ne "") {
@@ -63,7 +66,7 @@ close SIP;
 # sipshowpeers.txt needs to be generated before calling this perl
 # script
 
-my %voip = (); # SIP trunks status keyed on sip.conf names 
+my %voip = (); # SIP trunks status keyed on sip.conf stanza names 
                # if no entry we can't see SIP trunk
 
 open SIP, "sipshowpeers.txt";
@@ -87,10 +90,12 @@ print "<script>\n";
 print "var hosts = new Array();\n";
 print "var users = new Array();\n";
 print "var passwords = new Array();\n";
+print "var stanzas = new Array();\n";
 foreach (@providers) {
     print "hosts[\'$_\'] = \'$host{$_}\';\n";
     print "users[\'$_\'] = \'$user{$_}\';\n";
     print "passwords[\'$_\'] = \'$pass{$_}\';\n";
+    print "stanzas[\'$_\'] = \'$stanza{$_}\';\n";
 }
 print "</script>\n";
 
@@ -111,10 +116,14 @@ print "</select></td></tr>\n";
 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") {
+if ($voip{$stanza{$provider_current}} eq "OK") {
     $icon = "<img src=\"tick.png\" alt=\"VOIP Line OK\" />";
 }
 else {
     $icon = "<img src=\"cross.png\" alt=\"VOIP Line OK\" />";
 }
 print "<tr><td>Voip Line Status:</td><td>$icon</td></tr>";
+
+# hidden field to pass stanza with form
+
+print "<tr><td><input type=\"hidden\" name=\"stanza\" id=\"stanza\" value=\"$stanza{$provider_current}\"></td></tr>";