All pastes #11174 Raw Edit

Stuff

public text v1 · immutable
#11174 ·published 2005-05-07 16:56 UTC
rendered paste body
REQUIRES asterisk-perl LIBRARY

/etc/asterisk/voicemail.conf:
3523 => 3523,Kelly Wheeler,,,tz=central,group=1&2

extensions.conf:

exten => 20,1,AGI(/usr/local/bin/vm-group.agi,default&${EXTEN})
exten => 20,2,Noop(VOICEMAIL_GROUP=${VOICEMAIL_GROUP})
exten => 20,3,Voicemail(${VOICEMAIL_GROUP})

/usr/local/bin/vm-group.agi:

#!/usr/bin/perl -w
use Fcntl;
use Fcntl ":flock";
use Asterisk::AGI;

my %input;

#$verbose="yes";

$AGI = new Asterisk::AGI;
%input = $AGI->ReadParse();
$AGI->setcallback(\&mycallback);

($vm_context, $vm_group) = $ARGV[0] =~/(.*)\&(.*)/;
#printf("vm_context=%s vm_group=%s\n", $vm_context, $vm_group);
verbose("vm_group=$vm_group vm_context=$vm_context");

$current_vm_context = "";

if(!sysopen($vm_conf_file_handle, "/etc/asterisk/voicemail.conf", O_RDONLY))
{
  printf("Cannot open /etc/asterisk/voicemail.conf!\n");
  exit(1);
}

while($vm_conf_line = <$vm_conf_file_handle>) {
  chomp($vm_conf_line);
#  printf("vm_conf_line=%s\n", $vm_conf_line);
#  verbose("vm_conf_line=$vm_conf_line=");
  if((substr($vm_conf_line,0,1) eq ";") || (length($vm_conf_line) == 0)) {
    next;
  }
  ($tmp_vm_context) = $vm_conf_line =~ /\[(.*)\]/;
  if(defined($tmp_vm_context)) {
    if($current_vm_context ne "") {
      $group_list = "$vm_group" . "&" . join("&", @vm_group_members);
      $AGI->set_variable("VOICEMAIL_GROUP", "$group_list");
      exit(0);
    }
    if($tmp_vm_context eq $vm_context) {
      $current_vm_context = $vm_context;
      next;
    }
  } else {
    if($current_vm_context eq $vm_context) {
      ($tmp_vm_box, $tmp_vm_group) = $vm_conf_line =~ /(\d+).*group=([0-9\&]+).*/;
      if(defined($tmp_vm_group)) {
#        printf("tmp_vm_box=%s  tmp_group=%s\n", $tmp_vm_box, $tmp_vm_group);
        verbose("tmp_vm_box=$tmp_vm_box  tmp_vm_group=$tmp_vm_group");
        @tmp_vm_groups = split("&", $tmp_vm_group);
        foreach $group (@tmp_vm_groups) {
          if($group eq $vm_group) {
            push(@vm_group_members, $tmp_vm_box);
          }
        }
      }
    } else {
      next;
    }
  }
}

sub mycallback {
        my ($returncode) = @_;
        print STDERR "MYCALLBACK: User Hungup ($returncode)\n";
        exit($returncode);
}

sub verbose {
  if (defined($verbose)) {
    $AGI->verbose("@_", $verbose);
    return(0);
  }
}