Skip to content

Commit

Permalink
php 5.1 compatible, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nethram committed Jan 28, 2015
1 parent ccaf60f commit cd2853a
Show file tree
Hide file tree
Showing 16 changed files with 1,106 additions and 38 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ Webserver

Installation
------------
1-Copy all files and directories to a directory in your web-server where asterisk is installed.
1-On your Asterisk server,copy all files and directories to a web directory (eg; /var/www/html/Callblaster).

2- Open config.php in a text editor and change database configurations and base path to the installed directory.

Provide your MySql host,database name, database user and database password. Give all privileges on the database to the user.
2-Open config.php in a text editor and change database configurations and base path to the installed directory.

Provide your MySql host,database name, database user and database password. Give all privileges on the database to the user.
You may use same database for Asterisk and Callblaster, credentials can be found at /etc/asterisk/freepbx.conf


//Database configuration
Expand All @@ -60,11 +60,12 @@ You can change welcome sound file path here.

$basepath="/var/www/html/callblastergpl/";

$agipath="/var/lib/asterisk/agi-bin/";

$welcomeSound = $basepath."audio/testmenu";
//sound file without extension
$agipath="/var/lib/asterisk/agi-bin/";

//Set default audio file, it will be used if no audio file specified in number list.
//...........................................

$welcomeSound = $basepath."audio/welcome";

//...........................................

Expand Down
103 changes: 103 additions & 0 deletions asyncCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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);
$i++;
elseif($controls['pause']):
sleep(1);
endif;
}
}

?>
Binary file added audio/welcome.wav
Binary file not shown.
20 changes: 13 additions & 7 deletions audioFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
*....................
* www.nethram.com
*/
require('config.php');
require_once('config.php');
error_reporting(E_ALL);
ini_set('display_errors', 1);


function displayAudio()
{

global $basepath;
exec("ls -t audio/",$files);
echo("<table>");
foreach($files as $file)
{
$size = filesize("files/$file")/1024;
$filedate = date ("m/d/Y H:i:s", filemtime("files/$file"));
{
//$size = filesize($basepath."/files/$file")/1024;
//$filedate = date ("m/d/Y H:i:s", filemtime($basepath."/files/$file"));
$link="audio/$file";
echo "<tr><td>$file</td> <td> <a target='_blank' href='$link'>Download</a> </td> <td>
Expand All @@ -36,6 +40,7 @@ function displayAudio()

}

if(isset($_POST['action'])):
if($_POST['action']=="Upload Audio")
{

Expand All @@ -51,13 +56,14 @@ function displayAudio()
$dest = $basepath."/audio/$fileName.wav";
move_uploaded_file($_FILES['audioFile']['tmp_name'],$tmpDest);

shell_exec('asterisk -x "file convert '. $tmpDest.' '.$dest.'"',$output);

$out=shell_exec('asterisk -rx "file convert '. $tmpDest.' '.$dest.'"');
var_dump($out);
echo "<script type='text/javascript'>alert('Audio Added Successfully');</script>";

}

}
endif;

?>
<html>
Expand Down
4 changes: 2 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[callblaster]
interval=2
interval=10
[press1]
context=from-internal
extension=104
extension=10
[press2]
context=from-internal
extension=103
14 changes: 9 additions & 5 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
//Database configuration
//.............................................
$db_host="localhost";
$db_name="callblaster";
$db_user="root";
$db_pass="passw0rd";
$db_name="asterisk";
$db_user="asteriskuser";
$db_pass="amp109";
//.............................................


//caller id and name
$caller_id="Nethram<4088271111>";
//..............................................


//paths
//..............................................

$basepath="/var/www/html/callblastergpl/";
$basepath="/var/www/html/callblaster/";

$agipath="/var/lib/asterisk/agi-bin/";

$welcomeSound = $basepath."audio/testmenu";
$welcomeSound = $basepath."audio/welcome";
//sound file without extension
//..............................................

Expand Down
Empty file added control.ini
Empty file.
26 changes: 26 additions & 0 deletions control.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

if(isset($_POST['action'])){
$condition=$_POST['action'];
if($condition=="pause"){
$reset_controls="pause=true\nstop=false";
file_put_contents('control.ini', $reset_controls);
$controls=parse_ini_file('control.ini');
print_r($controls);
}
if($condition=="start"){
$reset_controls="pause=false\nstop=false";
file_put_contents('control.ini', $reset_controls);
$controls=parse_ini_file('control.ini');
print_r($controls);
}
if($condition=="stop"){
$reset_controls="pause=false\nstop=true";
file_put_contents('control.ini', $reset_controls);
$controls=parse_ini_file('control.ini');
print_r($controls);
}


}

3 changes: 2 additions & 1 deletion demoCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
$fileName= $basepath."audio/".basename($file, $exten);


$callFile = "Channel: SIP/Sonetel/$phone\n";
$callFile = "Channel: local/$phone@from-internal\n";
$callFile .= "Application: Playback\n";
$callFile .= "CallerID: $caller_id\n";
$callFile .= "Data: $fileName\n";
file_put_contents("/tmp/demoCall.call",$callFile);
exec("mv /tmp/demoCall.call /var/spool/asterisk/outgoing/demoCall.call");
Expand Down
12 changes: 6 additions & 6 deletions downloadLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
*/

require_once("connection.php");

error_reporting(E_ALL);
ini_set('display_errors', 1);

if(isset($_REQUEST['file']))
{
$file = $_REQUEST['file'];
$file=substr($basepath,0,-1).$file;
header('Content-type: text/csv');
header("Content-disposition: attachment;filename=log.csv");


//echo $file;
//echo "<br>";
//echo $_REQUEST['file'];

$query = "select * from logs where csvFile='$file' and type='heading'";

Expand Down Expand Up @@ -62,10 +66,6 @@
echo $ret;






}


Expand Down
Loading

0 comments on commit cd2853a

Please sign in to comment.