-v is for verbose, damnit

So, the vast majority of every day administrative command line utilities for Linux use -v as the switch for verbose…. when you use -v you EXPECT verbose. Well sometimes you get that one package which just CANNOT follow the rules. Someone has to think outside the box, someone has to be a unique snowflake. That someone should not be a mass process killing utility! whoever thought up that the argument -v to pkill should INVERT THE MATCH should really take a long slow look at how important being unique really is… because if you’re not aware of this, and you run something like pkill -9 -v nagios…. as root… it’s not going to do what you expect. Nothing good comes of that command.

This has been a PSA

Logging post data

Lets say you have a relatively complex php web application, like wordpress. You have it running under apache (which is common.) You have good control of your site via .htaccess (which is common — permalinks and all.) And something happens to your blog (e.g. someone is exploiting some unknown vulnerability to compromise your content), which you want to track down. So you want to log, for instance, HTTP POST data. Your first instinct might be to add some logging code to index.php (mine was) But there are a lot of possible places which might be directly accessed, especially in the admin. So The trick I use (and this is probably the only time I’ve ever condoned this) is to use PHPs auto_prepend_file functionality.

Make a /home/user/postlog/ directory, then a /home/user/postlog/logs/ directory (and chmod a+rw that one.) Next make a simple /home/user/postlog/postlog.php file with the following contents:

<?php 
if ( isset($_POST) && is_array($_POST) && count($_POST) > 0 ) { 
  $log_dir = dirname( __FILE__ ) . '/logs/'; 
  $log_name = "posts-" . $_SERVER['REMOTE_ADDR'] . "-" . date("Y-m-d-H") . ".log"; 
  $log_entry = gmdate('r') . "\t" . $_SERVER['REQUEST_URI'] . "
" . serialize($_POST) . "

"; 
  $fp=fopen( $log_dir . $log_name, 'a' ); 
  fputs($fp, $log_entry); 
  fclose($fp); } 
?>

Finally add this line to the top of your .htaccess file:

php_value auto_prepend_file /home/user/postlog/postlog.php

If all went well this should start logging any request to any php file with any post data into the /home/user/postlog/logs/ direcory (with a unique log per ip per day)

Autumn Leaves Leaf (Irc Bot) — Chanlogger

Simple, straight forward. Logs channel messages.

class Chanlogger < AutumnLeaf
 def did_receive_channel_message(sender, channel, msg)
  log_base = File::dirname(File::dirname(__FILE__)) + "/data/logs"
   subdir = log_base + "/" + Date::today.to_s[0..6]
  Dir::mkdir(subdir) if false == File::directory?(subdir)
  logfile = subdir + "/" + channel.to_s.sub('#','') + "@" + Date::today.to_s
  f = File::open(logfile, 'a')
  f.puts(Time::now.to_s + "\t" + sender.to_s + "\t" + msg.to_s)
  f.close()
 end
end

Well I’m Back

After a week (plus 2 days) vacation I’m back in thw swing of things… At least until the 20th when I take off to meet up with the gang once more.  I’ll be glad when all this traveling is done… I’m something of a simple homebody and this shuffling from one place to another makes me itchy 🙂

The vacation was OK. It rained almost constantly, was cold. The drive up was the worst, it just happened to coincide with a huge storm, and we could hardly see the road as we drove through the mountains (thank God for GPS.) There was no fence so we had to stand out in the rain to let the dogs do their business. The shops were alright, a lot of them closed for THEIR vacations (being the tourist off season.) Before we left the window in the kitchen sprung a leak just in time for a huge rainstorm. Bella went into heat (again) and had to wear a diaper the whole time. The dogs didn’t behave well (dogs neverdo when cooped up for a week solid (on top of the hormone cocktail of bella going into heat.))  We did get about 3/4 of a day on the beach in the sun towards the end.

We’ll get bella fixed as soon as shes out of heat. We would have done so earlier but for various medical complications (eye surgery, then heat, then the new cat brought ringworm to the home with it, and now heat again.)  Dont worry, we’re not planning on having our own puppies.  Not at this juncture in our lives anyway.

All said, I was relieved to finally get home where things made sense, and even if bad things were to continue plaguing us  we could deal with it in the known comforts of our own home.

Just a friendly new years eve reminder!

Keep your WP installs up to date!  You never know who might b using the holidays (and their general hustle and bustle) to cloak their activities. Often times you’ll find that bad things happen while you we’re off doing other things for a while. This is usually no coincidence 🙂

So upgrade those WP’s kiddies!

Well I made the switch to Leopard (First impressions)

First of all I did not “upgrade” I backed up (using iBackup 6.2,) then booted into the installation DVD (restart, hold C for a long time) and then entered the disk utility, formatted my disk, and installed fresh.  After rebooting and finishing my installation, I re-downloaded iBackup, and restored selected applications (and their settings,) My system settings, and my home directory.

The bad:

iBackup does not backup dot folders in the root of a backed up folder! It backed up .svn directories in my svn checkouts, but not (for example) my .ssh or .subversion folders in ~/.  For the vast majority of users this doesnt matter. but for developers and admins (I happen to be both) this is severely annoying.  Lucking I keep a backup of my .bash_profile, and my ssh rsa and dsa keys.  So all is well

The good:

I was extremely happy about a lot of things in leopard!!  First of all my delete button works now instead of entering “~” each time i hit it.  Second subversion was installed by default (yay!)  Third the builtin ssh command now supports public key authentication from ~/.ssh/ keys by default (yay!)

Thats all. My first impressions have been very good. I’m happy with the product, and these minor improvements have really made me smile. They were little annoyances, but annoyances nonetheless that hindered me every day (especially the delete key thing.)  That makes the already enjoyable OSX experience that much more enjoyable.  Haven’t had to use macports for anything yet!

colorizing php cli scripts

It’s pretty common in most scripting languages which center around the command line (bash, perl, etc) to find information on colorizing your shell script output, mainly because those languages are tied very tightly to command line use. It can be difficult, however, to find information about adding this same nice feature to a php cli script. The reason is simple: most people dont use php for cli applications; most cli programmers use something else. It’s not difficult to adapt the same techniques listed in most bash howtos (generally in the section reserved for colorizing your command prompt) for generating colored terminal output for php.

echo "\033[31mred\033[37m
";

echo "\033[32mgreen\033[37m
";

echo "\033[41;30mblack on red\033[40;37m
";

Simple, functional, useful (even if a bit complicated.) I leave it to you to lookup a bash prompt colorization howto to hunt down your own list of escape color codes (call it homework.)

Cheers