Thursday, March 20, 2008

DD-WRT Firmware on Buffalo WHR-G54S

I've had the Buffalo WHR-G54S router for about a year, but tonight I decided to install the popular third-party firmware DD-WRT.  I knew the router was compatible with DD-WRT when I purchased it (that was part of the reason I selected it).  I highly recommend the WHR-G54S; it has worked well for as long as I've had it.

Actually, it hasn't performed flawlessly.  In fact, I've been having problems since my new roommate moved in.  He likes to P2P when he's not here (which is usually when I'm here and want to use the bandwidth).  Tonight when I got home, my computer was having major connectivity issues.  Even after stopping his downloads, the problems continued.  I had to power-cycle my cable modem and router just to get a simple page to load.  Before rebooting it, even the web-configuration tools on the router couldn't load (so the issues were in the router?!?)  That's why after a year, I decided to give DD-WRT a shot.  Hopefully it will improve my connection (or contain tools to shape the P2P traffic/give me priority)!

I just wanted to give some pointers that helped me through the process:

  • As this article points out, dd-wrt.[version]_mini_generic.bin is the firmware file you want to use when first flashing from Buffalo's factory firmware.  That means you want to download dd-wrt.[version]_mini.zip from the DD-WRT Downloads Area.  At the time of writing, the latest stable version was 2.3_SP2.
  • The DD-WRT Wiki Installation Page was very helpful, especially the Precautions and Buffalo > TFTP Flashing Buffalo Routers under Windows sections.  I followed the instructions from the latter and successfully flashed the router on the second try. (the first try, I jumped the gun when the red light came on; when you see the first ping as the router comes back up hit enter immediately, I only got one successful ping during the TFTP window the first time around)
  • My reset button is labeled "init" and sits on butt end of the router, next to the "bridge" switch and directly opposite the antenna jack.  You will need something thin like a paperclip to press it.
  • When unplugging and re-plugging my router, I used the router (DC power) end of the power cable, since this was easier to do with the router sitting on the desk next to my keyboard.  I unplugged everything else except a singe Ethernet cable from my computer.
  • My Ethernet port (nForce 4 built-in) is auto-sensing, but came back well before the TFTP ping.

The installation went so smoothly, I'm wondering why I waited this long to try DD-WRT.  The answer is, "If it ain't broke, don't fix it!"  Hopefully I'll have more to say when I've had a chance to play with some of the firmware's more advanced settings.  I can say that even the "mini" version has all of the features I used in the original Buffalo firmware.  Unfortunately I forgot to write down the port-forwarding settings I had for serving HL2:Deathmatch and Synergy internet games.  Oh well, I'm sure I can find the ports again.

