Wednesday, May 9, 2012

Fixing the Postfix Envelope Address

I found errors in my /var/log/syslog indicating undelivered email because my MTA didn't recognize the envelope addresses. The Postfix address rewriting readme provided a simple solution: use /etc/postfix/generic to rewrite those "bad" addresses to something acceptable. I did that. But, then I realized that I would need to "build" generic into generic.db (and restart postfix) before I could be sure the rewrites would take effect. A search brought me to a page on Postfix Makefiles; it had more information than I needed, but it did provide the important command. Running sudo postmap generic from /etc/postfix rebuilt my generic.db.

Tuesday, March 20, 2012

Partitioning a new 2 Terrabyte disk

To make sure it will be a while before we have to revisit my wife's backup strategy, I bought a 2TB drive and installed it in my machine to serve as a Samba network drive for her backups. The physical install didn't present any nontrivial problems.

I ran into the first puzzle when I booted-up the machine for the first time. After selecting the default boot kernel via grub I got an error message indicating a missing partition table or some such. Ack! Did I somehow damage my primary drive while installing the new one? Then, I realized---the order used by grub might have changed. I edited the boot commands, changing "hd1" to "hd0". Viola! Back to normal.

After booting-up, I ran fdisk /dev/sdb. I created a single primary partition for the entire disk, but then got a strange warning message:

Partition 1 does not start on physical sector boundary.

A Google search indicated that I might need to start at 8 or 64 or some such. But, when I tried that, I got the same warning. Some more searching led me to an IBM article on Linux on 4KB-sector disks. After finding the fdisk section, I followed their advice to turn off DOS compatibility ('c') and change display units ('u'); when I again tried creating the partition, the warning disappeared.

Note: If I had been more observant, I would have noticed that fdisk told me about the 'c' and 'u' options when it started-up. Doh!

Note: I needed the disk UUID in order to make a proper /etc/fstab entry. The easiest way I found to get this is to run

ls -la /dev/disk/by-uuid/
Each UUID is linked to its corresponding device.

Note: I was slightly upset that only 1.7T of the 1.8T was available immediately after formatting. I learned that this was probably due to the 5% reserved for system use. I lowered this to 2% using the following command:

sudo tune2fs -m 2 /dev/sdb1

Sunday, March 18, 2012

Setting up Samba for Windows Backup

Until recently, my wife has been a happy Mozy customer. She didn't mind paying for the 50 gig plan because she runs a website and blog for her business and needs a reliable backup solution that she doesn't have to worry about. About a month ago, she got a notification that Mozy hadn't performed a backup for 7 days because she exceeded her quota. This was the first time she had ever hit the 50 gig limit. She opted to pay for an extra 20 gig quota, thinking it would last quite a while. A month later, she got the notice again about being out of quota. Then, she realized, videos take up a lot of space! I helped her start looking at other backup options---paying for an additional 20 gigs of space every month did not seem like a good plan to either of us.

After looking into various options, I realized that the best one might be free---using backup software on her machine to save her data to a samba share on my Ubuntu box. I followed the Ubuntu instructions for setting up a Samba file server. Here are two notes that would have saved me a lot of time:

  • Try using a workgroup name of "WORKGROUP" unless you have explicitly changed it on the Windows machine. I saw mentions of "HOMEGROUP" on my wife's Vista box and tried that first, but the real workgroup name was "WORKGROUP".
  • To access the shared drive, enter "\\machinename". If there is a "Run" option in your Start menu, enter it there. For Vista, I entered this into a Start menu "Search files and programs" search box.

I then went searching for Windows backup software. I found and tried Cobian backup. After much fiddling and reading, I learned that "backup" software is not what I was looking for---I wanted software to (efficiently) keep a current replica of my wifes files. Cobian could only do this by running a "full" backup each run. I wanted the functionality of "rsync" which apparently is known as "file synchronization". Next, I discovered GoodSync which seemed to have the right functionality. One annoying part is that it required my wife's Windows account to have a password in order to set up an automatic sync. Easy enough. At this point, I had the desired automatic file synchronization functionality as long as I had the "guest ok = yes" setting for the samba share.

Next, I wanted to require authentication for the samba share. I followed the "Security = user" instructions provided by Ubuntu, but then found that I could authenticate with my Ubuntu account, but not the one I had set up for my wife. Next, I created an samba user/password for my wife with smbpasswd. I could access the share, but GoodSync was giving me strage errors every time a automatic backup tried to run. Finally, I realized my wife's account didn't have permission to write to the share. I learned of the "admin users" samba option and added my wife's Ubuntu account to the list of admin users for the share. Finally, the automatic file sync worked without issue.

P.S. At some point, I tried mapping the samba share to a Windows drive letter (e.g. "Z:"). But, that didn't help and only created more confusing error messages. In fact, GoodSync had no trouble using the "\\machinemame" notation to reference the samba share.

Tuesday, July 26, 2011

How to Create a Web-Based Video Converter

My wife teaches cooking classes near Boston and blogs about food. Recently, she's become interested in video. She's already made a few videos using Windows Movie Maker (WMM), like this one on how to dice an onion. But, she's finding that free movie editing software just doesn't cut it. The kicker was when she published a video, learned that the volume was too low and couldn't find any way to raise the volume in WMM---it only allows limited volume adjustment.

She had already started researching video software options and settled on Sony Vegas. Yes, people complain that it crashes and/or runs slowly, but those same people are trying to process relatively large movies. My wife is looking to publish 5 minute non-HD videos on YouTube. So far, Sony Vegas has worked well for her. The one problem she's encountered is that Sony Vegas can't import Flip Video AVI files. She found a free Windows-based converter. But, it leaves a blatant watermark and screwed-up a half-second of the audio track.

