Configuration


6 avril 2009: 22:05: nicolasConfiguration, Recette

We have a Trixbox server at the office, and I have one at my home too. They have been working fine independently of each other for a while, but I figured if they could talk to each other over the internet instead of our VoIP provider, I could save few bucks each year and get a higher geek score.

Well, there’s a good reason I wanted this: I wanted my home extension to not only ring my cell phone, but also my office phone, but the office has a single number and a menu where you have to compose an extension. I haven’t found how to tell Trixbox to compose an extension after dialing a number, so linking both Trixbox server made sense.

I’m going to describe how I did it, because I need to explain this to a co-worker, and there’s generally a lack of good documentation on the internet.

My office has a static IP address, so my home server will be connecting to the office. This should fit most people with dynamic IP addresses at home. I did this from the office and created an SSH tunnel to the web interface of my trixbox home server: ssh -L8080:trixbox:80 me@home.

Open UDP port 4569 in the office firewall

Open UDP port 4569 in the office firewall and map it to your Trixbox server. This will allow anyone on the internet to connect to your Asterisk server with the IAX2 protocol. To increase security, I suggest you limit who can connect to the block of IP addresses of your ISP, or to your IP address it you have a fixed IP address.

Create an extension in the office server

On your office Trixbox web interface, enter Admin mode and go to PBX > PBX Settings, then go in Extensions, click Add Extension and pick Generic IAX2 Extension. Enter your real name in the Display Name, put your home phone number in User Extension, create a password (numeric only?) in the field named secret and click Submit. Apply your changes.

Add a trunk in your home server

On your home Trixbox web interface, enter Admin mode and go to PBX > PBX Settings, then go in Trunks, click Add Trunk and Add IAX2 Trunk.

In the Outbound Caller ID field, enter Your Name . Enter office for the Trunk Name and fill the PEER Details form by specifying your office IP address or host name for the host, the extension number you just created on you office server for the user, and the extension password for the secret.

Name your USER Context something like office-in, and fill the USER Details just like you did with PEER Details, except this one doesn’t need the host. Next, fill the Register String with “extension:password@host_or_ip”, where host_or_ip is the host or IP address of your office. Submit and apply your changes.

Check that the IAX2 connection was made

On your home Trixbox web interface, enter Admin mode and go to PBX > PBX Status, and in the IAX2 Registry section, check that you new trunk is in state Registered. If it is not, I suggest you check the logs of both the office and the home server to figure out what went wrong. This is where you need ninja skills. Leave a comment here if you need help.

Create an inbound route at home

Now, if someone composes your new extension at work, it will reach your home server, but you’ll get a message saying “All circuits are busy” because you haven’t said where to route the call. On you home server, you need to go to PBX > PBX Settings, Inbound Routes and click Add Incoming Route. Enter “office” in Description.

Ideally, you would specify a DID Number, but I’m not yet sure what the office server passes in so I left it blank for now. This means the Inbound route will match all incoming calls. I also have other routes with a DID Number specified and they are still functional, so the catch-all shouldn’t be a problem for you too.

Now choose what you want to do. Most likely, you’ll want to ring an existing extension, or a ring group. Submit and apply your changes. From the office, calling the IAX2 extension should ring your home extension. If it doesn’t, check the logs on both servers and mentally prepare yourself to bang your head on a wall. Fortunately, I didn’t have to.

Create an outbound route at home

Now that you can call your extension at home, you’ll want to be able to call the office from home. For this, you need a new Outbound Route. Go to PBX > PBX Settings, Outbound Routes and click Add Route. A nice name for this would be “office”. As for the Dial Patterns, I have three:

5141234567
5141234567|XXX
7|.

The first line means the route will match that exact number. The second line is mostly useful if I don’t have line three, which is a shortcut for line two: Dialing any number prefixed with “7″ will be sent to your office server with the “7″ stripped.

