dolibarr 18.0.8
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
38function 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
69function 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
100function 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
122function dolEncrypt($chain, $key = '', $ciphering = 'AES-256-CTR', $forceseed = '')
123{
124 global $conf;
125 global $dolibarr_disable_dolcrypt_for_debug;
126
127 if ($chain === '' || is_null($chain)) {
128 return '';
129 }
130
131 $reg = array();
132 if (preg_match('/^dolcrypt:([^:]+):(.+)$/', $chain, $reg)) {
133 // The $chain is already a crypted string
134 return $chain;
135 }
136
137 if (empty($key)) {
138 $key = $conf->file->instance_unique_id;
139 }
140 if (empty($ciphering)) {
141 $ciphering = 'AES-256-CTR';
142 }
143
144 $newchain = $chain;
145
146 if (function_exists('openssl_encrypt') && empty($dolibarr_disable_dolcrypt_for_debug)) {
147 if (empty($key)) {
148 return $chain;
149 }
150
151 $ivlen = 16;
152 if (function_exists('openssl_cipher_iv_length')) {
153 $ivlen = openssl_cipher_iv_length($ciphering);
154 }
155 if ($ivlen === false || $ivlen < 1 || $ivlen > 32) {
156 $ivlen = 16;
157 }
158 if (empty($forceseed)) {
159 $ivseed = dolGetRandomBytes($ivlen);
160 } else {
161 $ivseed = dol_substr(md5($forceseed), 0, $ivlen, 'ascii', 1);
162 }
163
164 $newchain = openssl_encrypt($chain, $ciphering, $key, 0, $ivseed);
165 return 'dolcrypt:'.$ciphering.':'.$ivseed.':'.$newchain;
166 } else {
167 return $chain;
168 }
169}
170
181function dolDecrypt($chain, $key = '')
182{
183 global $conf;
184
185 if ($chain === '' || is_null($chain)) {
186 return '';
187 }
188
189 if (empty($key)) {
190 if (!empty($conf->file->dolcrypt_key)) {
191 // If dolcrypt_key is defined, we used it in priority
192 $key = $conf->file->dolcrypt_key;
193 } else {
194 // We fall back on the instance_unique_id
195 $key = $conf->file->instance_unique_id;
196 }
197 }
198
199 //var_dump('key='.$key);
200 $reg = array();
201 if (preg_match('/^dolcrypt:([^:]+):(.+)$/', $chain, $reg)) {
202 $ciphering = $reg[1];
203 if (function_exists('openssl_decrypt')) {
204 if (empty($key)) {
205 dol_syslog("Error dolDecrypt decrypt key is empty", LOG_WARNING);
206 return $chain;
207 }
208 $tmpexplode = explode(':', $reg[2]);
209 if (!empty($tmpexplode[1]) && is_string($tmpexplode[0])) {
210 $newchain = openssl_decrypt($tmpexplode[1], $ciphering, $key, 0, $tmpexplode[0]);
211 } else {
212 $newchain = openssl_decrypt($tmpexplode[0], $ciphering, $key, 0, null);
213 }
214 } else {
215 dol_syslog("Error dolDecrypt openssl_decrypt is not available", LOG_ERR);
216 return $chain;
217 }
218 return $newchain;
219 } else {
220 return $chain;
221 }
222}
223
234function dol_hash($chain, $type = '0')
235{
236 global $conf;
237
238 // No need to add salt for password_hash
239 if (($type == '0' || $type == 'auto') && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'password_hash' && function_exists('password_hash')) {
240 return password_hash($chain, PASSWORD_DEFAULT);
241 }
242
243 // Salt value
244 if (!empty($conf->global->MAIN_SECURITY_SALT) && $type != '4' && $type !== 'openldap') {
245 $chain = $conf->global->MAIN_SECURITY_SALT.$chain;
246 }
247
248 if ($type == '1' || $type == 'sha1') {
249 return sha1($chain);
250 } elseif ($type == '2' || $type == 'sha1md5') {
251 return sha1(md5($chain));
252 } elseif ($type == '3' || $type == 'md5') {
253 return md5($chain);
254 } elseif ($type == '4' || $type == 'openldap') {
255 return dolGetLdapPasswordHash($chain, getDolGlobalString('LDAP_PASSWORD_HASH_TYPE', 'md5'));
256 } elseif ($type == '5' || $type == 'sha256') {
257 return hash('sha256', $chain);
258 } elseif ($type == '6' || $type == 'password_hash') {
259 return password_hash($chain, PASSWORD_DEFAULT);
260 } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1') {
261 return sha1($chain);
262 } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1md5') {
263 return sha1(md5($chain));
264 }
265
266 // No particular encoding defined, use default
267 return md5($chain);
268}
269
282function dol_verifyHash($chain, $hash, $type = '0')
283{
284 global $conf;
285
286 if ($type == '0' && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'password_hash' && function_exists('password_verify')) {
287 if (! empty($hash[0]) && $hash[0] == '$') {
288 return password_verify($chain, $hash);
289 } elseif (dol_strlen($hash) == 32) {
290 return dol_verifyHash($chain, $hash, '3'); // md5
291 } elseif (dol_strlen($hash) == 40) {
292 return dol_verifyHash($chain, $hash, '2'); // sha1md5
293 }
294
295 return false;
296 }
297
298 return dol_hash($chain, $type) == $hash;
299}
300
308function dolGetLdapPasswordHash($password, $type = 'md5')
309{
310 if (empty($type)) {
311 $type = 'md5';
312 }
313
314 $salt = substr(sha1(time()), 0, 8);
315
316 if ($type === 'md5') {
317 return '{MD5}' . base64_encode(hash("md5", $password, true)); //For OpenLdap with md5 (based on an unencrypted password in base)
318 } elseif ($type === 'md5frommd5') {
319 return '{MD5}' . base64_encode(hex2bin($password)); // Create OpenLDAP MD5 password from Dolibarr MD5 password
320 } elseif ($type === 'smd5') {
321 return "{SMD5}" . base64_encode(hash("md5", $password . $salt, true) . $salt);
322 } elseif ($type === 'sha') {
323 return '{SHA}' . base64_encode(hash("sha1", $password, true));
324 } elseif ($type === 'ssha') {
325 return "{SSHA}" . base64_encode(hash("sha1", $password . $salt, true) . $salt);
326 } elseif ($type === 'sha256') {
327 return "{SHA256}" . base64_encode(hash("sha256", $password, true));
328 } elseif ($type === 'ssha256') {
329 return "{SSHA256}" . base64_encode(hash("sha256", $password . $salt, true) . $salt);
330 } elseif ($type === 'sha384') {
331 return "{SHA384}" . base64_encode(hash("sha384", $password, true));
332 } elseif ($type === 'ssha384') {
333 return "{SSHA384}" . base64_encode(hash("sha384", $password . $salt, true) . $salt);
334 } elseif ($type === 'sha512') {
335 return "{SHA512}" . base64_encode(hash("sha512", $password, true));
336 } elseif ($type === 'ssha512') {
337 return "{SSHA512}" . base64_encode(hash("sha512", $password . $salt, true) . $salt);
338 } elseif ($type === 'crypt') {
339 return '{CRYPT}' . crypt($password, $salt);
340 } elseif ($type === 'clear') {
341 return '{CLEAR}' . $password; // Just for test, plain text password is not secured !
342 }
343 return "";
344}
345
366function restrictedArea(User $user, $features, $object = 0, $tableandshare = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid', $isdraft = 0, $mode = 0)
367{
368 global $db, $conf;
369 global $hookmanager;
370
371 // Define $objectid
372 if (is_object($object)) {
373 $objectid = $object->id;
374 } else {
375 $objectid = $object; // $objectid can be X or 'X,Y,Z'
376 }
377 if ($objectid == "-1") {
378 $objectid = 0;
379 }
380 if ($objectid) {
381 $objectid = preg_replace('/[^0-9\.\,]/', '', $objectid); // For the case value is coming from a non sanitized user input
382 }
383
384 //dol_syslog("functions.lib:restrictedArea $feature, $objectid, $dbtablename, $feature2, $dbt_socfield, $dbt_select, $isdraft");
385 /*print "user_id=".$user->id.", features=".$features.", feature2=".$feature2.", objectid=".$objectid;
386 print ", dbtablename=".$tableandshare.", dbt_socfield=".$dbt_keyfield.", dbt_select=".$dbt_select;
387 print ", perm: user->right->".$features.($feature2 ? "->".$feature2 : "")."=".($user->hasRight($features, $feature2, 'lire'))."<br>";
388 */
389
390 $parentfortableentity = '';
391
392 // Fix syntax of $features param
393 $originalfeatures = $features;
394 if ($features == 'agenda') {
395 $tableandshare = 'actioncomm&societe';
396 $feature2 = 'myactions|allactions';
397 $dbt_select = 'id';
398 }
399 if ($features == 'bank') {
400 $features = 'banque';
401 }
402 if ($features == 'facturerec') {
403 $features = 'facture';
404 }
405 if ($features == 'supplier_invoicerec') {
406 $features = 'fournisseur';
407 $feature2 = 'facture';
408 }
409 if ($features == 'mo') {
410 $features = 'mrp';
411 }
412 if ($features == 'member') {
413 $features = 'adherent';
414 }
415 if ($features == 'subscription') {
416 $features = 'adherent';
417 $feature2 = 'cotisation';
418 }
419 if ($features == 'website' && is_object($object) && $object->element == 'websitepage') {
420 $parentfortableentity = 'fk_website@website';
421 }
422 if ($features == 'project') {
423 $features = 'projet';
424 }
425 if ($features == 'product') {
426 $features = 'produit';
427 }
428 if ($features == 'productbatch') {
429 $features = 'produit';
430 }
431 if ($features == 'tax') {
432 $feature2 = 'charges';
433 }
434 if ($features == 'workstation') {
435 $feature2 = 'workstation';
436 }
437 if ($features == 'fournisseur') { // When vendor invoice and purchase order are into module 'fournisseur'
438 $features = 'fournisseur';
439 if (is_object($object) && $object->element == 'invoice_supplier') {
440 $feature2 = 'facture';
441 } elseif (is_object($object) && $object->element == 'order_supplier') {
442 $feature2 = 'commande';
443 }
444 }
445 if ($features == 'payment_sc') {
446 $tableandshare = 'paiementcharge';
447 $parentfortableentity = 'fk_charge@chargesociales';
448 }
449 if ($features == 'evaluation') {
450 $features = 'hrm';
451 $feature2 = 'evaluation';
452 }
453
454 //print $features.' - '.$tableandshare.' - '.$feature2.' - '.$dbt_select."\n";
455
456 // Get more permissions checks from hooks
457 $parameters = array('features'=>$features, 'originalfeatures'=>$originalfeatures, 'objectid'=>$objectid, 'dbt_select'=>$dbt_select, 'idtype'=>$dbt_select, 'isdraft'=>$isdraft);
458 $reshook = $hookmanager->executeHooks('restrictedArea', $parameters);
459
460 if (isset($hookmanager->resArray['result'])) {
461 if ($hookmanager->resArray['result'] == 0) {
462 if ($mode) {
463 return 0;
464 } else {
465 accessforbidden(); // Module returns 0, so access forbidden
466 }
467 }
468 }
469 if ($reshook > 0) { // No other test done.
470 return 1;
471 }
472
473 // Features/modules to check
474 $featuresarray = array($features);
475 if (preg_match('/&/', $features)) {
476 $featuresarray = explode("&", $features);
477 } elseif (preg_match('/\|/', $features)) {
478 $featuresarray = explode("|", $features);
479 }
480
481 // More subfeatures to check
482 if (!empty($feature2)) {
483 $feature2 = explode("|", $feature2);
484 }
485
486 $listofmodules = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
487
488 // Check read permission from module
489 $readok = 1;
490 $nbko = 0;
491 foreach ($featuresarray as $feature) { // first we check nb of test ko
492 $featureforlistofmodule = $feature;
493 if ($featureforlistofmodule == 'produit') {
494 $featureforlistofmodule = 'product';
495 }
496 if ($featureforlistofmodule == 'supplier_proposal') {
497 $featureforlistofmodule = 'supplierproposal';
498 }
499 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
500 $readok = 0;
501 $nbko++;
502 continue;
503 }
504
505 if ($feature == 'societe' && (empty($feature2) || !in_array('contact', $feature2))) {
506 if (!$user->hasRight('societe', 'lire') && !$user->hasRight('fournisseur', 'lire')) {
507 $readok = 0;
508 $nbko++;
509 }
510 } elseif (($feature == 'societe' && (!empty($feature2) && in_array('contact', $feature2))) || $feature == 'contact') {
511 if (empty($user->rights->societe->contact->lire)) {
512 $readok = 0;
513 $nbko++;
514 }
515 } elseif ($feature == 'produit|service') {
516 if (empty($user->rights->produit->lire) && empty($user->rights->service->lire)) {
517 $readok = 0;
518 $nbko++;
519 }
520 } elseif ($feature == 'prelevement') {
521 if (empty($user->rights->prelevement->bons->lire)) {
522 $readok = 0;
523 $nbko++;
524 }
525 } elseif ($feature == 'cheque') {
526 if (empty($user->rights->banque->cheque)) {
527 $readok = 0;
528 $nbko++;
529 }
530 } elseif ($feature == 'projet') {
531 if (empty($user->rights->projet->lire) && empty($user->rights->projet->all->lire)) {
532 $readok = 0;
533 $nbko++;
534 }
535 } elseif ($feature == 'payment') {
536 if (!$user->hasRight('facture', 'lire')) {
537 $readok = 0;
538 $nbko++;
539 }
540 } elseif ($feature == 'payment_supplier') {
541 if (empty($user->rights->fournisseur->facture->lire)) {
542 $readok = 0;
543 $nbko++;
544 }
545 } elseif ($feature == 'payment_sc') {
546 if (empty($user->rights->tax->charges->lire)) {
547 $readok = 0;
548 $nbko++;
549 }
550 } elseif (!empty($feature2)) { // This is for permissions on 2 levels (module->object->read)
551 $tmpreadok = 1;
552 foreach ($feature2 as $subfeature) {
553 if ($subfeature == 'user' && $user->id == $objectid) {
554 continue; // A user can always read its own card
555 }
556 if ($subfeature == 'fiscalyear' && $user->hasRight('accounting', 'fiscalyear', 'write')) {
557 // only one right for fiscalyear
558 $tmpreadok = 1;
559 continue;
560 }
561 if (!empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) {
562 $tmpreadok = 0;
563 } elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) {
564 $tmpreadok = 0;
565 } else {
566 $tmpreadok = 1;
567 break;
568 } // Break is to bypass second test if the first is ok
569 }
570 if (!$tmpreadok) { // We found a test on feature that is ko
571 $readok = 0; // All tests are ko (we manage here the and, the or will be managed later using $nbko).
572 $nbko++;
573 }
574 } elseif (!empty($feature) && ($feature != 'user' && $feature != 'usergroup')) { // This is permissions on 1 level (module->read)
575 if (empty($user->rights->$feature->lire)
576 && empty($user->rights->$feature->read)
577 && empty($user->rights->$feature->run)) {
578 $readok = 0;
579 $nbko++;
580 }
581 }
582 }
583
584 // If a or and at least one ok
585 if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
586 $readok = 1;
587 }
588
589 if (!$readok) {
590 if ($mode) {
591 return 0;
592 } else {
594 }
595 }
596 //print "Read access is ok";
597
598 // Check write permission from module (we need to know write permission to create but also to delete drafts record or to upload files)
599 $createok = 1;
600 $nbko = 0;
601 $wemustcheckpermissionforcreate = (GETPOST('sendit', 'alpha') || GETPOST('linkit', 'alpha') || in_array(GETPOST('action', 'aZ09'), array('create', 'update', 'set', 'upload', 'add_element_resource', 'confirm_deletebank', 'confirm_delete_linked_resource')) || GETPOST('roworder', 'alpha', 2));
602 $wemustcheckpermissionfordeletedraft = ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete');
603
604 if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
605 foreach ($featuresarray as $feature) {
606 if ($feature == 'contact') {
607 if (empty($user->rights->societe->contact->creer)) {
608 $createok = 0;
609 $nbko++;
610 }
611 } elseif ($feature == 'produit|service') {
612 if (empty($user->rights->produit->creer) && empty($user->rights->service->creer)) {
613 $createok = 0;
614 $nbko++;
615 }
616 } elseif ($feature == 'prelevement') {
617 if (!$user->rights->prelevement->bons->creer) {
618 $createok = 0;
619 $nbko++;
620 }
621 } elseif ($feature == 'commande_fournisseur') {
622 if (empty($user->rights->fournisseur->commande->creer) || empty($user->rights->supplier_order->creer)) {
623 $createok = 0;
624 $nbko++;
625 }
626 } elseif ($feature == 'banque') {
627 if (!$user->hasRight('banque', 'modifier')) {
628 $createok = 0;
629 $nbko++;
630 }
631 } elseif ($feature == 'cheque') {
632 if (empty($user->rights->banque->cheque)) {
633 $createok = 0;
634 $nbko++;
635 }
636 } elseif ($feature == 'import') {
637 if (empty($user->rights->import->run)) {
638 $createok = 0;
639 $nbko++;
640 }
641 } elseif ($feature == 'ecm') {
642 if (!$user->rights->ecm->upload) {
643 $createok = 0;
644 $nbko++;
645 }
646 } elseif (!empty($feature2)) { // This is for permissions on 2 levels (module->object->write)
647 foreach ($feature2 as $subfeature) {
648 if ($subfeature == 'user' && $user->id == $objectid && $user->hasRight('user', 'self', 'creer')) {
649 continue; // User can edit its own card
650 }
651 if ($subfeature == 'user' && $user->id == $objectid && $user->hasRight('user', 'self', 'password')) {
652 continue; // User can edit its own password
653 }
654 if ($subfeature == 'user' && $user->id != $objectid && $user->hasRight('user', 'user', 'password')) {
655 continue; // User can edit another user's password
656 }
657
658 if (empty($user->rights->$feature->$subfeature->creer)
659 && empty($user->rights->$feature->$subfeature->write)
660 && empty($user->rights->$feature->$subfeature->create)) {
661 $createok = 0;
662 $nbko++;
663 } else {
664 $createok = 1;
665 // Break to bypass second test if the first is ok
666 break;
667 }
668 }
669 } elseif (!empty($feature)) { // This is for permissions on 1 levels (module->write)
670 //print '<br>feature='.$feature.' creer='.$user->rights->$feature->creer.' write='.$user->rights->$feature->write; exit;
671 if (empty($user->rights->$feature->creer)
672 && empty($user->rights->$feature->write)
673 && empty($user->rights->$feature->create)) {
674 $createok = 0;
675 $nbko++;
676 }
677 }
678 }
679
680 // If a or and at least one ok
681 if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
682 $createok = 1;
683 }
684
685 if ($wemustcheckpermissionforcreate && !$createok) {
686 if ($mode) {
687 return 0;
688 } else {
690 }
691 }
692 //print "Write access is ok";
693 }
694
695 // Check create user permission
696 $createuserok = 1;
697 if (GETPOST('action', 'aZ09') == 'confirm_create_user' && GETPOST("confirm", 'aZ09') == 'yes') {
698 if (!$user->hasRight('user', 'user', 'creer')) {
699 $createuserok = 0;
700 }
701
702 if (!$createuserok) {
703 if ($mode) {
704 return 0;
705 } else {
707 }
708 }
709 //print "Create user access is ok";
710 }
711
712 // Check delete permission from module
713 $deleteok = 1;
714 $nbko = 0;
715 if ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete') {
716 foreach ($featuresarray as $feature) {
717 if ($feature == 'bookmark') {
718 if (!$user->rights->bookmark->supprimer) {
719 if ($user->id != $object->fk_user || empty($user->rights->bookmark->creer)) {
720 $deleteok = 0;
721 }
722 }
723 } elseif ($feature == 'contact') {
724 if (!$user->rights->societe->contact->supprimer) {
725 $deleteok = 0;
726 }
727 } elseif ($feature == 'produit|service') {
728 if (!$user->hasRight('produit', 'supprimer') && !$user->hasRight('service', 'supprimer')) {
729 $deleteok = 0;
730 }
731 } elseif ($feature == 'commande_fournisseur') {
732 if (!$user->rights->fournisseur->commande->supprimer) {
733 $deleteok = 0;
734 }
735 } elseif ($feature == 'payment_supplier') { // Permission to delete a payment of an invoice is permission to edit an invoice.
736 if (!$user->rights->fournisseur->facture->creer) {
737 $deleteok = 0;
738 }
739 } elseif ($feature == 'payment') {
740 if (!$user->rights->facture->paiement) {
741 $deleteok = 0;
742 }
743 } elseif ($feature == 'payment_sc') {
744 if (!$user->rights->tax->charges->creer) {
745 $deleteok = 0;
746 }
747 } elseif ($feature == 'banque') {
748 if (!$user->hasRight('banque', 'modifier')) {
749 $deleteok = 0;
750 }
751 } elseif ($feature == 'cheque') {
752 if (empty($user->rights->banque->cheque)) {
753 $deleteok = 0;
754 }
755 } elseif ($feature == 'ecm') {
756 if (!$user->rights->ecm->upload) {
757 $deleteok = 0;
758 }
759 } elseif ($feature == 'ftp') {
760 if (!$user->rights->ftp->write) {
761 $deleteok = 0;
762 }
763 } elseif ($feature == 'salaries') {
764 if (!$user->rights->salaries->delete) {
765 $deleteok = 0;
766 }
767 } elseif ($feature == 'adherent') {
768 if (empty($user->rights->adherent->supprimer)) {
769 $deleteok = 0;
770 }
771 } elseif ($feature == 'paymentbybanktransfer') {
772 if (empty($user->rights->paymentbybanktransfer->create)) { // There is no delete permission
773 $deleteok = 0;
774 }
775 } elseif ($feature == 'prelevement') {
776 if (empty($user->rights->prelevement->bons->creer)) { // There is no delete permission
777 $deleteok = 0;
778 }
779 } elseif (!empty($feature2)) { // This is for permissions on 2 levels
780 foreach ($feature2 as $subfeature) {
781 if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) {
782 $deleteok = 0;
783 } else {
784 $deleteok = 1;
785 break;
786 } // For bypass the second test if the first is ok
787 }
788 } elseif (!empty($feature)) { // This is used for permissions on 1 level
789 //print '<br>feature='.$feature.' creer='.$user->rights->$feature->supprimer.' write='.$user->rights->$feature->delete;
790 if (empty($user->rights->$feature->supprimer)
791 && empty($user->rights->$feature->delete)
792 && empty($user->rights->$feature->run)) {
793 $deleteok = 0;
794 }
795 }
796 }
797
798 // If a or and at least one ok
799 if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
800 $deleteok = 1;
801 }
802
803 if (!$deleteok && !($isdraft && $createok)) {
804 if ($mode) {
805 return 0;
806 } else {
808 }
809 }
810 //print "Delete access is ok";
811 }
812
813 // If we have a particular object to check permissions on, we check if $user has permission
814 // for this given object (link to company, is contact for project, ...)
815 if (!empty($objectid) && $objectid > 0) {
816 $ok = checkUserAccessToObject($user, $featuresarray, $object, $tableandshare, $feature2, $dbt_keyfield, $dbt_select, $parentfortableentity);
817 $params = array('objectid' => $objectid, 'features' => join(',', $featuresarray), 'features2' => $feature2);
818 //print 'checkUserAccessToObject ok='.$ok;
819 if ($mode) {
820 return $ok ? 1 : 0;
821 } else {
822 if ($ok) {
823 return 1;
824 } else {
825 accessforbidden('', 1, 1, 0, $params);
826 }
827 }
828 }
829
830 return 1;
831}
832
848function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tableandshare = '', $feature2 = '', $dbt_keyfield = '', $dbt_select = 'rowid', $parenttableforentity = '')
849{
850 global $db, $conf;
851
852 if (is_object($object)) {
853 $objectid = $object->id;
854 } else {
855 $objectid = $object; // $objectid can be X or 'X,Y,Z'
856 }
857 $objectid = preg_replace('/[^0-9\.\,]/', '', $objectid); // For the case value is coming from a non sanitized user input
858
859 //dol_syslog("functions.lib:restrictedArea $feature, $objectid, $dbtablename, $feature2, $dbt_socfield, $dbt_select, $isdraft");
860 //print "user_id=".$user->id.", features=".join(',', $featuresarray).", objectid=".$objectid;
861 //print ", tableandshare=".$tableandshare.", dbt_socfield=".$dbt_keyfield.", dbt_select=".$dbt_select."<br>";
862
863 // More parameters
864 $params = explode('&', $tableandshare);
865 $dbtablename = (!empty($params[0]) ? $params[0] : '');
866 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
867
868 foreach ($featuresarray as $feature) {
869 $sql = '';
870
871 //var_dump($feature);exit;
872
873 // For backward compatibility
874 if ($feature == 'societe' && !empty($feature2) && is_array($feature2) && in_array('contact', $feature2)) {
875 $feature = 'contact';
876 $feature2 = '';
877 }
878 if ($feature == 'member') {
879 $feature = 'adherent';
880 }
881 if ($feature == 'project') {
882 $feature = 'projet';
883 }
884 if ($feature == 'projet' && !empty($feature2) && is_array($feature2) && !empty(array_intersect(array('project_task', 'projet_task'), $feature2))) {
885 $feature = 'project_task';
886 }
887 if ($feature == 'task' || $feature == 'projet_task') {
888 $feature = 'project_task';
889 }
890 if ($feature == 'eventorganization') {
891 $feature = 'agenda';
892 $dbtablename = 'actioncomm';
893 }
894 if ($feature == 'payment_sc' && empty($parenttableforentity)) {
895 // If we check perm on payment page but $parenttableforentity not defined, we force value on parent table
896 $parenttableforentity = '';
897 $dbtablename = "chargesociales";
898 $feature = "chargesociales";
899 $objectid = $object->fk_charge;
900 }
901
902 $checkonentitydone = 0;
903
904 // Array to define rules of checks to do
905 $check = array('adherent', 'banque', 'bom', 'don', 'mrp', 'user', 'usergroup', 'payment', 'payment_supplier', 'payment_sc', 'product', 'produit', 'service', 'produit|service', 'categorie', 'resource', 'expensereport', 'holiday', 'salaries', 'website', 'recruitment', 'chargesociales', 'knowledgemanagement'); // Test on entity only (Objects with no link to company)
906 $checksoc = array('societe'); // Test for object Societe
907 $checkparentsoc = array('agenda', 'contact', 'contrat'); // Test on entity + link to third party on field $dbt_keyfield. Allowed if link is empty (Ex: contacts...).
908 $checkproject = array('projet', 'project'); // Test for project object
909 $checktask = array('projet_task', 'project_task'); // Test for task object
910 $checkhierarchy = array('expensereport', 'holiday', 'hrm'); // check permission among the hierarchy of user
911 $checkuser = array('bookmark'); // check permission among the fk_user (must be myself or null)
912 $nocheck = array('barcode', 'stock'); // No test
913
914 //$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...).
915
916 // If dbtablename not defined, we use same name for table than module name
917 if (empty($dbtablename)) {
918 $dbtablename = $feature;
919 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename); // We change dbtablename, so we set sharedelement too.
920 }
921
922 // To avoid an access forbidden with a numeric ref
923 if ($dbt_select != 'rowid' && $dbt_select != 'id') {
924 $objectid = "'".$objectid."'"; // Note: $objectid was already cast into int at begin of this method.
925 }
926 // Check permission for objectid on entity only
927 if (in_array($feature, $check) && $objectid > 0) { // For $objectid = 0, no check
928 $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
929 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
930 if (($feature == 'user' || $feature == 'usergroup') && isModEnabled('multicompany')) { // Special for multicompany
931 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
932 if ($conf->entity == 1 && $user->admin && !$user->entity) {
933 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
934 $sql .= " AND dbt.entity IS NOT NULL";
935 } else {
936 $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
937 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
938 $sql .= " AND ((ug.fk_user = dbt.rowid";
939 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
940 $sql .= " OR dbt.entity = 0)"; // Show always superadmin
941 }
942 } else {
943 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
944 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
945 }
946 } else {
947 $reg = array();
948 if ($parenttableforentity && preg_match('/(.*)@(.*)/', $parenttableforentity, $reg)) {
949 $sql .= ", ".MAIN_DB_PREFIX.$reg[2]." as dbtp";
950 $sql .= " WHERE dbt.".$reg[1]." = dbtp.rowid AND dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
951 $sql .= " AND dbtp.entity IN (".getEntity($sharedelement, 1).")";
952 } else {
953 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
954 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
955 }
956 }
957 $checkonentitydone = 1;
958 }
959 if (in_array($feature, $checksoc) && $objectid > 0) { // We check feature = checksoc. For $objectid = 0, no check
960 // If external user: Check permission for external users
961 if ($user->socid > 0) {
962 if ($user->socid != $objectid) {
963 return false;
964 }
965 } elseif (isModEnabled("societe") && ($user->hasRight('societe', 'lire') && empty($user->rights->societe->client->voir))) {
966 // If internal user: Check permission for internal users that are restricted on their objects
967 $sql = "SELECT COUNT(sc.fk_soc) as nb";
968 $sql .= " FROM (".MAIN_DB_PREFIX."societe_commerciaux as sc";
969 $sql .= ", ".MAIN_DB_PREFIX."societe as s)";
970 $sql .= " WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).")";
971 $sql .= " AND sc.fk_user = ".((int) $user->id);
972 $sql .= " AND sc.fk_soc = s.rowid";
973 $sql .= " AND s.entity IN (".getEntity($sharedelement, 1).")";
974 } elseif (isModEnabled('multicompany')) {
975 // If multicompany and internal users with all permissions, check user is in correct entity
976 $sql = "SELECT COUNT(s.rowid) as nb";
977 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
978 $sql .= " WHERE s.rowid IN (".$db->sanitize($objectid, 1).")";
979 $sql .= " AND s.entity IN (".getEntity($sharedelement, 1).")";
980 }
981
982 $checkonentitydone = 1;
983 }
984 if (in_array($feature, $checkparentsoc) && $objectid > 0) { // Test on entity + link to thirdparty. Allowed if link is empty (Ex: contacts...).
985 // If external user: Check permission for external users
986 if ($user->socid > 0) {
987 $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
988 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
989 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
990 $sql .= " AND dbt.fk_soc = ".((int) $user->socid);
991 } elseif (isModEnabled("societe") && ($user->hasRight('societe', 'lire') && empty($user->rights->societe->client->voir))) {
992 // If internal user: Check permission for internal users that are restricted on their objects
993 $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
994 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
995 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
996 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
997 $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
998 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
999 } elseif (isModEnabled('multicompany')) {
1000 // If multicompany and internal users with all permissions, check user is in correct entity
1001 $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
1002 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1003 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1004 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1005 }
1006
1007 $checkonentitydone = 1;
1008 }
1009 if (in_array($feature, $checkproject) && $objectid > 0) {
1010 if (isModEnabled('project') && empty($user->rights->projet->all->lire)) {
1011 $projectid = $objectid;
1012
1013 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1014 $projectstatic = new Project($db);
1015 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1016
1017 $tmparray = explode(',', $tmps);
1018 if (!in_array($projectid, $tmparray)) {
1019 return false;
1020 }
1021 } else {
1022 $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
1023 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1024 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1025 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1026 }
1027 $checkonentitydone = 1;
1028 }
1029 if (in_array($feature, $checktask) && $objectid > 0) {
1030 if (isModEnabled('project') && empty($user->rights->projet->all->lire)) {
1031 $task = new Task($db);
1032 $task->fetch($objectid);
1033 $projectid = $task->fk_project;
1034
1035 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1036 $projectstatic = new Project($db);
1037 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1038
1039 $tmparray = explode(',', $tmps);
1040 if (!in_array($projectid, $tmparray)) {
1041 return false;
1042 }
1043 } else {
1044 $sharedelement = 'project'; // for multicompany compatibility
1045 $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
1046 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1047 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1048 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1049 }
1050
1051 $checkonentitydone = 1;
1052 }
1053 //var_dump($sql);
1054
1055 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
1056 // If external user: Check permission for external users
1057 if ($user->socid > 0) {
1058 if (empty($dbt_keyfield)) {
1059 dol_print_error('', 'Param dbt_keyfield is required but not defined');
1060 }
1061 $sql = "SELECT COUNT(dbt.".$dbt_keyfield.") as nb";
1062 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1063 $sql .= " WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).")";
1064 $sql .= " AND dbt.".$dbt_keyfield." = ".((int) $user->socid);
1065 } elseif (isModEnabled("societe") && empty($user->rights->societe->client->voir)) {
1066 // If internal user without permission to see all thirdparties: Check permission for internal users that are restricted on their objects
1067 if ($feature != 'ticket') {
1068 if (empty($dbt_keyfield)) {
1069 dol_print_error('', 'Param dbt_keyfield is required but not defined');
1070 }
1071 $sql = "SELECT COUNT(sc.fk_soc) as nb";
1072 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1073 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1074 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1075 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1076 $sql .= " AND sc.fk_soc = dbt.".$dbt_keyfield;
1077 $sql .= " AND sc.fk_user = ".((int) $user->id);
1078 } else {
1079 // On ticket, the thirdparty is not mandatory, so we need a special test to accept record with no thirdparties.
1080 $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
1081 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1082 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = dbt.".$dbt_keyfield." AND sc.fk_user = ".((int) $user->id);
1083 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1084 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1085 $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR sc.fk_user IS NULL)";
1086 }
1087 } elseif (isModEnabled('multicompany')) {
1088 // If multicompany, and user is an internal user with all permissions, check that object is in correct entity
1089 $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
1090 $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1091 $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1092 $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1093 }
1094 }
1095
1096 // For events, check on users assigned to event
1097 if ($feature === 'agenda' && $objectid > 0) {
1098 // Also check owner or attendee for users without allactions->read
1099 if ($objectid > 0 && empty($user->rights->agenda->allactions->read)) {
1100 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1101 $action = new ActionComm($db);
1102 $action->fetch($objectid);
1103 if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
1104 return false;
1105 }
1106 }
1107 }
1108
1109 // For some object, we also have to check it is in the user hierarchy
1110 // Param $object must be the full object and not a simple id to have this test possible.
1111 if (in_array($feature, $checkhierarchy) && is_object($object) && $objectid > 0) {
1112 $childids = $user->getAllChildIds(1);
1113 $useridtocheck = 0;
1114 if ($feature == 'holiday') {
1115 $useridtocheck = $object->fk_user;
1116 if (!$user->hasRight('holiday', 'readall') && !in_array($useridtocheck, $childids) && !in_array($object->fk_validator, $childids)) {
1117 return false;
1118 }
1119 }
1120 if ($feature == 'expensereport') {
1121 $useridtocheck = $object->fk_user_author;
1122 if (!$user->hasRight('expensereport', 'readall') && !in_array($useridtocheck, $childids)) {
1123 return false;
1124 }
1125 }
1126 if ($feature == 'hrm' && in_array('evaluation', $feature2)) {
1127 $useridtocheck = $object->fk_user;
1128
1129 if ($user->hasRight('hrm', 'evaluation', 'readall')) {
1130 // the user can view evaluations for anyone
1131 return true;
1132 }
1133 if (!$user->hasRight('hrm', 'evaluation', 'read')) {
1134 // the user can't view any evaluations
1135 return false;
1136 }
1137 // the user can only their own evaluations or their subordinates'
1138 return in_array($useridtocheck, $childids);
1139 }
1140 }
1141
1142 // For some object, we also have to check it is public or owned by user
1143 // Param $object must be the full object and not a simple id to have this test possible.
1144 if (in_array($feature, $checkuser) && is_object($object) && $objectid > 0) {
1145 $useridtocheck = $object->fk_user;
1146 if (!empty($useridtocheck) && $useridtocheck > 0 && $useridtocheck != $user->id && empty($user->admin)) {
1147 return false;
1148 }
1149 }
1150
1151 if ($sql) {
1152 $resql = $db->query($sql);
1153 if ($resql) {
1154 $obj = $db->fetch_object($resql);
1155 if (!$obj || $obj->nb < count(explode(',', $objectid))) { // error if we found 0 or less record than nb of id provided
1156 return false;
1157 }
1158 } else {
1159 dol_syslog("Bad forged sql in checkUserAccessToObject", LOG_WARNING);
1160 return false;
1161 }
1162 }
1163 }
1164
1165 return true;
1166}
1167
1168
1180function httponly_accessforbidden($message = 1, $http_response_code = 403, $stringalreadysanitized = 0)
1181{
1182 top_httphead();
1183 http_response_code($http_response_code);
1184
1185 if ($stringalreadysanitized) {
1186 print $message;
1187 } else {
1188 print htmlentities($message);
1189 }
1190
1191 exit(1);
1192}
1193
1207function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params = null)
1208{
1209 global $conf, $db, $user, $langs, $hookmanager;
1210 global $action, $object;
1211
1212 if (!is_object($langs)) {
1213 include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
1214 $langs = new Translate('', $conf);
1215 $langs->setDefaultLang();
1216 }
1217
1218 $langs->load("errors");
1219
1220 if ($printheader) {
1221 if (function_exists("llxHeader")) {
1222 llxHeader('');
1223 } elseif (function_exists("llxHeaderVierge")) {
1224 llxHeaderVierge('');
1225 }
1226 }
1227 print '<div class="error">';
1228 if (empty($message)) {
1229 print $langs->trans("ErrorForbidden");
1230 } else {
1231 print $langs->trans($message);
1232 }
1233 print '</div>';
1234 print '<br>';
1235 if (empty($showonlymessage)) {
1236 if (empty($hookmanager)) {
1237 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
1238 $hookmanager = new HookManager($db);
1239 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1240 $hookmanager->initHooks(array('main'));
1241 }
1242
1243 $parameters = array('message'=>$message, 'params'=>$params);
1244 $reshook = $hookmanager->executeHooks('getAccessForbiddenMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1245 print $hookmanager->resPrint;
1246 if (empty($reshook)) {
1247 $langs->loadLangs(array("errors"));
1248 if ($user->login) {
1249 print $langs->trans("CurrentLogin").': <span class="error">'.$user->login.'</span><br>';
1250 print $langs->trans("ErrorForbidden2", $langs->transnoentitiesnoconv("Home"), $langs->transnoentitiesnoconv("Users"));
1251 print $langs->trans("ErrorForbidden4");
1252 } else {
1253 print $langs->trans("ErrorForbidden3");
1254 }
1255 }
1256 }
1257 if ($printfooter && function_exists("llxFooter")) {
1258 llxFooter();
1259 }
1260
1261 exit(0);
1262}
1263
1264
1272{
1273 global $conf;
1274
1275 $max = $conf->global->MAIN_UPLOAD_DOC; // In Kb
1276 $maxphp = @ini_get('upload_max_filesize'); // In unknown
1277 if (preg_match('/k$/i', $maxphp)) {
1278 $maxphp = preg_replace('/k$/i', '', $maxphp);
1279 $maxphp = $maxphp * 1;
1280 }
1281 if (preg_match('/m$/i', $maxphp)) {
1282 $maxphp = preg_replace('/m$/i', '', $maxphp);
1283 $maxphp = $maxphp * 1024;
1284 }
1285 if (preg_match('/g$/i', $maxphp)) {
1286 $maxphp = preg_replace('/g$/i', '', $maxphp);
1287 $maxphp = $maxphp * 1024 * 1024;
1288 }
1289 if (preg_match('/t$/i', $maxphp)) {
1290 $maxphp = preg_replace('/t$/i', '', $maxphp);
1291 $maxphp = $maxphp * 1024 * 1024 * 1024;
1292 }
1293 $maxphp2 = @ini_get('post_max_size'); // In unknown
1294 if (preg_match('/k$/i', $maxphp2)) {
1295 $maxphp2 = preg_replace('/k$/i', '', $maxphp2);
1296 $maxphp2 = $maxphp2 * 1;
1297 }
1298 if (preg_match('/m$/i', $maxphp2)) {
1299 $maxphp2 = preg_replace('/m$/i', '', $maxphp2);
1300 $maxphp2 = $maxphp2 * 1024;
1301 }
1302 if (preg_match('/g$/i', $maxphp2)) {
1303 $maxphp2 = preg_replace('/g$/i', '', $maxphp2);
1304 $maxphp2 = $maxphp2 * 1024 * 1024;
1305 }
1306 if (preg_match('/t$/i', $maxphp2)) {
1307 $maxphp2 = preg_replace('/t$/i', '', $maxphp2);
1308 $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
1309 }
1310 // Now $max and $maxphp and $maxphp2 are in Kb
1311 $maxmin = $max;
1312 $maxphptoshow = $maxphptoshowparam = '';
1313 if ($maxphp > 0) {
1314 $maxmin = min($maxmin, $maxphp);
1315 $maxphptoshow = $maxphp;
1316 $maxphptoshowparam = 'upload_max_filesize';
1317 }
1318 if ($maxphp2 > 0) {
1319 $maxmin = min($maxmin, $maxphp2);
1320 if ($maxphp2 < $maxphp) {
1321 $maxphptoshow = $maxphp2;
1322 $maxphptoshowparam = 'post_max_size';
1323 }
1324 }
1325 //var_dump($maxphp.'-'.$maxphp2);
1326 //var_dump($maxmin);
1327
1328 return array('max'=>$max, 'maxmin'=>$maxmin, 'maxphptoshow'=>$maxphptoshow, 'maxphptoshowparam'=>$maxphptoshowparam);
1329}
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.
Class to manage translations.
Class to manage Dolibarr users.
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.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
dolEncrypt($chain, $key='', $ciphering='AES-256-CTR', $forceseed='')
Encode a string with a symetric encryption.
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.
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.