Simple Socket-over-HTTP bridge

Have you ever been behind a restricted firewall that only allows HTTP/HTTPS requests, but blocks you from checking Mail via IMAP or sending Mail via SMTP?

If so, this Socket-over-HTTP Bridge can save you the day. However, you need access to an Apache/WSGI enabled server that can act as the other side of the bridge.

→

Instead of Facebook...

Normalerweise, als ich noch Facebook hatte, hätte ich heute wohl einen Post gemacht. Stattdessen nutz ich diesmal den Blog :)

Ich sitz im Zug, auf dem Weg nach Wien zum Flughafen. Über Dubai geht's auf nach Sydney!

Kann sein, dass ich den einen oder anderen Blog-Post von Australien aus machen werde…vielleicht sogar mit Photos :)

2013/02/01 00:00 · Andreas Böhler

Authenticate ownCloud against postfixAdmin database

We recently set up an ownCloud hosted site as well as a mailserver based on postfixAdmin. In order to authenticate ownCloud to postfixAdmin, one can use either user_imap oder user_pwauth. Both methods work, but with the drawback that a user list cannot be retrieved.

In order to overcome this limit, I developed a simple app for ownCloud to authenticate against an arbitrary mySQL database. Currently, only the crypt() password method is supported, but database, table and column details can be configured in the admin backend.

You can find the details (and the code!) in my mercurial repository at

2012/11/27 00:00 · Andreas Böhler

Recovering contacts from dead Android phone

A friend of mine recently dropped her Android phone on the floor and the screen cranked - only the backlight would come on, but nothing was displayed. As she didn't sync her contacts, she asked me how to get her contacts back. Here is what I did:

I remembered that I once installed ClockWorkMod recovery alongside with CyanogenMod on the device. Unfortunately, I left USB debugging disabled in Android, as I had hoped to be able to pull the database files via ADB on plugging the phone in. Luckily, CWM comes with ADB debugging enabled, so I booted straight into CWM (on the ZTE Blade by holding down the Vol- button while powering the phone on), attached the phone to the computer and logged in. First step: Mount the data partition with

andy@x200t:~$ adb shell
android:~$ mount /data
android:~$ exit

Then, pull the contacts file:

andy@x200t:~$ adb pull /data/data/

This is actually a SQLite database containing all the contact's information. A short research on the internet revealed nothing of interest, so I had to dig myself into the format of the file. I came up with a simple Python converter script, that converts most of the information into a VCard file. Phone numbers are all trated as cell numbers and E-Mail addresses are all treated as home mail addresses. I put question marks on the fields where I suspect lies the relevant information to distinguish the type of phone number, but the information was not consistent in the file. Run the script with the .db file as first parameter and a non-existing .vcf file as second parameter. If the file exists, it will be overwritten without notice. To my big surprise, the resulting .vcf file was accepted by Google Contacts on the first try…

Of course you can also extract the contacts2.db file from e.g. a recent Nandroid backup.

Here is the (ugly, but working) code:

#!/usr/bin/env python2

import sqlite3
import sys
import codecs

class Contact:
    def __init__(self, id): = id
        self.phoneNumbers = []
        self.mailAddresses = []
        self.lastname = ""
        self.firstname = ""
        self.hasPhone = False

    def GetPhones(self):
        return self.phoneNumbers

    def AddPhone(self, number):

    def AddMail(self, mail):

    def GetMails(self):
        return self.mailAddresses

    def SetFirstname(self, firstname):
        self.firstname = firstname

    def SetLastname(self, lastname):
        self.lastname = lastname

    def GetName(self):
        return (self.lastname, self.firstname)

    def GetId(self):

    def GetVCard(self):
        vcard = []
        vcard.append("N:" + self.lastname + ";" + self.firstname)
        if len(self.lastname) > 0 and len(self.firstname) > 0:
            vcard.append("FN:" + self.firstname + " " + self.lastname)
        elif len(self.lastname) > 0:
            vcard.append("FN:" + self.lastname)
        elif len(self.firstname) > 0:
            vcard.append("FN:" + self.firstname)
        for phone in self.phoneNumbers:
            vcard.append("TEL;type=CELL:" + phone)
        for mail in self.mailAddresses:
            vcard.append("EMAIL;type=INTERNET;type=HOME:" + mail)
        return vcard

