Archive for March, 2007

Cisco develops smart robot nodes to maintain network connectivity.

I found this via slashdot ….

Military & Aerospace Electronics – Cisco develops smart robot nodes to maintain network connectivity while on the move Company engineers built prototype cube-shaped robots that sense when a laptop computer user is about to lose wireless network connectivity and move toward the user to maintain the network link, said Dave Buster, product marketing manager for the Cisco Global Government Solutions Group (GGSG) in Research Triangle Park, N.C.

Ok, on first glance you think, how cool what a gimmick, and then you smile as you see the colour from your IT security officers face drain away… the chances are that they have spent hours tuning the radios so that very little WIFI leaks outside the building, now imaging a robot that will follow you outside and all that effort is wasted. I think there’s a good lesson here, obscurity isn’t security, if your WIFI is rock solid then a little exposure won’t be a problem.

In general I think the idea is good, as it could allow you to cover area’s dynamically, i.e. if robots could make their way over to the meeting rooms or canteen when usage went up that would be cool, but I guess that would cause problems with free channels etc, what about the idea of a sony dog with a wi-fi repeater in ? You could have one AP inside, and that could follow you out to the garden ! Oh the possibilities ! :cool:

Recent phpBB Topics on WordPress Plugin v0.3

UPDATE: This Plugin has been updated, please download the update from http://wordpress.org/extend/plugins/phpbb-recent-topics/, and please comment on the new post, thanks.

phpBB recent topics admin interface in WP 2.3.x
Admin GUI

Another day, another plug-in update…..Version 0.2 never saw the light of day, after fixing my compatibility issue I moved straight into setting up the admin interface. So here we have it, a proper implementation :)

Download phpBB Recent Topics

Installation

  • Unzip phpbb_recent_topics.tgz in your `/wp-content/plugins/` directory. (You’ll have a new directory, with this plugin in /wp-content/plugins/phpbb_recent_topics)
  • Activate the plugin through the ‘Plugins’ menu in WordPress
  • Configure the plugin, you need to tell wordpress about phpbb, this is done in the wordpress menu ‘Options’ -> ‘phpBB Recent Topics’
    The following Settings are required:

    • * The name of your phpBB database (e.g phpbb)
    • * The name of the table where topics are held (the default is phpbb_topics )
    • * The full url of your forum for links (e.g. http://www.mydomain.com/forum)
    • * The number of topics to show. (If left blank you get 5)
  • Hit ‘Update Options”
  • To output the list of topics in a page or post…
    • * create a new page/post, type {phpbb_recent_topics} , hit ‘Publish’ or ‘Create new page’

    To output the list of topics in your theme sidebar…

    • * edit sidebar.php and inside <div id=”sidebar”> type…
      <?php
      if (function_exists('phpbb_topics')) {
      phpbb_topics();
      }
      ?>

A bit about Database configuration.
If wordpress & phpBB share a DB already then set $PHPBBDB to DB_NAME and everything will be fine, else you’re going to need to GRANT the wordpress user read access to phpBB.

How to GRANT wordpress read only access to phpBB ?
If you don’t know it already you need to find your wordpress mysql user id, it’ll be in wp-config.php

define('DB_USER', 'wp_user');     // Your MySQL username

and you should have already found your phpbb database & table for the above.
You need to type the following syntax into your mysql database

GRANT SELECT ON phpbb_database.phpbb_topics TO wp_user@localhost;

this can be achieved by logging into phpmyadmin as your phpbb user, selecting SQL and pasting the correct GRANT into the text box.

Upgrading from Version 0.1
Upgrading is optional. This version has two major changes: The first basically fixes the compatibility issue I have running two php ob_start processes in wordpress; the second is the introduction of a “proper” admin interface (rather than hacking the php file).
To upgrade, make a note of the following settings:

$PHPBBDB = "phpbb"; //phpBB db name
$TOPIC_TABLE = "phpbb_topics"; //phpbb topics table
$SITEURL = "http://www.mydomain.com/forum"; //Forum URL

Deactivate version 0.1, and follow the Installation instructions above :)

Frequently Asked Questions

  • Can I output 10 Topics in my Page, and 3 Topics in my Sidebar ?
    • Yes ! In the WordPress menu ‘Options’ -> ‘phpBB Recent Topics’, set ‘The number of topics to show’ to 10, and then in your sidebar include…<?php
      if (function_exists(‘phpbb_topics’)) {
      phpbb_topics(3);
      }
      ?>
  • Can I exclude a certain forum from the list ?
    • In this version, the only way to do that is to hack /wp-content/plugins/phpbb_recent_topics/display/display.php, change
      $results = $wpdb->get_results("SELECT * FROM $TOPIC_TABLE ORDER BY topic_time DESC LIMIT $LIMIT");

      to

      $results = $wpdb->get_results("SELECT * FROM $TOPIC_TABLE WHERE forum_id != 1 ORDER BY topic_time DESC LIMIT $LIMIT");

      to exclude forum 1 from the list. I plan to setup a proper solution to this in the next version.

Finally Subversion
You also might be interested to know that I’ve been getting to grips with the wordpress plug-ins svn, so you can get work directly from here; and when wordpress.org re-crawls my readme the latest version will also be available on wordpress.org/extend/plugins/ :cool:

root cookie v1.2 (wordpress plugin)

UPDATE: This Plugin has been updated, please comment on the new post, thanks.

I’ve been a bit slow, aja pointed out the fault a few days ago, but I’ve been a bit slow off the mark :(

Anyway, here’s the official announcement,

root cookie version 1.2

This version primarily fixed the logout issue, and yup, I’ve learnt by my mistakes it loads it gently too ;)

links for 2007-03-20

How to Monitor wordpress with Nagios

WordPress like many web applications relies on apache (or something else) to serve the HTTP pages and mysql to store the data. Your wordpress website is important to you, so you need an external monitoring system to let you know what’s going on.

Nagios is a great, enterprise class, open-source monitoring application; and what you need do is configure it to exactly represent how wordpress works; if you can get that right you can immediately get notified if any piece of the puzzle fails.

I’m going to write up a simple example of how to monitor wordpress and it’s associated jigsaw pieces, so we’re going to setup one host with appropriate dependant services. Ultimately, you should configure nagios to suit exactly how your environment works, but hopefully this “how to” will get you started.

Basic Config.
To configure nagios you need have services (such as http) associated with hosts; to get started, I’m going to have to assume you have followed another “how to” and have nagios up and running, and monitoring localhost, you can even use my own config generator to get you started ;) Basically you should have a host.cfg entry like so:

define host{
        use                     generic-host            ; Name of host template to use
        host_name               linickx.com
        alias                   My WebSite
        address                 www.linickx.com
        check_command           check-host-alive
        max_check_attempts      10
        check_period            24x7
        notification_interval   120
        notification_period     24x7
        notification_options    d,r
        contact_groups  admins
        }

The first (and easiest) part of wordpress to monitor is the web-server which serves the web pages on port 80, so a /etc/nagios/serivces.cfg entry like.

define service{
use                             generic-service         ; Name of servic
e template to use
host_name                       www.linickx.com
service_description             HTTP
is_volatile                     0
check_period                    24x7
max_check_attempts              10
normal_check_interval           1
retry_check_interval            1
contact_groups                  admins
notification_options            w,u,c,r
notification_interval           960
notification_period             24x7
check_command                   check_http
}

Getting Technical.
Have you noticed the deliberate mistake ? I’m using resolvable names in my config files, this is deliberate as my website is on a shared server, and check_http with an IP address is very different to check_http www.linickx.com , but in order for www.linickx.com to work, DNS needs to be working. While we are here, it makes sense to monitor that as well. In /etc/nagios/checkcommands.cfg add an entry similar to….

# 'check_dns' command definition
define command{
        command_name    check_dns_linickx-com
        command_line    $USER1$/check_dns -H www.linickx.com -a 69.73.189.228
        }

Where the -a ip address , is the ip of your “A Record”, if you don’t know what that is you can use dnsstuff.com to find it for you. You can now create a service that uses that command…

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linickx.com
        service_description             DNS
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              10
        normal_check_interval           5
        retry_check_interval            1
        contact_groups                  admins
        notification_options            w,u,c,r
        notification_interval           960
        notification_period             24x7
        check_command                   check_dns_linickx-com
        }

