Commit 748ddac6 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Upload: rename 'chmod' to 'chmodFile'. Implement 'chmodDir'. Permissions...

Upload: rename 'chmod' to 'chmodFile'. Implement 'chmodDir'. Permissions applied for all new created directories.
parent dfd4016e
Pipeline #939 passed with stage
in 1 minute and 44 seconds
...@@ -2823,7 +2823,7 @@ See also at specific *FormElement* definitions. ...@@ -2823,7 +2823,7 @@ See also at specific *FormElement* definitions.
| autoOrient | string | | | autoOrient | string | |
| autoOrientCmd | string | | | autoOrientCmd | string | |
| autoOrientMimeType | string | | | autoOrientMimeType | string | |
| chmod | string | | | chmodFile / chmodDir | string | |
| slaveId | string | | | slaveId | string | |
| sqlBefore | string | | | sqlBefore | string | |
| sqlInsert | string | | | sqlInsert | string | |
...@@ -3489,7 +3489,9 @@ See also `downloadButton`_ to offer a download of an uploaded file. ...@@ -3489,7 +3489,9 @@ See also `downloadButton`_ to offer a download of an uploaded file.
* *fileReplace* = `always` - If `fileDestination` exist - replace it by the new one. * *fileReplace* = `always` - If `fileDestination` exist - replace it by the new one.
* *chmod* = <unix file permission mode> - e.g. `660` for owner and group read and writeable. Only the numeric mode is allowed. * *chmodFile* = <unix file permission mode> - e.g. `660` for owner and group read and writeable. Only the numeric mode is allowed.
* *chmodDir* = <unix file permission mode> - e.g. `770` for owner and group read, writeable and executable. Only the
numeric mode is allowed. Will be applied to all new created directories.
* autoOrient: images might contain EXIF data (e.g. captured via mobile phones) incl. an orientation tag like TopLeft, * autoOrient: images might contain EXIF data (e.g. captured via mobile phones) incl. an orientation tag like TopLeft,
BottomRight and so on. Web-Browser and other grafic programs often understand and respect those information and rotate BottomRight and so on. Web-Browser and other grafic programs often understand and respect those information and rotate
......
...@@ -985,7 +985,8 @@ const FE_FILE_AUTO_ORIENT = 'autoOrient'; ...@@ -985,7 +985,8 @@ const FE_FILE_AUTO_ORIENT = 'autoOrient';
const FE_FILE_AUTO_ORIENT_CMD = 'autoOrientCmd'; const FE_FILE_AUTO_ORIENT_CMD = 'autoOrientCmd';
const FE_FILE_AUTO_ORIENT_CMD_DEFAULT = 'convert -auto-orient {{fileDestination:V}} {{fileDestination:V}}.new; mv {{fileDestination:V}}.new {{fileDestination:V}}'; const FE_FILE_AUTO_ORIENT_CMD_DEFAULT = 'convert -auto-orient {{fileDestination:V}} {{fileDestination:V}}.new; mv {{fileDestination:V}}.new {{fileDestination:V}}';
const FE_FILE_AUTO_ORIENT_MIME_TYPE = 'autoOrientMimeType'; const FE_FILE_AUTO_ORIENT_MIME_TYPE = 'autoOrientMimeType';
const FE_FILE_CHMOD = 'chmod'; const FE_FILE_CHMOD_FILE = 'chmodFile';
const FE_FILE_CHMOD_DIR = 'chmodDir';
// Excel Import // Excel Import
const FE_IMPORT_TO_TABLE = 'importToTable'; const FE_IMPORT_TO_TABLE = 'importToTable';
......
...@@ -773,20 +773,27 @@ class Save { ...@@ -773,20 +773,27 @@ class Save {
throw new UserFormException("Upload failed, no target '" . FE_FILE_DESTINATION . "' specified.", ERROR_NO_TARGET_PATH_FILE_NAME); throw new UserFormException("Upload failed, no target '" . FE_FILE_DESTINATION . "' specified.", ERROR_NO_TARGET_PATH_FILE_NAME);
} }
// If given, get chmodDir. Needs to be prefixed with a 0 (=octal) - it should not be quoted! Symbolic mode is not allowed. E.g.: 0660, or 01777
if (empty($formElement[FE_FILE_CHMOD_DIR])) {
$chmodDir = false;
} else {
$chmodDir = octdec($formElement[FE_FILE_CHMOD_DIR]);
}
$overwrite = isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS; $overwrite = isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS;
Support::copyFile($srcFile, $pathFileName, $overwrite); Support::copyFile($srcFile, $pathFileName, $overwrite, $chmodDir);
// If given, get chmod. Needs to be prefixed with a 0 (=octal) - it should not be quoted! Symbolic mode is not allowed. E.g.: 0660, or 01777 // If given, get chmodFile. Needs to be prefixed with a 0 (=octal) - it should not be quoted! Symbolic mode is not allowed. E.g.: 0660, or 01777
if (empty($formElement[FE_FILE_CHMOD])) { if (empty($formElement[FE_FILE_CHMOD_FILE])) {
$chmod = false; $chmodFile = false;
} else { } else {
$chmod = octdec($formElement[FE_FILE_CHMOD]); $chmodFile = octdec($formElement[FE_FILE_CHMOD_FILE]);
} }
$this->autoOrient($formElement, $pathFileName); $this->autoOrient($formElement, $pathFileName);
HelperFile::doChmod($pathFileName, $chmod); HelperFile::doChmod($pathFileName, $chmodFile);
$this->splitUpload($formElement, $pathFileName, $chmod); $this->splitUpload($formElement, $pathFileName, $chmodFile);
return $pathFileName; return $pathFileName;
} }
......
...@@ -40,7 +40,7 @@ class HelperFile { ...@@ -40,7 +40,7 @@ class HelperFile {
* *
* @return bool|string * @return bool|string
*/ */
public static function tempnam(){ public static function tempnam() {
return tempnam(sys_get_temp_dir(), TMP_FILE_PREFIX); return tempnam(sys_get_temp_dir(), TMP_FILE_PREFIX);
} }
...@@ -227,9 +227,10 @@ class HelperFile { ...@@ -227,9 +227,10 @@ class HelperFile {
* @param bool $chmod * @param bool $chmod
* @throws UserFormException * @throws UserFormException
*/ */
public static function doChmod($pathFileName, $chmod=false){ public static function doChmod($pathFileName, $chmod = false) {
if($chmod!==false){
if(false===chmod($pathFileName, $chmod)){ if ($chmod !== false) {
if (false === chmod($pathFileName, $chmod)) {
throw new UserFormException("Failed: chmod $chmod '$pathFileName'", ERROR_IO_CHMOD); throw new UserFormException("Failed: chmod $chmod '$pathFileName'", ERROR_IO_CHMOD);
} }
} }
......
...@@ -78,7 +78,7 @@ class Support { ...@@ -78,7 +78,7 @@ class Support {
break; break;
case FORM_LOG_SESSION: case FORM_LOG_SESSION:
$perBeSession = self::$store->getVar(TYPO3_BE_USER, STORE_TYPO3) . '.'; $perBeSession = self::$store->getVar(TYPO3_BE_USER, STORE_TYPO3) . '.';
if(empty($perBeSession)){ if (empty($perBeSession)) {
throw new UserFormException('formLog: no BE User logged in', ERROR_NO_BE_USER_LOGGED); throw new UserFormException('formLog: no BE User logged in', ERROR_NO_BE_USER_LOGGED);
} }
break; break;
...@@ -1232,10 +1232,10 @@ class Support { ...@@ -1232,10 +1232,10 @@ class Support {
* specified. * specified.
* *
* @param string $pathFileName Path with Filename * @param string $pathFileName Path with Filename
* * @param bool|int $chmodDir false if not explicit set
* @throws UserFormException * @throws UserFormException
*/ */
public static function mkDirParent($pathFileName) { public static function mkDirParent($pathFileName, $chmodDir = false) {
$path = ""; $path = "";
// Teile "Directory/File.Extension" auf // Teile "Directory/File.Extension" auf
...@@ -1259,10 +1259,11 @@ class Support { ...@@ -1259,10 +1259,11 @@ class Support {
if ("dir" != filetype($path)) { if ("dir" != filetype($path)) {
throw new UserFormException("Can't create '$pathFileName': There is already a file with the same name as '$path'", ERROR_IO_DIR_EXIST_AS_FILE); throw new UserFormException("Can't create '$pathFileName': There is already a file with the same name as '$path'", ERROR_IO_DIR_EXIST_AS_FILE);
} }
} else } else {
mkdir($path, 0700); mkdir($path);
HelperFile::doChmod($path, $chmodDir);
}
} }
$path .= "/"; $path .= "/";
} }
} }
...@@ -1271,9 +1272,12 @@ class Support { ...@@ -1271,9 +1272,12 @@ class Support {
* @param $srcFile * @param $srcFile
* @param $pathFileName * @param $pathFileName
* @param bool $overwrite * @param bool $overwrite
* @param bool|int $chmodDir , 'false' if not change
* @throws UserFormException * @throws UserFormException
*/ */
public static function copyFile($srcFile, $pathFileName, $overwrite = false) { public
static function copyFile($srcFile, $pathFileName, $overwrite, $chmodDir = false) {
if (file_exists($pathFileName)) { if (file_exists($pathFileName)) {
if ($overwrite) { if ($overwrite) {
if (!unlink($pathFileName)) { if (!unlink($pathFileName)) {
...@@ -1284,7 +1288,7 @@ class Support { ...@@ -1284,7 +1288,7 @@ class Support {
} }
} }
Support::mkDirParent($pathFileName); Support::mkDirParent($pathFileName, $chmodDir);
// Do not use 'rename' - might cause trouble if src and dest are on different filesystems. // Do not use 'rename' - might cause trouble if src and dest are on different filesystems.
if (!copy($srcFile, $pathFileName)) { if (!copy($srcFile, $pathFileName)) {
...@@ -1300,7 +1304,8 @@ class Support { ...@@ -1300,7 +1304,8 @@ class Support {
/** /**
* *
*/ */
public static function createTempDir() { public
static function createTempDir() {
return exec("mktemp -d --tmpdir " . QFQ_TEMP_FILE_PATTERN); return exec("mktemp -d --tmpdir " . QFQ_TEMP_FILE_PATTERN);
...@@ -1313,7 +1318,8 @@ class Support { ...@@ -1313,7 +1318,8 @@ class Support {
* *
* @return string * @return string
*/ */
public static function falseEmptyToZero($val) { public
static function falseEmptyToZero($val) {
return ($val == '' || $val == false) ? '0' : $val; return ($val == '' || $val == false) ? '0' : $val;
} }
...@@ -1324,7 +1330,8 @@ class Support { ...@@ -1324,7 +1330,8 @@ class Support {
* @param string $key * @param string $key
* @return bool true: if $key exists and a) is empty or b) =='1' * @return bool true: if $key exists and a) is empty or b) =='1'
*/ */
public static function isEnabled(array $arr, $key) { public
static function isEnabled(array $arr, $key) {
if (!array_key_exists($key, $arr)) { if (!array_key_exists($key, $arr)) {
return false; return false;
} }
...@@ -1345,7 +1352,8 @@ class Support { ...@@ -1345,7 +1352,8 @@ class Support {
* *
* @return string * @return string
*/ */
public static function handleEscapeSpaceComment($str) { public
static function handleEscapeSpaceComment($str) {
$str = trim($str); $str = trim($str);
...@@ -1381,7 +1389,8 @@ class Support { ...@@ -1381,7 +1389,8 @@ class Support {
* *
* @return string * @return string
**/ **/
public static function ldap_escape($subject, $ignore = '', $flags = 0) { public
static function ldap_escape($subject, $ignore = '', $flags = 0) {
if (function_exists('ldap_escape')) { if (function_exists('ldap_escape')) {
...@@ -1453,7 +1462,8 @@ class Support { ...@@ -1453,7 +1462,8 @@ class Support {
* @return string * @return string
* @throws UserFormException * @throws UserFormException
*/ */
public static function htmlEntityEncodeDecode($mode, $data) { public
static function htmlEntityEncodeDecode($mode, $data) {
switch ($mode) { switch ($mode) {
case MODE_ENCODE: case MODE_ENCODE:
...@@ -1476,7 +1486,8 @@ class Support { ...@@ -1476,7 +1486,8 @@ class Support {
* @param $size_str * @param $size_str
* @return float|int|string * @return float|int|string
*/ */
public static function returnBytes($size_str) { public
static function returnBytes($size_str) {
$size_str = trim($size_str); $size_str = trim($size_str);
switch (substr($size_str, -1)) { switch (substr($size_str, -1)) {
...@@ -1503,7 +1514,8 @@ class Support { ...@@ -1503,7 +1514,8 @@ class Support {
* @param int $rc * @param int $rc
* @return string The content that is displayed on the website * @return string The content that is displayed on the website
*/ */
public static function qfqExec($cmd, &$rc = 0) { public
static function qfqExec($cmd, &$rc = 0) {
exec($cmd, $arr, $rc); exec($cmd, $arr, $rc);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment