📄 astconlcr.agi
字号:
#!/astercon2/perl/bin/perl# scperl /astercon2/perl (project info don't remove or modify)#!/usr/bin/perl#--------------------------------------------------------------## Astercon -- An open source softswitch and ippbx system.## Copyright (C) 2005 - 2008, Sun bing.## Sun bing <hoowa.sun@gmail.com>## See http://astercon.0420.com for more information about# the Astercon project.## license# The astercon project is licensed under the GNU 2.0 GPL. # astercon carries no restrictions on re-branding and # people are free to commercially re-distribute it.## any questions?# Please do not directly contact any of the maintainers of# this project for assistance;# the project provides a web site, bugs tracker,really chat.##--------------------------------------------------------------# ------------------------------------------------------------------------------# HEADER OF SCRIPTS# ------------------------------------------------------------------------------use FindBin qw($Bin);use strict "vars";use astercon::common;use astercon::database;use Asterisk::AGI;$|=1;#------------------------------------------------------------------------------# INIT SECTION#------------------------------------------------------------------------------# AUTO FLASH$|=1;# GET OUT COMMONmy $common = new astercon::common;my ($astcon_conf) = $common->{rc}->load_config(filename=>'/astercon2/etc/astcon.conf');# GET DATABASE SUPPORTmy $astodm = new astercon::database( dbuser=>$astcon_conf->{'general'}{'dbuser'}[0],dbpasswd=>$astcon_conf->{'general'}{'dbpasswd'}[0], dbhost=>$astcon_conf->{'general'}{'dbhost'}[0],dbname=>$astcon_conf->{'general'}{'dbname'}[0], dbport=>$astcon_conf->{'general'}{'dbport'}[0],dbsock=>$astcon_conf->{'general'}{'dbsock'}[0], conn=>1 );# GET AGI OBJECTmy $AGI = new Asterisk::AGI;my %input = $AGI->ReadParse();#ARG1=ASTERCON_OUTGROUP=if ($ARGV[0] eq '') {&toresponse(2);}if ($ARGV[1] eq '') {&toresponse(2);}#GET Prioritymy $rategroupref = $astodm->billing_get_rate($ARGV[1]);&toresponse(1) if (!defined $rategroupref);my $cur_priority = $rategroupref->{'Lcr_priority'};#GET all Rulesmy $lcrrategroupref = $astodm->lcr_get_rategroup(by_Rate_id=>$ARGV[1]);&toresponse(1) if (!defined $lcrrategroupref->[0]);#TRY range of current lcrmy (%cur_rule,%cutout_skiptrunk);%cutout_skiptrunk = map { $_ => $_ } split(/,/,$ARGV[2]);foreach (@$lcrrategroupref) { next if ($cutout_skiptrunk{$_->{'Trunk_name'}}); if ($_->{'Callee_prefix'} eq '' && $_->{'Call_start_time'} eq '') { $cur_rule{$_->{'Trunk_name'}} = $_; next; } elsif ($_->{'Callee_prefix'} ne '' && $ARGV[0] =~ /^$_->{'Callee_prefix'}/) { $cur_rule{$_->{'Trunk_name'}} = $_; next; } elsif ($_->{'Call_start_time'} ne '') { my @dtime = localtime(); if ($dtime[2] >= $_->{'Call_start_time'} && $dtime[2] <= $_->{'Call_end_time'}) { $cur_rule{$_->{'Trunk_name'}} = $_; next; } }}&toresponse(1) if (!keys %cur_rule);#NOT ANY RULE EXISTS QUIT#MATCH TRUNKS BY PRIORITYmy (@order_cur_rule);if ($cur_priority eq '1') { #璐ㄩ噺鏇撮珮浼樺厛 @order_cur_rule=sort { $cur_rule{$b}{Point_quality} <=> $cur_rule{$a}{Point_quality} || $cur_rule{$a}{Point_price} <=> $cur_rule{$b}{Point_price} } keys %cur_rule;} else { #浠锋牸鏇翠綆浼樺厛 @order_cur_rule=sort { $cur_rule{$a}{Point_price} <=> $cur_rule{$b}{Point_price} || $cur_rule{$b}{Point_quality} <=> $cur_rule{$a}{Point_quality} } keys %cur_rule;}&toresponse(0, $cur_rule{$order_cur_rule[0]}->{'Trunk_device'}, $order_cur_rule[0], $cur_rule{$order_cur_rule[0]}->{'Trunk_maxcurrent'});exit;sub toresponse{my $type = shift;my $trunk_device =shift;my $trunk_name = shift;my $trunk_maxcurrent = shift; if ($type eq '0' || $type eq '1') { foreach (@{$astcon_conf->{'callee_replace'}{'rule'}}) { my ($match,$replace) = split(/\?/,$_); my @match = split(/\,/,$match); my @replace = split(/\,/,$replace); next if ($#match < 0 || $#replace < 0); if ($ARGV[0] =~ /^$match[0]/ || $trunk_name eq $match[1]) { $ARGV[0] = substr($ARGV[0],$replace[0],length($ARGV[0])) if ($replace[0] > 0); $ARGV[0] = $replace[1].$ARGV[0] if ($replace[1] ne ''); $ARGV[0] = $replace[2] if ($replace[2] ne ''); last; } } } #SET $AGI->set_variable('ASTERCON_LCRSTATUS',$type); $AGI->set_variable('ARG1',$ARGV[0]); # normal if ($type eq '0') { $AGI->set_variable('ASTERCON_FAILEDON',$astcon_conf->{'smartlcr'}{'failed_on_failed'}[0]); $AGI->set_variable('ASTERCON_MAXON',$astcon_conf->{'smartlcr'}{'max_on_failed'}[0]); $AGI->set_variable('ASTERCON_MAXCURRENT',$trunk_maxcurrent); $AGI->set_variable('ARG2',$trunk_device); $AGI->set_variable('ASTERCON_LCRTRUNK_NAME',$trunk_name); $AGI->set_variable('ASTERCON_SKIPTRUNK',$ARGV[2].",$trunk_name"); # default settings } elsif ($type eq '1') { $AGI->set_variable('ASTERCON_FAILEDON','no'); $AGI->set_variable('ASTERCON_MAXON','no'); $AGI->set_variable('ASTERCON_MAXCURRENT',9999); $AGI->set_variable('ARG2',$astcon_conf->{'smartlcr'}{'default_trunk'}[0]); # error } else { $AGI->set_variable('ASTERCON_FAILEDON','no'); $AGI->set_variable('ASTERCON_MAXON','no'); $AGI->set_variable('ASTERCON_MAXCURRENT',9999); } exit;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -