#9713 ent Problems with the copy button fixed

This commit is contained in:
sergio 2023-02-13 13:58:37 +01:00
parent 6654327a1c
commit b3ca6c78bf
1 changed files with 93 additions and 100 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Images File Manager functions. * Images File Manager functions.
* *
@ -96,7 +97,7 @@ function upload_file($upload_file_or_zip, $default_real_directory, $destination_
check_login(); check_login();
if (! check_acl($config['id_user'], 0, 'AW')) { if (!check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit( db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION, AUDIT_LOG_ACL_VIOLATION,
'Trying to access File manager' 'Trying to access File manager'
@ -139,25 +140,8 @@ function upload_file($upload_file_or_zip, $default_real_directory, $destination_
$nombre_archivo = sprintf('%s/%s', $real_directory, $filename); $nombre_archivo = sprintf('%s/%s', $real_directory, $filename);
try { try {
$mimeContentType = mime_content_type($_FILES['file']['tmp_name']); $mimeContentType = mime_content_type($_FILES['file']['tmp_name']);
$fileExtension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$validFileExtension = true; if (empty($filterFilesType) === true || in_array($mimeContentType, $filterFilesType) === true) {
if (empty($fileExtension) === false) {
$filtered_types = array_filter(
$filterFilesType,
function ($value) use ($fileExtension) {
$mimeTypeExtensionName = explode('/', $value)[1];
return $mimeTypeExtensionName === $fileExtension;
}
);
if (empty($filtered_types) === true) {
$validFileExtension = false;
}
}
if ($validFileExtension === true && (empty($filterFilesType) === true || in_array($mimeContentType, $filterFilesType) === true)) {
$result = copy($_FILES['file']['tmp_name'], $nombre_archivo); $result = copy($_FILES['file']['tmp_name'], $nombre_archivo);
} else { } else {
$error_message = 'The uploaded file is not allowed. Only gif, png or jpg files can be uploaded.'; $error_message = 'The uploaded file is not allowed. Only gif, png or jpg files can be uploaded.';
@ -240,7 +224,7 @@ function create_text_file($default_real_directory, $destination_directory)
check_login(); check_login();
if (! check_acl($config['id_user'], 0, 'AW')) { if (!check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit( db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION, AUDIT_LOG_ACL_VIOLATION,
'Trying to access File manager' 'Trying to access File manager'
@ -310,7 +294,7 @@ if ($create_dir === true) {
$testHash = md5($directory.$config['server_unique_identifier']); $testHash = md5($directory.$config['server_unique_identifier']);
if ($hash !== $testHash) { if ($hash !== $testHash) {
ui_print_error_message(__('Security error.')); ui_print_error_message(__('Security error.'));
} else { } else {
$dirname = filemanager_safe_directory((string) get_parameter('dirname')); $dirname = filemanager_safe_directory((string) get_parameter('dirname'));
@ -366,7 +350,7 @@ if ($delete_file === true) {
} }
} else { } else {
if (unlink($filename) === true) { if (unlink($filename) === true) {
$config['filemanager']['delete'] = 1; $config['filemanager']['delete'] = 1;
} else { } else {
$config['filemanager']['delete'] = 0; $config['filemanager']['delete'] = 0;
} }
@ -516,111 +500,116 @@ function filemanager_file_explorer(
check_opened_dialog('create_folder'); check_opened_dialog('create_folder');
} }
<?php if ($allowCreateText === true) : ?> <?php if ($allowCreateText === true) : ?>
function show_create_text_file() { function show_create_text_file() {
actions_dialog('create_text_file'); actions_dialog('create_text_file');
$("#create_text_file").css("display", "block"); $("#create_text_file").css("display", "block");
check_opened_dialog('create_text_file'); check_opened_dialog('create_text_file');
} }
<?php endif ?> <?php endif ?>
function show_upload_file() { function show_upload_file() {
actions_dialog('upload_file'); actions_dialog('upload_file');
$("#upload_file").css("display", "block"); $("#upload_file").css("display", "block");
check_opened_dialog('upload_file'); check_opened_dialog('upload_file');
} }
function check_opened_dialog(check_opened){ function check_opened_dialog(check_opened) {
if(check_opened !== 'create_folder'){ if (check_opened !== 'create_folder') {
if (($("#create_folder").hasClass("ui-dialog-content") && $('#create_folder').dialog('isOpen') === true)) { if (($("#create_folder").hasClass("ui-dialog-content") && $('#create_folder').dialog('isOpen') === true)) {
$('#create_folder').dialog('close'); $('#create_folder').dialog('close');
} }
} }
<?php if ($allowCreateText === true) : ?> <?php if ($allowCreateText === true) : ?>
if(check_opened !== 'create_text_file'){ if (check_opened !== 'create_text_file') {
if (($("#create_text_file").hasClass("ui-dialog-content") && $('#create_text_file').dialog('isOpen') === true)) { if (($("#create_text_file").hasClass("ui-dialog-content") && $('#create_text_file').dialog('isOpen') === true)) {
$('#create_text_file').dialog('close'); $('#create_text_file').dialog('close');
}
} }
}
<?php endif ?> <?php endif ?>
if(check_opened !== 'upload_file'){ if (check_opened !== 'upload_file') {
if (($("#upload_file").hasClass("ui-dialog-content") && $('#upload_file').dialog('isOpen')) === true) { if (($("#upload_file").hasClass("ui-dialog-content") && $('#upload_file').dialog('isOpen')) === true) {
$('#upload_file').dialog('close'); $('#upload_file').dialog('close');
} }
} }
} }
function actions_dialog(action){ function actions_dialog(action) {
$('.'+action).addClass('file_table_modal_active'); $('.' + action).addClass('file_table_modal_active');
var title_action =''; var title_action = '';
switch (action) { switch (action) {
case 'create_folder': case 'create_folder':
title_action = "<?php echo __('Create a Directory'); ?>"; title_action = "<?php echo __('Create a Directory'); ?>";
break; break;
<?php if ($allowCreateText === true) : ?> <?php if ($allowCreateText === true) : ?>
case 'create_text_file': case 'create_text_file':
title_action = "<?php echo __('Create a Text'); ?>"; title_action = "<?php echo __('Create a Text'); ?>";
break; break;
<?php endif ?> <?php endif ?>
case 'upload_file': case 'upload_file':
title_action = "<?php echo __('Upload Files'); ?>"; title_action = "<?php echo __('Upload Files'); ?>";
break; break;
default: default:
break; break;
} }
$('#'+action) $('#' + action)
.dialog({ .dialog({
title: title_action, title: title_action,
resizable: true, resizable: true,
draggable: true, draggable: true,
modal: true, modal: true,
overlay: { overlay: {
opacity: 0.5, opacity: 0.5,
background: "black" background: "black"
}, },
width: 500, width: 500,
minWidth: 500, minWidth: 500,
minHeight: 210, minHeight: 210,
maxWidth: 800, maxWidth: 800,
maxHeight: 300, maxHeight: 300,
close: function () { close: function() {
$('.'+action).removeClass('file_table_modal_active'); $('.' + action).removeClass('file_table_modal_active');
} }
}).show(); }).show();
} }
function show_modal_real_path (path) { function show_modal_real_path(path) {
if (navigator.clipboard && window.isSecureContext) <?php $secure_con = true; ?>;
else <?php $secure_con = false; ?>;
$('#modal_real_path').addClass('file_table_modal_active'); $('#modal_real_path').addClass('file_table_modal_active');
$('#real_path').empty(); $('#real_path').empty();
$('#real_path').html(path); $('#real_path').html(path);
title_action = "<?php echo __('Real path'); ?>"; title_action = "<?php echo __('Real path'); ?>";
$('#modal_real_path') $('#modal_real_path')
.dialog({ .dialog({
title: title_action, title: title_action,
resizable: true, resizable: true,
draggable: true, draggable: true,
modal: true, modal: true,
overlay: { overlay: {
opacity: 0.5, opacity: 0.5,
background: "black" background: "black"
}, },
width: 448, width: 448,
minWidth: 448, minWidth: 448,
minHeight: 213, minHeight: 213,
maxWidth: 800, maxWidth: 800,
maxHeight: 300, maxHeight: 300,
close: function () { close: function() {
$('#modal_real_path').removeClass('file_table_modal_active'); $('#modal_real_path').removeClass('file_table_modal_active');
} }
}).show(); }).show();
$("#submit-submit").on("click",copyToClipboard); $("#submit-submit").on("click", copyToClipboard);
} }
function copyToClipboard() { function copyToClipboard() {
navigator.clipboard.writeText($("#real_path").text()).then(function (){ if (navigator.clipboard && window.isSecureContext) {
$('#modal_real_path').dialog('close'); window.navigator.clipboard.writeText($("#real_path").text()).then(function() {
}); $('#modal_real_path').dialog('close');
});
}
} }
</script> </script>
<?php <?php
@ -737,9 +726,9 @@ function filemanager_file_explorer(
if (pathinfo($fileinfo['realpath'], PATHINFO_EXTENSION) === 'php' if (pathinfo($fileinfo['realpath'], PATHINFO_EXTENSION) === 'php'
&& (is_readable($fileinfo['realpath']) === true || is_executable($fileinfo['realpath']) === true) && (is_readable($fileinfo['realpath']) === true || is_executable($fileinfo['realpath']) === true)
) { ) {
$error_message = __('This file could be executed by any user'); $error_message = __('This file could be executed by any user');
$error_message .= '. '.__('Make sure it can\'t perform dangerous tasks'); $error_message .= '. '.__('Make sure it can\'t perform dangerous tasks');
$data[1] = '<span class="error forced_title" data-title="'.$error_message.'" data-use_title_for_force_title="1">'.$data[1].'</span>'; $data[1] = '<span class="error forced_title" data-title="'.$error_message.'" data-use_title_for_force_title="1">'.$data[1].'</span>';
} }
$data[2] = ui_print_timestamp( $data[2] = ui_print_timestamp(
@ -753,11 +742,11 @@ function filemanager_file_explorer(
$data[3] = ui_format_filesize($fileinfo['size']); $data[3] = ui_format_filesize($fileinfo['size']);
} }
// Actions buttons // Actions buttons
// Delete button. // Delete button.
$data[4] = ''; $data[4] = '';
$data[4] .= '<span style="display: flex">'; $data[4] .= '<span style="display: flex">';
$typefile = array_pop(explode('.', $fileinfo['name'])); $typefile = array_pop(explode('.', $fileinfo['name']));
if (is_writable($fileinfo['realpath']) === true if (is_writable($fileinfo['realpath']) === true
&& (is_dir($fileinfo['realpath']) === false || count(scandir($fileinfo['realpath'])) < 3) && (is_dir($fileinfo['realpath']) === false || count(scandir($fileinfo['realpath'])) < 3)
&& ($readOnly === false) && ($readOnly === false)
@ -805,9 +794,9 @@ function filemanager_file_explorer(
$data[4] .= '<a href="javascript: show_modal_real_path(`'.$fileinfo['realpath'].'`);">'.html_print_image('images/book_edit.png', true, ['style' => 'margin-top: 2px;', 'title' => __('Real path'), 'class' => 'invert_filter']).'</a>'; $data[4] .= '<a href="javascript: show_modal_real_path(`'.$fileinfo['realpath'].'`);">'.html_print_image('images/book_edit.png', true, ['style' => 'margin-top: 2px;', 'title' => __('Real path'), 'class' => 'invert_filter']).'</a>';
} }
$data[4] .= '</span>'; $data[4] .= '</span>';
array_push($table->data, $data); array_push($table->data, $data);
} }
} else { } else {
ui_print_info_message( ui_print_info_message(
@ -900,7 +889,7 @@ function filemanager_file_explorer(
'content' => html_print_input_file( 'content' => html_print_input_file(
'file', 'file',
true, true,
[ 'style' => 'border:0; padding:0; width:100%' ] ['style' => 'border:0; padding:0; width:100%']
), ),
], ],
true true
@ -985,8 +974,12 @@ function filemanager_file_explorer(
// Show Modal Real Path // Show Modal Real Path
$modal_real_path = "<div><b>Real path to plugin execution is:</b></div> $modal_real_path = "<div><b>Real path to plugin execution is:</b></div>
<div id='real_path'></div> <div id='real_path'></div>";
<div style='float:right;margin: 5em 0 0 auto';>".html_print_submit_button(__('Copy'), 'submit', false, 'class="sub next"', true).'</div>';
if (isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '127.0.0.1') {
$modal_real_path .= "<div style='float:right;margin: 5em 0 0 auto';>".html_print_submit_button(__('Copy'), 'submit', false, 'class="sub next"', true).'</div>';
}
html_print_div( html_print_div(
[ [
'id' => 'modal_real_path', 'id' => 'modal_real_path',
@ -1141,4 +1134,4 @@ function filemanager_safe_directory(
} }
return $directory; return $directory;
} }