text stringlengths 0 152 |
|---|
lems, he needed to blacklist certain caller IDs in the meantime, and the database he |
wanted to use for this was a Microsoft SQL Server database. |
With a few exceptions, this is the actual dialplan: |
[span3pri] |
exten => _50054XX,1,NoOp() |
same => n,Set(CDR(accountcode)=pricall) |
; Does this callerID appear in the database? |
same => n,GotoIf($[${ODBC_ANIBLOCK(${CALLERID(number)})}]?busy) |
same => n(dial),Dial(DAHDI/G1/${EXTEN}) |
same => n(busy),Busy(10) ; Yes, you are on the blacklist. |
same => n,Hangup |
A Gentle Introduction to func_odbc |
| |
263 |
This dialplan, in a nutshell, passes all calls to another system for routing purposes, |
except those calls whose caller IDs are in a blacklist. The calls coming into this system |
used a block of 100 seven-digit DIDs. You will note a dialplan function is being used |
that you won’t find listed in any of the functions that ship with Asterisk: ODBC_ANI |
BLOCK(). This function was |
in another configuration file, |
instead defined |
func_odbc.conf: |
[ANIBLOCK] |
dsn=telesys |
readsql=SELECT IF(COUNT(1)>0, 1, 0) FROM Aniblock WHERE NUMBER='${ARG1}' |
So, your ODBC_ANIBLOCK()3 function connects to a data source in res_odbc.conf |
named telesys and selects a count of records that have the NUMBER specified by the |
argument, which is (referring to the preceding dialplan) the caller ID. Nominally, this |
function should return either a 1 (indicating the caller ID exists in the Aniblock |
table) or a 0 (if it does not). This value also evaluates directly to true or false, which |
means we don’t need to use an expression in our dialplan to complicate the logic. |
And that, in a nutshell, is what func_odbc is all about: writing custom dialplan func‐ |
tions that return a result from a database. Next up, a more detailed example of how |
one might use func_odbc. |
Getting Funky with func_odbc: Hot-Desking |
OK, back to the Dagwood sandwich we promised. |
We believe the value of func_odbc will become very clear to you if you work through |
the following example, which will produce a new feature on your Asterisk system that |
depends heavily on func_odbc. |
Picture a small company with a sales force of five people who have to share two desks. |
This is not as cruel as it seems, because these folks spend most of their time on the |
road, and they are each only in the office for at most one day each week. |
Still, when they do get into the office, they’d like the system to know which desk they |
are sitting at, so that their calls can be directed there. Also, the boss wants to be able |
to track when they are in the office and control calling privileges from those phones |
when no one is there. |
This need is typically solved by what is called a hot-desking feature. We have built one |
for you in order to show you the power of func_odbc. |
3 We’re using the IF() SQL function to make sure we return a value of 0 or 1. This works on MySQL 5.1 or |
later. If it does not work on your SQL installation, you could also check the returned result in the dialplan |
using the IF() function there. |
264 |
| |
Chapter 15: Relational Database Integration |
Let’s start with the easy stuff, and create two new phone credentials in our database. |
First, the endpoints table: |
MySQL> INSERT INTO asterisk.ps_endpoints (id,transport,aors,auth,context,disallow,allow, \ |
direct_media,callerid) |
VALUES |
('HOTDESK_1','transport-tls','HOTDESK_1','HOTDESK_1','hotdesk','all','ulaw','no', \ |
'HOTDESK_1'), |
('HOTDESK_2','transport-tls','HOTDESK_2','HOTDESK_2','hotdesk','all','ulaw','no', \ |
'HOTDESK_2'); |
Then, the auths: |
MySQL> INSERT INTO asterisk.ps_auths (id,auth_type,password,username) |
VALUES |
('HOTDESK_1','userpass','notsohot1','HOTDESK_1'), |
('HOTDESK_2','userpass','notsohot2','HOTDESK_2'); |
Finally, the aors: |
MySQL> INSERT INTO asterisk.ps_aors |
(id,max_contacts) |
VALUES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.