dolibarr  x.y.z
security.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2021 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2008-2021 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2020 Ferran Marcet <fmarcet@2byte.es>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  * or see https://www.gnu.org/
19  */
20 
38 function dol_encode($chain, $key = '1')
39 {
40  if (is_numeric($key) && $key == '1') { // rule 1 is offset of 17 for char
41  $output_tab = array();
42  $strlength = dol_strlen($chain);
43  for ($i = 0; $i < $strlength; $i++) {
44  $output_tab[$i] = chr(ord(substr($chain, $i, 1)) + 17);
45  }
46  $chain = implode("", $output_tab);
47  } elseif ($key) {
48  $result = '';
49  $strlength = dol_strlen($chain);
50  for ($i = 0; $i < $strlength; $i++) {
51  $keychar = substr($key, ($i % strlen($key)) - 1, 1);
52  $result .= chr(ord(substr($chain, $i, 1)) + (ord($keychar) - 65));
53  }
54  $chain = $result;
55  }
56 
57  return base64_encode($chain);
58 }
59 
69 function dol_decode($chain, $key = '1')
70 {
71  $chain = base64_decode($chain);
72 
73  if (is_numeric($key) && $key == '1') { // rule 1 is offset of 17 for char
74  $output_tab = array();
75  $strlength = dol_strlen($chain);
76  for ($i = 0; $i < $strlength; $i++) {
77  $output_tab[$i] = chr(ord(substr($chain, $i, 1)) - 17);
78  }
79 
80  $chain = implode("", $output_tab);
81  } elseif ($key) {
82  $result = '';
83  $strlength = dol_strlen($chain);
84  for ($i = 0; $i < $strlength; $i++) {
85  $keychar = substr($key, ($i % strlen($key)) - 1, 1);
86  $result .= chr(ord(substr($chain, $i, 1)) - (ord($keychar) - 65));
87  }
88  $chain = $result;
89  }
90 
91  return $chain;
92 }
93 
100 function dolGetRandomBytes($length)
101 {
102  if (function_exists('random_bytes')) { // Available with PHP 7 only.
103  return bin2hex(random_bytes((int) floor($length / 2))); // the bin2hex will double the number of bytes so we take length / 2
104  }
105 
106  return bin2hex(openssl_random_pseudo_bytes((int) floor($length / 2))); // the bin2hex will double the number of bytes so we take length / 2. May be very slow on Windows.
107 }
108 
119 function dolEncrypt($chain, $key = '', $ciphering = "AES-256-CTR")
120 {
121  global $dolibarr_main_instance_unique_id;
122 
123  if ($chain === '' || is_null($chain)) {
124  return '';
125  }
126 
127  $reg = array();
128  if (preg_match('/^dolcrypt:([^:]+):(.+)$/', $chain, $reg)) {
129  // The $chain is already a crypted string
130  return $chain;
131  }
132 
133  if (empty($key)) {
134  $key = $dolibarr_main_instance_unique_id;
135  }
136 
137  $newchain = $chain;
138 
139  if (function_exists('openssl_encrypt')) {
140  $ivlen = 16;
141  if (function_exists('openssl_cipher_iv_length')) {
142  $ivlen = openssl_cipher_iv_length($ciphering);
143  }
144  if ($ivlen === false || $ivlen < 1 || $ivlen > 32) {
145  $ivlen = 16;
146  }
147  $ivseed = dolGetRandomBytes($ivlen);
148 
149  $newchain = openssl_encrypt($chain, $ciphering, $key, 0, $ivseed);
150  return 'dolcrypt:'.$ciphering.':'.$ivseed.':'.$newchain;
151  } else {
152  return $chain;
153  }
154 }
155 
165 function dolDecrypt($chain, $key = '')
166 {
167  global $dolibarr_main_instance_unique_id;
168 
169  if ($chain === '' || is_null($chain)) {
170  return '';
171  }
172 
173  if (empty($key)) {
174  $key = $dolibarr_main_instance_unique_id;
175  }
176 
177  $reg = array();
178  if (preg_match('/^dolcrypt:([^:]+):(.+)$/', $chain, $reg)) {
179  $ciphering = $reg[1];
180  if (function_exists('openssl_decrypt')) {
181  $tmpexplode = explode(':', $reg[2]);
182  if (!empty($tmpexplode[1]) && is_string($tmpexplode[0])) {
183  $newchain = openssl_decrypt($tmpexplode[1], $ciphering, $key, 0, $tmpexplode[0]);
184  } else {
185  $newchain = openssl_decrypt($tmpexplode[0], $ciphering, $key, 0, null);
186  }
187  } else {
188  $newchain = 'Error function openssl_decrypt() not available';
189  }
190  return $newchain;
191  } else {
192  return $chain;
193  }
194 }
195 
206 function dol_hash($chain, $type = '0')
207 {
208  global $conf;
209 
210  // No need to add salt for password_hash
211  if (($type == '0' || $type == 'auto') && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'password_hash' && function_exists('password_hash')) {
212  return password_hash($chain, PASSWORD_DEFAULT);
213  }
214 
215  // Salt value
216  if (!empty($conf->global->MAIN_SECURITY_SALT) && $type != '4' && $type !== 'openldap') {
217  $chain = $conf->global->MAIN_SECURITY_SALT.$chain;
218  }
219 
220  if ($type == '1' || $type == 'sha1') {
221  return sha1($chain);
222  } elseif ($type == '2' || $type == 'sha1md5') {
223  return sha1(md5($chain));
224  } elseif ($type == '3' || $type == 'md5') {
225  return md5($chain);
226  } elseif ($type == '4' || $type == 'openldap') {
227  return dolGetLdapPasswordHash($chain, getDolGlobalString('LDAP_PASSWORD_HASH_TYPE', 'md5'));
228  } elseif ($type == '5' || $type == 'sha256') {
229  return hash('sha256', $chain);
230  } elseif ($type == '6' || $type == 'password_hash') {
231  return password_hash($chain, PASSWORD_DEFAULT);
232  } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1') {
233  return sha1($chain);
234  } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1md5') {
235  return sha1(md5($chain));
236  }
237 
238  // No particular encoding defined, use default
239  return md5($chain);
240 }
241 
254 function dol_verifyHash($chain, $hash, $type = '0')
255 {
256  global $conf;
257 
258  if ($type == '0' && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'password_hash' && function_exists('password_verify')) {
259  if ($hash[0] == '$') {
260  return password_verify($chain, $hash);
261  } elseif (strlen($hash) == 32) {
262  return dol_verifyHash($chain, $hash, '3'); // md5
263  } elseif (strlen($hash) == 40) {
264  return dol_verifyHash($chain, $hash, '2'); // sha1md5
265  }
266 
267  return false;
268  }
269 
270  return dol_hash($chain, $type) == $hash;
271 }
272 
280 function dolGetLdapPasswordHash($password, $type = 'md5')
281 {
282  if (empty($type)) {
283  $type = 'md5';
284  }
285 
286  $salt = substr(sha1(time()), 0, 8);
287 
288  if ($type === 'md5') {
289  return '{MD5}' . base64_encode(hash("md5", $password, true)); //For OpenLdap with md5 (based on an unencrypted password in base)
290  } elseif ($type === 'md5frommd5') {
291  return '{MD5}' . base64_encode(hex2bin($password)); // Create OpenLDAP MD5 password from Dolibarr MD5 password
292  } elseif ($type === 'smd5') {
293  return "{SMD5}" . base64_encode(hash("md5", $password . $salt, true) . $salt);
294  } elseif ($type === 'sha') {
295  return '{SHA}' . base64_encode(hash("sha1", $password, true));
296  } elseif ($type === 'ssha') {
297  return "{SSHA}" . base64_encode(hash("sha1", $password . $salt, true) . $salt);
298  } elseif ($type === 'sha256') {
299  return "{SHA256}" . base64_encode(hash("sha256", $password, true));
300  } elseif ($type === 'ssha256') {
301  return "{SSHA256}" . base64_encode(hash("sha256", $password . $salt, true) . $salt);
302  } elseif ($type === 'sha384') {
303  return "{SHA384}" . base64_encode(hash("sha384", $password, true));
304  } elseif ($type === 'ssha384') {
305  return "{SSHA384}" . base64_encode(hash("sha384", $password . $salt, true) . $salt);
306  } elseif ($type === 'sha512') {
307  return "{SHA512}" . base64_encode(hash("sha512", $password, true));
308  } elseif ($type === 'ssha512') {
309  return "{SSHA512}" . base64_encode(hash("sha512", $password . $salt, true) . $salt);
310  } elseif ($type === 'crypt') {
311  return '{CRYPT}' . crypt($password, $salt);
312  } elseif ($type === 'clear') {
313  return '{CLEAR}' . $password; // Just for test, plain text password is not secured !
314  }
315 }
316 
337 function restrictedArea(User $user, $features, $object = 0, $tableandshare = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid', $isdraft = 0, $mode = 0)
338 {
339  global $db, $conf;
340  global $hookmanager;
341 
342  if (is_object($object)) {
343  $objectid = $object->id;
344  } else {
345  $objectid = $object; // $objectid can be X or 'X,Y,Z'
346  }
347  $objectid = preg_replace('/[^0-9\.\,]/', '', $objectid); // For the case value is coming from a non sanitized user input
348 
349  //dol_syslog("functions.lib:restrictedArea $feature, $objectid, $dbtablename, $feature2, $dbt_socfield, $dbt_select, $isdraft");
350  //print "user_id=".$user->id.", features=".$features.", feature2=".$feature2.", objectid=".$objectid;
351  //print ", dbtablename=".$tableandshare.", dbt_socfield=".$dbt_keyfield.", dbt_select=".$dbt_select;
352  //print ", perm: ".$features."->".$feature2."=".($user->rights->$features->$feature2->lire)."<br>";
353 
354  $parentfortableentity = '';
355 
356  // Fix syntax of $features param
357  $originalfeatures = $features;
358  if ($features == 'facturerec') {
359  $features = 'facture';
360  }
361  if ($features == 'mo') {
362  $features = 'mrp';
363  }
364  if ($features == 'member') {
365  $features = 'adherent';
366  }
367  if ($features == 'subscription') {
368  $features = 'adherent';
369  $feature2 = 'cotisation';
370  }
371  if ($features == 'websitepage') {
372  $features = 'website';
373  $tableandshare = 'website_page';
374  $parentfortableentity = 'fk_website@website';
375  }
376  if ($features == 'project') {
377  $features = 'projet';
378  }
379  if ($features == 'product') {
380  $features = 'produit';
381  }
382 
383  // Get more permissions checks from hooks
384  $parameters = array('features'=>$features, 'originalfeatures'=>$originalfeatures, 'objectid'=>$objectid, 'dbt_select'=>$dbt_select, 'idtype'=>$dbt_select, 'isdraft'=>$isdraft);
385  $reshook = $hookmanager->executeHooks('restrictedArea', $parameters);
386 
387  if (isset($hookmanager->resArray['result'])) {
388  if ($hookmanager->resArray['result'] == 0) {
389  if ($mode) {
390  return 0;
391  } else {
392  accessforbidden(); // Module returns 0, so access forbidden
393  }
394  }
395  }
396  if ($reshook > 0) { // No other test done.
397  return 1;
398  }
399 
400  // Features/modules to check
401  $featuresarray = array($features);
402  if (preg_match('/&/', $features)) {
403  $featuresarray = explode("&", $features);
404  } elseif (preg_match('/\|/', $features)) {
405  $featuresarray = explode("|", $features);
406  }
407 
408  // More subfeatures to check
409  if (!empty($feature2)) {
410  $feature2 = explode("|", $feature2);
411  }
412 
413  $listofmodules = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
414 
415  // Check read permission from module
416  $readok = 1;
417  $nbko = 0;
418  foreach ($featuresarray as $feature) { // first we check nb of test ko
419  $featureforlistofmodule = $feature;
420  if ($featureforlistofmodule == 'produit') {
421  $featureforlistofmodule = 'product';
422  }
423  if (!empty($user->socid) && !empty($conf->global->MAIN_MODULES_FOR_EXTERNAL) && !in_array($featureforlistofmodule, $listofmodules)) { // If limits on modules for external users, module must be into list of modules for external users
424  $readok = 0;
425  $nbko++;
426  continue;
427  }
428 
429  if ($feature == 'societe') {
430  if (!$user->hasRight('societe', 'lire') && !$user->hasRight('fournisseur', 'lire')) {
431  $readok = 0;
432  $nbko++;
433  }
434  } elseif ($feature == 'contact') {
435  if (empty($user->rights->societe->contact->lire)) {
436  $readok = 0;
437  $nbko++;
438  }
439  } elseif ($feature == 'produit|service') {
440  if (empty($user->rights->produit->lire) && empty($user->rights->service->lire)) {
441  $readok = 0;
442  $nbko++;
443  }
444  } elseif ($feature == 'prelevement') {
445  if (empty($user->rights->prelevement->bons->lire)) {
446  $readok = 0;
447  $nbko++;
448  }
449  } elseif ($feature == 'cheque') {
450  if (empty($user->rights->banque->cheque)) {
451  $readok = 0;
452  $nbko++;
453  }
454  } elseif ($feature == 'projet') {
455  if (empty($user->rights->projet->lire) && empty($user->rights->projet->all->lire)) {
456  $readok = 0;
457  $nbko++;
458  }
459  } elseif ($feature == 'payment') {
460  if (empty($user->rights->facture->lire)) {
461  $readok = 0;
462  $nbko++;
463  }
464  } elseif ($feature == 'payment_supplier') {
465  if (empty($user->rights->fournisseur->facture->lire)) {
466  $readok = 0;
467  $nbko++;
468  }
469  } elseif ($feature == 'payment_sc') {
470  if (empty($user->rights->tax->charges->lire)) {
471  $readok = 0;
472  $nbko++;
473  }
474  } elseif (!empty($feature2)) { // This is for permissions on 2 levels
475  $tmpreadok = 1;
476  foreach ($feature2 as $subfeature) {
477  if ($subfeature == 'user' && $user->id == $objectid) {
478  continue; // A user can always read its own card
479  }
480  if (!empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) {
481  $tmpreadok = 0;
482  } elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) {
483  $tmpreadok = 0;
484  } else {
485  $tmpreadok = 1;
486  break;
487  } // Break is to bypass second test if the first is ok
488  }
489  if (!$tmpreadok) { // We found a test on feature that is ko
490  $readok = 0; // All tests are ko (we manage here the and, the or will be managed later using $nbko).
491  $nbko++;
492  }
493  } elseif (!empty($feature) && ($feature != 'user' && $feature != 'usergroup')) { // This is permissions on 1 level
494  if (empty($user->rights->$feature->lire)
495  && empty($user->rights->$feature->read)
496  && empty($user->rights->$feature->run)) {
497  $readok = 0;
498  $nbko++;
499  }
500  }
501  }
502 
503  // If a or and at least one ok
504  if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
505  $readok = 1;
506  }
507 
508  if (!$readok) {
509  if ($mode) {
510  return 0;
511  } else {
512  accessforbidden();
513  }
514  }
515  //print "Read access is ok";
516 
517  // Check write permission from module (we need to know write permission to create but also to delete drafts record or to upload files)
518  $createok = 1;
519  $nbko = 0;
520  $wemustcheckpermissionforcreate = (GETPOST('sendit', 'alpha') || GETPOST('linkit', 'alpha') || in_array(GETPOST('action', 'aZ09'), array('create', 'update', 'add_element_resource', 'confirm_delete_linked_resource')) || GETPOST('roworder', 'alpha', 2));
521  $wemustcheckpermissionfordeletedraft = ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete');
522 
523  if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
524  foreach ($featuresarray as $feature) {
525  if ($feature == 'contact') {
526  if (empty($user->rights->societe->contact->creer)) {
527  $createok = 0;
528  $nbko++;
529  }
530  } elseif ($feature == 'produit|service') {
531  if (empty($user->rights->produit->creer) && empty($user->rights->service->creer)) {
532  $createok = 0;
533  $nbko++;
534  }
535  } elseif ($feature == 'prelevement') {
536  if (!$user->rights->prelevement->bons->creer) {
537  $createok = 0;
538  $nbko++;
539  }
540  } elseif ($feature == 'commande_fournisseur') {
541  if (empty($user->rights->fournisseur->commande->creer) || empty($user->rights->supplier_order->creer)) {
542  $createok = 0;
543  $nbko++;
544  }
545  } elseif ($feature == 'banque') {
546  if (empty($user->rights->banque->modifier)) {
547  $createok = 0;
548  $nbko++;
549  }
550  } elseif ($feature == 'cheque') {
551  if (empty($user->rights->banque->cheque)) {
552  $createok = 0;
553  $nbko++;
554  }
555  } elseif ($feature == 'import') {
556  if (empty($user->rights->import->run)) {
557  $createok = 0;
558  $nbko++;
559  }
560  } elseif ($feature == 'ecm') {
561  if (!$user->rights->ecm->upload) {
562  $createok = 0;
563  $nbko++;
564  }
565  } elseif (!empty($feature2)) { // This is for permissions on one level
566  foreach ($feature2 as $subfeature) {
567  if ($subfeature == 'user' && $user->id == $objectid && $user->rights->user->self->creer) {
568  continue; // User can edit its own card
569  }
570  if ($subfeature == 'user' && $user->id == $objectid && $user->rights->user->self->password) {
571  continue; // User can edit its own password
572  }
573  if ($subfeature == 'user' && $user->id != $objectid && $user->rights->user->user->password) {
574  continue; // User can edit another user's password
575  }
576 
577  if (empty($user->rights->$feature->$subfeature->creer)
578  && empty($user->rights->$feature->$subfeature->write)
579  && empty($user->rights->$feature->$subfeature->create)) {
580  $createok = 0;
581  $nbko++;
582  } else {
583  $createok = 1;
584  // Break to bypass second test if the first is ok
585  break;
586  }
587  }
588  } elseif (!empty($feature)) { // This is for permissions on 2 levels ('creer' or 'write')
589  //print '<br>feature='.$feature.' creer='.$user->rights->$feature->creer.' write='.$user->rights->$feature->write; exit;
590  if (empty($user->rights->$feature->creer)
591  && empty($user->rights->$feature->write)
592  && empty($user->rights->$feature->create)) {
593  $createok = 0;
594  $nbko++;
595  }
596  }
597  }
598 
599  // If a or and at least one ok
600  if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
601  $createok = 1;
602  }
603 
604  if ($wemustcheckpermissionforcreate && !$createok) {
605  if ($mode) {
606  return 0;
607  } else {
608  accessforbidden();
609  }
610  }
611  //print "Write access is ok";
612  }
613 
614  // Check create user permission
615  $createuserok = 1;
616  if (GETPOST('action', 'aZ09') == 'confirm_create_user' && GETPOST("confirm", 'aZ09') == 'yes') {
617  if (!$user->rights->user->user->creer) {
618  $createuserok = 0;
619  }
620 
621  if (!$createuserok) {
622  if ($mode) {
623  return 0;
624  } else {
625  accessforbidden();
626  }
627  }
628  //print "Create user access is ok";
629  }
630 
631  // Check delete permission from module
632  $deleteok = 1;
633  $nbko = 0;
634  if ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete') {
635  foreach ($featuresarray as $feature) {
636  if ($feature == 'contact') {
637  if (!$user->rights->societe->contact->supprimer) {
638  $deleteok = 0;
639  }
640  } elseif ($feature == 'produit|service') {
641  if (!$user->rights->produit->supprimer && !$user->rights->service->supprimer) {
642  $deleteok = 0;
643  }
644  } elseif ($feature == 'commande_fournisseur') {
645  if (!$user->rights->fournisseur->commande->supprimer) {
646  $deleteok = 0;
647  }
648  } elseif ($feature == 'payment_supplier') { // Permission to delete a payment of an invoice is permission to edit an invoice.
649  if (!$user->rights->fournisseur->facture->creer) {
650  $deleteok = 0;
651  }
652  } elseif ($feature == 'payment') {
653  if (!$user->rights->facture->paiement) {
654  $deleteok = 0;
655  }
656  } elseif ($feature == 'payment_sc') {
657  if (!$user->rights->tax->charges->creer) {
658  $deleteok = 0;
659  }
660  } elseif ($feature == 'banque') {
661  if (empty($user->rights->banque->modifier)) {
662  $deleteok = 0;
663  }
664  } elseif ($feature == 'cheque') {
665  if (empty($user->rights->banque->cheque)) {
666  $deleteok = 0;
667  }
668  } elseif ($feature == 'ecm') {
669  if (!$user->rights->ecm->upload) {
670  $deleteok = 0;
671  }
672  } elseif ($feature == 'ftp') {
673  if (!$user->rights->ftp->write) {
674  $deleteok = 0;
675  }
676  } elseif ($feature == 'salaries') {
677  if (!$user->rights->salaries->delete) {
678  $deleteok = 0;
679  }
680  } elseif ($feature == 'adherent') {
681  if (empty($user->rights->adherent->supprimer)) {
682  $deleteok = 0;
683  }
684  } elseif ($feature == 'paymentbybanktransfer') {
685  if (empty($user->rights->paymentbybanktransfer->create)) { // There is no delete permission
686  $deleteok = 0;
687  }
688  } elseif ($feature == 'prelevement') {
689  if (empty($user->rights->prelevement->bons->creer)) { // There is no delete permission
690  $deleteok = 0;
691  }
692  } elseif (!empty($feature2)) { // This is for permissions on 2 levels
693  foreach ($feature2 as $subfeature) {
694  if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) {
695  $deleteok = 0;
696  } else {
697  $deleteok = 1;
698  break;
699  } // For bypass the second test if the first is ok
700  }
701  } elseif (!empty($feature)) { // This is used for permissions on 1 level
702  //print '<br>feature='.$feature.' creer='.$user->rights->$feature->supprimer.' write='.$user->rights->$feature->delete;
703  if (empty($user->rights->$feature->supprimer)
704  && empty($user->rights->$feature->delete)
705  && empty($user->rights->$feature->run)) {
706  $deleteok = 0;
707  }
708  }
709  }
710 
711  // If a or and at least one ok
712  if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
713  $deleteok = 1;
714  }
715 
716  if (!$deleteok && !($isdraft && $createok)) {
717  if ($mode) {
718  return 0;
719  } else {
720  accessforbidden();
721  }
722  }
723  //print "Delete access is ok";
724  }
725 
726  // If we have a particular object to check permissions on, we check if $user has permission
727  // for this given object (link to company, is contact for project, ...)
728  if (!empty($objectid) && $objectid > 0) {
729  $ok = checkUserAccessToObject($user, $featuresarray, $object, $tableandshare, $feature2, $dbt_keyfield, $dbt_select, $parentfortableentity);
730  $params = array('objectid' => $objectid, 'features' => join(',', $featuresarray), 'features2' => $feature2);
731  //print 'checkUserAccessToObject ok='.$ok;
732  if ($mode) {
733  return $ok ? 1 : 0;
734  } else {
735  if ($ok) {
736  return 1;
737  } else {
738  accessforbidden('', 1, 1, 0, $params);
739  }
740  }
741  }
742 
743  return 1;
744 }
745 
761 function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tableandshare = '', $feature2 = '', $dbt_keyfield = '', $dbt_select = 'rowid', $parenttableforentity = '')
762 {
763  global $db, $conf;
764 
765  if (is_object($object)) {
766  $objectid = $object->id;
767  } else {
768  $objectid = $object; // $objectid can be X or 'X,Y,Z'
769  }
770  $objectid = preg_replace('/[^0-9\.\,]/', '', $objectid); // For the case value is coming from a non sanitized user input
771 
772  //dol_syslog("functions.lib:restrictedArea $feature, $objectid, $dbtablename, $feature2, $dbt_socfield, $dbt_select, $isdraft");
773  //print "user_id=".$user->id.", features=".join(',', $featuresarray).", objectid=".$objectid;
774  //print ", tableandshare=".$tableandshare.", dbt_socfield=".$dbt_keyfield.", dbt_select=".$dbt_select."<br>";
775 
776  // More parameters
777  $params = explode('&', $tableandshare);
778  $dbtablename = (!empty($params[0]) ? $params[0] : '');
779  $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
780 
781  foreach ($featuresarray as $feature) {
782  $sql = '';
783 
784  //var_dump($feature);exit;
785 
786  // For backward compatibility
787  if ($feature == 'member') {
788  $feature = 'adherent';
789  }
790  if ($feature == 'project') {
791  $feature = 'projet';
792  }
793  if ($feature == 'task') {
794  $feature = 'projet_task';
795  }
796 
797  $checkonentitydone = 0;
798 
799  // Array to define rules of checks to do
800  $check = array('adherent', 'banque', 'bom', 'don', 'mrp', 'user', 'usergroup', 'payment', 'payment_supplier', 'product', 'produit', 'service', 'produit|service', 'categorie', 'resource', 'expensereport', 'holiday', 'salaries', 'website', 'recruitment'); // Test on entity only (Objects with no link to company)
801  $checksoc = array('societe'); // Test for object Societe
802  $checkother = array('contact', 'agenda'); // Test on entity + link to third party on field $dbt_keyfield. Allowed if link is empty (Ex: contacts...).
803  $checkproject = array('projet', 'project'); // Test for project object
804  $checktask = array('projet_task'); // Test for task object
805  $checkhierarchy = array('expensereport', 'holiday'); // check permission among the hierarchy of user
806  $nocheck = array('barcode', 'stock'); // No test
807 
808  //$checkdefault = 'all other not already defined'; // Test on entity + link to third party on field $dbt_keyfield. Not allowed if link is empty (Ex: invoice, orders...).
809 
810  // If dbtablename not defined, we use same name for table than module name
811  if (empty($dbtablename)) {
812  $dbtablename = $feature;
813  $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename); // We change dbtablename, so we set sharedelement too.
814  }
815 
816  // To avoid an access forbidden with a numeric ref
817  if ($dbt_select != 'rowid' && $dbt_select != 'id') {
818  $objectid = "'".$objectid."'"; // Note: $objectid was already cast into int at begin of this method.
819  }
820 
821  // Check permission for objectid on entity only
822  if (in_array($feature, $check) && $objectid > 0) { // For $objectid = 0, no check
823  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
824  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
825  if (($feature == 'user' || $feature == 'usergroup') && isModEnabled('multicompany')) { // Special for multicompany
826  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
827  if ($conf->entity == 1 && $user->admin && !$user->entity) {
828  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
829  $sql .= " AND dbt.entity IS NOT NULL";
830  } else {
831  $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
832  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
833  $sql .= " AND ((ug.fk_user = dbt.rowid";
834  $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
835  $sql .= " OR dbt.entity = 0)"; // Show always superadmin
836  }
837  } else {
838  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
839  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
840  }
841  } else {
842  $reg = array();
843  if ($parenttableforentity && preg_match('/(.*)@(.*)/', $parenttableforentity, $reg)) {
844  $sql .= ", ".MAIN_DB_PREFIX.$reg[2]." as dbtp";
845  $sql .= " WHERE dbt.".$reg[1]." = dbtp.rowid AND dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
846  $sql .= " AND dbtp.entity IN (".getEntity($sharedelement, 1).")";
847  } else {
848  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
849  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
850  }
851  }
852  $checkonentitydone = 1;
853  }
854  if (in_array($feature, $checksoc) && $objectid > 0) { // We check feature = checksoc. For $objectid = 0, no check
855  // If external user: Check permission for external users
856  if ($user->socid > 0) {
857  if ($user->socid != $objectid) {
858  return false;
859  }
860  } elseif (isModEnabled("societe") && ($user->hasRight('societe', 'lire') && empty($user->rights->societe->client->voir))) {
861  // If internal user: Check permission for internal users that are restricted on their objects
862  $sql = "SELECT COUNT(sc.fk_soc) as nb";
863  $sql .= " FROM (".MAIN_DB_PREFIX."societe_commerciaux as sc";
864  $sql .= ", ".MAIN_DB_PREFIX."societe as s)";
865  $sql .= " WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).")";
866  $sql .= " AND sc.fk_user = ".((int) $user->id);
867  $sql .= " AND sc.fk_soc = s.rowid";
868  $sql .= " AND s.entity IN (".getEntity($sharedelement, 1).")";
869  } elseif (isModEnabled('multicompany')) {
870  // If multicompany and internal users with all permissions, check user is in correct entity
871  $sql = "SELECT COUNT(s.rowid) as nb";
872  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
873  $sql .= " WHERE s.rowid IN (".$db->sanitize($objectid, 1).")";
874  $sql .= " AND s.entity IN (".getEntity($sharedelement, 1).")";
875  }
876 
877  $checkonentitydone = 1;
878  }
879  if (in_array($feature, $checkother) && $objectid > 0) { // Test on entity + link to thirdparty. Allowed if link is empty (Ex: contacts...).
880  // If external user: Check permission for external users
881  if ($user->socid > 0) {
882  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
883  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
884  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
885  $sql .= " AND dbt.fk_soc = ".((int) $user->socid);
886  } elseif (isModEnabled("societe") && ($user->hasRight('societe', 'lire') && empty($user->rights->societe->client->voir))) {
887  // If internal user: Check permission for internal users that are restricted on their objects
888  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
889  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
890  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
891  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
892  $sql .= " AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)"; // Contact not linked to a company or to a company of user
893  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
894  } elseif (isModEnabled('multicompany')) {
895  // If multicompany and internal users with all permissions, check user is in correct entity
896  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
897  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
898  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
899  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
900  }
901 
902  $checkonentitydone = 1;
903  }
904  if (in_array($feature, $checkproject) && $objectid > 0) {
905  if (isModEnabled('project') && empty($user->rights->projet->all->lire)) {
906  $projectid = $objectid;
907 
908  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
909  $projectstatic = new Project($db);
910  $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
911 
912  $tmparray = explode(',', $tmps);
913  if (!in_array($projectid, $tmparray)) {
914  return false;
915  }
916  } else {
917  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
918  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
919  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
920  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
921  }
922 
923  $checkonentitydone = 1;
924  }
925  if (in_array($feature, $checktask) && $objectid > 0) {
926  if (isModEnabled('project') && empty($user->rights->projet->all->lire)) {
927  $task = new Task($db);
928  $task->fetch($objectid);
929  $projectid = $task->fk_project;
930 
931  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
932  $projectstatic = new Project($db);
933  $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
934 
935  $tmparray = explode(',', $tmps);
936  if (!in_array($projectid, $tmparray)) {
937  return false;
938  }
939  } else {
940  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
941  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
942  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
943  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
944  }
945 
946  $checkonentitydone = 1;
947  }
948  if (!$checkonentitydone && !in_array($feature, $nocheck) && $objectid > 0) { // By default (case of $checkdefault), we check on object entity + link to third party on field $dbt_keyfield
949  // If external user: Check permission for external users
950  if ($user->socid > 0) {
951  if (empty($dbt_keyfield)) {
952  dol_print_error('', 'Param dbt_keyfield is required but not defined');
953  }
954  $sql = "SELECT COUNT(dbt.".$dbt_keyfield.") as nb";
955  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
956  $sql .= " WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).")";
957  $sql .= " AND dbt.".$dbt_keyfield." = ".((int) $user->socid);
958  } elseif (isModEnabled("societe") && empty($user->rights->societe->client->voir)) {
959  // If internal user: Check permission for internal users that are restricted on their objects
960  if ($feature != 'ticket') {
961  if (empty($dbt_keyfield)) {
962  dol_print_error('', 'Param dbt_keyfield is required but not defined');
963  }
964  $sql = "SELECT COUNT(sc.fk_soc) as nb";
965  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
966  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
967  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
968  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
969  $sql .= " AND sc.fk_soc = dbt.".$dbt_keyfield;
970  $sql .= " AND sc.fk_user = ".((int) $user->id);
971  } else {
972  // On ticket, the thirdparty is not mandatory, so we need a special test to accept record with no thirdparties.
973  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
974  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
975  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = dbt.".$dbt_keyfield." AND sc.fk_user = ".((int) $user->id);
976  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
977  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
978  $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR sc.fk_user IS NULL)";
979  }
980  } elseif (isModEnabled('multicompany')) {
981  // If multicompany and internal users with all permissions, check user is in correct entity
982  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
983  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
984  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
985  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
986  }
987  }
988  //print $sql;
989 
990  // For events, check on users assigned to event
991  if ($feature === 'agenda' && $objectid > 0) {
992  // Also check owner or attendee for users without allactions->read
993  if ($objectid > 0 && empty($user->rights->agenda->allactions->read)) {
994  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
995  $action = new ActionComm($db);
996  $action->fetch($objectid);
997  if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
998  return false;
999  }
1000  }
1001  }
1002 
1003  // For some object, we also have to check it is in the user hierarchy
1004  // Param $object must be the full object and not a simple id to have this test possible.
1005  if (in_array($feature, $checkhierarchy) && is_object($object) && $objectid > 0) {
1006  $childids = $user->getAllChildIds(1);
1007  $useridtocheck = 0;
1008  if ($feature == 'holiday') {
1009  $useridtocheck = $object->fk_user;
1010  if (!in_array($useridtocheck, $childids)) {
1011  return false;
1012  }
1013  $useridtocheck = $object->fk_validator;
1014  if (!in_array($useridtocheck, $childids)) {
1015  return false;
1016  }
1017  }
1018  if ($feature == 'expensereport') {
1019  $useridtocheck = $object->fk_user_author;
1020  if (!$user->rights->expensereport->readall) {
1021  if (!in_array($useridtocheck, $childids)) {
1022  return false;
1023  }
1024  }
1025  }
1026  }
1027 
1028  if ($sql) {
1029  $resql = $db->query($sql);
1030  if ($resql) {
1031  $obj = $db->fetch_object($resql);
1032  if (!$obj || $obj->nb < count(explode(',', $objectid))) { // error if we found 0 or less record than nb of id provided
1033  return false;
1034  }
1035  } else {
1036  dol_syslog("Bad forged sql in checkUserAccessToObject", LOG_WARNING);
1037  return false;
1038  }
1039  }
1040  }
1041 
1042  return true;
1043 }
1044 
1045 
1057 function httponly_accessforbidden($message = 1, $http_response_code = 403, $stringalreadysanitized = 0)
1058 {
1059  top_httphead();
1060  http_response_code($http_response_code);
1061 
1062  if ($stringalreadysanitized) {
1063  print $message;
1064  } else {
1065  print htmlentities($message);
1066  }
1067 
1068  exit(1);
1069 }
1070 
1084 function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params = null)
1085 {
1086  global $conf, $db, $user, $langs, $hookmanager;
1087 
1088  if (!is_object($langs)) {
1089  include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
1090  $langs = new Translate('', $conf);
1091  $langs->setDefaultLang();
1092  }
1093 
1094  $langs->load("errors");
1095 
1096  if ($printheader) {
1097  if (function_exists("llxHeader")) {
1098  llxHeader('');
1099  } elseif (function_exists("llxHeaderVierge")) {
1100  llxHeaderVierge('');
1101  }
1102  }
1103  print '<div class="error">';
1104  if (empty($message)) {
1105  print $langs->trans("ErrorForbidden");
1106  } else {
1107  print $langs->trans($message);
1108  }
1109  print '</div>';
1110  print '<br>';
1111  if (empty($showonlymessage)) {
1112  global $action, $object;
1113  if (empty($hookmanager)) {
1114  $hookmanager = new HookManager($db);
1115  // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1116  $hookmanager->initHooks(array('main'));
1117  }
1118  $parameters = array('message'=>$message, 'params'=>$params);
1119  $reshook = $hookmanager->executeHooks('getAccessForbiddenMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1120  print $hookmanager->resPrint;
1121  if (empty($reshook)) {
1122  $langs->loadLangs(array("errors"));
1123  if ($user->login) {
1124  print $langs->trans("CurrentLogin").': <span class="error">'.$user->login.'</span><br>';
1125  print $langs->trans("ErrorForbidden2", $langs->transnoentitiesnoconv("Home"), $langs->transnoentitiesnoconv("Users"));
1126  print $langs->trans("ErrorForbidden4");
1127  } else {
1128  print $langs->trans("ErrorForbidden3");
1129  }
1130  }
1131  }
1132  if ($printfooter && function_exists("llxFooter")) {
1133  llxFooter();
1134  }
1135 
1136  exit(0);
1137 }
1138 
1139 
1147 {
1148  global $conf;
1149 
1150  $max = $conf->global->MAIN_UPLOAD_DOC; // In Kb
1151  $maxphp = @ini_get('upload_max_filesize'); // In unknown
1152  if (preg_match('/k$/i', $maxphp)) {
1153  $maxphp = preg_replace('/k$/i', '', $maxphp);
1154  $maxphp = $maxphp * 1;
1155  }
1156  if (preg_match('/m$/i', $maxphp)) {
1157  $maxphp = preg_replace('/m$/i', '', $maxphp);
1158  $maxphp = $maxphp * 1024;
1159  }
1160  if (preg_match('/g$/i', $maxphp)) {
1161  $maxphp = preg_replace('/g$/i', '', $maxphp);
1162  $maxphp = $maxphp * 1024 * 1024;
1163  }
1164  if (preg_match('/t$/i', $maxphp)) {
1165  $maxphp = preg_replace('/t$/i', '', $maxphp);
1166  $maxphp = $maxphp * 1024 * 1024 * 1024;
1167  }
1168  $maxphp2 = @ini_get('post_max_size'); // In unknown
1169  if (preg_match('/k$/i', $maxphp2)) {
1170  $maxphp2 = preg_replace('/k$/i', '', $maxphp2);
1171  $maxphp2 = $maxphp2 * 1;
1172  }
1173  if (preg_match('/m$/i', $maxphp2)) {
1174  $maxphp2 = preg_replace('/m$/i', '', $maxphp2);
1175  $maxphp2 = $maxphp2 * 1024;
1176  }
1177  if (preg_match('/g$/i', $maxphp2)) {
1178  $maxphp2 = preg_replace('/g$/i', '', $maxphp2);
1179  $maxphp2 = $maxphp2 * 1024 * 1024;
1180  }
1181  if (preg_match('/t$/i', $maxphp2)) {
1182  $maxphp2 = preg_replace('/t$/i', '', $maxphp2);
1183  $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
1184  }
1185  // Now $max and $maxphp and $maxphp2 are in Kb
1186  $maxmin = $max;
1187  $maxphptoshow = $maxphptoshowparam = '';
1188  if ($maxphp > 0) {
1189  $maxmin = min($maxmin, $maxphp);
1190  $maxphptoshow = $maxphp;
1191  $maxphptoshowparam = 'upload_max_filesize';
1192  }
1193  if ($maxphp2 > 0) {
1194  $maxmin = min($maxmin, $maxphp2);
1195  if ($maxphp2 < $maxphp) {
1196  $maxphptoshow = $maxphp2;
1197  $maxphptoshowparam = 'post_max_size';
1198  }
1199  }
1200  //var_dump($maxphp.'-'.$maxphp2);
1201  //var_dump($maxmin);
1202 
1203  return array('max'=>$max, 'maxmin'=>$maxmin, 'maxphptoshow'=>$maxphptoshow, 'maxphptoshowparam'=>$maxphptoshowparam);
1204 }
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOIPCHECK')) llxHeaderVierge()
Header function.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage agenda events (actions)
Class to manage hooks.
Class to manage projects.
Class to manage tasks.
Definition: task.class.php:38
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:45
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1436
dolGetRandomBytes($length)
Return a string of random bytes (hexa string) with length = $length fro cryptographic purposes.
dol_encode($chain, $key='1')
Encode a string with base 64 algorithm + specific delta change.
checkUserAccessToObject($user, array $featuresarray, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='', $dbt_select='rowid', $parenttableforentity='')
Check that access by a given user to an object is ok.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolEncrypt($chain, $key='', $ciphering="AES-256-CTR")
Encode a string with a symetric encryption.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
dolDecrypt($chain, $key='')
Decode a string with a symetric encryption.
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.