<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.E-MailFormatvorlage18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=DE link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Brian told me to open a jira, what I did now.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>But here’s the script.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>It basically writes incoming calls to a database and removes
them after hangup.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>When intercepting it also rewrites the destination of the call.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Thanks, Klaus<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>#!/usr/bin/perl<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>use strict;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>use DBI;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>use POSIX qw(strftime);<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>our $session;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>use constant {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> false => 0,<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> true => 1,<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>};<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>my $EmptyString = "
"; # Used to delete regexp catches<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>my $dbargs = {AutoCommit => 0,<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> PrintError => 1};<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>my $dbh =
DBI->connect("dbi:SQLite:dbname=/opt/freeswitch/db/dialplan_call_info.db",
"", "", $dbargs);<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>$session->setHangupHook('on_hangup');<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>logInfo("Hook set");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub logString {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my ($Level, $Msg) = @_;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> freeswitch::consoleLog("$Level",
"$Msg\n");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub logDebug { my ($Msg) = @_; logString("DEBUG",
">>>>> $Msg"); }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub logInfo { my ($Msg) = @_; logString("INFO",
">>>>> $Msg"); }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub logNotice { my ($Msg) = @_; logString("NOTICE",
">>>>> $Msg"); }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub logWarning { my ($Msg) = @_; logString("WARNING",
">>>>> $Msg"); }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub logError { my ($Msg) = @_; logString("ERR",
">>>>> $Msg"); }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub logCritical { my ($Msg) = @_; logString("CRIT",
">>>>> $Msg"); }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub logAlert { my ($Msg) = @_; logString("ALERT",
">>>>> $Msg"); }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># The idea of these functions is to allow for easy pull in of
variables and then<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># automatically export any ones that have been changed when
UPDATEV.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># It will ensure you don't write to any non-imported variables,
but as we are<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># using a hash we cannot prevent invalid reads. If you are
really concerned about<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># this then you could use a specific read function which first
checks to make sure<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># its defined in CLEAN_VARS before returning.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>my %VARS;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>my %CLEAN_VARS;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># Takes one or more variables names to import in<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub GETV {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my @Arr = @_;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> foreach my $Var (@Arr) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $VARS{$Var} = $session->getVariable("$Var");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $CLEAN_VARS{$Var} = $VARS{$Var};<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> if (! defined $CLEAN_VARS{$Var}) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $CLEAN_VARS{$Var} = "";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># Generally not called directly, but will set the variable to
the value requested right away<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub SETV {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my ($Var, $Value) = @_;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $session->setVariable("$Var",
"$Value");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $VARS{$Var} = "$Value";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $CLEAN_VARS{$Var} = "$Value";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># If we don't care about a variables value, but wan't to
override it this will add it to the hash<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># so that when we write to it, we don't consider it a typo<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub ADDV {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my @Arr = @_;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> foreach my $Var(@Arr) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $CLEAN_VARS{$Var} = "123zzzzzZnzZZzz"; # Something
definitely won't match<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $VARS{$Var} = "";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># Updates any changed variables<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub UPDATEV {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> foreach my $Var (keys %VARS) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> # Make sure there were no typos<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> if (! defined $CLEAN_VARS{$Var}) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> die "Warning a variable of: '$Var' was not found in
CLEAN_VARS, did you forget to GET/ADD it first?";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> if ($VARS{$Var} ne $CLEAN_VARS{$Var}) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> SETV($Var, $VARS{$Var});<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># Dump all variables<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub DUMPV {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> foreach my $Var (sort keys %VARS) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> logInfo("$Var = '" . $VARS{$Var} . "'");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub CAN_ACCESS {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my ($Req) = @_;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> if ($VARS{app_rights} eq "ALL" || $VARS{app_rights}
=~ /#$Req#/) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> return true;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> } else {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> return false;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># Fetch some generic variables<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>GETV("uuid", "base_dir", "domain",
"app_rights", "de-ring",
"outgoing_soundtouch_profile", "hold_music",
"continue_on_fail");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>GETV("destination_number", "caller_id_name",
"caller_id_number", "effective_caller_id_name", "effective_caller_id_number");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>GETV("network_addr", "hangup_after_bridge",
"called_party_callgroup", "ringback",
"transfer_ringback", "sip_exclude_contact");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>GETV("call_timeout", "source",
"sip_to_params", "presence_id", "dialed_user",
"dialed_domain");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>GETV("voicemail_authorized",
"sip_authorized", "username", "accountcode",
"sip_from_user", "sip_to_user");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># Set some defaults<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>$VARS{hangup_after_bridge} = "true";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>$VARS{ringback} = $VARS{'de-ring'};<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>$VARS{transfer_ringback} = $VARS{hold_music};<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>$VARS{sip_exclude_contact} = $VARS{network_addr};<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>$VARS{call_timeout} = "60";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>$VARS{continue_on_fail} = "true"; #
NORMAL_TEMPORARY_FAILURE,USER_BUSY,NO_ANSWER,TIMEOUT,NO_ROUTE_DESTINATION<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>UPDATEV();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub bridgeCallInternally {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my ($DestNr) = @_;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> if ("${DestNr}" == "21") {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $VARS{call_timeout} = "15";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> UPDATEV();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $dbh->do("insert into current_calls (extension, uuid)
values ('$DestNr', '$VARS{uuid}')");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $dbh->commit();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>
$session->execute("record_session","\${base_dir}/recordings/\${strftime(%Y-%m-%d-%H-%M-%S)}_\${destination_number}_\${caller_id_number}.wav");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>
$session->execute("bridge","user/${DestNr}\@$VARS{domain}");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>sub on_hangup {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my $hup_session = shift;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my $hup_cause = shift;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> logInfo("Hangup uuid: '" . $hup_session->{uuid} .
"'");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> logInfo("Hangup cause: '$hup_cause'");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $dbh->do("delete from current_calls where uuid =
'" . $hup_session->{uuid} . "'");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $dbh->commit();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># Internal numbers<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>if ($VARS{destination_number} =~ /^(2[0-2])$/) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> UPDATEV();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> bridgeCallInternally($VARS{destination_number});<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'># Intercept call<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>if ($VARS{destination_number} =~ /^\*8(\d+)$/) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my $intercept_extension = "";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my $intercept_uuid = "";<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> my $sth = $dbh->prepare("select * from current_calls
where extension = ?");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $sth->execute($1);<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> while (my @data = $sth->fetchrow_array()) {<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $intercept_extension = $data[0];<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $intercept_uuid = $data[1];<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> logInfo("Intercept call from '$intercept_extension' -
'$intercept_uuid'");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> GETV("caller_id_number");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $dbh->do("update current_calls set extension =
'$VARS{caller_id_number}' where uuid = '$intercept_uuid'");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $dbh->commit();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $session->answer();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $session->execute("intercept",
"$intercept_uuid");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'> $session->execute("sleep", "1000");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>$dbh->disconnect();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Courier New";
color:#1F497D'>return 1;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
freeswitch-users-bounces@lists.freeswitch.org
[mailto:freeswitch-users-bounces@lists.freeswitch.org] <b>On Behalf Of </b>Michael
Collins<br>
<b>Sent:</b> Friday, June 26, 2009 10:57 PM<br>
<b>To:</b> freeswitch-users@lists.freeswitch.org<br>
<b>Subject:</b> Re: [Freeswitch-users] hangup hook after intercept doesn't get
triggered...<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'>Can you paste in your script so
we can see what is going on?<br>
-MC<o:p></o:p></p>
<div>
<p class=MsoNormal>On Fri, Jun 26, 2009 at 1:39 PM, Klaus Hochlehnert <<a
href="mailto:Mailings@kh-dev.de">Mailings@kh-dev.de</a>> wrote:<o:p></o:p></p>
<div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>Ok, and how can I
ask the hook to come with me?</span><o:p></o:p></p>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>If I understand this
right...</span><o:p></o:p></p>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>When a call comes in
the hook is set on the a-leg and it rings on the b-leg.</span><o:p></o:p></p>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>When I do an
intercept I kill the ringing b-leg and the interceptor is now the “new” b-leg,
right?</span><o:p></o:p></p>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>I would assume that
the “old” a-leg still has the hook on it or this wrong.</span><o:p></o:p></p>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>Thanks, Klaus</span><o:p></o:p></p>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p>
<div>
<div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0cm 0cm 0cm;
border-color:-moz-use-text-color -moz-use-text-color'>
<p><b><span style='font-size:10.0pt'>From:</span></b><span style='font-size:
10.0pt'> <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org"
target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a
href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>]
<b>On Behalf Of </b>Brian West<br>
<b>Sent:</b> Friday, June 26, 2009 10:28 PM<o:p></o:p></span></p>
<div>
<p class=MsoNormal><span style='font-size:10.0pt'><br>
<b>To:</b> <a href="mailto:freeswitch-users@lists.freeswitch.org"
target="_blank">freeswitch-users@lists.freeswitch.org</a><br>
<b>Subject:</b> Re: [Freeswitch-users] hangup hook after intercept doesn't get
triggered...<o:p></o:p></span></p>
</div>
</div>
</div>
<p> <o:p></o:p></p>
<p>well in your case I suspect your intercepting the leg of the call without
the hook on it.<o:p></o:p></p>
<div>
<div>
<div>
<p> <o:p></o:p></p>
</div>
<div>
<p>/b<o:p></o:p></p>
</div>
<div>
<p> <o:p></o:p></p>
<div>
<div>
<p>On Jun 26, 2009, at 3:22 PM, Klaus Hochlehnert wrote:<o:p></o:p></p>
</div>
<p style='margin-bottom:12.0pt'><o:p> </o:p></p>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>Actually one of my
first actions in the script is</span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>
$session->setHangupHook('on_hangup');</span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>When a call comes in
the hook is set and working.</span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>The second time the
script is called when I try to intercept. As it’s the same script there’s also
the function setHangupHook called.</span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>That’s what I’ve
currently done.</span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>How can I set up the
hook for the “new” bridge?</span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>Or is there a
possibility to set a global hook?</span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p>
</div>
<div>
<p><span lang=EN-US style='font-size:11.0pt;color:#1F497D'>Thanks, Klaus</span><o:p></o:p></p>
</div>
</div>
<p> <o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
<p class=MsoNormal style='margin-bottom:12.0pt'><br>
_______________________________________________<br>
Freeswitch-users mailing list<br>
<a href="mailto:Freeswitch-users@lists.freeswitch.org">Freeswitch-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users"
target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a
href="http://lists.freeswitch.org/mailman/options/freeswitch-users"
target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><o:p></o:p></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>