Keeping Track of WordPress Installs with Perl

January 20th, 2009

I’d taken a bit of a break from WordPress coding during the development of 2.7 and instead have been concentrating on simplifying the management of multiple WordPress installs. WordPress Mu offers is great for running multiple blogs for multiple users but sometimes it just doesn’t offer your users enough control over their own WordPress site. I’m going to post a number of tips and Perl snippets, detailing how to ease the management of your scripts.

Your first step is to be able to easily list the installs you have on your system. You could maintain a list but it’s easier to let MySQL do the hard work for you. Make sure your WordPress databases identifiable by name alone.

The following Perl snippet illustrates how you might list all your WordPress installs.

$sql = "show databases like 'wordpress_\%'";
$sth = $dbh->prepare("$sql");
$sth->execute();
while($row = $sth->fetchrow_arrayref){
	($name) = @$row;
	print $row , "\n";
}

It’s useful to be able to map your WordPress installations to their location on disk. You could record the location of each installation, but it’s probably better to have a standard location. For instance, each install could be found under /home/<sitename> or /var/www/<sitename>.

Here’s the Perl I use to map my database names to directories. The hash allows me to override the standard mapping for a few exceptional installations.

my %dir_exceptions = (
      "foo" => '/var/www/foo/wp',
      "bar" => '/home/bar/public_html/blog',
);
sub wordpress_location {
      my $name = shift;
      $name =~ m/wordpress_(.*)/;
      $name = $1;
      if(defined($dir_exceptions{"$name"})){
            return $dir_exceptions{"$name"};
      } else {
            return "/var/www/$name/";
      }
}

James Davis Perl, WordPress

Monitoring your WordPress install with tripwire

January 16th, 2009

You’ve installed WordPress, and you’re diligently upgrading with each new security fix that’s released. What happens if your install is compromised by a successful but previously unseen attack? What parts of your install has the attacker tampered with and which files can you trust? Will you notice the attack at all? A class of tools called file “integrity checkers” can monitor your WordPress install for unexpected and unauthorized changes. In this article I’ll show you how you can use Tripwire, perhaps the best known of these tools, to do just that. Read more…

James Davis WordPress

Here’s a quick way to run a petition in WordPress

October 3rd, 2007

I’ve written a short and simple plugin that embeds a web based petition into your WordPress page or post. Signatures are confirmed by e-mail and the administrative interface allows for customization along with deletion and exporting of signatures. Learn more now.

James Davis News