move extension translate_string and file_repo pandora_enterprise#12333

This commit is contained in:
daniel 2023-11-28 08:13:00 +01:00
parent 64cb2ad912
commit 3f3e8e42bc
18 changed files with 555 additions and 645 deletions

View File

@ -1,286 +0,0 @@
<?php
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
function pandora_files_repo_install()
{
global $config;
if (isset($config['files_repo_installed']) && $config['files_repo_installed'] == 1) {
return;
}
$full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/';
$full_sql_dir = $full_extensions_dir.'files_repo/sql/';
$file_path = '';
switch ($config['dbtype']) {
case 'mysql':
$file_path = $full_sql_dir.'files_repo.sql';
break;
case 'postgresql':
$file_path = $full_sql_dir.'files_repo.postgreSQL.sql';
break;
case 'oracle':
$file_path = $full_sql_dir.'files_repo.oracle.sql';
break;
}
if (!empty($file_path)) {
$result = db_process_file($file_path);
if ($result) {
// Configuration values
$values = [
'token' => 'files_repo_installed',
'value' => 1,
];
db_process_sql_insert('tconfig', $values);
}
}
}
function pandora_files_repo_uninstall()
{
global $config;
switch ($config['dbtype']) {
case 'mysql':
db_process_sql('DROP TABLE `tfiles_repo_group`');
db_process_sql('DROP TABLE `tfiles_repo`');
db_process_sql(
'DELETE FROM `tconfig`
WHERE `token` LIKE "files_repo_%"'
);
break;
case 'postgresql':
db_process_sql('DROP TABLE "tfiles_repo_group"');
db_process_sql('DROP TABLE "tfiles_repo"');
db_process_sql(
'DELETE FROM "tconfig"
WHERE "token" LIKE \'files_repo_%\''
);
break;
case 'oracle':
db_process_sql('DROP TRIGGER "tfiles_repo_group_inc"');
db_process_sql('DROP SEQUENCE "tfiles_repo_group_s"');
db_process_sql('DROP TABLE "tfiles_repo_group"');
db_process_sql('DROP TRIGGER "tfiles_repo_inc"');
db_process_sql('DROP SEQUENCE "tfiles_repo_s"');
db_process_sql('DROP TABLE "tfiles_repo"');
db_process_sql(
'DELETE FROM tconfig
WHERE token LIKE \'files_repo_%\''
);
break;
}
if (!empty($config['attachment_store'])) {
delete_dir($config['attachment_store'].'/files_repo');
}
}
function pandora_files_repo_godmode()
{
global $config;
if (!isset($config['files_repo_installed']) || !$config['files_repo_installed']) {
ui_print_error_message(__('Extension not installed'));
}
// ACL Check
check_login();
if (! check_acl($config['id_user'], 0, 'PM')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access to Files repository'
);
include 'general/noaccess.php';
return;
}
// Header tabs.
$godmode['text'] = '<a href="index.php?sec=godmode/extensions&sec2=extensions/files_repo">'.html_print_image('images/configuration@svg.svg', true, ['title' => __('Administration view'), 'class' => 'main_menu_icon invert_filter']).'</a>';
$godmode['godmode'] = 1;
$godmode['active'] = 1;
$operation['text'] = '<a href="index.php?sec=extensions&sec2=extensions/files_repo">'.html_print_image('images/see-details@svg.svg', true, ['title' => __('Operation view'), 'class' => 'main_menu_icon invert_filter']).'</a>';
$operation['operation'] = 1;
$onheader = [
'godmode' => $godmode,
'operation' => $operation,
];
// Header.
ui_print_standard_header(
__('Extensions'),
'images/extensions.png',
false,
'',
true,
$onheader,
[
[
'link' => '',
'label' => __('Admin tools'),
],
[
'link' => '',
'label' => __('Extension manager'),
],
[
'link' => '',
'label' => __('Files repository manager'),
],
]
);
$full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/';
include_once $full_extensions_dir.'files_repo/functions_files_repo.php';
// Directory files_repo check.
if (!files_repo_check_directory(true)) {
return;
}
$server_content_length = 0;
if (isset($_SERVER['CONTENT_LENGTH'])) {
$server_content_length = $_SERVER['CONTENT_LENGTH'];
}
// Check for an anoying error that causes the $_POST and $_FILES arrays.
// were empty if the file is larger than the post_max_size.
if (intval($server_content_length) > 0 && empty($_POST)) {
ui_print_error_message(__('Problem uploading. Please check this PHP runtime variable values: <pre> post_max_size (currently '.ini_get('post_max_size').')</pre>'));
}
// GET and POST parameters.
$file_id = (int) get_parameter('file_id');
$add_file = (bool) get_parameter('add_file');
$update_file = (bool) get_parameter('update_file');
$delete_file = (bool) get_parameter('delete');
// File add or update.
if ($add_file || ($update_file && $file_id > 0)) {
$groups = get_parameter('groups', []);
$public = (bool) get_parameter('public');
$description = io_safe_output((string) get_parameter('description'));
if (mb_strlen($description, 'UTF-8') > 200) {
$description = mb_substr($description, 0, 200, 'UTF-8');
}
$description = io_safe_input($description);
if ($add_file) {
$result = files_repo_add_file('upfile', $description, $groups, $public);
} else if ($update_file) {
$result = files_repo_update_file($file_id, $description, $groups, $public);
$file_id = 0;
}
if ($result['status'] == false) {
ui_print_error_message($result['message']);
}
}
// File delete.
if ($delete_file && $file_id > 0) {
$result = files_repo_delete_file($file_id);
if ($result !== -1) {
ui_print_result_message($result, __('Successfully deleted'), __('Could not be deleted'));
}
$file_id = 0;
}
// FORM.
include $full_extensions_dir.'files_repo/files_repo_form.php';
if (!$file_id) {
// LIST.
$manage = true;
include $full_extensions_dir.'files_repo/files_repo_list.php';
}
}
function pandora_files_repo_operation()
{
global $config;
// Header tabs.
$onheader = [];
if (check_acl($config['id_user'], 0, 'PM')) {
$godmode['text'] = '<a href="index.php?sec=godmode/extensions&sec2=extensions/files_repo">'.html_print_image('images/configuration@svg.svg', true, ['title' => __('Administration view'), 'class' => 'main_menu_icon invert_filter']).'</a>';
$godmode['godmode'] = 1;
$operation['text'] = '<a href="index.php?sec=extensions&sec2=extensions/files_repo">'.html_print_image('images/see-details@svg.svg', true, ['title' => __('Operation view'), 'class' => 'main_menu_icon invert_filter']).'</a>';
$operation['operation'] = 1;
$operation['active'] = 1;
$onheader = [
'godmode' => $godmode,
'operation' => $operation,
];
}
// Header.
ui_print_standard_header(
__('Files repository'),
'images/extensions.png',
false,
'',
false,
$onheader,
[
[
'link' => '',
'label' => __('Admin tools'),
],
[
'link' => '',
'label' => __('Extension manager'),
],
[
'link' => '',
'label' => __('Files repository'),
],
]
);
$full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/';
include_once $full_extensions_dir.'files_repo/functions_files_repo.php';
// Directory files_repo check.
if (!files_repo_check_directory(true)) {
return;
}
// LIST.
$full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/';
include $full_extensions_dir.'files_repo/files_repo_list.php';
}
extensions_add_operation_menu_option(__('Files repository'), null, null, 'v1r1');
extensions_add_main_function('pandora_files_repo_operation');
extensions_add_godmode_menu_option(__('Files repository manager'), 'PM', null, null, 'v1r1');
extensions_add_godmode_function('pandora_files_repo_godmode');
pandora_files_repo_install();

View File

@ -1,68 +0,0 @@
<?php
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
require_once '../../include/config.php';
$file_hash = (string) get_parameter('file');
// Only allow 1 parameter in the request
$check_request = (count($_REQUEST) === 1) ? true : false;
$check_get = (count($_GET) === 1) ? true : false;
$check_post = (count($_POST) === 0) ? true : false;
// Only allow the parameter 'file'
$check_parameter = (!empty($file_hash)) ? true : false;
$check_string = (preg_match('/^[0-9a-zA-Z]{8}$/', $file_hash) === 1) ? true : false;
$checks = ($check_request && $check_get && $check_post && $check_parameter && $check_string);
if (!$checks) {
throw_error(15);
// ERROR
}
// Get the db file row
$file = db_get_row_filter('tfiles_repo', ['hash' => $file_hash]);
if (!$file) {
throw_error(10);
// ERROR
}
// Case sensitive check
$check_hash = ($file['hash'] == $file_hash) ? true : false;
if (!$check_hash) {
throw_error(10);
// ERROR
}
// Get the location
$files_repo_path = io_safe_output($config['attachment_store']).'/files_repo';
$location = $files_repo_path.'/'.$file['id'].'_'.$file['name'];
if (!file_exists($location) || !is_readable($location) || !is_file($location)) {
throw_error(5);
// ERROR
}
// All checks are fine. Download the file!
header('Content-type: aplication/octet-stream;');
header('Content-Length: '.filesize($location));
header('Content-Disposition: attachment; filename="'.$file['name'].'"');
readfile($location);
function throw_error($time=15)
{
sleep($time);
$styleError = 'background:url("../images/err.png") no-repeat scroll 0 0 transparent; padding:4px 1px 6px 30px; color:#CC0000;';
echo "<h3 style='".$styleError."'>".__('Unreliable petition').'. '.__('Please contact the administrator').'</h3>';
exit;
}

View File

@ -1,168 +0,0 @@
<?php
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
global $config;
$full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/';
require_once $full_extensions_dir.'files_repo/functions_files_repo.php';
$offset = (int) get_parameter('offset');
$filter = [];
$filter['limit'] = $config['block_size'];
$filter['offset'] = $offset;
$filter['order'] = [
'field' => 'id',
'order' => 'DESC',
];
$files = files_repo_get_files($filter);
if (!empty($files)) {
if (!isset($manage)) {
$manage = false;
}
// Pagination
if ($manage) {
$url = ui_get_full_url('index.php?sec=godmode/extensions&sec2=extensions/files_repo');
} else {
$url = ui_get_full_url('index.php?sec=extensions&sec2=extensions/files_repo');
}
$total_files = files_repo_get_files(false, true);
ui_pagination($total_files, $url, $offset);
$table = new stdClass();
$table->width = '100%';
$table->class = 'info_table';
$table->style = [];
$table->style[1] = 'max-width: 200px;';
$table->style[4] = 'text-align: center;';
$table->head = [];
$table->head[0] = __('Name');
$table->head[1] = __('Description');
$table->head[2] = __('Size');
$table->head[3] = __('Last modification');
$table->head[4] = '';
$table->data = [];
foreach ($files as $file_id => $file) {
$data = [];
// Prepare the filename for the get_file.php script
$document_root = str_replace(
'\\',
'/',
io_safe_output($_SERVER['DOCUMENT_ROOT'])
);
$file['location'] = str_replace(
'\\',
'/',
io_safe_output($file['location'])
);
$relative_path = str_replace($document_root, '', $file['location']);
$file_name = explode('/', $file['location']);
$file_decoded = $file_name[(count($file_name) - 1)];
$file_path = base64_encode($file_decoded);
$hash = md5($file_path.$config['server_unique_identifier']);
$url = ui_get_full_url(
'include/get_file.php?file='.urlencode($file_path).'&hash='.$hash
);
$date_format = ($config['date_format']) ? io_safe_output($config['date_format']) : 'F j, Y - H:m';
$data[0] = "<a href=\"$url\" target=\"_blank\">".$file['name'].'</a>';
// Name
$data[1] = ui_print_truncate_text(
$file['description'],
'description',
true,
true
);
// Description
$data[2] = ui_format_filesize($file['size']);
// Size
$data[3] = date($date_format, $file['mtime']);
// Last modification
// Public URL
$data[4] = '';
$table->cellclass[][4] = 'table_action_buttons';
if (!empty($file['hash'])) {
$public_url = ui_get_full_url(
EXTENSIONS_DIR.'/files_repo/files_repo_get_file.php?file='.$file['hash']
);
$message = __('Copy to clipboard').': Ctrl+C -> Enter';
$action = "window.prompt('$message', '$public_url');";
$data[4] .= "<a href=\"javascript:;\" onclick=\"$action\">";
$data[4] .= html_print_image(
'images/world.png',
true,
['title' => __('Public link')]
);
// Public link image
$data[4] .= '</a> ';
}
$data[4] .= "<a href=\"$url\" target=\"_blank\">";
$data[4] .= html_print_image(
'images/download.png',
true,
[
'title' => __('Download'),
'style' => 'padding:3px',
]
);
// Download image
$data[4] .= '</a>';
if ($manage) {
$config_url = ui_get_full_url(
'index.php?sec=godmode/extensions&sec2=extensions/files_repo&file_id='.$file_id
);
$data[4] .= "<a href=\"$config_url\">";
$data[4] .= html_print_image(
'images/edit.svg',
true,
[
'title' => __('Edit'),
'class' => 'main_menu_icon invert_filter',
]
);
// Edit image
$data[4] .= '</a>';
$delete_url = ui_get_full_url(
'index.php?sec=godmode/extensions&sec2=extensions/files_repo&delete=1&file_id='.$file_id
);
$data[4] .= " <a href=\"$delete_url\" onClick=\"if (!confirm('".__('Are you sure?')."')) return false;\">";
$data[4] .= html_print_image(
'images/delete.svg',
true,
[
'title' => __('Delete'),
'class' => 'main_menu_icon invert_filter',
]
);
// Delete image
$data[4] .= '</a>';
}
$table->data[] = $data;
}
html_print_table($table);
} else {
ui_print_info_message(__('No items'));
}

View File

@ -1,16 +0,0 @@
CREATE TABLE tfiles_repo (
id NUMBER(5, 0) NOT NULL PRIMARY KEY,
name VARCHAR2(255) NOT NULL,
description VARCHAR2(500) NULL,
hash VARCHAR2(8) NULL
);
CREATE SEQUENCE tfiles_repo_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER tfiles_repo_inc BEFORE INSERT ON tfiles_repo REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tfiles_repo_s.nextval INTO :NEW.ID FROM dual; END;;
CREATE TABLE tfiles_repo_group (
id NUMBER(10, 0) NOT NULL PRIMARY KEY,
id_file NUMBER(5, 0) NOT NULL REFERENCES tfiles_repo(id) ON DELETE CASCADE,
id_group NUMBER(4, 0) NOT NULL
);
CREATE SEQUENCE tfiles_repo_group_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER tfiles_repo_group_inc BEFORE INSERT ON tfiles_repo_group REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tfiles_repo_group_s.nextval INTO :NEW.ID FROM dual; END;;

View File

@ -1,2 +0,0 @@
CREATE TABLE "tfiles_repo" ("id" SERIAL NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "description" VARCHAR(500) NULL default '', "hash" VARCHAR(8) NULL default '');
CREATE TABLE "tfiles_repo_group" ("id" SERIAL NOT NULL PRIMARY KEY, "id_file" INTEGER NOT NULL REFERENCES tfiles_repo("id") ON DELETE CASCADE, "id_group" INTEGER NOT NULL);

View File

@ -1,15 +0,0 @@
CREATE TABLE IF NOT EXISTS `tfiles_repo` (
`id` int(5) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`description` varchar(500) NULL default '',
`hash` varchar(8) NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `tfiles_repo_group` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_file` int(5) unsigned NOT NULL,
`id_group` int(4) unsigned NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_file`) REFERENCES tfiles_repo(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -1720,3 +1720,7 @@ include/functions_integriaims.php
include/ajax/integria_incidents.ajax.php include/ajax/integria_incidents.ajax.php
enterprise/operation/log/log_source.php enterprise/operation/log/log_source.php
enterprise/include/class/LogSource.class.php enterprise/include/class/LogSource.class.php
enterprise/extensions/translate_string
enterprise/extensions/translate_string.php
extensions/files_repo
extensions/files_repo.php

View File

@ -5,4 +5,33 @@ DROP TABLE tagent_access;
ALTER TABLE treport_content ADD check_unknowns_graph tinyint DEFAULT 0 NULL; ALTER TABLE treport_content ADD check_unknowns_graph tinyint DEFAULT 0 NULL;
DELETE FROM `tconfig` WHERE `token` LIKE 'translate_string_extension_installed';
CREATE TABLE IF NOT EXISTS `textension_translate_string` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`lang` VARCHAR(10) NOT NULL ,
`string` TEXT ,
`translation` TEXT ,
PRIMARY KEY (`id`),
KEY `lang_index` (`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
DELETE FROM `tconfig` WHERE `token` LIKE 'files_repo_installed';
CREATE TABLE IF NOT EXISTS `tfiles_repo` (
`id` int(5) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`description` varchar(500) NULL default '',
`hash` varchar(8) NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `tfiles_repo_group` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_file` int(5) unsigned NOT NULL,
`id_group` int(4) unsigned NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_file`) REFERENCES tfiles_repo(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
COMMIT; COMMIT;

View File

@ -0,0 +1,167 @@
<?php
/**
* File repository
*
* @category Files repository
* @package Pandora FMS
* @subpackage Enterprise
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2007-2023 Artica Soluciones Tecnologicas, http://www.artica.es
* This code is NOT free software. This code is NOT licenced under GPL2 licence
* You cannnot redistribute it without written permission of copyright holder.
* ============================================================================
*/
global $config;
// ACL Check.
check_login();
if (check_acl($config['id_user'], 0, 'PM') === false) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access to Files repository'
);
include 'general/noaccess.php';
return;
}
$tab = get_parameter('tab', '');
$url = 'index.php?sec=extensions&sec2=godmode/files_repo/files_repo';
// Header tabs.
$godmode['text'] = '<a href="'.$url.'&tab=configuration">';
$godmode['text'] .= html_print_image(
'images/configuration@svg.svg',
true,
[
'title' => __('Administration view'),
'class' => 'main_menu_icon invert_filter',
]
);
$godmode['text'] .= '</a>';
$godmode['godmode'] = 1;
$operation['text'] = '<a href="'.$url.'">';
$operation['text'] .= html_print_image(
'images/see-details@svg.svg',
true,
[
'title' => __('Operation view'),
'class' => 'main_menu_icon invert_filter',
]
);
$operation['text'] .= '</a>';
$operation['operation'] = 1;
$operation['active'] = 1;
$godmode['active'] = 0;
if ($tab === 'configuration') {
$godmode['active'] = 1;
$operation['active'] = 0;
}
$onheader = [
'godmode' => $godmode,
'operation' => $operation,
];
// Header.
ui_print_standard_header(
__('Extensions'),
'images/extensions.png',
false,
'',
true,
$onheader,
[
[
'link' => '',
'label' => __('Tools'),
],
[
'link' => '',
'label' => __('Files repository'),
],
]
);
require_once __DIR__.'/../../include/functions_files_repository.php';
// Directory files_repo check.
if (files_repo_check_directory() === false) {
return;
}
$server_content_length = 0;
if (isset($_SERVER['CONTENT_LENGTH'])) {
$server_content_length = $_SERVER['CONTENT_LENGTH'];
}
// Check for an anoying error that causes the $_POST and $_FILES arrays.
// were empty if the file is larger than the post_max_size.
if (intval($server_content_length) > 0 && empty($_POST)) {
ui_print_error_message(
__('Problem uploading. Please check this PHP runtime variable values: <pre> post_max_size (currently '.ini_get('post_max_size').')</pre>')
);
}
// GET and POST parameters.
$file_id = (int) get_parameter('file_id');
$add_file = (bool) get_parameter('add_file');
$update_file = (bool) get_parameter('update_file');
$delete_file = (bool) get_parameter('delete');
// File add or update.
if ($add_file === true || ($update_file === true && $file_id > 0)) {
$groups = get_parameter('groups', []);
$public = (bool) get_parameter('public');
$description = io_safe_output((string) get_parameter('description'));
if (mb_strlen($description, 'UTF-8') > 200) {
$description = mb_substr($description, 0, 200, 'UTF-8');
}
$description = io_safe_input($description);
if ($add_file === true) {
$result = files_repo_add_file('upfile', $description, $groups, $public);
} else if ($update_file === true) {
$result = files_repo_update_file($file_id, $description, $groups, $public);
$file_id = 0;
}
if ($result['status'] == false) {
ui_print_error_message($result['message']);
} else {
if ($add_file === true) {
ui_print_success_message(__('Successfully created'));
} else if ($update_file === true) {
ui_print_success_message(__('Successfully updated'));
}
}
}
// File delete.
if ($delete_file === true && $file_id > 0) {
$result = files_repo_delete_file($file_id);
if ($result !== -1) {
ui_print_result_message($result, __('Successfully deleted'), __('Could not be deleted'));
}
$file_id = 0;
}
$operation['active'] = 1;
if ($tab === 'configuration') {
include_once __DIR__.'/files_repo_form.php';
} else {
include_once __DIR__.'/files_repo_list.php';
}

View File

@ -1,20 +1,27 @@
<?php <?php
/**
* File repository Form
*
* @category Files repository
* @package Pandora FMS
* @subpackage Enterprise
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2007-2023 Artica Soluciones Tecnologicas, http://www.artica.es
* This code is NOT free software. This code is NOT licenced under GPL2 licence
* You cannnot redistribute it without written permission of copyright holder.
* ============================================================================
*/
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
global $config; global $config;
$full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/';
require_once $full_extensions_dir.'files_repo/functions_files_repo.php';
$file = []; $file = [];
$file['name'] = ''; $file['name'] = '';
@ -117,6 +124,10 @@ if ($file_id > 0) {
'file_id', 'file_id',
$file_id, $file_id,
true true
).html_print_input_hidden(
'update_file',
1,
true
) )
); );
} else { } else {
@ -150,8 +161,8 @@ if ($file_id > 0) {
$table->data[] = $row; $table->data[] = $row;
$url = ui_get_full_url('index.php?sec=godmode/extensions&sec2=extensions/files_repo'); $url = ui_get_full_url('index.php?sec=extensions&sec2=godmode/files_repo/files_repo');
echo "<form method='post' action='$url' enctype='multipart/form-data'>"; echo '<form method="post" action="'.$url.'" enctype="multipart/form-data">';
html_print_table($table); html_print_table($table);
html_print_action_buttons($submit_button); html_print_action_buttons($submit_button);
echo '</form>'; echo '</form>';

View File

@ -0,0 +1,153 @@
<?php
/**
* File repository List
*
* @category Files repository
* @package Pandora FMS
* @subpackage Enterprise
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2007-2023 Artica Soluciones Tecnologicas, http://www.artica.es
* This code is NOT free software. This code is NOT licenced under GPL2 licence
* You cannnot redistribute it without written permission of copyright holder.
* ============================================================================
*/
global $config;
$offset = (int) get_parameter('offset');
$filter = [];
$filter['limit'] = $config['block_size'];
$filter['offset'] = $offset;
$filter['order'] = [
'field' => 'id',
'order' => 'DESC',
];
$files = files_repo_get_files($filter);
if (empty($files) === false) {
$url = ui_get_full_url('index.php?sec=extensions&sec2=godmode/files_repo/files_repo');
$total_files = files_repo_get_files(false, true);
ui_pagination($total_files, $url, $offset);
$table = new stdClass();
$table->width = '100%';
$table->class = 'info_table';
$table->style = [];
$table->style[1] = 'max-width: 200px;';
$table->style[4] = 'text-align: center;';
$table->head = [];
$table->head[0] = __('Name');
$table->head[1] = __('Description');
$table->head[2] = __('Size');
$table->head[3] = __('Last modification');
$table->head[4] = '';
$table->data = [];
foreach ($files as $file_id => $file) {
$data = [];
// Prepare the filename for the get_file.php script.
$document_root = str_replace(
'\\',
'/',
io_safe_output($_SERVER['DOCUMENT_ROOT'])
);
$file['location'] = str_replace(
'\\',
'/',
io_safe_output($file['location'])
);
$relative_path = str_replace($document_root, '', $file['location']);
$file_name = explode('/', $file['location']);
$file_decoded = $file_name[(count($file_name) - 1)];
$file_path = base64_encode($file_decoded);
$hash = md5($file_path.$config['server_unique_identifier']);
$url_get_file = ui_get_full_url(
'include/get_file.php?file='.urlencode($file_path).'&hash='.$hash
);
$date_format = (isset($config['date_format']) === true) ? io_safe_output($config['date_format']) : 'F j, Y - H:m';
$data[0] = '<a href="'.$url_get_file.'" target="_blank">'.$file['name'].'</a>';
// Name.
$data[1] = ui_print_truncate_text(
$file['description'],
'description',
true,
true
);
// Description.
$data[2] = ui_format_filesize($file['size']);
// Size.
$data[3] = date($date_format, $file['mtime']);
// Last modification.
// Public URL.
$data[4] = '';
$table->cellclass[][4] = 'table_action_buttons';
if (empty($file['hash']) === false) {
$message = __('Copy to clipboard').': Ctrl+C -> Enter';
$action = 'window.prompt(\''.$message.'\', \''.$url_get_file.'\');';
$data[4] .= '<a href="javascript:;" onclick="'.$action.'">';
$data[4] .= html_print_image(
'images/world.png',
true,
['title' => __('Public link')]
);
// Public link image.
$data[4] .= '</a> ';
}
$data[4] .= '<a href="'.$url_get_file.'" target="_blank">';
$data[4] .= html_print_image(
'images/download.png',
true,
[
'title' => __('Download'),
'style' => 'padding:3px',
]
);
// Download image.
$data[4] .= '</a>';
$config_url = $url.'&tab=configuration&file_id='.$file_id;
$data[4] .= '<a href="'.$config_url.'">';
$data[4] .= html_print_image(
'images/edit.svg',
true,
[
'title' => __('Edit'),
'class' => 'main_menu_icon invert_filter',
]
);
// Edit image.
$data[4] .= '</a>';
$delete_url = $url.'&delete=1&file_id='.$file_id;
$data[4] .= '<a href="'.$delete_url.'" onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">';
$data[4] .= html_print_image(
'images/delete.svg',
true,
[
'title' => __('Delete'),
'class' => 'main_menu_icon invert_filter',
]
);
// Delete image.
$data[4] .= '</a>';
$table->data[] = $data;
}
html_print_table($table);
} else {
ui_print_info_message(__('No items'));
}

View File

@ -508,6 +508,8 @@ if ($access_console_node === true) {
enterprise_hook('skins_submenu'); enterprise_hook('skins_submenu');
enterprise_hook('translate_string_submenu');
$menu_godmode['gsetup']['sub'] = $sub; $menu_godmode['gsetup']['sub'] = $sub;
} }
} }

View File

@ -169,13 +169,21 @@ function extensions_get_extensions($enterprise=false, $rel_path='')
$file = readdir($handle); $file = readdir($handle);
} }
// Load extensions in enterprise directory if (isset($extensions['ipam.php']) === true) {
if (! $enterprise && file_exists($master_dir)) { unset($extensions['ipam.php']);
return array_merge($extensions, extensions_get_extensions(true, $rel_path));
} }
if (isset($extensions['ipam.php'])) { if (isset($extensions['translate_string.php']) === true) {
unset($extensions['ipam.php']); unset($extensions['translate_string.php']);
}
if (isset($extensions['files_repo.php']) === true) {
unset($extensions['files_repo.php']);
}
// Load extensions in enterprise directory.
if (! $enterprise && file_exists($master_dir)) {
return array_merge($extensions, extensions_get_extensions(true, $rel_path));
} }
return $extensions; return $extensions;

View File

@ -1,17 +1,34 @@
<?php <?php
/**
* Functions File repository
*
* @category Files repository
* @package Pandora FMS
* @subpackage Enterprise
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2007-2023 Artica Soluciones Tecnologicas, http://www.artica.es
* This code is NOT free software. This code is NOT licenced under GPL2 licence
* You cannnot redistribute it without written permission of copyright holder.
* ============================================================================
*/
// Pandora FMS - https://pandorafms.com global $config;
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list /**
// This program is free software; you can redistribute it and/or * Check repository writable.
// modify it under the terms of the GNU General Public License *
// as published by the Free Software Foundation; version 2 * @return mixed
// This program is distributed in the hope that it will be useful, */
// but WITHOUT ANY WARRANTY; without even the implied warranty of function files_repo_check_directory()
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
function files_repo_check_directory($print_messages=false)
{ {
global $config; global $config;
@ -21,11 +38,18 @@ function files_repo_check_directory($print_messages=false)
$result = false; $result = false;
$messages = ''; $messages = '';
// attachment/ check $msg_error = __('Attachment directory is not writable by HTTP Server');
if (!is_writable($attachment_path)) { $msg_error .= '</h3><p>';
$msg_error .= sprintf(
__('Please check that the web server has write rights on the %s directory'),
$attachment_path
);
// Attachment/ check.
if (is_writable($attachment_path) === false) {
$messages .= ui_print_error_message( $messages .= ui_print_error_message(
[ [
'message' => __('Attachment directory is not writable by HTTP Server').'</h3>'.'<p>'.sprinf(__('Please check that the web server has write rights on the %s directory'), $attachment_path), 'message' => $msg_error,
'no_close' => true, 'no_close' => true,
'force_style' => 'color: #000000 !important', 'force_style' => 'color: #000000 !important',
], ],
@ -33,17 +57,17 @@ function files_repo_check_directory($print_messages=false)
true true
); );
} else { } else {
// attachment/agent_packages/ check // Attachment/agent_packages/ check.
if (!file_exists($files_repo_path) || !is_writable($files_repo_path)) { if (file_exists($files_repo_path) === false || is_writable($files_repo_path) === false) {
// Create the directoty if not exist // Create the directoty if not exist.
if (!file_exists($files_repo_path)) { if (file_exists($files_repo_path) === false) {
mkdir($files_repo_path); mkdir($files_repo_path);
} }
if (!is_writable($files_repo_path)) { if (is_writable($files_repo_path) === false) {
$messages .= ui_print_error_message( $messages .= ui_print_error_message(
[ [
'message' => __('Attachment directory is not writable by HTTP Server').'</h3>'.'<p>'.sprintf(__('Please check that the web server has write rights on the %s directory'), $attachment_path), 'message' => $msg_error,
'no_close' => true, 'no_close' => true,
'force_style' => 'color: #000000 !important', 'force_style' => 'color: #000000 !important',
], ],
@ -58,48 +82,60 @@ function files_repo_check_directory($print_messages=false)
} }
} }
if ($print_messages) { echo $messages;
echo $messages;
}
return $result; return $result;
} }
function files_repo_check_file_acl($file_id, $user_id=false, $file_groups=false, $user_groups=false) /**
{ * Check acl file
*
* @param integer $file_id ID.
* @param boolean $user_id Users.
* @param boolean $file_groups File Groups.
* @param boolean $user_groups User Groups.
*
* @return boolean
*/
function files_repo_check_file_acl(
$file_id,
$user_id=false,
$file_groups=false,
$user_groups=false
) {
global $config; global $config;
$result = false; $result = false;
if (!$user_id) { if (empty($user_id) === true) {
$user_id = $config['id_user']; $user_id = $config['id_user'];
} }
if (is_user_admin($user_id)) { if (is_user_admin($user_id) === true) {
return true; return true;
} }
if (!$file_groups) { if (!$file_groups) {
$file_groups = files_repo_get_file_groups($file_id); $file_groups = files_repo_get_file_groups($file_id);
if (empty($file_groups)) { if (empty($file_groups) === true) {
$file_groups = []; $file_groups = [];
} }
} }
if (in_array(0, $file_groups)) { if (in_array(0, $file_groups) === true) {
return true; return true;
} }
if (!$user_groups) { if (!$user_groups) {
$user_groups = users_get_groups($user_id, false, true); $user_groups = users_get_groups($user_id, false, true);
if (empty($user_groups)) { if (empty($user_groups) === true) {
$user_groups = []; $user_groups = [];
} }
} }
foreach ($file_groups as $group_id) { foreach ($file_groups as $group_id) {
// $user_groups has the id in the array keys // $user_groups has the id in the array keys.
if (in_array($group_id, $user_groups)) { if (in_array($group_id, $user_groups) === true) {
$result = true; $result = true;
break; break;
} }
@ -109,13 +145,19 @@ function files_repo_check_file_acl($file_id, $user_id=false, $file_groups=false,
} }
/**
* File groups.
*
* @param integer $file_id File.
*
* @return array
*/
function files_repo_get_file_groups($file_id) function files_repo_get_file_groups($file_id)
{ {
$groups = []; $groups = [];
$filter = ['id_file' => $file_id]; $filter = ['id_file' => $file_id];
$result = db_get_all_rows_filter('tfiles_repo_group', $filter, 'id_group'); $result = db_get_all_rows_filter('tfiles_repo_group', $filter, 'id_group');
if (empty($result) === false) {
if (!empty($result)) {
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
$groups[] = $value['id_group']; $groups[] = $value['id_group'];
} }
@ -125,13 +167,19 @@ function files_repo_get_file_groups($file_id)
} }
/**
* File user groups.
*
* @param string $user_id User id.
*
* @return array
*/
function files_repo_get_user_groups($user_id) function files_repo_get_user_groups($user_id)
{ {
$groups = []; $groups = [];
$filter = ['id_usuario' => $user_id]; $filter = ['id_usuario' => $user_id];
$result = db_get_all_rows_filter('tusuario_perfil', $filter, 'id_grupo'); $result = db_get_all_rows_filter('tusuario_perfil', $filter, 'id_grupo');
if (empty($result) === false) {
if (!empty($result)) {
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
$groups[] = $value['id_grupo']; $groups[] = $value['id_grupo'];
} }
@ -141,7 +189,15 @@ function files_repo_get_user_groups($user_id)
} }
function files_repo_get_files($filter=false, $count=false) /**
* Get files.
*
* @param array $filter Filters.
* @param boolean $count Count.
*
* @return array
*/
function files_repo_get_files($filter=[], $count=false)
{ {
global $config; global $config;
@ -171,9 +227,9 @@ function files_repo_get_files($filter=false, $count=false)
$data['name'] = $file['name']; $data['name'] = $file['name'];
$data['description'] = $file['description']; $data['description'] = $file['description'];
$data['location'] = $files_repo_path.'/'.$file['id'].'_'.$data['name']; $data['location'] = $files_repo_path.'/'.$file['id'].'_'.$data['name'];
// Size in bytes // Size in bytes.
$data['size'] = filesize($data['location']); $data['size'] = filesize($data['location']);
// Last modification time in unix timestamp // Last modification time in unix timestamp.
$data['mtime'] = filemtime($data['location']); $data['mtime'] = filemtime($data['location']);
$data['groups'] = $file_groups; $data['groups'] = $file_groups;
$data['hash'] = $file['hash']; $data['hash'] = $file['hash'];
@ -188,6 +244,16 @@ function files_repo_get_files($filter=false, $count=false)
} }
/**
* Add file.
*
* @param string $file_input_name Name.
* @param string $description Description.
* @param array $groups Groups.
* @param boolean $public Mode.
*
* @return array
*/
function files_repo_add_file($file_input_name='upfile', $description='', $groups=[], $public=false) function files_repo_add_file($file_input_name='upfile', $description='', $groups=[], $public=false)
{ {
global $config; global $config;
@ -210,10 +276,10 @@ function files_repo_add_file($file_input_name='upfile', $description='', $groups
$invalid_extensions = '/^(php|php1|php2|php3|php4|php5|php7|php8|phar|phptml|phps)$/i'; $invalid_extensions = '/^(php|php1|php2|php3|php4|php5|php7|php8|phar|phptml|phps)$/i';
if (preg_match($invalid_extensions, $extension) === 0) { if (preg_match($invalid_extensions, $extension) === 0) {
// Replace conflictive characters // Replace conflictive characters.
$filename = str_replace([' ', '=', '?', '&'], '_', $filename); $filename = str_replace([' ', '=', '?', '&'], '_', $filename);
$filename = filter_var($filename, FILTER_SANITIZE_URL); $filename = filter_var($filename, FILTER_SANITIZE_URL);
// The filename should not be larger than 200 characters // The filename should not be larger than 200 characters.
if (mb_strlen($filename, 'UTF-8') > 200) { if (mb_strlen($filename, 'UTF-8') > 200) {
$filename = mb_substr($filename, 0, 200, 'UTF-8'); $filename = mb_substr($filename, 0, 200, 'UTF-8');
} }
@ -267,6 +333,16 @@ function files_repo_add_file($file_input_name='upfile', $description='', $groups
} }
/**
* Update file.
*
* @param string $file_id File Name.
* @param string $description Description.
* @param array $groups Groups.
* @param boolean $public Mode.
*
* @return array
*/
function files_repo_update_file($file_id, $description='', $groups=[], $public=false) function files_repo_update_file($file_id, $description='', $groups=[], $public=false)
{ {
global $config; global $config;
@ -308,6 +384,13 @@ function files_repo_update_file($file_id, $description='', $groups=[], $public=f
} }
/**
* Delete File
*
* @param string $file_id File Name.
*
* @return mixed
*/
function files_repo_delete_file($file_id) function files_repo_delete_file($file_id)
{ {
global $config; global $config;

View File

@ -410,32 +410,14 @@ function __($string /*, variable arguments */)
global $config; global $config;
if (defined('METACONSOLE')) { enterprise_include_once('include/functions_setup.php');
enterprise_include_once('meta/include/functions_meta.php'); $tranlateString = call_user_func_array(
'get_defined_translation',
array_values(func_get_args())
);
$tranlateString = call_user_func_array( if ($tranlateString !== false) {
'meta_get_defined_translation', return $tranlateString;
array_values(func_get_args())
);
if ($tranlateString !== false) {
return $tranlateString;
}
} else if (enterprise_installed()
&& isset($config['translate_string_extension_installed'])
&& $config['translate_string_extension_installed'] == 1
&& array_key_exists('translate_string.php', $extensions)
) {
enterprise_include_once('extensions/translate_string/functions.php');
$tranlateString = call_user_func_array(
'get_defined_translation',
array_values(func_get_args())
);
if ($tranlateString !== false) {
return $tranlateString;
}
} }
if ($string == '') { if ($string == '') {

View File

@ -82,10 +82,9 @@ if (empty($file) === true || empty($hash) === true || $hash !== md5($file_raw.$c
$downloadable_file = $_SERVER['DOCUMENT_ROOT'].'/pandora_console/'.$file; $downloadable_file = $_SERVER['DOCUMENT_ROOT'].'/pandora_console/'.$file;
break; break;
case 'extensions/files_repo': case 'godmode/files_repo/files_repo':
$attachment_path = io_safe_output($config['attachment_store']); $attachment_path = io_safe_output($config['attachment_store']);
$downloadable_file = $attachment_path.'/files_repo/'.$file; $downloadable_file = $attachment_path.'/files_repo/'.$file;
// $downloadable_file = $_SERVER['DOCUMENT_ROOT'].'/pandora_console/attachment/files_repo/'.$file;
break; break;
case 'godmode/servers/plugin': case 'godmode/servers/plugin':

View File

@ -752,6 +752,11 @@ if ($access_console_node === true) {
$sub['godmode/agentes/planned_downtime.list']['id'] = 'Scheduled_downtime'; $sub['godmode/agentes/planned_downtime.list']['id'] = 'Scheduled_downtime';
} }
if ((bool) check_acl($config['id_user'], 0, 'PM') === true) {
$sub['godmode/files_repo/files_repo']['text'] = __('File Repository');
$sub['godmode/files_repo/files_repo']['id'] = 'File_repository';
}
foreach ($config['extensions'] as $extension) { foreach ($config['extensions'] as $extension) {
// If no operation_menu is a godmode extension. // If no operation_menu is a godmode extension.
if ($extension['operation_menu'] == '') { if ($extension['operation_menu'] == '') {

View File

@ -4532,4 +4532,26 @@ CREATE TABLE IF NOT EXISTS `tpandora_cve` (
`cvss_score` DOUBLE DEFAULT NULL, `cvss_score` DOUBLE DEFAULT NULL,
`cvss_vector` VARCHAR(255) DEFAULT NULL, `cvss_vector` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`cve_id`) PRIMARY KEY (`cve_id`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ---------------------------------------------------------------------
-- Table `tfiles_repo`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tfiles_repo` (
`id` int(5) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`description` varchar(500) NULL default '',
`hash` varchar(8) NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ---------------------------------------------------------------------
-- Table `tfiles_repo_group`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tfiles_repo_group` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_file` int(5) unsigned NOT NULL,
`id_group` int(4) unsigned NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_file`) REFERENCES tfiles_repo(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;