From 096843fcfe0235f71fb61e876d2f1a91b6c9d7c3 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Thu, 4 Feb 2010 01:31:14 +0000 Subject: [PATCH] better voip line design, handles incoming VOIP calls git-svn-id: https://svn.code.sf.net/p/freetel/code@139 01035d8c-6547-0410-b346-abe4f91aad63 --- mini-asterisk-gui/Makefile | 2 +- mini-asterisk-gui/cgi-bin/set_voiplines.pl | 31 +++++++++++----------- mini-asterisk-gui/cgi-bin/set_voiplines.sh | 8 +++--- mini-asterisk-gui/cgi-bin/voiplines.js | 1 - mini-asterisk-gui/cgi-bin/voiplines.pl | 23 +++++----------- mini-asterisk-gui/etc/asterisk/sip.conf | 3 +-- 6 files changed, 29 insertions(+), 39 deletions(-) diff --git a/mini-asterisk-gui/Makefile b/mini-asterisk-gui/Makefile index 24703e5a..7e9d0a07 100644 --- a/mini-asterisk-gui/Makefile +++ b/mini-asterisk-gui/Makefile @@ -14,7 +14,7 @@ # usage: make HOST=test.machine.ip static test: - rcp cgi-bin/*.html cgi-bin/*.sh cgi-bin/*.pl cgi-bin/*.js cgi-bin/*.css \ + scp cgi-bin/*.html cgi-bin/*.sh cgi-bin/*.pl cgi-bin/*.js cgi-bin/*.css \ cgi-bin/*.png root@$(HOST):/www scp etc/asterisk/*.conf root@$(HOST):/etc/asterisk diff --git a/mini-asterisk-gui/cgi-bin/set_voiplines.pl b/mini-asterisk-gui/cgi-bin/set_voiplines.pl index 2cee2e13..114b7b06 100644 --- a/mini-asterisk-gui/cgi-bin/set_voiplines.pl +++ b/mini-asterisk-gui/cgi-bin/set_voiplines.pl @@ -7,7 +7,7 @@ $user = $ARGV[0]; $pass = $ARGV[1]; $host = $ARGV[2]; -$stanza_new = $ARGV[3]; +$provider_new = $ARGV[3]; # We need to slurp up the mini asterisk provider and spit them # back out. All must be commented out except for the one that @@ -29,24 +29,23 @@ while () { # look for commented or uncommented mini asterisk provider stanza - if (/\[(.*)\] .* mini-asterisk/) { + if (/\[(.*)\].* \"(.*)\" mini-asterisk/) { $stanza = $1; + $provider = $2; } if ($stanza eq "") { # we are not in an mini-asterisk provider stanza - if (/;*register => (\S*)@(\S*).*;.*(mini-asterisk.*)/) { - # an mini-asterisk register line + # however we may hit a mini-asterisk register line here - #print "XX stanza_new='$stanza_new' '$1' '$2' '$3'\n"; + if (/.*register => (\S*)@(\S*).*;.*(mini-asterisk.*)/) { + # the mini-asterisk register line, not only one register supported + # at the moment (one VOIP line) + + #print "XX provider_new='$provider_new' '$1' '$2' '$3'\n"; - if ($2 eq $stanza_new) { - print "register => $user\@$stanza_new; $3\n"; - } - else { - print ";register => $1\@$2 ; $3\n"; - } + print "register => $user\@$user/$user; $3\n"; } else { # OK so this is a regular sip.conf line, just echo to stdout @@ -60,14 +59,16 @@ while () { $_ =~ s/^\;//; - if ($stanza eq $stanza_new) { + if ($provider eq $provider_new) { # this stanza should be uncommented - if (/^user=/) { - print "user=$user\n"; + if (/\[.*\].* \".*\" mini-asterisk/) { + # rename stanza name to user name + # this is required to make incoming calls work + print "[$user] ; \"$provider\" mini-asterisk do not remove this comment\n"; } - if (/^username=/) { + elsif (/^username=/) { print "username=$user\n"; } elsif (/^fromuser=/) { diff --git a/mini-asterisk-gui/cgi-bin/set_voiplines.sh b/mini-asterisk-gui/cgi-bin/set_voiplines.sh index 18c339df..1afe1ec3 100644 --- a/mini-asterisk-gui/cgi-bin/set_voiplines.sh +++ b/mini-asterisk-gui/cgi-bin/set_voiplines.sh @@ -19,18 +19,18 @@ 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"` -stanza=`echo "$QUERY_STRING" | grep -oe "stanza=[^&?]*" | sed -n "s/stanza=//p"` +provider=`echo "$QUERY_STRING" | grep -oe "provider=[^&?]*" | sed -n "s/provider=//p"` # create new sip.conf with selected provider uncommented -echo "set_voiplines.sh" $user $pass $host $stanza >> /tmp/log.txt -perl set_voiplines.pl $user $pass $host $stanza > /etc/asterisk/sip.conf.new +echo "set_voiplines.sh" $user $pass $host $provider >> /tmp/log.txt +perl 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 # modify extensions.conf for new provider -sed -i "s#_1.,1,Dial(.*)#_1.,1,Dial(SIP/$stanza/\${EXTEN:1})#" /etc/asterisk/extensions.conf +sed -i "s#_1.,1,Dial(.*)#_1.,1,Dial(SIP/$user/\${EXTEN:1})#" /etc/asterisk/extensions.conf asterisk -rx "dialplan reload" 2>/dev/null 1 > /dev/null # get asterisk to load changes diff --git a/mini-asterisk-gui/cgi-bin/voiplines.js b/mini-asterisk-gui/cgi-bin/voiplines.js index 083838af..12201255 100644 --- a/mini-asterisk-gui/cgi-bin/voiplines.js +++ b/mini-asterisk-gui/cgi-bin/voiplines.js @@ -3,5 +3,4 @@ function changeProvider() { $('user').value = users[provider]; $('pass').value = passwords[provider]; $('host').value = hosts[provider]; - $('stanza').value = stanzas[provider]; } diff --git a/mini-asterisk-gui/cgi-bin/voiplines.pl b/mini-asterisk-gui/cgi-bin/voiplines.pl index d8ccdca8..c910fb63 100644 --- a/mini-asterisk-gui/cgi-bin/voiplines.pl +++ b/mini-asterisk-gui/cgi-bin/voiplines.pl @@ -10,7 +10,6 @@ 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 @@ -27,11 +26,10 @@ while () { # currently disabled mini-asterisk provider - if (/^;\[(.*)\].* \"(.*)\" mini-asterisk/) { - push (@providers, $2); - $provider = $2; - $stanza{$2} = $1; - #print "'$1' '$2'\n"; + if (/^;\[.*\].* \"(.*)\" mini-asterisk/) { + push (@providers, $1); + $provider = $1; + #print "'$1'\n"; } # current mini-asterisk provider @@ -40,16 +38,13 @@ while () { push (@providers, $2); $provider = $2; $provider_current = $2; - $stanza{$2} = $1; + $stanza_current = $1; #print "'$1' '$2'\n"; } if ($provider ne "") { #print $_; - if (/^;*user=(.*)/) { - $user{$provider} = $1; - } if (/^;*username=(.*)/) { $user{$provider} = $1; } @@ -93,7 +88,6 @@ foreach (@providers) { print "hosts[\'$_\'] = \'$host{$_}\';\n"; print "users[\'$_\'] = \'$user{$_}\';\n"; print "passwords[\'$_\'] = \'$pass{$_}\';\n"; - print "stanzas[\'$_\'] = \'$stanza{$_}\';\n"; } print "\n"; @@ -121,9 +115,9 @@ print "User:Password:\n"; print "Host:\n"; -#print "\nXXX $provider_current $stanza{$provider_current} $voip{$stanza{$provider_current}}\n"; +#print "\nXXX $provider_current $stanza_current} $voip{$stanza_current}\n"; -if ($voip{$stanza{$provider_current}} eq "Registered") { +if ($voip{$stanza_current} eq "Registered") { $icon = "\"OK\""; } else { @@ -131,6 +125,3 @@ else { } print "Voip Line Status:$icon\n"; -# hidden field to pass stanza with form - -print ""; diff --git a/mini-asterisk-gui/etc/asterisk/sip.conf b/mini-asterisk-gui/etc/asterisk/sip.conf index ee3e1046..4e8e4cc2 100644 --- a/mini-asterisk-gui/etc/asterisk/sip.conf +++ b/mini-asterisk-gui/etc/asterisk/sip.conf @@ -153,8 +153,7 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls ; register mini-asterisk voip line providers here -register => user@generic ; mini-asterisk - do not change this comment -;register => user@oeg ; mini-asterisk - do not change this comment +register => user@user ; mini-asterisk - do not change this comment ;----------------------------------------- NAT SUPPORT ------------------------ ; The externip, externhost and localnet settings are used if you use Asterisk -- 2.25.1