From e0e683d2e6ef6e8d6577e646c26d7f8b508e1568 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Tue, 12 Jan 2010 00:14:47 +0000 Subject: [PATCH] working on voip lines screen git-svn-id: https://svn.code.sf.net/p/freetel/code@107 01035d8c-6547-0410-b346-abe4f91aad63 --- easy-asterisk-gui/Makefile | 2 +- easy-asterisk-gui/set_ring.sh | 2 +- easy-asterisk-gui/set_voipline.sh | 35 +++++++++++ easy-asterisk-gui/set_voiplines.pl | 61 +++++++++++++++++++ easy-asterisk-gui/voiplines.pl | 19 ++++-- .../{voipline.sh => voiplines.sh} | 7 ++- 6 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 easy-asterisk-gui/set_voipline.sh create mode 100755 easy-asterisk-gui/set_voiplines.pl rename easy-asterisk-gui/{voipline.sh => voiplines.sh} (93%) diff --git a/easy-asterisk-gui/Makefile b/easy-asterisk-gui/Makefile index ed9f60d0..386bfe52 100644 --- a/easy-asterisk-gui/Makefile +++ b/easy-asterisk-gui/Makefile @@ -8,5 +8,5 @@ # make TESTIP=boris test test: - rcp 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 set_voiplines.pl 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_ring.sh b/easy-asterisk-gui/set_ring.sh index 17d928d8..c7b559c4 100644 --- a/easy-asterisk-gui/set_ring.sh +++ b/easy-asterisk-gui/set_ring.sh @@ -12,7 +12,7 @@ if [ $? -eq 1 ]; then echo '' echo "" echo "" -# exit + exit fi # extract extensions to ring and reload extensions.conf diff --git a/easy-asterisk-gui/set_voipline.sh b/easy-asterisk-gui/set_voipline.sh new file mode 100644 index 00000000..21b78446 --- /dev/null +++ b/easy-asterisk-gui/set_voipline.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# set_voipline.sh +# # David Rowe 12 Jan 2010 +# +# CGI to set voip line parameters in sip.conf. + +cat < + +set_network.sh + + +Please wait a few seconds..... + + + +EOF + +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"` + +./set_voipline.pl $user $pass $host > /etc/asterisk/sip.conf + +cat < + +set_voiplines.sh + + +Please wait a few seconds..... + + + +EOF \ No newline at end of file diff --git a/easy-asterisk-gui/set_voiplines.pl b/easy-asterisk-gui/set_voiplines.pl new file mode 100755 index 00000000..44e9f150 --- /dev/null +++ b/easy-asterisk-gui/set_voiplines.pl @@ -0,0 +1,61 @@ +#!/sbin/microperl +# set_voiplines.pl +# David Rowe 12 Jan 2010 +# +# Replaces fields in sip.conf, outputs new sip.conf contents to stdout + +$user = $ARGV[0]; +$pass = $ARGV[1]; +$host = $ARGV[2]; + +# slurp up voip trunk details -------------------------------- + +open SIP, "/etc/asterisk/sip.conf"; +$state = "looking for [voip]"; + +while () { + $next_state = $state; + + if ($state eq "looking for [voip]") { + + if (/^\[voip\]/) { + $next_state="inside [voip]"; + #print "$state $next_state\n"; + } + + print $_; + } + + if ($state eq "inside [voip]") { + + if (/^\[/) { + $next_state = "finished"; + } + + if (/user=/) { + print "user=$user\n"; + } + elsif (/secret=/) { + print "secret=$pass\n"; + } + elsif (/host=/) { + print "host=$host\n"; + } + else { + print $_; + } + } + + if ($state eq "finished") { + print $_; + } + + $state = $next_state; +} +close SIP; + +# generate form fields ------------------------------------------- + +print "User:\n"; +print "Password:"; +print "Host:"; diff --git a/easy-asterisk-gui/voiplines.pl b/easy-asterisk-gui/voiplines.pl index bed92342..bbb1ca66 100755 --- a/easy-asterisk-gui/voiplines.pl +++ b/easy-asterisk-gui/voiplines.pl @@ -10,17 +10,22 @@ open SIP, "/etc/asterisk/sip.conf"; $state = "looking for [voip]"; while () { + $next_state = $state; + if ($state eq "looking for [voip]") { if (/^\[voip\]/) { - $state="inside [voip]"; + $next_state="inside [voip]"; + #print "$state $next_state\n"; } } - if (($state eq "inside [voip]") { + if ($state eq "inside [voip]") { + #print $_; if (/^\[/) { - $state = "finished"; + $next_state = "finished"; + #print "$next_state\n"; } if (/user=(.*)/) { @@ -33,11 +38,13 @@ while () { $host = $1; } } + + $state = $next_state; } close SIP; -# generate form --------------------------------------------- +# generate form fields ------------------------------------------- print "User:\n"; -print "Password:"; -print "Host:"; +print "Password:"; +print "Host:"; diff --git a/easy-asterisk-gui/voipline.sh b/easy-asterisk-gui/voiplines.sh similarity index 93% rename from easy-asterisk-gui/voipline.sh rename to easy-asterisk-gui/voiplines.sh index 2b2df315..0bf0bcb8 100644 --- a/easy-asterisk-gui/voipline.sh +++ b/easy-asterisk-gui/voiplines.sh @@ -1,5 +1,5 @@ #!/bin/sh -# voipline.sh +# voiplines.sh # David Rowe 12 Jan 2010 # VOIP Line screen for Easy Asterisk GUI @@ -40,12 +40,13 @@ cat <   -
+

VOIP Line

  EOF -./voipline.pl + +./voiplines.pl cat <  -- 2.25.1