diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 05fabc831f..7cb50d8873 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-06-27 Miguel de Dios + + * godmode/servers/plugin.php, godmode/setup/file_manager.php, + include/functions_filemanager.php: added the filemanager to server + plugin, and of course change the code for to make this feature. + + MERGED FROM THE BRANCH PANDORA_4_0 + 2013-06-26 Miguel de Dios * extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql, diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index f6c3a78423..2ea6652512 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -29,6 +29,8 @@ if (is_ajax ()) { // Load global vars global $config; +require_once ("include/functions_filemanager.php"); + check_login (); if (! check_acl ($config['id_user'], 0, "LM")) { @@ -42,6 +44,8 @@ enterprise_include_once ('meta/include/functions_components_meta.php'); $view = get_parameter ("view", ""); $create = get_parameter ("create", ""); +$filemanager = (bool)get_parameter("filemanager", false); +$plugin_command = get_parameter('plugin_command', ''); if ($view != "") { $form_id = $view; @@ -50,26 +54,89 @@ if ($view != "") { $form_description = $plugin["description"]; $form_max_timeout = $plugin ["max_timeout"]; $form_max_retries = $plugin ["max_retries"]; - $form_execute = $plugin ["execute"]; + if (empty($plugin_command)) + $form_execute = $plugin ["execute"]; + else + $form_execute = $plugin_command; $form_plugin_type = $plugin ["plugin_type"]; $macros = $plugin ["macros"]; $parameters = $plugin ["parameters"]; } if ($create != "") { + $form_id = 0; $form_name = ""; $form_description = ""; $form_max_timeout = 15; $form_max_retries = 1; - $form_execute = ""; + $form_execute = $plugin_command; $form_plugin_type = 0; $form_parameters = ""; $macros = ""; $parameters = ""; } +//END LOAD VALUES + +// ===================================================================== +// 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); + + // 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'; + } + + 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); + + + return; +} + +// ===================================================================== +// END FILEMANAGER +// ===================================================================== // SHOW THE FORM -// ================================================================= +// ===================================================================== $sec = 'gservers'; @@ -168,6 +235,9 @@ if (($create != "") OR ($view != "")) { if ($locked) { $data[1] .= html_print_image('images/lock.png', true, array('class' => 'command_advanced_conf')); } + $data[1] .= ' '; + $data[1] .= html_print_image('images/file.png', true); + $data[1] .= ''; $table->data['plugin_command'] = $data; $data = array(); @@ -305,7 +375,7 @@ else { } enterprise_hook('open_meta_frame'); - + // Update plugin if (isset($_GET["update_plugin"])) { // if modified any parameter $plugin_id = get_parameter ("update_plugin", 0); @@ -419,7 +489,7 @@ else { $plugin_id = get_parameter ("kill_plugin", 0); $result = db_process_sql_delete('tplugin', array('id' => $plugin_id)); - + if (! $result) { ui_print_error_message(__('Problem deleting plugin')); } @@ -441,14 +511,14 @@ else { if ($rows !== false) { echo ''; - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; echo ""; $color = 0; foreach ($rows as $row) { - if ($color == 1){ + if ($color == 1) { $tdcolor = "datos"; $color = 0; } diff --git a/pandora_console/godmode/setup/file_manager.php b/pandora_console/godmode/setup/file_manager.php index 9529aad2f7..a09f0b865a 100644 --- a/pandora_console/godmode/setup/file_manager.php +++ b/pandora_console/godmode/setup/file_manager.php @@ -57,12 +57,11 @@ $banned_directories[ENTERPRISE_DIR] = true; if (isset ($banned_directories[$directory])) $directory = $fallback_directory; -// Current directory -$available_directories[$directory] = $directory; - $real_directory = realpath ($config['homedir'] . '/' . $directory); echo '

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

'; -filemanager_file_explorer($real_directory, $directory, 'index.php?sec=gsetup&sec2=godmode/setup/file_manager'); +filemanager_file_explorer($real_directory, + $directory, + 'index.php?sec=gsetup&sec2=godmode/setup/file_manager'); ?> diff --git a/pandora_console/include/functions_filemanager.php b/pandora_console/include/functions_filemanager.php index 8f9fcd0067..927960f0eb 100644 --- a/pandora_console/include/functions_filemanager.php +++ b/pandora_console/include/functions_filemanager.php @@ -151,6 +151,7 @@ if ($upload_file) { $filesize = $_FILES['file']['size']; $real_directory = (string) get_parameter('real_directory'); $directory = (string) get_parameter ('directory'); + $umask = (string)get_parameter('umask', ''); $hash = get_parameter('hash', ''); $testHash = md5($real_directory . $directory . $config['dbpass']); @@ -172,6 +173,10 @@ if ($upload_file) { $config['filemanager']['message'] = ui_print_error_message(__('Upload error'), '', true); } else { + if ($umask !== '') { + chmod($nombre_archivo, $umask); + } + $config['filemanager']['correct_upload_file'] = 1; $config['filemanager']['message'] = ui_print_success_message(__('Upload correct'), '', true); @@ -208,6 +213,7 @@ if ($create_text_file) { $real_directory = io_safe_output($real_directory); $directory = (string) get_parameter ('directory'); $directory = io_safe_output($directory); + $umask = (string)get_parameter('umask', ''); $hash = get_parameter('hash', ''); $testHash = md5($real_directory . $directory . $config['dbpass']); @@ -228,6 +234,10 @@ if ($create_text_file) { $config['filemanager']['message'] = ui_print_error_message(__('Error creating file'), '', true); } else { + if ($umask !== '') { + chmod($nombre_archivo, $umask); + } + $config['filemanager']['message'] = ui_print_success_message(__('Upload correct'), '', true); $config['filemanager']['correct_upload_file'] = 1; } @@ -403,12 +413,10 @@ function filemanager_read_recursive_dir($dir, $relative_path = '') { { while (false !== ($entry = readdir($handle))) { if (($entry != ".") && ($entry != "..")) { - if (is_dir($dir . $entry)) - { + if (is_dir($dir . $entry)) { $return = array_merge($return, filemanager_read_recursive_dir($dir . $entry . '/', $relative_path . $entry . '/' )); } - else - { + else { $return[] = array('relative' => $relative_path . $entry, 'absolute' => $dir . $entry); } } @@ -427,8 +435,11 @@ function filemanager_read_recursive_dir($dir, $relative_path = '') { * @param string $url The url to set in the forms and some links in the explorer. * @param string $father The directory father don't navigate bottom this. * @param boolean $editor The flag to set the edition of text files. + * @param string $url_file The url to put in the files instead the default. By default empty string and use the url of filemanager. + * @param boolean $download_button The flag to show download button, by default false. + * @param string $umask The umask as hex values to set the new files or updload. */ -function filemanager_file_explorer($real_directory, $relative_directory, $url, $father = '', $editor = false, $readOnly = false) { +function filemanager_file_explorer($real_directory, $relative_directory, $url, $father = '', $editor = false, $readOnly = false, $url_file = '', $download_button = false, $umask = '') { global $config; $hack_metaconsole = ''; @@ -437,34 +448,33 @@ function filemanager_file_explorer($real_directory, $relative_directory, $url, $ ?> data[1][1] .= ''; $table->data[1][1] .= ui_print_help_tip (__("The zip upload in this dir, easy to upload multiple files."), true); $table->data[1][1] .= html_print_input_file ('file', true, false); + $table->data[1][1] .= html_print_input_hidden('umask', $umask, true); $table->data[1][1] .= html_print_checkbox('decompress', 1, false, true); $table->data[1][1] .= __('Decompress'); $table->data[1][1] .= '   '; @@ -557,8 +568,9 @@ function filemanager_file_explorer($real_directory, $relative_directory, $url, $ $table->data[1][1] .= html_print_input_hidden ('real_directory', $real_directory, true); $table->data[1][1] .= html_print_input_hidden ('directory', $relative_directory, true); $table->data[1][1] .= html_print_input_hidden('hash', md5($real_directory . $relative_directory . $config['dbpass']), true); + $table->data[1][1] .= html_print_input_hidden('umask', $umask, true); $table->data[1][1] .= html_print_input_hidden ('create_text_file', 1, true); - $table->data[1][1] .= ''; + $table->data[1][1] .= ''; $table->data[1][1] .= ''; $table->colspan[1][1] =5; @@ -590,6 +602,12 @@ function filemanager_file_explorer($real_directory, $relative_directory, $url, $ if ($fileinfo['is_dir']) { $data[1] = ''.$fileinfo['name'].''; } + else if (!empty($url_file)) { + //Set the custom url file + $url_file_clean = str_replace('[FILE_FULLPATH]', $fileinfo['realpath'], $url_file); + + $data[1] = '' . $fileinfo['name'] . ''; + } else { $hash = md5($relative_path . $config['dbpass']); $data[1] = ''.$fileinfo['name'].''; @@ -631,8 +649,14 @@ function filemanager_file_explorer($real_directory, $relative_directory, $url, $ } } } + if ((!$fileinfo['is_dir']) && ($download_button)) { + $hash = md5($fileinfo['url'] . $config['dbpass']); + $data[4] .= ''; + $data[4] .= html_print_image('images/file.png', true); + $data[4] .= ''; + } $data[4] .= ''; - + array_push ($table->data, $data); } @@ -641,13 +665,13 @@ function filemanager_file_explorer($real_directory, $relative_directory, $url, $ echo "
"; echo ""; echo html_print_image('images/mimetypes/directory.png', true, array("title" => __('Create directory'))); - echo " "; + echo ""; echo ""; echo html_print_image('images/mimetypes/text.png', true, array("title" => __('Create text'))); - echo " "; + echo ""; echo ""; echo html_print_image('images/mimetypes/unknown.png', true, array("title" => __('Upload file/s'))); - echo " "; + echo ""; echo "
"; } else {
".__('Name')."".__('Type')."".__('Command')."" . __('Name') . "" . __('Type') . "" . __('Command') . "" . '' . __('Op.') . '' . "