mozilla

Revision 57805 of MCD, Mission Control Desktop, AKA AutoConfig

  • Revision slug: MCD,_Mission_Control_Desktop_AKA_AutoConfig
  • Revision title: MCD, Mission Control Desktop, AKA AutoConfig
  • Revision id: 57805
  • Created:
  • Creator: Jehanproc
  • Is current revision? No
  • Comment

Revision Content

<big>Mozilla AutoConfig</big>

Jehan Procaccia MCI INT-EVRY- jehan.procaccia@int-evry.fr 23 may 2006



Abstract : This document is a concret example of a centralized auto-configuration of mozilla suite 1.X.X , firefox & thunderbird, and the the record, old netscape 4.X . Its original inspiration comes from http://www.cs.colorado.edu/~dowdy/netscape_cfg/readme.txt and http://www.alain.knaff.lu/howto/MozillaCustomization/. It has been recently reordered , putting thunderbird and firefox in the begening, but for history, I've keept mozilla and netscape chapters, that are in certain points complementary, principaly on the web base autoconfig file.

TOC section Situation

  Situation

SEC END

INT-Evry (http://www.int-evry.fr/) manages about 2000 users (mostly students) who shares computers in labs and "self service" computer rooms. Hence a single computer might connect many different users all day long. Computers are dualboot (windows XP and Linux Fedora Core 4/5 ). All users have a personal account on a windows server and an LDAP account for linux authentification. TOC section Objective

  Objective

SEC END

The objective is to provide users with a mailer agent, a web browser, and a news reader which are automatically configured (preferences) at its invocation to the particular user connected at this momment on the computer. Choosing Mozilla products allows us to use the same program either while running Windows or Unix (Linux in our case).
Instead of configuring user by user individual preference files (~/.mozilla/default/randomdir/prefs.js) we will centralized defaults preferences. This centralized preference file can lock preferences (lockPref) or initialized them (defaultPref) based on environement variables (USER, HOME ...) and/or LDAP queries (for fetching email address, Common Name etc ...) .

TOC section Central configuration file

  Central configuration file

SEC END

That feature is provided through a javascript file.

TOC subsection file location

  file location

SEC END


For the old netscape 4.X the file is encoded (byteshift/rotary is 7), and the presence of that file (netscape.cfg) in the MOZILLA_HOME directory sufices for it to be read and executed.

For Mozilla 1.X.X , firefox, thunderbird or Netscape7 it is still a javascript file, the byteshift is 13 by default, but can be removed using the pref("general.config.obscure_value", 0); preference in all.js. The name of the file can be anything you want because it is named by a general.config preference that should be added at the end of file MOZILLA_HOME/default/pref/all.js or MOZILLA_HOME/greprefs/all.js : pref(``general.config.filename, ``mozilla.cfg); .


TOC subsection Warnings

  Warnings

SEC END

Beware of the location on the all.js file, all.js file has moved to MOZILLA_HOME/greprefs/all.js, and I noticed the same for thunderbird and firefox !


TOC subsection file encoding

  file encoding

SEC END

If needed, the encoding can be done with the perl script: moz-byteshift.pl available at http://www.alain.knaff.lu/howto/MozillaCustomization/moz-byteshift.pl . For Netscape 4.X the convert fonction from the Client Customization Kit (CCK) could also do that (and other things like personnalize autoinstallation ...): http://developer.netscape.com/docs/manuals/deploymt/config.htm

TOC subsection file API

  file API

SEC END

That centralized preference file uses a javascript API that allows us to do what we need. The fonctions available are defined in MOZILLA_HOME/default/autoconfig/prefcalls.js. Actually the presence of pref(``general.config.filename, ``mozilla.cfg); in all.js as described above, enable the read and execution of prefcalls.js. Avalaible functions are (see file for details):

function getPrefBranch() 
function pref(prefName, value) 
function defaultPref(prefName, value)
function lockPref(prefName, value) 
function unlockPref(prefName) 
function getPref(prefName) 
function getLDAPAttributes(host, base, filter, attribs) 
function getLDAPValue(str, key) 
function displayError(funcname, message)
function getenv(name) 

TOC section Thunderbird

  Thunderbird

SEC END

TOC subsection Support of autoconfig and ldap calls

  Support of autoconfig and ldap calls

SEC END

TOC subsubsection Autoconfig option and ldap support in thunderbird 1.5.X

  Autoconfig option and ldap support in thunderbird 1.5.X
SEC END

Fortunatly,autoconfig is now part of thunderbird default packages. MOZ_LDAP_XPCOM=1 and MOZ_EXTENSIONS_DEFAULT=" wallet spellcheck xmlextras pref webservices universalchardet auth are now present in the default configure script. see https://bugzilla.mozilla.org/show_bug.cgi?id=295329 for details.

TOC subsubsection Add the autoconfig option for old thunderbird 1.0.X

  Add the autoconfig option for old thunderbird 1.0.X
SEC END

By default, autoconfig did not made part of the binaries distribution of thunderbird (1.0.X) . It was apparently supposed to increasing the load of the binary for a feature not used by lots of individuals . Howerver for entrerpise deployement, it is vital !. So we needed to recompile thunderbird with autoconfig support, it's just a matter of adding --enable-extensions=pref in mozconfig file .

On my fedora core 3 system, I took the thunderbird source package thunderbird-1.0.2-1.3.3.src.rpm installed it (rpm -i) then modified /usr/src/redhat/SOURCES/thunderbird-mozconfig by adding :

ac_add_options --enable-extensions=pref

Compile and install :

$ rpmbuild -ba /usr/src/redhat/SPECS/thunderbird.spec
$ rpm -Uvh /usr/src/redhat/RPMS/i386/thunderbird-1.0.2-1.3.3.i386.rpm

After istallation, autoconfig is finally back here :

$ rpm -ql thunderbird | grep autoconfig
/usr/lib/thunderbird-1.0.2/chrome/en-US/locale/autoconfig
/usr/lib/thunderbird-1.0.2/components/autoconfig.xpt
/usr/lib/thunderbird-1.0.2/components/libautoconfig.so
/usr/lib/thunderbird-1.0.2/defaults/autoconfig
/usr/lib/thunderbird-1.0.2/defaults/autoconfig/platform.js
/usr/lib/thunderbird-1.0.2/defaults/autoconfig/prefcalls.js


TOC subsection configure autoconfig

  configure autoconfig

SEC END

Two directives ask thunderbird to use autoconfig at startup :

[root@b008-02 /usr/lib/thunderbird-1.5]
$tail -2 greprefs/all.js
pref("general.config.obscure_value", 0); // for MCD .cfg files
pref('general.config.filename', 'thunderbird.cfg'); // for MCD .cfg files

the first one just tells that we won't encode the file (no more rotary 13 or 7 ... :-) ), the second one is the name of the file to be read: /usr/lib/thunderbird-1.5/thunderbird.cfg.


TOC subsection Autoconfig directives

  Autoconfig directives

SEC END

Here we want to set users central mail preferences: Create one account from their login name, get their email adresse from an ldap request and set the entreprise imap and smtp servers. Hence, when working on multiuser workstations, one person gets automatically thunderbird configured for himself .

TOC subsubsection thunderbird.cfg

  thunderbird.cfg
SEC END

Here's the complete file, first we get the user login name from environement variables, then configure the ldap adress book , create an mail account, configure imap and smtp :

[root@b008-02 /usr/lib/thunderbird-1.5]
$ cat thunderbird.cfg
//put everything in a try/catch
try {

// 1) env variables
if(getenv("USER") != "") {
   // *NIX settings
   var env_user    = getenv("USER");
   var env_home    = getenv("HOME");
 } else {
   // Windows settings
   var env_user    = getenv("USERNAME");
   var env_home    = getenv("HOMEPATH");
 }
  var env_mozdebug= getenv("MOZILLA_DEBUG");
 // var env_user = prompt("indiquez votre login", toto);

// 2) lock general preferences
//LDAP address book
lockPref("ldap_2.prefs_migrated", true);
lockPref("ldap_2.servers.LDAPINT.auth.savePassword", true);
lockPref("ldap_2.servers.LDAPINT.description", "LDAP INT");
lockPref("ldap_2.servers.LDAPINT.filename", "abook-1.mab");
lockPref("ldap_2.servers.LDAPINT.uri", "ldap://ldap1.int-evry.Fr:389/ou=people,dc=int-evry,dc=fr??sub");
lockPref("ldap_2.servers.history.filename", "history.mab");
lockPref("ldap_2.servers.history.replication.lastChangeNumber", 0);
lockPref("ldap_2.servers.pab.filename", "abook.mab");
lockPref("ldap_2.servers.pab.replication.lastChangeNumber", 0);

//Account
lockPref("mail.account.account1.server", "server1");
lockPref("mail.account.account2.identities", "id1");
lockPref("mail.account.account2.server", "server2");
lockPref("mail.accountmanager.accounts", "account1,account2");
lockPref("mail.accountmanager.defaultaccount", "account2");
lockPref("mail.accountmanager.localfoldersserver", "server1");
lockPref("mail.identity.id1.directoryServer", "ldap_2.servers.LDAPINT");
lockPref("mail.identity.id1.draft_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Drafts");
lockPref("mail.identity.id1.drafts_folder_picker_mode", "0");
lockPref("mail.identity.id1.fcc_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Sent");
lockPref("mail.identity.id1.fcc_folder_picker_mode", "0");
lockPref("mail.identity.id1.organization", "INT Evry France");
lockPref("mail.identity.id1.overrideGlobal_Pref", true);
lockPref("mail.identity.id1.reply_to", "");

//IMAP
lockPref("mail.server.server2.hostname", "imap-int.int-evry.fr");
lockPref("mail.server.server2.isSecure", true);
lockPref("mail.server.server2.login_at_startup", true);
lockPref("mail.server.server2.max_cached_connections", 5);
//lockPref("mail.server.server2.name", "jehan.procaccia@int-evry.fr");
lockPref("mail.server.server2.type", "imap");
lockPref("mail.server.server2.userName", env_user );

//SMTP
lockPref("mail.identity.id1.smtpServer", "smtp1");
lockPref("mail.identity.id1.stationery_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Templates");
lockPref("mail.identity.id1.tmpl_folder_picker_mode", "0");
lockPref("mail.identity.id1.valid", true);

//SMTP general
lockPref("mail.smtp.defaultserver", "smtp1");
lockPref("mail.smtpserver.smtp1.auth_method", 0);
lockPref("mail.smtpserver.smtp1.hostname", "smtp-int.int-evry.fr");
lockPref("mail.smtpserver.smtp1.port", 25);
lockPref("mail.smtpserver.smtp1.try_ssl", 0);
lockPref("mail.smtpserver.smtp1.username", "");
lockPref("mail.smtpservers", "smtp1");
lockPref("mail.startup.enabledMailCheckOnce", true);
lockPref("mailnews.quotingPrefs.version", 1);
lockPref("mailnews.ui.threadpane.version", 5);

/* 3) define here (because if set after "4)" below it doesn't work !) processLDAPValues which is eventually called by getLDAPAttributes() just below,
 check getLDAPAttributes() code from $MOZILLA_HOME/defaults/autoconfig/prefcalls.js to see the inside call to "user defined" processLDAPValues
*/
function processLDAPValues (values) {
 if(values) {
      // set the global var with the values returned from the LDAP query
      ldap_values = values;
    var uid = getLDAPValue ( values ,"uid" );
    var cn = getLDAPValue ( values ,"cn" );
    var mail = getLDAPValue ( values ,"mail" );
    var URL =  getLDAPValue ( values ,"labeledURI" );

// Those ldap variables are only available is this processLDAPValues context !
// so we set the preferences that need them here .
lockPref("mail.identity.id1.useremail", mail);
lockPref("mail.server.server2.name", mail );
lockPref("mail.identity.id1.fullName", cn );
//Debug with popup error messages doesn't work anymore :-( !!
var env_mozdebug= getenv("MOZILLA_DEBUG");
if (env_mozdebug) {displayError("NO ERROR , just a debug, cn =" + cn + " and mail = " + mail ); }
    }
  }
// 4) Call Ldap servers to get Ldap Attributes (mail & cn) , this will finally call processLDAPValues , "3)" just above.
  getLDAPAttributes("ldap2.int-evry.fr","ou=people,dc=int-evry,dc=fr","uid=" + env_user,"uid,cn,mail,labeledURI");

// Close the try, and call the catch()
} catch(e) {
  displayError("lockedPref", e);
}


TOC subsubsection Test autoconfig

  Test autoconfig
SEC END

TOC paragraph Debug

Debug
SEC END

To check that our autoconfig works fine, we just set to env variable to check the read of thunderbird.cfg file:

$ export NSPR_LOG_MODULES=MCD:5
$ export NSPR_LOG_FILE=/tmp/thunderbird-log.txt
When thunderbird has started , you should read:
 $ cat /tmp/thunderbird-log.txt
-1209403040[808a788]: general.config.filename = thunderbird.cfg
-1209403040[808a788]: evaluating .cfg file thunderbird.cfg with obscureValue 0

TOC paragraph Clean

Clean
SEC END

Then, to be sure to start with a fresh thunderbird account , don't do that if you already have one and want to preserve you mails and preferences !!

$ rm -rf ~/.thunderbird

TOC paragraph Start it

Start it
SEC END



$ thunderbird
If thunderbird ask you to import your profile from netscape/mozilla depending on you mail client history, don't import anything, to check the autoconfig job alone !.


That should work, just restart the process by setting a different USER variable (USER=procacci, USER=test etc... anyone in you ldap directory ...) to check multiuser autoconfig .
TOC subsection Bugs reports related

  Bugs reports related

SEC END

for the record, for old 1.0.X releases ...

TOC subsubsection Unwanted white space reappeared

  Unwanted white space reappeared
SEC END

Unfortunatly the 'blank space bug' has reapered in thunderbird 1.0.2 . see:
<A HREF="https://bugzilla.mozilla.org/show_bug.cgi?id=229271"><tt>https://bugzilla.mozilla.org/show_bug.cgi?id=229271</tt></A>
Although it was corected in mozilla mainstream : ozilla/extensions/pref/autoconfig/src/nsLDAPSyncQuery.cpp 1.7.2.1 by late 2004, it is still present in thunderbird 1.0.2 at least :-( , so I applied the workaround I proposed in that bug report (start_pos =1;+).

TOC section Firefox

  Firefox

SEC END

It's the same principle as above for thunderbird. Binaries ditributions now include support for autoconfig (pref extension !) but unfortunatly not for ldap calls :-( (cf MOZ_LDAP_XPCOM=1) . It is not vital in firefox as it is for us in thunderbird (need to get the cn and email address to set email account, which are not available by default in the environement viriables ). However I could be usefull to get ldap values for firefox extra config , for example to set the default homepage to the labeledURI ldap attribute of the user.

TOC subsection Autoconfig (pref) and ldap support in packages

  Autoconfig (pref) and ldap support in packages

SEC END

TOC subsubsection Add ldap support in firefox 1.5

  Add ldap support in firefox 1.5
SEC END

A least from firefox 1.5, autonfig is compiled by default (cf browser, MOZ_EXTENSIONS_DEFAULT="pref...") but not ldap (MOZ_LDAP_XPCOM=1) . You need to recompile the package to get it, cf https://bugzilla.mozilla.org/show_bug.cgi?id=295329 .

TOC subsubsection Add autoconfig and ldap support in firefox 1.0.X

  Add autoconfig and ldap support in firefox 1.0.X
SEC END

Add pref extension (--enable-extensions=pref) and remove --disable-ldap from mozconfig file . One can check how firefox has been compiled by opening about:buildconfig (don't know the equivalent for thunderbird!, how as it been compile ??)

about:buildconfig

Build platform
target
i686-pc-linux-gnu

Build tools
Compiler  Version  Compiler flags
gcc  gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.fc3)  -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -pthread -pipe
c++  gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.fc3)  -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wno-long-long -pedantic -fshort-wchar -pthread -pipe -I/usr/X11R6/include

Configure arguments
--disable-mailnews --enable-extensions=cookie,xml-rpc,xmlextras,pref,transformiix,universalchardet,webservices,inspector,gnomevfs,negotiateauth --enable-crypto --disable-composer --enable-single-profile --disable-profilesharing --with-system-jpeg --with-system-zlib --with-system-png --with-pthreads --disable-tests --disable-jsd --disable-installer '--enable-optimize=-Os -g -pipe -m32 -march=i386 -mtune=pentium4' --enable-xft --enable-xinerama --enable-default-toolkit=gtk2 --enable-official-branding --disable-xprint --disable-strip --enable-pango 

TOC subsection all.js

  all.js

SEC END


[root@b008-02 /usr/lib/firefox-1.5.0.2]
$tail -4 greprefs/all.js
// autoconfig jehan
pref('general.config.obscure_value', 0);
pref('general.config.filename', 'firefox.cfg');

TOC subsection firefox.cfg

  firefox.cfg

SEC END

This file will set the browser home page to the labeledURI page defined in the user's ldap entry , hence it both check that autoconfig + ldap works fine .

[root@b008-02 /usr/lib/firefox-1.5.0.2]
$cat firefox.cfg
//put everything in a try/catch
try {

//Privacy & Security
defaultPref("signon.rememberSignons", false);

// 1) env variables
if(getenv("USER") != "") {
   // *NIX settings
   var env_user    = getenv("USER");
   var env_home    = getenv("HOME");
 } else {
   // Windows settings
   var env_user    = getenv("USERNAME");
   var env_home    = getenv("HOMEPATH");
 }
  var env_mozdebug= getenv("MOZILLA_DEBUG");

/* 2) define here (because if set after "3)" below it doesn't work !) processLDAPValues which is eventually called by getLDAPAttributes() just below,
 check getLDAPAttributes() code from $MOZILLA_HOME/defaults/autoconfig/prefcalls.js to see the inside call to "user defined" processLDAPValues
*/
function processLDAPValues (values) {
 if(values) {
      // set the global var with the values returned from the LDAP query
      ldap_values = values;
    var uid = getLDAPValue ( values ,"uid" );
    var cn = getLDAPValue ( values ,"cn" );
    var mail = getLDAPValue ( values ,"mail" );
    var URL =  getLDAPValue ( values ,"labeledURI" );
//Debug with popup error messages doesn't work anymore :-( !!
var env_mozdebug= getenv("MOZILLA_DEBUG");
if (env_mozdebug) {displayError("NO ERROR , just a debug, cn =" + cn + " and mail = " + mail + " ,labeledURI= " + URL ); }
lockPref("browser.startup.homepage", URL );
    }
  }

//lockPref("browser.startup.homepage", "http://www.renater.fr/" );
// 3) Call Ldap servers to get Ldap Attributes (mail & cn) , this will finally call processLDAPValues , "2)" just above.
  getLDAPAttributes("ldap2.int-evry.fr","ou=people,dc=int-evry,dc=fr","uid=" + env_user,"uid,cn,mail,labeledURI");

// Close the try, and call the catch()
} catch(e) {displayError("lockedPref", e);}


TOC subsection Debug

  Debug

SEC END

If you set a username and the MOZILLA_DEBUG variable ($export MOZILLA_DEBUG=1; export USER=procacci), then the displayError() will show you this popup :

<IMG SRC="mozilla-autoconfig-en001.png">

That's a popup titled as ``error, but it's just a debug tool for me as I didn't find any other way to popup information. cf <A HREF="https://bugzilla.mozilla.org/show_bug.cgi?id=206294"><tt>https://bugzilla.mozilla.org/show_bug.cgi?id=206294</tt></A> :

 ------- Comment #14 From Daniel Wang 2003-11-06 09:06 PDT [reply] -------

Jehan Procaccia, you need to change 5.8 to reflect what I said in comment 21.

Preference files and config files are special js files with limited scopes. They
can only call the get/set pref/env methods and have no access to other objects
(need to investigate what exactly are allowed). alert() is a method of the
Window object.

cf also related post in Newsgroups: mozilla.dev.tech.js-engine

Date: Wed, 17 May 2006 19:06:28 +0200
From: jehan procaccia <jehan.procaccia@int-evry.fr>

Newsgroups: mozilla.dev.tech.js-engine
Subject: scope of js file functions in firefox/thunderbird autoconfig context

TOC section Referecences

  Referecences

SEC END

TOC subsection Other docs about autoconfig

  Other docs about autoconfig

SEC END

http://mit.edu/~firefox/www/maintainers/autoconfig.html

http://www.alain.knaff.lu/howto/MozillaCustomization/index.html
http://thegoldenear.org/toolbox/windows/docs/mozilla-pre-config.html
http://ilias.ca/blog/2005/03/locking-mozilla-firefox-settings.html

compile on windows :
http://forums.mozillazine.org/viewtopic.php?t=276014

http://www.mozilla.org/community/developer-forums.html
http://forums.mozillazine.org/viewtopic.php?p=2090731&highlight=autoconfig#2090731
http://forums.mozillazine.org/viewtopic.php?p=1354355&highlight=autoconfig#1354355
http://forums.mozillazine.org/viewtopic.php?p=32783&highlight=autoconfig#32783
TOC subsection Related bugzilla

  Related bugzilla

SEC END

https://bugzilla.mozilla.org/show_bug.cgi?id=295329
https://bugzilla.mozilla.org/show_bug.cgi?id=222973
https://bugzilla.mozilla.org/show_bug.cgi?id=225288
https://bugzilla.mozilla.org/show_bug.cgi?id=178685

https://bugzilla.mozilla.org/show_bug.cgi?id=272970
https://bugzilla.mozilla.org/show_bug.cgi?id=206294
https://bugzilla.mozilla.org/show_bug.cgi?id=302096
TOC section OLD Mozilla1.X, possibly Netscape 6/7

  OLD Mozilla1.X, possibly Netscape 6/7

SEC END

The following is for the record ... it also contain an interesting feature that I did not use anymore -> autoconfig from an web server !

TOC subsection Changes

  Changes

SEC END

Between 2002 and 2003, we needed to upgrade the old netscape 4.X (4.79) version to Mozilla 1.X (1.4), and now (2004-2005) mozilla 1.7. The autoconfiguration subsystem is quite the same as described the section on 'old' Netscape 4.X , but also slightly different.

TOC subsection Mozilla new features in regard to netscape

  Mozilla new features in regard to netscape

SEC END

In Mozilla, we don't use anymore the convert function from netscape 4.5 CCK, but moz-byteshift.pl perl script, to encode mozilla.cfg file.

The use of the getLDAPAttributes() function by calling inside itself the processLDAPValues() as a user defined function (see prefcalls.js) forces us to slighlty change these calls in our original web-cgi javascript (here mci-mozilla-glob-prefs-tux.cgi ). The variable generated (mail, cn , uid) are defined only inside the processLDAPValues() function, that explains why lockPref related to these variables are located inside that function. I also couldn't use anymore the alert() fonction, so I changed to displayerror() function !

TOC subsection Locating the file on a web server

  Locating the file on a web server

SEC END

That was the case in the Netscape 4.X description above, however, it first was a hard thing to do in Mozilla , cf bug report: <A HREF="http://bugzilla.mozilla.org/show_bug.cgi?id=206294"><tt>http://bugzilla.mozilla.org/show_bug.cgi?id=206294</tt></A>. So now you only need to create a small encoded cfg file making a call to a web located cgi script which will actually generate the javascript configuration directives to the mozilla client. Hence you can change all of your mozilla clients preferences by simply modifying a single file on a web server, great !.


TOC subsubsection Call file

  Call file
SEC END

This file calls a cgi on a web server, the cgi generating the javascript code that will set preferences. Here the vendor name (mci-mozilla-web-tux) must match the name of the cfg file (mci-mozilla-web-tux.cfg).

$ cat mci-mozilla-web-tux.js
lockPref("general.config.vendor", "mci-mozilla-web-tux");
lockPref("autoadmin.global_config_url","http://corbeau.int-evry.fr/cgi-bin/mci-mozilla-glob-prefs-tux.cgi");

TOC subsection Encoding mozilla.js file to mozilla.cfg

  Encoding mozilla.js file to mozilla.cfg

SEC END

Just use the moz-byteshift.pl perl script which for mozilla1.X and Netscape 6/7 uses a shift of 13, in netscape 4.X it was 7.

$ more moz-byteshift.pl
#!/usr/bin/perl
 
# Byteshifting program for mozilla's netscape.cfg files
 
# Old netscape 4.x uses a bytechift of 7
#   To decode: moz-byteshift.pl -s -7 <netscape.cfg >netscape.cfg.txt
#   To encode: moz-byteshift.pl -s  7 <netscape.cfg.txt >netscape.cfg
 
# Mozilla uses a byteshift of 13
#   To decode: moz-byteshift.pl -s -13 <netscape.cfg >netscape.cfg.txt
#   To encode: moz-byteshift.pl -s  13 <netscape.cfg.txt >netscape.cfg
 
# To activate the netscape.cfg file, place the encoded netscape.cfg file
# into your C:\Program Files\mozilla.org\Mozilla directory.
# Then add the following line to your
# C:\Program Files\mozilla.org\Mozilla\defaults\pref\all.js file :
# pref("general.config.filename", "mozilla.cfg");
...

$ ./moz-byteshift.pl -s 13 < mci-mozilla-web-tux.js > mci-mozilla-web-tux.cfg


TOC subsection Location of mci-mozilla-web-tux.cfg

  Location of mci-mozilla-web-tux.cfg

SEC END

The location of the netscape.cfg (here renamed to mci-mozilla-web-tux.cfg) and the way to call it is different from the old netscape 4.X. It's location is in MOZILLA_HOME ; c:\program files\mozilla.org\mozilla in windows, or /usr/lib/mozilla-1.7-3/ in linux Fedora.


TOC subsection Call to mci-mozilla-web-tux.cfg

  Call to mci-mozilla-web-tux.cfg

SEC END

The way to call it is through all.js file by adding at the end:

$ tail -2 /usr/lib/mozilla-1.7-3/defaults/pref/all.js
pref("general.config.filename", "mci-mozilla-web-tux.cfg");
pref("general.config.vendor", "mci-mozilla-web-tux");

TOC subsection Web base cgi javascript preferences generator file

  Web base cgi javascript preferences generator file

SEC END


[root@corbeau /var/www/cgi-bin]
$ cat mci-mozilla-glob-prefs-tux.cgi
#!/usr/bin/perl -w
  
print ("Content-type: application/x-javascript-config\n\n");
$page = <<"EOP";
 
try {
  var env_user    = getenv("USER");
  var env_home    = getenv("HOME");
  var env_mozdebug= getenv("MOZILLA_DEBUG");
function processLDAPValues (values) {
    var uid = getLDAPValue ( values , "uid" );
    var cn = getLDAPValue ( values , "cn" );
    var mail = getLDAPValue ( values , "mail" );
lockPref("mail.server.server1.name", mail );
lockPref("mail.identity.id1.fullName", cn);
lockPref("mail.identity.id1.useremail", mail);
  
if (env_mozdebug) {
        displayError("debug mozilla.cfg v2.8", "mail:" + mail + "uid:" + uid + "cn" + cn + "user:" + env_user );
        } 
  }
//BROWSER
/*defaultPref("startup.homepage_override_url", "http://www.int-evry.fr/mci/user/");
lockPref("browser.startup.homepage_override", true);
lockPref("browser.startup.page", 1);
defaultPref("browser.startup.homepage", "http://www.int-evry.fr/mci/user/");
*/
lockPref("browser.startup.homepage", "http://www.int-evry.fr/mci/user/");
lockPref("browser.startup.homepage_override", true);
lockPref("general.config.vendor", "mci-mozilla-web-tux");
lockPref("startup.homepage_override_url", "http://www.int-evry.fr/mci/user/");
lockPref("browser.cache.disk.capacity", 0);
lockPref("network.cookie.cookieBehavior", 0);
lockPref("network.proxy.autoconfig_url", "http://www.int-evry.fr/local/config.proxy");
lockPref("network.proxy.type", 2);
 
//Account
lockPref("mail.account.account1.identities", "id1");
lockPref("mail.account.account1.server", "server1");
lockPref("mail.account.account2.server", "server2");
lockPref("mail.account.account3.server", "server3");
lockPref("mail.accountmanager.accounts", "account1,account2,account3");
lockPref("mail.accountmanager.defaultaccount", "account1");
 
//imap
lockPref("mail.server.server1.hostname", "imap-int.int-evry.fr");
lockPref("mail.server.server1.type", "imap");
lockPref("mail.server.server1.login_at_startup", true);
lockPref("mail.identity.id1.draft_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Drafts");
lockPref("mail.identity.id1.drafts_folder_picker_mode", "0");
lockPref("mail.identity.id1.fcc_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Sent");
lockPref("mail.identity.id1.fcc_folder_picker_mode", "0");
lockPref("mail.identity.id1.stationery_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Templates");
lockPref("mail.identity.id1.tmpl_folder_picker_mode", "0");
lockPref("mail.identity.id1.valid", true);
lockPref("mail.identity.id1.overrideGlobal_Pref", true);
lockPref("mail.server.server1.download_on_biff", true);
lockPref("mail.server.server1.login_at_startup", true);
lockPref("mail.server.server1.userName", env_user );
lockPref("mail.server.server1.delete_model", 0);
 
//SMTP
lockPref("mail.identity.id1.smtpServer", "smtp1");
defaultPref("mail.smtpserver.smtp1.auth_method", 0);
lockPref("mail.smtpservers", "smtp1");
lockPref("mail.smtpservers", "smtp1");
lockPref("mail.smtp.defaultserver", "smtp1");
lockPref("mail.smtpserver.smtp1.hostname", "smtp-int.int-evry.fr");
lockPref("mail.identity.id1.organization", "INT Evry France");
lockPref("mail.startup.enabledMailCheckOnce", true);
lockPref("mail.ui.folderpane.version", 3);
lockPref("mailnews.ui.threadpane.version", 2);
 
//LDAP config
lockPref("mail.identity.id1.directoryServer", "ldap_2.servers.ldapint");
lockPref("ldap_2.prefs_migrated", true);
lockPref("ldap_2.servers.history.filename", "history.mab");
lockPref("ldap_2.servers.history.replication.lastChangeNumber", 0);
lockPref("ldap_2.servers.ldapint.auth.savePassword", true);
lockPref("ldap_2.servers.ldapint.description", "ldap-int");
lockPref("ldap_2.servers.ldapint.filename", "abook-1.mab");
lockPref("ldap_2.servers.ldapint.position", 3);
lockPref("ldap_2.servers.ldapint.uri", "ldap://ldap1.int-evry.fr:389/ou=people,dc=int-evry,dc=fr??sub");
lockPref("ldap_2.servers.pab.filename", "abook.mab");
lockPref("ldap_2.servers.pab.replication.lastChangeNumber", 0);
 
//News config
lockPref("mail.server.server3.hostname", "news.int-evry.fr");
lockPref("mail.server.server3.max_cached_connections", 2);
lockPref("mail.server.server3.name", "news.int-evry.fr");
lockPref("mail.server.server3.type", "nntp");
lockPref("mail.server.server3.userName", env_user );
 
//Call to ldap to get user's attribute .
getLDAPAttributes ( "ldap2.int-evry.fr", "ou=people,dc=int-evry,dc=fr", "uid=" +env_user , "uid,cn,mail" );
 
} catch(e) {
  displayError("lockedPref", e);
}
 
EOP
print $page;

TOC subsection Windows particularities

  Windows particularities

SEC END

Without web base cgi file, beware that in windows, the original (before encoding) mozilla.js file must start with: //BEGIN CE prefs , if not you'll get ``failed to read configuration file ... message, and mozilla won't start :-( .
In Windows environement variables like USER or HOME, are USERNAME and HOMEPATH, that's why we must create a different pair of configuration files (cfg and cgi) for both systems (linux/windows). Perhaps there's a way in javascript to dectect operating system and hence use either USER or USERNAME, but I'am not that fluent in javascript to do that, let me know if you know ...//

TOC subsubsection Windows Call file

  Windows Call file
SEC END



$ cat mci-mozilla-web-win.js
lockPref("general.config.vendor", "mci-mozilla-web-win");
lockPref("autoadmin.global_config_url","http://corbeau.int-evry.fr/cgi-bin/mci-mozilla-glob-prefs-win.cgi");

TOC subsubsection Windows all.js file

  Windows all.js file
SEC END

To be encoded by moz-byteshift.pl as stated above ...

c:\type c:\program files\mozilla.org\mozilla\defaults\pref\all.js
pref("general.config.filename", "mci-mozilla-web-win.cfg");
pref("general.config.vendor", "mci-mozilla-web-win");

TOC subsubsection Windows cgi file

  Windows cgi file
SEC END


$ cat mci-mozilla-glob-prefs-win.cgi
#!/usr/bin/perl -w
  
print ("Content-type: application/x-javascript-config\n\n");
$page = <<"EOP";
 
try {
  var env_user    = getenv("USERNAME");
  var env_home    = getenv("HOMEPATH");
  var env_mozdebug= getenv("MOZILLA_DEBUG");
...

The rest of the file is identical to the linux version, only env var are different !.

TOC subsection Versions tested

  Versions tested

SEC END

This configuration was validated on linux with mozilla 1.4 , 1.6 and 1.7, and on windows with mozilla 1.4, 1.5, 1.7.

TOC section Debuging - bugzilla

  Debuging - bugzilla

SEC END

TOC subsection Run time messages

  Run time messages

SEC END

Notice the presence of var env_mozdebug=getenv("MOZILLA_DEBUG") which allows use to print debugging messages if MOZILLA_DEBUG is define either in shell for unix (export MOZILLA_DEBUG=1) or in command.com environement in windows (set MOZILLA_DEBUG=1)


TOC subsection Blank space bug

<A NAME="htoc44">8.2</A>  Blank space bug

SEC END

I noticed a problem which is due to be corrected in 1.8 I think ... here's the report and workaround: http://bugzilla.mozilla.org/show_bug.cgi?id=229271 in short add the following :

        start_pos += search_key.length;
//start 
        start_pos +=1;
//end
to function getLDAPValue() in autoconfig/preffcalls.js.


TOC subsection Documentation

  Documentation

SEC END

I also opened a report on the lack of documentation: http://bugzilla.mozilla.org/show_bug.cgi?id=178685 which ended to the wonderfull doc: http://wangrepublic.org/daniel/mozilla/prefs/

TOC subsection defeultPref for homepage

  defeultPref for homepage

SEC END

I cannot set the homepage with the defaultPref function, so that is is set by default, but still allow the user to change it !. A bugzilla is openned on this, see https://bugzilla.mozilla.org/show_bug.cgi?id=272970
TOC subsection greprefs right access

  greprefs right access

SEC END

Beware also on Linux that MOZILLA_HOME/greprefs directory is closed by default to users and then autoconfig doesn't work properly, I 've opened a bugzilla on this: <A HREF="https://bugzilla.mozilla.org/show_bug.cgi?id=270623"><tt>https://bugzilla.mozilla.org/show_bug.cgi?id=270623</tt></A>. Workaround -> chmod 755 greprefs !.


TOC subsection cgi base config file

  cgi base config file

SEC END

there has been a issue about the use of autoadmin.global_config_url, see :
http://bugzilla.mozilla.org/show_bug.cgi?id=206294
TOC section Mail folders

  Mail folders

SEC END

Implementing that solution, we encounter difficulties with mail folder. First idea was to use local mail fodlers from homedirectory of the current user. In unix that would have been $HOME/nsmail/... , in windows it would have been a samba mount of that same unix path (ex: U:\nsmail ; with U: =samba mount: \\samba-server\%USERNAME). Unfortunaltly file system writes and/or mail format differs between windows and unix, and folders becomes soon unreadable or even corrupted when read/written from one system and then the other. That's why we finally decided to use IMAP, and hence imap folders. By migrating from University of Whashinghton IMAP server to Cyrus IMAP we also inherited some intersting features like quotas, share folders, ACL, mail only account (no need for /etc/passwd entry !) much better performances, etc ...

TOC section reliabilty

  reliabilty

SEC END

TOC subsection failover and uniqueness

  failover and uniqueness

SEC END

A contribution from Roberto Aguilar gives to the mozilla autoconfig javascript a way to search through different ldap replicas in case one ldap server is down. It also allow us to use a single javscript for both systems (Linux and Windows) with a subtule if ... else test on environement variables.

TOC subsection Ldap failover

  Ldap failover

SEC END

Creating an array of possible running ldap servers permits an ldap failover, then a shuffle function allows us to randomly pick up a running ldap server.

The suffle function comes from here:

http://www.mickweb.com/javascript/arrays/pureshuffle.html

Before publishing the code changes, please add this right before the shuffle function:

 /**
  * setup the shuffle method for an array, from "mickweb script
  * factory" at:
  * http://www.mickweb.com/javascript/arrays/pureshuffle.html
  */

Here's how the ldap failover works:

// 2) setup multiple LDAP servers for failover
  var ldap_values;
  var ldap_servers = new Array('ldap2.int-evry.fr',
                      'ldap1.int-evry.fr',
                      'openldap.int-evry.fr'
                      );
  // shuffle function to randomize the server array
  // setup the shuffle method for an array
  Array.prototype.shuffle = function(times) {
    var i,j,t,l=this.length;
    while(times--) {
      with(Math) {
    i = floor(random()*l);
    j = floor(random()*l);
      }
      t       = this[i];
      this[i] = this[j];
      this[j] = t;
    }
    return this;
  }
 // mix up the ldap servers so we don't hit the same one each time
  ldap_servers.shuffle(10);
....
// 4) Call Ldap servers to get Ldap Attributes (mail & cn) , this will finally call processLDAPValues , "3)" just above.
// Go through the ldap replicas list
for(i = 0; i < ldap_servers.length; i ++) {
// Search for attribute mail & cn through ldap servers where uid = $USER|$USERNAME
  getLDAPAttributes(ldap_servers[i],
       "ou=people,dc=int-evry,dc=fr",
       "uid=" + env_user,
       "uid,cn,mail");
    // If we catch a running ldap server, exit the loop,
    if(ldap_values) {
      running_ldap_server = ldap_servers[i];
        // If $MOZILLA_DEBUG=1 display in a popup the running server
      if (env_mozdebug) {
        displayError("getLDAPAttributes: debug 2 running_ldap_server : " + running_ldap_server);
       }
      break;
    }
  }


TOC subsection Unique script for windows and linux

  Unique script for windows and linux

SEC END

an if ... else test permits us to check wether we use linux or windows environement variable for the USER / USERNAME

// 1) env variables
if(getenv("USER") != "") {
   // *NIX settings
   var env_user    = getenv("USER");
   var env_home    = getenv("HOME");
 } else {
   // Windows settings
   var env_user    = getenv("USERNAME");
   var env_home    = getenv("HOMEPATH");
 }
  var env_mozdebug= getenv("MOZILLA_DEBUG");

TOC subsection Final production script

  Final production script

SEC END

Here's the complete final and commented production script:

//Mozilla autoconfiguration, Jehan Procaccia & Roberto Aguilar
 
//put everything in a try/catch
try {
/*
1) define environement variables,
2) list & randomize ldap replicas,
3) define processLDAPValues(),
4) Call Ldap server to get Ldap Attributes (mail & cn) getLDAPAttributes()
5) set user preferences
*/
 
// 1) env variables
if(getenv("USER") != "") {
   // *NIX settings
   var env_user    = getenv("USER");
   var env_home    = getenv("HOME");
 } else {
   // Windows settings
   var env_user    = getenv("USERNAME");
   var env_home    = getenv("HOMEPATH");
 }
  var env_mozdebug= getenv("MOZILLA_DEBUG");
 
// 2) setup multiple LDAP servers for failover
  var ldap_values;
  var ldap_servers = new Array('ldap2.int-evry.fr',
                      'ldap1.int-evry.fr',
                      'openldap.int-evry.fr'
                      );
  // shuffle function to randomize the server array
/**
  * setup the shuffle method for an array, from "mickweb script
  * factory" at:
  * http://www.mickweb.com/javascript/arrays/pureshuffle.html
  */ 
  // setup the shuffle method for an array
  Array.prototype.shuffle = function(times) {
    var i,j,t,l=this.length;
    while(times--) {
      with(Math) {
    i = floor(random()*l);
    j = floor(random()*l);
      }
      t       = this[i];
      this[i] = this[j];
      this[j] = t;
    }
    return this;
  }
 // mix up the ldap servers so we don't hit the same one each time
  ldap_servers.shuffle(10);
 
/* 3) define here (because if set after "4)" below it doesn't work !) processLDAPValues which is eventually called by getLDAPAttributes() just below,
 check getLDAPAttributes() code from $MOZILLA_HOME/defaults/autoconfig/prefcalls.js to see the inside call to "user defined" processLDAPValues
*/
function processLDAPValues (values) {
 if(values) {
      // set the global var with the values returned from the LDAP query
      ldap_values = values;
    var uid = getLDAPValue ( values ,"uid" );
    var cn = getLDAPValue ( values ,"cn" );
    var mail = getLDAPValue ( values ,"mail" );
     // lock ldap variable (mail & cn)  dependant preferences while we have access to them
    lockPref("mail.server.server1.name",mail);
    lockPref("mail.identity.id1.fullName",cn);
    lockPref("mail.identity.id1.useremail",mail);
    defaultPref("network.ftp.anonymous_password", mail);
 
    // if $MOZILLA_DEBUG=1 , popup a debug message
    if (env_mozdebug) {
        displayError("NO ERROR -> MCI (jehan.procaccia@int-evry.fr)" + "\nthis message is displayed with displayError() ! \ndebug 1 mozilla.cfg v3.2 , NO FAILED,  S2IA again !", "\nmail:" + mail + "\nuid:" +uid + "\ncn:" +cn + "\nuser:" + env_user);
        }
    }
  }
 
// 4) Call Ldap servers to get Ldap Attributes (mail & cn) , this will finally call processLDAPValues , "3)" just above.
// Go through the ldap replicas list
for(i = 0; i < ldap_servers.length; i ++) {
// Search for attribute mail & cn through ldap servers where uid = $USER|$USERNAME
  getLDAPAttributes(ldap_servers[i],
       "ou=people,dc=int-evry,dc=fr",
       "uid=" + env_user,
       "uid,cn,mail");
    // If we catch a running ldap server, exit the loop,
    if(ldap_values) {
      running_ldap_server = ldap_servers[i];
        // If $MOZILLA_DEBUG=1 display in a popup the running server
      if (env_mozdebug) {
        displayError("getLDAPAttributes: debug 2 running_ldap_server : " + running_ldap_server);
       }
      break;
    }
  }
 
// 5) Set user preferences
 
//BROWSER
lockPref("browser.startup.homepage", "http://www.int-evry.fr/s2ia/portail/");
//unlockPref("browser.startup.homepage");
lockPref("browser.startup.homepage_override", true);
lockPref("startup.homepage_override_url", "http://www.int-evry.fr/s2ia/portail/");
//unlockPref("startup.homepage_override_url");
lockPref("browser.cache.disk.capacity", 100);
lockPref("network.cookie.cookieBehavior", 0);
 
//Network preferences
lockPref("network.proxy.autoconfig_url", "http://www.int-evry.fr/local/config.proxy");
lockPref("network.proxy.type", 2);
 
//Privacy & Security
defaultPref("signon.rememberSignons", false);
 
//Account
lockPref("mail.account.account1.identities", "id1");
lockPref("mail.account.account1.server", "server1");
lockPref("mail.account.account2.server", "server2");
lockPref("mail.account.account3.server", "server3");
lockPref("mail.accountmanager.accounts", "account1,account2,account3");
lockPref("mail.accountmanager.defaultaccount", "account1");
 
//imap
lockPref("mail.server.server1.hostname", "imap-int.int-evry.fr");
lockPref("mail.server.server1.type", "imap");
lockPref("mail.server.server1.login_at_startup", true);
lockPref("mail.identity.id1.draft_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Drafts");
lockPref("mail.identity.id1.drafts_folder_picker_mode", "0");
lockPref("mail.identity.id1.fcc_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Sent");
lockPref("mail.identity.id1.fcc_folder_picker_mode", "0");
lockPref("mail.identity.id1.stationery_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Templates");
lockPref("mail.identity.id1.tmpl_folder_picker_mode", "0");
lockPref("mail.identity.id1.valid", true);
lockPref("mail.identity.id1.overrideGlobal_Pref", true);
lockPref("mail.server.server1.download_on_biff", true);
lockPref("mail.server.server1.login_at_startup", true);
lockPref("mail.server.server1.userName", env_user );
lockPref("mail.server.server1.delete_model", 0);
 
//SMTP
defaultPref("mail.identity.id1.smtpServer", "smtp1");
defaultPref("mail.smtpserver.smtp1.auth_method", 0);
defaultPref("mail.smtpservers", "smtp1");
defaultPref("mail.smtpservers", "smtp1");
defaultPref("mail.smtp.defaultserver", "smtp1");
defaultPref("mail.smtpserver.smtp1.hostname", "smtp-int.int-evry.fr");
lockPref("mail.identity.id1.organization", "INT Evry France");
lockPref("mail.startup.enabledMailCheckOnce", true);
lockPref("mail.ui.folderpane.version", 3);
lockPref("mailnews.ui.threadpane.version", 2);
 
//LDAP config
lockPref("mail.identity.id1.directoryServer", "ldap_2.servers.ldapint");
lockPref("ldap_2.prefs_migrated", true);
lockPref("ldap_2.servers.history.filename", "history.mab");
lockPref("ldap_2.servers.history.replication.lastChangeNumber", 0);
lockPref("ldap_2.servers.ldapint.auth.savePassword", true);
lockPref("ldap_2.servers.ldapint.description", "ldap-int");
lockPref("ldap_2.servers.ldapint.filename", "abook-1.mab");
lockPref("ldap_2.servers.ldapint.position", 3);
lockPref("ldap_2.servers.ldapint.uri", "ldap://ldap1.int-evry.fr:389/ou=people,dc=int-evry,dc=fr??sub");
lockPref("ldap_2.servers.pab.filename", "abook.mab");
lockPref("ldap_2.servers.pab.replication.lastChangeNumber", 0);
 
//News config
lockPref("mail.server.server3.hostname", "news.int-evry.fr");
lockPref("mail.server.server3.max_cached_connections", 2);
lockPref("mail.server.server3.name", "news.int-evry.fr");
lockPref("mail.server.server3.type", "nntp");
lockPref("mail.server.server3.userName", env_user );
 
// Close the try, and call the catch()
} catch(e) {
  displayError("lockedPref", e);
}


TOC subsection for the record, old reliabily scripts ...

  for the record, old reliabily scripts ...

SEC END

At least tested on Netscape4.X
In the original files above (in Netscape 4.X section), we hard coded a single web server to retrieve the javascrip preference file, and a single hard coded ldap server to get mail and cn attributes. It would be safer to get secondary servers in case of failure. For the web server name we can use an ldap query to get the list of possible ones. hence we won't have to reencode netscape.cfg file at every changes. We set the netscape.cfg file just once while imaging computers with the operationg system, then any changes hapens in ldap or on the web server javascript preference file (central configuration).

TOC subsubsection Enhence netscape.cfg

  Enhence netscape.cfg
SEC END

Defining the list of possible web servers to query in netscape.cfg. We also set there the javascript preference file names so that netscape.cfg doesn't need to be change after imaging the computers at every changes we need to do .

TOC subsubsection LDAP web server list subtree

  LDAP web server list subtree
SEC END

$ ldapsearch -x * -b "ou=browser,ou=information,dc=int-evry, dc=fr" cn -LLL
dn: ou=browser,ou=information,dc=int-evry,dc=fr

dn: sn=http_server,ou=browser,ou=information,dc=int-evry, dc=fr
cn: web1.int-evry.fr
cn: web2.int-evry.fr

dn: sn=http_unix_file, ou=browser,ou=information,dc=int-evry, dc=fr
cn: /browser/config_file_unix.jsc

dn: sn=http_win_file, ou=browser,ou=information,dc=int-evry, dc=fr
cn: /browser/config_file_win.jsc

TOC subsubsection netscape.cfg

  netscape.cfg
SEC END

Here we select an operational ldap server simply by testing a ldap query, to make sure that our ldap queries for setting preferences will be answered . (again I am not fluent in javascript, there should be a better way to make sure that an ldap server is up and running, as for to check a web server, feel free to optimize this code, and let me know ...)

if ( getLDAPAttributes( "ldap1.int-evry.fr", \
 "ou=browser,ou=information,dc=int-evry,dc=fr", \
 "sn=http_server", "cn") )
 var running_ldap_server = "ldap1.int-evry.fr";
 else if ( getLDAPAttributes( "ldap2.int-evry.fr", \
 "ou=browser,ou=information,dc=int-evry,dc=fr", \
 "sn=http_server", "cn") )
  var running_ldap_server = "ldap2.int-evry.fr";
  else if ( getLDAPAttributes( "ldap0.int-evry.fr", \
  "ou=browser,ou=information,dc=int-evry,dc=fr", \
  "sn=http_server", "cn") )
   var running_ldap_server = "ldap0.int-evry.fr";
  else alert("No LDAP server availaible !!");

Here's a complete exemple of the unix netscape.cfg file.

with (PrefConfig) { // Must be done inside the PrefConfig module

// create some variables we might want to use later on...
var env_user    = getenv("USER");       // Windows username
var env_home    = getenv("HOME");       // User HomeDir
var env_mozilla_home    = getenv("MOZILLA_HOME");
var env_mozdebug        = getenv("MOZILLA_DEBUG");

//check which ldap server is running (needs a better procedure !)

if ( getLDAPAttributes( "ldap1.int-evry.fr", \
 "ou=browser,ou=information,dc=int-evry,dc=fr", \
 "sn=http_server", "cn") )
 var running_ldap_server = "ldap1.int-evry.fr";
 else if ( getLDAPAttributes( "ldap2.int-evry.fr", \
  "ou=browser,ou=information,dc=int-evry,dc=fr", \
  "sn=http_server", "cn") )
  var running_ldap_server = "ldap2.int-evry.fr";
  else if ( getLDAPAttributes( "ldap0.int-evry.fr", \
  "ou=browser,ou=information,dc=int-evry,dc=fr", \
  "sn=http_server", "cn") )
   var running_ldap_server = "ldap0.int-evry.fr";
  else alert("No LDAP server availaible !!");

if (running_ldap_server){ 
var ldap_http_server_values = getLDAPAttributes( running_ldap_server, \
"ou=browser,ou=information,dc=int-evry,dc=fr", "sn=http_server", "cn");
var ldap_http_server = getLDAPValue(ldap_http_server_values, "cn");
var ldap_http_unix_uri_values  = getLDAPAttributes( running_ldap_server, \
"ou=browser,ou=information,dc=int-evry,dc=fr", "sn=http_unix_file", "cn");
var ldap_http_unix_uri  = getLDAPValue(ldap_http_unix_uri_values, "cn");
var values = getLDAPAttributes( running_ldap_server, \
"ou=people,dc=int-evry,dc=fr", "uid="+env_user, "cn,mail" );
var ldap_email =  getLDAPValue(values, "mail");
var ldap_gecos = getLDAPValue(values, "cn");
env_user=env_user.toLowerCase();
}
else
 alert("No LDAP server available, autoconfig impossible !");

//popup debug message if export MOZILLA_DEBUG=1 
if (env_mozdebug) {
 alert("MOZILLA_DEBUG\nrunning ldap server: " + running_ldap_server );
 alert("MOZILLA_DEBUG\nExecuting " + ldap_http_server + \
 ldap_http_unix_uri );
 alert("MOZILLA_DEBUG\nfetching http://" + ldap_http_server \
 + ldap_http_unix_uri + "" );
}

//go fetch the prefence file in a HTTP server 
//needs a way to check if http server is running !

config(
"autoadmin.global_config_url", "http://" + ldap_http_server + \
ldap_http_unix_uri + ""
);

// Since we use a file, if it's not accessible, something is
// terribly wrong anyway
config(
"autoadmin.failover_to_cached", false
);

// don't use ?useremail=email-addr to cgi URL request
config(
"autoadmin.append_emailaddr", false
);

} // with (PrefConfig)


For the windows version of that netscape.cfg file, we replace ``sn=http_unix_file by `` sn=http_win_file in the ldap query .

TOC section OLD Netscape 4.X

  OLD Netscape 4.X

SEC END

TOC subsection call file, netscape.cfg

  call file, netscape.cfg

SEC END

In the following example, that file is a ``call file, because it will actually be used to only redirect call to an even more centralized file, a file that will be located on a web server. That allows us first to encode (byteshift) just once that file (netscape.cfg) because it will call an non encoded javascript file config_file_system.jsc (or whatever name) on the web server. Second, as that latest javascript file is located on a web server, there's no need to recopy it on every station at every single changes !. That feature is available through autoadmin.global_config_url directive as in config("autoadmin.global_config_url","http://www/browser/config-file-system.jsc"); for example. Unfortunaltly I am unable to run that really usefull directive with Netscape6/7 or Mozilla1.X :-( , if anyone knows how, please let me known !. In windows that encoded netscape.cfg file is located in NETSCAPE_HOME\Communicator\Program (C:\Program Files\netscape\Communicator\Programs) , in RedHat 7.3 it is in /usr/lib/X11/app-defaults . Beware that in windows, that file is already there, hence it must be saved before beeing replaced by our one, in order to come back to a normal state in case of problem. If neither original or personalized netscape.cfg is there, netscape won't start !.

// This file is not usable in its present form. it must be encoded
// with the ``convert'' fonction of the CCK ``file'' menu
// Netscapes' Flow of preference configuration:
//    configure defaults from internal javascript file in ns executable
//    global prefs from netscape.cfg (this file)
//    executes ~/.netscape/preferences.js file
//    executes ~/.netscape/user.js
// (somewhere in here liprefs.js is run, but i haven't yet figured out
// what liprefs is for....)
//=========================================================================

with (PrefConfig) { // Must be done inside the PrefConfig module

// create some variables we might want to use later on...
var platform    = getPlatform();        // E.G. SunOS4.1.3_U1
var env_user    = getenv("USER");       // Unix username
var env_home    = getenv("HOME");       // User HomeDir
var env_display = getenv("DISPLAY");    // X11 Display
var env_editor  = getenv("EDITOR");     // use in mail edit?
var env_visual  = getenv("VISUAL");     // use in mail edit?
var env_mozilla_home    = getenv("MOZILLA_HOME")
var env_mozdebug        = getenv("MOZILLA_DEBUG")
// For ease of update... We use the AutoAdmin operation to redirect
// netscape.cfg to read the plain-text "config-file-unix.jsc" file.  
// Any changes
// from now on can be made here w/o re-encoding the netscape.jsc file to
// netscape.cfg.
config(
"autoadmin.global_config_url", \
"http://lugdunum.int-evry.fr/browser/config-file-unix.jsc"
);
// How often (in minutes) to update
// Every 6 hours seems a good interval to keep hosers who don't ever
// exit netscape updated on current changes.
config(
"autoadmin.refresh_interval", 360
);
// Since we use a file, if it's not accessible, something is
// terribly wrong anyway
config(
"autoadmin.failover_to_cached", false
);
// don't use ?useremail=email-addr to cgi URL request
config(
"autoadmin.append_emailaddr", false
);


TOC subsection LockPref configuration file

  LockPref configuration file

SEC END

That file ( on the web server:http://www/browser/config-file-system.jsc ) is where we set and lock Preferences. Because computers are shared, we need to personnalize preferences base on the user login. The login is taken from environement variable, USER in unix, USERNAME in Windows. Different environement name and different path between windows and unix, explain why we need 2 different configuration file. There might be a way to manage those differences within a same file, but I am not very fluent in javascript :-( .


Here is an example of a lockPref preference configuration file for unix (config_file_unix.jsc). We lock (lockPref) some preferences (imap server name, companie name, cache location and size ...), others can be just set as default (defaultPref); startup.homepage ... We also use LDAP functions (from prefcalls.js) to get the current user (USER or USERNAME) email address and common name, respectively mail and cn in ldap.

[root@lugdunum /var/www/html/browser]
$ more config_file_unix.jsc
// Functions you can use:
// lockPref(name,value)  user is disallowed from changing
//  (aka lock_pref() )
// defaultPref(name,value)  unless user overrides, this is value
//  (aka default_pref() )
// unlockPref(name)  unlock previously "lockPref"-ed name
// config(name,value)  usually for menus...
// value = getPref(name)  gets current setting
// getLDAPAttributes( host, base, filter, attributes )
// getLDAPValue( values, attribute )
// .mime.type, .begin_mime_def, .end_mime_def..
// .plat
// alert(message);
// var = prompt(message);
// var = getPlatform()  returns Win32,...
//  getPlatform().contains("UNIX")...
// var = getenv(envvar)
// var = putenv(envvar)
//
// Objects/Functions you *can't* use because they aren't defined
// navigator.* (argh, this *REALLY* bites)
//=========================================================================
// Preferences Configuration
//=========================================================================
with (PrefConfig) {
var values = getLDAPAttributes( "ldap2.int-evry.fr", \
"ou=people,dc=int-evry,dc=fr", "uid="+env_user, "cn,mail" );
var ldap_email =  getLDAPValue(values, "mail");
var ldap_gecos = getLDAPValue(values, "cn");
//var toto = prompt("email");
//alert("ldap_mail = " + ldap_email + "toto="+toto );
if (env_mozdebug) {
 alert("env_user:" + env_user + "\nenv_home:" + env_home + \
"\nldap_email:" + ldap_email + "\nldap_gecos:" + ldap_gecos + "\n");
}
//-----------------------------------------------------------------------
// [ General Browser configuration ]
//-----------------------------------------------------------------------
config( "autoadmin.refresh_interval", 1440); // auto-update every 24 hours
defaultPref("browser.startup.page",1); 
//0=blank page, 1=homepage, 2=last visited
defaultPref("browser.startup.homepage", "http://www/mci/mode-d-emploi.shtml" );
lockPref("browser.cache.directory", "/tmp");
lockPref("browser.cache.memory_cache_size", 0);

lockPref("mail.server_type",1); // POP=0 IMAP=1
lockPref("network.hosts.imap_servers", "pop-int");
lockPref("mail.imap.server.pop-int.using_subscription",true);
lockPref("mail.imap.server.pop-int.userName", env_user);
lockPref("mail.identity.useremail", ldap_email);
lockPref("mail.identity.username", ldap_gecos);
lockPref("mail.check_new_mail", false);
lockPref("mail.directory", env_home+"/nsmail");
lockPref("mail.identity.defaultdomain", "int-evry.fr");
lockPref("mail.identity.organization", "INT Evry Essonne ");

// Ldap
lockPref("ldap_2.autoComplete.useDirectory", true);
lockPref("ldap_2.servers.LDAPINT.autoComplete.enabled", true);
lockPref("ldap_2.servers.LDAPINT.csid", "UTF-8");
lockPref("ldap_2.servers.LDAPINT.description", "LDAP INT");
lockPref("ldap_2.servers.LDAPINT.filename", "LDAPINT.na2");
lockPref("ldap_2.servers.LDAPINT.position", 2);
lockPref("ldap_2.servers.LDAPINT.searchBase", "ou=people,dc=int-evry,dc=fr");
lockPref("ldap_2.servers.LDAPINT.serverName", "ldap1.int-evry.fr");

//news
lockPref("news.directory", "/tmp");
//proxy
lockPref("network.proxy.autoconfig_url", \
"http://www.int-evry.fr/local/config.proxy");

} // with (PrefConfig)

HTMLFOOT ENDHTML FOOTER


Ce document a été traduit de LATEX par <A HREF="http://pauillac.inria.fr/~maranget/hevea/index.html">HEVEA</A>.

</BODY> </HTML>

Revision Source

<p><big><b>Mozilla AutoConfig</b></big>
</p><p><i>Jehan Procaccia MCI INT-EVRY- jehan.procaccia@int-evry.fr</i> 
23 may 2006
</p><p><br>
</p><p><br>
</p>
<blockquote><b>Abstract : </b>
This document is a concret example of a centralized auto-configuration of mozilla suite 1.X.X , firefox <code>&amp;</code> thunderbird, and the the record, old netscape 4.X . Its original inspiration comes from http://www.cs.colorado.edu/~dowdy/netscape_cfg/readme.txt and  http://www.alain.knaff.lu/howto/MozillaCustomization/. It has been recently reordered , putting thunderbird and firefox in the begening, but for history, I've keept mozilla and netscape chapters, that are in certain points complementary, principaly on the web base autoconfig file.</blockquote>
<p><span class="comment">TOC section Situation</span>
</p>
<h3 name=".C2.A0.C2.A0Situation">  Situation</h3><span class="comment">SEC END</span>
<p>INT-Evry (http://www.int-evry.fr/) manages about 2000 users (mostly students) who shares computers in labs and "self service" computer rooms. Hence a single computer might connect many different users all day long. Computers are dualboot (windows XP and Linux Fedora Core 4/5 ). All users have a personal account on a windows server and an LDAP account for linux authentification.
<span class="comment">TOC section Objective</span>
</p>
<h3 name=".C2.A0.C2.A0Objective">  Objective</h3><span class="comment">SEC END</span>
<p>The objective is to provide users with a mailer agent, a web browser, and a news reader which are automatically configured (preferences) at its invocation to the particular user connected at this momment on the computer. Choosing Mozilla products allows us to use the same program either while running Windows or Unix (Linux in our case). 
<br>
Instead of configuring user by user individual preference files (<code>~/.mozilla/default/randomdir/prefs.js</code>) we will centralized defaults preferences. This centralized preference file can lock preferences (<code>lockPref</code>) or initialized them (<code>defaultPref</code>) based on environement variables (<code>USER, HOME ...</code>) and/or LDAP queries (for fetching email address, Common Name etc ...) . <br>
<br>
<span class="comment">TOC section Central configuration file</span>
</p>
<h3 name=".C2.A0.C2.A0Central_configuration_file">  Central configuration file</h3><span class="comment">SEC END</span>
<p>That feature is provided through a javascript file.<br>
<br>
<span class="comment">TOC subsection file location</span>
</p>
<h4 name=".C2.A0.C2.A0file_location">  file location</h4><span class="comment">SEC END</span>
<p><br>
For the old netscape 4.X the file is encoded (byteshift/rotary is 7), and the presence of that file (netscape.cfg) in the MOZILLA_HOME directory sufices for it to be read and executed.
</p><p>For Mozilla 1.X.X , firefox, thunderbird or Netscape7 it is still a javascript file, the byteshift is 13 by default, but can be removed using the <code>pref("general.config.obscure_value", 0);</code> preference in <code>all.js</code>. The name of the file can be anything you want because it is named by a <code>general.config</code> preference that should be added at the end of file <code>MOZILLA_HOME/default/pref/all.js or MOZILLA_HOME/greprefs/all.js</code> : <code>pref(``general.config.filename<i>, ``mozilla.cfg</i>);</code> . <br>
</p><p><br>
<span class="comment">TOC subsection Warnings</span>
</p>
<h4 name=".C2.A0.C2.A0Warnings">  Warnings</h4><span class="comment">SEC END</span>
<p>Beware of the location on the <code>all.js</code> file, <code>all.js</code> file has moved to <code>MOZILLA_HOME/greprefs/all.js</code>, and I noticed the same for thunderbird and firefox ! <br>
</p><p><br>
<span class="comment">TOC subsection file encoding</span>
</p>
<h4 name=".C2.A0.C2.A0file_encoding">  file encoding</h4><span class="comment">SEC END</span>
<p>If needed, the encoding can be done with the perl script: moz-byteshift.pl available at http://www.alain.knaff.lu/howto/MozillaCustomization/moz-byteshift.pl .
For Netscape 4.X the convert fonction from the Client Customization Kit (CCK) could also do that (and other things like personnalize autoinstallation ...): http://developer.netscape.com/docs/manuals/deploymt/config.htm<br>
<br>
</p><p><span class="comment">TOC subsection file API</span>
</p>
<h4 name=".C2.A0.C2.A0file_API">  file API</h4><span class="comment">SEC END</span>
<p>That centralized preference file uses a javascript API that allows us to do what we need. The fonctions available are defined in <code>MOZILLA_HOME/default/autoconfig/prefcalls.js</code>. Actually the presence of <code>pref(``general.config.filename<i>, ``mozilla.cfg</i>);</code> in <code>all.js</code> as described above, enable the read and execution of <code>prefcalls.js</code>.
Avalaible functions are (see file for details):
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
function getPrefBranch() 
function pref(prefName, value) 
function defaultPref(prefName, value)
function lockPref(prefName, value) 
function unlockPref(prefName) 
function getPref(prefName) 
function getLDAPAttributes(host, base, filter, attribs) 
function getLDAPValue(str, key) 
function displayError(funcname, message)
function getenv(name) 
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC section Thunderbird</span>
</p>
<h3 name=".C2.A0.C2.A0Thunderbird">  Thunderbird</h3><span class="comment">SEC END</span>
<p><span class="comment">TOC subsection Support of autoconfig and ldap calls</span>
</p>
<h4 name=".C2.A0.C2.A0Support_of_autoconfig_and_ldap_calls">  Support of autoconfig and ldap calls</h4><span class="comment">SEC END</span>
<p><span class="comment">TOC subsubsection Autoconfig option and ldap support in thunderbird 1.5.X</span>
</p>
<h5 name=".C2.A0.C2.A0Autoconfig_option_and_ldap_support_in_thunderbird_1.5.X">  Autoconfig option and ldap support in thunderbird 1.5.X</h5><span class="comment">SEC END</span>
<p>Fortunatly,autoconfig is now part of thunderbird default packages.
<code> MOZ_LDAP_XPCOM=1 and MOZ_EXTENSIONS_DEFAULT=" wallet spellcheck xmlextras pref webservices universalchardet auth </code> are now present in the default <code>configure</code> script.
see https://bugzilla.mozilla.org/show_bug.cgi?id=295329 for details.<br>
<br>
<span class="comment">TOC subsubsection Add the autoconfig option for old thunderbird 1.0.X</span>
</p>
<h5 name=".C2.A0.C2.A0Add_the_autoconfig_option_for_old_thunderbird_1.0.X">  Add the autoconfig option for old thunderbird 1.0.X</h5><span class="comment">SEC END</span>
<p>By default, autoconfig did not made part of the binaries distribution of thunderbird (1.0.X) . It was apparently supposed to increasing the load of the binary for a feature not used by lots of individuals . Howerver for entrerpise deployement, it is vital !. So we needed to recompile thunderbird with autoconfig support, it's just a matter of adding <code>--enable-extensions=pref</code> in <code>mozconfig</code> file .<br>
<br>
On my fedora core 3 system, I took the thunderbird source package <code>thunderbird-1.0.2-1.3.3.src.rpm</code> installed it (rpm -i) then modified <code>/usr/src/redhat/SOURCES/thunderbird-mozconfig</code> by adding :<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
ac_add_options --enable-extensions=pref
</pre></td>
</tr></tbody></table></div><br>
<p>Compile and install :<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
$ rpmbuild -ba /usr/src/redhat/SPECS/thunderbird.spec
$ rpm -Uvh /usr/src/redhat/RPMS/i386/thunderbird-1.0.2-1.3.3.i386.rpm
</pre></td>
</tr></tbody></table></div><br>
<p>After istallation, autoconfig is finally back here :<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
$ rpm -ql thunderbird | grep autoconfig
/usr/lib/thunderbird-1.0.2/chrome/en-US/locale/autoconfig
/usr/lib/thunderbird-1.0.2/components/autoconfig.xpt
/usr/lib/thunderbird-1.0.2/components/libautoconfig.so
/usr/lib/thunderbird-1.0.2/defaults/autoconfig
/usr/lib/thunderbird-1.0.2/defaults/autoconfig/platform.js
/usr/lib/thunderbird-1.0.2/defaults/autoconfig/prefcalls.js

</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection configure autoconfig</span>
</p>
<h4 name=".C2.A0.C2.A0configure_autoconfig">  configure autoconfig</h4><span class="comment">SEC END</span>
<p>Two directives ask thunderbird to use autoconfig at startup :<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
[root@b008-02 /usr/lib/thunderbird-1.5]
$tail -2 greprefs/all.js
pref("general.config.obscure_value", 0); // for MCD .cfg files
pref('general.config.filename', 'thunderbird.cfg'); // for MCD .cfg files
</pre></td>
</tr></tbody></table></div><br>
<p>the first one just tells that we won't encode the file (no more rotary 13 or 7 ... :-) ), the second one is the name of the file to be read: <code>/usr/lib/thunderbird-1.5/thunderbird.cfg</code>.<br>
</p><p><br>
<span class="comment">TOC subsection Autoconfig directives</span>
</p>
<h4 name=".C2.A0.C2.A0Autoconfig_directives">  Autoconfig directives</h4><span class="comment">SEC END</span>
<p>Here we want to set users central mail preferences: Create one account from their login name, get their email adresse from an ldap request and set the entreprise imap and smtp servers. Hence, when working on multiuser workstations, one person gets automatically thunderbird configured for himself .<br>
<br>
<span class="comment">TOC subsubsection thunderbird.cfg</span>
</p>
<h5 name=".C2.A0.C2.A0thunderbird.cfg">  thunderbird.cfg</h5><span class="comment">SEC END</span>
<p>Here's the complete file, first we get the user login name from environement variables, then configure the ldap adress book , create an mail account, configure imap and smtp : <br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
[root@b008-02 /usr/lib/thunderbird-1.5]
$ cat thunderbird.cfg
//put everything in a try/catch
try {

// 1) env variables
if(getenv("USER") != "") {
   // *NIX settings
   var env_user    = getenv("USER");
   var env_home    = getenv("HOME");
 } else {
   // Windows settings
   var env_user    = getenv("USERNAME");
   var env_home    = getenv("HOMEPATH");
 }
  var env_mozdebug= getenv("MOZILLA_DEBUG");
 // var env_user = prompt("indiquez votre login", toto);

// 2) lock general preferences
//LDAP address book
lockPref("ldap_2.prefs_migrated", true);
lockPref("ldap_2.servers.LDAPINT.auth.savePassword", true);
lockPref("ldap_2.servers.LDAPINT.description", "LDAP INT");
lockPref("ldap_2.servers.LDAPINT.filename", "abook-1.mab");
lockPref("ldap_2.servers.LDAPINT.uri", "ldap://ldap1.int-evry.Fr:389/ou=people,dc=int-evry,dc=fr??sub");
lockPref("ldap_2.servers.history.filename", "history.mab");
lockPref("ldap_2.servers.history.replication.lastChangeNumber", 0);
lockPref("ldap_2.servers.pab.filename", "abook.mab");
lockPref("ldap_2.servers.pab.replication.lastChangeNumber", 0);

//Account
lockPref("mail.account.account1.server", "server1");
lockPref("mail.account.account2.identities", "id1");
lockPref("mail.account.account2.server", "server2");
lockPref("mail.accountmanager.accounts", "account1,account2");
lockPref("mail.accountmanager.defaultaccount", "account2");
lockPref("mail.accountmanager.localfoldersserver", "server1");
lockPref("mail.identity.id1.directoryServer", "ldap_2.servers.LDAPINT");
lockPref("mail.identity.id1.draft_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Drafts");
lockPref("mail.identity.id1.drafts_folder_picker_mode", "0");
lockPref("mail.identity.id1.fcc_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Sent");
lockPref("mail.identity.id1.fcc_folder_picker_mode", "0");
lockPref("mail.identity.id1.organization", "INT Evry France");
lockPref("mail.identity.id1.overrideGlobal_Pref", true);
lockPref("mail.identity.id1.reply_to", "");

//IMAP
lockPref("mail.server.server2.hostname", "imap-int.int-evry.fr");
lockPref("mail.server.server2.isSecure", true);
lockPref("mail.server.server2.login_at_startup", true);
lockPref("mail.server.server2.max_cached_connections", 5);
//lockPref("mail.server.server2.name", "jehan.procaccia@int-evry.fr");
lockPref("mail.server.server2.type", "imap");
lockPref("mail.server.server2.userName", env_user );

//SMTP
lockPref("mail.identity.id1.smtpServer", "smtp1");
lockPref("mail.identity.id1.stationery_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Templates");
lockPref("mail.identity.id1.tmpl_folder_picker_mode", "0");
lockPref("mail.identity.id1.valid", true);

//SMTP general
lockPref("mail.smtp.defaultserver", "smtp1");
lockPref("mail.smtpserver.smtp1.auth_method", 0);
lockPref("mail.smtpserver.smtp1.hostname", "smtp-int.int-evry.fr");
lockPref("mail.smtpserver.smtp1.port", 25);
lockPref("mail.smtpserver.smtp1.try_ssl", 0);
lockPref("mail.smtpserver.smtp1.username", "");
lockPref("mail.smtpservers", "smtp1");
lockPref("mail.startup.enabledMailCheckOnce", true);
lockPref("mailnews.quotingPrefs.version", 1);
lockPref("mailnews.ui.threadpane.version", 5);

/* 3) define here (because if set after "4)" below it doesn't work !) processLDAPValues which is eventually called by getLDAPAttributes() just below,
 check getLDAPAttributes() code from $MOZILLA_HOME/defaults/autoconfig/prefcalls.js to see the inside call to "user defined" processLDAPValues
*/
function processLDAPValues (values) {
 if(values) {
      // set the global var with the values returned from the LDAP query
      ldap_values = values;
    var uid = getLDAPValue ( values ,"uid" );
    var cn = getLDAPValue ( values ,"cn" );
    var mail = getLDAPValue ( values ,"mail" );
    var URL =  getLDAPValue ( values ,"labeledURI" );

// Those ldap variables are only available is this processLDAPValues context !
// so we set the preferences that need them here .
lockPref("mail.identity.id1.useremail", mail);
lockPref("mail.server.server2.name", mail );
lockPref("mail.identity.id1.fullName", cn );
//Debug with popup error messages doesn't work anymore :-( !!
var env_mozdebug= getenv("MOZILLA_DEBUG");
if (env_mozdebug) {displayError("NO ERROR , just a debug, cn =" + cn + " and mail = " + mail ); }
    }
  }
// 4) Call Ldap servers to get Ldap Attributes (mail &amp; cn) , this will finally call processLDAPValues , "3)" just above.
  getLDAPAttributes("ldap2.int-evry.fr","ou=people,dc=int-evry,dc=fr","uid=" + env_user,"uid,cn,mail,labeledURI");

// Close the try, and call the catch()
} catch(e) {
  displayError("lockedPref", e);
}

</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsubsection Test autoconfig</span>
</p>
<h5 name=".C2.A0.C2.A0Test_autoconfig">  Test autoconfig</h5><span class="comment">SEC END</span>
<p><span class="comment">TOC paragraph Debug</span>
</p>
<h6 name="Debug">Debug</h6><span class="comment">SEC END</span>
<p>To check that our autoconfig works fine, we just set to env variable to check the read of thunderbird.cfg file:<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
$ export NSPR_LOG_MODULES=MCD:5
$ export NSPR_LOG_FILE=/tmp/thunderbird-log.txt
</pre></td>
</tr></tbody></table></div>When thunderbird has started , you should read:<br>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
 $ cat /tmp/thunderbird-log.txt
-1209403040[808a788]: general.config.filename = thunderbird.cfg
-1209403040[808a788]: evaluating .cfg file thunderbird.cfg with obscureValue 0
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC paragraph Clean</span>
</p>
<h6 name="Clean">Clean</h6><span class="comment">SEC END</span>
<p>Then, to be sure to start with a fresh thunderbird account , don't do that if you already have one and want to preserve you mails and preferences !!<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
$ rm -rf ~/.thunderbird
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC paragraph Start it</span>
</p>
<h6 name="Start_it">Start it</h6><span class="comment">SEC END</span>
<p><br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>

$ thunderbird
</pre></td>
</tr></tbody></table></div>If thunderbird ask you to import your profile from netscape/mozilla depending on you mail client history, don't import anything, to check the autoconfig job alone !.
<p><br>
That should work, just restart the process by setting a different USER variable (USER=procacci, USER=test etc... anyone in you ldap directory ...) to check multiuser autoconfig . <br>
<span class="comment">TOC subsection Bugs reports related</span>
</p>
<h4 name=".C2.A0.C2.A0Bugs_reports_related">  Bugs reports related</h4><span class="comment">SEC END</span>
<p>for the record, for old 1.0.X releases ...<br>
<br>
<span class="comment">TOC subsubsection Unwanted white space reappeared</span>
</p>
<h5 name=".C2.A0.C2.A0Unwanted_white_space_reappeared">  Unwanted white space reappeared </h5><span class="comment">SEC END</span>
<p>Unfortunatly the 'blank space bug' has reapered in thunderbird 1.0.2 . see:<br>
&lt;A HREF="https://bugzilla.mozilla.org/show_bug.cgi?id=229271"&gt;<tt>https://bugzilla.mozilla.org/show_bug.cgi?id=229271</tt>&lt;/A&gt;
<br>
Although it was corected in mozilla mainstream :
<code>ozilla/extensions/pref/autoconfig/src/nsLDAPSyncQuery.cpp 1.7.2.1</code> by late 2004, it is still present in thunderbird 1.0.2 at least :-( , so I applied the workaround I proposed in that bug report (<code>start_pos </code>=1;+).<br>
<br>
</p><p><span class="comment">TOC section Firefox</span>
</p>
<h3 name=".C2.A0.C2.A0Firefox">  Firefox</h3><span class="comment">SEC END</span>
<p>It's the same principle as above for thunderbird. Binaries ditributions now include support for autoconfig (pref extension !) but unfortunatly not for ldap calls :-( (cf <code>MOZ_LDAP_XPCOM=1</code>) . It is not vital in firefox as it is for us in thunderbird (need to get the cn and email address to set email account, which are not available by default in the environement viriables ). However I could be usefull to get ldap values for firefox extra config , for example to set the default homepage to the <code>labeledURI</code> ldap attribute of the user.<br>
<br>
<span class="comment">TOC subsection Autoconfig (pref) and ldap support in packages</span>
</p>
<h4 name=".C2.A0.C2.A0Autoconfig_.28pref.29_and_ldap_support_in_packages">  Autoconfig (pref) and ldap support in packages</h4><span class="comment">SEC END</span>
<p><span class="comment">TOC subsubsection Add ldap support in firefox 1.5</span>
</p>
<h5 name=".C2.A0.C2.A0Add_ldap_support_in_firefox_1.5">  Add ldap support in firefox 1.5</h5><span class="comment">SEC END</span>
<p>A least from firefox 1.5, autonfig is compiled by default (cf browser, <code>MOZ_EXTENSIONS_DEFAULT="pref..."</code>) but not ldap (<code>MOZ_LDAP_XPCOM=1</code>) . You need to recompile the package to get it, cf https://bugzilla.mozilla.org/show_bug.cgi?id=295329 .<br>
<br>
</p><p><span class="comment">TOC subsubsection Add autoconfig and ldap support in firefox 1.0.X</span>
</p>
<h5 name=".C2.A0.C2.A0Add_autoconfig_and_ldap_support_in_firefox_1.0.X">  Add autoconfig and ldap support in firefox 1.0.X</h5><span class="comment">SEC END</span>
<p>Add pref extension (--enable-extensions=pref) and remove --disable-ldap from mozconfig file . One can check how firefox has been compiled by opening <code>about:buildconfig</code> (don't know the equivalent for thunderbird!, how as it been compile ??)<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
about:buildconfig

Build platform
target
i686-pc-linux-gnu

Build tools
Compiler  Version  Compiler flags
gcc  gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.fc3)  -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -pthread -pipe
c++  gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.fc3)  -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wno-long-long -pedantic -fshort-wchar -pthread -pipe -I/usr/X11R6/include

Configure arguments
--disable-mailnews --enable-extensions=cookie,xml-rpc,xmlextras,pref,transformiix,universalchardet,webservices,inspector,gnomevfs,negotiateauth --enable-crypto --disable-composer --enable-single-profile --disable-profilesharing --with-system-jpeg --with-system-zlib --with-system-png --with-pthreads --disable-tests --disable-jsd --disable-installer '--enable-optimize=-Os -g -pipe -m32 -march=i386 -mtune=pentium4' --enable-xft --enable-xinerama --enable-default-toolkit=gtk2 --enable-official-branding --disable-xprint --disable-strip --enable-pango 
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection all.js</span>
</p>
<h4 name=".C2.A0.C2.A0all.js">  all.js</h4><span class="comment">SEC END</span>
<p><br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
[root@b008-02 /usr/lib/firefox-1.5.0.2]
$tail -4 greprefs/all.js
// autoconfig jehan
pref('general.config.obscure_value', 0);
pref('general.config.filename', 'firefox.cfg');
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection firefox.cfg</span>
</p>
<h4 name=".C2.A0.C2.A0firefox.cfg">  firefox.cfg</h4><span class="comment">SEC END</span>
<p>This file will set the browser home page to the labeledURI page defined in the user's ldap entry , hence it both check that autoconfig + ldap works fine .<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
[root@b008-02 /usr/lib/firefox-1.5.0.2]
$cat firefox.cfg
//put everything in a try/catch
try {

//Privacy &amp; Security
defaultPref("signon.rememberSignons", false);

// 1) env variables
if(getenv("USER") != "") {
   // *NIX settings
   var env_user    = getenv("USER");
   var env_home    = getenv("HOME");
 } else {
   // Windows settings
   var env_user    = getenv("USERNAME");
   var env_home    = getenv("HOMEPATH");
 }
  var env_mozdebug= getenv("MOZILLA_DEBUG");

/* 2) define here (because if set after "3)" below it doesn't work !) processLDAPValues which is eventually called by getLDAPAttributes() just below,
 check getLDAPAttributes() code from $MOZILLA_HOME/defaults/autoconfig/prefcalls.js to see the inside call to "user defined" processLDAPValues
*/
function processLDAPValues (values) {
 if(values) {
      // set the global var with the values returned from the LDAP query
      ldap_values = values;
    var uid = getLDAPValue ( values ,"uid" );
    var cn = getLDAPValue ( values ,"cn" );
    var mail = getLDAPValue ( values ,"mail" );
    var URL =  getLDAPValue ( values ,"labeledURI" );
//Debug with popup error messages doesn't work anymore :-( !!
var env_mozdebug= getenv("MOZILLA_DEBUG");
if (env_mozdebug) {displayError("NO ERROR , just a debug, cn =" + cn + " and mail = " + mail + " ,labeledURI= " + URL ); }
lockPref("browser.startup.homepage", URL );
    }
  }

//lockPref("browser.startup.homepage", "http://www.renater.fr/" );
// 3) Call Ldap servers to get Ldap Attributes (mail &amp; cn) , this will finally call processLDAPValues , "2)" just above.
  getLDAPAttributes("ldap2.int-evry.fr","ou=people,dc=int-evry,dc=fr","uid=" + env_user,"uid,cn,mail,labeledURI");

// Close the try, and call the catch()
} catch(e) {displayError("lockedPref", e);}

</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection Debug</span>
</p>
<h4 name=".C2.A0.C2.A0Debug">  Debug</h4><span class="comment">SEC END</span>
<p>If you set a username and the <code>MOZILLA_DEBUG</code> variable (<code>$export MOZILLA_DEBUG=1; export USER=procacci</code>), then the <code>displayError()</code> will show you this popup :<br>
</p>
<div align="center">&lt;IMG SRC="mozilla-autoconfig-en001.png"&gt;</div><br>
<p>That's a popup titled as ``error<i>, but it's just a debug tool for me as I didn't find any other way to popup information. cf &lt;A HREF="https://bugzilla.mozilla.org/show_bug.cgi?id=206294"&gt;<tt>https://bugzilla.mozilla.org/show_bug.cgi?id=206294</tt>&lt;/A&gt; :<br></i>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
 ------- Comment #14 From Daniel Wang 2003-11-06 09:06 PDT [reply] -------

Jehan Procaccia, you need to change 5.8 to reflect what I said in comment 21.

Preference files and config files are special js files with limited scopes. They
can only call the get/set pref/env methods and have no access to other objects
(need to investigate what exactly are allowed). alert() is a method of the
Window object.
</pre></td>
</tr></tbody></table></div><br>
<p>cf also related post in Newsgroups: mozilla.dev.tech.js-engine<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
Date: Wed, 17 May 2006 19:06:28 +0200
From: jehan procaccia &lt;jehan.procaccia@int-evry.fr&gt;

Newsgroups: mozilla.dev.tech.js-engine
Subject: scope of js file functions in firefox/thunderbird autoconfig context
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC section Referecences</span>
</p>
<h3 name=".C2.A0.C2.A0Referecences">  Referecences</h3><span class="comment">SEC END</span>
<p><span class="comment">TOC subsection Other docs about autoconfig</span>
</p>
<h4 name=".C2.A0.C2.A0Other_docs_about_autoconfig">  Other docs about autoconfig</h4><span class="comment">SEC END</span>
<p>http://mit.edu/~firefox/www/maintainers/autoconfig.html<br>
</p><p>http://www.alain.knaff.lu/howto/MozillaCustomization/index.html<br>
http://thegoldenear.org/toolbox/windows/docs/mozilla-pre-config.html<br>
http://ilias.ca/blog/2005/03/locking-mozilla-firefox-settings.html<br>
<br>
compile on windows :<br>
http://forums.mozillazine.org/viewtopic.php?t=276014<br>
<br>
http://www.mozilla.org/community/developer-forums.html<br>
http://forums.mozillazine.org/viewtopic.php?p=2090731&amp;highlight=autoconfig#2090731<br>
http://forums.mozillazine.org/viewtopic.php?p=1354355&amp;highlight=autoconfig#1354355<br>
http://forums.mozillazine.org/viewtopic.php?p=32783&amp;highlight=autoconfig#32783<br>
<span class="comment">TOC subsection Related bugzilla</span>
</p>
<h4 name=".C2.A0.C2.A0Related_bugzilla">  Related bugzilla</h4><span class="comment">SEC END</span>
<p>https://bugzilla.mozilla.org/show_bug.cgi?id=295329<br>
https://bugzilla.mozilla.org/show_bug.cgi?id=222973<br>
https://bugzilla.mozilla.org/show_bug.cgi?id=225288<br>
https://bugzilla.mozilla.org/show_bug.cgi?id=178685<br>
</p><p>https://bugzilla.mozilla.org/show_bug.cgi?id=272970<br>
https://bugzilla.mozilla.org/show_bug.cgi?id=206294<br>
https://bugzilla.mozilla.org/show_bug.cgi?id=302096<br>
<span class="comment">TOC section OLD Mozilla1.X, possibly Netscape 6/7</span>
</p>
<h3 name=".C2.A0.C2.A0OLD_Mozilla1.X.2C_possibly_Netscape_6.2F7">  OLD Mozilla1.X, possibly Netscape 6/7 </h3><span class="comment">SEC END</span>
<p>The following is for the record ... it also contain an interesting feature that I did not use anymore -&gt; autoconfig from an web server !<br>
<br>
</p><p><span class="comment">TOC subsection Changes</span>
</p>
<h4 name=".C2.A0.C2.A0Changes">  Changes</h4><span class="comment">SEC END</span>
<p>Between 2002 and 2003, we needed to upgrade the old netscape 4.X (4.79) version to Mozilla 1.X (1.4), and now (2004-2005) mozilla 1.7. The autoconfiguration subsystem is quite the same as described the section on 'old' Netscape 4.X , but also slightly different. <br>
<br>
<span class="comment">TOC subsection Mozilla new features in regard to netscape</span>
</p>
<h4 name=".C2.A0.C2.A0Mozilla_new_features_in_regard_to_netscape">  Mozilla new features in regard to netscape</h4><span class="comment">SEC END</span>
<p>In Mozilla, we don't use anymore the convert function from netscape 4.5 CCK, but <code>moz-byteshift.pl</code> perl script, to encode <code>mozilla.cfg</code> file.<br>
</p><p>The use of the <code>getLDAPAttributes()</code> function by calling inside itself the processLDAPValues() as a user defined function (see prefcalls.js) forces us to slighlty change these calls in our original web-cgi javascript (here <code>mci-mozilla-glob-prefs-tux.cgi</code> ). The variable generated (mail, cn , uid) are defined only inside the processLDAPValues() function, that explains why lockPref related to these variables are located inside that function. I also couldn't use anymore the alert() fonction, so I changed to displayerror() function !<br>
<br>
<span class="comment">TOC subsection Locating the file on a web server</span>
</p>
<h4 name=".C2.A0.C2.A0Locating_the_file_on_a_web_server">  Locating the file on a web server</h4><span class="comment">SEC END</span>
<p>That was the case in the Netscape 4.X description above, however, it first was a hard thing to do in Mozilla , cf bug report: &lt;A HREF="http://bugzilla.mozilla.org/show_bug.cgi?id=206294"&gt;<tt>http://bugzilla.mozilla.org/show_bug.cgi?id=206294</tt>&lt;/A&gt;. So now you only need to create a small encoded <code> cfg </code> file making a call to a web located cgi script which will actually generate the javascript configuration directives to the mozilla client. Hence you can change all of your mozilla clients preferences by simply modifying a single file on a web server, great !. <br>
</p><p><br>
<span class="comment">TOC subsubsection Call file</span>
</p>
<h5 name=".C2.A0.C2.A0Call_file">  Call file</h5><span class="comment">SEC END</span>
<p>This file calls a cgi on a web server, the cgi generating the javascript code that will set preferences. Here the <code> vendor</code> name (mci-mozilla-web-tux) must match the name of the <code> cfg </code> file (mci-mozilla-web-tux.cfg).<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
$ cat mci-mozilla-web-tux.js
lockPref("general.config.vendor", "mci-mozilla-web-tux");
lockPref("autoadmin.global_config_url","http://corbeau.int-evry.fr/cgi-bin/mci-mozilla-glob-prefs-tux.cgi");
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection Encoding mozilla.js file to mozilla.cfg</span>
</p>
<h4 name=".C2.A0.C2.A0Encoding_mozilla.js_file_to_mozilla.cfg">  Encoding mozilla.js file to mozilla.cfg</h4><span class="comment">SEC END</span>
<p>Just use the moz-byteshift.pl perl script which for mozilla1.X and Netscape 6/7 uses a shift of 13, in netscape 4.X it was 7.<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
$ more moz-byteshift.pl
#!/usr/bin/perl
 
# Byteshifting program for mozilla's netscape.cfg files
 
# Old netscape 4.x uses a bytechift of 7
#   To decode: moz-byteshift.pl -s -7 &lt;netscape.cfg &gt;netscape.cfg.txt
#   To encode: moz-byteshift.pl -s  7 &lt;netscape.cfg.txt &gt;netscape.cfg
 
# Mozilla uses a byteshift of 13
#   To decode: moz-byteshift.pl -s -13 &lt;netscape.cfg &gt;netscape.cfg.txt
#   To encode: moz-byteshift.pl -s  13 &lt;netscape.cfg.txt &gt;netscape.cfg
 
# To activate the netscape.cfg file, place the encoded netscape.cfg file
# into your C:\Program Files\mozilla.org\Mozilla directory.
# Then add the following line to your
# C:\Program Files\mozilla.org\Mozilla\defaults\pref\all.js file :
# pref("general.config.filename", "mozilla.cfg");
...

$ ./moz-byteshift.pl -s 13 &lt; mci-mozilla-web-tux.js &gt; mci-mozilla-web-tux.cfg

</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection Location of mci-mozilla-web-tux.cfg</span>
</p>
<h4 name=".C2.A0.C2.A0Location_of_mci-mozilla-web-tux.cfg">  Location of mci-mozilla-web-tux.cfg </h4><span class="comment">SEC END</span>
<p>The location of the <code>netscape.cfg</code> (here renamed to mci-mozilla-web-tux.cfg) and the way to call it is different from the old netscape 4.X. It's location is in <code>MOZILLA_HOME ; c:\program files\mozilla.org\mozilla</code> in windows, or <code>/usr/lib/mozilla-1.7-3/</code> in linux Fedora. <br>
</p><p><br>
<span class="comment">TOC subsection Call to mci-mozilla-web-tux.cfg</span>
</p>
<h4 name=".C2.A0.C2.A0Call_to_mci-mozilla-web-tux.cfg">  Call to mci-mozilla-web-tux.cfg </h4><span class="comment">SEC END</span>
<p>The way to call it is through <code>all.js</code> file by adding at the end:<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
$ tail -2 /usr/lib/mozilla-1.7-3/defaults/pref/all.js
pref("general.config.filename", "mci-mozilla-web-tux.cfg");
pref("general.config.vendor", "mci-mozilla-web-tux");
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection Web base cgi javascript preferences generator file</span>
</p>
<h4 name=".C2.A0.C2.A0Web_base_cgi_javascript_preferences_generator_file">  Web base cgi javascript preferences generator file</h4><span class="comment">SEC END</span>
<p><br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
[root@corbeau /var/www/cgi-bin]
$ cat mci-mozilla-glob-prefs-tux.cgi
#!/usr/bin/perl -w
  
print ("Content-type: application/x-javascript-config\n\n");
$page = &lt;&lt;"EOP";
 
try {
  var env_user    = getenv("USER");
  var env_home    = getenv("HOME");
  var env_mozdebug= getenv("MOZILLA_DEBUG");
function processLDAPValues (values) {
    var uid = getLDAPValue ( values , "uid" );
    var cn = getLDAPValue ( values , "cn" );
    var mail = getLDAPValue ( values , "mail" );
lockPref("mail.server.server1.name", mail );
lockPref("mail.identity.id1.fullName", cn);
lockPref("mail.identity.id1.useremail", mail);
  
if (env_mozdebug) {
        displayError("debug mozilla.cfg v2.8", "mail:" + mail + "uid:" + uid + "cn" + cn + "user:" + env_user );
        } 
  }
//BROWSER
/*defaultPref("startup.homepage_override_url", "http://www.int-evry.fr/mci/user/");
lockPref("browser.startup.homepage_override", true);
lockPref("browser.startup.page", 1);
defaultPref("browser.startup.homepage", "http://www.int-evry.fr/mci/user/");
*/
lockPref("browser.startup.homepage", "http://www.int-evry.fr/mci/user/");
lockPref("browser.startup.homepage_override", true);
lockPref("general.config.vendor", "mci-mozilla-web-tux");
lockPref("startup.homepage_override_url", "http://www.int-evry.fr/mci/user/");
lockPref("browser.cache.disk.capacity", 0);
lockPref("network.cookie.cookieBehavior", 0);
lockPref("network.proxy.autoconfig_url", "http://www.int-evry.fr/local/config.proxy");
lockPref("network.proxy.type", 2);
 
//Account
lockPref("mail.account.account1.identities", "id1");
lockPref("mail.account.account1.server", "server1");
lockPref("mail.account.account2.server", "server2");
lockPref("mail.account.account3.server", "server3");
lockPref("mail.accountmanager.accounts", "account1,account2,account3");
lockPref("mail.accountmanager.defaultaccount", "account1");
 
//imap
lockPref("mail.server.server1.hostname", "imap-int.int-evry.fr");
lockPref("mail.server.server1.type", "imap");
lockPref("mail.server.server1.login_at_startup", true);
lockPref("mail.identity.id1.draft_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Drafts");
lockPref("mail.identity.id1.drafts_folder_picker_mode", "0");
lockPref("mail.identity.id1.fcc_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Sent");
lockPref("mail.identity.id1.fcc_folder_picker_mode", "0");
lockPref("mail.identity.id1.stationery_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Templates");
lockPref("mail.identity.id1.tmpl_folder_picker_mode", "0");
lockPref("mail.identity.id1.valid", true);
lockPref("mail.identity.id1.overrideGlobal_Pref", true);
lockPref("mail.server.server1.download_on_biff", true);
lockPref("mail.server.server1.login_at_startup", true);
lockPref("mail.server.server1.userName", env_user );
lockPref("mail.server.server1.delete_model", 0);
 
//SMTP
lockPref("mail.identity.id1.smtpServer", "smtp1");
defaultPref("mail.smtpserver.smtp1.auth_method", 0);
lockPref("mail.smtpservers", "smtp1");
lockPref("mail.smtpservers", "smtp1");
lockPref("mail.smtp.defaultserver", "smtp1");
lockPref("mail.smtpserver.smtp1.hostname", "smtp-int.int-evry.fr");
lockPref("mail.identity.id1.organization", "INT Evry France");
lockPref("mail.startup.enabledMailCheckOnce", true);
lockPref("mail.ui.folderpane.version", 3);
lockPref("mailnews.ui.threadpane.version", 2);
 
//LDAP config
lockPref("mail.identity.id1.directoryServer", "ldap_2.servers.ldapint");
lockPref("ldap_2.prefs_migrated", true);
lockPref("ldap_2.servers.history.filename", "history.mab");
lockPref("ldap_2.servers.history.replication.lastChangeNumber", 0);
lockPref("ldap_2.servers.ldapint.auth.savePassword", true);
lockPref("ldap_2.servers.ldapint.description", "ldap-int");
lockPref("ldap_2.servers.ldapint.filename", "abook-1.mab");
lockPref("ldap_2.servers.ldapint.position", 3);
lockPref("ldap_2.servers.ldapint.uri", "ldap://ldap1.int-evry.fr:389/ou=people,dc=int-evry,dc=fr??sub");
lockPref("ldap_2.servers.pab.filename", "abook.mab");
lockPref("ldap_2.servers.pab.replication.lastChangeNumber", 0);
 
//News config
lockPref("mail.server.server3.hostname", "news.int-evry.fr");
lockPref("mail.server.server3.max_cached_connections", 2);
lockPref("mail.server.server3.name", "news.int-evry.fr");
lockPref("mail.server.server3.type", "nntp");
lockPref("mail.server.server3.userName", env_user );
 
//Call to ldap to get user's attribute .
getLDAPAttributes ( "ldap2.int-evry.fr", "ou=people,dc=int-evry,dc=fr", "uid=" +env_user , "uid,cn,mail" );
 
} catch(e) {
  displayError("lockedPref", e);
}
 
EOP
print $page;
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection Windows particularities</span>
</p>
<h4 name=".C2.A0.C2.A0Windows_particularities">  Windows particularities</h4><span class="comment">SEC END</span>
<p>Without web base cgi file, beware that in windows, the original (before encoding) mozilla.js file must start with: <code>//BEGIN CE prefs </code> , if not you'll get ``failed to read configuration file ...<i> message, and mozilla won't start :-( .<br></i>
In Windows environement variables like USER or HOME, are USERNAME and HOMEPATH, that's why we must create a different pair of configuration files (cfg and cgi) for both systems (linux/windows). Perhaps there's a way in javascript to dectect operating system and hence use either USER or USERNAME, but I'am not that fluent in javascript to do that, let me know if you know ...//<br>
<br>
<span class="comment">TOC subsubsection Windows Call file</span>
</p>
<h5 name=".C2.A0.C2.A0Windows_Call_file">  Windows Call file</h5><span class="comment">SEC END</span>
<p><br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>

$ cat mci-mozilla-web-win.js
lockPref("general.config.vendor", "mci-mozilla-web-win");
lockPref("autoadmin.global_config_url","http://corbeau.int-evry.fr/cgi-bin/mci-mozilla-glob-prefs-win.cgi");
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsubsection Windows all.js file</span>
</p>
<h5 name=".C2.A0.C2.A0Windows_all.js_file">  Windows all.js file</h5><span class="comment">SEC END</span>
<p>To be encoded by moz-byteshift.pl as stated above ...<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
c:\type c:\program files\mozilla.org\mozilla\defaults\pref\all.js
pref("general.config.filename", "mci-mozilla-web-win.cfg");
pref("general.config.vendor", "mci-mozilla-web-win");
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsubsection Windows cgi file</span>
</p>
<h5 name=".C2.A0.C2.A0Windows_cgi_file">  Windows cgi file</h5><span class="comment">SEC END</span>
<p><br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
$ cat mci-mozilla-glob-prefs-win.cgi
#!/usr/bin/perl -w
  
print ("Content-type: application/x-javascript-config\n\n");
$page = &lt;&lt;"EOP";
 
try {
  var env_user    = getenv("USERNAME");
  var env_home    = getenv("HOMEPATH");
  var env_mozdebug= getenv("MOZILLA_DEBUG");
...
</pre></td>
</tr></tbody></table></div><br>
<p>The rest of the file is identical to the linux version, only env var are different !.<br>
<br>
<span class="comment">TOC subsection Versions tested</span>
</p>
<h4 name=".C2.A0.C2.A0Versions_tested">  Versions tested</h4><span class="comment">SEC END</span>
<p>This configuration was validated on linux with mozilla 1.4 , 1.6 and 1.7, and on windows with mozilla 1.4, 1.5, 1.7.<br>
<br>
<span class="comment">TOC section Debuging - bugzilla</span>
</p>
<h3 name=".C2.A0.C2.A0Debuging_-_bugzilla">  Debuging - bugzilla</h3><span class="comment">SEC END</span>
<p><span class="comment">TOC subsection Run time messages</span>
</p>
<h4 name=".C2.A0.C2.A0Run_time_messages">  Run time messages</h4><span class="comment">SEC END</span>
<p>Notice the presence of <code>var env_mozdebug=getenv("MOZILLA_DEBUG")</code> which allows use to print debugging messages if <code>MOZILLA_DEBUG</code> is define either in shell for unix (<code>export MOZILLA_DEBUG=1</code>) or in command.com environement in windows (<code>set MOZILLA_DEBUG=1</code>)<br>
</p><p><br>
<span class="comment">TOC subsection Blank space bug</span>
</p>
<h4 name=".3CA_NAME.3D.22htoc44.22.3E8.2.3C.2FA.3E.C2.A0.C2.A0Blank_space_bug">&lt;A NAME="htoc44"&gt;8.2&lt;/A&gt;  Blank space bug</h4><span class="comment">SEC END</span>
<p>I noticed a problem which is due to be corrected in 1.8 I think ...
here's the report and workaround:
http://bugzilla.mozilla.org/show_bug.cgi?id=229271
in short add the following :
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
        start_pos += search_key.length;
//start 
        start_pos +=1;
//end
</pre></td>
</tr></tbody></table></div>to function <code>getLDAPValue()</code> in <code>autoconfig/preffcalls.js</code>.<br>
<p><br>
<span class="comment">TOC subsection Documentation</span>
</p>
<h4 name=".C2.A0.C2.A0Documentation">  Documentation</h4><span class="comment">SEC END</span>
<p>I also opened a report on the lack of documentation:
http://bugzilla.mozilla.org/show_bug.cgi?id=178685
which ended to the wonderfull doc: http://wangrepublic.org/daniel/mozilla/prefs/ <br>
<br>
<span class="comment">TOC subsection defeultPref for homepage</span>
</p>
<h4 name=".C2.A0.C2.A0defeultPref_for_homepage">  defeultPref for homepage</h4><span class="comment">SEC END</span>
<p>I cannot set the homepage with the defaultPref function, so that is is set by default, but still allow the user to change it !. A bugzilla is openned on this, see https://bugzilla.mozilla.org/show_bug.cgi?id=272970 <br>
<span class="comment">TOC subsection greprefs right access</span>
</p>
<h4 name=".C2.A0.C2.A0greprefs_right_access">  greprefs right access</h4><span class="comment">SEC END</span>
<p>Beware also on Linux that <code>MOZILLA_HOME/greprefs</code> directory is closed by default to users and then autoconfig doesn't work properly, I 've opened a bugzilla on this: &lt;A HREF="https://bugzilla.mozilla.org/show_bug.cgi?id=270623"&gt;<tt>https://bugzilla.mozilla.org/show_bug.cgi?id=270623</tt>&lt;/A&gt;.
Workaround -&gt; <code>chmod 755 greprefs</code> !.<br>
</p><p><br>
<span class="comment">TOC subsection cgi base config file</span>
</p>
<h4 name=".C2.A0.C2.A0cgi_base_config_file">  cgi base config file</h4><span class="comment">SEC END</span>
<p>there has been a issue about the use of <code>autoadmin.global_config_url</code>, see :<br>
http://bugzilla.mozilla.org/show_bug.cgi?id=206294<br>
<span class="comment">TOC section Mail folders</span>
</p>
<h3 name=".C2.A0.C2.A0Mail_folders">  Mail folders</h3><span class="comment">SEC END</span>
<p>Implementing that solution, we encounter difficulties with mail folder. First idea was to use local mail fodlers from homedirectory of the current user. In unix that would have been <code>$HOME/nsmail/...</code> , in windows it would have been a samba mount of that same unix path (ex: <code>U:\nsmail</code> ; with <code>U:</code> =samba mount: <code>\\samba-server\%USERNAME</code>). Unfortunaltly file system writes and/or mail format differs between windows and unix, and folders becomes soon unreadable or even corrupted when read/written from one system and then the other.
That's why we finally decided to use IMAP, and hence imap folders. By migrating from University of Whashinghton IMAP server to Cyrus IMAP we also inherited some intersting features like quotas, share folders, ACL, mail only account (no need for /etc/passwd entry !) much better performances, etc ...<br>
<br>
<span class="comment">TOC section reliabilty</span>
</p>
<h3 name=".C2.A0.C2.A0reliabilty">  reliabilty</h3><span class="comment">SEC END</span>
<p><span class="comment">TOC subsection failover and uniqueness</span>
</p>
<h4 name=".C2.A0.C2.A0failover_and_uniqueness">  failover and uniqueness</h4><span class="comment">SEC END</span>
<p>A contribution from Roberto Aguilar gives to the mozilla autoconfig javascript a way to search through different ldap replicas in case one ldap server is down.
It also allow us to use a single javscript for both systems (Linux and Windows) with a subtule <code>if ... else</code> test on environement variables.<br>
<br>
<span class="comment">TOC subsection Ldap failover</span>
</p>
<h4 name=".C2.A0.C2.A0Ldap_failover">  Ldap failover</h4><span class="comment">SEC END</span>
<p>Creating an array of possible running ldap servers permits an ldap failover, then a shuffle function allows us to randomly pick up a running ldap server.<br>
<br>
The suffle function comes from here:
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
http://www.mickweb.com/javascript/arrays/pureshuffle.html

Before publishing the code changes, please add this right before the shuffle function:

 /**
  * setup the shuffle method for an array, from "mickweb script
  * factory" at:
  * http://www.mickweb.com/javascript/arrays/pureshuffle.html
  */
</pre></td>
</tr></tbody></table></div><br>
<p>Here's how the ldap failover works:<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
// 2) setup multiple LDAP servers for failover
  var ldap_values;
  var ldap_servers = new Array('ldap2.int-evry.fr',
                      'ldap1.int-evry.fr',
                      'openldap.int-evry.fr'
                      );
  // shuffle function to randomize the server array
  // setup the shuffle method for an array
  Array.prototype.shuffle = function(times) {
    var i,j,t,l=this.length;
    while(times--) {
      with(Math) {
    i = floor(random()*l);
    j = floor(random()*l);
      }
      t       = this[i];
      this[i] = this[j];
      this[j] = t;
    }
    return this;
  }
 // mix up the ldap servers so we don't hit the same one each time
  ldap_servers.shuffle(10);
....
// 4) Call Ldap servers to get Ldap Attributes (mail &amp; cn) , this will finally call processLDAPValues , "3)" just above.
// Go through the ldap replicas list
for(i = 0; i &lt; ldap_servers.length; i ++) {
// Search for attribute mail &amp; cn through ldap servers where uid = $USER|$USERNAME
  getLDAPAttributes(ldap_servers[i],
       "ou=people,dc=int-evry,dc=fr",
       "uid=" + env_user,
       "uid,cn,mail");
    // If we catch a running ldap server, exit the loop,
    if(ldap_values) {
      running_ldap_server = ldap_servers[i];
        // If $MOZILLA_DEBUG=1 display in a popup the running server
      if (env_mozdebug) {
        displayError("getLDAPAttributes: debug 2 running_ldap_server : " + running_ldap_server);
       }
      break;
    }
  }

</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection Unique script for windows and linux</span>
</p>
<h4 name=".C2.A0.C2.A0Unique_script_for_windows_and_linux">  Unique script for windows and linux</h4><span class="comment">SEC END</span>
<p>an <code> if ... else</code> test permits us to check wether we use linux or windows environement variable for the <code>USER / USERNAME</code><br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
// 1) env variables
if(getenv("USER") != "") {
   // *NIX settings
   var env_user    = getenv("USER");
   var env_home    = getenv("HOME");
 } else {
   // Windows settings
   var env_user    = getenv("USERNAME");
   var env_home    = getenv("HOMEPATH");
 }
  var env_mozdebug= getenv("MOZILLA_DEBUG");
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection Final production script</span>
</p>
<h4 name=".C2.A0.C2.A0Final_production_script">  Final production script</h4><span class="comment">SEC END</span>
<p>Here's the complete final and commented production script:<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
//Mozilla autoconfiguration, Jehan Procaccia &amp; Roberto Aguilar
 
//put everything in a try/catch
try {
/*
1) define environement variables,
2) list &amp; randomize ldap replicas,
3) define processLDAPValues(),
4) Call Ldap server to get Ldap Attributes (mail &amp; cn) getLDAPAttributes()
5) set user preferences
*/
 
// 1) env variables
if(getenv("USER") != "") {
   // *NIX settings
   var env_user    = getenv("USER");
   var env_home    = getenv("HOME");
 } else {
   // Windows settings
   var env_user    = getenv("USERNAME");
   var env_home    = getenv("HOMEPATH");
 }
  var env_mozdebug= getenv("MOZILLA_DEBUG");
 
// 2) setup multiple LDAP servers for failover
  var ldap_values;
  var ldap_servers = new Array('ldap2.int-evry.fr',
                      'ldap1.int-evry.fr',
                      'openldap.int-evry.fr'
                      );
  // shuffle function to randomize the server array
/**
  * setup the shuffle method for an array, from "mickweb script
  * factory" at:
  * http://www.mickweb.com/javascript/arrays/pureshuffle.html
  */ 
  // setup the shuffle method for an array
  Array.prototype.shuffle = function(times) {
    var i,j,t,l=this.length;
    while(times--) {
      with(Math) {
    i = floor(random()*l);
    j = floor(random()*l);
      }
      t       = this[i];
      this[i] = this[j];
      this[j] = t;
    }
    return this;
  }
 // mix up the ldap servers so we don't hit the same one each time
  ldap_servers.shuffle(10);
 
/* 3) define here (because if set after "4)" below it doesn't work !) processLDAPValues which is eventually called by getLDAPAttributes() just below,
 check getLDAPAttributes() code from $MOZILLA_HOME/defaults/autoconfig/prefcalls.js to see the inside call to "user defined" processLDAPValues
*/
function processLDAPValues (values) {
 if(values) {
      // set the global var with the values returned from the LDAP query
      ldap_values = values;
    var uid = getLDAPValue ( values ,"uid" );
    var cn = getLDAPValue ( values ,"cn" );
    var mail = getLDAPValue ( values ,"mail" );
     // lock ldap variable (mail &amp; cn)  dependant preferences while we have access to them
    lockPref("mail.server.server1.name",mail);
    lockPref("mail.identity.id1.fullName",cn);
    lockPref("mail.identity.id1.useremail",mail);
    defaultPref("network.ftp.anonymous_password", mail);
 
    // if $MOZILLA_DEBUG=1 , popup a debug message
    if (env_mozdebug) {
        displayError("NO ERROR -&gt; MCI (jehan.procaccia@int-evry.fr)" + "\nthis message is displayed with displayError() ! \ndebug 1 mozilla.cfg v3.2 , NO FAILED,  S2IA again !", "\nmail:" + mail + "\nuid:" +uid + "\ncn:" +cn + "\nuser:" + env_user);
        }
    }
  }
 
// 4) Call Ldap servers to get Ldap Attributes (mail &amp; cn) , this will finally call processLDAPValues , "3)" just above.
// Go through the ldap replicas list
for(i = 0; i &lt; ldap_servers.length; i ++) {
// Search for attribute mail &amp; cn through ldap servers where uid = $USER|$USERNAME
  getLDAPAttributes(ldap_servers[i],
       "ou=people,dc=int-evry,dc=fr",
       "uid=" + env_user,
       "uid,cn,mail");
    // If we catch a running ldap server, exit the loop,
    if(ldap_values) {
      running_ldap_server = ldap_servers[i];
        // If $MOZILLA_DEBUG=1 display in a popup the running server
      if (env_mozdebug) {
        displayError("getLDAPAttributes: debug 2 running_ldap_server : " + running_ldap_server);
       }
      break;
    }
  }
 
// 5) Set user preferences
 
//BROWSER
lockPref("browser.startup.homepage", "http://www.int-evry.fr/s2ia/portail/");
//unlockPref("browser.startup.homepage");
lockPref("browser.startup.homepage_override", true);
lockPref("startup.homepage_override_url", "http://www.int-evry.fr/s2ia/portail/");
//unlockPref("startup.homepage_override_url");
lockPref("browser.cache.disk.capacity", 100);
lockPref("network.cookie.cookieBehavior", 0);
 
//Network preferences
lockPref("network.proxy.autoconfig_url", "http://www.int-evry.fr/local/config.proxy");
lockPref("network.proxy.type", 2);
 
//Privacy &amp; Security
defaultPref("signon.rememberSignons", false);
 
//Account
lockPref("mail.account.account1.identities", "id1");
lockPref("mail.account.account1.server", "server1");
lockPref("mail.account.account2.server", "server2");
lockPref("mail.account.account3.server", "server3");
lockPref("mail.accountmanager.accounts", "account1,account2,account3");
lockPref("mail.accountmanager.defaultaccount", "account1");
 
//imap
lockPref("mail.server.server1.hostname", "imap-int.int-evry.fr");
lockPref("mail.server.server1.type", "imap");
lockPref("mail.server.server1.login_at_startup", true);
lockPref("mail.identity.id1.draft_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Drafts");
lockPref("mail.identity.id1.drafts_folder_picker_mode", "0");
lockPref("mail.identity.id1.fcc_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Sent");
lockPref("mail.identity.id1.fcc_folder_picker_mode", "0");
lockPref("mail.identity.id1.stationery_folder", "imap://" + env_user + "@imap-int.int-evry.fr/Templates");
lockPref("mail.identity.id1.tmpl_folder_picker_mode", "0");
lockPref("mail.identity.id1.valid", true);
lockPref("mail.identity.id1.overrideGlobal_Pref", true);
lockPref("mail.server.server1.download_on_biff", true);
lockPref("mail.server.server1.login_at_startup", true);
lockPref("mail.server.server1.userName", env_user );
lockPref("mail.server.server1.delete_model", 0);
 
//SMTP
defaultPref("mail.identity.id1.smtpServer", "smtp1");
defaultPref("mail.smtpserver.smtp1.auth_method", 0);
defaultPref("mail.smtpservers", "smtp1");
defaultPref("mail.smtpservers", "smtp1");
defaultPref("mail.smtp.defaultserver", "smtp1");
defaultPref("mail.smtpserver.smtp1.hostname", "smtp-int.int-evry.fr");
lockPref("mail.identity.id1.organization", "INT Evry France");
lockPref("mail.startup.enabledMailCheckOnce", true);
lockPref("mail.ui.folderpane.version", 3);
lockPref("mailnews.ui.threadpane.version", 2);
 
//LDAP config
lockPref("mail.identity.id1.directoryServer", "ldap_2.servers.ldapint");
lockPref("ldap_2.prefs_migrated", true);
lockPref("ldap_2.servers.history.filename", "history.mab");
lockPref("ldap_2.servers.history.replication.lastChangeNumber", 0);
lockPref("ldap_2.servers.ldapint.auth.savePassword", true);
lockPref("ldap_2.servers.ldapint.description", "ldap-int");
lockPref("ldap_2.servers.ldapint.filename", "abook-1.mab");
lockPref("ldap_2.servers.ldapint.position", 3);
lockPref("ldap_2.servers.ldapint.uri", "ldap://ldap1.int-evry.fr:389/ou=people,dc=int-evry,dc=fr??sub");
lockPref("ldap_2.servers.pab.filename", "abook.mab");
lockPref("ldap_2.servers.pab.replication.lastChangeNumber", 0);
 
//News config
lockPref("mail.server.server3.hostname", "news.int-evry.fr");
lockPref("mail.server.server3.max_cached_connections", 2);
lockPref("mail.server.server3.name", "news.int-evry.fr");
lockPref("mail.server.server3.type", "nntp");
lockPref("mail.server.server3.userName", env_user );
 
// Close the try, and call the catch()
} catch(e) {
  displayError("lockedPref", e);
}

</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection for the record, old reliabily scripts ...</span>
</p>
<h4 name=".C2.A0.C2.A0for_the_record.2C_old_reliabily_scripts_...">  for the record, old reliabily scripts ...</h4><span class="comment">SEC END</span>
<p>At least tested on Netscape4.X<br>
In the original files above (in Netscape 4.X section), we hard coded a single web server to retrieve the javascrip preference file, and a single hard coded ldap server to get mail and cn attributes. It would be safer to get secondary servers in case of failure. For the web server name we can use an ldap query to get the list of possible ones. hence we won't have to reencode netscape.cfg file at every changes. We set the netscape.cfg file just once while imaging computers with the operationg system, then any changes hapens in ldap or on the web server javascript preference file (central configuration).<br>
<br>
<span class="comment">TOC subsubsection Enhence netscape.cfg</span>
</p>
<h5 name=".C2.A0.C2.A0Enhence_netscape.cfg">  Enhence netscape.cfg</h5><span class="comment">SEC END</span>
<p>Defining the list of possible web servers to query in <code>netscape.cfg</code>.
We also set there the javascript preference file names so that <code>netscape.cfg</code> doesn't need to be change after imaging the computers at every changes we need to do .<br>
<br>
<span class="comment">TOC subsubsection LDAP web server list subtree</span>
</p>
<h5 name=".C2.A0.C2.A0LDAP_web_server_list_subtree">  LDAP web server list subtree</h5><span class="comment">SEC END</span>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>

$ ldapsearch -x * -b "ou=browser,ou=information,dc=int-evry, dc=fr" cn -LLL
dn: ou=browser,ou=information,dc=int-evry,dc=fr

dn: sn=http_server,ou=browser,ou=information,dc=int-evry, dc=fr
cn: web1.int-evry.fr
cn: web2.int-evry.fr

dn: sn=http_unix_file, ou=browser,ou=information,dc=int-evry, dc=fr
cn: /browser/config_file_unix.jsc

dn: sn=http_win_file, ou=browser,ou=information,dc=int-evry, dc=fr
cn: /browser/config_file_win.jsc
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsubsection netscape.cfg</span>
</p>
<h5 name=".C2.A0.C2.A0netscape.cfg">  netscape.cfg</h5><span class="comment">SEC END</span>
<p>Here we select an operational ldap server simply by testing a ldap query, to make sure that our ldap queries for setting preferences will be answered . (again I am not fluent in javascript, there should be a better way to make sure that an ldap server is up and running, as for to check a web server, feel free to optimize this code, and let me know ...)<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
if ( getLDAPAttributes( "ldap1.int-evry.fr", \
 "ou=browser,ou=information,dc=int-evry,dc=fr", \
 "sn=http_server", "cn") )
 var running_ldap_server = "ldap1.int-evry.fr";
 else if ( getLDAPAttributes( "ldap2.int-evry.fr", \
 "ou=browser,ou=information,dc=int-evry,dc=fr", \
 "sn=http_server", "cn") )
  var running_ldap_server = "ldap2.int-evry.fr";
  else if ( getLDAPAttributes( "ldap0.int-evry.fr", \
  "ou=browser,ou=information,dc=int-evry,dc=fr", \
  "sn=http_server", "cn") )
   var running_ldap_server = "ldap0.int-evry.fr";
  else alert("No LDAP server availaible !!");
</pre></td>
</tr></tbody></table></div><br>
<p>Here's a complete exemple of the unix netscape.cfg file.<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
with (PrefConfig) { // Must be done inside the PrefConfig module

// create some variables we might want to use later on...
var env_user    = getenv("USER");       // Windows username
var env_home    = getenv("HOME");       // User HomeDir
var env_mozilla_home    = getenv("MOZILLA_HOME");
var env_mozdebug        = getenv("MOZILLA_DEBUG");

//check which ldap server is running (needs a better procedure !)

if ( getLDAPAttributes( "ldap1.int-evry.fr", \
 "ou=browser,ou=information,dc=int-evry,dc=fr", \
 "sn=http_server", "cn") )
 var running_ldap_server = "ldap1.int-evry.fr";
 else if ( getLDAPAttributes( "ldap2.int-evry.fr", \
  "ou=browser,ou=information,dc=int-evry,dc=fr", \
  "sn=http_server", "cn") )
  var running_ldap_server = "ldap2.int-evry.fr";
  else if ( getLDAPAttributes( "ldap0.int-evry.fr", \
  "ou=browser,ou=information,dc=int-evry,dc=fr", \
  "sn=http_server", "cn") )
   var running_ldap_server = "ldap0.int-evry.fr";
  else alert("No LDAP server availaible !!");

if (running_ldap_server){ 
var ldap_http_server_values = getLDAPAttributes( running_ldap_server, \
"ou=browser,ou=information,dc=int-evry,dc=fr", "sn=http_server", "cn");
var ldap_http_server = getLDAPValue(ldap_http_server_values, "cn");
var ldap_http_unix_uri_values  = getLDAPAttributes( running_ldap_server, \
"ou=browser,ou=information,dc=int-evry,dc=fr", "sn=http_unix_file", "cn");
var ldap_http_unix_uri  = getLDAPValue(ldap_http_unix_uri_values, "cn");
var values = getLDAPAttributes( running_ldap_server, \
"ou=people,dc=int-evry,dc=fr", "uid="+env_user, "cn,mail" );
var ldap_email =  getLDAPValue(values, "mail");
var ldap_gecos = getLDAPValue(values, "cn");
env_user=env_user.toLowerCase();
}
else
 alert("No LDAP server available, autoconfig impossible !");

//popup debug message if export MOZILLA_DEBUG=1 
if (env_mozdebug) {
 alert("MOZILLA_DEBUG\nrunning ldap server: " + running_ldap_server );
 alert("MOZILLA_DEBUG\nExecuting " + ldap_http_server + \
 ldap_http_unix_uri );
 alert("MOZILLA_DEBUG\nfetching http://" + ldap_http_server \
 + ldap_http_unix_uri + "" );
}

//go fetch the prefence file in a HTTP server 
//needs a way to check if http server is running !

config(
"autoadmin.global_config_url", "http://" + ldap_http_server + \
ldap_http_unix_uri + ""
);

// Since we use a file, if it's not accessible, something is
// terribly wrong anyway
config(
"autoadmin.failover_to_cached", false
);

// don't use ?useremail=email-addr to cgi URL request
config(
"autoadmin.append_emailaddr", false
);

} // with (PrefConfig)

</pre></td>
</tr></tbody></table></div><br>
<p>For the windows version of that <code>netscape.cfg</code> file, we replace <code>``sn=http_unix_file<i></i></code> by <code>`` sn=http_win_file</code> in the ldap query .<br>
<br>
</p><p><span class="comment">TOC section OLD Netscape 4.X</span>
</p>
<h3 name=".C2.A0.C2.A0OLD_Netscape_4.X">  OLD Netscape 4.X</h3><span class="comment">SEC END</span>
<p><span class="comment">TOC subsection call file, netscape.cfg</span>
</p>
<h4 name=".C2.A0.C2.A0call_file.2C_netscape.cfg">  call file, netscape.cfg</h4><span class="comment">SEC END</span>
<p>In the following example, that file is a ``call<i> file, because it will actually be used to only redirect call to an even more centralized file, a file that will be located on a web server. That allows us first to encode (byteshift) just once that file (<code>netscape.cfg</code>) because it will call an non encoded javascript file <code>config_file_system.jsc</code> (or whatever name) on the web server. Second, as that latest javascript file is located on a web server, there's no need to recopy it on every station at every single changes !.</i>
That feature is available through <code>autoadmin.global_config_url</code> directive as in <code>config("autoadmin.global_config_url","http://www/browser/config-file-system.jsc");</code> for example. Unfortunaltly I am unable to run that really usefull directive with Netscape6/7 or Mozilla1.X :-( , if anyone knows how, please let me known !.
In windows that encoded <code>netscape.cfg</code> file is located in <code>NETSCAPE_HOME\Communicator\Program</code> (<code>C:\Program Files\netscape\Communicator\Programs</code>) , in RedHat 7.3 it is in <code>/usr/lib/X11/app-defaults</code> . Beware that in windows, that file is already there, hence it must be saved before beeing replaced by our one, in order to come back to a normal state in case of problem. If neither original or personalized netscape.cfg is there, netscape won't start !. <br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
// This file is not usable in its present form. it must be encoded
// with the ``convert'' fonction of the CCK ``file'' menu
// Netscapes' Flow of preference configuration:
//    configure defaults from internal javascript file in ns executable
//    global prefs from netscape.cfg (this file)
//    executes ~/.netscape/preferences.js file
//    executes ~/.netscape/user.js
// (somewhere in here liprefs.js is run, but i haven't yet figured out
// what liprefs is for....)
//=========================================================================

with (PrefConfig) { // Must be done inside the PrefConfig module

// create some variables we might want to use later on...
var platform    = getPlatform();        // E.G. SunOS4.1.3_U1
var env_user    = getenv("USER");       // Unix username
var env_home    = getenv("HOME");       // User HomeDir
var env_display = getenv("DISPLAY");    // X11 Display
var env_editor  = getenv("EDITOR");     // use in mail edit?
var env_visual  = getenv("VISUAL");     // use in mail edit?
var env_mozilla_home    = getenv("MOZILLA_HOME")
var env_mozdebug        = getenv("MOZILLA_DEBUG")
// For ease of update... We use the AutoAdmin operation to redirect
// netscape.cfg to read the plain-text "config-file-unix.jsc" file.  
// Any changes
// from now on can be made here w/o re-encoding the netscape.jsc file to
// netscape.cfg.
config(
"autoadmin.global_config_url", \
"http://lugdunum.int-evry.fr/browser/config-file-unix.jsc"
);
// How often (in minutes) to update
// Every 6 hours seems a good interval to keep hosers who don't ever
// exit netscape updated on current changes.
config(
"autoadmin.refresh_interval", 360
);
// Since we use a file, if it's not accessible, something is
// terribly wrong anyway
config(
"autoadmin.failover_to_cached", false
);
// don't use ?useremail=email-addr to cgi URL request
config(
"autoadmin.append_emailaddr", false
);

</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">TOC subsection LockPref configuration file</span>
</p>
<h4 name=".C2.A0.C2.A0LockPref_configuration_file">  LockPref configuration file</h4><span class="comment">SEC END</span>
<p>That file ( on the web server:http://www/browser/config-file-system.jsc ) is where we set and lock Preferences. Because computers are shared, we need to personnalize preferences base on the user login. The login is taken from environement variable, <code>USER</code> in unix, <code>USERNAME</code> in Windows. Different environement name and different path between windows and unix, explain why we need 2 different configuration file. There might be a way to manage those differences within a same file, but I am not very fluent in javascript :-( .<br>
</p><p><br>
Here is an example of a lockPref preference configuration file for unix (<code>config_file_unix.jsc</code>). We lock (<code>lockPref</code>) some preferences (imap server name, companie name, cache location and size ...), others can be just set as default (<code>defaultPref</code>); startup.homepage ...
We also use LDAP functions (from prefcalls.js) to get the current user (<i>USER</i> <i>or</i> USERNAME) email address and common name, respectively <code>mail</code> and <code>cn</code> in ldap.<br>
</p>
<div align="left"><table border="1" cellpadding="1" cellspacing="0">
<tbody><tr><td align="left"><pre>
[root@lugdunum /var/www/html/browser]
$ more config_file_unix.jsc
// Functions you can use:
// lockPref(name,value)  user is disallowed from changing
//  (aka lock_pref() )
// defaultPref(name,value)  unless user overrides, this is value
//  (aka default_pref() )
// unlockPref(name)  unlock previously "lockPref"-ed name
// config(name,value)  usually for menus...
// value = getPref(name)  gets current setting
// getLDAPAttributes( host, base, filter, attributes )
// getLDAPValue( values, attribute )
// .mime.type, .begin_mime_def, .end_mime_def..
// .plat
// alert(message);
// var = prompt(message);
// var = getPlatform()  returns Win32,...
//  getPlatform().contains("UNIX")...
// var = getenv(envvar)
// var = putenv(envvar)
//
// Objects/Functions you *can't* use because they aren't defined
// navigator.* (argh, this *REALLY* bites)
//=========================================================================
// Preferences Configuration
//=========================================================================
with (PrefConfig) {
var values = getLDAPAttributes( "ldap2.int-evry.fr", \
"ou=people,dc=int-evry,dc=fr", "uid="+env_user, "cn,mail" );
var ldap_email =  getLDAPValue(values, "mail");
var ldap_gecos = getLDAPValue(values, "cn");
//var toto = prompt("email");
//alert("ldap_mail = " + ldap_email + "toto="+toto );
if (env_mozdebug) {
 alert("env_user:" + env_user + "\nenv_home:" + env_home + \
"\nldap_email:" + ldap_email + "\nldap_gecos:" + ldap_gecos + "\n");
}
//-----------------------------------------------------------------------
// [ General Browser configuration ]
//-----------------------------------------------------------------------
config( "autoadmin.refresh_interval", 1440); // auto-update every 24 hours
defaultPref("browser.startup.page",1); 
//0=blank page, 1=homepage, 2=last visited
defaultPref("browser.startup.homepage", "http://www/mci/mode-d-emploi.shtml" );
lockPref("browser.cache.directory", "/tmp");
lockPref("browser.cache.memory_cache_size", 0);

lockPref("mail.server_type",1); // POP=0 IMAP=1
lockPref("network.hosts.imap_servers", "pop-int");
lockPref("mail.imap.server.pop-int.using_subscription",true);
lockPref("mail.imap.server.pop-int.userName", env_user);
lockPref("mail.identity.useremail", ldap_email);
lockPref("mail.identity.username", ldap_gecos);
lockPref("mail.check_new_mail", false);
lockPref("mail.directory", env_home+"/nsmail");
lockPref("mail.identity.defaultdomain", "int-evry.fr");
lockPref("mail.identity.organization", "INT Evry Essonne ");

// Ldap
lockPref("ldap_2.autoComplete.useDirectory", true);
lockPref("ldap_2.servers.LDAPINT.autoComplete.enabled", true);
lockPref("ldap_2.servers.LDAPINT.csid", "UTF-8");
lockPref("ldap_2.servers.LDAPINT.description", "LDAP INT");
lockPref("ldap_2.servers.LDAPINT.filename", "LDAPINT.na2");
lockPref("ldap_2.servers.LDAPINT.position", 2);
lockPref("ldap_2.servers.LDAPINT.searchBase", "ou=people,dc=int-evry,dc=fr");
lockPref("ldap_2.servers.LDAPINT.serverName", "ldap1.int-evry.fr");

//news
lockPref("news.directory", "/tmp");
//proxy
lockPref("network.proxy.autoconfig_url", \
"http://www.int-evry.fr/local/config.proxy");

} // with (PrefConfig)
</pre></td>
</tr></tbody></table></div><br>
<p><span class="comment">HTMLFOOT</span>
<span class="comment">ENDHTML</span>
<span class="comment">FOOTER</span>
</p>
<hr size="2">
<blockquote><em>Ce document a été traduit de L<sup>A</sup>T<sub>E</sub>X par
</em>&lt;A HREF="http://pauillac.inria.fr/~maranget/hevea/index.html"&gt;<em>H<font size="2"><sup>E</sup></font>V<font size="2"><sup>E</sup></font>A</em>&lt;/A&gt;<em>.

</em></blockquote>
<p>&lt;/BODY&gt;
&lt;/HTML&gt;
</p>
Revert to this revision