Raam Dev’s Weblog

Avatar

Life is a train which can easily, and probably does quite frequently, jump the tracks. Our paths are about as defined and predicable as ripples from a line drawn in the waves of a turbulent ocean.

HOWTO: Exclude songs when shuffling iTunes

I have a bunch of audio books and other non-music files in my iTunes library. When I set iTunes to shuffle through the songs in my library it naturally ends up playing one of those non-music files, causing me to stop whatever I’m doing and advance iTunes to the next song (using my iPhone remote, ha!).

When I realized how common a problem this must be for people, I looked around the settings in iTunes for a solution. Sure enough, you can tell iTunes to skip a file when shuffling! Just select the file (or group of files), right click, and choose Get Info -> Options -> Skip when shuffling.

Switching to suPHP; What a Mess!

When one of my users reported problems deleting files he had uploaded using a PHP script, I quickly discovered all the files being uploaded were owned by the user running the web server: nobody. This meant only the root user could delete those files.

Apache suEXEC is commonly used to resolve this problem. It allows Apache to run as the user who owns the domain being accessed. This way, files created by PHP would be owned by the user owning the site instead of the default nobody user.

However, Apache suEXEC only works if you’re using CGI as the PHP handler. The PHP5 handler on my server was set to use CGI, but I have PHP4 configured as the default PHP version and it was configured to use DSO. When I tried changing PHP4 to use CGI as the handler, most of the domains on my server displayed this:

Warning: Unexpected character in input: ‘’ (ASCII=15) state=1 in /usr/local/cpanel/cgi-sys/php4 on line 772
Warning: Unexpected character in input: ‘ in /usr/local/cpanel/cgi-sys/php4 on line 772
Warning: Unexpected character in input: ‘ in /usr/local/cpanel/cgi-sys/php4 on line 772
Warning: Unexpected character in input: ‘ in /usr/local/cpanel/cgi-sys/php4 on line 772
Parse error: syntax error, unexpected T_STRING in /usr/local/cpanel/cgi-sys/php4 on line 772

OK, that looks like a problem with cPanel. I don’t have time to debug cPanel’s problems.

suPHP, like suEXEC, is used to run Apache as the user who owns the domain. I decided to try recompiling Apache and PHP with suPHP enabled to see if that would fix the problem.

File Ownership Hell

suPHP worked, except now the sites using PHP sessions were trying to access stored session data in /tmp/ that was owned by the user nobody! So I deleted all the session data and that allowed the PHP sites to create new session data with file ownership of the user owning the domain.

But then I tried accessing my WordPress admin page and started getting permission denied errors in /wp-content/cache/. Same problem: the cache files that had been created before I enabled suPHP were owned by the user nobody and now the user who owns my domain couldn’t access them. A quick chown -R raamdev:raamdev /wp-content/cache/ fixed that problem.

Yeah, I could simply chown -R [user]:[user] /home/[user] for each of the users on the server, but there’s something about running a recursive command on files I’ve never seen, and know nothing about, that makes me uncomfortable.

More suPHP Limitations

I was beginning to worry that this was going to be more difficult than simply enabling suPHP and I wondered how many other sites I’m hosting could have similar problems. I tried accessing one of the high priority sites I’m hosting and discovered it was broken and displaying an “Internal Server Error”.

After a little research, I discovered that you cannot use php_value directives in .htaccess files with suPHP. The .htaccess file included with (created by?) Joomla! contained this at the bottom:

#Fix Register Globals
php_flag register_globals off

I already knew register_globals was turned off in the global PHP configuration, so I simply commented out that line and the site started working again.

Conclusion

It was at this point that I concluded it was too risky to just blindly enable suPHP while hosting over 50 domains, many of which I am not at all familiar with what’s being used or hosted. I will need to take the time to carefully crawl through all the sites making sure their .htaccess files don’t contain anything that might disrupt suPHP and then confirm all the sites are still working properly.

Lesson learned: Setup suPHP before you’re hosting 50+ domains.

Accessing the VMWare Fusion BIOS

As noted in the Known Issues section of the VMWare Fusion Release Notes, the VMWare Fusion BIOS goes by way too fast to give you a chance to access it. The only way you can access it is by modifying the .vmx configuration file for the VM:

The VMware Fusion BIOS posts too quickly to access.

Most users will not need to access the BIOS, but advanced users might want to do so, to change the boot order, set a boot password, or enable a second floppy drive. To work around this problem, use a text editor to add the following line to the configuration (.vmx) file of the virtual machine:

bios.forceSetupOnce = "TRUE"

The next time you boot up the virtual machine, it will automatically boot into the BIOS. This configuration option then reverts to FALSE. You must set the option to TRUE each time you want to boot the virtual machine into the BIOS.

Unable to connect using Sprint U727 on Leopard - FIXED

After so many hours trying to fix the damn U727 USB Sprint card, I finally have it working again. It was working fine up until about a week ago when it mysteriously stopped working. I was getting all kinds of messages, including “Unable to connect” and several seemingly useless messages in /var/log/ppp.log: “Connect script failed”, “LCP: timeout sending Config-Requests”, “CCLExit: -6021 (No carrier.)”, and “CCLExit: -6019 (Modem error, modem not responding.)”.

I finally came across this post that included a list of steps which billio discovered fixed the problem for him. I am re-posting his steps here (I hope he doesn’t mind):

1. Remove the Novatel USB device.

2. Download the latest driver package for Mac OS X from Sprint. It says it is for Tiger (10.4) but it seems to work.

3. Delete (sudo rm -rf) all the Novatel files from /System/Library/Extentions. Reboot.

4. Run the mpkg installer for the Sprint drivers.

5. Reboot.

6. Open Network Preferences; plug in the Novatel device; click “+” and add “Novatel CDMA” device.

7. Click “Advanced” button. Change vendor to Novatel and Model to CDMA.

8. Click “Connect” and it works.

And I couldn’t believe it, but that actually worked! (I’m writing this post using the Sprint card right now.) You can find the Sprint drivers here (select MAC OS from the drop down and download the Sprint SmartView software).

Problems Starting and Stopping MAMP in Leopard

First of all, I love MAMP (Apache, MySQL, and PHP for Mac). I use it on a regular basis for web development and it has been extremely useful since I started working on a Mac platform about a year ago. After upgrading to Mac OS X 10.5 (Leopard), I discovered MAMP would sometimes have problems starting and stopping. The MAMP widget and control panel would both say that Apache and MySQL are running, when in fact they were not.

MAMP App
MAMP Widget

When attempting to stop the services, MAMP would show the progress meter for a few seconds and then do nothing (the lights stayed green). This was quite annoying to say the least.

Apparently this is a known bug. But don’t fear, there is a solution! Click the Preferences button on the MAMP control panel, then click OK. MAMP will do some reinitializing and then all is well again. You’re also able to start/stop MAMP from the widget.

The latest version available is 1.7.1 and it was released on 08-13-2007, almost a full year ago! I suppose that’s what you can expect from a free version of their main product, MAMP Pro ($60), but slow bug fixes to their free version certainly wouldn’t make me feel good paying money for MAMP Pro.

Typing on Non-Editable PDFs

Have you ever wished you could fill out non-editable PDF forms on the computer, instead of being forced to print and fill them out by hand (while trying to squeeze the information into incredibly small areas)? Some PDF forms are designed with editable fields to allow you to fill them out from the computer, however many of the forms are simply in PDF format to make it easier for you to print and fill out by hand. Take this form for example:

If you’ve come across this problem before and looked for a solution, you may have discovered that many solutions require you to buy some PDF editing software. There is, however, a free solution which allows you to type text anywhere, on any PDF.

FoxIt Reader is a great lightweight Windows PDF reader. It launches extremely fast, so there is no more waiting 10 minutes for Acrobat to load when you accidentally click on a link to a PDF file. The only catch to this free solution is that you cannot save the edited PDF without FoxIt Reader adding an evaluation mark to it. However you can print the edited PDF without any evaluation marks, which is perfect if you’re just filling out a form to mail or fax somewhere.

After you download and install FoxIt Reader, open the PDF you want to edit. From the menu, choose Tools -> Commenting Tools -> Typewriter Tool or simply press Alt+8. This should open a nice font tool bar and allow you to place text anywhere on your PDF!

One thing I discovered is that it’s a lot easier to create the line of text near where its supposed to go and then move the text box into position. Trying to get the Typewriter cursor to start in the correct spot is very time consuming. When you’re done filling out the form, simply choose File -> Print and the PDF will print with your changes.

I use this solution a lot to fill out forms that I would otherwise need to fill out by hand. Not only does it make the form look more professional, but it also reduces the likelihood of the processor misspelling your name or reading your address incorrectly.

An Extension for Reordering the Thunderbird Account List

I have several email accounts setup in Thunderbird (an awesome and open-source email client) and occasionally I want to reorder the accounts listed on the left folder pane. The way I’ve been doing this up until now is by modifying the prefs.js file located in my Thunderbird profile directory. There is a line that looks like this:

user_pref("mail.accountmanager.accounts", "account4,account1,account3,account2");

By simply reordering the accounts listed there, I can change the order of the accounts listed in Thunderbird. However, there are a few problems with this method. You cannot have Thunderbird open while you’re editing the prefs.js file and the accounts don’t have any kind of description associated with them, so figuring out which is which can be quite annoying. If you’re lucky enough to be on a Unix-based system you can solve this using the grep command:


eris:~/Library/Thunderbird/Profiles/wlkj31iv.default raam$ grep -w "mail.server.server[0-9].name” prefs.js
user_pref(”mail.server.server1.name”, “Local Folders”);
user_pref(”mail.server.server2.name”, “Raam Dev”);
user_pref(”mail.server.server3.name”, “Akmai.net Support”);
user_pref(”mail.server.server4.name”, “Akmai.net Admin”);

But why should we have to go through all this trouble? I’m really surprised the Thunderbird developers haven’t added a feature that allows you to reorder the accounts, but then maybe they’re wondering why someone hasn’t written an extension to do it. :) Well thanks to chuonthis, we have exactly that.

If you’re using Thunderbird, you can download the Folderpane Thunderbird extension and try it out. I’ve tested it on both Windows and OS X and it works great! No more editing configuration files to change something in the UI!

Subversion on Mac OS X

My workplace is switching from CVS to Subversion for source-code version control so I need to pick up Subversion rather quickly. It took me awhile to get comfortable developing with CVS and now I need to learn stuff all over again. I even have scripts setup to help with the deployment of my project using CVS — now they need to be modified to work with Subversion. Oh well, I’m sure its for the best.

I’ve been reading the awesome, and free, Subversion book a lot lately and it has really helped with my understanding of how Subversion works. Since Subversion is not installed on OS X by default, we need to install it before using it from the command line. I downloaded the easy-to-install Subversion .dmg distributed by Martin Ott.

After running the .pkg-installer I was able to run svn help from the command line to confirm it was installed properly. If that command doesn’t work after installing, you may need to add this line to the .profile file (in your home directory):

export PATH=$PATH:/usr/local/bin

Now you should be able to run all the SVN commands from your Mac OS X command line. If you prefer a GUI interface to SVN, check out svnX. I do all my development from within Eclipse, so I’m using an SVN plugin for Eclipse called Subversive. I prefer it over the more commonly known Subeclipse plugin because Subversive has a friendlier, and seemingly more configurable, interface.

Checking out a project from the command line over SSH is really simple, however while searching Google I was unable to find this “simple” answer. If I had found the free Subversion book before searching for this answer, I probably wouldn’t be writing this:


svn checkout svn+ssh://svn.dev82.org/projects/myproject

That’s it! The syntax for checking out a project is very similar to CVS, however SVN has the concept of “URLs” to specify the location and type of connection to your repository. If you have SSH Client Keys setup, you can run SVN commands over SSH without the password prompt (which is necessary for the deployment scripts I use).

slGrid: Edit Mode without Add or Delete

I’ve been customizing slGrid for an application I’m developing at work. One of the things I needed to do was to enable the MODE_EDIT but at the same time prevent additions or deletions.

To prevent deletions, there is an option in /classes/gridclass.php called $editmode_delete, which you can simply set to false to prevent deletions and remove the ‘Delete’ column. However, this creates another problem: While editing a row, the ‘Delete’ button and the ‘Cancel’ button share the same column:

So by disabling deletions, we’re giving up our ‘Cancel’ button. This means the only way to get out of edit mode after clicking the ‘Edit’ button, is to refresh the page. OK, so thats not the end of the world. Lets continue.

Our next problem is insertions — we need to prevent users from adding new rows. I saw the $editmode_add option in /classes/gridclass.php, and assumed it would be as simple as changing it to false. But to my surprise, that only removed the ‘Add’ button, leaving the entire (empty) insertion row at the top of the table:

Well that doesn’t make any sense. If there is an option to disable insertions, why leave the unused empty row? After lots of digging I finally found the block of code that needs to be commented/removed to prevent the empty row from loading:

gridclass.php:

						if ($this->mode == MODE_EDIT)
			{
				$insert_row = array();
				$row_index = -1;

				foreach ($this->columns as $column)
					$insert_row[$column->name] = "";

				$this->CreateRow($insert_row, $row_index, $visible_row_index, $table_main);
				$row_index++;
			}

After commenting out that block of code, I finally have what I want; slGrid in Edit Mode without the ability to Add or Delete:

I’m going to be working with slGrid a lot now and I’ll be tweaking/customizing it quite a bit. I will be sure to share everything I learn here on my blog for others who may wish to use it.

Installing the Eclipse SQL Explorer Plugin on Mac OS X

There is a great plugin for Eclipse called SQL Explorer, which “is a thin SQL client that allows you to query and browse any JDBC compliant database”. I have a local LAMP (or in this case, MAMP) environment setup on my Mac for development purposes. Up until now I have been using phpMyAdmin through an external web browser to view/edit the MySQL database (Eclipse’s built-in web browser sucks — I cannot even copy/paste from it!). Since I do everything else from within Eclipse, moving outside the Eclipse window just to view tables/data in the database really interrupts my work-flow (not to mention the distractions that come with using a web browser ;) ).

SQL Explorer is really nice, once you get it working. I assumed it would be as simple as downloading the plugin and creating the connection to my local MySQL database — but that didn’t work. You can download and manually install the plugin, but choose to use the built-in Eclipse Install and Update functionality to download and install the plugin. Here is how it’s done:

  Download and Install Eclipse SQL Explorer Plugin


1. From within Eclipse, choose 'Help -> Software Updates -> Find and Install' from the menus

2. Choose the 'Search for new features to install' option and click Next

3. Click 'New Remote Site', enter 'SQL Explorer' in the Name field and 'http://eclipsesql.sourceforge.net/' in the URL field and then click OK

4. You should now see 'SQL Explorer' in the list of 'Sites to include in search'. Uncheck everything except 'SQL Explorer' and click Finish

5. A new screen should open which allows you to select 'SQL Explorer'. After selecting it, click Next

The SQL Explorer plugin should now be installed and available as a new perspective. You can start using it by selecting it in the Open Perspective list (Window -> Open Perspective -> Other...). Once you have opened the SQL Explorer, you will need to add a new connection. In the Connections tab, click the ‘New Connection Profile’ icon or right click anywhere inside the empty list and choose it. This will open the ‘Create New Connection Profile’ window.

This is where there is no documentation explaining what is really needed to connect to a MySQL database. You would think it would be as simple as selecting the MySQL Driver from the list, entering your database connection information and saving the connection. But upon doing this, I received the following error:

I don’t know about you, but I have definitely seen more informative error messages than com.mysql.jdbc.Driver. After a little research, I discovered that we actually need to install the MySQL JDBC driver before using SQL Explorer to connect to a MySQL database. I didn’t see this information anywhere in the SQL Explorer documentation or on the website. The fact that the Create New Connection window shows me a huge list of database drivers to choose from is very misleading!

Before we add the new driver, we need to download the MySQL JDBC Connector. You will want to copy the mysql-connector-java-5.0.8-bin.jar file somewhere permanent, since the new driver we create will look for for this file whenever we connect to a MySQL database.

  Download Connector and Create MySQL JDBC Driver


1. Download the MySQL JDBC Connector, extract and save the mysql-connector-java-5.0.8-bin.jar file some place permanent (I stored it in my /Applications/Eclipse/ directory)

2. Open the 'Create New Connection Profile' window in SQL Explorer, click the New Driver button

3. On the 'Create New Driver' screen fill in the Name field with something like 'MySQL JDBC Driver'

4. In the Example URL field fill in the following: jdbc:mysql://[<:3306>]/

5. Click the Extra Class Path button

6. Click Add and then select the mysql-connector-java-5.0.8-bin.jar file you downloaded

7. Click the List Drivers button. This should automatically fill in the Driver Class Name field at the bottom with 'com.mysql.jdbc.Driver'

At this point, you should have a window that looks like this:

Click the OK button. This will bring you back to the 'Create New Connection Profile' window. Now you should be able to select your new 'MySQL JDBC Driver' from the list of drivers, fill in the URL field with something like ‘jdbc:mysql://localhost:3306/test_database‘, and enter your MySQL Username and Password details (if you’re using MAMP, the defaults are root/root). Click OK and then double click on the new connection in the Connections list. Assuming your MySQL database is running and the connection details are correct, you should see the Database Structure tab populate and allow you to view the contents of your database.

For those who might want to know exactly what versions of software I am using, here is the list:

Mac OS X 10.4.10 on a MacBook Pro
Eclipse 3.2.2
SQL Explorer plugin 3.0.0.2006
MySQL JDBC Connector 5.0.8

I’ve only started to explore the possibilities of what can be done with SQL Explorer, but I can already tell it will make my development process much smoother. I was surprised that there wasn’t more readily available documentation explaining how to do what I have explained here, but hopefully someone will find this mini-tutorial useful.

Link Action plugin for slGrid

There was recently a plugin system added to slGrid, which is great because I recently found the need for a plugin that creates a link around specific cell content and decided to write one.

Link Action allows you to create a URL around the contents of a cell using the unique database column ID. It also allows you to pass the target page for the URL and optional URL arguments. If no target page is passed, it defaults to the current page calling the grid.

<?php
/*
 * Example usage:
 * $_SESSION["grid"]->SetPlugin("Full_Name", "link_action", array("target" => "users.php", "extra_args" => "&action=edit"));
 *
 * Assuming the database column ID is 24, and the Full_Name is Raam Dev, here is what the cell would contain:
 * <a href='users.php?id=24&action=edit'>Raam Dev</a>
 */

require_once('class.plugin.php');

class link_action_Plugin extends Grid_Plugin
{

	function introspect()
	{
		return(array(
			"name" 			=> "Link Action",
			"description" 	=> "Creates a URL to call an action using the unique database column ID",
			"author"		=> "Raam Dev <raam.m.dev (at) gmail (dot) com>",
			"version"		=> "1.0"
			));
	}

	function generateContent($cell, $args)
	{
		if(empty($args["target"])){
			$args["target"] = $PHP_SELF;
		}
		if(empty($args["extra_args"])){
			$args["extra_args"] = "";
		}
		return("<a href='".$args["target"]."?id=".$args["id"]."".$args["extra_args"]."'>$cell</a>");
	}
}
?>

slGrid, Ajax-Based PHP Grid Component

I found an absolutely awesome application called slGrid. It was recently bought by Senza Limiti, a technology consulting company based in Slovakia. They’ve since made slGrid an open-source application, which is very cool. It uses AJAX and PHP to provide an interface for creating grids by loading content directly from a database. You specify the table and fields, and it takes care of the rest. Check out the slGrid demo to get a better idea of what it does.

Using slGrid is literally as easy as this:


<?php
	$_SESSION["grid"]->SetDatabaseConnection("database_name", "user_name", "password");
	$_SESSION["grid"]->SetSqlSelect('field1, field2', 'table');
	$_SESSION["grid"]->SetUniqueDatabaseColumn("id_field", false);
	$_SESSION["grid"]->SetTitleName("slGrid");

	$_SESSION["grid"]->PrintGrid(MODE_VIEW);
?>