dolibarr  13.0.2
sync_users_dolibarr2ldap.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
27 if (!defined('NOSESSION')) define('NOSESSION', '1');
28 
29 $sapi_type = php_sapi_name();
30 $script_file = basename(__FILE__);
31 $path = __DIR__.'/';
32 
33 // Test if batch mode
34 if (substr($sapi_type, 0, 3) == 'cgi') {
35  echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36  exit(-1);
37 }
38 
39 if (!isset($argv[1]) || !$argv[1]) {
40  print "Usage: $script_file now\n";
41  exit(-1);
42 }
43 $now = $argv[1];
44 
45 require_once $path."../../htdocs/master.inc.php";
46 require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
47 require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";
48 
49 // Global variables
50 $version = DOL_VERSION;
51 $error = 0;
52 
53 /*
54  * Main
55  */
56 
57 @set_time_limit(0);
58 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
59 dol_syslog($script_file." launched with arg ".join(',', $argv));
60 
61 /*
62  * if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
63  * {
64  * print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
65  * exit(-1);
66  * }
67  */
68 
69 $sql = "SELECT rowid";
70 $sql .= " FROM ".MAIN_DB_PREFIX."user";
71 
72 $resql = $db->query($sql);
73 if ($resql) {
74  $num = $db->num_rows($resql);
75  $i = 0;
76 
77  $ldap = new Ldap();
78  $ldap->connect_bind();
79 
80  while ($i < $num) {
81  $ldap->error = "";
82 
83  $obj = $db->fetch_object($resql);
84 
85  $fuser = new User($db);
86  $fuser->fetch($obj->rowid);
87 
88  print $langs->trans("UpdateUser")." rowid=".$fuser->id." ".$fuser->getFullName($langs);
89 
90  $oldobject = $fuser;
91 
92  $oldinfo = $oldobject->_load_ldap_info();
93  $olddn = $oldobject->_load_ldap_dn($oldinfo);
94 
95  $info = $fuser->_load_ldap_info();
96  $dn = $fuser->_load_ldap_dn($info);
97 
98  $result = $ldap->add($dn, $info, $user); // Wil fail if already exists
99  $result = $ldap->update($dn, $info, $user, $olddn);
100  if ($result > 0) {
101  print " - ".$langs->trans("OK");
102  } else {
103  $error++;
104  print " - ".$langs->trans("KO").' - '.$ldap->error;
105  }
106  print "\n";
107 
108  $i++;
109  }
110 
111  $ldap->unbind();
112  $ldap->close();
113 } else {
114  dol_print_error($db);
115 }
116 
117 exit($error);
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage LDAP features.
Definition: ldap.class.php:30
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...