Asterisk HowTo

Da TondoWiki.

Ruota dentata.png

Pre-Bozza. Il seguente articolo non ha ancora raggiunto lo stato di Bozza. Ciò significa che molto probabilmente è stato redatto semplicemente annotando i passi principali o altre cose che solo l'autore potrebbe comprendere. E' quindi da considerarsi non solo incompleto ma molto probabilmente anche impreciso e non formalmente corretto. Per questi motivi è in dubbio l'autorevolezza stessa del documento.

Indice

Premessa

Abbiamo installato il tutto da sorgenti/svn perchè i pacchetti disponibili nonostante fosserò "aggiornati" davano problemi con il kernel 2.6.31 (aka non funzionava niente).

Compilazione e Installazione

DAHDI

DAHDI sta per Digium Asterisk Hardware Device Interface ed ha preso il posto del "vecchio" Zaptel/Zapata tant'è che si trovano guide che spiegano come passare dalle vecchie configurazioni alle nuove.

Non è il nostro caso che faremo la configurazione per la prima volta.

dahdi-linux

Moduli del kernel

cd /usr/src/
svn checkout http://svn.digium.com/svn/dahdi/linux/trunk dahdi-linux
cd dahdi-linux
make
make install

dahdi-tools

Utility necessarie a testare la scheda e generare la configurazione in automatico

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/dahdi-tools/dahdi-tools-current.tar.gz
tar -xvzf dahdi-tools-current.tar.gz
cd dahdi-tools-2.2.0
./configure
make menuselect

Entriamo in utilities e guardiamo se manca qualcosa. Nel nostro caso avevamo una [E] in dahdi_tool e andandoci sopra diceva che mancava libnewt quindi

apt-get install libnewt-dev

Quindi nuovamente i due comandi di prima (./configure e make menuselect) per vedere se tutte le dipendenze sono soddisfatte. Se tutto è ok procediamo con

make
make install
make config

Avviamo dahdi

/etc/init.d/dahdi start
root@asterisk:~# dahdi_hardware 
pci:0000:01:08.0     wcfxo+       1057:5608 Wildcard X100P
root@asterisk:~# dahdi_scan
[1]
active=yes
alarms=OK
description=Wildcard X100P Board 1
name=WCFXO/0
manufacturer=Digium
devicetype=Wildcard X100P
location=PCI Bus 01 Slot 09
basechan=1
totchans=1
irq=18
type=analog
port=1,FXO

Dalla console di asterisk

asterisk*CLI> dahdi show status
Description                              Alarms  IRQ    bpviol CRC4   Fra Codi Options  LBO
Wildcard X100P Board 1                   OK      0      0      0      CAS Unk  YEL      0 db (CSU)/0-133 feet (DSX-1)
asterisk*CLI> dahdi show channels 
   Chan Extension  Context         Language   MOH Interpret        Blocked    State     
 pseudo            default                    default                         In Service
      1            from-pstn       it         default                         In Service

GoogleTalk

Per fare/ricevere chiamate con asterisk usando GoogleTalk

cd /usr/src/
wget http://iksemel.googlecode.com/files/iksemel-1.4.tar.gz
tar -xf iksemel-1.4.tar.gz
cd iksemel-1.4/
./configure --prefix=/usr
make
make check
make install
ldconfig -v

Asterisk

Configurazioni

DAHDI

  • /etc/dahdi/system.conf
# Span 1: WCFXO/0 "Wildcard X100P Board 1" (MASTER)
fxsks=1
echocanceller=mg2,1

# Global data

loadzone        = it
defaultzone     = it
  • /etc/asterisk/chan_dahdi.conf
[channels]  
language=it                     ;audio language (voice)
usecallerid=yes
hidecallerid=no
callwaiting=no
threewaycalling=no
transfer=no
echocancel=no                   ;echocancel=256 means 256 / 8 = 32 ms.  o echocanel=yes.
echocancelwhenbridged=no
echotraining=no                 ;o 800 o 1600

;rxgain=-2.0                    ; Setting using ** dahdi_monitor 1 -vv **
;txgain=4.5

context=from-pstn
signalling=fxs_ks
group=1
channel=>1
  • /etc/asterisk/dahdi-channels.conf
; Span 1: WCFXO/0 "Wildcard X100P Board 1" (MASTER)
;;; line="1 WCFXO/0/0 FXSKS  (SWEC: MG2)"
signalling=fxs_ks
callerid=asreceived
group=1
context=from-pstn
channel => 1
callerid=
group=
context=default

sip.conf

;*** GLOBAL SETTING

[general]
context=default
bindport=5060
bindaddr=0.0.0.0
externhost=myip.dyndns.org
localnet=192.168.1.0/255.255.255.0
disallow=all
allow=alaw
allow=ulaw
language=it

;*** REGISTER STATEMENTS

register => 6969xxxxx:xxxxxxxxx@sip.cheapnet.it/052218xxxx5
register => 6554xxxxx:xxxxxxxxx@sip.cheapnet.it/052218xxxx2
 
;*** FRIENDS, USER AND PEERS

;type=user      ;può solo ricevere chiamate
;type=peer      ;può solo effettuare chiamate
;type=friend    ;può ricevere/effettuare chiamate

[6000]
type=friend
host=dynamic
secret=xxxxxxxx
context=interni1
nat=yes
qualify=yes

[6100]                        
type=friend
host=dynamic
secret=xxxxxxxx
context=interni2
nat=yes
qualify=yes

[cheapnet1]                                     ; LINEA 1
context=cheapnet-in
type=peer
username=6969xxxxxx@sip.cheapnet.it
secret=xxxxxxxxxx
fromuser=6969xxxxxx
fromdomain=sip.cheapnet.it
host=sip.cheapnet.it
outboundproxy=sip.cheapnet.it
insecure=invite,port
realm=sip.cheapnet.it
nat=yes
qualify=yes
disallow=all
allow=alaw
allow=ulaw

; ***** SECONDARIO ************************

[cheapnet2]
context=cheapnet-in                             ; LINEA 2
type=peer
username=6554xxxxxx@sip.cheapnet.it
secret=xxxxxxxxx
fromuser=6554xxxxxx
fromdomain=sip.cheapnet.it
host=sip.cheapnet.it
outboundproxy=sip.cheapnet.it
insecure=invite,port
realm=sip.cheapnet.it
nat=yes
qualify=yes
disallow=all
allow=alaw 
allow=ulaw

extensions.conf

[general]
static=yes
writeprotect=no
autofallthrough=yes
clearglobalvars=no
priorityjumping=no

[cheapnet-in]
                                                       ; LINEA 1
exten => 052218xxxx5,1,Dial(SIP/6000)                  ; squilla all'infinito
exten => 052218xxxx5,n,Hangup

exten => 052218xxxx2,1,Ringing                         ; LINEA 2
exten => 052218xxxx2,n,Wait(5)
exten => 052218xxxx2,n,Congestion(2)
exten => 052218xxxx2,n,Hangup

[cheapnet-out1]                                        ; LINEA 1

exten => _[03].,1,Dial(SIP/${EXTEN}@cheapnet1)         ; landline & mobile
exten => _[03].,n,Hangup

[cheapnet-out2]                                        ; LINEA 2

exten => _0.,1,Dial(SIP/${EXTEN}@cheapnet2)            ; landline only
exten => _0.,n,Hangup

Voicemail

  • /etc/asterisk/voicemail.conf

modificare le seguenti righe

[general] 
;format=wav49|gsm|wav
format=wav
; Who the e-mail notification should appear to come from
serveremail=youremail@yourdomain.tld
; Should the email contain the voicemail as an attachment
attach=yes
; Maximum number of messages per folder.  If not specified, a default value
; (100) is used.  Maximum value for this option is 9999.
maxmsg=100
; Maximum length of a voicemail message in seconds
maxsecs=180
; Minimum length of a voicemail message in seconds for the message to be kept
; The default is no minimum.
minsecs=3
; How many seconds of silence before we end the recording
maxsilence=10
emailsubject=[PBX voicemail]: New message (n. ${VM_MSGNUM}) from ${VM_CIDNUM} in mailbox ${VM_MAILBOX}
emaildateformat=%A, %d %B %Y at %H:%M:%S
mailcmd=perl /var/lib/asterisk/agi-bin/mp3vm.pl
[default]
6001 => 12345,Andrea Tondelli,blablablablablablabla@gmail.com


