PHP5 / GD2 Image Manipulation Package

26 11 2006

I decided to write a portable class library for basic image manipulation this week. It’s pretty incompatible with older versions of PHP and GD but in the environments I use, that’s not a problem (PHP > 5.1 and GD 2.0.28).

You can download the the package here with some api docs and examples (Around 1.1M) or here without the docs (15k).

If you use it and like it, drop me a line and let me know. There are more things I could make it do and error handling is pretty non-existent, but it serves my purposes for now… Next thing will be truetype font writing on the images…

You can see some online examples and the docs here



Compiling Clamav 0.88.5 from source on OpenBSD 3.7

28 10 2006

Fed up with getting messages from freshclam saying my clamav installation was out of date, and reluctant to update one of my OpenBSD installations to latest release, I set about trying to figure out how to compile clamav from source.

I started by downloading the latest stable source from www.clamav.net (0.88.5) and tried a simple

./configure
make

I was under no illusions that this would probably fail and it did:

...
/usr/local/lib/libclamav.so.1.17: undefined reference to `pthread_mutex_lock'
/usr/local/lib/libclamav.so.1.17: undefined reference to `pthread_join'
collect2: ld returned 1 exit status

Much google-ing later I was still having no luck … I tried a number of different ./configure arguments which I found in my ports tree at /usr/ports/security/clamav/Makefile until I found this thread started by Charles Farinella on the OpenBSD Misc List

I followed the instructions in this thread to the letter; found the block of text in the configure script:

openbsd*)
    if test "$have_pthreads" = "yes"; then
	LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -pthread"
	if test "$use_cr" = "no"; then
	    CLAMD_LIBS="$CLAMD_LIBS -pthread"
	    CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -pthread"
	else
	    CLAMD_LIBS="$CLAMD_LIBS -pthread -lc_r"
	    CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -pthread -lc_r"
	fi
	TH_SAFE="-thread-safe"

and changed LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -pthread" to LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -lpthread"
did a

./configure --disable-cr --disable-clamav
make
make install

and WOO-HOO all was good!!!

Just a couple of things, After installation I tried a freshclam and it complained that I should edit /usr/local/etc/clamd|freshclam.conf files - these are usually kept in /etc not /usr/local/etc so I cd’d to /usr/local/etc renamed the conf files and soft linked the files in /etc to /usr/local/etc and voilla!



Preventing Image Hotlinks With Apache Configuration Files

27 10 2006

As always, this is more a reminder to me than a ‘How-To’ - For ages I’d been meaning to stop certian sites from embedding images from my servers directly into their pages but I kept forgetting and also didn’t know exactly how to stop it. I found the time and inclination last night and turned to the apache manual…

<FilesMatch ".(gif|jpg|png)">
	SetEnvIfNoCase Referer "my.domain.co.uk/" local_ref=1
	Order Allow,Deny
	Allow from env=local_ref
</FilesMatch>

Pretty simple huh?
As I’m sure you can work out, if you have multiple domains all pointing at the same space you just need to add more regular expressions:

SetEnvIfNoCase Referer "my.domain.co.uk/" local_ref=1
SetEnvIfNoCase Referer "my.domain.com/" local_ref=1
(...etc)

References



Updating The ClamAV Daemon on OpenBSD 3.7

25 10 2006

Introduction

This post is now pretty pointless. The OpenBSD 3.7 ports tree is no longer maintained so you’ll only get up to clamav 0.88.3 (I think). Take a look at this post on compiling clamav from source.

This reference document describes the process for updating
ClamAV on OpenBSD 3.7 Release via the ports system.

Requirements

  • OpenBSD 3.7 Release (Although these intuctions will work on
    any version of OpenBSD with a little alteration)
  • A local copy of the OpenBSD Ports tree
  • This document assumes you already have a working (But out of date) copy of ClamAV installed.

Instructions

I use tcsh for my shell so you may need to alter the syntax for setting the
CVSROOT environment variable:

Update the Ports tree

Make sure you pick a cvs mirror close to you.

host: su
root# tcsh
root# setenv CVSROOT anoncvs@anoncvs.de.openbsd.org:/cvs
root# cd /usr/ports
root# cvs -q up -rOPENBSD_3_7 -Pd

Find and remove the clamav package

root# kill -s QUIT `cat /path/to/clamd.pid`
root# pkg_info -a | grep clamav
clamav-0.88.2       free virus scanner
root# pkg_delete clamav-0.88.2

Make and install the updated package and start the ClamAV daemon

root# cd /usr/ports/security/clamav
root# make install
(… Screenfulls of output ….)
root# freshclam
root# /usr/local/sbin/clamd


Setting Up a Local Nameserver on Mac OS X 10.4.x

23 10 2006

Instructions for setting up a local Nameserver in Mac OS X 10.4.x For Local Website Development

Introduction

Mac OS X Tiger comes with lots of traditional UNIX goodies, one of these is the BIND name server.

These guidelines are intended as a quick reference for setting up bind to resolve arbitrary
domain names so that in turn you can set up virtual hosts in apache.

I prefer this method to mucking about with NetInfo Manager and please feel free to point out
gotchas and caveats with this approach.

References

An Article at MacOSXHints.com

DNS & BIND By Paul Albitz

Set up the BIND Configuration files
  • Open up a terminal and become root
  • mkdir /System/Library/StartupItems/BIND
  • cd /System/Library/StartupItems/BIND
  • touch BIND
  • touch StartupParameters.plist

Edit the ./BIND file in your favourite editor and insert the following:

#!/bin/sh

. /etc/rc.common

if [ "${DNSSERVER}" = "-YES-" ]; then
  ConsoleMessage "Starting BIND DNS Server"
  /usr/sbin/named
fi

Make the BIND file executable with a chmod +x BIND

Edit the ./StartupParameters.plist

{
  Description = "Local Caching DNS Server";
  Provides = ("DNS Server");
  OrderPreference = "None";
  Messages =
  {
  start = "Starting BIND DNS Server";
  stop = "Stopping BIND DNS Server";
  };
}
Set up the rndc utility
  • Create the rndc.conf file: rndc-confgen > /etc/rndc.conf
  • Copy the key from rndc.conf into a new rndc.key file: head -n 6 /etc/rndc.conf > /etc/rndc.key

Edit the rndc.conf file and change the line that reads:

options {
	.....
	default-port 953;
};

To:

options {
	.....
	default-port 54;
};
Create a new Zone File
  • cd /var/named
  • touch my.site (rename my.site to your name of choice such as powerbook.site or something. Try to avoid ‘real’ tlds such as .com or .net etc…)
    • Edit the new zone file to read something like this:

      $TTL        86400
      @           IN    SOA      localhost. root.localhost.  (
                                 2003072405
                                 7200
                                 7200
                                 1209600
                                 172800 )
      
      ; Primary Name Server
                  IN    NS       localhost.
      
      ; which subdomains map to which address...
      my.site.    IN    A        127.0.0.1
      *.my.site.  IN    A        127.0.0.1
      

      Add the zone file to the end of the master named configuration file in /etc/named.conf

      zone "my.site" IN {
      	type master;
      	file "my.site";
      	allow-update { none; };
      };
      

All done!

Startup named by issuing as root # /System/Library/StartupItems/BIND/BIND

Now all you have to do to add a new domain name to your configuration is create a new zone file
as for my.site earlier, add the zone to the named configuration file in /etc/named.conf
and issue a rndc reload as root have your new “Domain Name” resolve to your local
machine.

Add as many virtual hosts in Apache as you like and off you go…