$ mkdir untar && cd untar && tar xvf ../FW-IPX1900_1.16.8.dat rootfs.jffs2 vmImage start_install.sh aimage.tar.gz
#!/bin/sh
useradd -groot -proot toor
$ sudo aptitude install asterisk libasterisk-agi-perl asterisk-mysql mysql-server
CREATE DATABASE astr; GRANT ALL PRIVILEGES ON astr.* TO 'asterisk'@'localhost' IDENTIFIED BY 'super-pass' WITH GRANT OPTION; EXIT;
$ mysql -uasterisk -psuper-pass astr
CREATE TABLE `cdr` ( `calldate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `clid` varchar(80) NOT NULL DEFAULT '', `src` varchar(80) NOT NULL DEFAULT '', `dst` varchar(80) NOT NULL DEFAULT '', `dcontext` varchar(80) NOT NULL DEFAULT '', `channel` varchar(80) NOT NULL DEFAULT '', `dstchannel` varchar(80) NOT NULL DEFAULT '', `lastapp` varchar(80) NOT NULL DEFAULT '', `lastdata` varchar(80) NOT NULL DEFAULT '', `duration` int(11) NOT NULL DEFAULT '0', `billsec` int(11) NOT NULL DEFAULT '0', `disposition` varchar(45) NOT NULL DEFAULT '', `amaflags` int(11) NOT NULL DEFAULT '0', `accountcode` varchar(20) NOT NULL DEFAULT '', `userfield` varchar(255) NOT NULL DEFAULT '', KEY `calldate` (`calldate`), KEY `dst` (`dst`), KEY `accountcode` (`accountcode`) ); EXIT;
# cp -r ../asterisk/ ~/asterisk_config # echo '' > cdr_mysql.conf && mcedit cdr_mysql.conf
[global] hostname=localhost dbname=astr table=cdr password=super-pass user=asterisk [columns] alias start => calldate
# mcedit sip.conf #include sip_general.conf #include sip_trunk.conf #include sip_internal.conf
[defaults](!) type = friend qualify = yes ; ; , context = phone_int canreinvite = no host = dynamic callgroup = 1 pickupgroup = 1 [101](defaults) secret = pass_for_reception callerid = "Sveta"<101> context = phone_long_d [112](defaults) secret = pass_for_artur callerid = “Artur"<112> context = phone_local [106](defaults) secret = pass_for_fax callerid = "Fax"<106> context = phone_too_long_d [495](defaults) secret = pass_msk callerid = "MSK"<495>
# mcedit sip_general.conf [general] bindport = 5060 bindaddr=0.0.0.0 allowguest = no allowtransfer = yes allowoverlap = no tos_sip = cs3 tos_audio = ef tos_video = af41 srvlookup = no minexpiry = 900 maxexpiry = 3600 defaultexpiry = 360 checkmwi = 10 language = en relaxdtmf = no rtptimeout = 550 rtpholdtimeout = 600 progressinband = never useragent = PBX dtmfmode = rfc2833 disallow = all domain = pbx.webnames.ru ; allow = ulaw,alaw,gsm,ilbc,g726,g729,g723 ; registertimeout = 60 registerattempts = 65535 externip = 8.8.8.8 ; ip externrefresh = 10 nat = yes canreinvite = nonat insecure = invite register = example_num:pass_for_example_num:example_num@proxyreg_time/example_num
# mcedit sip_trunk.conf [trunk](!) type = friend call-limit=1 canreinvite=no qualify=yes context= from_external disallow=all ; need to disallow=all before we can use allow= allow=ulaw ; Note: In user sections the order of codecs allow=alaw allow=g723.1 ; Asterisk only supports g723.1 pass-thru! allow=g729 ; Pass-thru only unless g729 license obtained allow=gsm ;; example_num [example_num] type = peer username = example_num fromuser = example_num secret = pass_for_example_num fromdomain = 1.1.1.1 ; external pbx ip host = 1.1.1.1 ; external pbx ip port = 5060 outboundproxy = 1.1.1.1 ; external pbx ip outboundproxyport = 5060 context = from_external ; [pstn_beeline](trunk) username = pstn_beeline fromuser = pstn_beeline host = dynamic secret = pass_for_beeline ;; 88001004022 (RosTelecom) [RTK] username = trace_num type = peer host = 2.2.2.2 ; external pbx ip insecure=port,invite context= from_external
register = example_num:pass_for_example_num:example_num@proxyreg_time/example_num
# mcedit extensions.conf [globals] [general] autofallthrough=yes ; ; ; dial_internal.pl - [out_int] ; exten => *, 1, NoOp() exten => _[1-9]XX, 1, Macro(monitor) exten => _[1-9]XX, n, Macro(int-dial,${EXTEN}) exten => _[1-9]XX, n, Hangup() ; - [out_local] ; exten => _X., 1, Macro(monitor) exten => _[1-79]XXXXXX, 2, Dial(SIP/${EXTEN}@pstn_beeline&SIP/${EXTEN}@example_num) exten => _0[1-79]XXXXXX, 2, Dial(SIP/${EXTEN:1}@pstn_beeline&SIP/${EXTEN:1}@example_num) exten => _83[1-79]XXXXXX, 2, Dial(SIP/${EXTEN:2}@pstn_beeline) exten => _85[1-79]XXXXXX, 2, Dial(SIP/${EXTEN:2}@example_num) ; - ; . exten => _094959874596, 2, Dial(SIP/${EXTEN:1}@pstn_beeline) ; msk line ; [out_long_d] ; exten => _X., 1, Macro(monitor) ; ; 1) - ; 2) - exten => _08X., 2, Dial(SIP/${EXTEN:1}@pstn_beeline&SIP/${EXTEN:1}@example_num) ; exten => _838X., 2, Dial(SIP/${EXTEN:2}@pstn_beeline) exten => _858X., 2, Dial(SIP/${EXTEN:2}@example_num) ; [out_too_long_d] exten => _X., 1, Macro(monitor) exten => _0X., 2, Dial(SIP/${EXTEN:1}@pstn_beeline&SIP/${EXTEN:1}@example_num) ; exten => _83X., 2, Dial(SIP/${EXTEN:2}@pstn_beeline) exten => _85X., 2, Dial(SIP/${EXTEN:2}@example_num) ; [phone_int] include => out_int ; [phone_local] include => phone_int include => out_local ; [phone_long_d] include => phone_local include => out_long_d ; [phone_too_long_d] include => phone_long_d include => out_too_long_d ; ======== ==============
exten => _0[1-79]XXXXXX, 2, Dial(SIP/${EXTEN:1}@pstn_beeline&SIP/${EXTEN:1}@example_num)
; [phone_local] include => phone_int include => out_local
; ========= ============== [from_external] exten => _X., 1, Macro(dial) exten => s, 1, Macro(dial) ; ========= ==============
exten => _[1-79]XX, n, Macro(int-dial,${EXTEN})
; =============================== ; ; /var/lib/asterisk/agi/dial_internal.pl ; ( ) ; ; users .. asterisk [macro-int-dial] exten => s, 1, NoOp() exten => s, 2, AGI(/var/lib/asterisk/agi/dial_internal.pl, ${ARG1}) exten => s, n, Hangup() ; ( ) ; ; [phone_int] ; /var/lib/asterisk/agi/ivr.pl [macro-monitor] exten => s, 1, AGI(/var/lib/asterisk/agi/monitor.pl) ; [macro-groupe-dial] exten => s, 1, Queue(${ARG1}, rtT,,,100) ; ; - ( ) ; ( <->. ), ; - “ , " [macro-dial] exten => s, 1, AGI(/var/lib/asterisk/agi/ivr.pl) exten => s, n, Hangup() ; ===============================
exten => s, 1, AGI(/var/lib/asterisk/agi/ivr.pl)
use Data::Dumper; use warnings; use strict; use Asterisk::AGI; use Time::localtime; my $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); # "" # , # check_ivr my $schedule_time = '/var/lib/asterisk/agi/schedule.conf'; # my $support = '300'; # my $recep = '101'; # non_working - # working - ( 9-13;14-18 ) # work_supp - (default 13-14; 18-21) my @ivr = (\&non_working, \&working, \&work_supp); #START $AGI->answer(); # my $mode = &check_ivr(); # $AGI->verbose( "Mode => $mode", 0); &{$ivr[$mode]}; # $AGI->hangup(); exit(); sub non_working{ # $AGI->exec('Playback', 'offduty'); } sub working{ # $AGI->exec('Playback', 'welcome'); # $AGI->exec('Macro', "monitor"); # $AGI->exec('Macro', "int-dial,$recep"); } sub work_supp{ $AGI->exec('Playback', 'welcome'); $AGI->exec('Macro', "monitor"); # $AGI->exec('Macro', "groupe-dial,$support"); } ################# check_ivr ##################################### # ( . ):# # $wday - ( - 0..6 )############### # $hour - ( - 0..23 )########################### # $date - ( - . )################### # ( 0..2 ):####################################### # 0 - ;########################################### # 1 - ;############################################## # 2 - ..###################################### sub check_ivr { my ( $wday, $hour, $date ) = @_; # - ($wday, $hour, $date ) = &_date_now_ if !$date||!$hour||!$date; my ( %check, $check); # - my %sch_dates; open ( SCH, $schedule_time ); while ( <SCH> ) { if ( $_ =~ /^(\d{1,2}\.\d{1,2})\s*(.*)[\r\n]*$/) { my ( $sch_date, $sch ) = ($1, $2); $date =~ s/^0(\d)/$1\./; $date =~ s/0(\d)$/$1/; $sch ||= '0'; $sch_dates{$sch_date} = $sch; } } close(SCH); foreach my $schedule_d (keys %sch_dates){ if ( $date eq $schedule_d ) { if ( $sch_dates{$date} ) { return &_check_time_( $hour, $sch_dates{$date} ); } else { return $sch_dates{$date} } } } # ? 1( ) 0 ( ) $check{wday} = $wday>0&&$wday<6 ? '1':'0'; # 0, 1, 2 - _check_time_ $check{hour} = &_check_time_( $hour ); $check = 1; foreach ( values %check ) { $check *= $_; } return $check; sub _check_time_ { # $hour_tm - # $wr_time - work time ( ) [9,13,18,21] my ( $hour_tm, $wr_time) = @_; # $wr_time - work time ( ) # () my %wr_time = &_parse_work_time_( $wr_time ); # 0 - # 1 - ( 9-13; 14-18 ) # 2 - c 13 14; 18 21 my $check_tm = 0; if( $hour_tm>$wr_time{st_office}&&$hour_tm<$wr_time{end_support} ) { if ( $hour_tm==$wr_time{lunch}||$hour_tm>$wr_time{end_office} ) { $check_tm = 2; } else { $check_tm = 1 } } return $check_tm; } # [9,13,18,21] # # %work_time = ( st_office => 8, # lunch => 13, # end_office => 17, # end_support => 21); sub _parse_work_time_ { my ( $work_time ) = @_; # 1 # . $work_time = "[9,13,18,21]" if (!$work_time||$work_time eq 1 ); $work_time =~ s/^\[(.+)\][\r\n]*$/$1/; my %work_time; ( $work_time{st_office}, $work_time{lunch}, $work_time{end_office}, $work_time{end_support}, $work_time{lunch_support} ) = split /\s*,\s*/, $work_time; $work_time{st_office} -= 1; $work_time{end_office} -= 1; return %work_time; } sub _date_now_ { return ( localtime->wday, localtime->hour, localtime->mday.'.'.(localtime->mon+1) ); } } __END__
CREATE TABLE `users` ( `num` int(11) PRIMARY KEY NOT NULL, `timeout` tinyint(4) NOT NULL DEFAULT '10', `queue` int(11) DEFAULT NULL );
INSERT INTO `users` VALUES (101,10,300), (106,20,0), (112,20,0);
exten => _[1-9]XX, n, Macro(int-dial,${EXTEN}) [macro-int-dial] exten => s, 1, NoOp() exten => s, 2, AGI(/var/lib/asterisk/agi/dial_internal.pl, ${ARG1}) exten => s, n, Hangup()
#!/usr/bin/perl use Data::Dumper; use warnings; use strict; use Asterisk::AGI; use DBI; my $user = 'asterisk'; my $pass = 'super-pass'; my $db = 'astr'; my $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); $AGI->answer(); # my $exten = $input{arg_1}; # , my ($timeout, $queue) = &get_timeout($exten); # # , . $timeout ||= '10'; #$AGI->verbose("$timeout $queue", 0); $AGI->exec('Dial', "SIP/$exten, $timeout, Tt"); # if ( $queue ) { # $AGI->verbose('$queue', 0); $AGI->exec('Macro', "groupe-dial,$queue") if ( $AGI->get_variable('DIALSTATUS') ne 'ANSWER'); } $AGI->hangup(); exit(); sub get_timeout { my ($num) = @_; my $dbh = DBI->connect("DBI:mysql:database=$db;host=localhost", $user, $pass, {'RaiseError' => 1}); my $sth = $dbh->prepare("SELECT * FROM users WHERE num like $num"); $sth->execute(); my $ref = $sth->fetchrow_hashref(); ( $timeout, $queue ) = ( ${$ref}{timeout}, ${$ref}{queue}); $sth->finish (); $dbh->disconnect(); return ($timeout, $queue); } __END__
#!/usr/bin/perl use Data::Dumper; use warnings; use strict; use Asterisk::AGI; use File::Path qw(make_path); # my $dir = '/mnt/pbx/'; my $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); # - , # my $prop = $input{arg_1}; $AGI->answer(); my ($date, $time) = split / /, $AGI->get_variable('CDR(start)'); $time =~ s/://g; $date =~ s/-/\//g; $date .= '/'; my $dir = $dir.$date; # $date =~ s/\///g; # # - 'ivr' $prop ||= $AGI->get_variable('CDR(src)'); # $prop =~ s/[\+\.\'\"\:\(\)\[\]\&\^\$\#\@\!\%\*\s]//g; my $file = $prop ? $dir.$date.".$time.$prop" : $dir.$date.".$time.anon"; # $file .= '.wav'; $AGI->exec('MixMonitor', "$file, a"); exit(); __END__
[general] persistentmembers=yes autofill=yes autopause=no monitor-type=MixMonitor strategy=ringall ; . ringinuse=no timeout=100 retry=2 wrapuptime=0 maxlen=0 defaultrule = plus10 [301] member => SIP/105,1 member => SIP/109,1 [300] member => SIP/102,1 member => SIP/108,1
Source: https://habr.com/ru/post/180265/
All Articles