From: drowe67 Date: Thu, 14 Jan 2010 23:12:35 +0000 (+0000) Subject: register => in sip.conf entries now being edited sucessfully X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=e85f262c70b0d6c6bc50524d05f00224fdd1354a;p=freetel-svn-tracking.git register => in sip.conf entries now being edited sucessfully git-svn-id: https://svn.code.sf.net/p/freetel/code@112 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/easy-asterisk-gui/set_voiplines.pl b/easy-asterisk-gui/set_voiplines.pl index b38112bf..30a76be5 100755 --- a/easy-asterisk-gui/set_voiplines.pl +++ b/easy-asterisk-gui/set_voiplines.pl @@ -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 () { # 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 () { } } else { + # comment out unused easy-asterisk stanzas print ";$_"; } } diff --git a/easy-asterisk-gui/set_voiplines.sh b/easy-asterisk-gui/set_voiplines.sh index 968a3870..696d4f40 100644 --- a/easy-asterisk-gui/set_voiplines.sh +++ b/easy-asterisk-gui/set_voiplines.sh @@ -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 < 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 diff --git a/easy-asterisk-gui/voiplines.js b/easy-asterisk-gui/voiplines.js index 12201255..083838af 100644 --- a/easy-asterisk-gui/voiplines.js +++ b/easy-asterisk-gui/voiplines.js @@ -3,4 +3,5 @@ function changeProvider() { $('user').value = users[provider]; $('pass').value = passwords[provider]; $('host').value = hosts[provider]; + $('stanza').value = stanzas[provider]; } diff --git a/easy-asterisk-gui/voiplines.pl b/easy-asterisk-gui/voiplines.pl index e2478e7d..1da1338d 100755 --- a/easy-asterisk-gui/voiplines.pl +++ b/easy-asterisk-gui/voiplines.pl @@ -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 () { # 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 "\n"; @@ -111,10 +116,14 @@ print "\n"; print "User:\n"; print "Password:"; print "Host:"; -if ($voip{"voip"} eq "OK") { +if ($voip{$stanza{$provider_current}} eq "OK") { $icon = "\"VOIP"; } else { $icon = "\"VOIP"; } print "Voip Line Status:$icon"; + +# hidden field to pass stanza with form + +print "";