Browse Source

Use dolChmod

Laurent Destailleur 2 years ago
parent
commit
0b4cacd291
100 changed files with 246 additions and 427 deletions
  1. 11 1
      htdocs/admin/security_file.php
  2. 1 1
      htdocs/api/class/api_documents.class.php
  3. 1 1
      htdocs/comm/action/class/actioncomm.class.php
  4. 1 3
      htdocs/compta/prelevement/class/bonprelevement.class.php
  5. 2 6
      htdocs/core/actions_massactions.inc.php
  6. 2 4
      htdocs/core/class/CMailFile.class.php
  7. 2 6
      htdocs/core/class/CSMSFile.class.php
  8. 1 3
      htdocs/core/class/ldap.class.php
  9. 1 4
      htdocs/core/class/rssparser.class.php
  10. 3 12
      htdocs/core/class/stats.class.php
  11. 4 8
      htdocs/core/class/utils.class.php
  12. 35 15
      htdocs/core/lib/files.lib.php
  13. 5 2
      htdocs/core/lib/functions.lib.php
  14. 2 6
      htdocs/core/lib/images.lib.php
  15. 1 3
      htdocs/core/lib/invoice2.lib.php
  16. 3 3
      htdocs/core/lib/modulebuilder.lib.php
  17. 1 1
      htdocs/core/lib/security2.lib.php
  18. 2 6
      htdocs/core/lib/website.lib.php
  19. 18 48
      htdocs/core/lib/website2.lib.php
  20. 2 8
      htdocs/core/lib/xcal.lib.php
  21. 1 3
      htdocs/core/modules/action/rapport.class.php
  22. 1 3
      htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php
  23. 3 5
      htdocs/core/modules/asset/doc/pdf_standard_asset.modules.php
  24. 1 3
      htdocs/core/modules/bank/doc/pdf_ban.modules.php
  25. 1 3
      htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php
  26. 1 3
      htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php
  27. 1 3
      htdocs/core/modules/cheque/doc/pdf_blochet.class.php
  28. 1 3
      htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php
  29. 1 3
      htdocs/core/modules/commande/doc/pdf_einstein.modules.php
  30. 1 3
      htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php
  31. 1 3
      htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php
  32. 1 3
      htdocs/core/modules/contract/doc/pdf_strato.modules.php
  33. 1 3
      htdocs/core/modules/delivery/doc/pdf_storm.modules.php
  34. 1 3
      htdocs/core/modules/delivery/doc/pdf_typhon.modules.php
  35. 1 3
      htdocs/core/modules/dons/html_cerfafr.modules.php
  36. 1 3
      htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php
  37. 1 3
      htdocs/core/modules/expedition/doc/pdf_espadon.modules.php
  38. 1 3
      htdocs/core/modules/expedition/doc/pdf_merou.modules.php
  39. 1 3
      htdocs/core/modules/expedition/doc/pdf_rouget.modules.php
  40. 1 3
      htdocs/core/modules/expensereport/doc/pdf_standard.modules.php
  41. 1 3
      htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
  42. 1 3
      htdocs/core/modules/facture/doc/pdf_crabe.modules.php
  43. 1 3
      htdocs/core/modules/facture/doc/pdf_sponge.modules.php
  44. 1 3
      htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php
  45. 1 3
      htdocs/core/modules/member/doc/doc_generic_member_odt.class.php
  46. 1 4
      htdocs/core/modules/member/doc/pdf_standard.class.php
  47. 1 3
      htdocs/core/modules/movement/doc/pdf_standard.modules.php
  48. 1 3
      htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php
  49. 1 3
      htdocs/core/modules/mrp/doc/pdf_vinci.modules.php
  50. 1 3
      htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php
  51. 1 4
      htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php
  52. 1 3
      htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php
  53. 1 3
      htdocs/core/modules/product/doc/pdf_standard.modules.php
  54. 1 3
      htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php
  55. 1 3
      htdocs/core/modules/project/doc/pdf_baleine.modules.php
  56. 1 3
      htdocs/core/modules/project/doc/pdf_beluga.modules.php
  57. 1 3
      htdocs/core/modules/project/doc/pdf_timespent.modules.php
  58. 1 3
      htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php
  59. 1 3
      htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php
  60. 1 3
      htdocs/core/modules/propale/doc/pdf_azur.modules.php
  61. 1 3
      htdocs/core/modules/propale/doc/pdf_cyan.modules.php
  62. 1 3
      htdocs/core/modules/rapport/pdf_paiement.class.php
  63. 1 3
      htdocs/core/modules/reception/doc/doc_generic_reception_odt.modules.php
  64. 1 3
      htdocs/core/modules/reception/doc/pdf_squille.modules.php
  65. 1 3
      htdocs/core/modules/societe/doc/doc_generic_odt.modules.php
  66. 1 3
      htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php
  67. 1 3
      htdocs/core/modules/stock/doc/pdf_standard.modules.php
  68. 1 2
      htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php
  69. 1 2
      htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php
  70. 1 3
      htdocs/core/modules/supplier_invoice/doc/doc_generic_supplier_invoice_odt.modules.php
  71. 1 3
      htdocs/core/modules/supplier_invoice/doc/pdf_canelle.modules.php
  72. 1 3
      htdocs/core/modules/supplier_order/doc/doc_generic_supplier_order_odt.modules.php
  73. 1 3
      htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php
  74. 1 3
      htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php
  75. 1 3
      htdocs/core/modules/supplier_payment/doc/pdf_standard.modules.php
  76. 1 3
      htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php
  77. 1 3
      htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php
  78. 1 1
      htdocs/core/modules/syslog/mod_syslog_file.php
  79. 1 3
      htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php
  80. 1 3
      htdocs/core/modules/user/doc/doc_generic_user_odt.modules.php
  81. 1 3
      htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php
  82. 1 3
      htdocs/ftp/index.php
  83. 1 1
      htdocs/includes/odtphp/odf.php
  84. 1 1
      htdocs/install/doctemplates/websites/website_template-corporate/containers/wrapper.php
  85. 1 1
      htdocs/install/doctemplates/websites/website_template-homesubmenu/containers/wrapper.php
  86. 1 1
      htdocs/install/doctemplates/websites/website_template-noimg/containers/wrapper.php
  87. 1 1
      htdocs/install/doctemplates/websites/website_template-onepageblackpurple/containers/wrapper.php
  88. 1 1
      htdocs/install/doctemplates/websites/website_template-restaurant/containers/wrapper.php
  89. 1 1
      htdocs/install/doctemplates/websites/website_template-stellar/containers/wrapper.php
  90. 6 4
      htdocs/install/step5.php
  91. 1 1
      htdocs/langs/en_US/admin.lang
  92. 1 0
      htdocs/langs/en_US/errors.lang
  93. 51 51
      htdocs/modulebuilder/index.php
  94. 1 3
      htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php
  95. 3 5
      htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php
  96. 5 9
      htdocs/projet/class/projectstats.class.php
  97. 1 3
      htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php
  98. 3 5
      htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php
  99. 1 3
      htdocs/website/class/website.class.php
  100. 4 9
      htdocs/website/index.php

+ 11 - 1
htdocs/admin/security_file.php

@@ -80,8 +80,18 @@ if ($action == 'updateform') {
 	}
 
 	if (!$error) {
+		$tmpumask = GETPOST('MAIN_UMASK', 'alpha');
+		$tmpumask = (octdec($tmpumask) & 0666);
+		$tmpumask = decoct($tmpumask);
+		if (!preg_match('/^0/', $tmpumask)) {
+			$tmpumask = '0'.$tmpumask;
+		}
+		if (empty($tmpumask) || $tmpumask === '0') {
+			$tmpumask = '0664';
+		}
+
 		$res3 = dolibarr_set_const($db, 'MAIN_UPLOAD_DOC', GETPOST('MAIN_UPLOAD_DOC', 'alpha'), 'chaine', 0, '', $conf->entity);
-		$res4 = dolibarr_set_const($db, "MAIN_UMASK", GETPOST('MAIN_UMASK', 'alpha'), 'chaine', 0, '', $conf->entity);
+		$res4 = dolibarr_set_const($db, "MAIN_UMASK", $tmpumask, 'chaine', 0, '', $conf->entity);
 		$res5 = dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", trim($antivircommand), 'chaine', 0, '', $conf->entity);
 		$res6 = dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", trim($antivirparam), 'chaine', 0, '', $conf->entity);
 		if ($res3 && $res4 && $res5 && $res6) {

+ 1 - 1
htdocs/api/class/api_documents.class.php

@@ -746,7 +746,7 @@ class Documents extends DolibarrApi
 		if ($fhandle) {
 			$nbofbyteswrote = fwrite($fhandle, $newfilecontent);
 			fclose($fhandle);
-			@chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
+			dolChmod($destfiletmp);
 		} else {
 			throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
 		}

+ 1 - 1
htdocs/comm/action/class/actioncomm.class.php

@@ -2278,7 +2278,7 @@ class ActionComm extends CommonObject
 
 			// Create temp file
 			$outputfiletmp = tempnam($conf->agenda->dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
-			@chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
+			dolChmod($outputfiletmp);
 
 			// Write file
 			if ($format == 'vcal') {

+ 1 - 3
htdocs/compta/prelevement/class/bonprelevement.class.php

@@ -1700,9 +1700,7 @@ class BonPrelevement extends CommonObject
 		}
 
 		fclose($this->file);
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($this->filename, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($this->filename);
 
 		return $result;
 	}

+ 2 - 6
htdocs/core/actions_massactions.inc.php

@@ -820,9 +820,7 @@ if (!$error && $massaction == "builddoc" && $permissiontoread && !GETPOST('butto
 
 			// check if pdftk is installed
 			if (file_exists($file)) {
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$langs->load("exports");
 				setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');
@@ -888,9 +886,7 @@ if (!$error && $massaction == "builddoc" && $permissiontoread && !GETPOST('butto
 			$now = dol_now();
 			$file = $diroutputmassaction.'/'.$filename.'_'.dol_print_date($now, 'dayhourlog').'.pdf';
 			$pdf->Output($file, 'F');
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($file);
 
 			$langs->load("exports");
 			setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');

+ 2 - 4
htdocs/core/class/CMailFile.class.php

@@ -1213,9 +1213,7 @@ class CMailFile
 			}
 
 			fclose($fp);
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($outputfile);
 		}
 	}
 
@@ -1797,7 +1795,7 @@ class CMailFile
 				if ($fhandle) {
 					$nbofbyteswrote = fwrite($fhandle, base64_decode($filecontent));
 					fclose($fhandle);
-					@chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
+					dolChmod($destfiletmp);
 				} else {
 					$this->errors[] = "Failed to open file '".$destfiletmp."' for write";
 					return -1;

+ 2 - 6
htdocs/core/class/CSMSFile.class.php

@@ -231,9 +231,7 @@ class CSMSFile
 			fputs($fp, "Message:\n".$this->message);
 
 			fclose($fp);
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($outputfile);
 		}
 	}
 
@@ -257,9 +255,7 @@ class CSMSFile
 			fputs($fp, "\nResult id=".$result);
 
 			fclose($fp);
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($outputfile);
 		}
 	}
 }

+ 1 - 3
htdocs/core/class/ldap.class.php

@@ -743,9 +743,7 @@ class Ldap
 		if ($fp) {
 			fputs($fp, $content);
 			fclose($fp);
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($outputfile);
 			return 1;
 		} else {
 			return -1;

+ 1 - 4
htdocs/core/class/rssparser.class.php

@@ -295,10 +295,7 @@ class RssParser
 				if ($fp) {
 					fwrite($fp, $str);
 					fclose($fp);
-					if (!empty($conf->global->MAIN_UMASK)) {
-						$newmask = $conf->global->MAIN_UMASK;
-					}
-					@chmod($newpathofdestfile, octdec($newmask));
+					dolChmod($newpathofdestfile);
 
 					$this->_lastfetchdate = $nowgmt;
 				} else {

+ 3 - 12
htdocs/core/class/stats.class.php

@@ -119,10 +119,7 @@ abstract class Stats
 			$fp = fopen($newpathofdestfile, 'w');
 			fwrite($fp, json_encode($data));
 			fclose($fp);
-			if (!empty($conf->global->MAIN_UMASK)) {
-				$newmask = $conf->global->MAIN_UMASK;
-			}
-			@chmod($newpathofdestfile, octdec($newmask));
+			dolChmod($newpathofdestfile);
 
 			$this->lastfetchdate[get_class($this).'_'.__FUNCTION__] = $nowgmt;
 		}
@@ -222,10 +219,7 @@ abstract class Stats
 			if ($fp) {
 				fwrite($fp, json_encode($data));
 				fclose($fp);
-				if (!empty($conf->global->MAIN_UMASK)) {
-					$newmask = $conf->global->MAIN_UMASK;
-				}
-				@chmod($newpathofdestfile, octdec($newmask));
+				dolChmod($newpathofdestfile);
 			} else {
 				dol_syslog("Failed to write cache file", LOG_ERR);
 			}
@@ -332,10 +326,7 @@ abstract class Stats
 			if ($fp) {
 				fwrite($fp, json_encode($data));
 				fclose($fp);
-				if (!empty($conf->global->MAIN_UMASK)) {
-					$newmask = $conf->global->MAIN_UMASK;
-				}
-				@chmod($newpathofdestfile, octdec($newmask));
+				dolChmod($newpathofdestfile);
 			}
 			$this->lastfetchdate[get_class($this).'_'.__FUNCTION__] = $nowgmt;
 		}

+ 4 - 8
htdocs/core/class/utils.class.php

@@ -494,9 +494,7 @@ class Utils
 					}
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($outputfile);
 			} else {
 				$langs->load("errors");
 				dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
@@ -739,9 +737,7 @@ class Utils
 				pclose($handlein);
 				fclose($handle);
 			}
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($outputfile);
 		}
 
 		// Update with result
@@ -1051,7 +1047,7 @@ class Utils
 					fclose($sourcehandle);
 					gzclose($gzfilehandle);
 
-					@chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK));
+					dolChmod($logpath.'/'.$logname.'.1.gz');
 				}
 
 				dol_delete_file($logpath.'/'.$logname, 0, 0, 0, null, false, 0);
@@ -1061,7 +1057,7 @@ class Utils
 				fclose($newlog);
 
 				//var_dump($logpath.'/'.$logname." - ".octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK));
-				@chmod($logpath.'/'.$logname, octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK));
+				dolChmod($logpath.'/'.$logname);
 			}
 		}
 

+ 35 - 15
htdocs/core/lib/files.lib.php

@@ -678,7 +678,7 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask
 	}
 
 	file_put_contents($newpathoftmpdestfile, $content);
-	@chmod($newpathoftmpdestfile, octdec($newmask));
+	dolChmod($newpathoftmpdestfile, $newmask);
 
 	// Rename
 	$result = dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
@@ -694,7 +694,7 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask
 		$newmask = '0664';
 	}
 
-	@chmod($newpathofdestfile, octdec($newmask));
+	dolChmod($newpathofdestfile, $newmask);
 
 	return 1;
 }
@@ -752,7 +752,7 @@ function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
 		$newmask = '0664';
 	}
 
-	@chmod($newpathofdestfile, octdec($newmask));
+	dolChmod($newpathofdestfile, $newmask);
 
 	return 1;
 }
@@ -900,6 +900,18 @@ function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $te
 			}
 		}
 
+		global $dolibarr_main_restrict_os_commands;
+		if (!empty($dolibarr_main_restrict_os_commands)) {
+			$arrayofallowedcommand = explode(',', $dolibarr_main_restrict_os_commands);
+			$arrayofallowedcommand = array_map('trim', $arrayofallowedcommand);
+			if (in_array(basename($destfile), $arrayofallowedcommand)) {
+				//$langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
+				//setEventMessages($langs->trans("ErrorFilenameReserved", basename($destfile)), null, 'errors');
+				dol_syslog("files.lib.php::dol_move canceled because target filename ".basename($destfile)." is using a reserved command name. we ignore the move request.", LOG_WARNING);
+				return false;
+			}
+		}
+
 		$result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
 		if (!$result) {
 			if ($destexists) {
@@ -975,11 +987,11 @@ function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $te
 		if (empty($newmask)) {
 			$newmask = empty($conf->global->MAIN_UMASK) ? '0755' : $conf->global->MAIN_UMASK;
 		}
-		$newmaskdec = octdec($newmask);
+
 		// Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too)
 		// to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this
 		// if ($isdir) $newmaskdec |= octdec('0111');  // Set x bit required for directories
-		@chmod($newpathofdestfile, $newmaskdec);
+		dolChmod($newpathofdestfile, $newmask);
 	}
 
 	return $result;
@@ -1219,9 +1231,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
 		// Move file
 		$return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
 		if ($return) {
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($file_name_osencoded);
 			dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
 			return $successcode; // Success
 		} else {
@@ -1303,7 +1313,7 @@ function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0,
 					// If it fails and it is because of the missing write permission on parent dir
 					if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
 						dol_syslog("Error in deletion, but parent directory exists with no permission to write, we try to change permission on parent directory and retry...", LOG_DEBUG);
-						@chmod(dirname($filename), fileperms(dirname($filename)) | 0200);
+						dolChmod(dirname($filename), decoct(fileperms(dirname($filename)) | 0200));
 						// Now we retry deletion
 						if ($nophperrors) {
 							$ok = @unlink($filename);
@@ -1592,11 +1602,10 @@ function dol_meta_create($object)
 		$fp = fopen($file, "w");
 		fputs($fp, $meta);
 		fclose($fp);
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($file, octdec($conf->global->MAIN_UMASK));
-		}
 
-			return 1;
+		dolChmod($file);
+
+		return 1;
 	} else {
 		dol_syslog('FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING);
 	}
@@ -1713,6 +1722,17 @@ function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesess
 				$destfile = dol_string_nohtmltag($destfile);
 				$destfull = dol_string_nohtmltag($destfull);
 
+				global $dolibarr_main_restrict_os_commands;
+				if (!empty($dolibarr_main_restrict_os_commands)) {
+					$arrayofallowedcommand = explode(',', $dolibarr_main_restrict_os_commands);
+					$arrayofallowedcommand = array_map('trim', $arrayofallowedcommand);
+					if (in_array(basename($destfull), $arrayofallowedcommand)) {
+						$langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
+						setEventMessages($langs->trans("ErrorFilenameReserved", basename($destfull)), null, 'errors');
+						return -1;
+					}
+				}
+
 				// Move file from temp directory to final directory. A .noexe may also be appended on file name.
 				$resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles, $upload_dir);
 
@@ -2388,7 +2408,7 @@ function dol_compress_dir($inputdir, $outputfile, $mode = "zip", $excludefiles =
 					$newmask = '0664';
 				}
 
-				@chmod($outputfile, octdec($newmask));
+				dolChmod($outputfile, $newmask);
 
 				return 1;
 			}
@@ -3215,7 +3235,7 @@ function dol_filecache($directory, $filename, $object)
 	}
 	$cachefile = $directory.$filename;
 	file_put_contents($cachefile, serialize($object), LOCK_EX);
-	@chmod($cachefile, 0644);
+	dolChmod($cachefile, '0644');
 }
 
 /**

+ 5 - 2
htdocs/core/lib/functions.lib.php

@@ -6864,13 +6864,16 @@ function dol_mkdir($dir, $dataroot = '', $newmask = '')
  *	Change mod of a file
  *
  *  @param	string		$filepath		Full file path
+ *  @param	string		$newmask		Force new mask. For example '0644'
  *	@return void
  */
-function dolChmod($filepath)
+function dolChmod($filepath, $newmask = '')
 {
 	global $conf;
 
-	if (!empty($conf->global->MAIN_UMASK)) {
+	if (!empty($newmask)) {
+		@chmod($filepath, octdec($newmask));
+	} elseif (!empty($conf->global->MAIN_UMASK)) {
 		@chmod($filepath, octdec($conf->global->MAIN_UMASK));
 	}
 }

+ 2 - 6
htdocs/core/lib/images.lib.php

@@ -362,9 +362,7 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x = 0,
 	}
 
 	// Set permissions on file
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($imgTargetName, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($imgTargetName);
 
 	// Free memory. This does not delete image.
 	imagedestroy($img);
@@ -761,9 +759,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
 	}
 
 	// Set permissions on file
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($imgThumbName);
 
 	// Free memory. This does not delete image.
 	imagedestroy($img);

+ 1 - 3
htdocs/core/lib/invoice2.lib.php

@@ -277,9 +277,7 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
 
 			if (!$error && $pagecount) {
 				$pdf->Output($file, 'F');
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 			}
 
 			if ($usestdout) {

+ 3 - 3
htdocs/core/lib/modulebuilder.lib.php

@@ -227,7 +227,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
 		$result = file_put_contents(dol_osencode($pathoffiletoedittarget), $contentclass);
 
 		if ($result) {
-			@chmod($pathoffiletoedittarget, octdec($newmask));
+			dolChmod($pathoffiletoedittarget, $newmask);
 		} else {
 			$error++;
 		}
@@ -369,7 +369,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
 
 	$result = file_put_contents($pathoffiletoedittarget, $contentsql);
 	if ($result) {
-		@chmod($pathoffiletoedittarget, octdec($newmask));
+		dolChmod($pathoffiletoedittarget, $newmask);
 	} else {
 		$error++;
 		setEventMessages($langs->trans("ErrorFailToCreateFile", $pathoffiletoedittarget), null, 'errors');
@@ -408,7 +408,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
 
 	$result2 = file_put_contents($pathoffiletoedittarget, $contentsql);
 	if ($result2) {
-		@chmod($pathoffiletoedittarget, octdec($newmask));
+		dolChmod($pathoffiletoedittarget, $newmask);
 	} else {
 		$error++;
 		setEventMessages($langs->trans("ErrorFailToCreateFile", $pathoffiletoedittarget), null, 'errors');

+ 1 - 1
htdocs/core/lib/security2.lib.php

@@ -457,7 +457,7 @@ function encodedecode_dbpassconf($level = 0)
 
 			// It's config file, so we set read permission for creator only.
 			// Should set permission to web user and groups for users used by batch
-			//@chmod($file, octdec('0600'));
+			//dolChmod($file, '0600');
 
 			return 1;
 		} else {

+ 2 - 6
htdocs/core/lib/website.lib.php

@@ -1210,9 +1210,7 @@ function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modify
 					$fp = fopen($filetosave, "w");
 					fputs($fp, $tmpgeturl['content']);
 					fclose($fp);
-					if (!empty($conf->global->MAIN_UMASK)) {
-						@chmod($filetosave, octdec($conf->global->MAIN_UMASK));
-					}
+					dolChmod($filetosave);
 				}
 			}
 		}
@@ -1281,9 +1279,7 @@ function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modify
 					$fp = fopen($filetosave, "w");
 					fputs($fp, $tmpgeturl['content']);
 					fclose($fp);
-					if (!empty($conf->global->MAIN_UMASK)) {
-						@chmod($filetosave, octdec($conf->global->MAIN_UMASK));
-					}
+					dolChmod($filetosave);
 				}
 			}
 		}

+ 18 - 48
htdocs/core/lib/website2.lib.php

@@ -45,9 +45,7 @@ function dolSaveMasterFile($filemaster)
 	$mastercontent .= "}\n";
 	$mastercontent .= '?>'."\n";
 	$result = file_put_contents($filemaster, $mastercontent);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($filemaster, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($filemaster);
 
 	return $result;
 }
@@ -79,9 +77,7 @@ function dolSavePageAlias($filealias, $object, $objectpage)
 	if ($result === false) {
 		dol_syslog("Failed to write file ".$filealias, LOG_WARNING);
 	}
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($filealias, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($filealias);
 
 	// Save also alias into language subdirectory if it is not a main language
 	if ($objectpage->lang && in_array($objectpage->lang, explode(',', $object->otherlang))) {
@@ -99,9 +95,7 @@ function dolSavePageAlias($filealias, $object, $objectpage)
 		if ($result === false) {
 			dol_syslog("Failed to write file ".$filealiassub, LOG_WARNING);
 		}
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($filealiassub, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($filealiassub);
 	} elseif (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
 		// Save also alias into all language subdirectories if it is a main language
 		if (empty($conf->global->WEBSITE_DISABLE_MAIN_LANGUAGE_INTO_LANGSUBDIR) && !empty($object->otherlang)) {
@@ -122,9 +116,7 @@ function dolSavePageAlias($filealias, $object, $objectpage)
 				if ($result === false) {
 					dol_syslog("Failed to write file ".$filealiassub, LOG_WARNING);
 				}
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($filealiassub, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($filealiassub);
 			}
 		}
 	}
@@ -276,9 +268,8 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage,
 
 	//var_dump($filetpl);exit;
 	$result = file_put_contents($filetpl, $tplcontent);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($filetpl, octdec($conf->global->MAIN_UMASK));
-	}
+
+	dolChmod($filetpl);
 
 	return $result;
 }
@@ -318,9 +309,8 @@ function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $o
 		$indexcontent .= '// END PHP ?>'."\n";
 
 		$result1 = file_put_contents($fileindex, $indexcontent);
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($fileindex, octdec($conf->global->MAIN_UMASK));
-		}
+
+		dolChmod($fileindex);
 
 		if (is_object($object) && $object->fk_default_home > 0) {
 			$objectpage = new WebsitePage($db);
@@ -352,9 +342,7 @@ function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $o
 						if ($result === false) {
 							dol_syslog("Failed to write file ".$fileindexsub, LOG_WARNING);
 						}
-						if (!empty($conf->global->MAIN_UMASK)) {
-							@chmod($fileindexsub, octdec($conf->global->MAIN_UMASK));
-						}
+						dolChmod($fileindexsub);
 					}
 				}
 			}
@@ -368,9 +356,7 @@ function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $o
 		$wrappercontent = file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.php');
 
 		$result2 = file_put_contents($filewrapper, $wrappercontent);
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($filewrapper, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($filewrapper);
 	} else {
 		$result2 = true;
 	}
@@ -394,9 +380,7 @@ function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent)
 
 	dol_mkdir($pathofwebsite);
 	$result = file_put_contents($filehtmlheader, $htmlheadercontent);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($filehtmlheader);
 
 	return $result;
 }
@@ -416,9 +400,7 @@ function dolSaveCssFile($filecss, $csscontent)
 
 	dol_mkdir($pathofwebsite);
 	$result = file_put_contents($filecss, $csscontent);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($filecss, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($filecss);
 
 	return $result;
 }
@@ -438,9 +420,7 @@ function dolSaveJsFile($filejs, $jscontent)
 
 	dol_mkdir($pathofwebsite);
 	$result = file_put_contents($filejs, $jscontent);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($filejs, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($filejs);
 
 	return $result;
 }
@@ -460,9 +440,7 @@ function dolSaveRobotFile($filerobot, $robotcontent)
 
 	dol_mkdir($pathofwebsite);
 	$result = file_put_contents($filerobot, $robotcontent);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($filerobot, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($filerobot);
 
 	return $result;
 }
@@ -482,9 +460,7 @@ function dolSaveHtaccessFile($filehtaccess, $htaccess)
 
 	dol_mkdir($pathofwebsite);
 	$result = file_put_contents($filehtaccess, $htaccess);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($filehtaccess, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($filehtaccess);
 
 	return $result;
 }
@@ -504,9 +480,7 @@ function dolSaveManifestJson($file, $content)
 
 	dol_mkdir($pathofwebsite);
 	$result = file_put_contents($file, $content);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($file, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($file);
 
 	return $result;
 }
@@ -526,9 +500,7 @@ function dolSaveReadme($file, $content)
 
 	dol_mkdir($pathofwebsite);
 	$result = file_put_contents($file, $content);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($file, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($file);
 
 	return $result;
 }
@@ -548,9 +520,7 @@ function dolSaveLicense($file, $content)
 
 	dol_mkdir($pathofwebsite);
 	$result = file_put_contents($file, $content);
-	if (!empty($conf->global->MAIN_UMASK)) {
-		@chmod($file, octdec($conf->global->MAIN_UMASK));
-	}
+	dolChmod($file);
 
 	return $result;
 }

+ 2 - 8
htdocs/core/lib/xcal.lib.php

@@ -284,10 +284,7 @@ function build_calfile($format, $title, $desc, $events_array, $outputfile)
 		fwrite($calfileh, "END:VCALENDAR");
 
 		fclose($calfileh);
-
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($outputfile);
 	} else {
 		dol_syslog("xcal.lib.php::build_calfile Failed to open file ".$outputfile." for writing");
 		return -2;
@@ -429,10 +426,7 @@ function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filt
 		fwrite($fichier, "</rss>");
 
 		fclose($fichier);
-
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($outputfile);
 	}
 }
 

+ 1 - 3
htdocs/core/modules/action/rapport.class.php

@@ -209,9 +209,7 @@ class CommActionRapport
 				$this->errors = $hookmanager->errors;
 			}
 
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($file);
 
 			$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php

@@ -480,9 +480,7 @@ class doc_generic_asset_odt extends ModelePDFAsset
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 3 - 5
htdocs/core/modules/asset/doc/pdf_standard_asset.modules.php

@@ -815,13 +815,11 @@ class pdf_standard_asset extends ModelePDFAsset
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
-					$this->result = array('fullpath'=>$file);
+				$this->result = array('fullpath'=>$file);
 
