Automator + XKpasswdA few weeks ago on the Chit Chat Across the Pond segment of the Nosillacast, I mentioned that I had an OS X service set up to generate a random password using my XKpasswd Perl module and copy it to the clipboard. Listeners enquired as to how they would go about doing that, so as promised, here’s a quick tutorial.

Obviously this tutorial is for Mac OS X users only, because OS-wide Services and Automator are OS X features. The screenshots are taken on 10.8 Mountain Lion, but this same technique definitely also works on OSX 10.7 Lion, and probably even on 10.6 Snow Leopard. This tutorial also assumes that you have downloaded the XKpasswd module, and saved it somewhere on your computer, along with either the sample dictionary file included with the module or one of your own making, and that you know where on your computer those files have been saved. In other words, you need to have XKpasswd.pm and a text file with one word per line somewhere on your hard drive. In my sample code I’m going to assume you’ve installed the Perl module to the suggested location, /usr/local/xkpasswd/XKpasswd.pm, and that you have customised the sample dictionary a little (more secure that way), and saved it to /usr/local/xkpasswd/dict.txt.


Read more

Tagged with:

I spent the weekend majorly re-factoring XKpasswd.pm, my Perl random password generation library. V0.1 was the last thing I wrote before reading Perl Best Practices, and looking back on that code really illustrated the value of that book when used in combination with the perlcritic code analyser.

The new version of the module provides all the functionality the old one did, and more. The refactoring has made the module simpler to use from within scripts, as well as easier to modify and extend. Some new features have also been added, including the ability to use the www.random.org web service as the source of randomness for the library. A full list of bug fixes and new features is included below.

I had hoped to distribute this version as both a ZIP file and a .PKG file, but XCode 4.4 is not being cooperative on the new Mountain Lion, so that will probably have to wait until version 0.3.

Update – 6 August 2012: The link below has been updated to point to version 0.2.1 of the code. Details of the bugs fixed in the release notes.

Download

Read more

Tagged with:

I ran into a problem this week when the perl libraries for accessing MySQL databases refused to work on Mac OS X Lion. I did a ‘regular’ install:

  1. Install the 64bit version of MySQL Community Server (being sure to use the .dmg version so as to get the .pkg installer)
  2. use CPAN to install the needed database libraries:
    1. $ perl -MCPAN -e shell
    2. cpan[1]> install Bundle::DBI
    3. cpan[1]> install DBD::mysql

There were no errors during the install, so I assumed all we well, until I tried to actually use the libraries to access a database that is! Using DBI to try connect to a MySQL database gave the following error:

install_driver(mysql) failed: Can't load '/Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
  Reason: image not found at /System/Library/Perl/5.12/darwin-thread-multi-2level/DynaLoader.pm line 204.

After a lot of googling I found plenty of people with the same problems, including people on Snow Leopard, so I figured this was not a new problem. I tried a number of the suggested solutions, and most did not work, but after two days of trying, I found one that did, and it was wonderfully simple!

The problem is that the MySQL libraries are not in the OS’s library path, so they are not being found, most of the proposed solutions tried to tackle the problem at compile time, or to use simlinks to hack the libraries into the path, but like I say, these solutions didn’t work for me. What did work is simply updating the library path in my environment!

If you run the command below before executing your Perl script the library is found and all is well!

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

It’s a little awkward to do this all the time, so I added the line to my ~/.bash_profile file, and now it just works for me!

I spent two frustrating days trying to fix this, so hopefully I’ll save others some time by sharing my solution.

Tagged with:

xkpasswd - a secure memorable password generator

Steve Gibson really set the cat among the pigeons with his Password Haystacks site a few months ago, and XKCD’s ‘Correct Horse Battery Staple’ web comic brought that message home to many many nerds and geeks. The basic idea is that you’re better off making your passwords long and memorable than short and complex. In the simplified XKCD example the password is simply made up of 4 common words, but Steve Gibson suggests you should add some padding around those words to make the passwords much harder to guess.

This is a lovely theory, but I’m not imaginative, and I need to invent a lot of passwords every week, so I wrote a Perl module to do it for me, and called it xkpasswd.pm. The first thing I’m announcing today is that I’ve made this library available for free for both personal and commercial use (under the FreeBSD license), you can download it from www.bartb.ie/xkpasswd.

Download

It’s great to have a library for nerds to play with, but what about everyone else? Well, that’s where my second announcement comes in, I’ve also created www.xkpasswd.net, a simple web front-end to the xkpasswd.pm module.

www.xkpasswd.net

In case anyone is wondering where the name comes from? It’s a mashing together of XKCD, and passwd, the Linux/Unix command for changing passwords. Because I used to use Solaris, and hence the yppasswd command, I liked the idea of keeping the prefix to just two letters, hence xkpasswd, rather than xkcdpasswd.

For any programmers interested in using the Perl module, it has no prerequisites other than base Perl, and all you need to get started is the module and a dictionary file to point it at. The download package contains the module, a sample dictionary, and a sample Perl script which invokes the module.

