Archive for the ‘Howto’ Category

jQuery snippet:

Thursday, July 12th, 2007

Here is a neat jQuery snippet that you can use to create extra elements in a form, underneath (mostly) the previous element. Took longer than it should have to create this since I didn’t quite understand the behavior of “before” and “after”… ie, a parent node has to exist for them to work.

<input name="field[]" type="text" /> <a href="#" onclick="$(this). before('<br/>'). before($(this). prev(). prev(). clone()); return false;" href="" >+</a>

This snippet works especially well inside of a table. 🙂 Unfortunately, I don’t have a demo of the code since I don’t have jQuery enabled on this blog.. yet. 🙂

LOLCat Creator Generator

Friday, July 6th, 2007

For those of you who have used my LOLCat Generator script, you would be happy to know that I’ve improved it slightly — now using it on images that have white backgrounds works decently. Things the LOLCat Creator can do:

  • Put a caption in any of the corners, with wordwrap
  • Generate from any one of the few random cat pictures I have on the site
  • Generate from any URL of an image that you give it

A lot of people have been using it, and there are some pretty amusing pictures that have been generated. I’ll have to post the best ones. 🙂

LOLCat Generator Page

Samba over an SSH proxy

Sunday, June 17th, 2007

I’m at Boys State for the fifth year in a row as a staff member where I serve as the webmaster/technical support person. Its always a lot of fun here at MSU, especially with the gigabit ethernet that I have access to… simply awesome.

Anyways, I needed to do some development on my server at home, and really.. my favorite editing tool for PHP is Notepad++, hands down. So, I found this link that tells you how to setup a SSH tunnel that lets you connect to a samba server on the remote server. Pretty neat idea.. it tells you to install a virtual network adapter that you can do your port forwarding to. Anyways, heres the link:

How to get remote SSH shell access on some servers running PHP

Saturday, June 2nd, 2007

I was trying to do an XML dump with MediaWiki for a friend, and the tools MediaWiki provides to do it requires shell access — which my friend does not have in his hosting package. So I tried using phpshell, but got annoyed that it would freeze anytime I executed something that required user input. After much thought, I devised a way to create an SSH shell using PHP (sorta) that I could use. Heres how you can do it too.

The Concept:

PHP can (usually) execute arbitrary executable files on the server that it resides on. If the executable forks, then it can open other programs or connect to remote resources, without hanging the PHP connection. I’ve written a program that does this, and executes a statement that connects to a remote SSH server, creates a tunnel to it, and opens a shell on that tunnel so that a user on the remote SSH server can connect to that port and use the shell. The statement looks like this:

netcat -l -p 20000 -s -e "/bin/bash -i" | ssh -NR 20001:localhost:20000 username@hostname -o "StrictHostKeyChecking false" -i key_file_name

You can connect to this shell by doing a

netcat localhost 20001

on the remote SSH server. You need to setup an SSH key on both servers so that the authentication doesn’t ask you for a password at all (see below). Of course, if those programs don’t exist on the remote server then this wont work (however, I have included a compiled version of gnu-netcat with the program that you can use).

The Usage:

This code works, but is still mostly a ‘proof of concept’.


  • You must be able to upload files to the server and ensure they are executable (though, the software tries to set the executable bits if it is not the case)
  • You must be either able to compile files in a executable format that the server can execute, or you must be able to compile files on the server itself (in which case, you probably don’t need this program!).
  • The user that the webserver (or the php CGI script) is running as must be able to write to a file
  • You need an accessible SSH server setup somewhere that you can add user accounts to
  • Forwarding must be enabled (default: yes)
  • Public key authentication must be enabled (default: yes)
  • It needs to have netcat installed
  • I used Linux to set this up


Awstats and logfiles

Monday, May 21st, 2007

I use for my web hosting, and they provide raw dumps of the apache logs for the website. Which is great, because you can do whatever analysis on them and it works nicely.. except for two things:

  • They don’t use a standard LogFormat directive
  • After about 6 weeks, the oldest log files get deleted

So, after much trial and error, I figured out a decent way to use Awstats to do my log analysis. I wrote a cron job that runs every monday morning (had to modify my crontab from the default), which basically downloads the latest logfile from my 1and1 account, and then runs awstats on it. It sounds pretty trivial — but 1and1 names their logfiles in the format access.log.[week].tar.gz.. which works until the year rolls over. So I added some logic in there to intelligently rename the files like access.log.[year].[week].tar.gz.

You can download the awstats 1and1 cron job here.

To use it, you need to be running Linux, and have awstats installed. You will need to modify some of the parameters of the cron script, but its decently commented. Additionally, your awstats configuration file needs to have the following two directives in it:

LogFormat= “%host %other %logname %time1 %methodurl %code %bytesd %virtualname %refererquot %uaquot %otherquot”

LogFile=”gunzip -c $(for i in `ls -rt /home/awstats/roadside/`; do echo /home/awstats/roadside/$i; done) |”

Just make sure you replace /home/awstats/roadside with the directory that you want to place your logfiles. Refer to the script for more documentation.

Note: The biggest problem I have with it is that it only updates once a week. I played with doing it every day, but then awstats tended to drop/ignore records that were out of sync, and it seemed to be better to have complete stats instead of having them updated every day. If you have a good solution for this, let me know!

Javascript/CSS enhanced Resume

Sunday, May 20th, 2007

When I was looking for research projects to participate in a few years ago, I decided the best way to find them would be by emailing various professors and sharing my interests with them. However, I figured a resume would be useful to share with them as well, and I only had it in MS word format. So I put it into HTML format.

However, the biggest problem with my resume is I tend to put a lot of stuff in my ‘master copy’ of my resume, and change it according to my targeted audience. So, by putting everything on the web, printing it out results in around 3 pages at this writing. Common resume advice always says to keep it under a page.

My solution: use javascript and CSS to create a resume that can serve multiple purposes! On the top of the resume, is a listbox that when switched, switches between a ‘full’ and ‘condensed’ version of my resume. The condensed version is designed to be printed out in only one page.

Heres how it works: (more…)

Dynamic SOCKS Proxy using PuTTY

Thursday, April 12th, 2007

 SSH is a powerful tool, and PuTTY is by far my preferred SSH client on Windows. Using SSH, you can use an SSH server as a proxy for any application that will allow you to use a SOCKS-type proxy. Of course, there are a lot of other tunnel types that SSH will allow you to do (X forwarding, remote to local, local to remote, etc), but this type of tunneling is especially useful. I’m posting this mainly because there isn’t a whole lot of documentation out there about this particular topic, and the stuff that did exist wasn’t so clear when I first started using this a few years ago. Without further ado…


Reliable Windows spyware and virus removal mini-guide

Saturday, February 24th, 2007

Someone at work asked me some advice about spyware removal, so heres some thoughts about how I remove spyware/viruses. I’ve been doing this for about 5 years, and the process I use removes all spyware/viruses about 90% of the time. Disclaimer: Use at your own risk. Don’t be stupid.

I use the following tools to scan computers, all of which can be downloaded free online. Run them in the order listed.

  • Process Explorer: (Download here) Use this to kill any processes that you don’t know what they are. Especially kill ones that don’t have a company name/description by them. You cant hurt anything by killing the wrong process, so kill away. If a process you kill causes another one to pop up, then thats definitely a bad thing, and typically is virus behavior. Usually you can kill it by “Killing Process Tree”. If that doesn’t work either, then I find that if you ‘suspend’ a process and its descendants, then you can kill it after that.
  • Autoruns: (Download here)This has an option to ‘Hide Microsoft Entries’ — use it. Deleting actual Microsoft programs is generally a bad idea, and shouldn’t be done unless you have a reason. The idea here is to kill anything (press the delete key, or uncheck it) that you don’t recognize, or something that doesn’t have a company name/description next to it. If you don’t recognize it, ask the computer owner/user whether or not they have heard of the program. If they don’t know what it is, then chances are its bad for the system. If in doubt, search for the item on google, and usually there will be some results with people saying whether it is good or not.
  • HijackThis: (Download here) This does the same thing as Autoruns, but gets stuff that it misses. Once again, kill anything that you don’t recognize. If it doesn’t list a company name, thats also a warning sign as well. Anything that is misspelled can be a warning sign (like Mircosoft instead of Microsoft, etc.. ). You could just delete everything on the list, because anything that shows up here is non-essential to your computer. However, don’t do that. Things like antivirus (which is useless anyways) and special keyboard programs will break.
  • Pocket Killbox: (Download here) This program is useful for a lot of things, but its primary usefulness if you don’t have any general needs is it can delete all tempory files. Its in one of the menu options, just select it, and run it. You’d be surprised at how many Windows bugs (especially Internet Exploiter) are caused by having too many temporary files. It also can signfically slow down your computer if you have too many of these. Pocket Killbox is useful for other things too, but chances are you’ll never use those capabilities. Just delete the temp files and you should be good.
  • WinsockFix: (Download here) If the person is having network connectivity issues, then many times WinsockFix can solve them. Just run it, and reboot. If they’re not having network issues, it generally won’t hurt if you run it anyways. Usually I don’t because then you have to wait for the system to reboot.

Well, thats my guide. If you have any questions, then post a comment or contact me and I’ll try to answer it. Good luck!