Over the years, I’ve written a bunch of Perl and PHP code for my own personal use. Some of it might be useful to others, some of it might be useless. Some of it doesn’t even work. It might be educational for folks who want to learn Perl or PHP, or need examples of how to code something.
Anyway, I wanted to put it all in one place so that people could find it and use it, if it is of any use. I’ve had fun writing up this archive, because I’ve come across some code that I wrote a long time ago, when I was ignorant of better ways to do things… but interesting code nonetheless. If you do end up using any of this code, take a minute and leave a comment on this entry. I’d love to know what folks are using this stuff for.
I’ll try to keep this entry up-to-date if I add or remove any code from the archive.
Scripts that end in .phps are PHP source. They should be renamed to end in .php to run on your system. Scripts that end in .txt are (most likely) Perl source. They can be named whatever you like, but for consistency should probably be renamed to end in .pl. To view the source, click on the name of the script.
This code is distributed without any warranty or any guarantee that it will work. Unless noted, there is no documentation. I might be able to help you use it, but I make no guarantee of that, either.
***blacklist_to_modsec|http://prwdot.org/docs/blacklisttomodsec.html***: Perl script to facilitate taking rules from a master blacklist and changing them into mod_security rules. Full documentation included.
***ConsoleLog|http://prwdot.org/code/ConsoleLog.txt***: Perl script for Mac OS X to display information on who has logged in at the console.
***ApacheLogParser|http://prwdot.org/code/ApacheLogParser.txt***: Perl script that takes an Apache logfile from standard input, parses it while searching for key text, and then prints some stats. Uses the Socket Perl module.
***ImageInfo|http://prwdot.org/code/ImageInfo.txt***: Perl script that takes an image file name as an argument and dumps out any information about the image. Uses the Image::Info and Data::Dumper Perl modules.
***ParsePCS|http://prwdot.org/code/ParsePCS.txt***: Perl script that takes a SprintPCS Picture Mail notification email from standard input, parses it, grabs the media, and inserts the info into a MySQL database. May not work with the current Picture Mail format. Uses the DBI Perl module.
***LogGrabber|http://prwdot.org/code/LogGrabber.txt***: Perl script that connects to an FTP server, downloads a bunch of specified log files, and puts them in a local archive. Could easily be used as a general FTP file grabber. Uses the Net::FTP Perl module.
***RSStoIPOD|http://prwdot.org/code/RSStoIPOD.txt***: Perl script that grabs an RSS feed, downloads the items, and puts them into iPod Notes format. I never quite got this one working, but someone might be interested in seeing how I tried to do it. Uses the LWP::Simple and XML::RAI modules.
***ScreenGrabber|http://prwdot.org/code/ScreenGrabber.txt***: Perl script for Mac OS X that runs the built-in screen capture utility and saves the captured file locally.
***ViewArchive|http://prwdot.org/code/ViewArchive.txt***: Perl CGI script that I wrote to allow web-based navigation of an archive of photos. Sort of a rudimentary photo gallery script. Uses the Image::Info Perl module.
***gallerize|http://prwdot.org/code/gallerize.txt***: Perl script that takes a bunch of photos and builds a static HTML page to display them, and also builds thumbnail images. Uses the Image::Magick Perl module.
***grabem|http://prwdot.org/code/grabem.txt***: Perl script that FTPs to a host, downloads a bunch of images, and puts them into a local date-based archive. Uses the Image::Magick, Net::FTP, File::Copy, and Getopt::Std Perl modules.
***pPhoto|http://prwdot.org/code/pPhoto.txt***: Perl script that copies files from a local directory, resizes them to a suitable size for posting in a web photo gallery, uploads them to an FTP server, and then archives them to a local directory. I used to use this tool to copy files from my digital camera memory cards and upload them to my web server so that I could add them to ***Gallery|http://gallery.menalto.com/*** – until iPhoto 4 came out, and I discovered ***iPhotoToGallery|http://zwily.com/iphoto/***. Uses the Image::Magick, Net::FTP, File::Copy, and Getopt::Std Perl modules.
***pcsblog (PHP)|http://prwdot.org/code/pcsblog.phps***: PHP script to display a ‘blog’ of photos taken on a SprintPCS Vision Picture Phone. Works with the ParsePCS script noted earlier. Uses PHP’s built-in MySQL database connectivity.
***pcsblog (Perl)|http://prwdot.org/code/pcsblog.txt***: Basically the Perl version of the above script. Uses the DBI and CGI Perl modules.
***sitechecker|http://prwdot.org/code/sitechecker.txt***: Perl script that takes a MacMall stock number as an argument, goes to the MacMall site, screen scrapes to get the price and number in stock, and then writes a report to a local HTML file. Used at one point via cron to monitor the availability and pricing of certain items. Probably needs to be updated to work with current MacMall website. Uses the LWP::Simple Perl module.
***thumbnail|http://prwdot.org/code/thumbnail.txt***: Perl script that takes the name of an image file as an argument, and creates a thumbnail file for that image. Uses the Image::Magick Perl module.
***urltest|http://prwdot.org/code/urltest.txt***: Perl script that checks the response time of one or more websites over a specified number of samples, and writes out data on the average response times. Uses the Time::HiRes and LWP::Simple Perl modules.
***analyze_tables|http://prwdot.org/code/analyze_tables.txt***: Perl script that takes the name of a MySQL database as an argument, and runs analyze/optimize commands on each table in that database. Uses the DBI Perl module.
***modsecauditlogparse|http://prwdot.org/code/modsecauditlogparse.txt***: Perl script that parses a mod_security audit log file and prints out some info on the types of things that have been blocked.
***spamhauschecker|http://prwdot.org/code/spamhauschecker.txt***: Perl script that checks whether a given IP address is listed on Spamhaus. Uses the Net::DNS::Resolver Perl module.
***tag_glue|http://prwdot.org/code/tag_glue.txt***: Perl MovableType Plugin that ‘glues’ together the contents of a given tag. Useful for joining Technorati tags together.
***PhotoManip|http://prwdot.org/code/PhotoManip.txt***: Perl script that takes a list of images from standard input, and performs some manipulations on them. Uses the Image::Magick Perl module.
***PhotoRatio|http://prwdot.org/code/PhotoRatio.txt***: Perl script that takes a base directory with a number of ‘album’ subdirectories, and calculates the average file size for files in that directory. Useful for telling if some photo albums are more bloated than others.
***blacklist_update|http://prwdot.org/code/blacklist_update.txt***: This is a good one. Perl script that actually simulates logging into a Movable Type installation, going to MT-Blacklist, and running a manual blacklist update. This was written for an old version of MT, and an old version of MT-Blacklist, and before I knew how to actually use MT and MTBL’s built-in modules. But it’s a good example of how to use WWW::Mechanize to perform automated, command-line browsing.