Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

lunes, 28 de diciembre de 2015

routing AGI queue freepbx

1-Create FreePBX virtual DID.

2-Route Virutal DID  to Queues or the desired destination.

3-On the DB there  is  colum called support_level(interger) that number match the Virtual DID

4- made a  custom destination or misc destination to the  agi

So based on  the query result we made a goto to the support level queue


[from-internal-custom]
exten=>101013,1,Agi(ivr.php)
same=>n,Hangup()


;;IVR AGI
#!/usr/bin/php -q

<?php
set_time_limit(30);
require('/var/lib/asterisk/agi-bin/phpagi-2.20/phpagi.php');
error_reporting(E_ALL);
$agi = new AGI();
$agi->answer();
$cid = $agi->parse_callerid();

$agi->stream_file("welcome");
$agi->stream_file("thank-you-for-calling");

$agi->exec("sayalpha","$cid[username]");

 $result = $agi->get_data('agent-pass',8000,5);

$keys = $result['result'];
if($keys){

$agi->stream_file("you-entered");

$agi->exec("sayalpha","$keys");

}

$setting=array("username"=>"root","password"=>"7816","host"=>"localhost","db"=>"test");

$link = mysqli_connect($setting["host"],$setting["username"],$setting["password"],$setting["db"]);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if ($keys){

$query="select * from customer_company where customer_id='$keys' limit 1";


if ($result = mysqli_query($link, $query)) {

    if   ($row = mysqli_fetch_assoc($result)) {


   $agi->stream_file("auth-thankyou");

/* route the call to the virtual DID based on support_level */

$agi->exec_goto('from-trunk',$row[support_level],1);
 }

      else {
$agi->stream_file("pin-invalid");


 }


   // printf(" Query failed: %s\n",mysqli_error($link));

}

}


else {
$agi->stream_file("im-sorry");


}

/* close connection */
mysqli_close($link);


?>








domingo, 27 de diciembre de 2015

ami alert

#!/usr/bin/php
<?php
require("setting.php");

$socket = fsockopen($host,"5038", $errno, $errstr,10);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: $username\r\n");
            fputs($socket, "Secret: $secret\r\n\r\n");
            fputs($socket, "Action: WaitEvent\r\n");
            fputs($socket, "Action: Logoff\r\n\r\n");

   while(!feof($socket)){

  $result=fread($socket,5000);
  $result.=date("Y-m-d H:i:s");

$events=array("HangupRequest","MusicOnHoldStart","MusicOnHoldStop");


foreach($events as $value) {

if (preg_match("/\b$value\b/i", $result, $match)){


if (preg_match("/\bHangupRequest\b/i", $result, $match)){

$elements=explode("\n",$result);

foreach($elements as $key=>$value) {
echo "$key $value\n";
$message="You have  missed call from number $elements[5]\n to extension $elements[7] at $elements[17]";
}

$num=explode(" ",$elements[5]);
$extensions=array(1001,101,1005);

if(in_array($num[1],$extensions)){

mail("ambiorixg12@gmail.com","  You have a missed call from $num[1]",$message);
}


}

}

continue;


}

}

}

fclose($socket);

?>

FreePBX Disabling Voicemail standard Prompt



Settings> Voicemail Admin> DialPlan Behaviour uncheck "Disable Standard Prompt"

http://community.freepbx.org/t/do-not-play-please-leave-message-after-tone-voicemail/16654

sábado, 26 de diciembre de 2015

Daily Call counter

Sucessfully conected to the database asterisk
TOTALCLIDDestinationDurationcontextCalldate
2"102" <004368>009142599811431internal2015-12-27 00:52:09

<?php

require_once("func.php");
require_once("setting.php");
$titles=Array("TOTAL","CLID","Destination","Duration","context","Calldate");

$record=array("total","clid","dst","billsec","dcontext","calldate");

$query="select Distinct count(dst) as total,billsec,clid,dst,dcontext,calldate  from cdr where SUBSTRING(calldate,1,10)=curdate() and dcontext like '%internal%' group by src";

$db_con=conect_db($setting[host],$setting[username],$setting[password],"asterisk");

table($titles);

display_records($db_con,$query,$record);


?>




viernes, 25 de diciembre de 2015

Starting fail2ban: ERROR Found no accessible config files for 'filter.d/freepbx' under /etc/fail2ban


Remove fail2ban and make sure  freepbx commercial repo are enables

[root@vultr etc]# yum remove fail2ban


Then install freepbx from the repo called  schmooze-commercial
issue this command


[root@vultr etc]#yum --disablerepo="*" --enablerepo="schmooze-commercial" install fail2ban





[root@vultr etc]# yum repolist
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirror.dattobackup.com
 * epel: ftp.osuosl.org
 * extras: mirrors.lga7.us.voxel.net
 * updates: centos.mirror.constant.com
repo id                                                                                repo name                                                                                        

                status
base                                                                                   CentOS-6 - Base                                                                                  

                 6,575
epel                                                                                   Extra Packages for Enterprise Linux 6 - x86_64                                                  

                11,836
extras                                                                                 CentOS-6 - Extras                                                                                

                    48
schmooze-commercial                                                                    schmooze-commercial                                                                              

                   163
updates                                                                                CentOS-6 - Updates                                                                              

                   958
repolist: 19,580


[root@vultr etc]# service fail2ban start

jueves, 24 de diciembre de 2015

Admin Interface logs you out on selection of any menu option



p_lindheimerPhilippe Lindheimer added a comment - 17/Feb/12 7:44 PM
note the permission denied errors? Did you use the scripts to upgrade PHP, that is your problem as php breaks ownership of these for the apache user.
We have updated amportal to fix this (even though it's not a FreePBX issue). If you are up-to-date with framework, executing "amportal chown" should fix the ownership issue.

VoIPTekVoIPTek added a comment - 17/Feb/12 11:30 PM
FYI yes, did update PHP as per Tony using "yum install php *".
The chown did fix the problem on one of the servers.
Thanks!

pmonevpmonev added a comment - 15/Aug/12 9:32 PM
Look at your httpd log files to find messages like this:
[Aug 15 14:06:57 2012|Wed] [error] [192.168.24.139|client] PHP Warning: session_start(): open(/var/lib/php/session/sess_q370hsbon837v7a2cuhvj2r7t7, O_RDWR) failed: Permission denied (13) in /apps/www/amp/docs/admin/config.php on line 71, referer: http://asterisk1.mventix.com/admin/config.php
Then from the terminal do:
rm -f /var/lib/php/session/sess_q370hsbon837v7a2cuhvj2r7t7
Make sure to replace sess_q370hsbon837v7a2cuhvj2r7t7 with the session that is in your log files.
/etc/init.d/httpd restart
That fixed my problem.

miércoles, 23 de diciembre de 2015

Missed call notification and hold and un hold notificator

php missed.php > /dev/null 2 &



#!/usr/bin/php
<?php
require("setting.php");

$socket = fsockopen($host,"5038", $errno, $errstr,10);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: $username\r\n");
            fputs($socket, "Secret: $secret\r\n\r\n");
            fputs($socket, "Action: WaitEvent\r\n");
            fputs($socket, "Action: Logoff\r\n\r\n");

   while(!feof($socket)){

  $result=fread($socket,5000);
  $result.=date("Y-m-d H:i:s");

$events=array("SoftHangupRequest","Hold","Unhold");


foreach($events as $value) {

if (preg_match("/\b$value\b/i", $result, $match)){

if (preg_match("/\bRing\b/i", $result, $match)){

echo $result;



mail("ambiorixg12@gmail.com","You have a missed call",$result);


}



if (preg_match("/\bHold\b/i", $result, $match)){

echo $result;



mail("ambiorixg12@gmail.com","Call is Unhold",$result);


}

if (preg_match("/\bUnhold\b/i", $result, $match)){

echo $result;



mail("ambiorixg12@gmail.com","Caller Has been Onhold",$result);

}


}
continue;


}

}

}

