$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
# 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
}
}
else {
+ # comment out unused easy-asterisk stanzas
print ";$_";
}
}
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 <<EOF
; Default is 0 tries, continue forever
;callevents=no ; generate manager events when sip ua performs events (e.g. hold)
+; register easy-asterisk voip line providers here
+
+;register => 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.
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
$('user').value = users[provider];
$('pass').value = passwords[provider];
$('host').value = hosts[provider];
+ $('stanza').value = stanzas[provider];
}
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
# 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 "") {
# 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";
print "var hosts = new Array();\n";
print "var users = new Array();\n";
print "var passwords = new Array();\n";
+print "var stanzas = new Array();\n";
foreach (@providers) {
print "hosts[\'$_\'] = \'$host{$_}\';\n";
print "users[\'$_\'] = \'$user{$_}\';\n";
print "passwords[\'$_\'] = \'$pass{$_}\';\n";
+ print "stanzas[\'$_\'] = \'$stanza{$_}\';\n";
}
print "</script>\n";
print "<tr><td>User:</td><td><input type=\"text\" name=\"user\" id=\"user\" value=\"$user{$provider_current}\"></td></tr>\n";
print "<tr><td>Password:</td><td><input type=\"password\" name=\"pass\" id=\"pass\" value=\"$pass{$provider_current}\"></td></tr>";
print "<tr><td>Host:</td><td><input type=\"text\" name=\"host\" id=\"host\" value=\"$host{$provider_current}\"></td></tr>";
-if ($voip{"voip"} eq "OK") {
+if ($voip{$stanza{$provider_current}} eq "OK") {
$icon = "<img src=\"tick.png\" alt=\"VOIP Line OK\" />";
}
else {
$icon = "<img src=\"cross.png\" alt=\"VOIP Line OK\" />";
}
print "<tr><td>Voip Line Status:</td><td>$icon</td></tr>";
+
+# hidden field to pass stanza with form
+
+print "<tr><td><input type=\"hidden\" name=\"stanza\" id=\"stanza\" value=\"$stanza{$provider_current}\"></td></tr>";