-
Notifications
You must be signed in to change notification settings - Fork 9
/
cm_date.agi
executable file
·149 lines (126 loc) · 2.99 KB
/
cm_date.agi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/perl
#
# cm_date.agi version 2.6
#
# Can be used in a call menu prompt to play a date string as defined by the settings below
#
# ; Below are the parameters needed for the script to be run properly
# ; the "SAY DATETIME" parameters for what to say separated by three dashes
# ; 1. offset from current epoch in seconds, positive or negative
# ; 1 hour is 3600
# ; 1 day is 86400
# ; 1 week is 604800
# ; 30 days is 2592000
# ; 1 year is 31536000
# ; 2. format of the date to say, i.e. "ABdY":
# ; A: Day of the week
# ; B: Month (Full Text)
# ; m: Month (Numeric)
# ; d: Day of the month
# ; Y: Year
# ; I: Hour (12-hour format)
# ; H: Hour (24-hour format)
# ; M: Minutes
# ; P: AM/PM
# ; Q: Shorthand for Today, Yesterday or ABdY
# ; R: Shorthand for HM
# ; S: Seconds
# ; T: Timezone
#
# ;inbound calls check calltime:
# ; (this example is for yesterday and says "Monday March 25th 2013")
# cm_date.agi,-86400---ABdY
#
# Copyright (C) 2013 Matt Florell <[email protected]> LICENSE: AGPLv2
#
# changes:
# 130326-1718 - First Build
#
$script = 'cm_date.agi';
$now_date_epoch = time();
$now_date = time();
$AGILOG = '1'; # 1=STDERR output
$exten='';
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
$i++;
}
### list of command-line array arguments:
@ARGV_vars = split(/---/, $ARGV[0]);
$epoch_offset = $ARGV_vars[0];
$datetime_format = $ARGV_vars[1];
}
$|=1;
while(<STDIN>)
{
chomp;
last unless length($_);
if ($AGILOG)
{
if (/^agi_(\w+)\:\s+(.*)$/)
{
$AGI{$1} = $2;
}
}
if (/^agi_context\:\s+(.*)$/) {$context = $1;}
}
$new_epoch = ($now_date_epoch + $epoch_offset);
if ($AGILOG) {$agi_string = "Date Epoch: |$now_date_epoch|$epoch_offset|$new_epoch| Format: |$datetime_format|"; &agi_output;}
# SAY DATETIME <time> <escape digits> [format] [timezone]
print "SAY DATETIME $new_epoch 0 \"$datetime_format\"\n"; checkresult($result);
exit;
sub checkresult
{
$pass=0;
$fail=0;
my ($res) = @_;
my $retval;
$tests++;
chomp $res;
if ($res =~ /^200/)
{
$res =~ /result=(-?\d+)/;
if (!length($1))
{
# print STDERR "FAIL ($res|$1)\n";
$fail++;
}
else
{
# print STDERR "PASS ($res|$1)\n";
$pass++;
}
}
else
{
# print STDERR "FAIL (unexpected result '$res')\n";
$fail++;
}
}
sub agi_output
{
if ($AGILOG >=2)
{
### open the log file for writing ###
open(Lout, ">>$AGILOGfile")
|| die "Can't open $AGILOGfile: $!\n";
print Lout "$now_date|$script|$agi_string\n";
close(Lout);
}
### send to STDERR writing ###
if ( ($AGILOG == '1') || ($AGILOG == '3') )
{print STDERR "$now_date|$script|$agi_string\n";}
$agi_string='';
}