Skip to content

Instantly share code, notes, and snippets.

@zouppen
Last active August 29, 2015 14:15
Show Gist options
  • Save zouppen/b82b0492eefbf602482f to your computer and use it in GitHub Desktop.
Save zouppen/b82b0492eefbf602482f to your computer and use it in GitHub Desktop.
SMS to IRC gateway using Irssi Proxy and Kannel

SMS to IRC gateway

Everybody! Get the feeling of the 90s! Let the dreams come true!

This is a proof of concept for implementing SMS to IRC gateway using Kannel SMS gateway, Irssi Proxy, and an ordinary mobile stick (in my case Huawei E166).

To send message to IRC, just type the following message and send it to the phone number of the gateway:

irc #targetchannel message

Of course, it supports private messages and all channel types.

Feel free to ask me for details if you really want to use this for something. :-)

The toughest job for me was getting Kannel running. Some combat notes: Debian package for Kannel is good, use it if available. Remember to disable all WAP stuff there and make sure all files have correct permissions.

# Snippet for kannel.conf which registers keyword "irc" and invokes
# IrcSms module with phone number. Please read
# http://www.kannel.org/download/kannel-userguide-snapshot/userguide.html#AEN3976
group = sms-service
keyword = irc
max-messages = 0
exec = "runhaskell /opt/SmsIrc.hs \"%p\" \"%s\" \"%r\""
-- |Kannel service for sending SMS messages to IRC via Irssi Proxy.
module Main where
import Control.Monad
import Network
import Network.HTTP.Base
import System.Environment
import System.IO
import Text.Printf
-- Some magic numbers
allowedPhone = "+358401234567"
irssiProxyHost = "localhost"
irssiProxyPort = 1337
irssiProxyPass = "salasana"
main :: IO ()
main = do
args <- getArgs
case map decodeAndSanitize args of
[phone,channel,msg] -> do
unless (phone == allowedPhone) $ fail "Unauthorized user"
irc channel msg
_ -> fail "Channel name and message required"
irc :: String -> String -> IO ()
irc channel msg = do
h <- connectTo irssiProxyHost $ PortNumber irssiProxyPort
hSetEncoding h utf8
hPrintf h "PASS %s\nUSER\nNICK\nPRIVMSG %s :%s\nQUIT\n" irssiProxyPass channel msg
hClose h
decodeAndSanitize :: String -> String
decodeAndSanitize = map (replace '\n' ' ') . urlDecode . map (replace '+' ' ')
where replace search replacement x = if search == x then replacement else x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment