2010-07-07 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_filemanager.php: added const MIME_TEXT. added source code to handler the updload files, zips, delete files/dir and create text files. Added function "delete_directory" for to delete recursive and or not empty any dir, function "file_explorer" to show a file explorer, "box_upload_file_complex" to show a controls to upload file or multiple files in a zip, "box_upload_file_explorer" to show controls to upload file, "box_upload_zip_explorer" to show controls to upload multiple files in a zip, "box_create_text_explorer" to show controls to create text files, and in function "get_file_manager_file_info" use new const MIME_TEXT. * godmode/agentes/modificar_agente.php: cleaned source code, closed the <tr> tag. * godmode/agentes/configurar_agente.php: added hook to enterprise functions for collection. * godmode/menu.php: added hook to enterprise functions for collection. * godmode/setup/file_manager.php:changed the source code for use new modular functions to show and management files. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2969 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
a8cbe503ef
commit
8eb5863007
|
@ -1,3 +1,26 @@
|
||||||
|
2010-07-07 Miguel de Dios <miguel.dedios@artica.es>
|
||||||
|
|
||||||
|
* include/functions_filemanager.php: added const MIME_TEXT. added source
|
||||||
|
code to handler the updload files, zips, delete files/dir and create text
|
||||||
|
files. Added function "delete_directory" for to delete recursive and or
|
||||||
|
not empty any dir, function "file_explorer" to show a file explorer,
|
||||||
|
"box_upload_file_complex" to show a controls to upload file or multiple
|
||||||
|
files in a zip, "box_upload_file_explorer" to show controls to upload
|
||||||
|
file, "box_upload_zip_explorer" to show controls to upload multiple files
|
||||||
|
in a zip, "box_create_text_explorer" to show controls to create text files,
|
||||||
|
and in function "get_file_manager_file_info" use new const MIME_TEXT.
|
||||||
|
|
||||||
|
* godmode/agentes/modificar_agente.php: cleaned source code, closed the <tr>
|
||||||
|
tag.
|
||||||
|
|
||||||
|
* godmode/agentes/configurar_agente.php: added hook to enterprise functions
|
||||||
|
for collection.
|
||||||
|
|
||||||
|
* godmode/menu.php: added hook to enterprise functions for collection.
|
||||||
|
|
||||||
|
* godmode/setup/file_manager.php:changed the source code for use new modular
|
||||||
|
functions to show and management files.
|
||||||
|
|
||||||
2010-07-05 Raúl Mateos <raulofpandora@gmail.com>
|
2010-07-05 Raúl Mateos <raulofpandora@gmail.com>
|
||||||
|
|
||||||
* include/functions.php, include/functions_reporting.php: Cleaned code.
|
* include/functions.php, include/functions_reporting.php: Cleaned code.
|
||||||
|
|
|
@ -226,7 +226,8 @@ if ($id_agente) {
|
||||||
echo '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=template&id_agente='.$id_agente.'">';
|
echo '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=template&id_agente='.$id_agente.'">';
|
||||||
echo "<img src='images/network.png' class='top' title='".__('Module templates')."'> </a></li>";
|
echo "<img src='images/network.png' class='top' title='".__('Module templates')."'> </a></li>";
|
||||||
|
|
||||||
enterprise_hook ('inventory_tab');
|
enterprise_hook('inventory_tab');
|
||||||
|
enterprise_hook('collection_tab');
|
||||||
|
|
||||||
echo '<li class="nomn">';
|
echo '<li class="nomn">';
|
||||||
echo '<a href="index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&ag_group='.$group.'">';
|
echo '<a href="index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&ag_group='.$group.'">';
|
||||||
|
|
|
@ -99,7 +99,7 @@ echo '<form method="post" action="index.php?sec=gagente&sec2=godmode/agentes
|
||||||
print_submit_button (__('Create agent'), 'crt', false, 'class="sub next"');
|
print_submit_button (__('Create agent'), 'crt', false, 'class="sub next"');
|
||||||
echo "</form>";
|
echo "</form>";
|
||||||
|
|
||||||
echo "</td></table>";
|
echo "</td></tr></table>";
|
||||||
|
|
||||||
$search_sql = '';
|
$search_sql = '';
|
||||||
if ($search != ""){
|
if ($search != ""){
|
||||||
|
|
|
@ -39,6 +39,7 @@ if (give_acl ($config['id_user'], 0, "AW")) {
|
||||||
|
|
||||||
$sub["godmode/agentes/planned_downtime"]["text"] = __('Scheduled downtime');
|
$sub["godmode/agentes/planned_downtime"]["text"] = __('Scheduled downtime');
|
||||||
}
|
}
|
||||||
|
enterprise_hook('agents_submenu');
|
||||||
|
|
||||||
$menu["gagente"]["sub"] = $sub;
|
$menu["gagente"]["sub"] = $sub;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,53 +26,53 @@ if (! give_acl ($config['id_user'], 0, "PM")) {
|
||||||
|
|
||||||
require_once ("include/functions_filemanager.php");
|
require_once ("include/functions_filemanager.php");
|
||||||
|
|
||||||
$delete_file = (bool) get_parameter ('delete_file');
|
//$delete_file = (bool) get_parameter ('delete_file');
|
||||||
$upload_file = (bool) get_parameter ('upload_file');
|
//$upload_file = (bool) get_parameter ('upload_file');
|
||||||
$create_dir = (bool) get_parameter ('create_dir');
|
//$create_dir = (bool) get_parameter ('create_dir');
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
print_page_header (__('File manager'), "", false, "", true);
|
print_page_header (__('File manager'), "", false, "", true);
|
||||||
|
|
||||||
// Upload file
|
//// Upload file
|
||||||
if ($upload_file) {
|
//if ($upload_file) {
|
||||||
if (isset ($_FILES['file']) && $_FILES['file']['name'] != "") {
|
// if (isset ($_FILES['file']) && $_FILES['file']['name'] != "") {
|
||||||
$filename = $_FILES['file']['name'];
|
// $filename = $_FILES['file']['name'];
|
||||||
$filesize = $_FILES['file']['size'];
|
// $filesize = $_FILES['file']['size'];
|
||||||
$directory = (string) get_parameter ('directory');
|
// $directory = (string) get_parameter ('directory');
|
||||||
|
//
|
||||||
// Copy file to directory and change name
|
// // Copy file to directory and change name
|
||||||
$nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename;
|
// $nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename;
|
||||||
if (! @copy ($_FILES['file']['tmp_name'], $nombre_archivo )) {
|
// if (! @copy ($_FILES['file']['tmp_name'], $nombre_archivo )) {
|
||||||
echo "<h3 class=error>".__('attach_error')."</h3>";
|
// echo "<h3 class=error>".__('attach_error')."</h3>";
|
||||||
} else {
|
// } else {
|
||||||
// Delete temporal file
|
// // Delete temporal file
|
||||||
unlink ($_FILES['file']['tmp_name']);
|
// unlink ($_FILES['file']['tmp_name']);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
if ($delete_file) {
|
//if ($delete_file) {
|
||||||
$filename = (string) get_parameter ('filename');
|
// $filename = (string) get_parameter ('filename');
|
||||||
echo "<h3>".__('Deleting')." ".$filename."</h3>";
|
// echo "<h3>".__('Deleting')." ".$filename."</h3>";
|
||||||
if (is_dir ($filename)) {
|
// if (is_dir ($filename)) {
|
||||||
rmdir ($filename);
|
// rmdir ($filename);
|
||||||
} else {
|
// } else {
|
||||||
unlink ($filename);
|
// unlink ($filename);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
$directory = (string) get_parameter ('directory', "/");
|
$directory = (string) get_parameter ('directory', "/");
|
||||||
|
|
||||||
// CREATE DIR
|
//// CREATE DIR
|
||||||
if ($create_dir) {
|
//if ($create_dir) {
|
||||||
$dirname = (string) get_parameter ('dirname');
|
// $dirname = (string) get_parameter ('dirname');
|
||||||
if ($dirname) {
|
// if ($dirname) {
|
||||||
@mkdir ($directory.'/'.$dirname);
|
// @mkdir ($directory.'/'.$dirname);
|
||||||
echo '<h3>'.__('Created directory %s', $dirname).'</h3>';
|
// echo '<h3>'.__('Created directory %s', $dirname).'</h3>';
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
// A miminal security check to avoid directory traversal
|
// A miminal security check to avoid directory traversal
|
||||||
if (preg_match ("/\.\./", $directory))
|
if (preg_match ("/\.\./", $directory))
|
||||||
|
@ -100,129 +100,10 @@ $available_directories[$directory] = $directory;
|
||||||
|
|
||||||
$real_directory = realpath ($config['homedir'].'/'.$directory);
|
$real_directory = realpath ($config['homedir'].'/'.$directory);
|
||||||
|
|
||||||
$table->width = '50%';
|
box_upload_file_explorer($real_directory, $directory);
|
||||||
|
|
||||||
$table->data = array ();
|
|
||||||
|
|
||||||
if (! is_file_manager_writable_dir ($real_directory)) {
|
|
||||||
echo "<h3 class='error'>".__('Current directory is not writable by HTTP Server')."</h3>";
|
|
||||||
echo '<p>';
|
|
||||||
echo __('Please check that current directory has write rights for HTTP server');
|
|
||||||
echo '</p>';
|
|
||||||
} else {
|
|
||||||
$table->data[1][0] = __('Upload file');
|
|
||||||
$table->data[1][1] = print_input_file ('file', true, false);
|
|
||||||
$table->data[1][2] = print_submit_button (__('Go'), 'go', false,
|
|
||||||
'class="sub next"', true);
|
|
||||||
$table->data[1][2] .= print_input_hidden ('directory', $directory, true);
|
|
||||||
$table->data[1][2] .= print_input_hidden ('upload_file', 1, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<form method="post" action="index.php?sec=gsetup&sec2=godmode/setup/file_manager" enctype="multipart/form-data">';
|
|
||||||
print_table ($table);
|
|
||||||
echo '</form>';
|
|
||||||
|
|
||||||
echo '<h3>'.__('Index of %s', $directory).'</h3>';
|
echo '<h3>'.__('Index of %s', $directory).'</h3>';
|
||||||
|
|
||||||
// List files
|
file_explorer($real_directory, $directory, 'index.php?sec=gsetup&sec2=godmode/setup/file_manager');
|
||||||
if (! is_dir ($real_directory)) {
|
|
||||||
echo __('Directory %s doesn\'t exist!', $directory);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$files = list_file_manager_dir ($real_directory);
|
|
||||||
|
|
||||||
$table->width = '90%';
|
|
||||||
$table->class = 'listing';
|
|
||||||
|
|
||||||
$table->colspan = array ();
|
|
||||||
$table->data = array ();
|
|
||||||
$table->head = array ();
|
|
||||||
$table->size = array ();
|
|
||||||
$table->align[4] = 'center';
|
|
||||||
|
|
||||||
$table->size[0] = '24px';
|
|
||||||
|
|
||||||
$table->head[0] = '';
|
|
||||||
$table->head[1] = __('Name');
|
|
||||||
$table->head[2] = __('Last modification');
|
|
||||||
$table->head[3] = __('Size');
|
|
||||||
$table->head[4] = __('Delete');
|
|
||||||
|
|
||||||
$prev_dir = explode ("/", $directory);
|
|
||||||
$prev_dir_str = "";
|
|
||||||
for ($i = 0; $i < (count ($prev_dir) - 1); $i++) {
|
|
||||||
$prev_dir_str .= $prev_dir[$i];
|
|
||||||
if ($i < (count ($prev_dir) - 2))
|
|
||||||
$prev_dir_str .= "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($prev_dir_str != '') {
|
|
||||||
$table->data[0][0] = print_image ('images/go_previous.png', true);
|
|
||||||
$table->data[0][1] = '<a href="index.php?sec=gsetup&sec2=godmode/setup/file_manager&directory='.$prev_dir_str.'">';
|
|
||||||
$table->data[0][1] .= __('Parent directory');
|
|
||||||
$table->data[0][1] .='</a>';
|
|
||||||
|
|
||||||
$table->colspan[0][1] = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_writable ($real_directory)) {
|
|
||||||
$table->data[1][0] = print_image ('images/mimetypes/directory.png', true,
|
|
||||||
array ('title' => __('Create directory')));
|
|
||||||
$table->data[1][1] = '<form method="post" action="index.php?sec=gsetup&sec2=godmode/setup/file_manager">';
|
|
||||||
$table->data[1][1] .= print_input_text ('dirname', '', '', 15, 255, true);
|
|
||||||
$table->data[1][1] .= print_submit_button (__('Create'), 'crt', false, 'class="sub next"', true);
|
|
||||||
$table->data[1][1] .= print_input_hidden ('directory', $directory, true);
|
|
||||||
$table->data[1][1] .= print_input_hidden ('create_dir', 1, true);
|
|
||||||
$table->data[1][1] .= '</form>';
|
|
||||||
|
|
||||||
$table->colspan[0][1] = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($files as $fileinfo) {
|
|
||||||
$data = array ();
|
|
||||||
|
|
||||||
switch ($fileinfo['mime']) {
|
|
||||||
case MIME_DIR:
|
|
||||||
$data[0] = print_image ('images/mimetypes/directory.png', true);
|
|
||||||
break;
|
|
||||||
case MIME_IMAGE:
|
|
||||||
$data[0] = print_image ('images/mimetypes/image.png', true);
|
|
||||||
break;
|
|
||||||
case MIME_ZIP:
|
|
||||||
$data[0] = print_image ('images/mimetypes/zip.png', true);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$data[0] = print_image ('images/mimetypes/unknown.png', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($fileinfo['is_dir']) {
|
|
||||||
$data[1] = '<a href="index.php?sec=gsetup&sec2=godmode/setup/file_manager&directory='.$directory.'/'.$fileinfo['name'].'">'.$fileinfo['name'].'</a>';
|
|
||||||
} else {
|
|
||||||
$data[1] = '<a href="'.$fileinfo['url'].'">'.$fileinfo['name'].'</a>';
|
|
||||||
}
|
|
||||||
$data[2] = print_timestamp ($fileinfo['last_modified'], true,
|
|
||||||
array ('prominent' => true));
|
|
||||||
if ($fileinfo['is_dir']) {
|
|
||||||
$data[3] = '';
|
|
||||||
} else {
|
|
||||||
$data[3] = format_filesize ($fileinfo['size']);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Delete button
|
|
||||||
if (is_writable ($fileinfo['realpath']) &&
|
|
||||||
(! is_dir ($fileinfo['realpath']) || count (scandir ($fileinfo['realpath'])) < 3)) {
|
|
||||||
$data[4] = '<form method="post" action="index.php?sec=gsetup&sec2=godmode/setup/file_manager">';
|
|
||||||
$data[4] .= '<input type="image" src="images/cross.png" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
|
|
||||||
$data[4] .= print_input_hidden ('filename', $fileinfo['realpath'], true);
|
|
||||||
$data[4] .= print_input_hidden ('delete_file', 1, true);
|
|
||||||
$data[4] .= '</form>';
|
|
||||||
} else {
|
|
||||||
$data[4] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
array_push ($table->data, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
print_table ($table);
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -26,6 +26,7 @@ define ('MIME_UNKNOWN', 0);
|
||||||
define ('MIME_DIR', 1);
|
define ('MIME_DIR', 1);
|
||||||
define ('MIME_IMAGE', 2);
|
define ('MIME_IMAGE', 2);
|
||||||
define ('MIME_ZIP', 3);
|
define ('MIME_ZIP', 3);
|
||||||
|
define ('MIME_TEXT', 4);
|
||||||
/**#@-*/
|
/**#@-*/
|
||||||
|
|
||||||
if (!function_exists ('mime_content_type')) {
|
if (!function_exists ('mime_content_type')) {
|
||||||
|
@ -104,6 +105,510 @@ if (!function_exists ('mime_content_type')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$upload_file_or_zip = (bool) get_parameter('upload_file_or_zip');
|
||||||
|
|
||||||
|
if ($upload_file_or_zip) {
|
||||||
|
$zip_or_file = get_parameter('zip_or_file');
|
||||||
|
if ($zip_or_file == 'file') {
|
||||||
|
$upload_file = true;
|
||||||
|
$upload_zip = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$upload_file = false;
|
||||||
|
$upload_zip = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$upload_file = (bool) get_parameter ('upload_file');
|
||||||
|
$upload_zip = (bool) get_parameter ('upload_zip');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload file
|
||||||
|
if ($upload_file) {
|
||||||
|
// Load global vars
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
check_login ();
|
||||||
|
|
||||||
|
if (! give_acl ($config['id_user'], 0, "PM")) {
|
||||||
|
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation", "Trying to access File manager");
|
||||||
|
require ("general/noaccess.php");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset ($_FILES['file']) && $_FILES['file']['name'] != "") {
|
||||||
|
$filename = $_FILES['file']['name'];
|
||||||
|
$filesize = $_FILES['file']['size'];
|
||||||
|
$real_directory = (string) get_parameter('real_directory');
|
||||||
|
$directory = (string) get_parameter ('directory');
|
||||||
|
|
||||||
|
// Copy file to directory and change name
|
||||||
|
if ($directory == '') {
|
||||||
|
$nombre_archivo = $real_directory .'/'. $filename;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename;
|
||||||
|
}
|
||||||
|
if (! @copy ($_FILES['file']['tmp_name'], $nombre_archivo )) {
|
||||||
|
echo "<h3 class=error>".__('attach_error')."</h3>";
|
||||||
|
} else {
|
||||||
|
// Delete temporal file
|
||||||
|
unlink ($_FILES['file']['tmp_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create text file
|
||||||
|
$create_text_file = (bool) get_parameter ('create_text_file');
|
||||||
|
if ($create_text_file) {
|
||||||
|
// Load global vars
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
check_login ();
|
||||||
|
|
||||||
|
if (! give_acl ($config['id_user'], 0, "PM")) {
|
||||||
|
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation", "Trying to access File manager");
|
||||||
|
require ("general/noaccess.php");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = get_parameter('name_file');
|
||||||
|
|
||||||
|
if ($filename != "") {
|
||||||
|
|
||||||
|
$real_directory = (string) get_parameter('real_directory');
|
||||||
|
$directory = (string) get_parameter ('directory');
|
||||||
|
|
||||||
|
if ($directory == '') {
|
||||||
|
$nombre_archivo = $real_directory .'/'. $filename;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename;
|
||||||
|
}
|
||||||
|
if (! @touch($nombre_archivo)) {
|
||||||
|
echo "<h3 class=error>".__('Error create file.')."</h3>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "<h3 class=error>".__('Error create file with empty name.')."</h3>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload file
|
||||||
|
if ($upload_zip) {
|
||||||
|
// Load global vars
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
check_login ();
|
||||||
|
|
||||||
|
if (! give_acl ($config['id_user'], 0, "PM")) {
|
||||||
|
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation", "Trying to access File manager");
|
||||||
|
require ("general/noaccess.php");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset ($_FILES['file']) && $_FILES['file']['name'] != "") {
|
||||||
|
$filename = $_FILES['file']['name'];
|
||||||
|
$filesize = $_FILES['file']['size'];
|
||||||
|
$real_directory = (string) get_parameter('real_directory');
|
||||||
|
$directory = (string) get_parameter ('directory');
|
||||||
|
|
||||||
|
// Copy file to directory and change name
|
||||||
|
if ($directory == '') {
|
||||||
|
$nombre_archivo = $real_directory .'/'. $filename;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename;
|
||||||
|
}
|
||||||
|
if (! @copy ($_FILES['file']['tmp_name'], $nombre_archivo )) {
|
||||||
|
echo "<h3 class=error>".__('attach_error')."</h3>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Delete temporal file
|
||||||
|
unlink ($_FILES['file']['tmp_name']);
|
||||||
|
|
||||||
|
//Extract the zip file
|
||||||
|
$zip = new ZipArchive;
|
||||||
|
$pathname = $config['homedir'].'/'.$directory.'/';
|
||||||
|
|
||||||
|
if ($zip->open($nombre_archivo) === true) {
|
||||||
|
$zip->extractTo($pathname);
|
||||||
|
unlink($nombre_archivo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CREATE DIR
|
||||||
|
$create_dir = (bool) get_parameter ('create_dir');
|
||||||
|
if ($create_dir) {
|
||||||
|
$directory = (string) get_parameter ('directory', "/");
|
||||||
|
|
||||||
|
$dirname = (string) get_parameter ('dirname');
|
||||||
|
if ($dirname != '') {
|
||||||
|
@mkdir ($directory.'/'.$dirname);
|
||||||
|
echo '<h3>'.__('Created directory %s', $dirname).'</h3>';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "<h3 class=error>".__('Error create file with empty name.')."</h3>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//DELETE FILE OR DIR
|
||||||
|
$delete_file = (bool) get_parameter ('delete_file');
|
||||||
|
if ($delete_file) {
|
||||||
|
$filename = (string) get_parameter ('filename');
|
||||||
|
echo "<h3>".__('Deleting')." ".$filename."</h3>";
|
||||||
|
if (is_dir ($filename)) {
|
||||||
|
rmdir ($filename);
|
||||||
|
} else {
|
||||||
|
unlink ($filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursive delete directory and empty or not directory.
|
||||||
|
*
|
||||||
|
* @param string $dir The dir to deletete
|
||||||
|
*/
|
||||||
|
function delete_directory($dir)
|
||||||
|
{
|
||||||
|
if ($handle = opendir($dir))
|
||||||
|
{
|
||||||
|
while (false !== ($file = readdir($handle))) {
|
||||||
|
if (($file != ".") && ($file != "..")) {
|
||||||
|
|
||||||
|
if (is_dir($dir . $file))
|
||||||
|
{
|
||||||
|
if (!rmdir($dir . $file))
|
||||||
|
{
|
||||||
|
delete_directory($dir . $file . '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unlink($dir . $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($handle);
|
||||||
|
rmdir($dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main function to show the directories and files.
|
||||||
|
*
|
||||||
|
* @param string $real_directory The string of dir as realpath.
|
||||||
|
* @param string $relative_directory The string of dir as 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.
|
||||||
|
*/
|
||||||
|
function file_explorer($real_directory, $relative_directory, $url, $father = '', $editor = false) {
|
||||||
|
?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function show_form_create_folder() {
|
||||||
|
$("#main_buttons").css("display", "none");
|
||||||
|
$("#create_folder").css("display", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_upload_file() {
|
||||||
|
$("#main_buttons").css("display", "none");
|
||||||
|
$("#upload_file").css("display", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_create_text_file() {
|
||||||
|
$("#main_buttons").css("display", "none");
|
||||||
|
$("#create_text_file").css("display", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_main_buttons_folder() {
|
||||||
|
$("#main_buttons").css("display", "");
|
||||||
|
$("#create_folder").css("display", "none");
|
||||||
|
$("#upload_file").css("display", "none");
|
||||||
|
$("#create_text_file").css("display", "none");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// List files
|
||||||
|
if (! is_dir ($real_directory)) {
|
||||||
|
echo __('Directory %s doesn\'t exist!', $relative_directory);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = list_file_manager_dir ($real_directory);
|
||||||
|
|
||||||
|
$table->width = '90%';
|
||||||
|
$table->class = 'listing';
|
||||||
|
|
||||||
|
$table->colspan = array ();
|
||||||
|
$table->data = array ();
|
||||||
|
$table->head = array ();
|
||||||
|
$table->size = array ();
|
||||||
|
$table->align[4] = 'center';
|
||||||
|
|
||||||
|
$table->size[0] = '24px';
|
||||||
|
|
||||||
|
$table->head[0] = '';
|
||||||
|
$table->head[1] = __('Name');
|
||||||
|
$table->head[2] = __('Last modification');
|
||||||
|
$table->head[3] = __('Size');
|
||||||
|
$table->head[4] = __('Actions');
|
||||||
|
|
||||||
|
$prev_dir = explode ("/", $relative_directory);
|
||||||
|
$prev_dir_str = "";
|
||||||
|
for ($i = 0; $i < (count ($prev_dir) - 1); $i++) {
|
||||||
|
$prev_dir_str .= $prev_dir[$i];
|
||||||
|
if ($i < (count ($prev_dir) - 2))
|
||||||
|
$prev_dir_str .= "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($prev_dir_str != '') && ($father != $relative_directory)) {
|
||||||
|
$table->data[0][0] = print_image ('images/go_previous.png', true);
|
||||||
|
$table->data[0][1] = '<a href="' . $url . '&directory='.$prev_dir_str.'">';
|
||||||
|
$table->data[0][1] .= __('Parent directory');
|
||||||
|
$table->data[0][1] .='</a>';
|
||||||
|
|
||||||
|
$table->colspan[0][1] = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_writable ($real_directory)) {
|
||||||
|
$table->data[1][0] = '';
|
||||||
|
$table->data[1][1] = '<div id="main_buttons">';
|
||||||
|
$table->data[1][1] .= print_button(__('Create folder'), 'folder', false, 'show_form_create_folder();', "class='sub'", true);
|
||||||
|
$table->data[1][1] .= print_button(__('Upload file/s'), 'up_files', false, 'show_upload_file();', "class='sub'", true);
|
||||||
|
$table->data[1][1] .= print_button(__('Create text file'), 'create_file', false, 'show_create_text_file();', "class='sub'", true);
|
||||||
|
$table->data[1][1] .= '</div>';
|
||||||
|
|
||||||
|
$table->data[1][1] .= '<div id="create_folder" style="display: none;">';
|
||||||
|
$table->data[1][1] .= print_button(__('Close'), 'close', false, 'show_main_buttons_folder();', "class='sub' style='float: left;'", true);
|
||||||
|
$table->data[1][1] .= '<form method="post" action="' . $url . '">';
|
||||||
|
$table->data[1][1] .= print_input_text ('dirname', '', '', 15, 255, true);
|
||||||
|
$table->data[1][1] .= print_submit_button (__('Create'), 'crt', false, 'class="sub next"', true);
|
||||||
|
$table->data[1][1] .= print_input_hidden ('directory', $relative_directory, true);
|
||||||
|
$table->data[1][1] .= print_input_hidden ('create_dir', 1, true);
|
||||||
|
$table->data[1][1] .= '</form>';
|
||||||
|
$table->data[1][1] .= '</div>';
|
||||||
|
|
||||||
|
$table->data[1][1] .= '<div id="upload_file" style="display: none;">';
|
||||||
|
$table->data[1][1] .= print_button(__('Close'), 'close', false, 'show_main_buttons_folder();', "class='sub' style='float: left;'", true);
|
||||||
|
$table->data[1][1] .= '<form method="post" action="' . $url . '" enctype="multipart/form-data">';
|
||||||
|
$table->data[1][1] .= print_help_tip (__("The zip upload in this collection, easy to upload multiple files."), true);
|
||||||
|
$table->data[1][1] .= print_input_file ('file', true, false);
|
||||||
|
$table->data[1][1] .= print_radio_button('zip_or_file', 'zip', '', false, true) . __('Multiple files zipped');
|
||||||
|
$table->data[1][1] .= print_radio_button('zip_or_file', 'file', '', true, true) . __('One');
|
||||||
|
$table->data[1][1] .= ' ';
|
||||||
|
$table->data[1][1] .= print_submit_button (__('Go'), 'go', false, 'class="sub next"', true);
|
||||||
|
$table->data[1][1] .= print_input_hidden ('real_directory', $real_directory, true);
|
||||||
|
$table->data[1][1] .= print_input_hidden ('directory', $relative_directory, true);
|
||||||
|
$table->data[1][1] .= print_input_hidden ('upload_file_or_zip', 1, true);
|
||||||
|
$table->data[1][1] .= '</form>';
|
||||||
|
$table->data[1][1] .= '</div>';
|
||||||
|
|
||||||
|
$table->data[1][1] .= '<div id="create_text_file" style="display: none;">';
|
||||||
|
$table->data[1][1] .= print_button(__('Close'), 'close', false, 'show_main_buttons_folder();', "class='sub' style='float: left;'", true);
|
||||||
|
$table->data[1][1] .= '<form method="post" action="' . $url . '">';
|
||||||
|
$table->data[1][1] .= print_input_text('name_file', '', '', 30, 50, true);
|
||||||
|
$table->data[1][1] .= print_submit_button (__('Create'), 'create', false, 'class="sub"', true);
|
||||||
|
$table->data[1][1] .= print_input_hidden ('real_directory', $real_directory, true);
|
||||||
|
$table->data[1][1] .= print_input_hidden ('directory', $relative_directory, true);
|
||||||
|
$table->data[1][1] .= print_input_hidden ('create_text_file', 1, true);
|
||||||
|
$table->data[1][1] .= '</form>';
|
||||||
|
$table->data[1][1] .= '</div>';
|
||||||
|
|
||||||
|
$table->colspan[1][1] =5;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($files as $fileinfo) {
|
||||||
|
$data = array ();
|
||||||
|
|
||||||
|
switch ($fileinfo['mime']) {
|
||||||
|
case MIME_DIR:
|
||||||
|
$data[0] = print_image ('images/mimetypes/directory.png', true);
|
||||||
|
break;
|
||||||
|
case MIME_IMAGE:
|
||||||
|
$data[0] = print_image ('images/mimetypes/image.png', true);
|
||||||
|
break;
|
||||||
|
case MIME_ZIP:
|
||||||
|
$data[0] = print_image ('images/mimetypes/zip.png', true);
|
||||||
|
break;
|
||||||
|
case MIME_TEXT:
|
||||||
|
$data[0] = print_image ('images/mimetypes/text.png', true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$data[0] = print_image ('images/mimetypes/unknown.png', true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fileinfo['is_dir']) {
|
||||||
|
$data[1] = '<a href="' . $url . '&directory='.$relative_directory.'/'.$fileinfo['name'].'">'.$fileinfo['name'].'</a>';
|
||||||
|
} else {
|
||||||
|
$data[1] = '<a href="'.$fileinfo['url'].'">'.$fileinfo['name'].'</a>';
|
||||||
|
}
|
||||||
|
$data[2] = print_timestamp ($fileinfo['last_modified'], true,
|
||||||
|
array ('prominent' => true));
|
||||||
|
if ($fileinfo['is_dir']) {
|
||||||
|
$data[3] = '';
|
||||||
|
} else {
|
||||||
|
$data[3] = format_filesize ($fileinfo['size']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Actions buttons
|
||||||
|
//Delete button
|
||||||
|
$data[4] = '';
|
||||||
|
if (is_writable ($fileinfo['realpath']) &&
|
||||||
|
(! is_dir ($fileinfo['realpath']) || count (scandir ($fileinfo['realpath'])) < 3)) {
|
||||||
|
$data[4] = '<form method="post" action="" style="float: left;">';
|
||||||
|
$data[4] .= '<input type="image" src="images/cross.png" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
|
||||||
|
$data[4] .= print_input_hidden ('filename', $fileinfo['realpath'], true);
|
||||||
|
$data[4] .= print_input_hidden ('delete_file', 1, true);
|
||||||
|
$data[4] .= '</form>';
|
||||||
|
|
||||||
|
if ($editor) {
|
||||||
|
if ($fileinfo['mime'] == MIME_TEXT) {
|
||||||
|
$data[4] .= "<a href='$url&edit_file=1&location_file=" . $fileinfo['realpath'] . "' style='float: left;'><img src='images/edit.png' style='margin-top: 2px;' /></a>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push ($table->data, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
print_table ($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $real_directory The string of dir as realpath.
|
||||||
|
* @param string $relative_directory The string of dir as relative path.
|
||||||
|
* @param string $url The url to set in the forms and some links in the explorer.
|
||||||
|
*/
|
||||||
|
function box_upload_file_complex($real_directory, $relative_directory, $url = '') {
|
||||||
|
$table->width = '100%';
|
||||||
|
|
||||||
|
$table->data = array ();
|
||||||
|
|
||||||
|
if (! is_file_manager_writable_dir ($real_directory)) {
|
||||||
|
echo "<h3 class='error'>".__('Current directory is not writable by HTTP Server')."</h3>";
|
||||||
|
echo '<p>';
|
||||||
|
echo __('Please check that current directory has write rights for HTTP server');
|
||||||
|
echo '</p>';
|
||||||
|
} else {
|
||||||
|
$table->data[1][0] = __('Upload') . print_help_tip (__("The zip upload in this collection, easy to upload multiple files."), true);
|
||||||
|
$table->data[1][1] = print_input_file ('file', true, false);
|
||||||
|
$table->data[1][2] = print_radio_button('zip_or_file', 'zip', __('Multiple files zipped'), false, true);
|
||||||
|
$table->data[1][3] = print_radio_button('zip_or_file', 'file', __('One'), true, true);
|
||||||
|
$table->data[1][4] = print_submit_button (__('Go'), 'go', false,
|
||||||
|
'class="sub next"', true);
|
||||||
|
$table->data[1][4] .= print_input_hidden ('real_directory', $real_directory, true);
|
||||||
|
$table->data[1][4] .= print_input_hidden ('directory', $relative_directory, true);
|
||||||
|
$table->data[1][4] .= print_input_hidden ('upload_file_or_zip', 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<form method="post" action="' . $url . '" enctype="multipart/form-data">';
|
||||||
|
print_table ($table);
|
||||||
|
echo '</form>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the box of fields for upload file.
|
||||||
|
*
|
||||||
|
* @param string $real_directory The string of dir as realpath.
|
||||||
|
* @param string $relative_directory The string of dir as relative path.
|
||||||
|
* @param string $url The url to set in the forms and some links in the explorer.
|
||||||
|
*/
|
||||||
|
function box_upload_file_explorer($real_directory, $relative_directory, $url = '') {
|
||||||
|
$table->width = '50%';
|
||||||
|
|
||||||
|
$table->data = array ();
|
||||||
|
|
||||||
|
if (! is_file_manager_writable_dir ($real_directory)) {
|
||||||
|
echo "<h3 class='error'>".__('Current directory is not writable by HTTP Server')."</h3>";
|
||||||
|
echo '<p>';
|
||||||
|
echo __('Please check that current directory has write rights for HTTP server');
|
||||||
|
echo '</p>';
|
||||||
|
} else {
|
||||||
|
$table->data[1][0] = __('Upload file');
|
||||||
|
$table->data[1][1] = print_input_file ('file', true, false);
|
||||||
|
$table->data[1][2] = print_submit_button (__('Go'), 'go', false,
|
||||||
|
'class="sub next"', true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('real_directory', $real_directory, true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('directory', $relative_directory, true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('upload_file', 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<form method="post" action="' . $url . '" enctype="multipart/form-data">';
|
||||||
|
print_table ($table);
|
||||||
|
echo '</form>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the box of fields for upload file zip.
|
||||||
|
*
|
||||||
|
* @param unknown_type $real_directory
|
||||||
|
* @param unknown_type $relative_directory
|
||||||
|
* @param string $url The url to set in the forms and some links in the explorer.
|
||||||
|
*/
|
||||||
|
function box_upload_zip_explorer($real_directory, $relative_directory, $url = '') {
|
||||||
|
$table->width = '60%';
|
||||||
|
|
||||||
|
$table->data = array ();
|
||||||
|
|
||||||
|
if (! is_file_manager_writable_dir ($real_directory)) {
|
||||||
|
echo "<h3 class='error'>".__('Current directory is not writable by HTTP Server')."</h3>";
|
||||||
|
echo '<p>';
|
||||||
|
echo __('Please check that current directory has write rights for HTTP server');
|
||||||
|
echo '</p>';
|
||||||
|
} else {
|
||||||
|
$table->data[1][0] = __('Upload zip file: ') . print_help_tip (__("The zip upload in this collection, easy to upload multiple files."), true);
|
||||||
|
$table->data[1][1] = print_input_file ('file', true, false);
|
||||||
|
$table->data[1][2] = print_submit_button (__('Go'), 'go', false,
|
||||||
|
'class="sub next"', true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('real_directory', $real_directory, true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('directory', $relative_directory, true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('upload_zip', 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<form method="post" action="' . $url . '" enctype="multipart/form-data">';
|
||||||
|
print_table ($table);
|
||||||
|
echo '</form>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the box of fields for create the text file.
|
||||||
|
*
|
||||||
|
* @param unknown_type $real_directory
|
||||||
|
* @param unknown_type $relative_directory
|
||||||
|
* @param string $url The url to set in the forms and some links in the explorer.
|
||||||
|
*/
|
||||||
|
function box_create_text_explorer($real_directory, $relative_directory, $url = '') {
|
||||||
|
$table->width = '60%';
|
||||||
|
|
||||||
|
$table->data = array ();
|
||||||
|
|
||||||
|
if (! is_file_manager_writable_dir ($real_directory)) {
|
||||||
|
echo "<h3 class='error'>".__('Current directory is not writable by HTTP Server')."</h3>";
|
||||||
|
echo '<p>';
|
||||||
|
echo __('Please check that current directory has write rights for HTTP server');
|
||||||
|
echo '</p>';
|
||||||
|
} else {
|
||||||
|
$table->data[1][0] = __('Create text file: ');
|
||||||
|
$table->data[1][1] = print_input_text('name_file', '', '', 30, 50, true);
|
||||||
|
$table->data[1][2] = print_submit_button (__('Create'), 'create', false,
|
||||||
|
'class="sub"', true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('real_directory', $real_directory, true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('directory', $relative_directory, true);
|
||||||
|
$table->data[1][2] .= print_input_hidden ('create_text_file', 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<form method="post" action="' . $url . '">';
|
||||||
|
print_table ($table);
|
||||||
|
echo '</form>';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the available directories of the file manager.
|
* Get the available directories of the file manager.
|
||||||
|
@ -205,6 +710,8 @@ function get_file_manager_file_info ($filepath) {
|
||||||
$info['mime'] = MIME_IMAGE;
|
$info['mime'] = MIME_IMAGE;
|
||||||
} else if (in_array ($info['mime_extend'], $zip_mimes)) {
|
} else if (in_array ($info['mime_extend'], $zip_mimes)) {
|
||||||
$info['mime'] = MIME_ZIP;
|
$info['mime'] = MIME_ZIP;
|
||||||
|
} else if (strpos ($info['mime_extend'], 'text') === 0) {
|
||||||
|
$info['mime'] = MIME_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $info;
|
return $info;
|
||||||
|
|
Loading…
Reference in New Issue