From DocDroppers
| Author:
| Nick84
|
| Date Released:
| Unknown
|
| Added to DD:
| 00:57, 4 Dec 2004 (EST)
|
#!/usr/bin/perl -w
# This script can be used to log incoming caller’s caller id to a text file.
# Usage:
# 1. Download the script to the Asterisk agi-bin directory (on Fedora 2 this
# defaults to /var/lib/asterisk/agi-bin/ )
# 2. Add in the following line (adapt if needed) above your existing code that
# handles incoming calls, and adjust the existing priorities appropriately.
# exten => s,1,AGI(call_log.agi)
# 3. Give the downloaded file execute permissions in the normal way (chmod).
# 4. Change the $log_file variable if needed to a suitable directly and create
# the file “call_log.txt”, ensure permissions are correct (if the file does not
# exist it will be created).
$log_file = '/root/call_log.txt';
print STDERR "Call log script run successful\n";
$|=1;
while(<STDIN>) {
chomp;
last unless length($_);
if (/^agi_(\w+)\:\s+(.*)$/) {
$AGI{$1} = $2;
}
}
&time_date;
if (-r $log_file && -w _) {
open(DAT,">>$log_file") || print("Save failed \"$log_file\"");
flock(DAT, 2);
print DAT $time_date."\t".$AGI{callerid}."\t".$AGI{extension}."\n";
close(DAT);
} else {
print STDERR "Failed opening $log_file\n";
open(DAT,">$log_file") || print("Save failed \"$log_file\"");
flock(DAT, 2);
print DAT "Call Log\n--------\n";
close(DAT);
}
sub time_date {
($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$longyr = $year + 1900;
$fixmo = $mon + 1;
if ($mday < 10) { $mday = "0$mday" ; }
if ($fixmo < 10) { $fixmo = "0$fixmo"; }
if ($hr < 10) { $hr = "0$hr" ; }
if ($min < 10) { $min = "0$min" ; }
if ($sec < 10) { $sec = "0$sec" ; }
#$hr = $hr+1; # Daylight saving fix
$time_date="$fixmo\/$mday\/$longyr $hr:$min:$sec";
}