Made it easier to configure personal addressbooks in a database.
authorpallo <pallo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 7 May 2001 20:29:14 +0000 (20:29 +0000)
committerpallo <pallo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 7 May 2001 20:29:14 +0000 (20:29 +0000)
Also included some rough documentation on how to install it and
on the tables you need in the database.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1343 7612ce4b-ef26-0410-bec9-ea0150e637f0

config/config_default.php
doc/db-backend.txt [new file with mode: 0644]
functions/addressbook.php

index c8fecd83e69a0ab1644fc36eb971fc26b9ddd917..e540b917b16cfdfbe677ba08639f58e7c0038964 100644 (file)
@@ -285,6 +285,14 @@ global $ldap_server;
 //                     "name" => "Netcenter Member Directory",
 //                     "base" => "ou=member_directory,o=netcenter.com");
 
+//  Database-driven private addressbooks
+//
+//    DSN (Data Source Name) for a database where the private
+//    addressbooks are stored.  See doc/db-backend.txt for more info.
+//    If it is not defined, the addressbooks are stored in files
+//    in the data dir.
+//
+//     $addrbook_dsn = 'mysql://user:pass@hostname/dbname';
 
 
  // you have an option to chose between javascript or html version of
diff --git a/doc/db-backend.txt b/doc/db-backend.txt
new file mode 100644 (file)
index 0000000..4b3a6d9
--- /dev/null
@@ -0,0 +1,84 @@
+$Id$
+
+
+Storing private addressbooks and preferences in a database
+==========================================================
+
+
+On sites with many users you might want to store your user data in a
+database instead of in files. This document describe how to configure
+SquirrelMail to do this.
+
+Methods for storing both personal addressbooks and user preferences in
+a database is as a part of the distribution.
+
+
+
+Configuring PEAR DB
+-------------------
+
+To work you must install the PEAR classes that is a part of PHP. Make
+sure the directory where the PEAR files are located is a part of your
+include path. See the PHP documentation for info on how to do that.
+
+
+
+Configuring addressbooks in database
+------------------------------------
+
+First you need to create a database and a table to store the data in.
+Create a database user with access to read and write in that table.
+
+For MySQL you would normally do something like:
+
+ (from the command line)
+ # mysqladmin create squirrelmail
+
+ (from the mysql client)
+ mysql> GRANT select,insert,update,delete ON squirrelmail.* 
+              TO squrreluser@localhost IDENTIFIED BY 'sqpassword';
+
+The table structure should be similar to this (for MySQL):
+
+   CREATE TABLE address (
+     owner varchar(16) DEFAULT '' NOT NULL,
+     nickname varchar(16) DEFAULT '' NOT NULL,
+     firstname varchar(128) DEFAULT '' NOT NULL,
+     lastname varchar(128) DEFAULT '' NOT NULL,
+     email varchar(128) DEFAULT '' NOT NULL,
+     label varchar(255),
+     PRIMARY KEY (owner,nickname),
+     KEY firstname (firstname,lastname)
+   );
+
+
+Next, edit config/config.php and add a DSN (Data Source Name) for the
+database. It should look something like:
+
+ $addrbook_dsn = 'mysql://squirreluser:sqpassword@localhost/squirrelmail';
+
+From now on all users' personal addressbooks will be stored in a
+database.
+
+
+
+Configuring preferences in database
+-----------------------------------
+
+There is no easy way to do this yet. You will have to remove
+functions/prefs.php and replace it with functions/db_prefs.php. Then
+edit the new functions/prefs.php (db_prefs.php) and change the $DSN to
+point to a database you create (can be the same you use for
+addressbooks).  Create a table similar to this (for MySQL):
+
+  CREATE TABLE userprefs (
+    user varchar(32) DEFAULT '' NOT NULL,
+    prefkey varchar(64) DEFAULT '' NOT NULL,
+    prefval blob DEFAULT '' NOT NULL,
+    PRIMARY KEY (user,prefkey)
+  );
+
+
+Default preferences can be set by altering the $default array in
+prefs.php (db_prefs.php).
+
index 26b6aed3a8c71a1f0f17db38c4ace99f4eb5959a..0fd0451bbe283eb0e1c8788961d942b08416b5a2 100644 (file)
    include('../functions/abook_local_file.php');
    include('../functions/abook_ldap_server.php');
 
-   // Un-comment if you're using database backend
-   // include('../functions/abook_database.php');
+   // Only load database backend if database is configured
+   if(isset($addrbook_dsn))
+      include('../functions/abook_database.php');
 
 
    // Create and initialize an addressbook object. 
    // Returns the created object
    function addressbook_init($showerr = true, $onlylocal = false) {
       global $data_dir, $username, $ldap_server;
+      global $addrbook_dsn;
       
       // Create a new addressbook object
       $abook = new AddressBook;
       
-      // Always add a local backend
-
-      // Use *either* file-based *or* database addressbook. Remove
-      // and insert comments to enable the one you want.
-
-      // ------ BEGIN Initialize file-based personal addressbook ------
-      $filename = sprintf('%s%s.abook', $data_dir, $username);
-      $r = $abook->add_backend('local_file', Array('filename' => $filename,
-                                                  'create'   => true));
-
-      if(!$r && $showerr) {
-        printf(_("Error opening file %s"), $filename);
-        exit;
+      // Always add a local backend. We use *either* file-based *or* a
+      // database addressbook. If $addrbook_dsn is set, the database
+      // backend is used. If not, addressbooks are stores in files.
+      if(isset($addrbook_dsn) && !empty($addrbook_dsn)) {
+        // Database
+        $r = $abook->add_backend('database', Array('dsn' => $addrbook_dsn,
+                                                   'owner' => $username,
+                                                   'table' => 'address'));
+        if(!$r && $showerr) {
+           printf(_("Error initializing addressbook database."));
+           exit;
+        }
+      } else {
+        // File
+        $filename = sprintf('%s%s.abook', $data_dir, $username);
+        $r = $abook->add_backend('local_file', Array('filename' => $filename,
+                                                     'create'   => true));
+        if(!$r && $showerr) {
+           printf(_("Error opening file %s"), $filename);
+           exit;
+        }
       }
-      // ------ END Initialize file-based personal addressbook ------
-
-      // ------ BEGIN Initialize database-based personal addressbook ------
-      //      $r = $abook->add_backend('database', Array('dsn' => 'mysql://dbuser@host/dbname',
-      //                                                'owner' => $username,
-      //                                                'table' => 'address'));
-      //      if(!$r && $showerr) {
-      //        printf(_("Error initializing addressbook: %s"), $filename);
-      //        exit;
-      //      }
-      // ------ END Initialize database-based personal addressbook ------
 
       if($onlylocal)
        return $abook;