Next, the Trunk Sequence only needs your Office trunk. Submit and apply your changes. Go home and dial “7″ followed by an extension that exists at your office. If it doesn’t ring, bang your head in the wall. If it doesn’t make it work, bang again. You know how this works. Did I mention to check your asterisk log files?

You’re done!

Well, perhaps not. Anyway, this should have helped getting you pretty close to what you wanted.

I did more: I added “7203#” in the follow-me settings of my home extension. “7″ selects the office trunk, 203 is my office extension, and the pound sing tells Trixbox this is not an extension, but an external call. It means someone calling me at home will also ring my office phone. Since the follow-me also includes my cell phone (”95141234567#”), I’m reachable more than ever.

At the office, my follow-me settings also include my cell phone, and now include the IAX2 extension of my home server. I’m reachable more than ever.

Feel free to share your questions as a comment below, share your experiences, or copy/modify/translate this post to a wiki or else. I’m also reachable through micro-blogging at Identi.ca. There is a real lack of good Trixbox recipes!

19 janvier 2009: 11:33: nicolasConfiguration, Fonctionnalité, Son

J’ai plusieurs sorties audio sur mon ordinateur: une intégrée à la carte mère, deux sur une carte d’extension PCI, et un casque d’écoute branché en USB. Ça fait un petit bout de temps que j’aimerais pouvoir jouer ma musique sur toutes ces sorties en même temps, quitte à mettre au minimum le volume des appareils non-voulus.

Avec Debian, dans Ubuntu, y’a un panneau de préférences pour le son, où je peux indiquer ce qui joue chaque catégorie de son. Je l’utilisais assez souvent pour changer entre haut-parleurs et casque d’écoute pour en mettre le raccourci dans un panneau du bureau. Ça reste insuffisant pour mes besoins.

En installant les programmes de configuration de PulseAudio, j’ai réussi à faire jouer Rhythmbox sur toutes mes sorties, simultanément. J’ai cherché PulseAudio dans l’ajout/suppression de programmes, mais pour ceux qui préféreraient copier-coller, voici l’équivalent en ligne de commande:

