diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 78b9c8d552..f4d9b358a2 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -105,6 +105,8 @@ enterprise_include_once ('meta/include/functions_components_meta.php'); $view = get_parameter ("view", ""); $create = get_parameter ("create", ""); $filemanager = (bool)get_parameter("filemanager", false); +$edit_file = get_parameter("edit_file",false); +$update_file = get_parameter("update_file",false); $plugin_command = get_parameter('plugin_command', ''); $tab = get_parameter('tab', ''); @@ -142,57 +144,102 @@ if ($create != "") { // INIT FILEMANAGER // ===================================================================== if ($filemanager) { - - $id_plugin = (int)get_parameter('id_plugin', 0); - - - /* Add custom directories here */ - $fallback_directory = "attachment/plugin"; - - $directory = (string) get_parameter ('directory', $fallback_directory); - $directory = str_replace("\\", "/", $directory); - - // A miminal security check to avoid directory traversal - if (preg_match ("/\.\./", $directory)) - $directory = $fallback_directory; - if (preg_match ("/^\//", $directory)) - $directory = $fallback_directory; - if (preg_match ("/^manager/", $directory)) - $directory = $fallback_directory; - - $banned_directories['include'] = true; - $banned_directories['godmode'] = true; - $banned_directories['operation'] = true; - $banned_directories['reporting'] = true; - $banned_directories['general'] = true; - $banned_directories[ENTERPRISE_DIR] = true; - - if (isset ($banned_directories[$directory])) - $directory = $fallback_directory; - - $real_directory = realpath ($config['homedir'] . '/' . $directory); - - echo '

' . __('Index of %s', $directory) . '

'; - - $chunck_url = '&view=' . $id_plugin; - if ($id_plugin == 0) { - $chunck_url = '&create=1'; + if($edit_file) { + $location_file = get_parameter("location_file",''); + $filename = array_pop(explode("/",$location_file)); + $file = file_get_contents($location_file); + echo "

" . __("Edit file") ." ".$filename. "

"; + //echo "" . __('Back to file explorer') . ""; + echo "
"; + //html_print_input_hidden('location_file', $locationFile); + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "
" . __('Edit') . "
"; + echo ""; + echo "
"; + html_print_input_hidden('location_file', $location_file); + + echo __('Compatibility mode').":"; + $options = array('unix' => 'Unix', 'windows' => 'Windows'); + html_print_select($options, 'compatibility', $compatibility); + echo " "; + echo "
"; + echo "
"; + }else { + + if($update_file){ + $location_file = get_parameter("location_file",''); + $contentFile = io_safe_output(get_parameter('content_file', '')); + $compatibility = get_parameter('compatibility', 'unix'); + $is_win_compatible = strpos($contentFile, "\r\n"); + // If is win compatible and the compatibility must be unix + if ($is_win_compatible !== false && $compatibility == 'unix') { + $contentFile = str_replace("\r\n", "\n", $contentFile); + } + // If is unix compatible and the compatibility must be win + else if ($is_win_compatible === false && $compatibility == 'windows') { + $contentFile = str_replace("\n", "\r\n", $contentFile); + } + $result = file_put_contents($location_file, $contentFile); + + } + $id_plugin = (int)get_parameter('id_plugin', 0); + + /* Add custom directories here */ + $fallback_directory = "attachment/plugin"; + + $directory = (string) get_parameter ('directory', $fallback_directory); + $directory = str_replace("\\", "/", $directory); + + // A miminal security check to avoid directory traversal + if (preg_match ("/\.\./", $directory)) + $directory = $fallback_directory; + if (preg_match ("/^\//", $directory)) + $directory = $fallback_directory; + if (preg_match ("/^manager/", $directory)) + $directory = $fallback_directory; + + $banned_directories['include'] = true; + $banned_directories['godmode'] = true; + $banned_directories['operation'] = true; + $banned_directories['reporting'] = true; + $banned_directories['general'] = true; + $banned_directories[ENTERPRISE_DIR] = true; + + if (isset ($banned_directories[$directory])) + $directory = $fallback_directory; + + $real_directory = realpath ($config['homedir'] . '/' . $directory); + + echo '

' . __('Index of %s', $directory) . '

'; + + $chunck_url = '&view=' . $id_plugin; + if ($id_plugin == 0) { + $chunck_url = '&create=1'; + } + + $homedir_filemanager = isset ($config['homedir_filemanager']) ? $config['homedir_filemanager'] : false; + filemanager_file_explorer($real_directory, + $directory, + 'index.php?sec=gservers&sec2=godmode/servers/plugin&filemanager=1&id_plugin=' . $id_plugin, + $fallback_directory, + true, + false, + 'index.php?sec=gservers&sec2=godmode/servers/plugin' . $chunck_url . '&plugin_command=[FILE_FULLPATH]&id_plugin=' . $id_plugin, + true, + 0775, + $homedir_filemanager); } - - $homedir_filemanager = isset ($config['homedir_filemanager']) ? $config['homedir_filemanager'] : false; - - filemanager_file_explorer($real_directory, - $directory, - 'index.php?sec=gservers&sec2=godmode/servers/plugin&filemanager=1&id_plugin=' . $id_plugin, - $fallback_directory, - false, - false, - 'index.php?sec=gservers&sec2=godmode/servers/plugin' . $chunck_url . '&plugin_command=[FILE_FULLPATH]&id_plugin=' . $id_plugin, - true, - 0775, - $homedir_filemanager); - - return; } diff --git a/pandora_console/include/functions_filemanager.php b/pandora_console/include/functions_filemanager.php index d638b15afb..0f6e0e955b 100644 --- a/pandora_console/include/functions_filemanager.php +++ b/pandora_console/include/functions_filemanager.php @@ -733,6 +733,7 @@ function filemanager_file_explorer($real_directory, $relative_directory, //Delete button $data[4] = ''; $data[4] .= ''; + $typefile = array_pop(explode(".",$fileinfo['name'])); if (is_writable ($fileinfo['realpath']) && (! is_dir ($fileinfo['realpath']) || count (scandir ($fileinfo['realpath'])) < 3)) { $data[4] .= '
'; @@ -752,14 +753,14 @@ function filemanager_file_explorer($real_directory, $relative_directory, $data[4] .= '
'; if (($editor) && (!$readOnly)) { - if ($fileinfo['mime'] == MIME_TEXT) { - $data[4] .= "" . html_print_image('images/edit.png', true, array("style" => 'margin-top: 2px;', 'title' => __('Edit file'))) . ""; + if (($typefile == 'sh') || ($typefile == 'pl') || ($typefile == 'vbs')) { + $data[4] .= "" . html_print_image('images/edit.png', true, array("style" => 'margin-top: 2px;', 'title' => __('Edit file'))) . ""; } } } if ((!$fileinfo['is_dir']) && ($download_button)) { - $hash = md5($fileinfo['url'] . $config['dbpass']); - $data[4] .= ''; + $hash = md5($fileinfo['realpath'] . $config['dbpass']); + $data[4] .= ''; $data[4] .= html_print_image('images/file.png', true); $data[4] .= ''; }