As of Firefox 3, Ubuntu stores its user-editable preferences file in /etc/firefox-3.0/pref/firefox.js If you make changes to this file, they will persist even when Ubuntu updates Firefox.
Unfortunately, you can’t use lockPref in /etc/firefox-3.0/pref/firefox.js!!! If you use “pref” it works, but “lockPref” is not recognized. So if you want to lock down the preferences to keep users from being able to change them (like for proxy settings), you have to do the following.
1. Add the following to the end of /etc/firefox-3.0/pref/firefox.js:
// tell firefox to load customized config file
pref("general.config.obscure_value", 0);
pref("general.config.filename", "firefox.cfg");
2. Create a file called firefox.cfg in /etc/firefox-3.0/pref/ with the following content (the first line in both files must start with a comment):
// Lock specific preferences in Firefox so that users cannot edit them
lockPref("app.update.enabled", false);
lockPref("network.proxy.http", "127.0.0.1");
lockPref("network.proxy.http_port", 8080);
lockPref("network.proxy.type", 1);
lockPref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, 192.168.1.0/24");
lockPref("network.proxy.share_proxy_settings", true);
lockPref("browser.startup.homepage", "http://www.desiredhomepage.com/");
3. Create another file in /etc/firefox-3.0/pref/ called copyfirefox.cfg.pl with the following contents (Thanks to Jeffrey LePage for this script):
# start of file
use strict;
# this gets the current firefox version
my $fire_ver = `/usr/bin/firefox -v`;
# this parses the version
chomp($fire_ver);
$fire_ver =~ s/^\s*Mozilla\s+Firefox\s+([\d\.]+).*$/$1/;
#Mozilla Firefox 3.0.13, Copyright (c) 1998 - 2009 mozilla.org
# this looks for firefox.cfg
if( -e "/usr/lib/firefox-$fire_ver/firefox.cfg" )
{
# firefox.cfg exists - this is good, no action is necessary
}
else
{
# make a symlink
symlink("/etc/firefox-3.0/pref/firefox.cfg", "/usr/lib/firefox-$fire_ver/firefox.cfg");
}
# end of file
4. Open the root crontab editor by typing the following in a terminal window:
sudo crontab -e
Add the following to the end of the root crontab in the crontab editor:
# Copy firefox.cfg to the current Firefox binary directory # to keep it working following an upgrade until this bug is fixed. * * * * * /usr/bin/perl /etc/firefox-3.0/pref/copyfirefox.cfg.pl /dev/null 2>&1
This script will create a symlink to firefox.cfg every minute in the current Firefox binary directory (/usr/lib/firefox-3.0.x where x is the version number) to protect againt upgrades where the directory changes to x+1. This is a very short script, so running it every minute will have almost no CPU overhead. But if you want even less CPU overhead, you could change the first asterisk in the crontab entry to */5 to make it run every 5 minutes instead of every minute, or */10 for every 10 minutes, etc.
5. Wait a minute for the crontab to fire. Then restart Firefox, and the preferences should be locked down. You should be able to use this to lock down any setting in about:config.
UPDATED Sept 3, 2009. Thanks to Jeffrey LePage (jglepage) for pointing out a better way to point to the .cfg file and for developing the perl script to create the symlink in the current Firefox installation directory.
Great tutorial! Worked like a charm.
Your technique works. However, it seems to fail when firefox upgrades. The main problem is that the firefox.cfg file must be placed in /usr/lib/firefox-3.0.x, and this directory changes each time firefox is upgraded. The firefox.cfg file is not copied over to the new directory. I have tested this in upgrade from 3.0.11 to 3.0.13 on Ubuntu 8.04.
I’ve been all over the forums and bugzilla, and I can find no solution that continues to work after a firefox upgrade.
It’s possible to keep the changes to firefox.js if you use /etc/firefox-3.0/pref/firefox.js. However, you still have to put the firefox.cfg file in /usr/lib/firefox-3.0.x/. Upon upgrade, the firefox.cfg is not copied over to the new /usr/lib/firefox-3.0.(x+1)/ directory.
Does anyone know a way of doing this that survives upgrades.
See a longer description of my techniqe below:
I’m attempting to lock firefox preferences, specifically network.proxy.type.
My technique works, but breaks when upgrades happen. Here’s how I do it:
append the following to /etc/firefox-3.0/pref/firefox.js:
//
pref(“general.config.obscure_value”, 0); // for MCD .cfg files
pref(“general.config.filename”, “firefox.cfg”);
…then put firefox.cfg in /usr/lib/firefox-3.0.x/, where 3.0.x is the currently installed version.
Contents of firefox.cfg:
//
lockPref(“network.proxy.type”, 4);
This works. The network settings are locked at “automatically detect network settings”. However, upon upgrade, the firefox.cfg is NOT copied to the new installation directory. Also, apt is unable to delete the old installation directory, probably because the new firefox.cfg file is not by apt.
How do you manage to lock settings and NOT have things break upon upgrade?
I Need to be able to manage dozens of machines, and I would prefer not to have to reconfigure everytime firefox upgrades.
jglepage, Thanks for the feedback. It’s great to hear that you can use firefox.js instead of having to create loadcustom.js. I’ll update the post to reflect that.
I’ll try out a couple of techniques to make firefox.cfg persistent and post an update when I get something to work.
jglepage, I tried several things including storing firefox.cfg in /etc/firefox-3.0/pref/ and then using a relative path to it in the general.config.filename entry. None of them worked.
So, I did a brute-force kludge of storing firefox.cfg in /etc/firefox-3.0/pref/ and creating a bash script also stored in /etc/firefox-3.0/pref/ that runs via crontab every minute to copy firefox.cfg to the /usr/lib/firefox-3.0.x directory.
I need to install a 9.04 test setup in VirtualBox to see if they fixed it. If not, I’ll submit a bug report suggesting that they add the lines to the end of firefox.js and include a firefox.cfg in /etc/firefox-3.0/pref/ with a symlink to it in the installation directory.