saving voip lines OK
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 14 Jan 2010 09:34:20 +0000 (09:34 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 14 Jan 2010 09:34:20 +0000 (09:34 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@111 01035d8c-6547-0410-b346-abe4f91aad63

easy-asterisk-gui/set_voiplines.pl
easy-asterisk-gui/voiplines.pl

index 674be0033eeb32b2d57ae4fbcd5697d72218c02b..b38112bf1b33d20ea6bb26a4861b3e9b8f97fe78 100755 (executable)
@@ -7,57 +7,64 @@
 $user = $ARGV[0];
 $pass = $ARGV[1];
 $host = $ARGV[2];
-$provider = $ARGV[3];
+$provider_new = $ARGV[3];
 
-# slurp up voip trunk details --------------------------------
+# We need to slurp up the easy asterisk provider and spit them
+# back out.  All must be commented out except for the one that
+# is selected.  Hopefully non-easy asterisk content of sip.conf
+# won't be affected.
 
 open SIP, "/etc/asterisk/sip.conf";
-$state = "looking for easy-asterisk";
-
+$provider = "";
 while (<SIP>) { 
-    $next_state = $state;
 
-    if ($state eq "looking for easy-asterisk") {
-       
-       if (/[voip\]/) {
-           $next_state="inside [voip]";
-           #print "$state $next_state\n";
-       }
+    # 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
+    # included in sip.conf
 
-       print $_;
+    if (/\[/) {
+       $provider = ""; 
     }
 
-    if ($state eq "inside [voip]") {
+    # look for commented or uncommented easy asterisk provider stanza
 
-       if (/^\[/) {
-           $next_state = "finished";
-       }
-       if (/^;.*\[/) {
-           $next_state = "finished";
-       }
+    if (/\[.* \"(.*)\" easy-asterisk/) {
+       $provider = $1;
+    }
 
-       if (/^user=/) {
-           print "user=$user\n";
-       }
-       elsif (/^fromuser=/) {
-           print "fromuser=$user\n";
-       }
-       elsif (/^secret=/) {
-           print "secret=$pass\n";
-       }
-       elsif (/^host=/) {
-           print "host=$host\n";
+    if ($provider ne "") {
+       # OK, we are in an easy-asterisk stanza
+
+       # strip off any leading ";"
+
+       $_ =~ s/^\;//;
+       
+       if ($provider eq $provider_new) {
+
+           # this stanza should be uncommented
+
+           if (/^user=/) {
+               print "user=$user\n";
+           }
+           elsif (/^fromuser=/) {
+               print "fromuser=$user\n";
+           }
+           elsif (/^secret=/) {
+               print "secret=$pass\n";
+           }
+           elsif (/^host=/) {
+               print "host=$host\n";
+           }
+           else {
+               print $_;
+           }
        }
        else {
-           print $_;
+           print ";$_";
        }
     }
 
-    if ($state eq "finished") {
-       print $_;
-    }
-
-    $state = $next_state;
 }
 close SIP;
 
index 3c2dfd51ee76adc4d9d0d3c60c13f728736b2973..e2478e7d7318de70ef4c0797dbf05de8307430c8 100755 (executable)
@@ -20,7 +20,7 @@ while (<SIP>) {
     # back on below if it contains easy-asterisk keyword. This allows
     # non-easy asterisk SIP devices to be included in sip.conf
 
-    if (/^\[/) {
+    if (/\[/) {
        $provider = ""; 
     }