line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Asterisk::Outgoing; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Asterisk::Outgoing - Create outgoing call queue file |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Asterisk::Outgoing; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $out = new Asterisk::Outgoing; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$out->setvariable('Channel', 'Zap/1/'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$out->setvariable('MaxRetries', 0); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$out->setvariable('RetryTime', 60); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$out->setvariable('WaitTime', 60); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$out->setvariable('Application', 'Playback'); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$out->setvariable('Data', 'beep'); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$out->create_outgoing; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
require 5.004; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
540
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
32
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
33
|
1
|
|
|
1
|
|
3
|
use Fcntl ':flock'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
136
|
|
34
|
1
|
|
|
1
|
|
223
|
use Asterisk; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
35
|
1
|
|
|
1
|
|
2
|
use vars qw(@ISA); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
501
|
|
36
|
|
|
|
|
|
|
@ISA = ('Asterisk'); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $VERSION = '0.02'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
1
|
|
|
1
|
0
|
624
|
my ($class, %args) = @_; |
42
|
1
|
|
|
|
|
1
|
my $self = {}; |
43
|
1
|
|
|
|
|
2
|
$self->{OUTDIR} = '/var/spool/asterisk/outgoing'; |
44
|
1
|
|
|
|
|
1
|
$self->{OUTTIME} = undef; |
45
|
1
|
|
|
|
|
2
|
$self->{OUTVARS} = {}; |
46
|
1
|
|
|
|
|
1
|
$self->{CUSTOM_VARS} = (); |
47
|
1
|
|
|
|
|
3
|
$self->{ALLOWEDVARS} = [ 'channel', 'maxretries', 'retrytime', 'waittime', 'context', 'extension', 'priority', 'application', 'data', 'callerid', 'setvar']; |
48
|
1
|
|
33
|
|
|
6
|
bless $self, ref $class || $class; |
49
|
1
|
|
|
|
|
2
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub outdir { |
53
|
2
|
|
|
2
|
0
|
745
|
my ($self, $dir) = @_; |
54
|
|
|
|
|
|
|
|
55
|
2
|
100
|
|
|
|
5
|
if (defined($dir)) { |
56
|
1
|
|
|
|
|
2
|
$self->{OUTDIR} = $dir; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
10
|
return $self->{OUTDIR}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub outtime { |
63
|
1
|
|
|
1
|
0
|
1
|
my ($self, $time) = @_; |
64
|
|
|
|
|
|
|
|
65
|
1
|
50
|
|
|
|
3
|
if (defined($time)) { |
|
|
0
|
|
|
|
|
|
66
|
1
|
|
|
|
|
2
|
$self->{OUTTIME} = $time; |
67
|
|
|
|
|
|
|
} elsif (!defined($self->{OUTTIME})) { |
68
|
0
|
|
|
|
|
0
|
$self->{OUTTIME} = time(); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
4
|
return $self->{OUTTIME}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub checkvariable { |
75
|
16
|
|
|
16
|
0
|
2904
|
my ($self, $var) = @_; |
76
|
|
|
|
|
|
|
|
77
|
16
|
|
|
|
|
15
|
my $ret = 0; |
78
|
|
|
|
|
|
|
|
79
|
16
|
|
|
|
|
8
|
foreach my $allowed (@{$self->{ALLOWEDVARS}}) { |
|
16
|
|
|
|
|
28
|
|
80
|
176
|
100
|
|
|
|
373
|
if ($allowed =~ /$var/i) { |
81
|
15
|
|
|
|
|
14
|
$ret = 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
16
|
|
|
|
|
74
|
return $ret; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub setvariable { |
88
|
4
|
|
|
4
|
0
|
799
|
my ($self, $var, $value) = @_; |
89
|
|
|
|
|
|
|
|
90
|
4
|
50
|
|
|
|
5
|
if ($self->checkvariable($var)) { |
91
|
4
|
50
|
|
|
|
8
|
if ($var =~ /setvar/i) { |
92
|
0
|
|
|
|
|
0
|
push @{$self->{CUSTOM_VARS}},$value; |
|
0
|
|
|
|
|
0
|
|
93
|
|
|
|
|
|
|
} else { |
94
|
4
|
|
|
|
|
10
|
$self->{OUTVARS}{$var} = $value; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub create_outgoing { |
100
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $time = $self->outtime(); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $outdir = $self->outdir(); |
105
|
0
|
|
|
|
|
|
my $filename = $outdir . '/' . $time . '.outgoing'; |
106
|
0
|
0
|
|
|
|
|
open(OUTFILE, ">$filename") || return 0; |
107
|
0
|
|
|
|
|
|
flock(OUTFILE, LOCK_EX); |
108
|
0
|
|
|
|
|
|
utime($time, $time, $filename); |
109
|
0
|
|
|
|
|
|
foreach my $var (keys %{$self->{OUTVARS}}) { |
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
print OUTFILE "$var: " . $self->{OUTVARS}{$var} . "\n"; |
111
|
|
|
|
|
|
|
} |
112
|
0
|
|
|
|
|
|
foreach my $var (@{$self->{CUSTOM_VARS}}) { |
|
0
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
print OUTFILE 'SetVar: ' . $var . "\n"; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
flock(OUTFILE, LOCK_UN); |
116
|
0
|
|
|
|
|
|
close(OUTFILE); |
117
|
0
|
|
|
|
|
|
utime($time, $time, $filename); |
118
|
0
|
|
|
|
|
|
return 1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |