Educating the world

Our blog has over 10,000 readers a month

What the world thinks of techies

July 1st, 2010

I’ve been in I.T. for all of my working life. I’m a geekie type but I have a personality underneath with friends to prove it. I’ve met a lot of techie people who are, quite frankly, really dull so I can see where the stereotype comes from. We are like policeman and lawyers - handy to have in your arsenal of friends but you probably won’t invite them out for a beer unless you need something.

One of my favourite programs is Garth Marenghi’s Darkplace which is a spoof TV “horror series from the early 1980s that was considered so groundbreaking and terrifying that it was promptly sat on by the company that commissioned it". In the fifth episode Scotch Mist, kilt wearing ghosts come back to Romsford to seek revenge on Dagg Douglas MD because of the less than flattering things he said in a chip shop after his plane was diverted to Prestwick airport. Anyway, Scotch Mist rolls in (very much like John Carpenter’s The Fog) and starts killing the hospital staff leaving there bodies on the moor covered in tartan patterns. The quote comes during one of the director-commentary-style inserts that broke up the show.

Dean Learner: We found out that the mist was poisonous when two techies died. Now I don’t like to see anyone die, but if someone has to die, it might as well be a techie… because another one comes along, it’s the same belt, it’s the same hammer in the tool belt, you can barely tell the difference.

Building redir (redir.c) from patched sources

June 22nd, 2010

There is a really handy utility for Un*x called: redir (redir.c). It is a user level program that does port redirection. It’s really handy if you want a quick and dirty way of making traffic on one port on your machine point to another port on another machine. I’ve used this technique to by-pass firewalls and bounce traffic through places it’s not supposed to go.

I could have used iptables or ipchains, but these require root access which you might not have. Under Un*x you need root privileges to open a port numbered less than 1000 but most of the time you are re-routing normal application services like Oracle Forms and jInitiator which opens a gazillion ports to various machines to do application server stuff.

Also using iptables or ipchains is so final, not to mention fiddly to set up! Besides another reason to use redir is that the program can be modified to allow you to watch or collect the traffic, which could be infinitely more useful &#59;)

Unfortunately, redir is no longer in a standard distro so it has to be built from scratch. The program itself hasn’t changed for about 10 years so it is only available in source and patched source. I’m going to describe below how to download, patch and build the redir application.

  1. Create a working folder and go into it.

    mkdir redir
    cd redir

  2. Go to http://redir.sourcearchive.com/ and find the latest version.
  3. At the time of writing this article the latest version is 2.2.1-9. Download those components.

    wget http://redir.sourcearchive.com/downloads/2.2.1-9/redir_2.2.1.orig.tar.gz
    wget http://redir.sourcearchive.com/downloads/2.2.1-9/redir_2.2.1-9.diff.gz
    wget http://redir.sourcearchive.com/downloads/2.2.1-9/redir_2.2.1-9.dsc

  4. Check the integrity of the downloads with md5sum and compare them against the values listed in the *.dsc file

    md5sum redir_2.2.1-9.diff.gz redir_2.2.1.orig.tar.gz
    e82abbecfa8ca5941e6601d61b84303d redir_2.2.1-9.diff.gz
    4342fadac30504c86c8db7beefe01995 redir_2.2.1.orig.tar.gz

  5. Uncompress the sources.

    gunzip redir_2.2.1-9.diff.gz
    tar -xvzf redir_2.2.1.orig.tar.gz

  6. The first patch expects the files to be in different places, so shift things around a little to make it match up, don’t worry about the mv/subdirectory warning.

    mv redir-2.2.1 redir-2.2.1.orig
    mkdir redir-2.2.1.orig/debian
    mv redir-2.2.1.orig/* redir-2.2.1.orig/debian

  7. Now apply the patch.

    patch -p0 -i redir_2.2.1-9.diff

  8. There’s no dpatch on Plesk so we will have to apply the patches by hand using the normal patch command. Change to the main source folder.

    cd redir-2.2.1.orig/debian

  9. The patches must be applied in order so list them out and build a patch script.

    ls patches/[0-9][0-9]_* | sed ’s/^/patch -i &/’ > do.patch

  10. Then run them all.

    sh ./do.patch

  11. Now that we have applied all the patches, we must clean and build.

    make clean
    make

Now we’ll test it. The following command listens to port 12345 and relays all connections to port 22 (on the same machine). So by talking to port 12345 we are actually talking to our SSH service listening on port 22.

  1. Launch the port redirector service in the background.

    ./redir –lport=12345 –cport=22 &

  2. Connect to the service.

    ssh -D 12345 localhost

  3. Log in and then log out.

    hostname
    exit

  4. Kill service.

    kill %1

Go play!

Adding custom fields codes to a Word document

June 18th, 2010

The first page in my documentation is always the title page. You know the sort - big company logo along with the title of the document and a couple of other useful pieces of information for filing like file name, version, last updated date and author. Each one of my pages has headers and footers. The page header contains the title and the version of the document whilst the footer contains the company name with a copyright message and the page number.

As you can see there is repeating information which has to be managed and updated. So often I get documents where the version date is changed on the front page but the author has forgotten to update it in the headers or footers. This is where Microsoft Word Fields come in handy.

A Microsoft Word Field is a property that is tucked away inside the document or is generated by Microsoft Word. The best example of a Field that most people use without noticing is Page Number or Number of Pages. These are just 2 of the really common ones, there are loads and you can create your own.

The documentation is a bit thin which is a bit surprising for Microsoft. I had a look on the interweb for other blogs describing how to add these mystical fields but most of them were pretty complicated and I was left to use good old fashioned trial and error to figure it out. And now that I have I’m telling the world.

So let’s go with my example from the first paragraph. In order to make it easier to see when it’s working lets fill in the property information first. If we don’t do this first after we set up our Field it will be blank and we won’t be able to tell if it is blank because it’s broken or it’s blank because it’s empty.

For Office 2010, Go to File->Info and click the Properties drop down on the right hand side (under the preview of the document)and Advanced Properties.

  1. From Word’s menu select File->Properties.
  2. Goto the General tab.
  3. Fill in as many of the document properties as you can but do include at the very least: Title, Subject, Author, Company.
  4. Now go to the Custom tab.
  5. Next to Name enter version.
  6. Next to Type select Number from the drop down box.
  7. Next to Value enter 0.1 (or whatever your document version is).
  8. At this point the Add button will become enabled, so click it.
  9. version will appear in the Properties: list in the bottom part of the screen.
  10. Finally click Ok.

You have now added all the information you want in one central place. Next we need to create our front page. We will embed several Fields in it.

  1. Set up the image in the centre of the page and make it look pretty.
  2. Under the image we want the document Title, so place the cursor somewhere sensible and set the font and format you want.
  3. From the menus select Insert->Field…
  4. Make sure the Category is set to (All).
  5. Select Title from the field names.
  6. Choose the Format of the field.
  7. Click Ok.
  8. The title of your document will appear, when you click on it, it will appear with a grey background to show it’s a field code.

At the bottom of the screen we are going to write our file and documentation fields.

  1. First write the text: Document File name
  2. Next set up the font and format in the way you like for this piece of information.
  3. From the Insert menu select Field….
  4. Ensure the Category is set to (All) and select FileName.
  5. Next write Date and from the field’s menu select SaveDate picking the format you would like the date to be displayed in.
  6. Getting the idea yet? Next write Author and select Author from the field’s dialogue.
  7. Finally enter Version. This one is a custom field in the document properties so select DocProperty from the Field names and because we have already set up the version value it should appear in the Property list so select it and press Ok.

In each case when we add the the Field code to the document it will appear updated in the document, with a grey background if you click on it. Now just do the same for the headers and footers and you’re done.

When you change any of your document properties just go into File->Properties make the changes you want. When you return to the document. Highlight the field by clicking on it and from the context menu select Update Field. Unfortunately the header and footer Fields are not covered in the Select All (Control-A) and so must be done separately.

Plesk Mailman cheat sheet

June 7th, 2010

Plesk provides mail list capabilities via MailMan which is one of those Unix programs (services) that has just been around forever. The software is pretty much rock solid and hasn’t been updated in ages. It does what it says on the tin. It allows users to sign up for a mail list and manage their delivery options.

As far as administering a MailMan list goes there is about a thousand trees worth of documentation. Once the application was completed the developers had no more excuses and so had to finish writing the documentation as well &#59;) Although the documentation is very thorough you do, kind of, have to read almost all of it in order to find the bits you want. It is like writing socket applications - loads of documentation and options but you generally just reuse the same 5 lines! MailMan has just the same characteristics, there are only a couple of things you need to do.

So here is a cheatsheet for the most commonly used URLs for managing a MailMan list. For the purpose of the following examples I will assume the list in question is called my-list-name and list email address is my-list-name@example.com.

Normal user login
List email address = my-list-name@example.com
Password reminder, subscribe and unsubscribe
http://lists.example.com/mailman/options/my-list-name

Administrator login
http://lists.example.com/mailman/admin/my-list-name

Archive - email history
http://lists.example.com/mailman/private/my-list-name/

Export list members
This exports the list of members in the following form and places one member per line:

“Full name” <emailaddress>

From the command line:

/usr/lib/mailman/bin/list_members -f my-list-name

List commands
Send blank email with subject of:

help

to my-list-name-request@example.com (notice the -request on the end)

List of members
Send blank email with subject of:

who <password>

to my-list-name-request@example.com (notice the -request on the end)

Subscribe to list
http://lists.example.com/mailman/listinfo/my-list-name
Fill in “Subscribing to My-List-Name” section.

Personal settings
http://lists.example.com/mailman/options/my-list-name

Change email address
From the following page you can unsubscribe from the list using your old email address. When you have unsubscribed from the list you can add yourself back on under a different email address and password.
http://lists.example.com/mailman/options/my-list-name

Administration section
http://lists.example.com/mailman/admin/my-list-name/general

Missing B2evolution posts

June 2nd, 2010

I recently had a very strange problem with my B2evolution installation. Some of my posts had gone missing! When I say missing I mean half missing! You could search for the articles and they would appear in the list of search results. You could also find them by looking at them in the year/month/day grouping view. When the article was displayed in the results view or the date grouping view it looked fully formed, however when you clicked on the title to open the actual article it replaced the last ‘-’ (dash or minus (for the search engines &amp;#59;&amp;#41; )) in the URL title with a ‘:’ (colon) and gave the message:

Tags: move-a-window-when-its-title-bar-is-off
Sorry, there is nothing to display…

I asked in the forums and they said check the configuration file for a work around. So in $BLOGROOT/conf/_advanced.php I found the comment in question:

Enable a workaround to allow accessing posts with URL titles ending with dash (workaround for old bug).

In b2evolution v2.4.5 new tag URLs were introduced: You could choose to have tag URLs ending with a dash. This lead to problems with post URL titles accidentally ending with a dash (today, URL titles cannot end with a dash any more): Instead of displaying the post, the post title was handled as a tag name. When this setting is enabled, all tag names which are exactly 40 chars long and end with a dash are handled in the following way:
Try to find a post with the given tag name as the URL title. If there is a matching post, display it; otherwise, display the normal tag page.

Note: If you use a 39 chars-long tag name, have an URL title which is the same as the tag *but* additionally has a dash at the end and you use the dash as a tag URL “marker", you won’t be able to access either the post or the tag page, depending on the value of this setting.

@global boolean $tags_dash_fix
@internal Tblue> We perhaps should notify the user if we detect bogus post URLs (check on upgrade?) and recommend enabling this setting.

So to fix the problem immediately add the following line to $BLOGROOT/conf/_basic_config.php:

PHP

$tags_dash_fix 1;

This will fix the problem and give you time to fix the database. Fixing the database requires SQL command line access to the database so careful what you do! Always take a backup before attempting any SQL on a database.

To check which other articles have been affected you can run the following bit of SQL:

Code

SELECT post_ID,
concat('|', post_urltitle, '|')
FROM evo_items__item
WHERE post_urltitle like '%-';

This gives you the following output. I have surrounded the post url title with ‘|’ (pipe) characters so you can easily see where the field value starts and stops.

+---------+--------------------------------------------+
| post_ID | concat('|',post_urltitle,'|')              |
+---------+--------------------------------------------+
|     132 | |attempted-to-assign-id-from-null-one-to-| |
|      53 | |import-and-access-to-mysql-database-for-| |
|      90 | |move-a-window-when-its-title-bar-is-off-| |
|     105 | |prevent-tomcat-redeploying-when-running-| |
+---------+--------------------------------------------+

We will now run the SQL that removes the last ‘-’ (minus or dash) from the post’s URL title.

Code

UPDATE evo_items__item SET
post_urltitle = substr(
post_urltitle, 1, length(post_urltitle)-1
) WHERE post_urltitle like '%-';

For each record where the post_urltitle ends with a ‘-’ (minus), replace it with the parts of the text from character position 1 to character position one less than the length of the text.

When you have completed the database fix you can remove the $tags_dash_fix line from $BLOGROOT/conf/_basic_config.php.

The current B2evolution code prevents post URL titles from being created ending in a ‘-’ (minus or dash) so once you have fixed the issue it doesn’t need to be revisited.