Soporte & Consultoria

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

domingo, 26 de febrero de 2012

Ejecutando comandos del sistema desde Asterisk

 Con la Aplicacion System() podemos ejecutar comandos del sistema desde Asterisk. Es decir que llamando a una extension o  selecionando alguna opcion del nuestro IVR, Podriamos reiniciar nuestra central, Descargar un archivo, Borrar un fichero o lo que tu imaginacion y conocimiento te permitan.


UNA NOTA IMPORTANTE PODEMOS USAR EL COMANDO  which   para saber la ruta completa del comando que queremos ejecutar desde Asterisk. Ejemplo para saber la ruta especifica del comando ls

$ which ls
/bin/ls
 


System()

[shell]
exten=>500,1,Authenticate(5415)    ; Apaga nuestro Sistema
same=>n,Playback(goodbye)
same=>n,system(/sbin/init 0)
same=>hangup()

exten=>501,1,Authenticate(5415)  ; Reinicia nuestro Sistema
same=>n,Playback(goodbye)
same=>n,system(/sbin/init 6)
same=>hangup()



Example 1

exten => s,1,system(echo "${DATETIME} - ${CALLERID} - ${CHANNEL}" >> /var/log/asterisk/calls)

Example 2


; dial 700 = Restart Asterisk
 exten => 700,1,Playback(posix-restarting) ; "Restarting asterisk"
 exten => 700,2,Wait(1)
 exten => 700,3,System(/usr/sbin/asterisk -rx reload)
 exten => 700,4,Hangup

Example 3


; Extension 200 Mini Call ID WinPopup Example
 exten => 200,1,NoOp(${CALLERID} ${DATETIME})
 exten => 200,2,System(/bin/echo -e "'Incoming Call From: ${CALLERID} \\r Received: ${DATETIME}'"|/usr/bin/smbclient -M target_netbiosname)
 exten => 200,3,Dial,sip/sipuser|30|t        
 exten => 200,4,Congestion

Example 4


 ; Dump call info to a serial receipt printer on ttyS1
 exten => 200,1,NoOp(${CALLERID} ${DATETIME})
 exten => 200,2,System(/bin/echo "'${CALLERID} ${DATETIME}'" > /dev/ttyS1)
 exten => 200,3,Dial,sip/sipuser|30|t        
 exten => 200,4,Congestion


Security


My associate received a call from PG&E and realized the horror of System()

Problem

Running System() has access to any program the user running asterisk has access to
CALLERID can be set by a remote user

Example

exten => 200,1,Set(CALLERID(NAME)=PG&/bin/echo BADIDEA > /ROOTED.txt)
exten => 200,2,System(/bin/echo -e "'Incoming Call From: ${CALLERID} \\r Received: ${DATETIME}'"|/usr/bin/smbclient -M target_netbiosname)

Measure 1

By using perl I was able to prevent the first example but I'm sure the possibility is still there:

exten => 200,1,Set(CALLERID(NAME)=PG&/bin/echo BADIDEA > /ROOTED.txt)
exten => 200,2,System(/bin/perl -e 'print Incoming Call From:" . "${CALLERIDNAME}" | /usr/bin/smbclient -M target_netbiosname)

Measure 2


Fine tune this to your liking:

[macro-smb-cid]
exten => s,1,NoOp
exten => s,2,Set(regx="([a-zA-Z0-9]+)")
exten => s,3,Set(CCIDNAME=$["${CALLERIDNAME}": ${regx}])
exten => s,4,Set(regx="([0-9]+)")
exten => s,5,Set(CCIDNUM=$["${CALLERIDNUM}": ${regx}])
exten => s,6,TrySystem(/usr/bin/perl -e \'print "${DATETIME} " . " ${CCIDNAME} " . " \<${CCIDNUM}\>" \' | /usr/bin/smbclient -M target_netbiosname)

Update!! Asterisk-1.4 returns 0 (as it should) when your regex matches. Instead use the function FILTER.
This example is experimental...
[macro-smb-cid]
exten => s,1,NoOp
exten => s,2,Set(FLTNA=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz)
exten => s,3,Set(CIDNA=${FILTER(${FLTNA},${CALLERID(NAME)})})
exten => s,4,Set(FLTNU=(0123456789)
exten => s,5,Set(CIDNU=${FILTER(${FLTNU},${CALLERID(num)})})
exten => s,6,TrySystem(/usr/bin/perl -e \'print "${DATETIME} " . " ${CCIDNAME} " . " \<${CCIDNUM}\>" \' | /usr/bin/smbclient -M target_netbiosname)

I'd like to hear from you if you know another way... cwidger@gmail.com
what's wrong with using System(su userWithNoRights -c "some command") ?


See also

No hay comentarios:

Publicar un comentario