Thursday, October 27, 2011

Going to FUDCon Pune

Just got my visa. See you all there!

Clearing Evolution IMAP local mail cache

Quite straightforward:

rm -rf ~/.local/share/evolution/mail/{imapx,imap}/*

Friday, October 14, 2011

Dennis Ritchie (1941-2011)

A titan of which all tech giants and all of us stands on

Friday, October 07, 2011

Opps ..

Opps , to Fedora Planet, sorry that some old posts appeared in frontpage .. I changed my feed to aggregate the PlanetFedora tag instead of Fedora, and tagged a number of old contents ..

but seems like PlanetPlanet sorted items by updated date rather than published date ..

Tuesday, October 04, 2011

A simple demo application using collective.trajectory

Last week I wrote about a Plone library called collective.trajectory which allows you to do url routing on Plone content type. Back then it was only able to route the context, but I have yet to try develop something on it yet.

A few days ago on, I gave a talk on it, so naturally, I'll need to test to develop something on it first before doing the talk. Using trajectory, I hacked together a simple app, which fetch a profile page from Facebook, to demonstrate the library capabilities. Here's the howto.


Create a content type which can be added on any part of site, where if user load a subpath of the content, it will load a profile info from, and serve it as a context in Plone.

Creating an archetype project

First you'll need ZopeSkel in your buildout. Add this section into buildout.cfg:

recipe = zc.recipe.egg
eggs = 

Execute ./bin/buildout install paster afterwards. Once thats done, you should have paster command in your bin directory.

Create an archetype product using ZopeSkel.

./bin/paster create -t archetype 
Selected and implied templates:
  ZopeSkel#basic_namespace  A basic Python project with a namespace package
  ZopeSkel#plone            A project for Plone products
  ZopeSkel#archetype        A Plone project that uses Archetypes content types
Enter project name: example.trajectory

That should create a directory called example.trajectory in the current directory. Now, lets create a simple archetype content.

cd example.trajectory
../bin/paster addcontent contenttype
Enter contenttype_name (Content type name ) ['Example Type']: FacebookProfiles
Enter contenttype_description (Content type description ) ['Description of the Example Type']: An 
application which fetch facebook profile from
Enter folderish (True/False: Content type is Folderish ) [False]: 

Notice that Folderish is False. We doesn't need the content to be folderish here.

Hooking the archetype product to Plone

After creating the archetype product above, we'll need to hook it in Plone.

In your buildout.cfg, add these:

eggs = 

zcml =

develop = 

Run ./bin/buildout and at this point, you should have the base we need for this demo app. If you start the Plone server you should see the product installable, and you can add the content after installing the product. Now for the fun stuff.

Registering trajectory traverser to contenttype

Edit example.trajectory/example/trajectory/configure.zcml , and add this:

<adapter factory="collective.trajectory.components.Traverser"

Registering routes and factories

Edit example.trajectory/example/trajectory/content/, and you can register the routes directly there.

import traject
from collective.trajectory import getApp, Model
from zope.globalrequest import getRequest
import json, urllib
class FacebookProfiles(base.ATCTContent):

class Profile(Model):
    def __init__(self, id, data): = id = data

def factory(profile_id):
    data = urllib.urlopen('' % profile_id).read()
    data = json.loads(data)
    return Profile(profile_id, data)

def arguments(obj):
    return {

traject.register(FacebookProfiles, 'profile/:profile_id', factory)
traject.register_inverse(FacebookProfiles, Profile,
                    'profile/:profile_id', arguments)

Done, now when you access http://site/path/to/facebookprofilesapp/profile/somefacebookid, you should get a Profile object.

Now we need to register a simple view for the profile

Registering a default view

Create example.trajectory/example/trajectory/browser/ and fill it with this:

from Products.Five import BrowserView

class ProfileView(BrowserView):

Edit example.trajectory/example/trajectory/browser/configure.zcml and add this:


Create example.trajectory/example/trajectory/browser/ and fill it with this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns=""
  <div metal:fill-slot="content">
      <h1 tal:content="context/data/username"/>
         <dd tal:content="context/data/name"></dd>
         <dt>Facebook Page</dt>
         <dd><a href="#" tal:attributes="href context/data/link" tal:content="here/data/link"></a></dd>

Thats it, if you add the FacebookProfiles content into your plone site, take for example http://site/myfolder/fbprofiles , when you load http://site/myfolder/fbprofiles/profile/yourfacebookid you should get a page with user 'yourfacebookid' details

I've uploaded the example.trajectory demo into so that you can try it and refer to it.

Happy hacking!

Monday, October 03, 2011

Email server with Postfix, Dovecot, and LDAP

I think I'll skip the introduction as this is mainly a note for myself

The LDAP Setup

I'm not going to cover how to setup LDAP. The setup that I'm using for this system is organized where all users are under an Organizational Unit called 'people' (ou=people,dc=organization,dc=org) with this schema:

dn: uid=user,ou=people,dc=organization,dc=org
objectClass: posixAccount
objectClass: inetOrgPerson
uid: user
homeDirectory: /home/user
userPassword: <passwordhash>

Configuring Dovecot

Add these into dovecot.conf

mail_uid = 5000
mail_gid = 5000

auth default {
  mechanisms = plain
  passdb ldap {
          args = /etc/dovecot-ldap.pass
  userdb ldap {
          args = /etc/dovecot-ldap.user

  # for postfix to authenticate against
  socket listen {
        client {
          # Assuming the default Postfix $queue_directory setting
          path = /var/spool/postfix/private/auth
          mode = 0660
          # Assuming the default Postfix user and group
          user = postfix
          group = postfix


hosts = host.of.ldap.server:389
sasl_bind = no
auth_bind = yes
ldap_version = 3
deref = never
base = uid=%n,ou=people,dc=organization,dc=org
scope = base
dn = uid=manager,dc=organization,dc=org
dnpass = password


hosts = host.of.ldap.server:389
sasl_bind = no
auth_bind = yes
ldap_version = 3
deref = never
base = uid=%n,ou=people,dc=organization,dc=org
scope = base
user_attrs = homeDirectory=home
dn = uid=manager,dc=organization,dc=org
dnpass = password

Configuring Postfix

Add these into your

accounts_server_host = host.of.ldap.server
accounts_search_base = ou=people,dc=organization,dc=org
accounts_query_filter = (&(objectClass=inetOrgPerson)(mail=%s))
accounts_result_attribute = homeDirectory
accounts_result_format  =  %s/Mailbox
accounts_scope = sub
accounts_cache = yes
accounts_bind = yes
accounts_bind_dn = uid=manager,dc=organization,dc=org
accounts_bind_pw = password
accounts_version = 3

virtual_transport = virtual
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_mailbox_base = /
virtual_mailbox_maps = ldap:accounts
virtual_mailbox_domains =

smtpd_sasl_type = dovecot
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = no
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_path = private/auth

Make sure domains under virtual_mailbox_domains is not listed under mydestinations.

Thats it I think, not sure if I missed anyting.

Radiate: A simple push server for SocketIO (alpha)

Based on my previous post on WebSocket server using Tornado, I've hacked the code more to be a SocketIO server instead of just WebSocket, so that it can be used on many browsers until everyone support WebSocket. The SocketIO connection is handled by TornadIO, a neat SocketIO library for Tornado.

I've uploaded the code here in github:

I've packaged Radiate together with a buildout.cfg, so you can deploy it easily by just using these few lines of commands
git clone radiate
cd radiate
To start the daemon, just execute:
./bin/radiate-admin fg
The readme file on how to deploy and use Radiate is here:

Sunday, October 02, 2011

Simple websocket push service using Tornado

WebSocket server side documentation/guides around tend to be very node.js oriented. However, I don't fancy rewriting stuff I already have simply to be able to make use of WebSocket. After some research, I figured out a mechanism for a service which will handle push for WebSocket, in a simpler manner which are familiar to everyone - simple POST/GET!

Example server code: (on Tornado 11.0)

import tornado.ioloop
import tornado.web
from tornado import websocket

    'sockets': []

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

class ClientSocket(websocket.WebSocketHandler):
    def open(self):
        print "WebSocket opened"

    def on_close(self):
        print "WebSocket closed"

class Announcer(tornado.web.RequestHandler):
    def get(self, *args, **kwargs):
        data = self.get_argument('data')
        for socket in GLOBALS['sockets']:

application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/socket", ClientSocket),
    (r"/push", Announcer),

if __name__ == "__main__":

Example Client Javascript (jQuery)

$(document).ready(function () {
    var ws = new WebSocket("ws://localhost:8888/socket");
    ws.onmessage = function(event) {
       $('body').append('<div>' + + '</div>');
    $('body').append('<div> Start! </div>');

How to try

Start the Tornado server, load http://localhost:8888/push?data=somedatahere. This will send 'somedatahere' to the websockets and notify them all with the string.

Probably this can evolve to a nicer service system. But I'll hack on it more later
Locations of visitors to this page