Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- # Written by ES on 5/16/11
- #use Asterisk::Manager;
- use Asterisk::AMI;
- use Mysql;
- use strict;
- # become daemon
- my $pid = fork();
- open ("PID", ">/var/run/eswitch.pid");
- print PID $pid;
- close (PID);
- if($pid) {
- #end parent process
- # print "#parent process";
- exit(0);
- }else {
- # print "#child process";
- }
- # set new process group
- setpgrp;
- # setsid ? only C
- open(STDERR, ">>", "/var/log/eswitch.log");
- my $host = XXXXXXXXXXXX;
- my $database = XXXXXXXXXXXX;
- my $user = XXXXXXXXXXXX;
- my $pw = XXXXXXXXXXXX;
- my $connect = Mysql->connect($host, $database, $user, $pw);
- my $astman = amiconnect();
- while(1) {
- open ("LOG", ">> /var/log/eswitch.log");
- sleep(2);
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
- print LOG ("$year-$mon-$mday $hour:$min:$sec\n");
- $year+=1900;$mon++;
- my $sql = "select customer, snumber, dnumber, dtype from active";
- my $res = $connect->query($sql);
- while(my @row = $res->fetchrow()) {
- print LOG ("Calling ".$row[2]." from ".$row[1]." at $year-$mon-$mday $hour:$min:$sec.\n");
- my $response = $astman->action({Action => 'Originate',
- Channel => 'Local/'.$row[2].'@outbound',
- Context => 'page',
- CallerID => $row[1],
- Exten => $row[1],
- Priority => 1,
- OriginateHack => 1,
- Async => 1});
- print LOG ($response->{'Message'} );
- $connect->query("delete from active where customer='".$row[0]."' and snumber='".$row[1]."' and dnumber='".$row[2]."' and dtype='".$row[3]."'");
- }
- # close (LOG);
- }
- sub amiconnect {
- my $ami = Asterisk::AMI->new( PeerAddr => '127.0.0.1',
- PeerPort => '5038',
- Username => XXXXXXXXXXXX,
- Secret => XXXXXXXXXXXX,
- Keepalive=> '2',
- on_error => \&amiconnect
- );
- die "Unable to connect to asterisk" unless ($ami);
- return $ami;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement