Skip to content

Commit

Permalink
Merge pull request #139 from dereks/dereks/109-duplicated_configs
Browse files Browse the repository at this point in the history
Dereks/109 duplicated configs
  • Loading branch information
Pavel Solomienko authored Mar 26, 2017
2 parents a19a5de + 0258f2a commit 758e696
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 238 deletions.
45 changes: 3 additions & 42 deletions config/filemanager.config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"fileSorting": "NAME_ASC",
"folderPosition": "bottom",
"quickSelect": false,
"charsLatinOnly": false,
"logger": false,
"allowChangeExtensions": false,
"capabilities": [
"select",
"upload",
Expand Down Expand Up @@ -53,51 +53,12 @@
"requestParams": []
},
"security": {
"allowFolderDownload": true,
"allowChangeExtensions": false,
"allowNoExtension": false,
"normalizeFilename": true
"allowNoExtension": false
},
"upload": {
"multiple": true,
"maxNumberOfFiles": 5,
"paramName": "files",
"chunkSize": false,
"fileSizeLimit": 16000000,
"policy": "DISALLOW_ALL",
"restrictions": [
"jpg",
"jpe",
"jpeg",
"gif",
"png",
"svg",
"txt",
"pdf",
"odp",
"ods",
"odt",
"rtf",
"doc",
"docx",
"xls",
"xlsx",
"ppt",
"pptx",
"csv",
"ogv",
"avi",
"mkv",
"mp4",
"webm",
"m4v",
"ogg",
"mp3",
"wav",
"zip",
"rar",
"md"
]
"chunkSize": false
},
"viewer": {
"absolutePath": true,
Expand Down
6 changes: 1 addition & 5 deletions connectors/ashx/filemanager.ashx
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,12 @@ public class filemanager : IHttpHandler
sb.AppendLine(" \"culture\": \"nl\",");
sb.AppendLine(" \"charsLatinOnly\": false,");
sb.AppendLine(" \"capabilities\": false");
sb.AppendLine(" \"allowFolderDownload\": false,");
sb.AppendLine("},");
sb.AppendLine("\"security\": {");
sb.AppendLine(" \"allowFolderDownload\": false,");
sb.AppendLine(" \"allowChangeExtensions\": false,");
sb.AppendLine(" \"allowNoExtension\": false,");
sb.AppendLine(" \"normalizeFilename\": true");
sb.AppendLine("},");
sb.AppendLine("\"upload\": {");
sb.AppendLine(" \"paramName\": \"files\",");
sb.AppendLine(" \"chunkSize\": false,");
sb.AppendLine(" \"fileSizeLimit\": 16000000,");
sb.AppendLine(" \"policy\": \"ALLOW_ALL\"");
//sb.AppendLine(" \"restrictions\": { \"jpg\" }");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,51 +372,37 @@ public JSONObject actionInitiate(HttpServletRequest request) throws FileManagerE
JSONObject init = new JSONObject();
JSONObject data = new JSONObject();
JSONObject attributes = new JSONObject();
Boolean overrideClientConfig = Boolean.parseBoolean(propertiesConfig.getProperty("overrideClientConfig"));
data.put("id", "/");
data.put("type", "initiate");

if(overrideClientConfig){
JSONObject options = new JSONObject();
options.put("culture", propertiesConfig.getProperty("culture"));
options.put("charsLatinOnly", Boolean.parseBoolean(propertiesConfig.getProperty("charsLatinOnly")));
if( propertiesConfig.getProperty("capabilities") != null ){
options.put("capabilities", propertiesConfig.getProperty("capabilities"));
} else{
options.put("capabilities", false);
}

JSONObject security = new JSONObject();
security.put("allowFolderDownload", Boolean.parseBoolean(propertiesConfig.getProperty("allowFolderDownload")));
security.put("allowChangeExtensions", Boolean.parseBoolean(propertiesConfig.getProperty("allowChangeExtensions")));
security.put("allowNoExtension", Boolean.parseBoolean(propertiesConfig.getProperty("allowNoExtension")));
security.put("normalizeFilename", Boolean.parseBoolean(propertiesConfig.getProperty("normalizeFilename")));
security.put("editRestrictions", propertiesConfig.getProperty("editRestrictions").split(","));

JSONObject upload = new JSONObject();
upload.put("paramName", propertiesConfig.getProperty("upload_paramName"));
if( propertiesConfig.getProperty("upload_chunkSize") != null ){
upload.put("chunkSize", propertiesConfig.getProperty("upload_chunkSize"));
} else{
upload.put("chunkSize", false);
}
try {
upload.put("fileSizeLimit", Long.parseLong(propertiesConfig.getProperty("upload_fileSizeLimit")));
}catch (NumberFormatException e){
logger.error("fileSizeLimit -> Format Exception", e);
}
upload.put("policy", propertiesConfig.getProperty("upload_policy"));
upload.put("restrictions", propertiesConfig.getProperty("upload_restrictions").split(","));

JSONObject sharedConfig = new JSONObject();
sharedConfig.put("options", options);
sharedConfig.put("security", security);
sharedConfig.put("upload", upload);
attributes.put("config", sharedConfig);
JSONObject options = new JSONObject();
options.put("culture", propertiesConfig.getProperty("culture"));
options.put("charsLatinOnly", Boolean.parseBoolean(propertiesConfig.getProperty("charsLatinOnly")));
if( propertiesConfig.getProperty("capabilities") != null ){
options.put("capabilities", propertiesConfig.getProperty("capabilities"));
} else{
options.put("capabilities", false);
}
else {
attributes.put("config", new JSONObject());
options.put("allowFolderDownload", Boolean.parseBoolean(propertiesConfig.getProperty("allowFolderDownload")));

JSONObject security = new JSONObject();
security.put("allowNoExtension", Boolean.parseBoolean(propertiesConfig.getProperty("allowNoExtension")));
security.put("editRestrictions", propertiesConfig.getProperty("editRestrictions").split(","));

JSONObject upload = new JSONObject();
try {
upload.put("fileSizeLimit", Long.parseLong(propertiesConfig.getProperty("upload_fileSizeLimit")));
}catch (NumberFormatException e){
logger.error("fileSizeLimit -> Format Exception", e);
}
upload.put("policy", propertiesConfig.getProperty("upload_policy"));
upload.put("restrictions", propertiesConfig.getProperty("upload_restrictions").split(","));

JSONObject sharedConfig = new JSONObject();
sharedConfig.put("options", options);
sharedConfig.put("security", security);
sharedConfig.put("upload", upload);
attributes.put("config", sharedConfig);

data.put("attributes", attributes);
init.put("data", data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,8 @@ public JSONObject actionRename(HttpServletRequest request) throws FileManagerExc
}

if (!sourceFile.isDirectory()) {

if (!Boolean.parseBoolean(propertiesConfig.getProperty("allowChangeExtensions"))) {
String newFileExt = FileUtils.getExtension(targetName);
String oldFileExt = FileUtils.getExtension(sourceFile.getName());
if (!oldFileExt.equals(newFileExt)) {
return getErrorResponse(dictionnary.getProperty("FORBIDDEN_CHANGE_EXTENSION"));
}
if (!isAllowedFileType(targetName)) {
return getErrorResponse(dictionnary.getProperty("INVALID_FILE_TYPE"));
}
if (!isAllowedFileType(targetName)) {
return getErrorResponse(dictionnary.getProperty("INVALID_FILE_TYPE"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Overrides client-side configuration options (in json file) with the counterparts in the current file.
overrideClientConfig=false

# ------------------------
# General options section
# ------------------------
Expand Down Expand Up @@ -28,15 +25,12 @@ dateFormat=yyyy-MM-dd HH:mm:ss
# Means all capabilities handled by the application are available.
capabilities=select,upload,download,rename,copy,move,replace,delete,edit

# ------------------------
# Security section
# ------------------------

# Allow users to download a Zip archive of a specific folder and contents (including subfolders).
allowFolderDownload=false

# Allow users to change extension when renaming files.
allowChangeExtensions=false
# ------------------------
# Security section
# ------------------------

# If set to "true", allow users to upload file with no extension.
allowNoExtension=false
Expand Down Expand Up @@ -68,11 +62,6 @@ outputFilter_images=jpg,jpe,jpeg,gif,png,svg,bmp
# Upload section
# ------------------------

# The parameter name for the file form data (the request argument name).
# See https://github.com/blueimp/jQuery-File-Upload/wiki/Options#paramname

upload_paramName=files

# The maximum allowed file size (in Bytes). If set to "false", no size limitations applied.
# See https://github.com/blueimp/jQuery-File-Upload/wiki/Options#maxfilesize.
upload_fileSizeLimit=16000000
Expand Down
60 changes: 22 additions & 38 deletions connectors/php/LocalFilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,24 @@ public function initUploader($settings = [])
*/
public function actionInitiate()
{
$shared_config = [];
if($this->config['overrideClientConfig']) {
// config options to override at the client-side
$shared_config = [
'options' => [
'culture' => $this->config['options']['culture'],
'charsLatinOnly' => $this->config['options']['charsLatinOnly'],
'capabilities' => $this->config['options']['capabilities'],
],
'security' => [
'allowFolderDownload' => $this->config['security']['allowFolderDownload'],
'allowChangeExtensions' => $this->config['security']['allowChangeExtensions'],
'allowNoExtension' => $this->config['security']['allowNoExtension'],
'normalizeFilename' => $this->config['security']['normalizeFilename'],
'editRestrictions' => $this->config['security']['editRestrictions'],
],
'upload' => [
'paramName' => $this->config['upload']['paramName'],
'chunkSize' => $this->config['upload']['chunkSize'],
'fileSizeLimit' => $this->config['upload']['fileSizeLimit'],
'policy' => $this->config['upload']['policy'],
'restrictions' => $this->config['upload']['restrictions'],
],
];
}
// config options that affect the client-side
$shared_config = [
'options' => [
'culture' => $this->config['options']['culture'],
'charsLatinOnly' => $this->config['options']['charsLatinOnly'],
'capabilities' => $this->config['options']['capabilities'],
'allowFolderDownload' => $this->config['options']['allowFolderDownload'],
],
'security' => [
'allowNoExtension' => $this->config['security']['allowNoExtension'],
'editRestrictions' => $this->config['security']['editRestrictions'],
],
'upload' => [
'fileSizeLimit' => $this->config['upload']['fileSizeLimit'],
'policy' => $this->config['upload']['policy'],
'restrictions' => $this->config['upload']['restrictions'],
],
];

return [
'id' => '/',
Expand Down Expand Up @@ -231,8 +224,7 @@ public function actionUpload()
])->post(false);

$response_data = [];
$files = isset($content[$this->config['upload']['paramName']]) ?
$content[$this->config['upload']['paramName']] : null;
$files = isset($content['files']) ? $content['files'] : null;
// there is only one file in the array as long as "singleFileUploads" is set to "true"
if ($files && is_array($files) && is_object($files[0])) {
$file = $files[0];
Expand Down Expand Up @@ -323,13 +315,6 @@ public function actionRename()

// check if file extension is consistent to the security Policy settings
if(is_file($old_file)) {
if (!$this->config['security']['allowChangeExtensions']) {
$ext_old = strtolower(pathinfo($old_file, PATHINFO_EXTENSION));
$ext_new = strtolower(pathinfo($new_file, PATHINFO_EXTENSION));
if($ext_old !== $ext_new) {
$this->error(sprintf($this->lang('FORBIDDEN_CHANGE_EXTENSION')));
}
}
if (!$this->is_allowed_file_type($new_file)) {
$this->error(sprintf($this->lang('INVALID_FILE_TYPE')));
}
Expand Down Expand Up @@ -562,7 +547,7 @@ public function actionReplace()
}

// check if the given file has the same extension as the old one
if(strtolower(pathinfo($_FILES[$this->config['upload']['paramName']]['name'], PATHINFO_EXTENSION)) != strtolower(pathinfo($source_path, PATHINFO_EXTENSION))) {
if(strtolower(pathinfo($_FILES['files']['name'], PATHINFO_EXTENSION)) != strtolower(pathinfo($source_path, PATHINFO_EXTENSION))) {
$this->error(sprintf($this->lang('ERROR_REPLACING_FILE') . ' ' . pathinfo($source_path, PATHINFO_EXTENSION)));
}

Expand All @@ -581,8 +566,7 @@ public function actionReplace()
])->post(false);

$response_data = [];
$files = isset($content[$this->config['upload']['paramName']]) ?
$content[$this->config['upload']['paramName']] : null;
$files = isset($content['files']) ? $content['files'] : null;
// there is only one file in the array as long as "singleFileUploads" is set to "true"
if ($files && is_array($files) && is_object($files[0])) {
$file = $files[0];
Expand Down Expand Up @@ -886,7 +870,7 @@ public function actionDownload()

if($is_dir_target) {
// check if permission is granted
if($this->config['security']['allowFolderDownload'] == false ) {
if($this->config['options']['allowFolderDownload'] == false ) {
$this->error(sprintf($this->lang('NOT_ALLOWED')));
}

Expand Down
4 changes: 2 additions & 2 deletions connectors/php/LocalUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function __construct($options = null, $initialize = false, $error_message
$this->fmData = $this->options['fm']['data'];

$this->options['upload_dir'] = $this->fmData['upload_dir'];
$this->options['param_name'] = $this->fm->config['upload']['paramName'];
$this->options['readfile_chunk_size'] = $this->fm->config['upload']['chunkSize'];
$this->options['param_name'] = 'files';
$this->options['readfile_chunk_size'] = 10 * 1024 * 1024;
$this->options['max_file_size'] = $this->fm->config['upload']['fileSizeLimit'];
// BaseFilemanager::is_allowed_file_type() is used instead of this regex check
$this->options['accept_file_types'] = '/.+$/i';
Expand Down
29 changes: 6 additions & 23 deletions connectors/php/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Overrides client-side configuration options (in json file) with the counterparts in the current file.
* @see LocalFilemanager::actionInitiate() for the options map
*/
"overrideClientConfig" => false,
"overrideClientConfig" => true,
/**
* Configure Logger class
*/
Expand Down Expand Up @@ -84,21 +84,16 @@
* For the full list of capabilities @see BaseFilemanager::actions_list
*/
"capabilities" => false,
],
/**
* Security section
*/
"security" => [
/**
* Default value "false".
* Allow users to download a Zip archive of a specific folder and contents (including subfolders).
*/
"allowFolderDownload" => false,
/**
* Default value "false".
* Allow users to change extension when renaming files.
*/
"allowChangeExtensions" => false,
],
/**
* Security section
*/
"security" => [
/**
* Default value "false".
* If set to "true", allow users to upload file with no extension.
Expand Down Expand Up @@ -161,18 +156,6 @@
* Upload section
*/
"upload" => [
/**
* Default value "files".
* The parameter name for the file form data (the request argument name).
* See https://github.com/blueimp/jQuery-File-Upload/wiki/Options#paramname
*/
"paramName" => "files",
/**
* Default value "files". By default files will be uploaded as a whole.
* To upload large files in smaller chunks, set this option to a preferred chunk size (in Bytes).
* See https://github.com/blueimp/jQuery-File-Upload/wiki/Options#maxchunksize
*/
"chunkSize" => false,
/**
* Default value "16000000" (16 MB).
* The maximum allowed file size (in Bytes). If set to "false", no size limitations applied.
Expand Down
Loading

0 comments on commit 758e696

Please sign in to comment.