Creare il file /var/lib/asterisk/agi-bin/mp3vm.pl

#!/usr/bin/perl
open(VOICEMAIL,"|/usr/sbin/sendmail -t");
open(LAMEDEC,"|/usr/bin/dos2unix|/usr/bin/base64 -di|/usr/bin/lame --quiet --preset voice - /var/spool/asterisk/tmp/vmout.$$.mp3");
open(VM,">/var/spool/asterisk/tmp/vmout.debug.txt");
my $inaudio = 0;
loop: while(<>){
  if(/^\.$/){
    last loop;
  }
  if(/^Content-Type: audio\/x-wav/i){
    $inaudio = 1;
  }
  if($inaudio){
    while(s/^(Content-.*)wav(.*)$/$1mp3$2/gi){}
    if(/^\n$/){
      iloop: while(<>){
        print LAMEDEC $_;
        if(/^\n$/){
          last iloop;
        }
      }
      close(LAMEDEC);
      print VOICEMAIL "\n";
      print VM "\n";
      open(B64,"/usr/bin/base64 /var/spool/asterisk/tmp/vmout.$$.mp3|");
      while(<B64>){
        print VOICEMAIL $_;
        print VM $_;
      }
      close(B64);
      print VOICEMAIL "\n";
      print VM "\n";
      $inaudio = 0;
    }
  }
  print VOICEMAIL $_;
  print VM $_;
}
print VOICEMAIL "\.";
print VM "\.";
close(VOICEMAIL);
close(VM);

#CLEAN UP THE TEMP FILES CREATED
#This has to be done in a separate cron type job
#because unlinking at the end of this script is too fast,
#the message has not even gotten piped to send mail yet

quindi

chmod a+rx /var/lib/asterisk/agi-bin/mp3vm.pl

AGI - Asterisk Gateway Interface

Tutte le variabili che Asterisk passa automaticamente allo script sono le seguenti

Semplicissima estensione che invoca l'AGI

exten => 6999,1,Answer
exten => 6999,n,AGI(nothing.php)

Semplicissimo (ora che ho capito) AGI che non fa niente. Il codice va inserito dove c'è scritto Operational Code starts here rimuovendo i commenti. Quindi

nano /usr/share/asterisk/agi-bin/nothing.php
#!/usr/bin/php -q
<?

   ob_implicit_flush(false);
   set_time_limit(6);

   $stdin = fopen('php://stdin', 'r');

   /* Handling execution input from Asterisk */
   $agivars = array();
   while (!feof($stdin))
   {
         $temp = fgets($stdin);
         $temp = str_replace("\n","",$temp);
         $s = explode(":",$temp);
         $agivars[$s[0]] = trim($s[1]);
         if ($temp == "")
         {
              break;
         }
   }
   extract($agivars);

   /* Operational Code starts here */
   //
   //
   //

   /* Finalization of AGI script and clean-ups */
   fclose ($stdin);

   exit(0);

?>

Per vedere quel che succede durante l'esecuzione della AGI digitate nella command line di asterisk

asterisk*CLI> agi set debug on

E vi troverete una cosa simile a questa

 == Using SIP RTP CoS mark 5
   -- Executing [6999@interni2:1] Answer("SIP/6100-09b36258", "") in new stack
   -- Executing [6999@interni2:2] AGI("SIP/6100-09b36258", "frompstn.agi") in new stack
   -- Launched AGI Script /var/lib/asterisk/agi-bin/frompstn.agi
