Résumé :
This document is a concret example of a centralized auto-configuration of mozilla 1.X.X , firefox &
thunderbird, and the 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.
~/.mozilla/default/randomdir/prefs.js
) we will centralized those 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 ...) . 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 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'');
. all.js
file, all.js
file has moved to MOZILLA_HOME/greprefs/all.js
, and I noticed the same for thunderbird and firefox ! 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) |
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.--enable-extensions=pref
in mozconfig
file .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 |
$ rpmbuild -ba /usr/src/redhat/SPECS/thunderbird.spec $ rpm -Uvh /usr/src/redhat/RPMS/i386/thunderbird-1.0.2-1.3.3.i386.rpm |
$ 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 |
[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 |
/usr/lib/thunderbird-1.5/thunderbird.cfg
.[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); } |
$ export NSPR_LOG_MODULES=MCD:5 $ export NSPR_LOG_FILE=/tmp/thunderbird-log.txt |
$ cat /tmp/thunderbird-log.txt -1209403040[808a788]: general.config.filename = thunderbird.cfg -1209403040[808a788]: evaluating .cfg file thunderbird.cfg with obscureValue 0 |
$ rm -rf ~/.thunderbird |
$ thunderbird |
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;+).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.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 .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 |
[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'); |
[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);} |
MOZILLA_DEBUG
variable ($export MOZILLA_DEBUG=1; export USER=procacci
), then the displayError()
will show you this popup :------- 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. |
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 |
moz-byteshift.pl
perl script, to encode mozilla.cfg
file.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 ! 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 !. 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"); |
$ 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 |
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. 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"); |
[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; |
//BEGIN CE prefs
, if not you'll get ``failed to read configuration file ...'' message, and mozilla won't start :-( .$ 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"); |
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"); |
$ 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"); ... |
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
)start_pos += search_key.length; //start start_pos +=1; //end |
getLDAPValue()
in autoconfig/preffcalls.js
.MOZILLA_HOME/greprefs
directory is closed by default to users and then autoconfig doesn't work properly, I 've opened a bugzilla on this: https://bugzilla.mozilla.org/show_bug.cgi?id=270623.
Workaround -> chmod 755 greprefs
!.autoadmin.global_config_url
, see :$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 ...if ... else
test on environement variables.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 */ |
// 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; } } |
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"); |
//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); } |
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 .$ 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 |
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 !!"); |
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) |
netscape.cfg
file, we replace ``sn=http_unix_file''
by `` sn=http_win_file''
in the ldap query .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 ); |
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 :-( .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) |
Ce document a été traduit de LATEX par HEVEA.