Settin up a custom Weave Sync Server for Firefox 4

 

Introduction

Starting with Firefox 4 it is really easy to keep your different Firefox browser setups at home, on your mobile or at work in sync. The Mozilla Corporation even hosts a central server for you so basically the setup can’t be more easy.

Yet, if you’re a little paranoid and you don’t want to store your precious browser data on someoneelse’s servers, you might wish for your own sync server. There are two posibilities to setup your own server: the Weave Minial Server and the full blown one.

Weave Minimal Server’s development has been stopped now and is deprecated since shortly after FF4’s relase. Therefore, this article documents the setup of the full server.

The chosen install location will be /var/www/weave. The article assumes a Mysql server for authentication installed locally. Further, a functional Apache 2 server is assumed with a fully configured SSL setup. The documentation was tested using an Ubuntu 10.10 setup.

Package Retrieval and Storage

A working installation of a full Weave server consists of of two packages: the Weave Sync Server and the Weave Registration Server. You may download and unpack the archives like this:

mkdir -p /var/www/weave/weave-synchronisation \
         /var/www/weave/weave-registration 
cd /var/www/weave && touch index.html
   wget http://hg.mozilla.org/services/sync-server/archive/tip.tar.gz
   tar xzf tip.tar.gz -C weave-synchronisation --strip=1 && rm tip.tar.gz
   wget http://hg.mozilla.org/services/reg-server/archive/tip.tar.gz
   tar xzf tip.tar.gz -C weave-registration --strip=1 && rm tip.tar.gz

In case the download links are deprecated, go and look for the according packages at their respective root directories: http://hg.mozilla.org/services/sync-server/ and http://hg.mozilla.org/services/reg-server/.

Note as of Oct 29, 2011: the links are deprecated as the whole sync-server gets an overhaul. The old version is still running smooth though, so the updated links are: http://hg.mozilla.org/services/deprecated/sync-server/ and http://hg.mozilla.org/services/deprecated/reg-server/.

Database Setup

Create a new database called weave containing the following tables:

CREATE TABLE `collections` (
  `userid` int(11) NOT NULL,
  `collectionid` smallint(6) NOT NULL,
  `name` varchar(32) NOT NULL,
  PRIMARY KEY  (`userid`,`collectionid`),
  KEY `nameindex` (`userid`,`name`)
) ENGINE=InnoDB;
CREATE TABLE `wbo` (
  `username` int(11) NOT NULL,
  `collection` smallint(6) NOT NULL default '0',
  `id` varbinary(64) NOT NULL default '',
  `parentid` varbinary(64) default NULL,
  `predecessorid` varbinary(64) default NULL,
  `sortindex` int(11) default NULL,
  `modified` bigint(20) default NULL,
  `payload` longtext,
  `payload_size` int(11) default NULL,
  `ttl` int(11) default '2100000000',
  PRIMARY KEY  (`username`,`collection`,`id`),
  KEY `parentindex` (`username`,`collection`,`parentid`),
  KEY `modified` (`username`,`collection`,`modified`),
  KEY `weightindex` (`username`,`collection`,`sortindex`),
  KEY `predecessorindex` (`username`,`collection`,`predecessorid`),
  KEY `size_index` (`username`,`payload_size`)
) ENGINE=InnoDB;
create table users (
 id int(11) NOT NULL PRIMARY KEY auto_increment,
 username varchar(32),
 password_hash varbinary(128),
 email varbinary(64),
 status tinyint(4) default '1',
 alert text,
 reset varbinary(32) default null,
 reset_expiration datetime
) engine=InnoDB;

Now, create a user named weave in mysql with data permissions on the newly created Weave database. Remember the user’s password for later.

Config Adjustments on Sync and Reg Server

To customise the configs of reg and sync portion of the full Weave server, two files have to be created before being edited:

cd /var/www/weave/weave-synchronisation/1.1 && \
   cp default_constants.php.dist default_constants.php
cd /var/www/weave/weave-registration/1.0 && \
   cp weave_user_constants.php.dist weave_user_constants.php
Adjustment of the Synchronisation Server

Now, edit /var/www/weave/weave-synchronisation/1.1/default_constants.php. First, adjust the mysql user’s database password according to the previous step. Chanve weave to your own password there in the two line that say:

if (!defined('WEAVE_MYSQL_STORE_READ_PASS')) { define('WEAVE_MYSQL_STORE_READ_PASS', 'weave'); }

Next, adjust the size of maximum payload in the following line. I recommend just adding a zero to 262144:

if (!defined('WEAVE_PAYLOAD_MAX_SIZE')) { define('WEAVE_PAYLOAD_MAX_SIZE', 262144); } #256K

Now, uncomment the following line and insert a random character string where its supposed to:

#if (!defined('WEAVE_SHA_SALT')) { define('WEAVE_SHA_SALT', 'salt goes here'); }

You might also want to adjust the default quota from 5 MB to maybe 20 MB. Uncomment this line and adjust it:

#if (!defined('WEAVE_QUOTA')) { define('WEAVE_QUOTA', 5120000); } #5M
Adjustment of the Registration Server

The configuration file for the registration server is located at /var/www/weave/weave-registration/1.0/weave_user_constants.php. The following lines need to be customised. First, insert the mysql password by replacing the string weave:

if (!defined('WEAVE_MYSQL_AUTH_PASS')) { define('WEAVE_MYSQL_AUTH_PASS', 'weave'); }

Next, uncomment the salt line as before and insert the same character string as before for the sync server:

#if (!defined('WEAVE_SHA_SALT')) { define('WEAVE_SHA_SALT', 'salt goes here'); }

