Monday, 1 September 2008

 

SMS to Laconi.ca - An introduction

I've not posted in a while, but I thought I'd put together some notes about a little project I started to help out the Laconi.ca community.

Just to introduce Laconi.ca for those who don't already know about it; it's a federated micro-blogging system. You might have heard about this from people talking about identi.ca (which is the best known implementation of the Laconi.ca code base).

So, what does my project do to help you?

A lot of these micro-blogging systems have their message sizes based on the size of an SMS text message, but the Laconi.ca code doesn't have a way of receiving text messages. The code I wrote allows members of the community to set up their own SMS gateway which, using the most complete Laconi.ca API (which just so happens to be based on the Twitter API) relays the message to any Laconi.ca (or, because it's based on the Twitter API - twitter) instance.

If you want to set up your own smsToLaconica gateway, the code is available from my Subversion Repository, but you will also need a few things.I set up Bluez using the Gnome Bluetooth tools by pairing the phone with the computer, but I know that not everyone has even a desktop on their Linux machines, so I've researched a little and found that everything we need can be done with one tool, hcitool.

Running the command
hcitool scan
will return
Scanning ...
11:22:33:44:55:66 MyDeviceName
where 11:22:33:44:55:66 is the Bluetooth ID of the device. Pair the device with the adaptor using the command
hcitool cc 11:22:33:44:55:66
Once the phone is paired, as root, edit /etc/bluetooth/rfcomm.conf and add the following text:
rfcomm0 {
bind yes;
device 11:22:33:44:55:66
channel 1;
}
again, using your own device's Bluetooth ID instead of 11:22:33:44:55:66. Restart the bluetooth service using
/etc/init.d/bluetooth restart
and then we need to configure Ser2Net.

WARNING: Ser2Net, by default, exposes a serial port as a general access telnet service with no restriction on who can access it. This does have a security implication in that once started, if your instance of the smsToLaconica scripts aren't using the port, then potentially any user of that system could connect to your mobile phone and dial out. This is solved by doing two things - 1) make sure your smsToLaconica script is always running and 2) allow ser2net only to bond to the localhost adaptor, not your ethernet adaptor by prefixing the port number with the IP address as detailed below. This still leaves this service open to local exploit, but ultimately your local users may have had access to the serial ports already.

Install ser2net (which is available in most Linux distributions) and edit the config file (again as root) in /etc/ser2net.conf, deleting the existing lines (unless you're likely to want to share your COM1: for anything else) and add the following line:
127.0.0.1,2000:telnet:600:/dev/rfcomm0:9600 8DATABITS NONE 1STOPBIT
Save this file, then restart the ser2net service with
/etc/init.d/ser2net restart
then telnet to localhost 2000. Confirm it works by sending the AT command to it - you should see a response of "OK", although you may also get a response of
AT

OK
Now you can set up the scripts for your own local copy of smsToLaconica. To make smsToLaconica work, you'll need php with php-curl and php-mysql, which are usually available from your repositories. You'll also need a MySQL server which stores the account details of your users and the messages before processing.

Check out a copy of the Subversion Repository (or just pull the files from the server) and put them in a NON-WEB-DIRECTORY. This is very important! Almost all of these files are not web pages, with the exceptions being ui.php and admin.php. If the only user on this SMS gateway is you, you don't even need to put those into a web directory (see the notes below). Edit the config.php file with appropriate settings and import the SQL table structure to the database configured in config.php, then finally call the run_scripts.sh (which just calls the read_sms.php and process_db.php scripts into the background).

If you put the ui.php and admin.php files into your web host, you will also need a copy of the config.php file. ui.php is where users configure their laconi.ca instance, username and password, and get told the mobile number to send an authorization code to. This is also the same page where they can remove their details from the gateway. The admin page shows how many users are on which Laconi.ca instances and any unhandled messages.

There is currently no index page for the web instance, and no user authentication, so you should probably configure .htaccess files for the admin page, if not remove it completely, or use it to send e-mails to the admin using crontab.

To set up the system without the web interface, you should insert a row into the database table called users, with the following columns completed: base_url, username, password and code. The code column should be something to send to the SMS gateway to associate your number with the service.

If you get stuck with any of this lot, please leave a comment, send me an e-mail or follow me on identi.ca

Labels: , , , ,


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]