From: drowe67 Date: Thu, 14 Jan 2010 08:50:29 +0000 (+0000) Subject: pull down menu feature working with two provider options, fills user/pass/host fields... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=f0fa035d514d911b9c612794cab286c25bd7f8a8;p=freetel-svn-tracking.git pull down menu feature working with two provider options, fills user/pass/host fields automatically git-svn-id: https://svn.code.sf.net/p/freetel/code@110 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/easy-asterisk-gui/Makefile b/easy-asterisk-gui/Makefile index e5bff4e8..bc6998af 100644 --- a/easy-asterisk-gui/Makefile +++ b/easy-asterisk-gui/Makefile @@ -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 diff --git a/easy-asterisk-gui/set_voiplines.pl b/easy-asterisk-gui/set_voiplines.pl index 80575118..674be003 100755 --- a/easy-asterisk-gui/set_voiplines.pl +++ b/easy-asterisk-gui/set_voiplines.pl @@ -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 () { $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"; } diff --git a/easy-asterisk-gui/set_voiplines.sh b/easy-asterisk-gui/set_voiplines.sh index 4820b789..968a3870 100644 --- a/easy-asterisk-gui/set_voiplines.sh +++ b/easy-asterisk-gui/set_voiplines.sh @@ -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 index 00000000..12201255 --- /dev/null +++ b/easy-asterisk-gui/voiplines.js @@ -0,0 +1,6 @@ +function changeProvider() { + provider = $('provider').value; + $('user').value = users[provider]; + $('pass').value = passwords[provider]; + $('host').value = hosts[provider]; +} diff --git a/easy-asterisk-gui/voiplines.pl b/easy-asterisk-gui/voiplines.pl index feeac43e..3c2dfd51 100755 --- a/easy-asterisk-gui/voiplines.pl +++ b/easy-asterisk-gui/voiplines.pl @@ -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 () { - $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 () { } close SIP; -# Determine list of possible VOIP lines to use - -open SIP, "/etc/asterisk/sip.conf"; - -@voiplines=(); - -while () { - 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 () { close SIP; +# javascript to handle changing providers + +print "\n"; + # generate form fields ------------------------------------------- print "Provider\n"; -print "\n"; +foreach (@providers) { + if ($_ eq $provider_current) { print "\n"; } else { @@ -99,9 +108,9 @@ foreach (@voiplines) { } print "\n"; -print "User:\n"; -print "Password:"; -print "Host:"; +print "User:\n"; +print "Password:"; +print "Host:"; if ($voip{"voip"} eq "OK") { $icon = "\"VOIP"; } diff --git a/easy-asterisk-gui/voiplines.sh b/easy-asterisk-gui/voiplines.sh index dddb8bf1..6891eac9 100644 --- a/easy-asterisk-gui/voiplines.sh +++ b/easy-asterisk-gui/voiplines.sh @@ -26,9 +26,13 @@ cat < + Easy Asterisk - VOIP Line EOF