If you like to have user registration protected by captcha (I assume you do), get an account at http://recaptcha.net/ and get yourself a global key. Adjust the following three line to suit your needs:

#if (!defined('WEAVE_REGISTER_USE_CAPTCHA')) { define('WEAVE_REGISTER_USE_CAPTCHA', 0); }
#if (!defined('RECAPTCHA_PUBLIC_KEY')) { define('RECAPTCHA_PUBLIC_KEY', '6LfWcwUAAAAAABnmLyhmgddYeJGdiRlo2MWSOpAl'); }
#if (!defined('RECAPTCHA_PRIVATE_KEY')) { define('RECAPTCHA_PRIVATE_KEY', '6LfWcwUAAAAAAHpjpBNSaxwLVQXQIG-S0Y6IG38O '); }

Apache2 Setup

This article assumes that you have your Apache 2 webserver SSL-secured and that you want the Weave server to be located at https://yourdomain.tld/weave/. Therefore, the following lines need to be inserted into your Apache 2 config (in Ubuntu that is /etc/apache2/sites-enabled/default-ssl):

# ----- weave-server -----------------------------------------------------------------
<Directory "/var/www/weave/">
  Options Indexes FollowSymLinks
  AllowOverride none
  Order allow,deny
  Allow from all
</Directory>

Alias /weave/1.0 /var/www/weave/weave-synchronisation/1.1/index.php
Alias /weave/1.1 /var/www/weave/weave-synchronisation/1.1/index.php
Alias /weave/1.2 /var/www/weave/weave-synchronisation/1.1/index.php

Alias /weave/user/1.0 /var/www/weave/weave-registration/1.0/index.php
Alias /weave/user/1 /var/www/weave/weave-registration/1.0/index.php
Alias /weave/user /var/www/weave/weave-registration/1.0/index.php
Alias /weave/misc/1.0/captcha_html /var/www/weave/weave-registration/1.0/captcha.php
Alias /weave/misc/1/captcha_html /var/www/weave/weave-registration/1.0/captcha.php

Alias /weave /var/www/weave
# ----- /weave-server ----------------------------------------------------------------

Run

service apache2 reload

to make the changes work.

Client Setup

To use your brand new Weave server in your shiny Firefox 4, choose Set Up Sync... from the Tools menu. There, you will need to create a new account and enter your server address (https://yourdomain.tld/weave/) in the server field after choosing the use of a custom server over Firefox Sync Server.

Leave a comment ?

16 Comments.

  1. Nice work ! Thx.

    The registration works fine for me, but I’ve got an authentification error when I launch the synchronisation … the “WEAVE_SHA_SALT” is the same for the sync packages and the registration packages.

    • Thanks for your comment.

      Indeed, you need to give reg and sync server the same salt, that’s why I wrote to use the same salt. I rewrote that part now in order to be more precise. Thanks for the input!

      /Dirk

  2. Thanks for your reply. Even if I put the same salt in the configurations files, Sync still say “Sync encountered an error while connecting: Incorrect account name or passoword” after i have completed the registration (my user account is well created in the database)

    • Hm,

      that’s odd. Maybe try to disable the captcha registration verifier. That’s often a point of failure due to quite complex configuration.

      /Dirk

      • I finally read what I was copy and pasting and saw that the apache2 config was pointing to /var/www/weave/weave-syncronisation/ instead of /var/www/weave/weave-synchronisation/ Once I fixed that, my firefox syncs with my Ubuntu 10.04.2 LTS server without errrors.

        Thank you for this write up.

        • Thanks to you, too. You realised my error nearly in sync with kevin. Funny incident reagarding a sync issue ;)

  3. mkdir -p /var/www/weave/weave-synchronisation \ /var/www/weave/weave-registration

    Should be

    mkdir -p /var/www/weave/weave-weave-syncronisation \ /var/www/weave/weave-registration

    • Thanks for the hint on that typo. Yet, the typo was in the apache-config where I wrote “syncronisation” instead of “synchronisation”. I suppose that’s what you meant.

      /Dirk

  4. I am new to MySQL. I can’t grant the privilege ‘data’ to the database. I tried usage but that seemed too restrictive. Can you be more specific as to the necessary permissions?

    Great guide. It only took me a short time to get things rolling.

    • Do you get any error message as to why you can’t give ‘data’ privileges to the db? It could help to know if the mysql-users you are using for creation of the new db just suffers from too many restrictions.

      Regards Dirk

      • I granted all privileges to user weave in order to get things working. It seems like too much. I got SQL errors when I tried to grant the ‘data’ privilege. If there is a better solution, please post the necessary SQL command.

        Thank you for your quick response. Everything seems to be working according to plan.

  5. I added these two lines in the Apache 2 config:

    Alias /weave/weave-registration-static /var/www/weave/weave-registration/1.0/static Alias /weave/weave-password-reset /var/www/weave/weave-registration/1.0/forgot_password.php

    before the line

    Alias /weave /var/www/weave

    This was in order to enable password reset functionality. I lifted this from a few other sites. That did the trick :)

  6. Thank you very much for this article. Working perfect for me on Ubuntu Server 10.4.

  7. These 2 downloads are showing in the hg listings as deprecated – I think due to http://tobyelliott.wordpress.com/2011/07/12/so-long-php-and-thanks-for-all-the-fish/ this.

  8. I have followed step by step in this tutorial, everything is describe, how to install and configure own Firefox Sync Server (Weave) with MySQL. http://terminal28.com/how-to-install-and-configure-own-firefox-sync-server-weave-debian/

Leave a Comment