In the future I also plan to release a JavaScript-only version if the library so that others can embed xkpasswd-based password generators in their own sites without needing Perl CGI support on their servers. I’m also experimenting with creating an OS X Service to allow people to easily generate xkpasswd passwords from anywhere within OS X, and perhaps even a native OS X Application. So stay tuned!

XKCD - Password Strength

Tagged with:

Following on from my post yesterday with three examples of using Automator to create Services, and some good suggestions in the comments, I spent some time this afternoon making the script in the third of those examples a little more efficient, and a lot more robust.

The Service I optimised was the one to strip keywords from image files. This Service assumes that both Growl and EXIFTool are installed, and that you’re running OS X 10.6 Snow Leopard or later.

Read more

Tagged with:

Automator IconSome Apple haters just love to say that there is nothing to a Mac except for flashy marketing. There are a million different reasons that’s BS, but one in particular is ease of automation. The learning curve to start automating your Mac is very short and very gentle. Without ever seeing a single line of code you can add your own custom functionality to OS X to relieve you of your most boring repetitive tasks. If you can tolerate seeing a line or two of code, you can take things even further and tie Unix command line tools straight into your GUI. The best candidates for automation are simple repetitive tasks that you do often. You might only save 30 seconds each time, but if do that 10 times a day that soon adds up! In this post I just want to give three simple examples to whet your appetite and hopefully get you thinking about some simple tasks in your computing life that you could easily automate.

Read more

Tagged with:

Since I first started using OS X at version 10.3 I’ve always felt that the services menu had great potential but badly needed some fit and polish to make it actually live up to that promise. It has been so bad that it is basically forgotten, and almost no one remebers that it even exists. In every application in OS X there is a menu item under the apps’s main menu (the one in bold with the same name as the app) called Services, that’s what I’m talking about. When it comes to the services menu both Tiger and Leopard were major disappointments because they didn’t bring any real improvement to the neglected services menu. SnowLeopard on the other hand is a totally different story. Similarly, when Automator first came out I thought it had great promise, but that it was a very 1.0 kind of offering, again, in need of some fit and polish to allow it live up to its obvious potential. SnowLeopard provides a lot of that fit and polish, and really brings Automator forward significantly. And what’s better, Apple have combined the fit and finish in these two apparently unrelated products together, to provide some exceptionally powerful functionality.

Read more

Tagged with:

Update (18 June 2012) – A more up-to-date version of these scripts can now be found here.

My Myers Briggs personality profile insists that I “prefer economy of effort”, you can probably translate that to “is a lazy sod”. Because of this I like automating repetitive tasks. It all started when I wanted a quick and easy way to prepare my images for posting to my website. I wanted them resized with my URL and the Creative Commons icon added in, and I wanted to be able to process a whole directory of images in one go. I started by playing around with the GD libs in PHP, but soon realised it would be quicker and easier to use Perl to shell out to the command line tools from Image Magick. At the time I wrote a post on my choice to do this which also contained the initial code. That code has been expanded and evolved since, and now includes functions for rendering nice (in my opinion) borders and titles on my better images. If you want to see examples checkout the Photo of the Week category on this blog..

[tags]Perl, Image Magick, script, programming, image processing[/tags]

Read more

Tagged with:

For my post yesterday on the HD-DVD key I needed to convert the 128bit HEX key into a decimal number and then divide it by two. I figured this would be easy. I’d wander over to Google, search for “convert hex to decimal” and hey-presto, I’d get a web-based converter somewhere to bang the hex key into and get out a decimal number. This soon proved not to work in practice for large numbers. All the converters I tried gave me back floating point numbers with very large exponents. The means loads of precision was lost and hence I couldn’t get the exact number the MPAA claimed to own. So I did what I always do when I can’t find a program to do what I want, I hacked something together in Perl! Now, when I say hacked I do mean hacked. It only took me a few minutes to do and what do ya know, Perl lost precision too, giving me an answer of 1.32562788879895e+37. So, I needed to re-implement this algorithm in a language that could give me basically unlimited integer arithmetic. I chose Java because of the java.math.BigInteger class and because Java is the language I know best. I implemented the same basic algorithm in both languages. It’s interesting to see just how much bigger the Java code is!

[tags]Java, Perl[/tags]

Read more

Tagged with:

I’m pretty sure this is useless on most versions of Linux because the default DHCP plugin that comes with the Nagios Plugins distribution has this functionality and seems to work just fine everywhere except on RedHat-based distros like RHEL, Centos and Fedora Core. On these systems the default plugin does not seem to work and fails to detect any DHCP servers. This plugin is different to the one I gave instructions for before which tests whether a particular DHCP server is answering requests, this plugin finds rogue servers, it will not alert you if any of your actual DHCP servers are down. Hence, you should probably install both. This plugin is not very polished, it is rough and ready but I know it works on RHEL4. If you’re running a different system you may have to do some minor tweaks but this should serve as an excellent starting point none-the-less.

[tags]Nagios, DHCP, RedHat, RHEL, CentOS, Fedora, Linux[/tags]

Read more

Tagged with:

« go back