Commit 633b3a33 authored by Carsten  Rose's avatar Carsten Rose
Browse files

F6894 / Upload: chmod for file creation - fixes #6894

parent 451fbcf3
Pipeline #934 passed with stage
in 1 minute and 42 seconds
......@@ -2820,7 +2820,10 @@ See also at specific *FormElement* definitions.
| maxFileSize | string | |
| fileDestination | string | |
| fileReplace | string | |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+
| autoOrient | string | |
| autoOrientCmd | string | |
| autoOrientMimeType | string | |
| chmod | string | |
| slaveId | string | |
| sqlBefore | string | |
| sqlInsert | string | |
......@@ -3486,6 +3489,8 @@ See also `downloadButton`_ to offer a download of an uploaded file.
* *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.
* 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
such images automatically. If not, the image might be displayed in an unwanted oritentation.
......
......@@ -26,7 +26,6 @@ sendEMailOptions =
dateFormat = dd.mm.yyyy
# cat=dynamic/config; type=string; label=Fill store 'SYSTEM' by SQL 1:Default is empty. SQL query fired during QFQ load. The result have to be exactly one row. That row will be merged to store 'SYSTEM'. Retrieve values via '{{column:Y}}'. Example 'SELECT id AS _periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1'
fillStoreSystemBySql1 =
......
......@@ -224,6 +224,7 @@ const ERROR_IO_CHDIR = 1310;
const ERROR_IO_CREATE_FILE = 1311;
const ERROR_IO_COPY_FILE = 1312;
const ERROR_IO_FILE_NOT_FOUND = 1313;
const ERROR_IO_CHMOD = 1314;
//Report
const ERROR_UNKNOWN_LINK_QUALIFIER = 1400;
......@@ -983,6 +984,7 @@ const FE_FILE_AUTO_ORIENT = 'autoOrient';
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_MIME_TYPE = 'autoOrientMimeType';
const FE_FILE_CHMOD = 'chmod';
// Excel Import
const FE_IMPORT_TO_TABLE = 'importToTable';
......
......@@ -443,9 +443,9 @@ class Save {
$this->feSpecNative[$key][FE_MODE_SQL] = $mode;
}
if(isset($formElement[FE_ACCEPT_ZERO_AS_REQUIRED]) && $formElement[FE_ACCEPT_ZERO_AS_REQUIRED] != '0' &&
isset($clientValues[$formElement[FE_NAME]]) && $clientValues[$formElement[FE_NAME]]=='0'){
$mode='fake'; // The next if() should never be true.
if (isset($formElement[FE_ACCEPT_ZERO_AS_REQUIRED]) && $formElement[FE_ACCEPT_ZERO_AS_REQUIRED] != '0' &&
isset($clientValues[$formElement[FE_NAME]]) && $clientValues[$formElement[FE_NAME]] == '0') {
$mode = 'fake'; // The next if() should never be true.
}
if (!$requiredOff && $mode == FE_MODE_REQUIRED && empty($clientValues[$formElement[FE_NAME]])) {
......@@ -776,8 +776,17 @@ class Save {
$overwrite = isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS;
Support::copyFile($srcFile, $pathFileName, $overwrite);
// 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 (empty($formElement[FE_FILE_CHMOD])) {
$chmod = false;
} else {
$chmod = octdec($formElement[FE_FILE_CHMOD]);
}
$this->autoOrient($formElement, $pathFileName);
$this->splitUpload($formElement, $pathFileName);
HelperFile::doChmod($pathFileName, $chmod);
$this->splitUpload($formElement, $pathFileName, $chmod);
return $pathFileName;
}
......@@ -793,16 +802,16 @@ class Save {
* @throws UserFormException
* @throws UserReportException
*/
private function autoOrient(array $formElement, $pathFileName){
private function autoOrient(array $formElement, $pathFileName) {
// 'autoOrient' wished?
if(!isset($formElement[FE_FILE_AUTO_ORIENT]) || $formElement[FE_FILE_AUTO_ORIENT]=='0' ){
if (!isset($formElement[FE_FILE_AUTO_ORIENT]) || $formElement[FE_FILE_AUTO_ORIENT] == '0') {
return; // No
}
// Upload has matching MimeType?
$mimeTypeList = empty($formElement[FE_FILE_AUTO_ORIENT_MIME_TYPE]) ? 'image/jpeg,image/png,image/tiff' : $formElement[FE_FILE_AUTO_ORIENT_MIME_TYPE];
if(!HelperFile::checkFileType($pathFileName, $pathFileName, $mimeTypeList)) {
if (!HelperFile::checkFileType($pathFileName, $pathFileName, $mimeTypeList)) {
return;
}
......@@ -823,13 +832,14 @@ class Save {
* current page/file.
*
* @param array $formElement
* @param $pathFileName
* @param string $pathFileName
* @param int $chmod
* @throws CodeException
* @throws DbException
* @throws UserFormException
* @throws UserReportException
*/
private function splitUpload(array $formElement, $pathFileName) {
private function splitUpload(array $formElement, $pathFileName, $chmod) {
if (empty($formElement[FE_FILE_SPLIT]) || empty($formElement[FE_FILE_DESTINATION_SPLIT])) {
return;
......@@ -846,7 +856,7 @@ class Save {
// Filetype testen: nur Dateien splitten die man auch wirklich entpacken kann
switch ($fileSplit) {
case FE_FILE_SPLIT_SVG:
$this->splitSvg($pathFileName, $fileDestinationSplit, $fileSplitTableName);
$this->splitSvg($pathFileName, $fileDestinationSplit, $fileSplitTableName, $chmod);
break;
default:
throw new UserFormException("Unknown 'fileSplit' type: " . $formElement[FE_FILE_SPLIT], ERROR_UNKNOWN_TOKEN);
......@@ -857,14 +867,15 @@ class Save {
* Split's the PDF file $pathFileNameSrc in several SVG-file, one per page.
* For every created file, a record in table 'Split' is created, storing the pathFileName to the individual file.
*
* @param $pathFileNameSrc
* @param $fileDestinationSplit
* @param $fileSplitTableName
* @param string $pathFileNameSrc
* @param string $fileDestinationSplit
* @param string $fileSplitTableName
* @param int $chmod
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
private function splitSvg($pathFileNameSrc, $fileDestinationSplit, $fileSplitTableName) {
private function splitSvg($pathFileNameSrc, $fileDestinationSplit, $fileSplitTableName, $chmod) {
Support::mkDirParent($fileDestinationSplit);
......@@ -910,6 +921,7 @@ class Save {
}
$rc = rename($file, Support::joinPath($cwd, $fileDestination));
HelperFile::doChmod($fileDestination, $chmod);
// Insert records.
$this->db->sql($sql, ROW_REGULAR, [$fileSplitTableName, $this->store->getVar(COLUMN_ID, STORE_RECORD), $fileDestination]);
......
......@@ -221,4 +221,18 @@ class HelperFile {
return false;
}
/**
* @param $pathFileName
* @param bool $chmod
* @throws UserFormException
*/
public static function doChmod($pathFileName, $chmod=false){
if($chmod!==false){
if(false===chmod($pathFileName, $chmod)){
throw new UserFormException("Failed: chmod $chmod '$pathFileName'", ERROR_IO_CHMOD);
}
}
}
}
\ No newline at end of file
......@@ -1289,6 +1289,7 @@ class Support {
if (!rename($srcFile, $pathFileName)) {
throw new UserFormException("Rename file: '$srcFile' > '$pathFileName'", ERROR_IO_RENAME);
}
}
/**
......
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