We have HTTP and DNS monitored, all the wordpress data is stored in a mySQL database, so now you need to monitor that, to do that you need to setup another checkcommand; add the following.

# mySQL command definition
define command{
command_name    check_mysql
command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$
}

This check command will log into the database and report OK if it is working, much better than check_tcp 3306 . Now you can add the following service entry

define service{
use                             generic-service         ; Name of servic
e template to use
host_name                       www.linickx.com
service_description             mySQL
is_volatile                     0
check_period                    24x7
max_check_attempts              10
normal_check_interval           5
retry_check_interval            1
contact_groups                  admins
notification_options            w,u,c,r
notification_interval           960
notification_period             24x7
check_command                   check_mysql!USERNAME!PASSWORD
}

For this to work the user will need to have permissions to log into the nagios machine, so if you followed the wordpress codex and added “TO wordpressusername@localhost” in your mysql statement, you’ll need to add that to run

GRANT ALL PRIVILEGES ON databasename.* TO wordpressusername@NAGIOS-SERVER;

where NAGIOS-SERVER is a resolvable name or ip address. Note: Don’t forget about firewalls ! Make sure that TCP 3306 is open between your nagios box & wordpress website.

The bit that actually monitors wordpress.
You are now independently checking both HTTPD & MYSQL, but what if wordpress can’t actually connect (lets say wp-config.php is screwed), both these checks will pass and nagios will stay green; what you need to do is monitor a page. If that page works , everything’s fine, if the page fails (and you get the default database connection error page) then nagios flags and alert. We’re going to add another checkcommand

# 'check linickx.com wordpress' command definition
define command{
        command_name    check_wp_linickx
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -u /blog/about-me
-s "About Me"
        }

You can alter this in anyway you want, but what it does is it looks for http://$HOSTADDRESS$/blog/about-me (so http://www.linickx.com/blog/about-me) and if that page returns “About Me” then everything is OK.

Tidying up with dependencies.
We’ve already established that if either mySQL, http or DNS fails, wordpress will fail, so we want to ensure we don’t get hit with double alerts about the same problem, enter dependencies. HTTP is dependant on DNS, enter the following in /etc/nagios/dependencies.cfg (make sure you have cfg_file=/etc/nagios/dependencies.cfg in /etc/nagios/nagios.cfg )

define servicedependency{
        host_name                       linickx.com
        service_description             DNS
        dependent_host_name             linickx.com
        dependent_service_description   HTTP
        execution_failure_criteria      n
        notification_failure_criteria   u,c
        inherits_parent         1
        }

and WordPress is dependant on HTTP & mySQL , so you need…

define servicedependency{
        host_name                       linickx.com
        service_description             HTTP
        dependent_host_name             linickx.com
        dependent_service_description   WordPress
        execution_failure_criteria      n
        notification_failure_criteria   u,c
        inherits_parent         1
        }

define servicedependency{
        host_name                       linickx.com
        service_description             mySQL
        dependent_host_name             linickx.com
        dependent_service_description   WordPress
        execution_failure_criteria      n
        notification_failure_criteria   u,c
        inherits_parent         1
        }

You can check your config with nagios -v /etc/nagios/nagios.cfg , assuming you have no errors wait for checks to go green and begin testing. Tests you can run can be anything from unplugging the cable from your nagios box to simulate a complete failure, to stopping the mysql service on your website to make sure check_mysql works.

Making it pretty for the hell of it.
Nagios has a web interface, one of the things we can do is customize it to represent our config, how about a pretty icon for our website ? or a custom wordpress action ? Here’s how to setup a pretty icon and action (button to click on) for our wordpress service.

To get started, you’ll probably need a copy of the wordpress logo from the svn , I then cut the “W” out to make a square icon, but you can do what you like :) Firstly something non essential: To display any icon in nagios as a “host icon” you’re going to need it in both png and gd2 image format, you’ll have to install a conversion tool. (for redhat)

yum install gd-progs

to run the conversion, use the following…

pngtogd2 wordpress-logo.png wordpress-logo.gd2 0 1

