Tiplet: monitor realtime web site traffic on a Linux server with tmux and tail

I run a VPS which has numerous sites on it. Whilst I was trying to pin down the root cause of sporadic hard lockups and runaway memory usage, I settled on a somewhat inefficient (yet very handy) line of code which I run inside a tmux session over a PuTTY SSH connection (two other panes run iftop and watch --interval=0.1 iostat -m for realtime disk I/O).

An aside: tmux is like screen on speed, way more extensible and SO MUCH EASIER TO USE, I highly recommend you give it a try if you're a commandline warrior. There's some highly useful tutorials to help you get up to speed - google "tmux tutorial", Hawk Host's two-parter has some good stuff in it.

To accomplish this I'm taking advantage of the fact that DirectAdmin (which by default provides a base of Apache 2, MySQL and PHP 5) stores its httpd access logs in a common folder: /var/log/httpd/domains/<virtualhost>.log</a>. I'm combining the tail command with grep's egrep functionality (grep -e) and some pattern matching. It's not perfect: I have to occasionally Ctrl+C and restart the command as it stalls out, but it does everything I need.

Full command and my somewhat explanatory breakdown after the jump

Tiplet: one-click Lock Screen for OS X

It must be in the name... Chris Cook devised an excellent little (Automator-based) scriptlet, self-contained as an .app Obviously (obviously, natch) if you hit Command-Option-Q for Quick User Switch - which is one HELL of a difficult keyboard combo if you can't get your thumb to do the double keypress - plus it will close all open apps and processes and physically end your login session.

Chris Cook's Lock Screen app works great - and still works with 10.5.8 on the MBP1,1 I use at work. Give it a try if you dislike leaving your Mac unlocked whilst you go do other srs bsns.

(I'm also aware that there's umpteen other ways to both lock a workstation and accomplish Fast User Switching without mousing to the option; look here (StackExchange), here (MacWorld) and here (MacWorld again) for starters.

Tiplet: disabling TinyMCE's mangling of YouTube embed code

I've been hacking an install of phpns to make it work a little more neatly with my company's web site (which is a real Frankensite and in BAD need of a rip-and-replace).

Anyway, if you use phpns - or any CMS which uses TinyMCE for WYSIWYG text entry / editing - you'll find that if you embed code like YouTube links in code view, switch back to WYSIWYG view, then switch back to code view again... All your lovely embed codes are gone!

This was really annoying me, so I decided to have a hunt about for a quick 'n dirty solution. After lots of forum reading, a few things were clear:

  • TinyMCE won't let you easily disable its code cleaning / HTML verification, which sucks
  • Even the TinyMCE devs aren't quite sure how to efficiently stop this from happening
  • Trying to fully disable its HTML verification / cleanup routines is nigh-on impossible, the codebase is a spider's web of PHP
  • and by default, it hates all <object> and <embed> tags, even if you have the TinyMCE Flash plugin installed.

This can royally screw with your meticulously-entered YouTube embeds. However, on his blog, Akbar neatly demonstrates a simple but effective method to stop TinyMCE eating your embed code - and all you need to do is add the object and embed tags and possible variables... There's a full demo, with borrowable code, on his web site.

Tiplet: Recovering a 'ghost' domain in DirectAdmin

I added a domain name to an account on one of my DirectAdmin-managed servers yesterday, and when I came to tweak some of its settings a few hours later it had mysteriously disappeared from the domains list in the control panel! (I think this was due to a dirty restart of the core DirectAdmin program, but I'm still not 100% sure). What was strange was that all the files (private and public_html) were still there if I FTPed in, the domain still resolved and loaded if I typed in its URL into a browser - but I couldn't access the control panel settings for it (so no email, no MySQL management etc). A crippled domain.

Even more frustratingly, attempting to rename/delete the domain's folder via FTP or SSH didn't work, and I couldn't re-add the domain to the account as DirectAdmin could (bizarrely) still see that it was already hosting it! Moving/deleting the domain's DNS zone file didn't work, and neither did a DirectAdmin restart. So, Catch 22... What to do? Continue reading "Tiplet: Recovering a 'ghost' domain in DirectAdmin"