by R.I. Pienaar | Feb 23, 2005 | Code
I have a number of FreeBSD machines with jails on them that require me to keep stats and graphs of their bandwidth usage.
The solution I came up with is to add counter rules in the kernel IPFW firewall table and then plug a simple perl script into Net SNMP which will put each ipfw counter rule’s current byte count on a unique OID that you can query and graph using something Cacti.
This same technique can be used to graph things like only HTTP, SMTP, etc traffic, or infact anything that you can express as a IPFW counter rule.
Read the full entry for details on how I implemented this.
(more…)
by R.I. Pienaar | Feb 13, 2005 | Code
While configuring up my new FreeBSD 5.3 server I noticed that the rc system now supports starting up your jails using settings in /etc/rc.conf. I am not sure when this came about, I have not used FreeBSD 5.x much but I have to say it is a lot nicer than my own hacked up RC scripts.
Read on for more details about this and some other tools that is useful for jail management.
(more…)
by R.I. Pienaar | Jan 30, 2005 | Code
Posts for my photoblog are structured in a specific way. I put the image name in the entry body and the text in the extended entry. As long as I stick to that format my templates will automatically put in the right thumbnails, full size images etc.
While this is pretty simple to keep in mind and I have been doing it manually I wanted to automate things a bit. I also wanted to include some EXIF info for each image which Movable Type could not do on its own.
The solution was to write a simple blogging client in perl, read on for some details.
First off, lets cover the EXIF extraction, I found a excellent module in the FreeBSD ports system called Image::ExifTool. From its description:
ExifTool provides an extensible set of perl modules to read and write
meta information in image files. It reads EXIF, GPS, IPTC, XMP,
GeoTIFF, ICC Profile and Photoshop IRB meta information from JPEG,
TIFF, GIF, THM, CRW (Canon RAW), CR2 (Canon 1D Mk II RAW), MRW (Minolta
RAW), NEF (Nikon Electronic image Format), PEF (Pentax RAW), ORF
(Olympus RAW Format) and DNG (Digital Negative) images, as well as the
maker notes of many digital cameras by various manufacturers including
Canon, Casio, FujiFilm, Minolta/Konica-Minolta, Nikon, Olympus/Epson,
Panasonic/Leica, Pentax/Asahi, Sanyo and Sigma/Foveon. It writes EXIF,
GPS, IPTC, XMP and MakerNotes information to JPEG, TIFF, GIF, THM, CR2,
NEF, PEF and DNG files.
Using it is trivial, and you can read all the details at its CPAN Page. For me it was as simple as this:
my $exifTool = new Image::ExifTool;
$exifInfo = $exifTool->ImageInfo("$photodir/$image");
$tagDescription = $exifTool->GetDescription($tag);
%tagValue = $exifTool->GetValue($tag);
Really simple, to see for yourself what information this will find
in a image you can run the included ‘exiftool’ script, here is some
sample output:
—- ExifTool —-
ExifTool Version Number : 3.72
—- File —-
File Name : 30012005.jpg
File Size : 67KB
File Type : JPG
Image Width : 366
Image Height : 550
—- EXIF —-
Software : Adobe Photoshop CS Windows
Flash : No Flash
Exif Image Width : 366
Exif Image Length : 550
Compression : JPEG (old-style)
Thumbnail Offset : 586
Thumbnail Length : 6137
—- IPTC —-
Application Record Version : 2
—- Photoshop —-
Photoshop Thumbnail : (Binary data 6137 bytes, use -b option to extract)
—- XMP —-
Version : 2.2
Raw File Name : DSC_4995.NEF
White Balance : As Shot
Exposure : +0.85
Shadows : 5
Brightness : 50
Contrast : +25
Saturation : 0
Sharpness : 25
Luminance Smoothing : 0
Color Noise Reduction : 25
Chromatic Aberration R : 0
Chromatic Aberration B : 0
Vignette Amount : 0
Shadow Tint : 0
Red Hue : 0
Red Saturation : 0
Green Hue : 0
Green Saturation : 0
Blue Hue : 0
Blue Saturation : 0
Tv(Shutter Speed) : 1/500
Shutter Speed Value : 1/500
Av(Aperture Value) : 5.6
Aperture Value : 5.6
Exposure Program : Program AE
Shooting Date/Time : 2005:01:23 13:58:27
Exposure Compensation : -0.33
Max Aperture Value : 5.7
Metering Mode : Multi-segment
Focal Length : 125.0mm
Focal Length In 35mm Format : 187
Color Space : Unknown (4294967295)
ISO Speed : 200
Flash Fired : False
Flash Return : No return detection
Flash Mode : Unknown (0)
Flash Function : False
Flash Red Eye Mode : False
Lens : 18.0-125.0 mm f/3.3-5.6
Make : NIKON CORPORATION
Camera Model Name : NIKON D70
Orientation : Horizontal (normal)
X Resolution : 300
Y Resolution : 300
Resolution Unit : inches
Creator Tool : Adobe Photoshop CS Windows
Date/Time Of Last Modification : 2005:01:23 17:21:22
Date/Time Of Digitization : 2005:01:23 17:21:22
Metadata Date : 2005:01:23 17:21:22
Derived From Instance ID : uuid:121a03ec-6d63-11d9-bfa3-cf79758759c4
Derived From Document ID : adobe:docid:photoshop:121a03eb-6d63-11d9-bfa3-cf79758759c4
Document ID : adobe:docid:photoshop:121a03ef-6d63-11d9-bfa3-cf79758759c4
Format : image/jpeg
—- Composite —-
Av(Aperture Value) : 5.6
Image Size : 366×550
Scale Factor To 35mm Equivalent : 1.5
Tv(Shutter Speed) : 1/500
Thumbnail Image : (Binary data 6137 bytes, use -b option to extract)
Focal Length : 125.0mm (35mm equivalent: 187.0mm)
This is very impressive, you can see multiple sets of data, example
is the Exposure, I shot it at -0.33 in the camera then bumped it to
+0.85 in Photoshop CS RAW Plugin.
Now that I have a good way to extract meta data from my images the next step was to do the blog posting, this was trivial using Net::MovableType, below is a quick code snippet, read all about it at CPAN
use Net::MovableType;
my $mt = new Net::MovableType(‘http://your.com/rsd.xml’);
$mt->username(‘user’);
$mt->password(‘secret’);
$entry = {
title => “Hello World from Net::MovableType”,
description => “Look ma, no hands!”
};
$postID = $mt->newPost($entry);
$mt->publishPost($postID);
Very simple, it has many other functions, you can read, edit,
categorise etc, all the stuff you can do from the standard Movable Type
API.
(more…)
by R.I. Pienaar | Nov 1, 2004 | Code
I made version 1.1 of my Simple Photo Browser available, this release adds exif support if you have exif compiled into your php.
The white and black themes has been updated with exif support and there are some slight changes in the installation procedure. A sample of the exif support can be seen here
Download: http://www.devco.net/code/spb/spb-1.1.tgz
by R.I. Pienaar | Aug 28, 2004 | Code
I have been using a bit of code I wrote for some of the small photo albums I uploaded here and decided I will polish it up a bit and make it available for download if anyone else is interested. This is not a big system for managing 100s of photos, it is designed to be ideal for showing up to 30 or so images in a nice clean manner.
You basically untar the distribution into the directory of your choice, copy your images into the img/ subdirectory. Create a list of files to display with something as simple as “cd img ; ls > list.txt” and add individual captions for photos by editing photo.jpg.txt. More info in the README file.
It supports themes and I think it is quite easy to create your own using the two provided in the tarball as a starting point. It can also work along with mod_rewrite to make nice looking URL’s but you can configure it to work without mod_rewrite as well.
Written in PHP and only needs your basic PHP, nothing fancy. Two samples exist of installations one using the provided black theme and one using the white theme both of these samples use mod_rewrite.
Version 1.0 is available for download: http://www.devco.net/code/spb/spb-1.0.tgz
by R.I. Pienaar | Aug 13, 2004 | Code
Following from my previous post about blocking some more countries I discovered a bit of a short coming in the code I used to calculate CIDR notation from ranges of IP’s. So a bit of searching on CPAN got me Net::CIDR.
use Net::CIDR;
$range = shift;
print (join(“\n”, Net::CIDR::range2cidr(“$range”)) . “\n” );
This will take any given range of ip address in format a.b.c.d-w.x.y.z and spew out a list of subnets required to cover the whole range:
# ./range2cidr.pl 64.139.147.0-64.139.170.255
64.139.147.0/24
64.139.148.0/22
64.139.152.0/21
64.139.160.0/21
64.139.168.0/23
64.139.170.0/24
So with this I now have hopefully a more accurate set of rules that will not block bits of New Zeeland as well by accident.