The dream app?  Setting up a Cron job that pipes fortune to net send on the hour.  Imagine - every computer on the network (or maybe just your roommate's) gets a dialog box with a fortune every hour, courtesy of your local router and DD-WRT.  Priceless.

Monday, March 17, 2008

Email2Trac on Windows

See the official Email2Trac documentation for an up to date version of these instructions.


If you're not familiar with Trac: Trac is an integrated issue tracking system, wiki, and SVN repository browser. It is open source software (under the very liberal BSD licence), and is popular as a public bug tracker for many open source projects. Email2Trac is a plugin (actually, more of a script) for Trac that enables users to submit bugs via email.

Email2Trac was clearly created by *nix users, but since it is written in Python, can be made to work in Windows without too much hassle. This post is a summary of a couple messages I posted to the Trac Users Group detailing our Email2Trac setup.


Platform: Windows Server 2003, Python 2.4, Trac 0.10.3, email2trac 0.10 (year+ old install)

There are 3 pieces you need to effectively turn emails into Trac tickets:

  1. A way to receive emails on your Trac server
  2. A way to process or convert emails into Trac tickets (this would be the email2trac python script)
  3. A way to automate part 2

Here's what we use on Windows:

Receiving Emails via SMTP

We use Windows' built-in SMTP server to deliver mail to our Trac server. When I setup email2trac, I thought that this step was going to be the most difficult (mostly because I have no experience with email servers/services). Surprisingly, it is actually the easiest step. The trick is to install the SMTP server, but not the POP server, so that emails are received and left as files in the "drop" folder. (This is the way an email server hands off email between the two services) In a way, email2trac performs the distribution functions normally handled by POP.

Install the SMTP service via Windows Components.

  1. Open Add/Remove Programs (Start > Control Panel > Add or Remove Programs)
  2. Click "Add/Remove Windows Components" in the left-hand bar.
  3. Use the "Details..." button to drill-in to Application Server > Internet Information Services (IIS) > SMTP Service. In Windows XP, it's just Internet Information Services (IIS) > SMTP Service.
  4. Check the box next to SMTP Service, click "OK", "OK", "Next", "Finish".

At this point, you should ensure that the SMTP Service is running (on my workstation it didn't start after installation; this may be a policy issue).

  1. Open up the Services dialog at Start > Control Panel > Admistrative Tools >Services.
  2. Scroll down to "Simple Mail Transfer Protocol (SMTP).
  3. If startup type is not "Automatic", double-click the service. Change "Startup Type" to "Automatic". Click "OK".
  4. If status is not "started", click play button in services dialog toolbar to start the service.

The SMTP service should be configured and ready to receive emails out of the box. You can find SMTP settings at Start > Control Panel > Admistrative Tools >Internet Information Services (IIS) Manager. The installation automatically creates the default domain "Local (Default)" and the corresponding drop folder at C:\Inetpub\mailroot\Drop. You can see that my email2trac batch script picks up .eml files from that location.

To actually receive emails on the server, you have to send to an address of the form "anything@trac-server.domain.com". Your Exchange or other mail server should automatically forward the emails to your Trac server. If you want to use a different address, you will likely have to configure your mail server to forward the mail. The name before the @ can be anything; POP service usually uses this to distribute mail to inboxes, SMTP and email2trac ignore it. A possible enhancement to email2trac would be to use the local-part of the address to identify the destination environment for the ticket. You will probably want to give out a single address, just to keep things consistent; since it is our Help Desk's Trac, we use "helpdesk@trac-server.domain.com".

Alternative Way to Receive Emails

If the server that hosts Trac already handles emails (thus the SMTP domain "trac-server.domain.com" is taken), you will need a different method to receive emails. Instead of using SMTP, you can setup an email box/address for Trac on your existing email system, and use a POP client to retrieve and save emails to a folder. Said POP client could be run in the same batch file used to automate Email2Trac as described below (or replace the Email2Trac call If the POP client can run scripts directly).

Fetchmail is an email client that can be setup in this way with Exchange. See this post for details (Thanks, Nicole). This article details installing Cygwin/Fetchmail on Windows.

Setting Up Email2Trac

The Email2Trac script isn't very Windows-friendly out of the box. I didn't so much install it, as I ripped the main Python files out of the source tarball. Python code doesn't need to be compiled, so this works fine.

  1. Extract email2trac.tar.gz (I use 7zip)
  2. Navigate into the resulting email2trac-0.x folder and rename:
    email2trac.py.in   to email2trac.py   and
    delete_spam.py.in to delete_spam.py
  3. Copy email2trac.py, delete_spam.py, and email2trac.conf to the location where you want to run the script (I put mine in C:\python24\scripts)

For Email2Trac 0.10, I had to alter the script slightly to run. Edit email2trac.py with your favorite editor (I use IDLE, which comes with the Windows Python package).

Comment out the syslog import (line 95 in 0.10); change:

import syslog

to

#import syslog

Note: It looks like this is fixed in Email2Trac 0.13

Next change the name of the default config file (line 984 in 0.10); change:

configfile = '@email2trac_conf@'

to

configfile = 'email2trac.conf'

Depending on how you call the Email2Trac script, you might need to specify a fully-qualified path to your config file. (Thanks Nicole) Use something like this instead:

configfile = 'C:\python24\scripts\email2trac.conf'

Note: You can also specify the config file when calling the script using this switch: -f [config file] or --file=[config file] This may be an easier/cleaner solution than changing the default in the script. I haven't tested this option.

Next, you'll want to edit email2trac.conf. Be sure to configure your environment with Windows-style paths, and specify the temp directory, which is used to extract attachments. Also, make sure the temp directory exists. The top of mine looks like this:

[DEFAULT]
project: C:\trac\project1
tmpdir: C:\temp
...

Note: We only use email2trac with one environment on our server (despite the fact we run several). There is no easy way (that I know of) to use multiple environments with the current version of the Email2Trac script in this setup.

If you are running Trac 0.11, you will also need to add the following under your [DEFAULT] section: (Thanks Nicole)

trac_version: 0.11

You will likely want to make more changes to the config file to suit your needs. See the Email2Trac documentation for details.

At this point, you should be able to push a single email into a ticket from the command-line. Type:

cd C:\python24\Scripts
python email2trac.py < C:\path\to\email.eml

Note: Change paths above based where you saved email2trac and where your emails are dropped. Also depends on Python being in your PATH; add C:\python24 (or your python root) to your PATH, or replace python with C:\python24\python.exe in the above.

Automating Email2Trac

We use Windows' Scheduled Tasks to automate email2trac. This works in two parts: a batch file to run the script on a set of emails and a scheduled task to run said batch file at regular intervals.

Create a new batch file in the same folder as your email2trac.py, something like C:\python24\Scripts\trac-email.bat. Edit it with notepad and insert the following:

@echo off

for %%f in (C:\Inetpub\mailroot\Drop\*.eml) do python email2trac.py < %%f
del C:\Inetpub\mailroot\Drop\*.eml

Note: Change the path C:\Inetpub\mailroot\Drop\ to the location where your emails are dropped, and change *.eml, if they have different extensions. Same PATH caveats as above.

Now create the Scheduled Task:

  1. Start the Scheduled Task Wizard(Start > Control Panel > Scheduled Tasks > Add Scheduled Task). Click "Next >".
  2. Use "Browse..." to select the batch file you just created as the program you wish to run.
  3. Give the task a name, select "Daily". Click "Next >".
  4. Set "Start time:" to 12:00 AM, "Perform this task:" to "Every Day", "Start date:" to current date. Click "Next >".
  5. Enter a user. I had problems running the task as the unprivileged user that runs tracd, so I set myself as the user (definitely not as secure, but our Trac is on our local intranet). Click "Next >".
  6. Check "Open advanced properties..." and click "Finish". The edit task dialog will pop up.
  7. Click "Schedule" tab, then "Advanced...".
  8. Check "Repeat task", set "Every:" to 10 minutes (or your desired interval). Set "Duration:" to 24 hours.
  9. Click "OK", "OK" to close the dialogs.

You can now test your task by right-clicking it and selecting "Run". You should see a command-line window briefly appear. Check that the emails are gone and new tickets have been created in your Trac.


Disclaimer: I am not an expert on email, nor do I have much Python experience. This documentation was written up months after I setup Email2Trac, but should be fairly complete.

Wednesday, March 5, 2008

"Rounders+ Green"

I just finished making the majority of template changes to this blog.  After working with the Blogger template system, I'm satisfied that it will continue to meet my needs, because it is so flexible.

I call my new template "Rounders+ Green".  It is a mutation (or intelligent design change, if you prefer) of the Rounders 2 theme here on Blogger.

  • I expanded the width by 200px from around 800px to around 1000px.  (I would call this "optimized for 1024x768")
  • This broke the rounded corners, so I came up with a (arguably better) way to do rounded corners, using 6 stacked <div>s.  The bottom div provides the properly sized rectangle of the chosen theme color.  The next four <div>s each add a corner "mask" image, rounding off the bottom <div>'s shape.  The final <div> sets up padding for the internal layout of that particular section.  All 6 <div>s occupy the same space; after the first, each fills the entirety of the parent.  All of the layout is done in CSS, using background-color and background:url.  This approach could probably be reduced to 4 <div>s by placing two of the corners with the bottom and top <div>s.
  • I added icons for RSS and tags, using CSS of course.
  • I added formatting to the blog footer, to better match the header.
  • I aligned all of the left-side text (at least on the front page).  (This was mostly done already)
  • I fixed the post-header-line-1 section, which lacked any formatting.  I decided to float it right, and moved it before the post title, so that it would occupy space within the title block.
  • I added <pre> tag formatting for any code blocks that I insert.  This may need to be expanded, depending on what I post.  (A command-line style might be nice)

I'd like to publish the template, but first I have to figure out if I can "attach" items (like the xml file) to a post.  If not, I'll likely use my Google Pages site, or Sky Drive.


There are a few things left to be done with the template.  This list is mostly just a reminder for me.

  • Look at cleaning up the comments section on the individual post pages.  Create icons for the comments section header, and the add comment link.  (Word-bubble and plus, 12x12 on rounded orange)
  • Add tags icon to listing on left.  Maybe re-think use of orange for this icon.
  • Add icon for archive section, if seems missing after adding tags icon.
  • Move all images to my google pages site, to make things more uniform.
  • Use new corner technique for all rounded sections.
  • I'd still really like to attempt a stretch version of the template for bigger/smaller screens.
  • Try to add syntaxhighlighter to the mix.  (See this post for details)

Saturday, March 1, 2008

Sticking With Blogger (Update)

Moving Away From Blogger


Less than 24 hours in, and I'm already not liking Blogger. I'm sure it's useful for most people, but the lack of code support made my first "real" post a pain. Also, I couldn't find any themes I really liked. After posting that code, I realized how skinny that main column is. I figure I should find the right tool NOW before I have too many posts that may be hard to migrate.

I'd like to try WordPress, since I have some experience with the software from a web languages course I took in college. I notice they offer free hosting as well.


Update: I tried Wordpress. Not useful. I'm a bit of a control freak; I like to be able to control the layout of my blog. With Wordpress, you have to pay to customize.

Looking again at the customization options for Blogger, I think I'll give it another go.  And I mostly like the Rounders template I picked.  The fact that it is optimized for 800x600 was it's major drawback, but now that I see that I can easily customize it, not a problem.  Same goes with code formatting; I used a Blogger code-format tool to generate ugly chunks of HTML/CSS around each piece of code.  I should be able to roll that formatting into my template CSS, and get by with a simple <pre><code></code></pre>

I've already done some tweaking to the template; with just a little modification, it's now "optimized" for 1024x768.  I'd really like to change it to "stretch" or fill up the horizontal space available.  I think with a little work, that should be possible.  I'm hoping to recycle the original Rounders corner images, so I don't have to host my own... we'll see how that goes.