sudo apt-get install `apt-cache search PulseAudio|grep ^pa|cut -d ' ' -f1

ou plus explicitement:

sudo apt-get install padevchooser paman paprefs pavucontrol pavumeter

Puis, dans Applications, Son et vidéo, il y a maintenant “PulseAudio Device Chooser” qui ajoute une icône dans la barre de notification du panneau. En cliquant sur “Configure Local Sound Server”, vous verrez un onglet “Simultaneous Output”. Activez cette option. Maintenant, il faut dire à Gnome d’utiliser PulseAudio en allant dans Système, Préférences, Son. Dans la liste de périphériques de sortie, il y a maintenant “Serveur de son PulseAudio”.

Pour une raison que j’ignore, j’ai dû redémarrer mon PC pour que PulseAudio démarre correctement. Pour voir si le serveur PulseAudio est démarré, dans l’applet PulseAudio, cliquez sur Manager. Si vous êtes connecté, c’est qu’il roule!

Pour finir, toujours dans l’applet, choisissez “Simultaneous output” dans “Default Sink”.

Paramètres PulseAudio

31 mars 2008: 23:37: nicolasConfiguration, Courriel, Recette

Quand je me suis acheté un laptop et que je l’ai utilisé ailleurs que chez moi, j’ai réalisé que je ne pouvais pas facilement envoyer de courriels, parce qu’il fallait que je change ma configuration de serveur sortant selon le fournisseur d’accès internet où je me trouvais. Ceci, parce qu’Exim refusait de faire le relai de mes courriels si je tentais d’utiliser mon serveur SMTP à la maison, évitant ainsi d’être un “relai ouvert” (open relay).

Récemment, j’ai donné des adresses courriel à des membres de ma famille, et j’ai eu un problème semblable, quoique plus frustrant: le fournisseur d’accès internet refuse de faire le relai quand l’adresse de l’envoyeur n’est pas reconnue. Avec Vidéotron, je ne pouvais pas envoyer un courriel prétendant provenir de marchildon.net, alors qu’un envoyeur@videotron.ca fonctionne.

Ça fait longtemps que je savais ce que je devais faire: activer l’authentification SMTP. Voici donc comment j’y suis parvenu.

Premièrement, j’ai testé une authentification très simple, avec un nom d’usager et un mot de passe fixes. J’ai pu tester sur mon serveur en production car j’étais le seul qui l’utilisait comme serveur sortant pour mon réseau local privé.

Dans /etc/exim4/conf.d/auth/30_exim4-config_examples, j’ai ajouté:

fixed_plain:
  driver = plaintext
  public_name = PLAIN
  server_advertise_condition = *
  server_prompts = :
  server_condition = \
    ${if and {{eq{$2}{username}}{eq{$3}{mysecret}}}}
  server_set_id = $2

Puis j’ai activé cette configuration avec /etc/init.d/exim4 reload, et j’ai voulu tester ça avec une session telnet. J’ai converti l’usager et le mot de passe en base64 pour ensuite passer le résultat à la commande AUTH d’une session SMTP:

vesicule:~# cat bin/encode
#!/usr/bin/perl
use MIME::Base64;
printf ("%s", encode_base64(eval "\"$ARGV[0]\”"));
vesicule:~# bin/encode '\\0username\\0mysecret'
AHVzZXJuYW1lAG15c2VjcmV0
vesicule:~# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 mail.marchildon.net ESMTP Exim 4.50 Mon, 31 Mar 2008 20:59:54 -0400
EHLO marchildon.net
250-mail.marchildon.net Hello localhost [127.0.0.1]
250-SIZE 52428800
250-PIPELINING
250-AUTH PLAIN   <----------- yes!
250 HELP
AUTH PLAIN asdf
535 Incorrect authentication data
AUTH PLAIN AHVzZXJuYW1lAG15c2VjcmV0
235 Authentication succeeded
QUIT
221 mail.marchildon.net closing connection

J’ai vérifié ci-haut qu’en passant n’importe quoi à AUTH (”asdf”), j’obtenais un échec, et qu’en passant le bon usager et mot de passe (la ligne “AUTH PLAIN AHVzZXJuYW1lAG15c2VjcmV0″), j’obtenais un succès.

Ensuite, j’ai voulu faire en sorte que les mots de passe soient les mêmes que pour les connexion POP et IMAP fournies par courier-imap. J’ai donc modifié ma configuration dans 30_exim4-config_examples pour ceci:

plain_courier_authdaemon:
  driver = plaintext
  public_name = PLAIN
  server_advertise_condition = *
  server_prompts = :
  server_condition = ${extract {address} {${readsocket{/var/run/courier/authdaemon/socket} \
      {AUTH ${strlen:exim\nlogin\n$2\n$3\n}\nexim\nlogin\n$2\n$3\n} }} {yes} fail}
  server_set_id = $2

J’ai répété le test avec un session telnet, cette fois-ci avec mon nom d’usager et mon vrai mot de passe (toujours encodé base64).

Satisfait, j’ai voulu mentionner dans les en-têtes du message le nom de l’usager qui a été authentifié. J’ai donc ajouté ceci à main/02_exim4-config_options:

received_header_text = Received: \
  ${if def:sender_rcvhost {from $sender_rcvhost\n\t}\
  {${if def:sender_ident \
  {from ${quote_local_part:$sender_ident} }}\
  ${if def:sender_helo_name {(helo=$sender_helo_name)\n\t}}}}\
  by $primary_hostname \
  ${if def:received_protocol {with $received_protocol}} \
  ${if def:tls_cipher {($tls_cipher)\n\t}}\
  (Exim $version_number)\n\t\
  ${if def:sender_address \
  {(envelope-from <$sender_address>)\n\t}}\
  id $message_id\
  ${if def:received_for {\n\tfor $received_for}}\
  ${if def:authenticated_id {\n\tauthenticated $authenticated_id}}

La ligne importante est ${if def:authenticated_id {\n\tauthenticated $authenticated_id}}.

J’aurais pu terminer ici, mais j’étais conscient que mon mot de passe aurait été transmis pratiquement en clair sur internet. J’ai donc entrepris de configurer TLS, d’abord en générant un certificat auto-signé:

# cd /etc/exim4
# /usr/share/doc/exim4-base/examples/exim-gencert
# ls -l exim.*
-rw-r-----  1 root Debian-exim 721 2008-03-31 22:18 exim.crt
-rw-r-----  1 root Debian-exim 887 2008-03-31 22:18 exim.key
# openssl x509 -noout -text -in /etc/exim4/exim.crt | head -n 14
Certificate:
    Data:
        Version: 1 (0x0)
        Serial Number:
            b8:35:2c:e2:2f:8c:95:f7
        Signature Algorithm: md5WithRSAEncryption
        Issuer: C=CA, ST=Qu\xC3\xA9bec, CN=mail.marchildon.net
        Validity
            Not Before: Apr  1 02:21:52 2008 GMT
            Not After : Apr  1 02:21:52 2011 GMT
        Subject: C=CA, ST=Qu\xC3\xA9bec, CN=mail.marchildon.net
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (1024 bit)

Notez que j’ai spécifié mail.marchildon.net parce que je spécifie la même chose dans la configuration du serveur sortant dans Thunderbird. Si je mets autre chose, j’obtiens un avertissement de sécurité de la part de Thunderbird.

Comme dernière configuration pour activer TLS, j’ai créé le fichier /etc/exim4/conf.d/main/00_local:

MAIN_TLS_ENABLE = true

Après un /etc/init.d/exim4 reload, j’ai vérifié que Exim annonce son support de connexions TLS:

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 mail.marchildon.net ESMTP Exim 4.50 Mon, 31 Mar 2008 22:20:20 -0400
EHLO marchildon.net
250-mail.marchildon.net Hello localhost [127.0.0.1]
250-SIZE 52428800
250-PIPELINING
250-STARTTLS   <------------- Yes!
250 HELP
QUIT
221 mail.marchildon.net closing connection

J’ai ensuite forcé Thunderbird à utiliser TLS pour le serveur sortant SMTP, et j’ai testé l’envoi d’un courriel à partir de mon réseau privé. Le log d’Exim montre que la connexion était encryptée (X=TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) et que j’étais authentifié (A=plain_courier_authdaemon:nicolas):

# tail -n 1 /var/log/exim4/mainlog
2008-03-31 22:22:05 1JgW8T-0005HZ-GQ <= nicolas@marchildon.net H=cortex [192.168.1.50] P=esmtpsa X=TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32 A=plain_courier_authdaemon:nicolas S=870 id=47F1A467.8000509@marchildon.net

J’ai ensuite testé le relai d’un courriel en provenance d’internet avec un tunnel SSH et Thunderbird se connectant au port 2500 de localhost:

# ssh -L2500:marchildon.net:25 nicolas@remote-host.org

Le relai est accepté, comme prévu:

# tail -n 1 /var/log/exim4/mainlog
2008-03-31 22:28:00 1JgWDj-0005Hz-3w <= nicolas@marchildon.net H=nagios.solucorp.qc.ca ([127.0.0.1]) [207.253.4.248] P=esmtpsa X=TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32 A=plain_courier_authdaemon:nicolas S=1545 id=47F1A5A1.6050108@marchildon.net

Enfin, j’ai désactivé TLS et vérifié que le relai est refusé, parce que ma configuration ne permet pas l’authentification sur une connexion non-encryptée:

# tail -n 1 /var/log/exim4/mainlog
2008-03-31 22:31:39 H=nagios.solucorp.qc.ca ([127.0.0.1]) [207.253.4.248] F= rejected RCPT : relay not permitted