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