ari – asterisk rickroll improved.

Even though the idea is brilliant, I did not like the way the original was implemented. I came up with this solution while rewriting our company’s dialplan in Lua.

So naturally, you will need the pbx_lua interpreter. You also need the music by Rick Astley himself. A preformated .gsm file can be found here. I use pbx_spool for .call files.

extensions.lua:

function rickroll()
 app.answer()
 app.background("rick")
 sleep(math.random(180))
 file = io.open("/var/spool/asterisk/outgoing/rickroll" .. math.random(9999) .. ".call","w")
 file:write("Channel: SIP/" .. channel.CALLERID("num"):get() .."\nApplication: PlayBack\nData: rick\n")
 file:close()
end

And then just assign it to some context:

extensions = {
 some_context = {
 ["_X."] = rickroll;
 };

So what does it do? It plays Rick Astleys “Never gonna let you down”. And then it waits random amount of seconds (0-180) before it calls back – and does the rickroll all over again. Thanks to Andy Goodwin for the inspiration, and Calle for the heads up.

Caveats:

  • It does not check the caller ID. Call will be returned no matter what.
  • It uses random, not unique values for call-files. Possible race condition.
  • You can always use channel["CALLERID(num)"]:set(“value”) to change the callerid.

But as an added bonus, it seems to work with most voicemails.

Sending pdfs as fax with Asterisk.

To send a fax using asterisks send_fax you obviously need the app_fax loaded. It can only be compiled into source if you have spandsp libraries available.

An easy way of sending faxes is to use .call files. These files are flat text YAML-like files which tells asterisk to execute a call. It can be used for many purposes, but is most commonly used for callbacks and faxes. In our case, the following example will do:

Channel: SIP/sip_out/87654321
CallerID: 12345678
Application: SendFAX
Data: /tmp/faxtest.tiff
SetVar: T38CALL=0

Name this file something.call and place it in our asterisk spool directory, defaults to /var/spool/asterisk/outgoing/

The script that generates the file must specify the destination number at the end of ‘Channel’, and wherever the .tiff fax is located. To convert from .pdf to .tiff, use you can use ghostscript (gs):

/usr/bin/gs -q -SDEVICE=tiffg4 -r203x98 -sPAPERSIZE=letter \
-sOutputFile=/somedir/send.tiff -dNOPAUSE -dBATCH -- /somedir/somepdf

Do not disturb for Asterisk

It is a common misconception (for some reason) that *78 and *79 is default for enable and disable do not disturb. This has to be configured in your dialplan like everything else:

[dnd]
; Enable DnD
exten => *78,1,Set(DB(SIP/DND/${CALLERID(num)})=1)
exten => *78,n,Playback(beep)
; Disable DnD
exten => *79,1,NoOp(${DB_DELETE(SIP/DND/${CALLERID(num)})})
exten => *79,n,Playback(beep)

And then include in your dial macro/sub:

exten => s,5,Set(LOCAL(dnd)=${DB("SIP/DND"/${ext})})
exten => s,6,Gosubif($[${dnd}]?8:7)
exten => s,7,Dial(${dev},10)
exten => s,8,Gosub(somewhere,s,1(${ext}))

Note that you don’t really need to answer and play the beep file. It’s just a matter of taste.

All things cat

All systems administrators are well familiar with the concatenation tool ‘cat’, and some also know of the variants such as ‘tac’, ’supercat’ and even the improved cat – ‘dog’. A few more or less useful listing of concatenation tools:

cat - the basic concatenation tool.
supercat - Introduces coloring and can be used for syntax highlighting.
tac - reverse cat.
dog - improved cat. Can fetch the newspaper (http streams)
hungrycat - Removes bytes as it concatenates leaving the file empty once completed.
ncat - Network cat. A versatile network utility.
irccat - concatenates and displays file contents on a IRC channel
barcat - Not really a concatenation tool. Produces progress bar in a *NIX shell.
cryptcat - A lightweight encrypted variant of netcat.
safecat - A "safe" variant of cat which does return codes correctly.

socat - Socket concatenation. A versatile utility handling sockets. Thanks to Christian Bryn.

And then there’s zcat and bzcat for concatenating compressed files.

Note that ‘dog’ also escapes binary  by default which can be nice when handling data in stdout, but will cause errors when concatenating binary files into files, sockets or alike. On the other hand, ‘cat’ will not escape leaving the terminal exposed. This has been exploited in several situations where a systems administrator would concatenate a log file containing malicious requests. When concatenating this to stdout, depending on your terminal, code can be executed.

If anyone knows about any other ‘cat’-like tools, please tell me.