if len(sys.argv) < 3:
    sys.exit("Must give filenames as arguments")

fn = sys.argv[1]
db = sqlite3.Connection(fn)
contacts = {}
c = db.cursor()
c.execute("SELECT COUNT(*) FROM contacts")

num_entries = c.fetchone()[0]

print "Getting " + str(num_entries) + " contacts..."

c.execute("SELECT name_raw_contact_id, has_phone_number FROM contacts")

while True:
    row = c.fetchone()
    if row is None: break
    if not contacts.has_key(row[0]):
        contacts[row[0]] = Contact(row[0])
        contacts[row[0]].hasPhone = row[1]

for key in contacts.keys():
    c.execute("SELECT mimetype_id, data_version, data1, data2, data3 FROM data WHERE raw_contact_id = " + str(contacts[key].GetId()))
    while True:
        row = c.fetchone()
        if row is None: break
        if row[0] == 1: # Mail
        elif row[0] == 6: # Name
            if row[4]:
            if row[3]:
        elif row[0] == 5: # Phone
            if row[3] == 2: # Mobile?
            elif row[3] == 1: # Home?

fp =[2], "w", "utf-8")
print "Contact's Details: "
for key in contacts.keys():
    if contacts[key].GetId() != 0:
        string = ""
        last, first = contacts[key].GetName()
        if len(last) > 0 and len(first) > 0:
            string += last + " " + first
        elif len(last) > 0:
            string += last
        elif len(first) > 0:
            string += first
        phones = contacts[key].GetPhones()
        for phone in phones:
            string += phone + " "
        mails = contacts[key].GetMails()
        for mail in mails:
            string += mail + " "
        print string


Extracting lecture slides from Video

Sometimes, I get lecture videos online, but no slides in PDF or whatever other format, or I could buy the slides for a few euros.

Luckily, being a computer enthusiast, I looked for a quick, easy way to extract the slides from the videos, without too much hassle. My first try was to rely on the video encoder to correctly use keyframes, but it turned out that I ended up with 1000 images for 15 slides. Dooh.

Next try: postprocessing the slides and removing duplicate ones. I came up with a very simple python script, that now runs ffmpeg to extract the keyframes and then does a simple histogram comparison of the images. Now i went down to about 30 images for 15 slides - not bad, most of the dupliate ones were recorded mouse movements or slide transitions. I can live with that.

Here is the script (the histogram part is stolen from

#!/usr/bin/env python2

import math, operator
from PIL import Image
import sys
import os
import glob
import subprocess
import shutil

def compare(file1, file2):
    image1 =
    image2 =
    h1 = image1.histogram()
    h2 = image2.histogram()
    rms = math.sqrt(reduce(operator.add,
                           map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
    return rms

if __name__=='__main__':
    if len(sys.argv) < 3:
        sys.exit("Need video file and output dir as parameter")
    if not os.path.exists("decomp"):
        sys.exit("decomp already exists, exit")
    if not os.path.exists(sys.argv[2]):

    cmd = ["ffmpeg", "-i", sys.argv[1], "-vf", "select='eq(pict_type,I)'", "-vsync", "0", "-f", "image2", "decomp/%09d.png"]

    print "Running ffmpeg: " + " ".join(cmd)

    print "Done, now eliminating duplicate images and moving unique ones to output folder..."

    filelist = glob.glob(os.path.join("decomp", '*.png'))
    for ii in range(0, len(filelist)):
        if ii < len(filelist)-1:
            if compare(filelist[ii], filelist[ii+1]) == 0:
                print 'Found similar images: ' + filelist[ii] + " and " + filelist[ii+1]
                print 'Found unique image: ' + filelist[ii]
                head, tail = os.path.split(filelist[ii])
                shutil.copyfile(filelist[ii], sys.argv[2] + os.path.sep + tail)
            shutil.copyfile(filelist[ii], sys.argv[2] + os.path.sep + tail)
2012/08/01 00:00 · Andreas Böhler
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information