-
Notifications
You must be signed in to change notification settings - Fork 26
/
asyncCall.php
106 lines (89 loc) · 2.77 KB
/
asyncCall.php
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
<?php
$dest = $argv[1];
function str_getcsv_line($string)
{
$string = preg_replace_callback(
'|"[^"]+"|',
create_function(
'$matches',
'return str_replace(\',\',\'*comma*\',$matches[0]);'
),$string );
$array = explode(',',$string);
$array = str_replace('*comma*',',',$array);
return $array;
}
if(file_exists($argv[1]))
{
require_once($basepath.'connection.php');
set_time_limit(0);
chdir($basepath);
$csv = array();
$lines = file($dest, FILE_IGNORE_NEW_LINES);
foreach ($lines as $key => $value)
{
if(!empty($value))
$csv[$key] = str_getcsv_line($value);
}
$audioIndex = count($csv[0])-2;
$phoneIndex = count($csv[0])-1;
$itemCount = count($csv,0);
$fields=implode(",",$csv[0]);
$query = "insert into logs(fields,time,status,options,type,csvFile) values('$fields',NOW(),'upload','Nil','heading','$dest')";
$result = mysql_query($query) or die("Database Error");
echo "Records Found : ".($itemCount-1)."<br>";
$i=1;
while($i<=$itemCount-1)
{
$config = parse_ini_file("config.ini",true);
$interval = $config['callblaster']['interval'];
//pause-stop controls
file_put_contents('control.ini', $reset_controls);
$controls=parse_ini_file('control.ini');
if($controls['stop']){
exit();
}
if(!$controls['pause']):
$number = $csv[$i][$phoneIndex];
$audio = $csv[$i][$audioIndex];
$fields = implode(",",$csv[$i]);
$query = "insert into logs(fields,time,status,options,type,csvFile) values('$fields',NOW(),'Dialling','Nil','field','$dest')";
$result = mysql_query($query) or die("Database Error");
$id = mysql_insert_id();
$phone = $number;
$phone=substr($phone,0,10);
$callFile = "Channel: local/$phone@from-internal\n";
$callFile .= "MaxRetries: 2\n";
$callFile .= "WaitTime: 30\n";
$callFile .= "CallerID: $caller_id\n";
$callFile .= "Context: callblaster\n";
$callFile .= "Extension: 333\n";
$callFile .= "Set: userAudio=$audio\n";
$callFile .= "Set: userNumber=$number\n";
$callFile .= "Set: dbid=$id\n";
$callFileName = $number."_".time().".call";
file_put_contents("/tmp/$callFileName",$callFile);
$time=date("c",time());
try
{
exec("mv /tmp/$callFileName /var/spool/asterisk/outgoing/$callFileName");
$msg = $time." -- Call file to 1".$number." created -- CSV file: $dest\n";
$status="Dialled";
}
catch(Exception $e)
{
$msg=$time." -- ERROR:".$e->getMessage()." -- CSV file : $dest\n";
$status="Dial Failed";
}
$query = "update logs set status='$status', time=NOW() where autoID='$id'";
$result = mysql_query($query) or die("Database Error");
file_put_contents("logs/callLog.txt",$msg,FILE_APPEND);
//sleep($interval);
$interval=$interval*1000000;
usleep($interval);
$i++;
elseif($controls['pause']):
sleep(1);
endif;
}
}
?>