<SIP/6100-09b36258>AGI Tx >> agi_request: frompstn.agi
<SIP/6100-09b36258>AGI Tx >> agi_channel: SIP/6100-09b36258
<SIP/6100-09b36258>AGI Tx >> agi_language: it
<SIP/6100-09b36258>AGI Tx >> agi_type: SIP
<SIP/6100-09b36258>AGI Tx >> agi_uniqueid: 1262214606.23
<SIP/6100-09b36258>AGI Tx >> agi_version: 1.6.1.9
<SIP/6100-09b36258>AGI Tx >> agi_callerid: 6100
<SIP/6100-09b36258>AGI Tx >> agi_calleridname: unknown
<SIP/6100-09b36258>AGI Tx >> agi_callingpres: 0
<SIP/6100-09b36258>AGI Tx >> agi_callingani2: 0
<SIP/6100-09b36258>AGI Tx >> agi_callington: 0
<SIP/6100-09b36258>AGI Tx >> agi_callingtns: 0
<SIP/6100-09b36258>AGI Tx >> agi_dnid: 6999
<SIP/6100-09b36258>AGI Tx >> agi_rdnis: unknown
<SIP/6100-09b36258>AGI Tx >> agi_context: interni2
<SIP/6100-09b36258>AGI Tx >> agi_extension: 6999
<SIP/6100-09b36258>AGI Tx >> agi_priority: 2
<SIP/6100-09b36258>AGI Tx >> agi_enhanced: 0.0
<SIP/6100-09b36258>AGI Tx >> agi_accountcode: 
<SIP/6100-09b36258>AGI Tx >> agi_threadid: -1236509840
<SIP/6100-09b36258>AGI Tx >> 
   -- <SIP/6100-09b36258>AGI Script frompstn.agi completed, returning 0
   -- Auto fallthrough, channel 'SIP/6100-09b36258' status is 'UNKNOWN'

Appunti alla rinfusa

  • removed
exten => _X.,1,AbsoluteTimeout(1200)
exten => _X.,2,Dial(SIP/Provider/${EXTEN:0})


[newsms]
exten => 400,n,Answer
; exten => 400,n,AbsoluteTimeout(1200)
; exten => 400,n,Background("hello")
; exten => 400,n,Wait(5)
exten => 400,n,HangUp()


originate SIP/numero@peer-sip.conf extension 400@newsms

GUI

Installazione

Sorgenti aggiornati disponibili all'indirizzo http://downloads.asterisk.org/pub/

Creare una directory asterisk dove posizionare i sorgenti, ad esempio sotto /usr/src:

~$ cd /usr/src/
~$ mkdir asterisk/
~$ cd asterisk/

Scaricare le versioni aggiornate del software asterisk e i suoi relativi addons:

~$ wget http://downloads.digium.com/pub/asterisk/asterisk-1.6.0.6.tar.gz
~$ wget http://downloads.digium.com/pub/asterisk/asterisk-addons-1.6-current.tar.gz

Scaricare in oltre mediante svn i sorgenti dell'interfaccia utente:

~$ svn checkout http://svn.digium.com/svn/asterisk-gui/branches/2.0 asterisk-gui

Tutto l'occorrente per l'installazione è stato preparato, scompattare gli archivi:



Installazione di Asterisk

~$ tar xvf asterisk-1.6.0.6.tar.gz
~$ cd asterisk-1.6.0.6
~$ ./configure
~$ make
~$ make install
~$ make samples
~$ make config

Installazione di Asterisk Addons

~$ tar xvf asterisk-addons-1.6-current.tar.gz
~$ cd asterisk-addons-1.6.0.1
~$ ./configure
~$ make
~$ make install

Installazione di Asterisk GUI

~$ cd asterisk-gui
~$ ./configure
~$ make
~$ make install
~$ make samples

Configurazione

~$ vim /etc/asterisk/http.conf

[general]
enabled=yes
bindaddr=127.0.0.1
bindport=8088
enablestatic=yes
redirect = / /static/config/cfgbasic.html
sslenable = yes
sslbindport = 8089
sslbindaddr = 127.0.0.1


~$ vim /etc/asterisk/manager.conf

[general]
enabled = yes
webenabled = yes
port = 5038
bindaddr = 0.0.0.0

[admin]
secret = adminpasswd
read = system,call,log,verbose,command,agent,user,config
write = system,call,log,verbose,command,agent,user,config,originate


Patch

Link utili

16-12-2009

Strumenti personali