Although this is technically a blog, it's primary content is a series of articles on how to get Firefox working in a corporate Windows environment. Later ones build on earlier ones, so you might want to use the Table of Contents on the right to read through it chronologically instead of reading straight down from here.

AutoConfiguring XMarks for the Logged In User (v3.6)

(These are the instructions for Firefox 3.6 and XMarks BYOS 1.0.  If you want the newest instructions, go here.)

This is what it's all been leading up to.  This is what I started this blog for, because I couldn't find anyone else online who accomplished it.

So let's back up.  I wanted to roll out Firefox as the default browser in my organization.  So that means pushing it out via Active Directory so I can keep it updated.  If I just installed a plain vanilla copy on my image it would quickly go out of date.

However, I also want people's important settings to follow them from computer to computer.  I consider bookmarks to be in that category.  You can do this with roaming profiles, but after seeing how slow this was on someone else's setup I've been determined to avoid that.

You can redirect Internet Explorer's Favorites folder by changing two registry keys with a login script:
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Favorites
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites
But Firefox doesn't have something similar, which has held it back until now.  There's a bookmark syncing extension called XMarks, and you can even sync to a private server, but I don't want people to have to configure it themselves.  They're not going to remember the settings if I use a private server, and most aren't going to bother setting up an XMarks account if I don't.  Plus I've found it's always, always worth the extra effort to have things Just Work™.  It's a better experience for them, and it saves you trouble in the long run.  So here we go.

Set up a WebDAV Server

You need a server for XMarks to sync to, and it supports both WebDAV and FTP.  They recommend WebDAV so that's what we're using.

I have a Windows Server 2003 machine I can add it to, so the rest of the instructions in this section are for IIS 6.  You can use Apache or whatever else you want but you're on your own.  This page might help though.

Add IIS and WebDAV to the server if they're not already installed.  Go to Control Panel > Add or Remove Programs > Add/Remove Windows Components > Application Server > Internet Information Services (IIS) > World Wide Web Service and check off Word Wide Web Service and WebDAV Publishing.

Now go to Administrative Tools > Internet Information Services (IIS) Manager, find your web site (Default Web Site or one you created if you already had it installed) and go into its Properties.

I personally changed the TCP port to 8082 and made a DNS alias "FirefoxBookmarks" to the server so I can move it around if need be, but that's not required.

Go to the Home Directory tab and make sure Read and Write are checked off.  You also want to go to the folder it shows under Local Path and make sure Everyone has read and write NTFS permissions on them (right click the folder in Explorer > Properties > Security.)

Go to the HTTP Headers tab and click MIME Types.  Add .json as text/css.

You should be all set on this part.  Make sure syncing works with a manually installed and configured copy of XMarks BYOS before continuing.

Pushing Out the Configuration

Hey, remember the script from this post?  Yeah, go get that.  Change the webDAVURL variable to point to the server you just set up.  You can run it manually on your own computer until you're sure it's working correctly, but when you roll this out you want it to be a login script in Active Directory.

These are the settings it creates for you in user.js:
  • extensions.xmarksbyos.syncOnShutdownAsk = false
    Remember how I like things to Just Work™?  Well part of that is not risking the server's copy going out of date so they're wondering where their new bookmarks are, so I force the shutdown sync.  It only takes a second or two, and this way they don't have an unnecessary popup asking them about it either.
  • extensions.xmarksbyos.url-bookmarks = "[webDAVURL]/[username]-bookmarks.json"
    This is where their bookmarks are going to be saved.
  • extensions.xmarksbyos.url-passwords = "[webDAVURL]/[username]-passwords.json"
    This is where their passwords will be saved if they set it up.  I didn't bother trying to make it happen automatically.
  • extensions.xmarksbyos.username = "[username]"
    Don't know if it's strictly necessary, but we want XMarks to think it's fully configured so it doesn't open the setup window.
We still have the little problem of the password.  It isn't stored in user.js so we can't push it out that way.  It isn't required by WebDAV so we don't even need it, but XMarks thinks it does and will pop up the setup window without it.  Grr.

So it's time to hack XMarks.

Editing XMarks BYOS

So if you haven't caught on by now, this is all based on XMarks BYOS, a stripped down version of XMarks that lets you use your own server and doesn't have the extra fluff like ratings that I didn't want anyway.  Go get the XPI and unpack it as described in this article.  Use those instructions to check install.rdf too since it might have the maxVersion issue described there.

We need to make two edits.  The first is in chrome\content\foxmarks-settings.js.  Find "get passwordNoPrompt()" and add "return "ignore";" as the first line so it looks like this:

This makes XMarks think it always has a password.  Now it thinks it's fully configured and won't pop up a settings dialog, but thanks to some quirk in the code (or lets be honest, our hacking, since I'm not hugely familiar with XMarks' internals) it won't actually start syncing automatically.  If you perform a manual sync it will succeed and then start syncing on its own, but it won't start on it's own without that kick start.

So we have another edit to make.  In chrome\content\foxmarks-statusbar.js find "function StatusBarLoad()" and add "foxmarks.synchronize(true);" right before the return statement so it looks like this:

Now when the status bar widget loads, it will force a background sync (not the pop-up window kind.)  This successfully kick starts the process and it will now sync automatically on its own.  As a bonus it forces it to happen as soon as Firefox is opened, which is nice if someone's on a different computer as they don't have to wait for their bookmarks to show up.

(Why StatusBarLoad()?  I could force a sync in a number of places but it was always the one that pops up the syncing window.  I was looking at the status bar code while trying to examine the background sync mechanism and managed to do this.  And when you get something that works you stop looking, right?  So status bar code it is, just because it works.)

So now with those two changes, plus the change to install.rdf if you needed it, you can now package and push out your edited copy of XMarks BYOS as an MSI using the rest of the instructions here.

Hey, couldn't I have just done all this for you and let you download the pre-hacked MSI?  No.  XMarks BYOS isn't open source as far as I know, so I can't redistribute it.  I can just give you instructions on how to do it yourself.

That's It!

So now you're where I am.  You can push out Firefox, Flash, and XMarks BYOS via Active Directory.  Also PlainOldFavorites or any other extensions you want to add.  XMarks will autoconfig thanks to our generated user.js and a couple of code hacks.  Everything will sync to our internal WebDAV server, and everything will be transparent to the end user.  No configuration or pop-ups, they just get their bookmarks on any computer automatically.  It took a lot of effort (I had to figure all this out, you just had to read it!) but it's always beautiful when something Just Works™.

Where to from here?  Well in my organization I haven't actually made Firefox the default browser yet.  That's going to come as part of the reimaging I'll be doing very soon.  However I did push out this entire system ahead of time so the people who were already using Firefox would have their bookmarks all synced up and safe beforehand.  No issues so far.

As we transition to Firefox being the default browser and spend some time living with it I'll post any other issues and workarounds I come across.  I didn't find anything else like this on the web so this is my contribution to helping people use Firefox at work.

No comments:

Post a Comment