]> git.sur5r.net Git - contagged/commitdiff
Merge commit '75245bbc807b67247234c9103b162008c5b5b326' into cweiske
authorAndreas Gohr <gohr@cosmocode.de>
Tue, 26 Aug 2014 09:39:17 +0000 (11:39 +0200)
committerAndreas Gohr <gohr@cosmocode.de>
Tue, 26 Aug 2014 09:39:17 +0000 (11:39 +0200)
* commit '75245bbc807b67247234c9103b162008c5b5b326':
  allow custom field definitions in config.php
  fix broken evolutionPerson fields (country not provided, but anniversary and categories exist)
  make object classes configurable in inc/config.php
  Fix issue #10: vcards need CRLF and newline at the end
  fix broken tags.php
  make categories work with evolutionPerson schema
  nicer error display
  tell where the error happened
  search address book subtree, not only one level
  ignore cache files
  move config.php to config.php.dist, ignore user config

.gitignore [new file with mode: 0644]
entry.php
inc/config.php [deleted file]
inc/config.php.dist [new file with mode: 0644]
inc/fields.php
inc/functions.php
inc/template.php
index.php

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..99ee56f
--- /dev/null
@@ -0,0 +1,2 @@
+inc/config.php
+/cache/
index 2bf488a7f15e3bff60579c19f1baf7bf37de9756..1e5e7552976de876ee184fccb105b3866df15614 100644 (file)
--- a/entry.php
+++ b/entry.php
@@ -71,7 +71,9 @@ if($_REQUEST['mode']=='vcf'){
   $filename = $entry['givenname'].'_'.$entry['name'].'.vcf';
   header("Content-Disposition: attachment; filename=\"$filename\"");
   header("Content-type: text/x-vcard; name=\"$filename\"; charset=utf-8");
-  $smarty->display($template);
+  $output = $smarty->fetch($template) . "\n";
+  $output = str_replace("\n", "\r\n", $output);
+  echo $output;
 }else{
   header('Content-Type: text/html; charset=utf-8');
   $smarty->display($template);
diff --git a/inc/config.php b/inc/config.php
deleted file mode 100644 (file)
index 03741d4..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-  // LDAP URL; if set, takes precedence over ldapserver and ldapport
-  #$conf['ldapurl']     = 'ldaps://ldap.example.com/';
-
-  // Which LDAP Server to use?
-  $conf['ldapserver']  = 'ldap';
-
-  // Which LDAP Port Server to use? (389 is standard, 636 for ssl)
-  $conf['ldapport']    = 389;
-
-  // Use LDAP protocol version 3? (0|1)
-  $conf['ldapv3'] = 1;
-
-  // What is the root dn on this Server?
-  $conf['ldaprootdn']  = 'o=cosmocode, c=de';
-
-  // Where are the user Accounts stored?
-  $conf['usertree']    = 'ou=people, '.$conf['ldaprootdn'];
-
-  // How to match users? %u is replaced by the given login
-  $conf['userfilter']  = '(&(uid=%u)(objectClass=posixAccount))';
-
-  // Show the users as contacts, too?
-  $conf['displayusertree'] = 0;
-
-  // Use these values to bind to the ldap directory when not logged in (leave blank for anonymous bind)
-  $conf['anonbinddn']  = '';
-  $conf['anonbindpw']  = '';
-
-  // Which language to use (see lang directory)
-  $conf['lang']        = 'en';
-
-  // Default Country for new entries (ISO3166)
-  $conf['country'] = 'US';
-
-  // Where to store public contacts?
-  $conf['publicbook']  = 'ou=contacts, '.$conf['ldaprootdn'];
-
-  // Where to store private contacts (relative to $conf['usertree'])
-  $conf['privatebook'] = 'ou=contacts';
-
-  // What fields to look at when searching?
-  $conf['searchfields'] = array('uid','mail','name','givenname','o');
-
-  // Should the public address book be viewable by logged in users only? (0|1)
-  $conf['userlogreq']  = 0;
-
-  // Should we try to login using the username and password provided by httpd? (0|1)
-  $conf['httpd_auth']  = 0;
-
-  // Store the first 4 tags in Thunderbird's custom fields when using ldapab.schema
-  $conf['tbtaghack']   = 1;
-
-  // Dateformat for birthdays and anniversary
-  // see http://www.php.net/manual/en/function.strftime.php
-  $conf['dateformat']  = '%Y/%m/%d';
-  #$conf['dateformat']  = '%d.%m.%Y';
-
-  // Google maps key, you can specify multiple when running the app through different vhosts
-  $conf['gmaps'] = array(
-    'localhost'        => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSoniRWQPYZHIWuWPbij8hFqvrEuw',
-    'intranet.cosmo'   => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RTxyuybgLnXtMVD7dljhze3zUboVhTqk9yc-rQVvv2YwFFJN20RCNbIVA',
-    'intranet'         => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RTjlGRJ-JcA4ENdYSxSTUELqnaldxSOyZdbUNylw_BZHH1bBLrQNGtjZg',
-    'fileserver.cosmo' => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RQ2oMD1p7-NjsUZiDyjvzpK3IuhixTXdHGQRp8jtjwAl-P4oPPEB_hGgw',
-  );
-
-  // Force recompilation of smarty templates?
-  $conf['smartycompile'] = 0;
-
-
diff --git a/inc/config.php.dist b/inc/config.php.dist
new file mode 100644 (file)
index 0000000..8ace7f5
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+
+  // LDAP URL; if set, takes precedence over ldapserver and ldapport
+  #$conf['ldapurl']     = 'ldaps://ldap.example.com/';
+
+  // Which LDAP Server to use?
+  $conf['ldapserver']  = 'ldap';
+
+  // Which LDAP Port Server to use? (389 is standard, 636 for ssl)
+  $conf['ldapport']    = 389;
+
+  // Use LDAP protocol version 3? (0|1)
+  $conf['ldapv3'] = 1;
+
+  // What is the root dn on this Server?
+  $conf['ldaprootdn']  = 'o=cosmocode, c=de';
+
+  // Where are the user Accounts stored?
+  $conf['usertree']    = 'ou=people, '.$conf['ldaprootdn'];
+
+  // How to match users? %u is replaced by the given login
+  $conf['userfilter']  = '(&(uid=%u)(objectClass=posixAccount))';
+
+  // Show the users as contacts, too?
+  $conf['displayusertree'] = 0;
+
+  // Use these values to bind to the ldap directory when not logged in (leave blank for anonymous bind)
+  $conf['anonbinddn']  = '';
+  $conf['anonbindpw']  = '';
+
+  // Which language to use (see lang directory)
+  $conf['lang']        = 'en';
+
+  // Default Country for new entries (ISO3166)
+  $conf['country'] = 'US';
+
+  // Where to store public contacts?
+  $conf['publicbook']  = 'ou=contacts, '.$conf['ldaprootdn'];
+
+  // Where to store private contacts (relative to $conf['usertree'])
+  $conf['privatebook'] = 'ou=contacts';
+
+  // What fields to look at when searching?
+  $conf['searchfields'] = array('uid','mail','name','givenname','o');
+
+  // Should the public address book be viewable by logged in users only? (0|1)
+  $conf['userlogreq']  = 0;
+
+  // Should we try to login using the username and password provided by httpd? (0|1)
+  $conf['httpd_auth']  = 0;
+
+  // Store the first 4 tags in Thunderbird's custom fields when using ldapab.schema
+  $conf['tbtaghack']   = 1;
+
+  // Dateformat for birthdays and anniversary
+  // see http://www.php.net/manual/en/function.strftime.php
+  $conf['dateformat']  = '%Y/%m/%d';
+  #$conf['dateformat']  = '%d.%m.%Y';
+
+  // Google maps key, you can specify multiple when running the app through different vhosts
+  $conf['gmaps'] = array(
+    'localhost'        => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSoniRWQPYZHIWuWPbij8hFqvrEuw',
+    'intranet.cosmo'   => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RTxyuybgLnXtMVD7dljhze3zUboVhTqk9yc-rQVvv2YwFFJN20RCNbIVA',
+    'intranet'         => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RTjlGRJ-JcA4ENdYSxSTUELqnaldxSOyZdbUNylw_BZHH1bBLrQNGtjZg',
+    'fileserver.cosmo' => 'ABQIAAAAwcgTzX14Lq48uGhuAgaC-RQ2oMD1p7-NjsUZiDyjvzpK3IuhixTXdHGQRp8jtjwAl-P4oPPEB_hGgw',
+  );
+
+  // Force recompilation of smarty templates?
+  $conf['smartycompile'] = 0;
+
+// LDAP classes to store with contacts.
+$conf['oclasses'] = array(
+    'inetOrgPerson',
+    //'contactPerson',
+    //'OXUserObject',
+    //'evolutionPerson',
+    //'officePerson',
+);
+
+//custom LDAP field mappings, see inc/fields.php
+$conf['customFields'] = array();
index 9229e7206462377b19f07ac677a9c8d9b4aed9af..25e05085be232fc0d4e70e03a7b528438ad54ab4 100644 (file)
  * handled by the template as well)
  */
 
+global $conf;
 
 /**
  * The object classes to store with contacts
  */
-$OCLASSES[] = 'inetOrgPerson';
+$OCLASSES = $conf['oclasses'];
 
 /**
  * The standard fields suported by OpenLDAP's default schemas
@@ -47,46 +48,47 @@ $FIELDS = array(
  * If the provided "extended" schema is used the following fields
  * and object classes are added
  */
-$OCLASSES[] = 'contactPerson';
-$FIELDS['anniversary']  = 'anniversary';
-$FIELDS['_marker']      = 'marker';                  // aka. tags
-$FIELDS['country']      = 'c';
+if (array_search('contactPerson', $conf['oclasses']) !== false) {
+    $FIELDS['anniversary']  = 'anniversary';
+    $FIELDS['_marker']      = 'marker';                  // aka. tags
+    $FIELDS['country']      = 'c';
+}
 
 /**
  * If the open exchange schema is used the following fields
  * and object classes are added
  */
-/* comment in if you want to use it
-$OCLASSES[] = 'OXUserObject';
-$FIELDS['country']          = 'userCountry';
-$FIELDS['birthday']         = 'birthDay';
-$FIELDS['ipphone']          = 'IPPhone';
-$FIELDS['_marker']          = 'OXUserCategories';
-$FIELDS['instantmessenger'] = 'OXUserInstantMessenger';
-$FIELDS['timezone']         = 'OXTimeZone';
-$FIELDS['position']         = 'OXUserPosition';
-$FIELDS['certificate']      = 'relClientCert';
-$FIELDS['domain']           = 'domain';
-*/
+if (array_search('OXUserObject', $conf['oclasses']) !== false) {
+    $FIELDS['country']          = 'userCountry';
+    $FIELDS['birthday']         = 'birthDay';
+    $FIELDS['ipphone']          = 'IPPhone';
+    $FIELDS['_marker']          = 'OXUserCategories';
+    $FIELDS['instantmessenger'] = 'OXUserInstantMessenger';
+    $FIELDS['timezone']         = 'OXTimeZone';
+    $FIELDS['position']         = 'OXUserPosition';
+    $FIELDS['certificate']      = 'relClientCert';
+    $FIELDS['domain']           = 'domain';
+}
 
 /**
  * If the Evolution schema is used the following fields
  * and object classes are added
  */