I figured this would be an easy problem to solve with Linux software. Sure enough, a bit of searching and I discovered ffmpeg, which is available in Debian. After a few minutes of man-page reading, I had a command-line to perform the conversion:

ffmpeg -i myvideo.avi -target ntsc-vcd myvideo.mpg
Note that this generates NTSC video. If you're in Europe, you might want PAL, which you'd get by changing the target to pal-vcd.

But, this wouldn't cut it. My wife didn't want to have to copy to Linux, convert, then copy back or wait for me to get home just so she could start editing a video. So, I set to work on creating a web-based converter. Creating a script to upload the video is straightforward and easy to find. Here's an example of file upload HTML and PHP. But, what this page doesn't tell you about are the hard limits PHP has on file and memory sizes. Here is a PHP "bug" which describes the max file size ("exceeds the limit of 8388608 bytes") problem I quickly encountered. Sniper provides the config settings that need to be edited:

post_max_size = 256M
upload_max_filesize = 256M
memory_limit = 256M
I modified these settings in /etc/php5/apache2/php.ini, restarted my web server, and then was able to upload video files larger than 8 megs. The final question was how to push the converted video back to my wife's web browser. For some reason, all the pages I found on how to upload a file didn't mention anything about the possibility of pushing binary data back to the user. Finally, I stumbled upon the PHP readfile function. Occasionally, PHP is nice in that it provides tools and examples for what you probably want to do, like push an entire file to a user's web browser. The readfile manual page provides a full example for how to do this, including the necessary HTTP headers and proper output buffer management.

Here's what I ended-up with. Note that this script is unsafe due to the fact that it executes a shell command. Also, it relies on /tmp being the usual "temp" directory and can fail if a file already exists with the name $outfile. But, it serves it's purpose for me.

<?php
if ($_FILES["video"]["name"]) {
  $pattern = '/(.+)\.avi$/i';
  $replacement = '${1}.mpg';
  $outfile = preg_replace($pattern, $replacement, basename($_FILES["video"]["name"]));
  $cmd = "ffmpeg -i " . $_FILES["video"]["tmp_name"] . " -target ntsc-vcd " . $outfile;
  chdir("/tmp");
  shell_exec($cmd);
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename=' . $outfile);
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($outfile));
  ob_clean();
  flush();
  readfile($outfile);
  unlink($outfile);
  exit;
} else {
?>
<html>
<body>
<form enctype="multipart/form-data" action="video.php" method="POST">
Choose a file to upload: <input name="video" type="file" /><br />
<input type="submit" value="Upload Video" />
</form>
</body>
<?php
}
?>

Tuesday, July 19, 2011

How to Create a GMail Filter Based on Reply-To

Today, I found myself trying to filter a message in Gmail based on the "Reply-to:" header. "Reply-to:" was the only user-friendly header that clearly distinguished it from other types of messages I receive. I knew that Gmail allows list-based filtering using a "list:" prefix in the "Has the words:" field. But, I haven't found a resource to tell you what, if any, other prefixes are allowed. I tried "reply-to:" without success. Then, I searched and found another poor soul with the same dilema. A bit more futzing and I discovered that "replyto:" was the correct prefix. Unfortunately, the Google help forum won't let me post a reply (!) So, I am hoping that romadatnvwisp will read this post and learn how easy it is to filter based on the "Reply-to:" header. Maybe he's figured it out himself?

To recap... lets say you want to filter messages with a Reply-to: address of "me@sample.com". Here's how you do it:

  1. Click the gear icon in the upper-right-hand-corner of Gmail, then select "Mail settings"
  2. Click the "filters" tab, scroll to the bottom and click "Create a new filter"
  3. Type "replyto:me@sample.com" in the "Has the words" field
  4. Click "Next Step" and finish creating the filter; note that matching messages should appear below after clicking "Next Step"

Sunday, July 10, 2011

How to Add Share Buttons in Blogger

Google has redesigned the Blogger administration interface.  As a result, the instructions posted by Blogger a month ago on how to add the "+1" button are no longer valid.  "Design >  Page Elements" no longer exists.  Instead, you need to click "Layout" then click the tiny "Edit" link at the bottom right-hand corner of the "Blog Posts" box.  This will give you a list of post option.  Make sure the "Show Share Buttons" checkbox is checked, then scroll to the bottom and hit "Save".

Didn't work?  That's expected if your blogger has existed for a while (more than 1 year?).  Fortunately, this Blogger Templates post on how to add share buttons describes how to hack it (scroll down).  This trick worked nicely for all but one of the blogs I administer.  Unfortunately, for my wife's Beyond Salmon blog which was created six years ago, it only sort-of worked---the buttons came out very small and the "+1" button didn't appear (even after I moused over the other share buttons, which was the only way "+1" would appear on some other blogs).  Bleh.

Friday, July 1, 2011

I Want My Old Google Calendar Back!

My wife woke up this morning to discover that her Google Calendar had been transformed via Google's effort to evolve the Google design and experience.  I fail to see how this effort is a good idea.  The result is that my wife can see fewer events on her "Month" calendar (which is the primary view she uses).  She used to be able to see six events per day.  Now she can see four and she has to click the "more" link to see all events on a day with 5 or 6 events.  It seems that this is due to wasted space.  There is more padding/spacing around everything, including day-of-the-week names and date numbers.  What's the point of spreading-out everything in the display if it distances you from useful information without improving usability?  I'm at a loss.  Fortunately, it's easy to revert to the old UI---click the gear icon in the upper-right-hand-corner, then select "Use the classic look".

Disclosure: I joined Google via the ITA Software acquisition and have no involvement in the above-discussed UI redesign.

Update 7/4/11: Apparently, I'm not the only one who thinks the Google Calendar redesign is a bad idea.