Skip to content
This repository has been archived by the owner on Feb 14, 2020. It is now read-only.

Commit

Permalink
Remove file upload as a valid metadatafield type, fixes #547 and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy Baukema committed Dec 18, 2014
1 parent e6c08c0 commit 7488446
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 1,323 deletions.
27 changes: 0 additions & 27 deletions app/config-dist/config_janus_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ janus_service_registry_core:
validate: leneq40
supported:
- 0
certificate:
type: file
filetype: '*.pem'
maxsize: '3 M'
required: false

# Information fields
'name:#':
Expand All @@ -249,10 +244,6 @@ janus_service_registry_core:
supported:
- en
- da
icon:
type: file
filetype: '*.jpg' # *.jpg; *.gif; *.*
maxsize: '100' # Valid units are B, KB, MB, and GB. The default unit is KB.

# Contact person fields
'contacts:#:contactType':
Expand Down Expand Up @@ -381,11 +372,6 @@ janus_service_registry_core:
validate: leneq40
supported:
- 0
certificate:
type: file
filetype: '*.pem'
maxsize: '3 M' # Valid units are B, KB, MB, and GB. The default unit is KB
required: false # *.jpg; *.gif; *.*

# Information fields
'name:#':
Expand All @@ -409,10 +395,6 @@ janus_service_registry_core:
supported:
- en
- da
icon:
type: file
filetype: '*.jpg' # *.jpg; *.gif; *.*
maxsize: '100' # Valid units are B, KB, MB, and GB. The default unit is KB.

# Contact person fields
'contacts:#:contactType':
Expand Down Expand Up @@ -591,11 +573,6 @@ janus_service_registry_core:
validate: leneq40
supported:
- 0
certificate:
type: file
filetype: '*.pem'
maxsize: '3 M' # Valid units are B, KB, MB, and GB. The default unit is KB.
required: false

# Information fields
'name:#':
Expand All @@ -619,10 +596,6 @@ janus_service_registry_core:
supported:
- en
- da
icon:
type: file
filetype: '*.jpg' # *.jpg; *.gif; *.*
maxsize: '100' # Valid units are B, KB, MB, and GB. The default unit is KB.

# Contact person fields
'contacts:#:contactType':
Expand Down
4 changes: 0 additions & 4 deletions lib/MetadataField.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ protected function _initOptions($options)
);

switch($options['type']) {
case 'file':
$this->_allowed_options[] = 'filetype';
$this->_allowed_options[] = 'maxsize';
break;
case 'select':
$this->_allowed_options[] = 'select_values';
break;
Expand Down
70 changes: 0 additions & 70 deletions templates/editentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'module.php/janus/resources/components/jquery/jquery.min.js"></script>' . "\n";
$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'module.php/janus/resources/components/jqueryui/ui/minified/jquery-ui.custom.min.js"></script>' . "\n";
$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'module.php/janus/resources/scripts/swfupload.js"></script>' . "\n";
$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'module.php/janus/resources/scripts/jquery-asyncUpload-0.1.js"></script>' . "\n";
$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'module.php/janus/resources/scripts/json2-min.js"></script>'."\n";
$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'module.php/janus/resources/scripts/jquery.tmpl.min.js"></script>'."\n";
$this->data['head'] .= '<script type="text/javascript" src="/' . $this->data['baseurlpath'] . 'module.php/janus/resources/scripts/datehelper.js"></script>'."\n";
Expand Down Expand Up @@ -372,35 +370,7 @@ function changeId(elm) {
select_html.options[select_html.length] = new Option(select_values[i], select_values[i]);
}
}
}
break;
case 'file':
$('<input type="file" name="meta_value[' + index + ']" id="meta_value[' + index + ']" />').appendTo(makker);
var config = {
upload_url: '/<?php echo $this->data['baseurlpath']; ?>module.php/janus/AJAXRequestHandler.php',
flash_url: '/<?php echo $this->data['baseurlpath']; ?>module.php/janus/resources/scripts/swfupload.swf',
button_image_url: '/<?php echo $this->data['baseurlpath']; ?>module.php/janus/resources/scripts/blankButton.png',
existingFilename: metadata[index]["default"],
disableDuringUpload: "INPUT[type=submit]",
button_text: "<font face=\"Arial\" size=\"13pt\"><?php echo $this->t('choose_file'); ?></font>",
post_params: {
"PHPSESSID" : "<?php echo $this->cookie_name; ?>",
"SimpleSAMLAuthToken" : "<?php echo isset($_COOKIE['SimpleSAMLAuthToken']) ? $_COOKIE['SimpleSAMLAuthToken'] : ''; ?>",
"func" : "uploadFile",
"eid" : "<?php echo $this->data['entity']->getEid(); ?>",
"index" : "meta_value[" + index + "]"
}
};

if(metadata[index]["filetype"] !== undefined) {
config.file_types = metadata[index]["filetype"];
}

if(metadata[index]["maxsize"] !== undefined) {
config.file_size_limit = metadata[index]["maxsize"];
}

$("input:file[name=meta_value[" + index + "]]").makeAsyncUploader(config);
break;
default:
$('<input type="text" name="meta_value[' + index + ']" class="width_100" value="' + metadata[index]["default"] + '" onfocus="this.value=\'\';" />').appendTo(makker);
Expand Down Expand Up @@ -603,46 +573,6 @@ class="display_none"
}
}
break;
case 'file':
if($modifymetadata == 'readonly="readonly"') {
echo '<input class="width_100" type="text" name="edit-metadata-'. htmlspecialchars($data->getKey()) .'" value="' . htmlspecialchars($data->getValue()) .'" ' . $modifymetadata . ' />';
} else {
echo '<input type="file" name="edit-metadata-'. $data->getKey() .'" id="edit-metadata-'. $data->getKey() .'" />';
echo '<script type="text/javascript">
<!--
$("input:file[name=edit-metadata-'. $data->getKey() .']").makeAsyncUploader({
upload_url: "/'. $this->data['baseurlpath'] .'module.php/janus/AJAXRequestHandler.php",
flash_url: "/'. $this->data['baseurlpath'] .'module.php/janus/resources/scripts/swfupload.swf",
button_image_url: "/'. $this->data['baseurlpath'] .'module.php/janus/resources/scripts/blankButton.png",
existingFilename: "' . $data->getValue() . '",
disableDuringUpload: "INPUT[type=submit]",
button_text: "<font face=\"Arial\" size=\"13pt\">'. $this->t('choose_file') .'</font>",';
if(isset($metadata_field->maxsize)) {
echo 'file_size_limit: "' . $metadata_field->maxsize . '",' . "\n";
}
if(isset($metadata_field->filetype)) {
echo 'file_types: "' . $metadata_field->filetype . '",' . "\n";
}
echo 'post_params: {
"PHPSESSID" : "'. $this->cookie_name .'",
"SimpleSAMLAuthToken" : "'. (isset($_COOKIE['SimpleSAMLAuthToken'])?$_COOKIE['SimpleSAMLAuthToken']:'') .'",
"func" : "uploadFile",
"eid" : "'. $this->data['entity']->getEid() .'",
"index" : "edit-metadata-'. $data->getKey() .'"
},
swfupload_loaded_handler : function() {
var elm = $("#edit-metadata-'. $data->getKey() .'_completedMessage");
elm.css("text-decoration", "underline");
elm.css("cursor", "pointer");
elm.click(function() {
window.open(encodeURI("/'. $this->data['baseurlpath'] .'module.php/janus/previewfile.php?eid=' . $this->data['entity']->getEid() . '&file=' . $data->getValue() . '"), "Preview", "location=no, scrollbars=yes, resizable=yes, toolbar=no, menubar=no");
});
}
});
-->
</script>';
}
break;
default:
$validate = isset($metadata_field->validate) ? 'onkeyup="validateInput(this, \'' . $metadata_field->validate . '\');"' : '';
echo '<input class="width_100" type="text" name="edit-metadata-'. $data->getKey() .'" value="' . htmlspecialchars($data->getValue()) .'" ' . $modifymetadata . ' ' . $validate . ' />';
Expand Down
58 changes: 0 additions & 58 deletions www/AJAXRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function checkEntityPermission($janus_config, $params)
}

$ALLOWED_FUNCTIONS = array(
'uploadFile',
'getARP',
'validateMetadataField',
'markAsRead',
Expand Down Expand Up @@ -158,63 +157,6 @@ function checkEntityPermission($janus_config, $params)
// Handle GET requests
}

function file_upload_error_message($error_code) {
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
return 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
case UPLOAD_ERR_FORM_SIZE:
return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
case UPLOAD_ERR_PARTIAL:
return 'The uploaded file was only partially uploaded';
case UPLOAD_ERR_NO_FILE:
return 'No file was uploaded';
case UPLOAD_ERR_NO_TMP_DIR:
return 'Missing a temporary folder';
case UPLOAD_ERR_CANT_WRITE:
return 'Failed to write file to disk';
case UPLOAD_ERR_EXTENSION:
return 'File upload stopped by extension';
default:
return 'Unknown upload error';
}
}

function uploadFile($params) {
if(!isset($params['eid']))
return FALSE;

if(!isset($params['index']))
return FALSE;

$janus_config = sspmod_janus_DiContainer::getInstance()->getConfig();
$uploaddir = $janus_config->getString('metadatafields.uploadpath') . $params['eid'];

$return = Array();

if(!file_exists($uploaddir)) {
if(!@mkdir($uploaddir)) {
$return['status'] = 'error_noupload';
$return['error_message'] = 'Could not create upload directory';
}
}

$uploadFileName = time() . '_' . basename($_FILES['Filedata']['name']);
$uploadfile = $uploaddir . '/' . $uploadFileName;

if (@move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadfile)) {
$return['newfilename'] = $uploadFileName;
$return['status'] = 'success';
} else {
$return['status'] = 'error_noupload';
$return['error_code'] = $_FILES['Filedata']['error'];
$return['error_message'] = file_upload_error_message($_FILES['Filedata']['error']);
}

$return['index'] = $params['index'];

return $return;
}

function getARP($params) {
if(!isset($params['aid'])) {
return false;
Expand Down
47 changes: 0 additions & 47 deletions www/previewfile.php

This file was deleted.

Loading

0 comments on commit 7488446

Please sign in to comment.