-					return 1; // No error
+				return 1; // No error
 			} else {
 				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
 				return 0;

+ 1 - 3
htdocs/core/modules/bank/doc/pdf_ban.modules.php

@@ -250,9 +250,7 @@ class pdf_ban extends ModeleBankAccountDoc
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php

@@ -429,9 +429,7 @@ class pdf_sepamandate extends ModeleBankAccountDoc
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php

@@ -498,9 +498,7 @@ class doc_generic_bom_odt extends ModelePDFBom
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/cheque/doc/pdf_blochet.class.php

@@ -203,9 +203,7 @@ class BordereauChequeBlochet extends ModeleChequeReceipts
 			$this->errors = $hookmanager->errors;
 		}
 
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($file, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($file);
 
 		$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php

@@ -496,9 +496,7 @@ class doc_generic_order_odt extends ModelePDFCommandes
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/commande/doc/pdf_einstein.modules.php

@@ -676,9 +676,7 @@ class pdf_einstein extends ModelePDFCommandes
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php

@@ -900,9 +900,7 @@ class pdf_eratosthene extends ModelePDFCommandes
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php

@@ -492,9 +492,7 @@ class doc_generic_contract_odt extends ModelePDFContract
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/contract/doc/pdf_strato.modules.php

@@ -496,9 +496,7 @@ class pdf_strato extends ModelePDFContract
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/delivery/doc/pdf_storm.modules.php

@@ -634,9 +634,7 @@ class pdf_storm extends ModelePDFDeliveryOrder
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/delivery/doc/pdf_typhon.modules.php

@@ -619,9 +619,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/dons/html_cerfafr.modules.php

@@ -240,9 +240,7 @@ class html_cerfafr extends ModeleDon
 				$handle = fopen($file, "w");
 				fwrite($handle, $form);
 				fclose($handle);
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php

@@ -559,9 +559,7 @@ class doc_generic_shipment_odt extends ModelePdfExpedition
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/expedition/doc/pdf_espadon.modules.php

@@ -763,9 +763,7 @@ class pdf_espadon extends ModelePdfExpedition
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/expedition/doc/pdf_merou.modules.php

@@ -425,9 +425,7 @@ class pdf_merou extends ModelePdfExpedition
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/expedition/doc/pdf_rouget.modules.php

@@ -669,9 +669,7 @@ class pdf_rouget extends ModelePdfExpedition
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/expensereport/doc/pdf_standard.modules.php

@@ -539,9 +539,7 @@ class pdf_standard extends ModeleExpenseReport
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php

@@ -520,9 +520,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/facture/doc/pdf_crabe.modules.php

@@ -908,9 +908,7 @@ class pdf_crabe extends ModelePDFFactures
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/facture/doc/pdf_sponge.modules.php

@@ -1058,9 +1058,7 @@ class pdf_sponge extends ModelePDFFactures
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php

@@ -469,9 +469,7 @@ class pdf_soleil extends ModelePDFFicheinter
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/member/doc/doc_generic_member_odt.class.php

@@ -412,9 +412,7 @@ class doc_generic_member_odt extends ModelePDFMember
 
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 4
htdocs/core/modules/member/doc/pdf_standard.class.php

@@ -455,10 +455,7 @@ class pdf_standard extends CommonStickerGenerator
 		// Output to file
 		$pdf->Output($file, 'F');
 
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($file, octdec($conf->global->MAIN_UMASK));
-		}
-
+		dolChmod($file);
 
 		$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/movement/doc/pdf_standard.modules.php

@@ -791,9 +791,7 @@ class pdf_standard extends ModelePDFMovement
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php

@@ -484,9 +484,7 @@ class doc_generic_mo_odt extends ModelePDFMo
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/mrp/doc/pdf_vinci.modules.php

@@ -684,9 +684,7 @@ class pdf_vinci extends ModelePDFMo
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php

@@ -337,9 +337,7 @@ class pdf_standardlabel extends CommonStickerGenerator
 		// Output to file
 		$pdf->Output($file, 'F');
 
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($file, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($file);
 
 		$this->result = array('fullpath'=>$file);
 

+ 1 - 4
htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php

@@ -360,10 +360,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
 		// Output to file
 		$pdf->Output($file, 'F');
 
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($file, octdec($conf->global->MAIN_UMASK));
-		}
-
+		dolChmod($file);
 
 		$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php

@@ -481,9 +481,7 @@ class doc_generic_product_odt extends ModelePDFProduct
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/product/doc/pdf_standard.modules.php

@@ -581,9 +581,7 @@ class pdf_standard extends ModelePDFProduct
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php

@@ -1167,9 +1167,7 @@ class doc_generic_project_odt extends ModelePDFProjects
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/project/doc/pdf_baleine.modules.php

@@ -521,9 +521,7 @@ class pdf_baleine extends ModelePDFProjects
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/project/doc/pdf_beluga.modules.php

@@ -769,9 +769,7 @@ class pdf_beluga extends ModelePDFProjects
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/project/doc/pdf_timespent.modules.php

@@ -524,9 +524,7 @@ class pdf_timespent extends ModelePDFProjects
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php

@@ -845,9 +845,7 @@ class doc_generic_task_odt extends ModelePDFTask
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php

@@ -523,9 +523,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/propale/doc/pdf_azur.modules.php

@@ -873,9 +873,7 @@ class pdf_azur extends ModelePDFPropales
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/propale/doc/pdf_cyan.modules.php

@@ -990,9 +990,7 @@ class pdf_cyan extends ModelePDFPropales
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/rapport/pdf_paiement.class.php

@@ -343,9 +343,7 @@ class pdf_paiement
 			$this->errors = $hookmanager->errors;
 		}
 
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($file, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($file);
 
 		$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/reception/doc/doc_generic_reception_odt.modules.php

@@ -485,9 +485,7 @@ class doc_generic_reception_odt extends ModelePdfReception
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/reception/doc/pdf_squille.modules.php

@@ -599,9 +599,7 @@ class pdf_squille extends ModelePdfReception
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				return 1; // No error
 			} else {

+ 1 - 3
htdocs/core/modules/societe/doc/doc_generic_odt.modules.php

@@ -433,9 +433,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php

@@ -484,9 +484,7 @@ class doc_generic_stock_odt extends ModelePDFStock
 
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/stock/doc/pdf_standard.modules.php

@@ -595,9 +595,7 @@ class pdf_standard extends ModelePDFStock
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 2
htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php

@@ -659,8 +659,7 @@ class pdf_eagle extends ModelePdfStockTransfer
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK))
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 2
htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php

@@ -796,8 +796,7 @@ class pdf_eagle_proforma extends ModelePDFCommandes
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK))
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/supplier_invoice/doc/doc_generic_supplier_invoice_odt.modules.php

@@ -483,9 +483,7 @@ class doc_generic_supplier_invoice_odt extends ModelePDFSuppliersInvoices
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/supplier_invoice/doc/pdf_canelle.modules.php

@@ -622,9 +622,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/supplier_order/doc/doc_generic_supplier_order_odt.modules.php

@@ -478,9 +478,7 @@ class doc_generic_supplier_order_odt extends ModelePDFSuppliersOrders
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php

@@ -840,9 +840,7 @@ class pdf_cornas extends ModelePDFSuppliersOrders
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php

@@ -722,9 +722,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/supplier_payment/doc/pdf_standard.modules.php

@@ -478,9 +478,7 @@ class pdf_standard extends ModelePDFSuppliersPayments
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 3
htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php

@@ -510,9 +510,7 @@ class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php

@@ -702,9 +702,7 @@ class pdf_aurore extends ModelePDFSupplierProposal
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$this->result = array('fullpath'=>$file);
 

+ 1 - 1
htdocs/core/modules/syslog/mod_syslog_file.php

@@ -180,7 +180,7 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
 			$message = dol_print_date(dol_now('gmt'), 'standard', 'gmt').$delay." ".sprintf("%-7s", $logLevels[$content['level']])." ".sprintf("%-15s", $content['ip'])." ".($this->ident > 0 ?str_pad('', $this->ident, ' ') : '').$content['message'];
 			fwrite($filefd, $message."\n");
 			fclose($filefd);
