Voip Asterisk
Qualche breve cenno sulla configurazione:
File Extension.conf :
il numero chiamato è tradotto in una variabile chiamata ${EXTEN}
Ogni linea è scritta nel seguente formato:
exten => estensione,priorità,applicazione
Ad esempio:
exten => 113456,1,Answer
exten => 113456,2,Playback(NomefileinMP3)
exten => 113456,3,Wait(1)
Esistono dei caratteri speciali che devono essere sempre preceduti da "_" per essere intrpretati
X = numero qualsiasi
. = sequenza di numeri qualsiasi
Ad esempio:
exten => _561.,1,Dial(IAX2/1/${EXTEN})
exten => 200,1,Dial(SIP/200,20)
exten => 200,1,Dial(SIP/200&SIP/201,20)
nel primo caso se arriva una chiamata ad un qualsiasi numero che comincia per "561" verrà chiamata le extension 1 del canale iax (configurata nel file iax.conf) comunicando il numero chiamante, nel secondo caso se arriva una chiamata al numero "200" viene inoltrata all'extension 200 del canale sip (configurata nel file sip.conf) ma farà squollare il telefono solo per 20 secondi dopodichè passerà alla riga successiva. Nel terzo caso squillerà anche il 201.
se in oltre vogliamo che qualsiasi sia l'estensione chiamata la riga dello script sia presa in considerazione (ad esempio una macro usata da più estensioni) si può usare S al posto del numero
exten=> s,1,<comando>
se vogliamo filtrare per un'extension in base al numero che ha chiamato:
exten => <estensione chiamata>/<numero che la ha chiamata>,1,<comando>
File sip.conf
[general]
port = 5060 ; Imposta la porta UDP che rimane inascolto sul SIP
bindaddr = 0.0.0.0 ; Indirizzi di provenienza accettati (in tal caso tutti)
allow=all ; Permette tutti i tipi di codifica
context = stuffcalls ; Inoltra le chiamte SIP non previste in questo contesto
register => USERNAME:PASSWORD:NUMEROTELEFONO@PROVIDER:PORTA/EXTENSION ; per le chiamate in ingresso
[200]
type=friend ; Questo canale può inviare e ricevere chiamate
username=200 ; Username
secret=pwd ; Password
host=dynamic ; Permette la registrazione del client da IP che possono cambiare (dinamici)
context=sipfrom ; contesto dove finiranno le chiamate da questo client
mailbox=100 ; Attiva l'indicatore di messaggi se ci sono messaggi in segreteria
Comandi da riga di comando:
reload - soft-restart: utile per aggiornare Asterisk con eventuali modifiche apportate nei file di configurazione (es. sip.conf)
stop gracefully - fa ripartire Asterisk, attende fino a quando non ci sono più chiamate attive
stop now - fa ripartire Asterisk interrompendo tutte le chiamate attive
show dialplan: mostra il piano di instradamanto delle chiamate
sip show peers: utilissimo per visualizzare i client SIP registrati
iax2 show peers: visualizza i client SIP registrati
show channels - mostra tutti i canali attivi
Variabili predefinite
There are some channel variables set by Asterisk that you can refer to in your dialplan definitions. Asterisk-defined variables, in contrast to user-defined variables, are case sensitive. Note: Several of these builtin variables have been converted to functions in 1.2, to allow setting their values.
- ${ACCOUNTCODE}: Account code, if specified - see Asterisk billing (DEPRECATED in 1.2.0 and removed in 1.4. Use ${CDR(accountcode)}
- ${ANSWEREDTIME}: This is the amount of time(in seconds) for actual call.
- ${BLINDTRANSFER}: The active SIP channel that dialed the number. This will return the SIP Channel that dialed the number when doing blind transfers - see BLINDTRANSFER
- ${CALLERID(all)}: The current Caller ID name and number - See Setting Callerid for usage in Asterisk 1.4
- ${CALLERID(name)}: The current Caller ID name - ${CALLERIDNAME} was used in versions of Asterisk prior to 1.2.0, it was DEPRECATED in 1.2.0 and removed in 1.4.
- ${CALLERID(num)}: The current Caller ID number - ${CALLERIDNUM} was used in versions of Asterisk prior to 1.2.0, it was DEPRECATED in 1.2.0 and removed in 1.4.
(Note: this is not necessarily numeric as the name would indicate and can legitimately contain the space character. Commands acting on this variable (such as 'GotoIf', for example) should be aware of this).
- ${CALLINGPRES}: PRI Call ID Presentation variable for incoming calls (See callingpres )
- ${CHANNEL}: Current channel name
- ${CONTEXT}: The name of the current context
- ${DATETIME}: Current date time in the format: DDMMYYYY-HH:MM:SS This is deprecated in Asterisk 1.2, instead use :${STRFTIME(${EPOCH},,%d%mNaVH:NaVS)})
- ${DIALEDPEERNAME}: Name of the called party. Broken for now, see DIALEDPEERNAME
- ${DIALEDPEERNUMBER}: Number of the called party. Broken for now, see DIALEDPEERNUMBER
- ${DIALEDTIME}: Time since the number was dialed (only works when dialed party answers the line?!)
- ${DIALSTATUS}: Status of the call. See DIALSTATUS (note: In the current SVN release, DIALSTATUS seems to have been removed. Now you should use the DEVSTATE function. Try in astersisk console "core show function DEVSTATE" for more informations)
- ${DNID}: Dialed Number Identifier. Limitations apply, see DNID
- ${EPOCH}: The current UNIX-style epoch (number of seconds since 1 Jan 1970)
- ${EXTEN}: The current extension
- ${HANGUPCAUSE}: The last hangup return code on a Zap channel connected to a PRI interface
- ${INVALID_EXTEN}: The extension asked for when redirected to the i (invalid) extension
- ${LANGUAGE}: The current language setting. See Asterisk multi-language
- ${MEETMESECS}: Number of seconds a user participated in a MeetMe conference
- ${PRIORITY}: The current priority
- ${RDNIS}: The current redirecting DNIS, Caller ID that redirected the call. Limitations apply, see RDNIS
- ${SIPDOMAIN}: SIP destination domain of an inbound call (if appropriate)
- ${SIP_CODEC}: Used to set the SIP codec for a call (apparently broken in Ver 1.0.1, ok in Ver. 1.0.3 & 1.0.4, not sure about 1.0.2)
- ${SIPCALLID}: The SIP dialog Call-ID: header
- ${SIPUSERAGENT}: The SIP user agent header
- ${TIMESTAMP}: Current date time in the format: YYYYMMDD-HHMMSS This is deprecated as of Asterisk 1.4, instead use :${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
- ${TRANSFERCAPABILITY}: Type of Channel
- ${TXTCIDNAME}: Result of application TXTCIDName (see below)
- ${UNIQUEID}: Current call unique identifier
- ${TOUCH_MONITOR}: used for "one touch record" (see features.conf, and wW dial flags). If is set on either side of the call then that var contains the app_args for app_monitor otherwise the default of WAV||m is used
Variabili di applicazione
Some applications take extra input or provide output using channel variables.
- AgentCallbackLogin returns ${AGENTBYCALLERID_${CALLERID}}: The ID of the agent successfully logged on.
- ChanIsAvail returns ${AVAILCHAN}: The first available channel
- Dial takes input from ${VXML_URL}: Send XML Url to Cisco 7960 or to i6net VoiceXML browser
- Dial takes input from ${ALERT_INFO}: Set ring cadence or allow intercom on for various SIP phones
- Dial returns ${CAUSECODE}: If the dial failed, this is the errormessage
- Dial returns ${DIALSTATUS}: Text code returning status of last dial attempt.
- Dial takes input from ${TRANSFER_CONTEXT}: If this variable exists, when a #transfer is executed it goes to the selected extension on this context.
- EnumLookup returns ${ENUM}: The result of the lookup
- Hangup reads the ${PRI_CAUSE} variable for setting PRI return codes
- MeetMe takes input from {MEETME_AGI_BACKGROUND}: An AGI script to run
- MeetMe returns ${MEETMESECS}: The number of seconds the user was in a conference
- Playback returns ${PLAYBACKSTATUS}: The status of the command (FAILED|SUCCESS)
- Queue returns ${QUEUESTATUS}: The reason for popping the call out of the queue
- TXTCIDName returns ${TXTCIDNAME}: The result of the DNS lookup
- VoiceMail returns ${VMSTATUS}: indicates the status of the execution of the VoiceMail application. Possible values are: SUCCESS | USEREXIT | FAILED .
Variabili di Macro
When in a macro context, extra channel variables are available.
- ${ARG1}: The first argument passed to the macro
- ${ARG2}: The second argument passed to the macro (and so on)
- ${MACRO_CONTEXT}: The context of the extension that triggered this macro
- ${MACRO_EXTEN}: The extension that triggered this macro
- ${MACRO_OFFSET}: Set by a macro to influence the priority where execution will continue after exiting the macro
- ${MACRO_PRIORITY}: The priority in the extension where this macro was triggered
Variabili del file extension
- ${REASON}: A number that represents the reason why an outgoing call failed. See Asterisk Reason variable.
Variabili di ambiente
You may access unix environment variables using the syntax:
${ENV(foo)}
- ${ENV(ASTERISK_PROMPT)}: the current Asterisk CLI prompt.
- ${ENV(RECORDED_FILE)}: the filename of the last file saved by the Record command (available in CVS > 2004-03-21)