autoconfig-users-thirdlane.pl
#!/usr/bin/perl
$file = "/etc/asterisk/voicemail.conf";
open( CONFIG, "<$file" ) or die("Could not open $file");
while (<CONFIG>) {
chomp;
$_ =~ s/^\s+//g;
$_ =~ s/([^;]*)[;](.*)/$1/g;
$_ =~ s/\s+$//g;
if ( /^#/ || /^;/ || /^$/ ) {
next;
} # Ignores comments and empty lines
if (/^\Q[\E/) {
s/\[(.*)\]/$1/g;
$context = $_;
if($context =~ /^default/) {
$context =~ s/^default-//g;
if($hubo>0) {
print "buttonfile=automatic-thirdlane-buttons.cfg $oldcontext\n\n";
$hubo=0;
}
if($context ne "default") {
print "[$context]\n";
}
}
}
if (/=>/) {
$_ =~ s/\s//g;
@partes = split(/=>/,$_,2);
$exten = $partes[0];
$resto = $partes[1];
@partes = split(/,/,$resto,2);
$secret = $partes[0];
$oldcontext=$context;
print "user=$exten:$secret:all\n";
$hubo++;
}
}
close(CONFIG);
print "buttonfile=automatic-thirdlane-buttons.cfg $oldcontext\n\n";
automatic-thirdlane-buttons.cfg
#exec autoconfig-buttons-thirdlane.pl $1
autoconfig-buttons-thirdlane.pl
#!/usr/bin/perl
$file = "/etc/asterisk/users.txt";
$mycontext = $ARGV[0];
open( CONFIG, "<$file" ) or die("Could not open $file");
while (<CONFIG>) {
chomp;
$_ =~ s/^\s+//g;
$_ =~ s/([^;]*)[;](.*)/$1/g;
$_ =~ s/\s+$//g;
if ( /^#/ || /^;/ || /^$/ ) {
next;
} # Ignores comments and empty lines
if (/^\Q[\E/) {
s/\[(.*)\]/$1/g;
$context = $_;
@partes = split (/-/,$context,2);
$context= $partes[0];
$extension = $partes[1];
if($context eq $mycontext) {
$dale=1;
} else {
$dale=0;
}
} else {
if($dale==1) {
my ($key,$val) = split(/=/,$_,2);
$config->{$mycontext}{$extension}{$key}=$val;
}
}
}
close(CONFIG);
while ( my ( $uno, $dos ) = each( %{ $config->{$mycontext} } ) ) {
$label = $dos->{first_name}." ".$dos->{last_name};
$exten = $dos->{ext};
$ctx = "from-inside-$mycontext";
$mbox = $dos->{mailbox};
$chan = $dos->{phones};
print "[$chan]\n";
print "type=extension\n";
print "extension=$exten\n";
print "context=$ctx\n";
print "label=$label\n";
print "mailbox=$mbox\n\n";
}