[AsteriskBrasil] RES: OFF-TOPIC - Simulador de Asterisk

andre andre em sertelinfo.com.br
Quinta Maio 7 11:20:09 BRT 2009


SENHORES EM BREVE ESTAREI DISPONIBILIZANDO UM IPBX COMPLETO BASEADO NOS PABX
CONVENCIONAIS, ESTAMOS EM FASE FINAL DO IPBX, ESTAREI DANDO UM TREINAMENTO
SOBRE ESSE PROJETO EM BREVE. SEGUE ABAIXO UMA PARTE DO CODIGO, UTILIZANDO
MACROS E FUNÇÕES DO ASTERISK E CONEXÇÃO MYSQL.

[ipbx]
include => ipbx-adicional

;################################################################## CONTEXTO
PARA VALIDAR NUMERO DISCADO
########################################################################

exten => _X.,1,set(callerid=${CALLERID(num)})
exten => _X.,2,set(exten=${EXTEN})
exten => _X.,3,Noop(${exten})
exten => _X.,4,set(newexten=${exten:0:1})
exten => _X.,5,Noop(${newexten})
exten => _X.,6,Gotoif($[ $[ "${newexten}" != "0"] ] & $[ "${LEN(${exten})}"
<= "4"] ?8:11)
exten => _X.,7,Noop(BINA ${exten})
exten => _X.,8,Macro(consulta-fac,${SELECTFACCADEADO},${callerid})
exten => _X.,9,Gotoif($[ $[ "${result}" = "1"] ]?end)
exten =>
_X.,10,Macro(ipbx-exten-consulta,${SELECTFACDND},${SELECTFACDESVIO},${SELECT
FACCADEADO},${exten},${GROUP})
exten => _X.,11,Macro(consulta-fac,${SELECTFACCADEADO})
exten => _X.,12,Gotoif($[ $[ "${result}" = "1"] ]?end)
exten => _X.,13,Macro(trunck-out,${callerid},${exten:1})
exten => _X.,n,Hangup()
exten => _X.,n(end),SendText(username ${CALLERID(num)} com cadeado ativado)
exten => _X.,n,Busy()

;exten => _X.,n,Gotoif($["${DB(SERTEL/ipbx/emergencia/${exten:1})}" =
"${exten:1}"]?4)
;exten =>
_X.,n,Macro(ipbx-exten-consulta,${SELECTFACDND},${SELECTFACDESVIO},${SELECTF
ACCADEADO},${exten})

;###########################################################################
############################################################################
#########################

[macro-trunck-out]
exten => s,1,Noop(${desvioon})
;exten => s,1,Noop(${ARG2:0:4})
exten => s,2,Gotoif($[${LEN(${ARG2})} < 8]?dstinterno)
exten => s,3,Gotoif($[ $[ "${LEN(${ARG2})}" = "8"] | $[ "${ARG2:0:4}" =
"0800"]  | $[ "${ARG2:0:4}" = "0300"] ]?dstlocal)
exten => s,4,Gotoif($[ $[ ${LEN(${ARG2})} = 9] | $[${LEN(${ARG2})} < 14]
]?dstddd)
exten => s,5,Gotoif($[${LEN(${ARG2})} >= 15]?dstddi)

exten => s,6(dstinterno),set(numero_local=${ARG2})
;exten => s,n,Gotoif($[${LEN(${numero_local})} <= 4]?)
exten => s,7,Gotoif($[ $[ "${newexten}" != "0"] ] & $[ "${LEN(${exten})}" <=
"4"] ?8:9)
exten => s,8,macro(exten_out,${numero_local})
exten => s,9,macro(dst-emergencia,${numero_local})
exten => s,n,Hangup()

exten => s,n(dstlocal),set(numero_local=${ARG2})
exten => s,n,macro(dstlocal,${numero_local})
exten => s,n,Hangup()

exten => s,n(dstddd),set(numero_ddd=${ARG2})
exten => s,n,macro(dstddd,${numero_ddd})
exten => s,n,Hangup()

exten => s,n(dstddi),set(numero_ddi=${ARG2})
exten => s,n,macro(dstddi,${numero_ddi})
exten => s,n,Hangup()

[macro-dstlocal]
exten => s,1,set(dstlocal=${ARG1})
exten => s,n,Set(destino=${ARG1:0:1})
exten => s,n,set(srcfree=${ARG1:0:4})
exten => s,n,Noop(${destino})
exten => s,n,Gotoif($[ $[ $["${destino}" = "2"] ] | $["${destino}" = "3"] |
$["${destino}" = "4"] | $["${srcfree}" = "0800"] | $["${srcfree}" =
"0300"]]?local)
exten => s,n,Gotoif($[ $[ $["${destino}" = "7"] ] | $["${destino}" = "8"] |
$["${destino}" = "9"] ]?movel)

exten =>
s,8(local),macro(ipbx-consulta,${SELECTCATEXT},${SELECTREC},${SELECTAUTH},${
dstlocal})
exten => s,n,Hangup()
exten =>
s,10(movel),macro(ipbx-consulta,${SELECTCATMOVEL},${SELECTREC},${SELECTAUTH}
,${dstlocal})
exten => s,n,Hangup()

[macro-dstddd]
exten => s,1,Set(destino=${ARG1:0:6})
exten => s,2,Set(destddd=${destino:-1:1})
exten => s,n,set(dest=${ARG1})
exten => s,n,Noop(${destino})
exten => s,n,Gotoif($[ $[{destddd} = 2] | $[${destddd} = 3] | $[${destddd} =
4] ]?dddlocal)
exten => s,n,Gotoif($[ $[{destddd} = 7] | $[${destddd} = 8] | $[${destddd} =
9] ]?dddmovel)

exten =>
s,n(dddlocal),macro(ipbx-consulta,${SELECTCATDDD},${SELECTREC},${SELECTAUTH}
,${dest})
exten => s,n,Hangup()
exten =>
s,n(dddmovel),macro(ipbx-consulta,${SELECTCATDDDMOVEL},${SELECTREC},${SELECT
AUTH},${dest})
exten => s,n,Hangup()

[macro-dstddi]
exten => s,1,Set(destino=${ARG1:0:9})
exten => s,2,Set(destlocal=${destino:-1:1})
exten => s,n,set(destddi=${ARG1})
exten => s,n,Noop(${destino})
exten => s,n,Gotoif($[ $[{destlocal} = 2] | $[${destlocal} = 3] |
$[${destlocal} = 4] ]?ddilocal)
exten => s,n,Gotoif($[ $[{destlocal} = 7] | $[${destlocal} = 8] |
$[${destlocal} = 9] ]?ddimovel)

exten =>
s,n(ddilocal),macro(ipbx-consulta,${SELECTCATDDIFIXO},${SELECTREC},${SELECTA
UTH},${destddi})
exten => s,n,Hangup()
exten =>
s,n(ddimovel),macro(ipbx-consulta,${SELECTCATDDIMOVEL},${SELECTREC},${SELECT
AUTH},${destddi})
exten => s,n,Hangup()

[macro-ipbx-consulta]
exten => s,1,set(CALLERID=${callerid})
exten => s,2,MYSQL(Connect connid ${server} ${user} ${pass} ${dbname}) 
exten => s,3,MYSQL(Query resultid ${connid} SELECT\ ${ARG1}\,
${ARG2}\,${ARG3}\,${SELECTFACCADEADO} FROM\`${tableramais}`\
WHERE\`username`=\'${callerid}\') 
exten => s,4,MYSQL(Fetch foundRow ${resultid} result1 result2 result3
result4) ; fetch row 

exten => s,5,Set(result1=${result1})
exten => s,6,set(result2=${result2})
exten => s,7,set(result3=${result3})
exten => s,n,Gotoif($[ $[{ARG1} = categoria_acesso_ddd ] ]?ddd_ddi)
exten => s,n,GotoIf($[ $[ "${ARG1}" = "categoria_acesso_ddd"] ]| $["${ARG1}"
= "categoria_acesso_movel_ddd"] | $["${ARG1}" = "categoria_acesso_ddi"] |
$["${ARG1}" = "categoria_acesso_movel_ddi"] ]?ddd_ddi) 
exten => s,n,Noop(${ARG1})
exten => s,n,macro(rota_out,${result1},${result2},${result3},${ARG4})
exten =>
s,n(ddd_ddi),macro(rota_out_ddd_ddi,${result1},${result2},${result3},${ARG4}
)
exten => s,n,hangup()

[macro-rota_out]
exten => s,1,Noop(${ARG1})
exten => s,n,Noop(${ARG2})
exten => s,n,Noop(${ARG3})
exten => s,n,Noop(${ARG4})
exten => s,n,NooP(${result4})
exten => s,n,set(CAT=${ARG1})
exten => s,n,set(FACREC=${ARG2})
exten => s,n,set(FACAUTH=${ARG3})
exten => s,n,set(DSTOUT=${ARG4})
exten => s,n,Gotoif($["${CAT}" = "0"]?no-route|s|1)
exten => s,n,Gotoif($["${DESVIOON}" = "1"]?rec)
exten => s,n,Gotoif($["${FACAUTH}" = "0"])?rec)
exten => s,n,macro(ipbx-auth,${CAT},${FACREC},${FACAUTH},${DSTOUT})
exten => s,n(rec),macro(out-rec,${CAT},${FACREC},${FACAUTH},${DSTOUT})
exten => s,n,hangup()

;| $["${ARG1}" = "categoria_acesso_movel_ddd"]
[macro-ipbx-auth]
exten => s,1,playback(auth-thankyou)
exten => s,n,set(CAT=${ARG1})
exten => s,n,set(FACREC=${ARG2})
exten => s,n,set(FACAUTH=${ARG3})
exten => s,n,set(DSTOUT=${ARG4})
exten => s,n,Read(auth,,,,,)
exten => s,n,set(auth=${auth})
exten =>
s,n,macro(consulta_senha,${CAT},${FACREC},${FACAUTH},${DSTOUT},${auth})

[macro-consulta_senha]
exten => s,1,wait(1)
exten => s,n,set(CAT=${ARG1})
exten => s,n,set(FACREC=${ARG2})
exten => s,n,set(FACAUTH=${ARG3})
exten => s,n,set(DSTOUT=${ARG4})
exten => s,n,MYSQL(Connect connid ${server} ${user} ${pass} ${dbname}) 
exten => s,n,MYSQL(Query resultid ${connid} SELECT\ nome
FROM\`${TABLEUSERS}`\ WHERE\`senha`=\'${ARG5}\') 
exten => s,n,MYSQL(Fetch foundRow ${resultid} nome ) ; fetch row 
exten => s,n,goto(macro)
exten => s,n(macro),macro(out-rec,${CAT},${FACREC},${FACAUTH},${DSTOUT})
;exten => s,n,MYSQL(Clear ${resultid}) 
;exten => s,n,MYSQL(Disconnect ${connid})
;exten => s,n,hangup()

[macro-ipbx-consulta-fac]
exten => s,1,set(CALLERID=${callerid})
exten => s,n,set(desvioon=${result2})
exten => s,n,NooP(${ARG1})
exten => s,n,NooP(${ARG2})
exten => s,n,MYSQL(Connect connid ${server} ${user} ${pass} ${dbname}) 
exten => s,n,MYSQL(Query resultid ${connid} SELECT\ ${ARG1}
FROM\`${tableramais}`\ WHERE\`username`=\'${ARG2}\') 
exten => s,n,MYSQL(Fetch foundRow ${resultid} result1 ) ; fetch row
exten => s,n,Noop(${result1})
exten => s,n,macro(trunck-out,${callerid},${result1})
exten => s,n,goto(hangup,s,1)

[macro-consulta-fac]
exten => s,1,set(CALLERID=${callerid})
exten => s,2,NooP(${ARG1})
exten => s,3,NooP(${ARG2})
exten => s,4,MYSQL(Connect connid ${server} ${user} ${pass} ${dbname}) 
exten => s,5,MYSQL(Query resultid ${connid} SELECT\ ${ARG1}
FROM\`${tableramais}`\ WHERE\`username`=\'${callerid}\') 
exten => s,6,MYSQL(Fetch foundRow ${resultid} result ) ; fetch row
exten => s,n,Noop(${result})

[macro-out-rec]
exten => s,1,NooP(${ARG1})
exten => s,n,Gotoif($["${ARG2}" = "0"]?dial)
exten => s,n,Set(CDR(userfield)=andre)
exten => s,n,Set(${CALLERID(num)}=/usr/local/monitor/saintes/${ARG4})
exten => s,n,Set(CALLFILENAME=${STRFTIME(,,[%H_%M_%S][%d-%m-%Y])} username
${CALLERID(num)}-${ARG4})
exten => s,n,Monitor(wav49,${${CALLERID(num)}}/${CALLFILENAME}, mb)

;exten => s,n(dial),Gotoif($["${ARG1}" = "0"]?dnd|s|1)

exten =>
s,n(dial),DIAL(${TIPOTRONCOLOCAL}/${PREFIXO1}${ARG4${FLAG1}}${provedorlocal}
,${ringtime},${dialoptions})

exten => s,n,NoOp( Dial Status: ${DIALSTATUS}) 
exten => s,n,Goto(s-${DIALSTATUS},1) 

exten => s-NOANSWER,1,goto(dial-status,s,1)
exten => s-ANSWER,1,goto(update-events,s,1)
exten => s-CONGESTION,1,goto(dial-status,s,1)
exten => s-CANCEL,1,goto(dial-status,s,1)
exten => s-BUSY,1,goto(dial-status,s,1)
exten => s-CHANUNAVAIL,1,goto(dial-status,s,1) 

exten => h,1,NoOp( Dial Status: ${DIALSTATUS}) 
exten => h,n,Goto(h-${DIALSTATUS},1) 

exten => h-NOANSWER,1,goto(dial-status,s,1)
exten => h-ANSWER,1,goto(update-events,s,1)
exten => h-CONGESTION,1,goto(dial-status,s,1)
exten => h-CANCEL,1,goto(dial-status,s,1) 
exten => h-BUSY,1,goto(dial-status,s,1)
exten => h-CHANUNAVAIL,1,goto(dial-status,s,1) 

[macro-dnd]
exten => s,1,Playback(do-not-disturb&activated)
exten => s,n,goto(dial-status,s,1)

[no-route]
exten => s,1,Playback(no-rights)
exten => s,n,goto(dial-status,s,1)

[dial-status]
exten => s,1,Gotoif($["${nome}" = ""]?5)
exten => s,n,Set(CDR(accountcode)=${nome})
exten => s,n,Noop(${exten})
exten => s,n,Hangup()
exten => s,n,Set(CDR(accountcode)= ${CALLERID(name)})
exten => s,n,Noop(${exten})
exten => s,n,Hangup()

[update-events]
exten => s,1,Gotoif($["${nome}" != ""]?3)
exten => s,n,Set(nome=${CALLERID(name)})
exten => s,n,MYSQL(Connect connid ${server} ${user} ${pass} ${dbname})
exten => s,n,MYSQL(Query update ${connid} UPDATE\ ${tablecdr}\ SET\
nome=\'${nome}\'\ WHERE\ UNIQUEID\=\'${UNIQUEID}\') 
exten => s,n,MYSQL(Disconnect ${connid})

;exten => s,n,NooP(${destino})
;exten => s,n,goto(update,s,1)
exten => h,n,hangup(1)

Atenciosamente,
André Luiz
Sertel-Info 
 -  http://www.sertelinfo.com.br
/ - andre em sertelinfo.com.br
a-  21-4063-4241 / 8566-4952

-----Mensagem original-----
De: asteriskbrasil-bounces em listas.asteriskbrasil.org
[mailto:asteriskbrasil-bounces em listas.asteriskbrasil.org] Em nome de
Alexandre Cavalcante Alencar
Enviada em: quinta-feira, 7 de maio de 2009 10:45
Para: asteriskbrasil em listas.asteriskbrasil.org
Assunto: Re: [AsteriskBrasil] OFF-TOPIC - Simulador de Asterisk

Olá Henrique, bom dia,

2009/5/7 Jose Henrique Goncalves <suhenrique em gmail.com>:
>
> Bom dia,
>
> Concordo o VMware eh uma boa opcao para se criar um ambiente de teste. Se
v
> tem o Vista pode usar o VMware Server(eh free basta se registrar e baixar)
e
> depois escolha o sabor do linux q mais sabe ou se preferir baixe um
> iso(AsteriskNOW, Elastixs, TrixBox, Meucci...).

Xen, KVM, QEmu são excelentes opções

> O unico incoveniente eh se v pretende testar Dahdi(antigo zap) com placas
> XP101P, ou necessitar de placas especificas na maquina, isto nao sera
> possivel com maquinas virtuais.
>

No Xen você pode informar o PCI ID do dispositivo que você deseja que
a VM acesse. No arquivo de definição da VM adicione o PCI ID como
reportado pelo lspci:

$ lspci
01:00.0 Ethernet controller: Intel Corporation 82571EB Gigabit
Ethernet Controller (rev 06)
01:00.1 Ethernet controller: Intel Corporation 82571EB Gigabit
Ethernet Controller (rev 06)
03:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5754
Gigabit Ethernet PCI Express (rev 02)
04:00.0 Network controller: Tiger Jet Network Inc. Tiger3XX Modem/ISDN
interface

No arquivo de configuração:

pci = ['04:00.0']
pci = ['01:00.1']

Neste caso, estou passando a placa TE110P e uma das duas portas da
placa de rede Dual Port Gigabit Intel para controle da VM.

> []
> Henrique

-- 
Alexandre C Alencar (Skarmeth)
http://blog.alexandrealencar.net/
http://www.alexandrealencar.net/
http://people.debian-ce.org/skarmeth/
_______________________________________________
Openmoko Freerunner, primeiro telefone open source, disponível no Brasil
rodando o Android da Google.
http://www.neodroid.com

Compre uma camiseta da AsteriskBrasil.org!
http://www.voipmania.com.br

Acesse o canal IRC de discussão sobre Asterisk em Português Brasileiro na
rede Freenode.net: #asterisk-br
_______________________________________________
Lista de discussões AsteriskBrasil.org
AsteriskBrasil em listas.asteriskbrasil.org
http://listas.asteriskbrasil.org/mailman/listinfo/asteriskbrasil



Mais detalhes sobre a lista de discussão AsteriskBrasil