Skip to content

Instantly share code, notes, and snippets.

@ambiorixg12
ambiorixg12 / Centos 7 CDR ODBC
Last active January 6, 2024 15:00
CDR ODBC MYSL Centos 7
Install dependencies
yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel
yum install mysql-connector-odbc
/etc/odbc.ini
[asterisk-mysql]
Description = MySQL connection to 'asterisk' database
Driver = MySQL
Database = asterisk
@ambiorixg12
ambiorixg12 / confbridge hack
Created December 19, 2018 03:34
Couting users on a conference and listing all channels on a conference
confbridge Hack()
Counting users on a conf
asterisk -x " confbridge list 5001" | awk '{print $1}' | grep -w SIP | wc -l
listing channels on a conf
asterisk -x " confbridge list 5001" | awk '{print $1}' | grep -w SIP
@ambiorixg12
ambiorixg12 / register search
Created December 19, 2018 03:36
searching for register sip device range
@ambiorixg12
ambiorixg12 / originate command
Last active April 4, 2019 15:21
Asterisk Originate example
asterisk -x "channel originate Local/18097143489@myoutbound extension s@moh"
asterisk -x "channel originate Local/103@home extension s@moh"
[myoutbound]
exten=>_x.,1,verbose( calling to ${EXTEN})
same=>n,Set(CALLERID(num)=${calleridnumber}) ;callerid to use
same=>n,Dial(SIP/${EXTEN}@trunk,25) ;trunk to use
@ambiorixg12
ambiorixg12 / live channels
Created December 19, 2018 03:44
displaying all sip active channels
<?php
$channel=shell_exec("asterisk -x \" core show channels\" | awk '{print $1}' | awk '/SIP/{print}'");
$channelist=explode("\n",$channel);
foreach($channelist as $key=> $value) {
if (preg_match("/\bSIP\b/i", $value,$match)){
echo "$key : $value\n";
}
@ambiorixg12
ambiorixg12 / mysql survey
Created December 19, 2018 03:46
Simple Asterisk MYSQL INSERT SURVEY
[survey1]
exten=>_991,1,Answer()
same=>n,Playback(/var/lib/asterisk/agi-bin/survey/welcomesurvey)
same=>n(q1),read(q1,/var/lib/asterisk/agi-bin/survey/pregunta1,1)
same => n,GotoIf($[${q1}>5]?q1)
same=>n(q2),read(q2,/var/lib/asterisk/agi-bin/survey/pregunta2,1)
same => n,GotoIf($[${q2}>5]?q2)
same=>n(q3),read(q3,/var/lib/asterisk/agi-bin/survey/pregunta3,1)
same => n,GotoIf($[${q3}>5]?q3)
same=>n,Playback(/var/lib/asterisk/agi-bin/survey/goodbyesurvey)
@ambiorixg12
ambiorixg12 / playing sound on a call chanspy
Last active January 18, 2019 01:17
playing sound file on a call chanspy
Let's say SIP device have a call with 6000 just run the following command
Playing the sound
vultr*CLI> originate Local/6005@alert application playback demo-thanks
;; This context inject the audio
[alert]
exten=>_x.,1,Noop()
same => n,ChanSpy(PJSIP/${EXTEN},Bq)
@ambiorixg12
ambiorixg12 / Confirmation call
Created December 19, 2018 04:28
This script ask to a person to dial a destination and record a message and then the other party listen the message and accept or not the call
;;;;;;;;;;;;;;confirmation call;;;;;;;;;;;;;;;;;;;;;;;
[confirmation_call_original2]
exten=>_.,1,Answer()
same=>n(wish),Set(message=pls-entr-num-uwish2-call)
same=>n(rec),read(exten,${message},4,,,5)
same=>n,GotoIf($["${exten}"=""]?wish)
same=>n,Playback(pls-rcrd-name-at-tone)
same=>n,Record(/root/demo/recording/${UNIQUEID}.wav,,20,y)
@ambiorixg12
ambiorixg12 / redirecting channels in a live call
Created December 19, 2018 04:33
redirecting both call legs to different destination using in a live call
exten=>_6XXX,1,NoCDR()
same=>n,Noop(${EXTEN} ${CHANNEL} ${CDR(dstchannel)})
same=>n,Set(__DYNAMIC_FEATURES=transf)
exten=>_6XXX,n,Dial(PJSIP/${EXTEN})
;;;;custom transfer
@ambiorixg12
ambiorixg12 / extracting from header
Last active July 3, 2019 22:10
extracting from header from an INViTE
;;;;;sip headers
[sipheader]
exten=>_x.,1,Noop(reading from header ${PJSIP_HEADER(read,from)})
same=>n,Set(from=${PJSIP_HEADER(read,from)})
same=>n,Set(fromip=${CUT(from,>,1)})
same=>n,Set(ip=${SHELL(php /root/cut.php "${fromip}")})
same=>n,Set(pseudodid=${CUT(from,@,1)})
same=>n,Noop(${ip})