-/* comment in if you want to use it
-$OCLASSES[] = 'evolutionPerson';
-$OCLASSES[] = 'officePerson';
-$FIELDS['department']  = 'ou';
-$FIELDS['state']       = 'st';
-$FIELDS['country']     = 'c';
-$FIELDS['phone']       = 'primaryPhone';
-$FIELDS['switchboard'] = 'companyPhone';
-$FIELDS['note']        = 'note';
-$FIELDS['manager']     = 'seeAlso';
-$FIELDS['birthday']    = 'birthDate';
-$FIELDS['spouse']      = 'spouseName';
-*/
+if (array_search('evolutionPerson', $conf['oclasses']) !== false) {
+    $FIELDS['anniversary'] = 'anniversary';
+    $FIELDS['department']  = 'ou';
+    $FIELDS['state']       = 'st';
+    $FIELDS['phone']       = 'primaryPhone';
+    $FIELDS['switchboard'] = 'companyPhone';
+    $FIELDS['note']        = 'note';
+    $FIELDS['manager']     = 'seeAlso';
+    $FIELDS['birthday']    = 'birthDate';
+    $FIELDS['spouse']      = 'spouseName';
+    $FIELDS['_marker']     = 'categories'; // aka. tags
+}
 
+// add custom fields from config
+$FIELDS = array_merge($FIELDS, $conf['customFields']);
 
 /**
  * Flip the array
index bbae2701b2f18402547082e66515a8d8548bdf80..301148c63b91a53693e4cf6f29e3667dd3b54297 100644 (file)
@@ -344,7 +344,7 @@ function ldap_store_objectclasses($dn,$classes){
   $add['objectClass'] = $set;
 
   $r = @ldap_mod_replace($LDAP_CON,$dn,$add);
-  tpl_ldaperror();
+  tpl_ldaperror('store object classes');
 
 /*  print '<pre>';
   print_r($set);
@@ -387,7 +387,7 @@ function ldap_queryabooks($filter,$types){
   $result3 = array();
 
   // public addressbook
-  $sr      = @ldap_list($LDAP_CON,$conf['publicbook'],
+  $sr      = @ldap_search($LDAP_CON,$conf['publicbook'],
                         $filter,$types);
   tpl_ldaperror();
   $result1 = ldap_get_binentries($LDAP_CON, $sr);
index a86152092c22bce1dd12c3f257bfd9df02e12f4a..dc913bd07435df1397f9335dcae2996cbc1d26d5 100644 (file)
@@ -117,9 +117,9 @@ function tpl_ldaperror($message=""){
   if($errno){
     $__LDAPERROR__ .= ldap_err2str($errno);
     if(!empty($message)){
-      $__LDAPERROR__ .= "($message)";
+      $__LDAPERROR__ .= " ($message)";
     }elseif($errno == 4){
-      $__LDAPERROR__ .= "(You need to increase this limit in your server config)";
+      $__LDAPERROR__ .= " (You need to increase this limit in your server config)";
     }
     $__LDAPERROR__ .= '<br />';
   }
index 56e98ab43823daf0cfb5e9b77bab5c497291b7fc..7910e3afa2b41507b0b5f304624db59eedbf0352 100644 (file)
--- a/index.php
+++ b/index.php
 
     if(!empty($marker)){
       // Search by tag
-      $ldapfilter = '(&(objectClass=contactPerson)';
+      $ldapfilter = '(&(objectClass=evolutionPerson)';
       $marker = explode(',',$marker);
       foreach($marker as $m){
         $m = trim($m);