that’ll give you a chunk size of 0 and no compression as recommended for nagios.

But if you just want service icons, then you can get away with just a png. Save any custom images in /usr/share/nagios/images/logos/ make sure they’re readable ( e.g. chmod 644 file ) and we’re good to go.

So the config file, 1st make sure you have cfg_file=/etc/nagios/serviceextinfo.cfg enabled in /etc/nagios/nagios.cfg . My sericeextinfo.cfg has the following…

define serviceextinfo{
host_name               linickx.com
service_description     WordPress
notes                   My website  powered by wordpress !
icon_image              wordpress-w.png
icon_image_alt          WordPress
action_url              http://$HOSTADDRESS$/blog/wp-admin/
}

What this does is it adds my wordpress-w icon to the nagios status pages, and give me a “red star” type icon which when I click on takes me to my wordpress admin page… cool !

Some compulsory Screen-shots.

Nagios Host Detail Example Nagios Service detail for WordPress

That should just about wrap it up, one fully monitored wordpress installation; as you can see this can be adapted to monitor any php / mysql app :) Please let me know if you have any further suggestions.

Compatability issues with phpbb recent topics plugin ?

I’ve recently run into a compatibility problem with my phpbb topic plugin, basically I tried to copy the code I did ( the ob_start / stop buffer thing ) and I found that the second time I ran the loop it didn’t work !

Anyway in lieu of working on an admin interface for setting up the phpbb connection I’m solving this, if anyone is having a similar issue please let me know.

Oh, and this might be of interest…

———- Forwarded message ———-
From: Nick
Date: 12-Mar-2007 11:38
Subject: Re: Recent phpBB Topics on WordPress Plugin
To: Paul Stokes

Hi Paul,

You can do this by playing with the SQL statement in the plugin, for example

SELECT * FROM $TOPIC_TABLE WHERE forum_id != 1 ORDER BY topic_time DESC LIMIT $limit

would exclude topics from forum 1

hope that helps,
Nick

On 11/03/07, Paul Stokes wrote:

Hello,

First I must say what a great plug-in you have here!
Is there a way to keep the hidden forums topic hidden?
Thanks
-Paul

Google Reader Notifier – Firefox Extension

This is one of those extensions I couldn’t live without !

Google Reader Notifier | Firefox Add-ons | Mozilla Corporation Google Reader Notifier by Mark D.B.D This firefox extension shows you how many unread items you have in your Google Reader account.

Service Recovery Scripts & Error Page Tips.

A couple of weeks ago, I was proper ill with flu; the problem with looking after your own server is that only you can fix it – it’s well and good having monitoring systems (nagios) telling you about faults, but if you can’t read or see the alerts the fault won’t get resolved.

During this time I was ill, for an unknown reason the mySQL process on my server died, as such my website (and others I look after) were down for 8 hours. The fix was simple, one command, restart the service and normal service was resumed (excuse the pun).

This led to me to the conclusion that there must be a way to get the server to fix it’s self. after all, why do a job when you can get a computer to do it for you ! Fortunately I had a light bulb moment and realised that I could use the init scripts that are provided by redhat, the below code will restart apache (httpd) and mySQL on a redhat based system in the event that the service was not stopped cleanly. (In-fact this config has only be tested on CentOS, your mileage may vary on anything else)

#!/bin/bash

# taken from redhast default scripts - /etc/rc.d/init.d/functions

# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
export PATH

status() {
        local base=${1##*/}
        local pid

        # Test syntax.
        if [ "$#" = 0 ] ; then
                echo $"Usage: status {program}"
                return 1
        fi

        # First try "pidof"
        pid=`pidof -o $$ -o $PPID -o %PPID -x $1 ||
             pidof -o $$ -o $PPID -o %PPID -x ${base}`
        if [ -n "$pid" ]; then
# Uncomment this if you want OK messages
#               echo $"${base} (pid $pid) is running..."
                return 0
        fi

        # Next try "/var/run/*.pid" files
        if [ -f /var/run/${base}.pid ] ; then
                read pid < /var/run/${base}.pid
                if [ -n "$pid" ]; then
                        echo $"${base} dead but pid file exists"
                        /etc/init.d/${base} restart
                        return 1
                fi
        fi
        # See if /var/lock/subsys/${base} exists
        if [ -f /var/lock/subsys/${base} ]; then
                echo $"${base} dead but subsys locked"
                /etc/init.d/${base} restart
                return 2
        fi
        echo $"${base} is stopped"
        return 3
}

# found in /etc/init.d/httpd
httpd=${HTTPD-/usr/sbin/httpd}

status mysqld
status $httpd

If you save this, as /etc/cron.hourly/auto_recovery.sh , then do chmod +x /etc/cron.hourly/auto_recovery.sh , assuming you’ve not changed the default cron setup, every hour mySQL & httpd will be checked, if they have died the’ll be restarted and root will get an e-mail about what happened.

Cool eh !

A final finishing touch: I wanted to change the default “Database Down” error messages on my two most popular applications.

  • Melvin Rivera has written a tutorial on how to customize the wordpress error page, note that it involves editing a file outside of wp-content, that means you’ll have to re-do this “hack” every time you upgrade wordpress.
  • PHPBB: Setting a custom error page on that is really easy, first create a php page displaying your message. Then at the bottom of /path/to/phpbb-install/includes/db.php you’ll see
    // Make the database connection.
    $db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
    if(!$db->db_connect_id)
    {
    message_die(CRITICAL_ERROR, "Could not connect to the database");
    }

    change it to

     // Make the database connection.
    $db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
    if(!$db->db_connect_id)
    {
     include("/path/to/my-custom-error-page.php");
            die();
    }

Now if you database dies, for the time it’s down (before cron fixes it) wordpress & phpbb sites would get a much prettier error message. Obviously there’s no solution for apache as there’s nothing to serve the pages, but hopefully this kind of thing doesn’t happen to often :D

Recent phpBB Topics on WordPress Plugin

UPDATE: This Plugin has been updated, the latest version is available on wordpress.org please comment on the new post, thanks.

Written primarily for my wife to use in the future, but I’ve developed a pluging that allows you to post a list of recent phpBB threads/topics within wordpress.

If found this plugin by Brandon Alexander but it wasn’t right for my needs, firstly he looks up usernames from phpBB, now my phpBB & wordpress installs don’t share databases and I thought it was a bit of a security risk giving wordpress access to my users password hashes… and secondly that plugin gives a list of recent posts, not what I wanted, and wanted threads (topics).

This is the 1st version, the massive fault with it is that you have to edit the file (to tell it where to find phpBB), I’m not yet smart enough to include an admin interface.

Installation: Download phpbb_recent_topics.txt and save as phpbb_recent_topics.php in your wordpress plugins directory. Edit the file, and change these bits to your appropriate settings…

$PHPBBDB = "phpbb_database"; // phpBB db name
$TOPIC_TABLE = "phpbb_topics"; // phpbb topics table
$SITEURL = "http://www.domain.com/phpbb"; //Forum (phpbb) URL

A bit about Database configuration.
If wordpress & phpBB share a DB already then set $PHPBBDB to DB_NAME and everything will be fine, else you’re going to need to GRANT the wordpress user read access to phpBB.

How to GRANT wordpress read only access to phpBB ?
If you don’t know it already you need to find your wordpress mysql user id, it’ll be in wp-config.php

define('DB_USER', 'wp_user');     // Your MySQL username

and you should have already found your phpbb database & table for the above.
You need to type the following syntax into your mysql database

GRANT SELECT ON phpbb_database.phpbb_topics TO wp_user@localhost;

this can be achieved by logging into phpmyadmin as your phpbb user, selecting SQL and pasting the correct GRANT into the text box.

Plugin Usage.
The plugin can be used in two ways, for those who don’t like editing templates you can call (type)

{phpbb_recent_topics}

from any post or page, and it will be replaced with an list of the last 5 topics.

For those who want to include the list in a sidebar template or similar, call the following function: phpbb_topics(), something like

 if ( function_exists('phpbb_topics') ) { phpbb_topics(5); }

where by the number 5 can be replaced with anything less that 10, and that’ll be the number of topics returned.

Hopefully that all makes sense, feel free to contact me with problems.

UPDATE: Comments about combatability issues here please.