diff --git a/UPGRADE b/UPGRADE index 6a702513..3d71171c 100644 --- a/UPGRADE +++ b/UPGRADE @@ -232,6 +232,22 @@ OTHER CHANGES: 40. Added agent_status function to the non-agent API +41. Added method for logging SIP error codes, also display of those codes in the + agent screen. The logging goes to the vicidial_carrier_log and + vicidial_dial_log tables and includes both the SIP code and the reason + (i.e. 503 "Service Unavailable"). To get this to work, you need to patch + Asterisk with the extras/sipcausecodelog_1.4.39.1.patch file for + Asterisk 1.4, and for Asterisk 1.8 the patch is pending. + + cd /usr/src/asterisk/asterisk-1.4.39.1-vici + patch -p1 < ./sipcausecodelog_1.4.39.1.patch + (file to patch: channels/chan_sip.c) + make clean + ./configure + make + make install + (then stop and restart asterisk) + diff --git a/bin/AST_VDsales_export.pl b/bin/AST_VDsales_export.pl index 7ae10dfd..7cb996c0 100644 --- a/bin/AST_VDsales_export.pl +++ b/bin/AST_VDsales_export.pl @@ -1,13 +1,13 @@ #!/usr/bin/perl # -# AST_VDsales_export.pl version: 2.4 +# AST_VDsales_export.pl version: 2.6 # # This script is designed to gather sales for a VICIDIAL Outbound-only campaign and # post them to a directory # # /usr/share/astguiclient/AST_VDsales_export.pl --campaign=GOODB-GROUP1-GROUP3-GROUP4-SPECIALS-DNC_BEDS --output-format=fixed-as400 --sale-statuses=SALE --debug --filename=BEDSsaleMMDD.txt --date=yesterday --email-list=test@gmail.com --email-sender=test@test.com # -# Copyright (C) 2012 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2013 Matt Florell LICENSE: AGPLv2 # # CHANGES # 61219-1118 - First version @@ -30,6 +30,7 @@ # 110829-1045 - Changed recording lookup to try to find by vicidial_id first # 120511-2029 - Added CLI options for FTP login details # 120705-1954 - Added --temp-dir=XXX option +# 130406-2146 - Added --email-post-audio # $txt = '.txt'; @@ -58,6 +59,7 @@ $OUTtalkmin=0; $INcalls=0; $INtalk=0; $INtalkmin=0; +$email_post_audio=0; $secX = time(); $time = $secX; @@ -181,6 +183,7 @@ if (length($ARGV[0])>1) print " [--with-did-lookup] = Looks up the DID pattern and name the call came in on if possible\n"; print " [--email-list=test@test.com:test2@test.com] = send email results to these addresses\n"; print " [--email-sender=vicidial@localhost] = sender for the email results\n"; + print " [--email-post-audio] = send an email after sending audio over FTP\n"; print " [--quiet] = quiet\n"; print " [--test] = test\n"; print " [--debug] = debugging messages\n"; @@ -445,6 +448,12 @@ if (length($ARGV[0])>1) else {$email_sender = 'vicidial@localhost';} + if ($args =~ /--email-post-audio/i) + { + $email_post_audio=1; + print "\n----- EMAIL POST AUDIO: $email_post_audio -----\n\n"; + } + if ($args =~ /--ftp-server=/i) { @data_in = split(/--ftp-server=/,$args); @@ -924,6 +933,39 @@ if (!$Q) {print "TOTAL SALES: $TOTAL_SALES\n";} if (!$Q) {print "TOTAL EXCLUDED BY CALLTIME: $CALLTIME_KICK\n";} if (!$Q) {print "script execution time in seconds: $secZ minutes: $secZm\n";} +###### POST FTP EMAIL SECTION + +if ( (length($Ealert)>5) && (length($email_list) > 3) && ($email_post_audio > 0) ) + { + print "Sending post-FTP email: $email_list\n"; + + use MIME::QuotedPrint; + use MIME::Base64; + use Mail::Sendmail; + + $mailsubject = "VICIDIAL Lead Export POST AUDIO $outfile"; + + %mail = ( To => "$email_list", + From => "$email_sender", + Subject => "$mailsubject", + ); + $boundary = "====" . time() . "===="; + $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; + + $message = encode_qp( "VICIDIAL Lead Export POST AUDIO:\n\n Total Records: $TOTAL_SALES\n" ); + + $boundary = '--'.$boundary; + $mail{body} .= "$boundary\n"; + $mail{body} .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; + $mail{body} .= "Content-Transfer-Encoding: quoted-printable\n\n"; + $mail{body} .= "$message\n"; + $mail{body} .= "$boundary\n"; + $mail{body} .= "--\n"; + + sendmail(%mail) or die $mail::Sendmail::error; + print "ok. log says:\n", $mail::sendmail::log; ### print mail log for status + } + exit; diff --git a/bin/AST_inbound_email_parser.pl b/bin/AST_inbound_email_parser.pl index cc2cadcc..1a19a619 100644 --- a/bin/AST_inbound_email_parser.pl +++ b/bin/AST_inbound_email_parser.pl @@ -153,7 +153,7 @@ if($min==0) {$min=60;} $minutes=($hour*60)+$min; # $minutes=0; # Uncomment if you want to TEST ONLY, so you can test this at any time. -$stmt="select * from vicidial_email_accounts where active='Y'"; +$stmt="select email_account_id,email_account_name,email_account_description,user_group,protocol,email_replyto_address,email_account_server,email_account_user,email_account_pass,active,email_frequency_check_mins,group_id,default_list_id,call_handle_method,agent_search_method,campaign_id,list_id,email_account_type from vicidial_email_accounts where active='Y'"; $rslt=$dbhA->prepare($stmt); $rslt->execute(); diff --git a/bin/AST_manager_listen.pl b/bin/AST_manager_listen.pl index aa1acbe3..3bcdff98 100644 --- a/bin/AST_manager_listen.pl +++ b/bin/AST_manager_listen.pl @@ -38,12 +38,15 @@ # 100625-1220 - Added waitfors after logout to fix broken pipe errors in asterisk # 100903-0041 - Changed lead_id max length to 10 digits # 130108-1705 - Changes for Asterisk 1.8 compatibility +# 130412-1216 - Added sip hangup cause logging from new patch AMI event # # constants $DB=1; # Debug flag, set to 0 for no debug messages, lots of output $US='__'; $MT[0]=''; +$vdcl_update=0; +$vddl_update=0; ### begin parsing run-time options ### if (length($ARGV[0])>1) @@ -325,7 +328,7 @@ while($one_day_interval > 0) } ##### parse through all other important events ##### - if ( ($input_lines[$ILcount] =~ /State: Ringing|State: Up|State: Dialing|Event: Newstate|Event: Hangup|Event: Newcallerid|Event: Shutdown|Event: CPD-Result/) && ($input_lines[$ILcount] !~ /ZOMBIE/) ) + if ( ($input_lines[$ILcount] =~ /State: Ringing|State: Up|State: Dialing|Event: Newstate|Event: Hangup|Event: Newcallerid|Event: Shutdown|Event: CPD-Result|Event: SIP-Hangup-Cause/) && ($input_lines[$ILcount] !~ /ZOMBIE/) ) { $input_lines[$ILcount] =~ s/^\n|^\n\n//gi; @command_line=split(/\n/, $input_lines[$ILcount]); @@ -642,6 +645,72 @@ while($one_day_interval > 0) } } } + if ($input_lines[$ILcount] =~ /Event: SIP-Hangup-Cause/) + { + # Event: SIP-Hangup-Cause + # Privilege: system,all + # ChannelDriver: SIP + # Channel: SIP/paraxip-out-08291448 + # CallerIDName: M4121149450000795193 + # Uniqueid: 1233564450.141 + # Result: 603 + if ( ($command_line[3] =~ /^Channel: /i) && ($command_line[5] =~ /^Uniqueid: /i) ) + { + &get_time_now; + + $channel = $command_line[3]; + $channel =~ s/Channel: |\s*$//gi; + $callid = $command_line[4]; + $callid =~ s/CallerIDName: |\s*$//gi; + $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; + if ($callid =~ /\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S/) {$callid =~ s/ .*//gi;} + $uniqueid = $command_line[5]; + $uniqueid =~ s/Uniqueid: |\s*$//gi; + $result = $command_line[6]; + $result =~ s/Result: |\s*$//gi; + @result_details=split(/\|/, $result); + if ( (length($result)>0) && ($result_details[0] !~ /^407|^487/) ) + { + $lead_id = substr($callid, 10, 10); + $lead_id = ($lead_id + 0); + $beginUNIQUEID = $uniqueid; + $beginUNIQUEID =~ s/\..*//gi; + $stmtA = "UPDATE vicidial_dial_log SET sip_hangup_cause='$result_details[0]',sip_hangup_reason='$result_details[1]',uniqueid='$uniqueid' where caller_code='$callid' and server_ip='$server_ip' and lead_id='$lead_id';"; + print STDERR "|$stmtA|\n"; + my $affected_rows = $dbhA->do($stmtA); + if($DB){print "|$affected_rows dial_log updated|$callid|$server_ip|$result|\n";} + $vddl_update = ($vddl_update + $affected_rows); + + $preCtarget = ($beginUNIQUEID - 10); # 10 seconds before call start + ($preCsec,$preCmin,$preChour,$preCmday,$preCmon,$preCyear,$preCwday,$preCyday,$preCisdst) = localtime($preCtarget); + $preCyear = ($preCyear + 1900); + $preCmon++; + if ($preCmon < 10) {$preCmon = "0$preCmon";} + if ($preCmday < 10) {$preCmday = "0$preCmday";} + if ($preChour < 10) {$preChour = "0$preChour";} + if ($preCmin < 10) {$preCmin = "0$preCmin";} + if ($preCsec < 10) {$preCsec = "0$preCsec";} + $preCSQLdate = "$preCyear-$preCmon-$preCmday $preChour:$preCmin:$preCsec"; + + $postCtarget = ($beginUNIQUEID + 10); # 10 seconds after call start + ($postCsec,$postCmin,$postChour,$postCmday,$postCmon,$postCyear,$postCwday,$postCyday,$postCisdst) = localtime($postCtarget); + $postCyear = ($postCyear + 1900); + $postCmon++; + if ($postCmon < 10) {$postCmon = "0$postCmon";} + if ($postCmday < 10) {$postCmday = "0$postCmday";} + if ($postChour < 10) {$postChour = "0$postChour";} + if ($postCmin < 10) {$postCmin = "0$postCmin";} + if ($postCsec < 10) {$postCsec = "0$postCsec";} + $postCSQLdate = "$postCyear-$postCmon-$postCmday $postChour:$postCmin:$postCsec"; + + $stmtA = "UPDATE vicidial_carrier_log SET sip_hangup_cause='$result_details[0]',sip_hangup_reason='$result_details[1]' where server_ip='$server_ip' and lead_id='$lead_id' and call_date > \"$preCSQLdate\" and call_date < \"$postCSQLdate\" order by call_date desc limit 1;"; + print STDERR "|$stmtA|\n"; + my $affected_rows = $dbhA->do($stmtA); + if($DB){print "|$affected_rows carrier_log updated|$callid|$server_ip|$uniqueid|$result_details[0]|$result_details[1]|\n";} + $vdcl_update = ($vdcl_update + $affected_rows); + } + } + } } $ILcount++; } @@ -651,7 +720,7 @@ while($one_day_interval > 0) $endless_loop--; $keepalive_count_loop++; - if($DB){print STDERR "loop counter: |$endless_loop|$keepalive_count_loop|\r";} + if($DB){print STDERR "loop counter: |$endless_loop|$keepalive_count_loop| |$vddl_update|$vdcl_update|\r";} ### putting a blank file called "sendmgr.kill" in a directory will automatically safely kill this program if ( (-e "$PATHhome/listenmgr.kill") or ($sendonlyone) ) @@ -817,7 +886,7 @@ while($one_day_interval > 0) } ##### parse through all other important events ##### - if ( ($input_lines[$ILcount] =~ /Event: Newstate|Event: Hangup|Event: NewCallerid|Event: Shutdown|Event: CPD-Result/) && ($input_lines[$ILcount] !~ /ZOMBIE/) ) + if ( ($input_lines[$ILcount] =~ /Event: Newstate|Event: Hangup|Event: NewCallerid|Event: Shutdown|Event: CPD-Result|Event: SIP-Hangup-Cause/) && ($input_lines[$ILcount] !~ /ZOMBIE/) ) { $input_lines[$ILcount] =~ s/^\n|^\n\n//gi; @command_line=split(/\n/, $input_lines[$ILcount]); @@ -982,6 +1051,72 @@ while($one_day_interval > 0) } } } + if ($input_lines[$ILcount] =~ /Event: SIP-Hangup-Cause/) + { + # Event: SIP-Hangup-Cause + # Privilege: system,all + # ChannelDriver: SIP + # Channel: SIP/paraxip-out-08291448 + # CallerIDName: M4121149450000795193 + # Uniqueid: 1233564450.141 + # Result: 603 + if ( ($command_line[2] =~ /^Channel: /i) && ($command_line[4] =~ /^Uniqueid: /i) ) + { + &get_time_now; + + $channel = $command_line[2]; + $channel =~ s/Channel: |\s*$//gi; + $callid = $command_line[3]; + $callid =~ s/CallerIDName: |\s*$//gi; + $callid =~ s/^\"//gi; $callid =~ s/\".*$//gi; + if ($callid =~ /\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S\S/) {$callid =~ s/ .*//gi;} + $uniqueid = $command_line[4]; + $uniqueid =~ s/Uniqueid: |\s*$//gi; + $result = $command_line[5]; + $result =~ s/Result: |\s*$//gi; + @result_details=split(/\|/, $result); + if ( (length($result)>0) && ($result_details[0] !~ /^407|^487/) ) + { + $lead_id = substr($callid, 10, 10); + $lead_id = ($lead_id + 0); + $beginUNIQUEID = $uniqueid; + $beginUNIQUEID =~ s/\..*//gi; + $stmtA = "UPDATE vicidial_dial_log SET sip_hangup_cause='$result_details[0]',sip_hangup_reason='$result_details[1]',uniqueid='$uniqueid' where caller_code='$callid' and server_ip='$server_ip' and lead_id='$lead_id';"; + print STDERR "|$stmtA|\n"; + my $affected_rows = $dbhA->do($stmtA); + if($DB){print "|$affected_rows dial_log updated|$callid|$server_ip|$result|\n";} + $vddl_update = ($vddl_update + $affected_rows); + + $preCtarget = ($beginUNIQUEID - 10); # 10 seconds before call start + ($preCsec,$preCmin,$preChour,$preCmday,$preCmon,$preCyear,$preCwday,$preCyday,$preCisdst) = localtime($preCtarget); + $preCyear = ($preCyear + 1900); + $preCmon++; + if ($preCmon < 10) {$preCmon = "0$preCmon";} + if ($preCmday < 10) {$preCmday = "0$preCmday";} + if ($preChour < 10) {$preChour = "0$preChour";} + if ($preCmin < 10) {$preCmin = "0$preCmin";} + if ($preCsec < 10) {$preCsec = "0$preCsec";} + $preCSQLdate = "$preCyear-$preCmon-$preCmday $preChour:$preCmin:$preCsec"; + + $postCtarget = ($beginUNIQUEID + 10); # 10 seconds after call start + ($postCsec,$postCmin,$postChour,$postCmday,$postCmon,$postCyear,$postCwday,$postCyday,$postCisdst) = localtime($postCtarget); + $postCyear = ($postCyear + 1900); + $postCmon++; + if ($postCmon < 10) {$postCmon = "0$postCmon";} + if ($postCmday < 10) {$postCmday = "0$postCmday";} + if ($postChour < 10) {$postChour = "0$postChour";} + if ($postCmin < 10) {$postCmin = "0$postCmin";} + if ($postCsec < 10) {$postCsec = "0$postCsec";} + $postCSQLdate = "$postCyear-$postCmon-$postCmday $postChour:$postCmin:$postCsec"; + + $stmtA = "UPDATE vicidial_carrier_log SET sip_hangup_cause='$result_details[0]',sip_hangup_reason='$result_details[1]' where server_ip='$server_ip' and lead_id='$lead_id' and call_date > \"$preCSQLdate\" and call_date < \"$postCSQLdate\" order by call_date desc limit 1;"; + print STDERR "|$stmtA|\n"; + my $affected_rows = $dbhA->do($stmtA); + if($DB){print "|$affected_rows carrier_log updated|$callid|$server_ip|$uniqueid|$result_details[0]|$result_details[1]|\n";} + $vdcl_update = ($vdcl_update + $affected_rows); + } + } + } } $ILcount++; } @@ -991,7 +1126,7 @@ while($one_day_interval > 0) $endless_loop--; $keepalive_count_loop++; - if($DB){print STDERR "loop counter: |$endless_loop|$keepalive_count_loop|\r";} + if($DB){print STDERR "loop counter: |$endless_loop|$keepalive_count_loop| |$vddl_update|$vdcl_update|\r";} ### putting a blank file called "sendmgr.kill" in a directory will automatically safely kill this program if ( (-e "$PATHhome/listenmgr.kill") or ($sendonlyone) ) diff --git a/bin/FastAGI_log.pl b/bin/FastAGI_log.pl index da75aad4..19c1bf32 100644 --- a/bin/FastAGI_log.pl +++ b/bin/FastAGI_log.pl @@ -25,7 +25,7 @@ # exten => h,1,DeadAGI(agi://127.0.0.1:4577/call_log--HVcauses--PRI-----NODEBUG-----${HANGUPCAUSE}-----${DIALSTATUS}-----${DIALEDTIME}-----${ANSWEREDTIME}) # # -# Copyright (C) 2012 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2013 Matt Florell LICENSE: AGPLv2 # # CHANGELOG: # 61010-1007 - First test build @@ -64,6 +64,7 @@ # 121120-0922 - Added QM socket-send functionality # 121124-2303 - Added Other Campaign DNC option # 121129-2322 - Added enhanced_disconnect_logging option +# 130412-1321 - Added sip_hangup_cause to carrier log # # defaults for PreFork @@ -588,10 +589,10 @@ sub process_request if ($carrier_logging_active > 0) { + $beginUNIQUEID = $unique_id; + $beginUNIQUEID =~ s/\..*//gi; if ($callerid =~ /^M/) { - $beginUNIQUEID = $unique_id; - $beginUNIQUEID =~ s/\..*//gi; $stmtA = "SELECT uniqueid FROM call_log where uniqueid LIKE \"$beginUNIQUEID%\" and caller_code LIKE \"%$CIDlead_id\";"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -605,10 +606,50 @@ sub process_request } $sthA->finish(); } - $stmtA = "INSERT IGNORE INTO vicidial_carrier_log set uniqueid='$uniqueid',call_date='$now_date',server_ip='$VARserver_ip',lead_id='$CIDlead_id',hangup_cause='$hangup_cause',dialstatus='$dialstatus',channel='$channel',dial_time='$dial_time',answered_time='$answered_time';"; + $sip_hangup_cause=0; + $sip_hangup_reason=''; + + + + $preCtarget = ($beginUNIQUEID - 10); # 10 seconds before call start + ($preCsec,$preCmin,$preChour,$preCmday,$preCmon,$preCyear,$preCwday,$preCyday,$preCisdst) = localtime($preCtarget); + $preCyear = ($preCyear + 1900); + $preCmon++; + if ($preCmon < 10) {$preCmon = "0$preCmon";} + if ($preCmday < 10) {$preCmday = "0$preCmday";} + if ($preChour < 10) {$preChour = "0$preChour";} + if ($preCmin < 10) {$preCmin = "0$preCmin";} + if ($preCsec < 10) {$preCsec = "0$preCsec";} + $preCSQLdate = "$preCyear-$preCmon-$preCmday $preChour:$preCmin:$preCsec"; + + $postCtarget = ($beginUNIQUEID + 10); # 10 seconds after call start + ($postCsec,$postCmin,$postChour,$postCmday,$postCmon,$postCyear,$postCwday,$postCyday,$postCisdst) = localtime($postCtarget); + $postCyear = ($postCyear + 1900); + $postCmon++; + if ($postCmon < 10) {$postCmon = "0$postCmon";} + if ($postCmday < 10) {$postCmday = "0$postCmday";} + if ($postChour < 10) {$postChour = "0$postChour";} + if ($postCmin < 10) {$postCmin = "0$postCmin";} + if ($postCsec < 10) {$postCsec = "0$postCsec";} + $postCSQLdate = "$postCyear-$postCmon-$postCmday $postChour:$postCmin:$postCsec"; + + $stmtA = "SELECT sip_hangup_cause,sip_hangup_reason FROM vicidial_dial_log where lead_id='$CIDlead_id' and server_ip='$VARserver_ip' and call_date > \"$preCSQLdate\" and call_date < \"$postCSQLdate\" order by call_date desc;"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $sip_hangup_cause = $aryA[0]; + $sip_hangup_reason = $aryA[1]; + } + $sthA->finish(); + + $stmtA = "INSERT IGNORE INTO vicidial_carrier_log set uniqueid='$uniqueid',call_date='$now_date',server_ip='$VARserver_ip',lead_id='$CIDlead_id',hangup_cause='$hangup_cause',dialstatus='$dialstatus',channel='$channel',dial_time='$dial_time',answered_time='$answered_time',sip_hangup_cause='$sip_hangup_cause',sip_hangup_reason='$sip_hangup_reason';"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $VCARaffected_rows = $dbhA->do($stmtA); - if ($AGILOG) {$agi_string = "-- CARRIER LOG insert: |$VCARaffected_rows|$CIDlead_id|$hangup_cause"; &agi_output;} + if ($AGILOG) {$agi_string = "-- CARRIER LOG insert: |$VCARaffected_rows|$CIDlead_id|$hangup_cause|$sip_hangup_cause|$sip_hangup_reason|"; &agi_output;} } } } @@ -920,7 +961,10 @@ sub process_request } $sthA->finish(); - $stmtA = "INSERT INTO vicidial_log SET uniqueid='$uniqueid',lead_id='$VD_lead_id',list_id='$VD_list_id',status='$VDL_status',campaign_id='$VD_campaign_id',call_date='$VD_call_time',start_epoch='$VD_start_epoch',phone_code='$VD_phone_code',phone_number='$VD_phone_number',user='VDAD',processed='N',length_in_sec='0',end_epoch='$VD_start_epoch',alt_dial='$VD_alt_dial';"; + $vl_commentsSQL = ''; + if ($callerid =~ /^M\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + {$vl_commentsSQL=",comments='MANUAL'";} + $stmtA = "INSERT INTO vicidial_log SET uniqueid='$uniqueid',lead_id='$VD_lead_id',list_id='$VD_list_id',status='$VDL_status',campaign_id='$VD_campaign_id',call_date='$VD_call_time',start_epoch='$VD_start_epoch',phone_code='$VD_phone_code',phone_number='$VD_phone_number',user='VDAD',processed='N',length_in_sec='0',end_epoch='$VD_start_epoch',alt_dial='$VD_alt_dial' $vl_commentsSQL;"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $VDLIaffected_rows = $dbhA->do($stmtA); if ($AGILOG) {$agi_string = "-- VDAD vicidial_log insert: |$VDLIaffected_rows|$uniqueid|$CIDlead_id|$VDL_status|"; &agi_output;} diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index 05c5cea9..47a6d875 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -1998,7 +1998,10 @@ dialstatus VARCHAR(16), channel VARCHAR(100), dial_time SMALLINT(3) UNSIGNED default '0', answered_time SMALLINT(4) UNSIGNED default '0', -index (call_date) +sip_hangup_cause SMALLINT(4) UNSIGNED default '0', +sip_hangup_reason VARCHAR(50) default '', +index (call_date), +index (lead_id) ); CREATE TABLE vicidial_list_update_log ( @@ -2709,7 +2712,11 @@ channel VARCHAR(100) default '', context VARCHAR(100) default '', timeout MEDIUMINT(7) UNSIGNED default '0', outbound_cid VARCHAR(100) default '', +sip_hangup_cause SMALLINT(4) UNSIGNED default '0', +sip_hangup_reason VARCHAR(50) default '', +uniqueid VARCHAR(20) default '', index (caller_code), +index (lead_id), index (call_date) ); @@ -3097,4 +3104,4 @@ UPDATE vicidial_configuration set value='1766' where name='qc_database_version'; UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1341',db_schema_update_date=NOW(); +UPDATE system_settings SET db_schema_version='1342',db_schema_update_date=NOW(); diff --git a/extras/upgrade_2.6.sql b/extras/upgrade_2.6.sql index cfee4d5b..4bbd3770 100644 --- a/extras/upgrade_2.6.sql +++ b/extras/upgrade_2.6.sql @@ -313,3 +313,20 @@ UPDATE system_settings SET db_schema_version='1340',db_schema_update_date=NOW() ALTER TABLE system_settings ADD level_8_disable_add ENUM('0','1') default '0'; UPDATE system_settings SET db_schema_version='1341',db_schema_update_date=NOW() where db_schema_version < 1341; + +ALTER TABLE vicidial_dial_log ADD sip_hangup_cause SMALLINT(4) UNSIGNED default '0'; +ALTER TABLE vicidial_dial_log_archive ADD sip_hangup_cause SMALLINT(4) UNSIGNED default '0'; +ALTER TABLE vicidial_dial_log ADD sip_hangup_reason VARCHAR(50) default ''; +ALTER TABLE vicidial_dial_log_archive ADD sip_hangup_reason VARCHAR(50) default ''; +ALTER TABLE vicidial_dial_log ADD uniqueid VARCHAR(20) default ''; +ALTER TABLE vicidial_dial_log_archive ADD uniqueid VARCHAR(20) default ''; + +ALTER TABLE vicidial_carrier_log ADD sip_hangup_cause SMALLINT(4) UNSIGNED default '0'; +ALTER TABLE vicidial_carrier_log_archive ADD sip_hangup_cause SMALLINT(4) UNSIGNED default '0'; +ALTER TABLE vicidial_carrier_log ADD sip_hangup_reason VARCHAR(50) default ''; +ALTER TABLE vicidial_carrier_log_archive ADD sip_hangup_reason VARCHAR(50) default ''; + +CREATE INDEX vddllid on vicidial_dial_log (lead_id); +CREATE INDEX vdcllid on vicidial_carrier_log (lead_id); + +UPDATE system_settings SET db_schema_version='1342',db_schema_update_date=NOW() where db_schema_version < 1342; diff --git a/www/agc/vdc_db_query.php b/www/agc/vdc_db_query.php index 324e5961..67dc9058 100644 --- a/www/agc/vdc_db_query.php +++ b/www/agc/vdc_db_query.php @@ -326,10 +326,11 @@ # 130328-0009 - Converted ereg to preg functions # 130328-1015 - Added validation for agent manual dial permission on DIAL links # 130402-2242 - Added user_group variable to _call_url functions +# 130412-1348 - Added SIP cause code display on failed calls # -$version = '2.6-224'; -$build = '130402-2242'; +$version = '2.6-225'; +$build = '130412-1348'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=533; $one_mysql_log=0; @@ -666,6 +667,66 @@ $hangup_cause_dictionary = array( 127 => "Interworking, unspecified." ); +##### SIP Hangup Cause Dictionary ##### +$sip_hangup_cause_dictionary = array( +400 => "Bad Request.", +401 => "Unauthorized.", +402 => "Payment Required.", +403 => "Forbidden.", +404 => "Not Found.", +405 => "Method Not Allowed.", +406 => "Not Acceptable.", +407 => "Proxy Authentication Required.", +408 => "Request Timeout.", +409 => "Conflict.", +410 => "Gone.", +411 => "Length Required.", +412 => "Conditional Request Failed.", +413 => "Request Entity Too Large.", +414 => "Request-URI Too Long.", +415 => "Unsupported Media Type.", +416 => "Unsupported URI Scheme.", +417 => "Unknown Resource-Priority.", +420 => "Bad Extension.", +421 => "Extension Required.", +422 => "Session Interval Too Small.", +423 => "Interval Too Brief.", +424 => "Bad Location Information.", +428 => "Use Identity Header.", +429 => "Provide Referrer Identity.", +433 => "Anonymity Disallowed.", +436 => "Bad Identity-Info.", +437 => "Unsupported Certificate.", +438 => "Invalid Identity Header.", +470 => "Consent Needed.", +480 => "Temporarily Unavailable.", +481 => "Call/Transaction Does Not Exist.", +482 => "Loop Detected..", +483 => "Too Many Hops.", +484 => "Address Incomplete.", +485 => "Ambiguous.", +486 => "Busy Here.", +487 => "Request Terminated.", +488 => "Not Acceptable Here.", +489 => "Bad Event.", +491 => "Request Pending.", +493 => "Undecipherable.", +494 => "Security Agreement Required.", +500 => "Server Internal Error.", +501 => "Not Implemented.", +502 => "Bad Gateway.", +503 => "Service Unavailable.", +504 => "Server Time-out.", +505 => "Version Not Supported.", +513 => "Message Too Large.", +580 => "Precondition Failure.", +600 => "Busy Everywhere.", +603 => "Decline.", +604 => "Does Not Exist Anywhere.", +606 => "Not Acceptable." +); + + ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### @@ -3565,7 +3626,7 @@ if ($ACTION == 'manDiaLlookCaLL') $end_epoch = $row[2]; ### Check carrier log for error - $stmt="SELECT dialstatus,hangup_cause FROM vicidial_carrier_log where uniqueid='$uniqueid' and server_ip='$server_ip' and channel='$channel' and dialstatus IN('BUSY','CHANUNAVAIL','CONGESTION') LIMIT 1;"; + $stmt="SELECT dialstatus,hangup_cause,sip_hangup_cause,sip_hangup_reason FROM vicidial_carrier_log where uniqueid='$uniqueid' and server_ip='$server_ip' and channel='$channel' and dialstatus IN('BUSY','CHANUNAVAIL','CONGESTION') LIMIT 1;"; $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00292',$user,$server_ip,$session_name,$one_mysql_log);} if ($DB) {echo "$stmt\n";} @@ -3573,13 +3634,24 @@ if ($ACTION == 'manDiaLlookCaLL') if ($CL_mancall_ct > 0) { $row=mysql_fetch_row($rslt); - $dialstatus =$row[0]; - $hangup_cause =$row[1]; - + $dialstatus = $row[0]; + $hangup_cause = $row[1]; + $sip_hangup_cause = $row[2]; + $sip_hangup_reason = $row[3]; + $channel = $dialstatus; $hangup_cause_msg = "Cause: " . $hangup_cause . " - " . hangup_cause_description($hangup_cause); + $sip_hangup_cause_msg=''; + if (strlen($sip_hangup_cause) > 1) + { + $sip_hangup_cause_msg = "SIP: " . $sip_hangup_cause . " - "; + if (strlen($sip_hangup_reason) < 2) + {$sip_hangup_cause_msg .= sip_hangup_cause_description($sip_hangup_cause);} + else + {$sip_hangup_cause_msg .= $sip_hangup_reason;} + } - $call_output = "$uniqueid\n$channel\nERROR\n" . $hangup_cause_msg; + $call_output = "$uniqueid\n$channel\nERROR\n" . $hangup_cause_msg . "\n
" . $sip_hangup_cause_msg; $call_good++; ### Delete call record @@ -8147,14 +8219,14 @@ if ($ACTION == 'updateDISPO') if ( ($auto_dial_level < 1) or (preg_match('/^M/',$MDnextCID)) ) { - $stmt = "SELECT count(*) from vicidial_log where lead_id='$lead_id' and user='$user' and call_date > \"$four_hours_ago\";"; + $stmt = "SELECT count(*) from vicidial_log where lead_id='$lead_id' and call_date > \"$four_hours_ago\" and ( (user='$user') or ( (comments='MANUAL') and status IN('AB','ADC','ADCT') ) );"; if ($format=='debug') {echo "\n";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00213',$user,$server_ip,$session_name,$one_mysql_log);} $row=mysql_fetch_row($rslt); if ($row[0] > 0) { - $stmt="UPDATE vicidial_log set status='$log_dispo_choice' where lead_id='$lead_id' and user='$user' and call_date > \"$four_hours_ago\" order by uniqueid desc limit 1;"; + $stmt="UPDATE vicidial_log set status='$log_dispo_choice',user='$user' where lead_id='$lead_id' and call_date > \"$four_hours_ago\" and ( (user='$user') or ( (comments='MANUAL') and status IN('AB','ADC','ADCT') ) ) order by uniqueid desc limit 1;"; if ($format=='debug') {echo "\n";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00145',$user,$server_ip,$session_name,$one_mysql_log);} @@ -12127,5 +12199,12 @@ function hangup_cause_description($code) else { return "Unidentified Hangup Cause Code."; } } +##### SIP Hangup Cause Description Map ##### +function sip_hangup_cause_description($sip_code) + { + global $sip_hangup_cause_dictionary; + if ( array_key_exists($sip_code,$sip_hangup_cause_dictionary) ) { return $sip_hangup_cause_dictionary[$sip_code]; } + else { return "Unidentified SIP Hangup Cause Code."; } + } ?> diff --git a/www/agc/vicidial.php b/www/agc/vicidial.php index e4aee9aa..4cd162cf 100644 --- a/www/agc/vicidial.php +++ b/www/agc/vicidial.php @@ -398,10 +398,11 @@ # 130328-0934 - Applied changes from Issue #655 # 130328-1017 - Added validation for agent manual dial permission on DIAL links # 130402-2250 - Added user_group variable in scripts, forms and webforms +# 130412-1359 - Added SIP message for failed calls # -$version = '2.6-366c'; -$build = '130402-2250'; +$version = '2.6-367c'; +$build = '130412-1359'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=79; $one_mysql_log=0; @@ -6745,7 +6746,8 @@ function set_length(SLnumber,SLlength_goal,SLdirection) if (XDalert == 'ERROR') { var XDerrorDesc = MDlookResponse_array[3]; - var DiaLAlerTMessagE = "Call Rejected: " + XDchannel + "\n" + XDerrorDesc; + var XDerrorDescSIP = MDlookResponse_array[4]; + var DiaLAlerTMessagE = "Call Rejected: " + XDchannel + "\n" + XDerrorDesc + "\n" + XDerrorDescSIP; TimerActionRun("DiaLAlerT",DiaLAlerTMessagE); } if ( (XDchannel.match(regMDL)) && (asterisk_version != '1.0.8') && (asterisk_version != '1.0.9') && (MD_ring_secondS < 10) ) @@ -6797,7 +6799,8 @@ function set_length(SLnumber,SLlength_goal,SLdirection) if (MDalert == 'ERROR') { var MDerrorDesc = MDlookResponse_array[3]; - var DiaLAlerTMessagE = "Call Rejected: " + MDchannel + "\n" + MDerrorDesc; + var MDerrorDescSIP = MDlookResponse_array[4]; + var DiaLAlerTMessagE = "Call Rejected: " + MDchannel + "\n" + MDerrorDesc + "\n" + MDerrorDescSIP; TimerActionRun("DiaLAlerT",DiaLAlerTMessagE); } if ( (MDchannel.match(regMDL)) && (asterisk_version != '1.0.8') && (asterisk_version != '1.0.9') )