1. August 21, 2012

      OCR a scanned PDF with Tesseract

      Simple really: I wanted to OCR a scanned PDF, then embed the output text back into the PDF so that I can search. Surprisingly, an application for this doesn’t already exist, so here’s my script:

      [bash]
      #!/bin/sh

      cp $1 $1.bak

      pages=$(pdftk $1 dump_data output | grep NumberOfPages | sed -E ‘s/(.*): (\d*)/\2/g’)

      for i in `seq 1 $pages`;
      do
      convert -monochrome -density 600 $1\[$(($i - 1 ))\] page$i.tif
      tesseract page$i.tif output -l eng
      pdftk $1 attach_files output.txt to_page $i output $1.new
      mv $1.new $1
      rm output.txt
      done
      [/bash]

    2. October 10, 2011

      Aladdin eToken on Ubuntu 11.10 (oneiric ocelot) amd64

      Update: In my mad rush to get everything working, I completely missed that 8.1 was released, which adds native 64-bitness. Apart from linking /usr/lib64/libeToken.so to /usr/lib/libeToken.so.8, there are no hacks required anymore! Yay!

      I’ve just installed the oneiric release candidate. And I like the changes. And I like that with a little tweaking, my eToken still works!

      I did a bare-metal install, as I’ve now upgraded to SSD. So, I’ve updated my tutorial to match.

      1. Install 11.10 amd64. Now, even though SAC amd64 is supposed to be amd64, they lied, and it ships with i386 binaries that just happen to work on amd64. So you’ll need to prep your x86_64 system with i386 goodness, by using: [code]sudo apt-get install ia32-libs libhal1 opensc pcscd[/code]

        • Note that I said libhal1, in DIRECT CONTRADICTION to SafeNet’s user guide. if you don’t, you’ll see things pop up in /var/log/syslog like [code]pcscd: dyn_unix.c:37:DYN_LoadLibrary() /usr/lib/pcsc/drivers/aks-ifdh.bundle/Contents/Linux/libAksIfdh.so: libhal.so.1: cannot open shared object file: No such file or directory[/code]
      2. You’ll need the 32-bit libpcsclite1 and libhal1. Simply run:
        [code]
        wget http://archive.ubuntu.com/ubuntu/pool/main/p/pcsc-lite/libpcsclite1_1.7.2-2ubuntu2_i386.deb
        wget http://archive.ubuntu.com/ubuntu/pool/main/h/hal/libhal1_0.5.14-0ubuntu6_i386.deb
        dpkg -x libpcsclite1_1.7.2-2ubuntu2_i386.deb libpcsclite1-i386
        dpkg -x libhal1_0.5.14-0ubuntu6_i386.deb libhal1-i386
        sudo cp libpcsclite1-i386/lib/libpcsclite.so.1.0.0 /lib32
        sudo cp libhal1-i386/usr/lib/libhal.so.1.0.0 /usr/lib32
        sudo ln -s /usr/lib32/libhal.so.1.0.0 /usr/lib32/libhal.so.1
        sudo ln -s /lib32/libpcsclite.so.1.0.0 /lib32/libpcsclite.so.1
        [/code]
      3. Download the SafeNet Authentication Client for Linux 8.0. In theory you should have a support agreement with SafeNet to download this, but you CAN find it on Google, including from SafeNet themselves (hint: try SAC instead of the full spelling). Install it with [code]dpkg -i SafenetAuthenticationClient-8.0.5-0_amd64.deb[/code]

      Note: if you’ve got this working before, you’ll notice that in 11.10 they’ve moved from /usr/lib being a link of /usr/lib64 to being it’s own directory; the result being the new location of /usr/lib64/libeTPkcs11.so for your PKCS11 applications.

      So there you go. If you add the /usr/lib64/libeTPkcs11.so to Firefox and Thunderbird, you should see your certificates. If you run PKIMonitor, you should be able to modify your eToken.

      For a quick verification, run [code]pkcs11-tool --module /usr/lib64/libeTPkcs11.so -L[/code], and you should see your eToken.

    3. July 8, 2011

      Aladdin eToken on Ubuntu 11.04 (natty narwhal) amd64

      Update: this has been updated for 11.10, check it out here.

      This is more complicated than it should be, for no real reason. I like my eToken, and have been trying for a good year to get it working on 64-bit Linux. Today, I sat down, started from scratch, and nutted it out. The following 3-step procedure should be all that’s needed to get it working.

      1. Install 11.04 amd64. Now, even though SAC amd64 is supposed to be amd64, they lied, and it ships with i386 binaries that just happen to work on amd64. So you’ll need to prep your x86_64 system with i386 goodness, by using: [code]sudo apt-get install ia32-libs libhal1 opensc pcscd[/code]

        • Note that I said libhal1, in DIRECT CONTRADICTION to SafeNet’s user guide. if you don’t, you’ll see things pop up in /var/log/syslog like [code]pcscd: dyn_unix.c:37:DYN_LoadLibrary() /usr/lib/pcsc/drivers/aks-ifdh.bundle/Contents/Linux/libAksIfdh.so: libhal.so.1: cannot open shared object file: No such file or directory[/code]
      2. Download the SafeNet Authentication Client for Linux 8.0. In theory you should have a support agreement with SafeNet to download this, but you CAN find it on Google, including from SafeNet themselves (hint: try SAC instead of the full spelling). Install it with [code]dpkg -i SafenetAuthenticationClient-8.0.5-0_amd64.deb[/code]
      3. Finally, you’ll need the 32-bit libpcsclite1. Simply run:
        [code]
        wget http://archive.ubuntu.com/ubuntu/pool/main/p/pcsc-lite/libpcsclite1_1.7.2-2ubuntu2_i386.deb
        dpkg -x libpcsclite1_1.7.2-2ubuntu2_i386.deb libpcsclite1-i386
        sudo cp libpcsclite1-i386/lib/* /lib32
        [/code]

      So there you go. If you add the /usr/lib/libeTPkcs11.so to Firefox and Thunderbird, you should see your certificates. If you run PKIMonitor, you should be able to modify your eToken.

      For a quick verification, run [code]pkcs11-tool --module /usr/lib/libeTPkcs11.so -L[/code], and you should see your eToken.

      Also, good-bye Windows XP. This was the last thing preventing me from using Ubuntu on a daily basis, and now you’ve been completely replaced.

    4. June 21, 2011

      KVM virtual console to physical TTY

      This took me longer than it should’ve to figure out… I wanted to take the virtual console (pts) from a KVM virtual machine, and map it to a physical tty, so that I could login to my virtual machine from the physical keyboard, without having to login to the virtual host itself. This can be done with a simple one-liner:

      screen /dev/pts/1 > /dev/tty9 < /dev/tty9 &

      Add that to /etc/rc.d/rc.local to start on system startup (hopefully after the VM has started), and I'm all set!

    5. August 23, 2010

      pfSense IPv6 HowTo (PPTP with Thomson ST536v6 in NZ)

      I’ve just spent a few hours getting this going, and so I thought I’d write up a quick howto.

      1. Install VirtualBox. Windows Virtual PC doesn’t support starting machines as services, and I never really liked VMWare Server due to it’s high overhead.
      2. Created a virtual machine and install pfSense 1.2.3. Accept VirtualBox’s default FreeBSD settings, except create 2 network cards (pfSense won’t work without at least 2), both bridged to the physical network interface. Remember that the modem will run on a different IP address range (10.0.0.138), and so while using VLANs and actually separating the networks is an option, having everything on the same network won’t do anything bad.
      3. Now that pfSense is running, setup the Thomson ST536v6 to act as a PPTP server. This is so that pfSense will get the real, public internet connection with real-world IP address. Much nicer than having to use NAT or DMZ, and the Thomson does a nice job of this. Telnet into the modem (remember the default username is Administrator and password is blank) and run the following commands (which WILL destroy your current config). Note: this forum post is mostly correct, but I kept getting an “Invalid phonebook destination name, phonebook is in use.” error when trying to flush the ATM interface without first detaching it.
        [text]:system reset
        :ppp relay flush
        :eth flush
        :atm ifdetach intf=atm_0_100
        :atm flush
        :ppp flush
        :atm phonebook flush
        :saveall
        :atm phonebook add name=BrPPPoE_ph addr=0.100
        :service system modify name=PPTP state=enabled
        :saveall
        :system reboot[/text]
      4. After power cycling the modem, time to configure pfSense. Bind LAN to em0 and WAN to em1 (or vice-versa, doesn’t matter). pfSense will take forever bringing up the WAN interface, because it’s expecting a DHCP lease which isn’t available. The LAN interface will start acting as a DHCP server, which is good, given you’ve just told your modem to stop doing that.
      5. Login to the pfSense web UI. Under Interfaces, select WAN. Change the Type to PPTP. The Username and Password won’t have any effect for Telecom ADSL connections (user@xtrabb.co.nz and telecom work fine), but for UBS or LLU connections you’ll need to use something specific. Set the Local IP address to 10.0.0.139/24 and the Remote IP address to 10.0.0.138 (which the modem should be listening on, as well as 192.168.1.254).
      6. Not quite sure what causes the PPTP connection to stand up (I think I just waited and it came up automatically), but at this point you could probably power cycle the virtual pfSense and it should all liven up. If you’ve done it right, you should have an internet connection on your clients (you may need to refresh the DHCP lease). Step one complete!
      7. Now for tunnelled IPv6, to go http://tunnelbroker.net and sign up for a tunnel. Don’t forget to tick the IPv6 enable box (under Advanced in pfSense’s System menu)
      8. There’s a great shell script here which takes care of creating the tunnel on pfSense. You’ll need to run this on each restart, but each time you restart your public IP address is likely to change anyway. I may get bored and update the script to handle this automatically at some point…
      9. Anyway, if you can get to http://ipv6.google.com, step two complete!
    6. July 2, 2010

      jQuery qtip & fullcalendar

      Was having a really strange problem today; getting qtip (1.0.0-rc3) and fullcalendar (1.4.5) to play nice. No matter what, it was erroring on line 139:

      [js]$(this).data(‘qtip’).current = $(this).data(‘qtip’).interfaces.length[/js]

      Thankfully the intertubes had a very helpful post; changing line 134:

      [js]if(typeof $(this).data(‘qtip’) == ‘object’)[/js]

      to:

      [js]if(typeof $(this).data(‘qtip’) == ‘object’ && $(this).data(‘qtip’) !== null)[/js]

      made it all happy. Good coding practice FTW…

    7. June 7, 2010

      Signs of life

      Ya, it’s been a while since adding content to this site, I know. It’s on the todo list.

      While helping my lovely wife and my grandfather-in-law get their blogs online, I realised I’ve mostly neglected mine. It’s not because I don’t love you, sweet internets, but because I’ve found that the free time I once had for ranting online has almost vanished. It’s honours project time, my final year of uni, my victory lap. Although I don’t have exams, it feels like I’m being tested every day. It feels like it’s no longer fun whimsical nonsense, at uni and at work. And as much as I thought it never would, I want it to be over quickly.

      I gave up writing for Nexus; not because I didn’t enjoy it, but because I felt my writing was getting to the stage of interestingness. Throughout all the articles of The Nerdery, you’ll notice a certain “shit, gotta get this done before Monday” feel to them. They were forced. And then, something happened at the start of the year; I felt like I had something to say. I felt like I had to educate the masses. Unfortunately, this came at a time where the new editor felt that Nexus had evolved too much over Josh’s tenure, and decided to take it back a notch. I felt like I no longer belonged.

      It’s the sort of feeling I’m starting to find from places where I thought I had permanent membership.

      Anywho, that’s enough emo for one night.

    8. November 26, 2009

      A simple Twisted PubSub Server

      I’ve been looking all day for this, and almost gave up and went back to Java. If you’re like me and want a simple PubSub server for Twisted, go here.

      Why did this take all day to find? Why can’t common things like this be explained in the Twisted documentation, the book, or even linked as example code? Something has to really frustrate me to make me want to use Java…

    9. October 13, 2009

      Safari Crashes, PubSubAgent has issues, everything dies, oh my!

      Ever had one of those days, where everything just seems to be going wrong? Over the last 6 hours, I’ve been trying to debug why Safari, Mail.app, iTunes and Adium crash without ANY explanation, after any of said applications tried to load a webpage.

      It started randomly (haven’t made major changes in the last few days), so I assumed it was something corrupted. The only hint was that after Safari, Mail, iTunes or Adium crashed, PubSubAgent would use 100% CPU time. So, I fire up Instruments and look at the trace for PubSubAgent. It seems to be calling CFHTTPCookieStorageFlushCookieStores many times, which is odd, because a quick Google doesn’t return anything useful about this system call, obviously related to CFHTTP.

      Fast forward 4 hours later when I’ve cleared caches, nuked my Safari config, tried removing PubSubAgent (which just made it worse). The fix? Removing ~/Library/Cookies/Cookies.plist. Oddly enough, it has a companion – ~/Library/Cookies/Cookies.plist – corrupt.

      So, just a recap; somewhere the system knew my Cookies file was corrupted. But instead of spitting this out to the Console, throwing a Dialog, or ANY form of useful information, I had to trudge through my Library looking for something which could be causing the problem, and manually removing it. It was by chance that I noticed the Cookies folder, which is strangely not in the Safari folder where one would normally expect it.

      And just to make matters worse; Safari’s “Reset Safari” did nothing to solve the problem. That’s right, checking the “Remove all cookies” checkbox did NOT remove the cookies!

      Good user interaction FTW!

    10. September 19, 2009

      Snow Leopard: Outdated-software-R-us!

      I apologize in advance for the lack of coherency in this post; it’s late, and I’m tired.

      So, I have a custom backup script (mostly because I know I can do it better for my workflow than some off the shelf solution). It uses tar’s listed-incremental function to do, as you can guess, incremental backups over a monthly cycle. It’s been working well since I made it on Tiger, except today, the first time I’ve tried to take a backup since upgrading to Snow Leopard. It straight off failed, claiming it doesn’t understand listed-incrementals.

      I’m scratching my head as to why (it’s really not a complex script), before I realise it’s using an older version of tar than what shipped with Tiger and Leopard (or it’s using BSD tar as opposed to GNU tar… but I can’t verify what Tiger/Leopard had, all I know is it worked previously). Hmmm… ok. So I open Macports, install the latest version of gnutar, removed the crappy Snow Leopard tar and all keps going happily… except I now have a wiggling suspicion in the back of my mind that there is another disturbance in the force…

      I dig a little, and it’s not long before I discover that Apple also decided to ship bzip2 1.0.4, which has a security exploit that was fixed 1 year 6 months before 10.6 was released…

      WTF Apple? Is anyone paying attention to software releases over there? It makes me wonder, what other outdated, exploitable software is installed on my laptop?