fclose($socket);

?>

martes, 22 de diciembre de 2015

setting random callerid

Easy Hard Way
[rand-cid]
exten=>_x.,1,Noop(Let's change  cid ${CALLERID(num)})
same=>n,Set(cid=${RAND(1000,9999)})
same=>n,Set(area=${EXTEN:1:6})
same=>n,Noop(new cid is ${area}${cid} )
same=>n,Set(CALLERID(num)=${area}${cid})
same=>n,Return(${CALLERID(num)})


[outbound]
exten=>_008.,1,Gosub(rand-cid,${EXTEN:3},1)
same=>n,Dial(SIP/rapidvox/${EXTEN:3})
same=>n,Hangup()


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
easy way
[random-cid]
exten=>_1nxxnxxxxxx,1,Noop(catching the caller id ${CALLERID(num)})
same=>n,Set(cid=${RAND(1000,9999)})
same=>n,Set(area=${EXTEN:1:6})
same=>n,Noop(new cid is ${area}${cid} )
same=>n,Set(CALLERID(num)=${area}${cid})
same=>n,Dial(SIP/rapidvox/${EXTEN})

Asterisk Rand Function

RAND()

RAND(min,max)
(beginning Asterisk 1.4)
Returns a randomly-generated number between min and max inclusive. The default for min is 0, for max the default is the largest integer supported by the system (usually 2147483647).
; Choose a random number between 1 and 10 (inclusive):
exten => 123,1,Set(coincidence=${RAND(1,10)})

; Game of chance:
exten => 123,1,GotoIf($[${RAND(0,100)} < 25]?won:lost)
exten => won,1,Playback(won)
exten => won,n,Goto(123,1)
exten => lost,1,Playback(lost)
exten => lost,n,Goto(123,1)

lunes, 21 de diciembre de 2015

PHPAGI MYSQLI

#!/usr/bin/php -q
<?php
set_time_limit(30);
require('/var/lib/asterisk/agi-bin/phpagi-2.20/phpagi.php');
error_reporting(E_ALL);
$agi = new AGI();
$agi->answer();
$cid = $agi->parse_callerid();
$agi->stream_file("welcome");
$agi->exec("sayalpha","$cid[username]");

 $result = $agi->get_data('agent-pass',8000,3);

$keys = $result['result'];
if($keys){
$agi->stream_file("you-entered");

$agi->exec("sayalpha","$keys");

}

$setting=array("username"=>"root","password"=>"11234","host"=>"localhost","db"=>"asterisk");

$link = mysqli_connect($setting["host"],$setting["username"],$setting["password"],$setting["db"]);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if ($keys){
$query = "select dst from cdr where  src='$keys' order by calldate desc limit 1";



if ($result = mysqli_query($link, $query)) {


    if ($row = mysqli_fetch_assoc($result)) {
$agi->exec("sayalpha","$row[dst]");

 }

      else {
$agi->stream_file("pin-invalid");


 }


   // printf(" Query failed: %s\n",mysqli_error($link));

}

}
 

else {
$agi->stream_file("im-sorry");

 
}

/* close connection */
mysqli_close($link);


?>

domingo, 20 de diciembre de 2015

event alert email

#!/usr/bin/php
<?php
require("setting.php");

$socket = fsockopen($host,"5038", $errno, $errstr,10);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: $username\r\n");
            fputs($socket, "Secret: $secret\r\n\r\n");
            fputs($socket, "Action: WaitEvent\r\n");
            fputs($socket, "Action: Logoff\r\n\r\n");

   while(!feof($socket)){

  $result=fread($socket,5000);
  $result.=date("Y-m-d H:i:s");
$events=array("SoftHangupRequest","Newchannel","ChallengeResponseFailed","InvalidPassword","InvalidAccountID","Hold","Unhold");


foreach($events as $value) {


if (preg_match("/\b$value\b/i", $result, $match)){

echo "$result\n";



if (preg_match("/\bHold\b/i", $result, $match)){

echo "$result\n";



mail("ambiorixg12@gmail.com","Call is Unhold",$result);


}

if (preg_match("/\bUnhold\b/i", $result, $match)){

echo "$result\n";



mail("ambiorixg12@gmail.com","Caller Has been Onhold",$result);


}


}
continue;


}

}

}

fclose($socket);

?>


viernes, 18 de diciembre de 2015

claro sip trunk routing table

10.0.0.254 (sip trunk gateway)
10.0.0.253 (internet gateway)
172.31.21.1 SIP trunk IP ( this provide signaling)
172.31.21.254 SIP trunk Media Server (This provide audio)

nano /etc/rc.local


/sbin/route add -host 172.31.21.1 gw 10.0.0.254 dev eth0
/sbin/route add -host 172.31.21.254 gw 10.0.0.254 dev eth0
/sbin/route del default gw 10.0.0.254
/sbin/route add default gw 10.0.0.253
/sbin/route add -net 172.31.21.0 netmask 255.255.255.255 gw 10.0.0.254 dev eth0





[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.31.21.0     10.0.0.254      255.255.255.255 UGH   0      0        0 eth0
172.31.21.1     10.0.0.254      255.255.255.255 UGH   0      0        0 eth0
172.31.21.254   10.0.0.254      255.255.255.255 UGH   0      0        0 eth0
10.0.0.0        *               255.255.255.0   U     0      0        0 eth0
default         10.0.0.253      0.0.0.0         UG    0      0        0 eth0

Using an IP alias with only one nic

ifconfig eth0:0 192.168.1.100 up  (ip alias)

/sbin/route add -net 172.31.21.1 netmask 255.255.255.255 gw 192.168.1.254 dev eth0:0

/sbin/route add -net 172.31.21.254 netmask 255.255.255.255 gw 192.168.1.254 dev eth0:0


Asterisk MYSQL Caller ID lookup

 [cidlookup]
exten=>_x.,1,Noop( checking the callerid ${CALLERID(num)})
same=>n,Set(__cid=${SHELL(mysql --user=root --password='12340' --skip-column-names  dialer -e 'select dnc_phone  from dnc where dnc_phone="${CALLERID(num)}" limit 0,1 ')})
same=>n,Noop( result ${cid:0:3})
same => n,GotoIf($["${CALLERID(num)}"="${cid:0:3}"]?allow:disallow)
same=>n(allow),Playback(demo-thanks)
same=>n,Hangup()
same=>n(disallow),Playback(im-sorry)
same=>n,Hangup()

jueves, 17 de diciembre de 2015

Asterisk Expressions


Asterisk dialplan expressions are special expressions that can be used in the dialplan of Asterisk.

Syntax

$[expr1 operator expr2]


The high-level view of variable evaluations in Asterisk:

Since most user input will come via config files to Asterisk, some filtering and substitutions are done
as the config files are read.

Next, as the dialplan is executed, the ${ ... } variables and functions are evaluated and substituted.

And lastly, the contents of $[ .. ] expressions are evaluated and substituted.


Parameter Quoting:

exten => s,5,BackGround,blabla

The parameter (blabla) can be quoted ("blabla"). In this case, a comma does not terminate the field. However, the double quotes will be passed down to the Background command, in this example.

Also, characters special to variable substitution, expression evaluation, etc (see below), can be quoted. For example, to literally use a $ on the string "$1231", quote it with a preceding \. Special characters that must be quoted to be used, are [ ] $ " \. (to write \ itself, use \\).

These double quotes and escapes are evaluated at the level of the asterisk config file parser.

Double quotes can also be used inside expressions, as discussed below.

Spaces Inside Variable

UPDATE: with the latest Asterisk Beta (1.2.0_2) there is the following notice:

Dialplan Expressions:

  • The dialplan expression parser (which handles $[ ... ] constructs) has gone through a major upgrade, but has one incompatible change: spaces are no longer required around expression operators, including string comparisons. However, you can now use quoting to keep strings together for comparison. For more details, please read the doc/README.variables file, and check over your dialplan for possible problems.

If the variable being evaluated contains spaces, there can be problems.

For these cases, double quotes around text that may contain spaces will force the surrounded text to be evaluated as a single token. The double quotes will be counted as part of that lexical token.

As an example:

exten => s,6,GotoIf($[ "${CALLERIDNAME}" : "Privacy Manager" ]?callerid-liar|s|1:s|7)

The variable CALLERIDNAME could evaluate to "DELOREAN MOTORS" (with a space) but the above will evaluate to:

"DELOREAN MOTORS" : "Privacy Manager"

and will evaluate to 0.

The above without double quotes would have evaluated to:

DELOREAN MOTORS : Privacy Manager

and will result in syntax errors, because token DELOREAN is immediately followed by token MOTORS and the expression parser will not know how to evaluate this expression.

Null Strings

Testing to see if a string is null can be done in one of three different ways:

exten => _XX.,1,GotoIf($["${calledid}" != ""]?3)

exten => _XX.,1,GotoIf($[foo${calledid} != foo]?3)

exten => _XX.,1,GotoIf($[${LEN(${calledid})} > 0]?3)

The second example above is the way suggested by the WIKI. It will work as long as there are no spaces in the evaluated value.

The first way should work in all cases, and indeed, might now be the safest way to handle this situation.

The third way seems the most logical. Anyone care to comment. Besides the LEN() function, there is now also ISNULL. Keep in mind such function calls need to kept inside ${...}.

Logical operators

  • expr1 | expr2 (Logical OR)
    • If expr1 evaluates to a non-empty string or a non-zero value, returns this value ("true"). Otherwise returns the evaluation of expr2.
  • expr1 & expr2 (Logical AND)
  • !expr (Logical Unary Complement)
    • If both expressions evaluate to non-empty strings or non-zero values, then returns the value of expr1 ("true"). Otherwise returns zero ("false").
    • Not available in versions of Asterisk < 1.1
    • Note that if a space is inserted between the '!' and the expression, an error will occur.

Using Logical operators

To use logical operator on conditionals commands like GotoIf do it like this:

exten => s,n,GotoIf($[ $[ "${FOO}" = "1" ] & $[ "${BAR}" = "2" ] ]?labelTrue:labelFalse)

Comparison operators

  • expr1 = expr2
  • expr1 != expr2
  • expr1 < expr2
  • expr1 > expr2
  • expr1 <= expr2
  • expr1 >= expr2
    • If both arguments are integers, returns the result of an integer comparison. Otherwise returns the result of string comparison using the locale-specific collation sequence. In either case, the result of a comparison is 1 if the specified relation is true, or 0 if the relation is false.

Arithmetic operators

  • expr1 + expr2
  • expr1 - expr2
  • - expr (unary negation operator)
    • Returns the results of addition or subtraction of integer-valued arguments.
    • Not available in versions of Asterisk < 1.1
  • expr1 * expr2
  • expr1 / expr2
  • expr1 % expr2
    • Return the results of multiplication, integer division, or remainder of integer-valued arguments.

Asterisk 1.6 Arithmetic

In 1.6 and above, we upgraded the $[] expressions to handle floating point numbers. Because of this, folks counting on integer behavior would be disrupted. To make the same results possible, some rounding and integer truncation functions have been added to the core of the Expr2 parser. Indeed, dialplan functions can be called from $[..] expressions without the ${...} operators. The only trouble might be in the fact that the arguments to these functions must be specified with a comma. If you try to call the MATH function, for example, and try to say 3 + MATH(7*8), the expression parser will evaluate 7*8 for you into 56, and the MATH function will most likely complain that its input doesn't make any sense. We also provide access to most of the floating point functions in the C library. (but not all of them).

While we don't expect someone to want to do Fourier analysis in the dialplan, we don't want to preclude it, either.

Here is a list of the 'builtin' functions in Expr2. All other dialplan functions are available by simply calling them (read-only). In other words, you don't need to surround function calls in $[...] expressions with ${...}. Don't jump to conclusions, though! - you still need to wrap variable names in curly braces!

  • COS(x) x is in radians. Results vary from -1 to 1.
  • SIN(x) x is in radians. Results vary from -1 to 1.
  • TAN(x) x is in radians.
  • ACOS(x) x should be a value between -1 and 1.
  • ASIN(x) x should be a value between -1 and 1.
  • ATAN(x) returns the arc tangent in radians; between -PI/2 and PI/2.
  • ATAN2(x,y) returns a result resembling y/x, except that the signs of both args are used to determine the quadrant of the result. Its result is in radians, between -PI and PI.
  • POW(x,y) returns the value of x raised to the power of y.
  • SQRT(x) returns the square root of x.
  • FLOOR(x) rounds x down to the nearest integer.
  • CEIL(x) rounds x up to the nearest integer.
  • ROUND(x) rounds x to the nearest integer, but round halfway cases away from zero.
  • RINT(x) rounds x to the nearest integer, rounding halfway cases to the nearest even integer.
  • TRUNC(x) rounds x to the nearest integer not larger in absolute value.
  • REMAINDER(x,y) computes the remainder of dividing x by y. The return value is x - n*y, where n is the value x/y, rounded to the nearest integer. If this quotient is 1/2, it is rounded to the nearest even number.
  • EXP(x) returns e to the x power.
  • EXP2(x) returns 2 to the x power.
  • LOG(x) returns the natural logarithm of x.
  • LOG2(x) returns the base 2 log of x.
  • LOG10(x) returns the base 10 log of x.

Regular expressions

  • expr1 : regexp
    • The ':' operator matches expr1 against regexp, which must be a regular expression. The regular expression is anchored to the beginning of the string with an implicit '^'.
    • If the match succeeds and regexp contains at least one regular expression subexpression '\(...\)', the string corresponding to '\1' is returned; otherwise the result returned is the number of characters matched. If the match fails and regexpcontains a regular expression subexpression, the null string is returned; otherwise 0.
  • expr1 =~ expr2
    • Exactly the same as the ':' operator, except that the match is not anchored to the beginning of the string. Pardon any similarity to seemingly similar operators in other programming languages!
    • The ":" and "=~" operators share the same precedence.
    • Not available in versions of Asterisk < 1.1

THE DOCUMENTATION ABOVE FOR REGULAR EXPRESSIONS IS WOEFULLY INADEQUATE. The problem seems to be that the regular expression syntax conflicts with Asterisk expression syntax. As a result, one must backslash escape anything which looks like it might be an expression operator. Also, contrary to what is suggested above, it does not seem to be necessary to backslash escape the parentheses.

Here is one example that works:

exten => stripcidtext,n,Set(regx="([0-9]+)") ; Note the quotes -- and note that parentheses are REQUIRED if you want to return the matched string
exten => stripcidtext,n,Set(cid2=$["${cid}" : ${regx}]) ; Returns numeric beginning to string

So if ${cid} contains 123foo then ${cid2} will contain just 123.

However, if ${cid} contains foo123 then ${cid2} will be empty. Supposedly you could use =~ instead of : and the string matching would work anywhere, but I don't think that works correctly (at least, I could not get =~ to work).

Here is another example:

exten => s,n,Set(enum-protocol=$["${enum-record}" : "([a-zA-Z0-9]\+)\:"])

If enum-record contains "sip:18005558355@tf.voipmich.com", then this command will set enum-protocol to "sip".

Ternary "if" (inline conditional) operator

  • expr1 ? expr2 :: expr3
    • Traditional ternary operator. If expr1 is a number that evaluates to 0 (false), expr3 is result of the this expression evaluation. Otherwise, expr2 is the result.
    • If expr1 is a string, and evaluates to an empty string, or the two characters (""), then expr3 is the result. Otherwise, expr2 is the result.
    • In Asterisk, all 3 exprs will be "evaluated"; if expr1 is "true", expr2 will be the result of the "evaluation" of this expression. expr3 will be the result otherwise.
    • This operator has the lowest precedence.
    • Not available in versions of Asterisk < 1.1
    • This operator is quite buggy. The IF function is recommended instead.

Parentheses are used for grouping in the usual manner.

Operator Precedence

  1. Parentheses: ()
  2. Unary operators !-
  3. Regular expression comparison: :=~
  4. Multiplicative arithmetic operators: */%
  5. Additive arithmetic operators: +-
  6. Comparison operators: =!=<><=>=
  7. Logical operators: |&
  8. Ternary "if" (inline conditional) operator: ? :

Conditionals

There are now several conditional applications-- an example is the conditional gotoIf :

exten => 1,2,GotoIf,condition?label1:label2

If condition is true go to label1, else go to label2. Labels are interpreted exactly as in the normal goto command.

"condition" is just a string. If the string is empty or "0", the condition is considered to be false, if it's anything else, the condition is true. This is designed to be used together with the expression syntax described above, eg :

exten => 1,2,GotoIf,$[${CALLERID} = 123456]2|1:3|1

Example

After the sequence:

exten => 1,1,SetVar(lala=$[1 + 2]);
exten => 1,2,SetVar(koko=$[2 * ${lala}]);

the value of ${koko} is "6".

See also

martes, 15 de diciembre de 2015

Asterisk/ FreePBX trunk

FPBX

[FPBX]
host=dialer.asterisk.com
fromuser=FPX
type=peer
disallow=all
allow=ulaw&alaw
qualify=yes
nat=force_rport,comedia
context=from-dialer
port=5060
transport=udp
trustrpid=yes
sendrpid=yes
dtmfmode=rfc2833

FreePBX Dial Plan

[from-dialer]
exten=>_xxx,1,Goto(from-internal,${EXTEN},1)
same=>n,Hangup()

exten=>_1234567890,1,Goto(from-trunk,${EXTEN},1)
same=>n,Hangup()




Vicidial

[vicidial]
host=pbx2.asterisk.com
fromuser=vicidial
type=peer
disallow=all
allow=ulaw
allow=alaw
qualify=yes
nat=force_rport,comedia
context=trunkinbound
port=5060
transport=udp
trustrpid=yes
sendrpid=yes
dtmfmode=rfc2833

Dial Plan Vicidial Outgoing

exten => _66.,1,AGI(agi://127.0.0.1:4577/call_log)
exten => _66.,n,Dial(SIP/${EXTEN:2}@1458,,To)
exten => _66.,n,Hangup

viernes, 11 de diciembre de 2015

Pre-dial handlers Specificatio

n

Saltar al final de los metadatos
Ir al inicio de los metadatos

1. Summary

Pre-dial - Ability to run dialplan on callee and caller channel right before actual Dial. Available on the Dial and FollowMe applications.

2. Description

Pre-dial handlers allow you to execute a dialplan Gosub on a channel before a call is placed but after the Dial application is invoked. You can execute a dialplan Gosub on the caller channel and on each callee channel dialed.
The 'B' option executes a dialplan Gosub on the caller channel before any callee channels are created.
The 'b' option executes a dialplan Gosub on each callee channel after it is created but before the call is placed to the end-device.
Example execution sequences to show when things happen:
SIP/foo is calling SIP/bar
SIP/foo is the caller,
SIP/bar is the callee,
SIP/baz is another callee,
Example 1
<SIP/foo-123> Dial(SIP/bar,,B(context^exten^priority))
<SIP/foo-123> Executing context,exten,priority
<SIP/foo-123> calling SIP/bar-124
Example 2
<SIP/foo-123> Dial(SIP/bar,,b(context^exten^priority))
<SIP/bar-124> Executing context,exten,priority
<SIP/foo-123> calling SIP/bar-124
Example 3
<SIP/foo-123> Dial(SIP/bar&SIP/baz,,b(context^exten^priority))
<SIP/bar-124> Executing context,exten,priority
<SIP/baz-125> Executing context,exten,priority
<SIP/foo-123> calling SIP/bar-124
<SIP/foo-123> calling SIP/baz-125

3. Syntax

b([[context^]exten^]priority[(arg1[^...][^argN])])
B([[context^]exten^]priority[(arg1[^...][^argN])])
The syntax is intentionally similar to the Gosub application. If context or exten are not supplied then the current values from the caller channel are used.

4. Use cases

4.1. Pre-dial callee channels (Option 'b')

Say SIP/abc is calling SIP/def. In the dialplan you have: Dial(SIP/def). When executed, SIP/def-123234 is created. But how can you tell that from dialplan?
You can use a pickup macro: M or U options to Dial(), but you have to wait till the called channel answers to know. The new pre-dial option 'b' to Dial(), will let you run dialplan on the newly created channel before the call is placed to the end-device.
New way
Dial(SIP/def,,b(context^exten^priority))
Dialplan will run on SIP/def-123234 and allow you to know right away what channel will be used, and you can set specific variables on that channel.

4.2. Pre-dial caller channels (Option 'B')

You can run dialplan on the caller channel right before the dial, which is a great place to do a last microsecond UNLOCK to ensure good channel behavior.
Example
exten => _X.,1,GotoIf($[${LOCK(foo)}=1]?:failed)
exten => _X.,n,do stuff
exten => _X.,n,Set(Is_Unlocked=${UNLOCK(foo)})
exten => _X.,n,Dial(SIP/abc)
exten => _X.,n(failed),Hangup()
With this above example, say SIP/123 and SIP/234 are running this dialplan.
  1. SIP/123 locks foo
  2. SIP/123 unlocks foo
  3. Due to some CPU load issue, SIP/123 takes its time getting to Dial(SIP/abc) and doesn't do it right away.
  4. Meanwhile... SIP/234 zips right by, lock 'foo' is already unlocked
  5. SIP/234 grabs the lock, does its thing and it gets to Dial(SIP/abc).
  6. SIP/123 wakes up and finally gets to the Dial().
Now you have two channels dialing SIP/abc when there was supposed to be one.
If your intention is to ensure that Dial(SIP/abc) is only done one at a time, you may have unexpected behavior lurking.
New way
exten => _X.,1,GotoIf($[${LOCK(foo)}=1]?:failed)
exten => _X.,n,do stuff...
exten => _X.,n,Dial(SIP/abc,,B(unlock^s^1))
exten => _X.,n,GotoIf($[${Is_Unlocked}=1]?already_unlocked:not_unlocked)
exten => _X.,n(not_unlocked),Set(Is_Unlocked=${UNLOCK(foo)})
exten => _X.,n(already_unlocked),Do after dial stuff...
exten => _X.,n(failed),Hangup()

[unlock]
exten => s,1,Set(Is_Unlocked=${UNLOCK(foo)})
Now, under no circumstances can this dialplan be run through and execute the Dial unless lock 'foo' is released. Obviously this doesn't ensure that you're not calling SIP/abc more than once (you would need more dialplan logic for that), but it will allow a dialplan coder to also put the Dial in the locked section to ensure tighter control.