I’m a big fan of the dc calculator - what could be clearer than typing 25sc1p1p[dSa+pLarlc1-dsc0<x]sxlxx to print the first 25 fibbonacci numbers?

There are more online calculators than anyone would care to count, but I couldn’t find a dc one, so I put one online yesterday evening.

http://dc.pr0.uk

I’ve also made an instance available as a socket - connect to dc.pr0.uk, port 1312.

If you are interested in how I set it up, please read on, otherwise, please feel free to play around.

I have a small vm, on which dc is installed. That’s the starting point. To expose this to the world, I first installed xinetd, and set it up to serve dc on port 1312. This happens to be an Ubuntu box, so the command is:

apt-get install xinetd

Here is the entry for dc which lives at /etc/xinetd.d/dc.

# description: A service which exposes dc to the world. 
service dc
{
        disable         = no
        type            = UNLISTED
        id              = dc-stream
        socket_type     = stream
        protocol        = tcp
        server          = /usr/local/bin/dctelnet
        user            = dc
        wait            = no
        port            = 1312
        rlimit_cpu      = 60
}

I’ve created a user ‘dc’, with no dangerous permissions, and created a wrapper script in /usr/local/bin/dctelnet:

#!/bin/bash
dc --version
sed -u -e 's/\r/\n/g' | dc

This script changes carriage returns as sent via telnet into line feeds as would be send by a terminal. Without this, dc complains about not understanding the carriage return characters. I also print out the version info for dc as a banner when you first connect.

To get the web version running, we need two more steps - a service which exposes a websocket and translates between that and a normal socket, and a page which is served to clients and connects to the websocket.

I have taken both of these from websockify. To start the websockify server on port 1313, run something like this:

nohup ./run 1313 localhost:1312 2>&1 & 

I used the wstelnet.html page from the websockify package, but changed the host and port to be hard coded to point to my dc server.

Finally, open the ports to the world - something like this:

iptables -A INPUT -p tcp --dport 1312 -j ACCEPT
iptables -A INPUT -p tcp --dport 1313 -j ACCEPT

And dc online is now live.