-			@chmod($logfile, octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK));
+			dolChmod($logfile);
 		}
 	}
 }

+ 1 - 3
htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php

@@ -405,9 +405,7 @@ class doc_generic_ticket_odt extends ModelePDFTicket
 
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/user/doc/doc_generic_user_odt.modules.php

@@ -433,9 +433,7 @@ class doc_generic_user_odt extends ModelePDFUser
 
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php

@@ -491,9 +491,7 @@ class doc_generic_usergroup_odt extends ModelePDFUserGroup
 
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 1 - 3
htdocs/ftp/index.php

@@ -287,9 +287,7 @@ if ($action == 'download') {
 
 
 		if ($result) {
-			if (!empty($conf->global->MAIN_UMASK)) {
-				@chmod($localfile, octdec($conf->global->MAIN_UMASK));
-			}
+			dolChmod($localfile);
 
 			// Define mime type
 			$type = 'application/octet-stream';

+ 1 - 1
htdocs/includes/odtphp/odf.php

@@ -880,7 +880,7 @@ IMG;
 				pclose($handlein);
 				fclose($handle);
 			}
-			if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
+			dolChmod($outputfile);
 		}
 
 		if ($retval == 0) {

+ 1 - 1
htdocs/install/doctemplates/websites/website_template-corporate/containers/wrapper.php

@@ -156,7 +156,7 @@ if ($rss) {
 
 		// Create temp file
 		$outputfiletmp = tempnam($dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
-		@chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
+		dolChmod($outputfiletmp);
 
 		// Write file
 		$result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp, '', $website->virtualhost.'/wrapper.php?rss=1'.($l ? '&l='.$l : ''), $l);

+ 1 - 1
htdocs/install/doctemplates/websites/website_template-homesubmenu/containers/wrapper.php

@@ -156,7 +156,7 @@ if ($rss) {
 
 		// Create temp file
 		$outputfiletmp = tempnam($dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
-		@chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
+		dolChmod($outputfiletmp);
 
 		// Write file
 		$result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp, '', $website->virtualhost.'/wrapper.php?rss=1'.($l ? '&l='.$l : ''), $l);

+ 1 - 1
htdocs/install/doctemplates/websites/website_template-noimg/containers/wrapper.php

@@ -156,7 +156,7 @@ if ($rss) {
 
 		// Create temp file
 		$outputfiletmp = tempnam($dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
-		@chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
+		dolChmod($outputfiletmp);
 
 		// Write file
 		$result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp, '', $website->virtualhost.'/wrapper.php?rss=1'.($l ? '&l='.$l : ''), $l);

+ 1 - 1
htdocs/install/doctemplates/websites/website_template-onepageblackpurple/containers/wrapper.php

@@ -156,7 +156,7 @@ if ($rss) {
 
 		// Create temp file
 		$outputfiletmp = tempnam($dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
-		@chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
+		dolChmod($outputfiletmp);
 
 		// Write file
 		$result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp, '', $website->virtualhost.'/wrapper.php?rss=1'.($l ? '&l='.$l : ''), $l);

+ 1 - 1
htdocs/install/doctemplates/websites/website_template-restaurant/containers/wrapper.php

@@ -156,7 +156,7 @@ if ($rss) {
 
 		// Create temp file
 		$outputfiletmp = tempnam($dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
-		@chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
+		dolChmod($outputfiletmp);
 
 		// Write file
 		$result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp, '', $website->virtualhost.'/wrapper.php?rss=1'.($l ? '&l='.$l : ''), $l);

+ 1 - 1
htdocs/install/doctemplates/websites/website_template-stellar/containers/wrapper.php

@@ -137,7 +137,7 @@ if ($rss) {
 
 		// Create temp file
 		$outputfiletmp = tempnam($dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
-		@chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
+		dolChmod($outputfiletmp);
 
 		// Write file
 		$result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp, '', $website->virtualhost.'/wrapper.php?rss=1'.($l ? '&l='.$l : ''), $l);

+ 6 - 4
htdocs/install/step5.php

@@ -443,11 +443,12 @@ if ($action == "set") {
 				$fp = @fopen($lockfile, "w");
 				if ($fp) {
 					if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
-						$force_install_lockinstall = 444; // For backward compatibility
+						$force_install_lockinstall = '444'; // For backward compatibility
 					}
 					fwrite($fp, "This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.")");
 					fclose($fp);
-					@chmod($lockfile, octdec($force_install_lockinstall));
+					dolChmod($lockfile, $force_install_lockinstall);
+
 					$createlock = 1;
 				}
 			}
@@ -490,11 +491,12 @@ if ($action == "set") {
 			$fp = @fopen($lockfile, "w");
 			if ($fp) {
 				if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
-					$force_install_lockinstall = 444; // For backward compatibility
+					$force_install_lockinstall = '444'; // For backward compatibility
 				}
 				fwrite($fp, "This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.")");
 				fclose($fp);
-				@chmod($lockfile, octdec($force_install_lockinstall));
+				dolChmod($lockfile, $force_install_lockinstall);
+
 				$createlock = 1;
 			}
 		}

+ 1 - 1
htdocs/langs/en_US/admin.lang

@@ -374,7 +374,7 @@ DoTestSendHTML=Test sending HTML
 ErrorCantUseRazIfNoYearInMask=Error, can't use option @ to reset counter each year if sequence {yy} or {yyyy} is not in mask.
 ErrorCantUseRazInStartedYearIfNoYearMonthInMask=Error, can't use option @ if sequence {yy}{mm} or {yyyy}{mm} is not in mask.
 UMask=UMask parameter for new files on Unix/Linux/BSD/Mac file system.
-UMaskExplanation=This parameter allow you to define permissions set by default on files created by Dolibarr on server (during upload for example).<br>It must be the octal value (for example, 0666 means read and write for everyone).<br>This parameter is useless on a Windows server.
+UMaskExplanation=This parameter allow you to define permissions set by default on files created by Dolibarr on server (during upload for example).<br>It must be the octal value (for example, 0666 means read and write for everyone.). Recommended value is 0660<br>This parameter is useless on a Windows server.
 SeeWikiForAllTeam=Take a look at the Wiki page for a list of contributors and their organization
 UseACacheDelay= Delay for caching export response in seconds (0 or empty for no cache)
 DisableLinkToHelpCenter=Hide the link "<b>Need help or support</b>" on the login page

+ 1 - 0
htdocs/langs/en_US/errors.lang

@@ -262,6 +262,7 @@ ErrorParameterMustBeEnabledToAllwoThisFeature=Error, parameter <b>%s</b> must be
 ErrorLoginDateValidity=Error, this login is outside the validity date range
 ErrorValueLength=Length of field '<b>%s</b>' must be higher than '<b>%s</b>'
 ErrorReservedKeyword=The word '<b>%s</b>' is a reserved keyword
+ErrorFilenameReserved=The filename <b>%s</b> can't be used as it is a reserved and protected command. 
 ErrorNotAvailableWithThisDistribution=Not available with this distribution
 ErrorPublicInterfaceNotEnabled=Public interface was not enabled
 ErrorLanguageRequiredIfPageIsTranslationOfAnother=The language of new page must be defined if it is set as a translation of another page

+ 51 - 51
htdocs/modulebuilder/index.php

@@ -1246,20 +1246,20 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
 			}
 			if ($objectname != $firstobjectname) {
 				$rightToadd = "
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = 'Read objects of ".$module."'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = 'Read objects of ".$module."';
 		\$this->rights[\$r][4] = '".strtolower($objectname)."';
-		\$this->rights[\$r][5] = 'read'; 
+		\$this->rights[\$r][5] = 'read';
 		\$r++;
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = 'Create/Update objects of ".$module."'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = 'Create/Update objects of ".$module."';
 		\$this->rights[\$r][4] = '".strtolower($objectname)."';
-		\$this->rights[\$r][5] = 'write'; 
+		\$this->rights[\$r][5] = 'write';
 		\$r++;
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = 'Delete objects of ".$module."'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = 'Delete objects of ".$module."';
 		\$this->rights[\$r][4] = '".strtolower($objectname)."';
-		\$this->rights[\$r][5] = 'delete'; 
+		\$this->rights[\$r][5] = 'delete';
 		\$r++;
 		";
 				dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectname).'*/'.$rightToadd."/*END ".strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */'));
@@ -1835,20 +1835,20 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
 
 		// regenerate permissions and delete them
 		$rights = "
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = 'Read objects of ".$module."'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = 'Read objects of ".$module."';
 		\$this->rights[\$r][4] = '".strtolower($objectname)."';
-		\$this->rights[\$r][5] = 'read'; 
+		\$this->rights[\$r][5] = 'read';
 		\$r++;
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = 'Create/Update objects of ".$module."'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = 'Create/Update objects of ".$module."';
 		\$this->rights[\$r][4] = '".strtolower($objectname)."';
-		\$this->rights[\$r][5] = 'write'; 
+		\$this->rights[\$r][5] = 'write';
 		\$r++;
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = 'Delete objects of ".$module."'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = 'Delete objects of ".$module."';
 		\$this->rights[\$r][4] = '".strtolower($objectname)."';
-		\$this->rights[\$r][5] = 'delete'; 
+		\$this->rights[\$r][5] = 'delete';
 		\$r++;
 		";
 
@@ -2050,10 +2050,10 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
 		}
 		//prepare stirng to add
 		$rightToAdd = "
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = '$label'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = '$label';
 		\$this->rights[\$r][4] = '$objectForPerms';
-		\$this->rights[\$r][5] = '$crud'; 
+		\$this->rights[\$r][5] = '$crud';
 		\$r++;
 		";
 		$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
@@ -2152,18 +2152,18 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
 
 		//prepare right want to delete
 		$right = "
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = '$x1'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = '$x1';
 		\$this->rights[\$r][4] = '$x2';
-		\$this->rights[\$r][5] = '$x3'; 
+		\$this->rights[\$r][5] = '$x3';
 		\$r++;
 		";
 		// right after editing
 		$rightUpdated = "
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = '$label'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = '$label';
 		\$this->rights[\$r][4] = '$objectForPerms';
-		\$this->rights[\$r][5] = '$crud'; 
+		\$this->rights[\$r][5] = '$crud';
 		\$r++;
 		";
 	if (!$error) {
@@ -2209,10 +2209,10 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p
 		$x3 = $permissions[$key][5];
 		//prepare right want to delete
 		$rightTodelete = "
-		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); 
-		\$this->rights[\$r][1] = '$x1'; 
+		\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+		\$this->rights[\$r][1] = '$x1';
 		\$this->rights[\$r][4] = '$x2';
-		\$this->rights[\$r][5] = '$x3'; 
+		\$this->rights[\$r][5] = '$x3';
 		\$r++;
 		";
 
@@ -2286,7 +2286,7 @@ if ($action == 'savefile' && empty($cancel)) {
 			dol_delete_file($pathoffile);
 			$result = file_put_contents($pathoffile, $content);
 			if ($result) {
-				@chmod($pathoffile, octdec($newmask));
+				dolChmod($pathoffile, $newmask);
 
 				setEventMessages($langs->trans("FileSaved"), null);
 			} else {
@@ -2394,19 +2394,19 @@ if ($dirins && $action == 'confirm_deletemenu' && GETPOST('menukey', 'int')) {
 	if ($menus[$key]['type'] == 'top') {
 			$menuTop = "
 		\$this->menu[\$r++] = array(
-			'fk_menu'=>'".$menus[$key]['fk_menu']."', 
-			'type'=>'".$menus[$key]['type']."', 
+			'fk_menu'=>'".$menus[$key]['fk_menu']."',
+			'type'=>'".$menus[$key]['type']."',
 			'titre'=>'".$menus[$key]['titre']."',
 			'prefix' => img_picto('', \$this->picto, 'class=\"paddingright pictofixedwidth valignmiddle\"'),
 			'mainmenu'=>'".$menus[$key]['mainmenu']."',
 			'leftmenu'=> '',
 			'url'=>'".$menus[$key]['url']."',
-			'langs'=>'".$menus[$key]['langs']."', 
+			'langs'=>'".$menus[$key]['langs']."',
 			'position'=>1000 + \$r,
-			'enabled'=>'isModEnabled(\"".strtolower($module)."\")', 
+			'enabled'=>'isModEnabled(\"".strtolower($module)."\")',
 			'perms' =>'".$menus[$key]['perms']."',
 			'target'=>'".$menus[$key]['target']."',
-			'user'=>".$menus[$key]['user'].", 
+			'user'=>".$menus[$key]['user'].",
 		);";
 		$check = dolReplaceInFile($moduledescriptorfile, array($menuTop => '',"\t\t".'/*TOPMENU '.strtolower($menus[$key]['titre']).'*/'."\n" => '', '/*END TOPMENU '.strtolower($menus[$key]['titre']).'*/'."\n\t\t" => ''));
 	}
@@ -2579,19 +2579,19 @@ if ($dirins && $action == 'addmenu' && empty($cancel)) {
 		if ($type == 'top') {
 			$menuTop = "
 		\$this->menu[\$r++] = array(
-			'fk_menu'=>'".$fk_menu."', 
-			'type'=>'".strtolower($type)."', 
+			'fk_menu'=>'".$fk_menu."',
+			'type'=>'".strtolower($type)."',
 			'titre'=>'".ucfirst($titre)."',
 			'prefix' => img_picto('', \$this->picto, 'class=\"paddingright pictofixedwidth valignmiddle\"'),
 			'mainmenu'=>'".$mainmenu."',
 			'leftmenu'=> '".$leftmenu."',
 			'url'=>'".$url."',
-			'langs'=>'".strtolower($module)."@".strtolower($module)."', 
+			'langs'=>'".strtolower($module)."@".strtolower($module)."',
 			'position'=>1000 + \$r,
-			'enabled'=>'isModEnabled(\"".strtolower($module)."\")', 
+			'enabled'=>'isModEnabled(\"".strtolower($module)."\")',
 			'perms' =>'".$perms."',
 			'target'=>'".$target."',
-			'user'=>".$user.", 
+			'user'=>".$user.",
 		);";
 			$addTopMenu = dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER TOPMENU */' => '/*TOPMENU '.strtolower($titre).'*/'.$menuTop."\n\t\t".'/*END TOPMENU '.strtolower($titre).'*/'."\n\t\t/* END MODULEBUILDER TOPMENU */"));
 		}
@@ -2605,7 +2605,7 @@ if ($dirins && $action == 'addmenu' && empty($cancel)) {
 			'mainmenu'=>'".strtolower($module)."',
 			'leftmenu'=>'".strtolower($leftmenu)."',
 			'url'=>'".$url."',
-			'langs'=>'".strtolower($module)."@".strtolower($module)."', 
+			'langs'=>'".strtolower($module)."@".strtolower($module)."',
 			'position'=>1100+\$r,
 			'enabled'=>'\$conf->".strtolower($module)."->enabled',
 			'perms'=>'".$perms."',
@@ -2662,12 +2662,12 @@ if ($dirins && $action == "modify_menu" && GETPOST('menukey', 'int') && empty(GE
 			'mainmenu'=>'".$menus[$key]['mainmenu']."',
 			'leftmenu' =>'".$menus[$key]['leftmenu']."',
 			'url' =>'".$menus[$key]['url']."',
-			'langs'=>'".$menus[$key]['langs']."', 
+			'langs'=>'".$menus[$key]['langs']."',
 			'position'=>1000 + \$r,
-			'enabled'=>'isModEnabled(\"".strtolower($module)."\")', 
+			'enabled'=>'isModEnabled(\"".strtolower($module)."\")',
 			'perms' =>'".$menus[$key]['perms']."',
 			'target'=>'".$menus[$key]['target']."',
-			'user'=>".$menus[$key]['user'].", 
+			'user'=>".$menus[$key]['user'].",
 		);";
 
 		$fk_menu = GETPOST('fk_type', 'alpha');
@@ -2691,12 +2691,12 @@ if ($dirins && $action == "modify_menu" && GETPOST('menukey', 'int') && empty(GE
 			'mainmenu'=>'".$menus[$key]['mainmenu']."',
 			'leftmenu' =>'".$menus[$key]['leftmenu']."',
 			'url' =>'".$url."',
-			'langs'=>'".$menus[$key]['langs']."', 
+			'langs'=>'".$menus[$key]['langs']."',
 			'position'=>1000 + \$r,
-			'enabled'=>'".$menus[$key]['enabled']."', 
+			'enabled'=>'".$menus[$key]['enabled']."',
 			'perms' =>'".$perms."',
 			'target'=>'".$target."',
-			'user'=>".$user.", 
+			'user'=>".$user.",
 		);";
 
 
@@ -2716,12 +2716,12 @@ if ($dirins && $action == "modify_menu" && GETPOST('menukey', 'int') && empty(GE
 			'mainmenu'=>'".$menus[$key]['mainmenu']."',
 			'leftmenu' =>'".$menus[$key]['leftmenu']."',
 			'url' =>'".$url."',
-			'langs'=>'".$menus[$key]['langs']."', 
+			'langs'=>'".$menus[$key]['langs']."',
 			'position'=>1000 + \$r,
-			'enabled'=>'isModEnabled(\"".strtolower($module)."\")', 
+			'enabled'=>'isModEnabled(\"".strtolower($module)."\")',
 			'perms' =>'".$perms."',
 			'target'=>'".$target."',
-			'user'=>'".$user."', 
+			'user'=>'".$user."',
 		);";
 
 			dolReplaceInFile($moduledescriptorfile, array($menuTomodify => $modifiedMenu));

+ 1 - 3
htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php

@@ -498,9 +498,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 3 - 5
htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php

@@ -783,13 +783,11 @@ class pdf_standard_myobject extends ModelePDFMyObject
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
-					$this->result = array('fullpath'=>$file);
+				$this->result = array('fullpath'=>$file);
 
-					return 1; // No error
+				return 1; // No error
 			} else {
 				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
 				return 0;

+ 5 - 9
htdocs/projet/class/projectstats.class.php

@@ -366,10 +366,7 @@ class ProjectStats extends Stats
 			if ($fp) {
 				fwrite($fp, json_encode($data));
 				fclose($fp);
-				if (!empty($conf->global->MAIN_UMASK)) {
-					$newmask = $conf->global->MAIN_UMASK;
-				}
-				@chmod($newpathofdestfile, octdec($newmask));
+				dolChmod($newpathofdestfile);
 			} else {
 				dol_syslog("Failed to write cache file", LOG_ERR);
 			}
@@ -479,12 +476,11 @@ class ProjectStats extends Stats
 				dol_mkdir($conf->user->dir_temp);
 			}
 			$fp = fopen($newpathofdestfile, 'w');
-			fwrite($fp, json_encode($data));
-			fclose($fp);
-			if (!empty($conf->global->MAIN_UMASK)) {
-				$newmask = $conf->global->MAIN_UMASK;
+			if ($fp) {
+				fwrite($fp, json_encode($data));
+				fclose($fp);
+				dolChmod($newpathofdestfile);
 			}
-			@chmod($newpathofdestfile, octdec($newmask));
 
 			$this->lastfetchdate[get_class($this).'_'.__FUNCTION__] = $nowgmt;
 		}

+ 1 - 3
htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php

@@ -482,9 +482,7 @@ class doc_generic_recruitmentjobposition_odt extends ModelePDFRecruitmentJobPosi
 				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
 				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
 				$odfHandler = null; // Destroy object
 

+ 3 - 5
htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php

@@ -710,13 +710,11 @@ class pdf_standard_recruitmentjobposition extends ModelePDFRecruitmentJobPositio
 					$this->errors = $hookmanager->errors;
 				}
 
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($file);
 
-					$this->result = array('fullpath'=>$file);
+				$this->result = array('fullpath'=>$file);
 
-					return 1; // No error
+				return 1; // No error
 			} else {
 				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
 				return 0;

+ 1 - 3
htdocs/website/class/website.class.php

@@ -1132,9 +1132,7 @@ class Website extends CommonObject
 		fputs($fp, $line);
 
 		fclose($fp);
-		if (!empty($conf->global->MAIN_UMASK)) {
-			@chmod($filesql, octdec($conf->global->MAIN_UMASK));
-		}
+		dolChmod($filesql);
 
 		// Build zip file
 		$filedir  = $conf->website->dir_temp.'/'.$website->ref.'/.';

+ 4 - 9
htdocs/website/index.php

@@ -939,8 +939,7 @@ if ($action == 'addcontainer' && $usercanedit) {
 						$fp = fopen($filetosave, "w");
 						fputs($fp, $tmpgeturl['content']);
 						fclose($fp);
-						if (!empty($conf->global->MAIN_UMASK))
-							@chmod($file, octdec($conf->global->MAIN_UMASK));
+						dolChmod($file);
 					}
 					*/
 
@@ -1008,8 +1007,7 @@ if ($action == 'addcontainer' && $usercanedit) {
 						//$fp = fopen($filetosave, "w");
 						//fputs($fp, $tmpgeturl['content']);
 						//fclose($fp);
-						//if (!empty($conf->global->MAIN_UMASK))
-						//	@chmod($file, octdec($conf->global->MAIN_UMASK));
+						//dolChmod($file);
 
 						//	$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
 						$pagecsscontent .= '/* Content of file '.$urltograbbis.' */'."\n";
@@ -2659,9 +2657,7 @@ if ($action == 'generatesitemaps' && $usercanedit) {
 			}
 			$domtree->appendChild($root);
 			if ($domtree->save($tempdir.$xmlname)) {
-				if (!empty($conf->global->MAIN_UMASK)) {
-					@chmod($tempdir.$xmlname, octdec($conf->global->MAIN_UMASK));
-				}
+				dolChmod($tempdir.$xmlname);
 				setEventMessages($langs->trans("SitemapGenerated", $xmlname), null, 'mesgs');
 			} else {
 				setEventMessages($object->error, $object->errors, 'errors');
@@ -5022,8 +5018,7 @@ if ((empty($action) || $action == 'preview' || $action == 'createfromclone' || $
 		print $out;
 
 		/*file_put_contents($filetpl, $out);
-		if (!empty($conf->global->MAIN_UMASK))
-			@chmod($filetpl, octdec($conf->global->MAIN_UMASK));
+		dolChmod($filetpl);
 
 		// Output file on browser
 		dol_syslog("index.php include $filetpl $filename content-type=$type");

Some files were not shown because too many files changed in this diff