2012-08-20 Miguel de Dios <miguel.dedios@artica.es>

* godmode/reporting/reporting_builder.main.php,
	godmode/reporting/reporting_builder.php,
	include/functions_reports.php, pandoradb.sql,
	pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
	operation/reporting/reporting_xml.php,
	operation/reporting/reporting_viewer.php,
	extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
	extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
	extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql: now the reports
	can set the group can edit or private edition.
	
	* include/functions_users.php: cleaned source code style.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6889 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-08-20 13:12:53 +00:00
parent 9c42aaad7d
commit 5c42c87962
13 changed files with 378 additions and 175 deletions

View File

@ -1,3 +1,18 @@
2012-08-20 Miguel de Dios <miguel.dedios@artica.es>
* godmode/reporting/reporting_builder.main.php,
godmode/reporting/reporting_builder.php,
include/functions_reports.php, pandoradb.sql,
pandoradb.postgreSQL.sql, pandoradb.oracle.sql,
operation/reporting/reporting_xml.php,
operation/reporting/reporting_viewer.php,
extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql: now the reports
can set the group can edit or private edition.
* include/functions_users.php: cleaned source code style.
2012-08-20 Sergio Martin <sergio.martin@artica.es>
* pandoradb_data.sql

View File

@ -169,6 +169,7 @@ ALTER TABLE treport_content_item ADD FOREIGN KEY (`id_report_content`) REFERENCE
-- Table `treport`
-- -----------------------------------------------------
ALTER TABLE treport ADD COLUMN `id_template` INTEGER UNSIGNED DEFAULT 0;
ALTER TABLE treport ADD COLUMN `id_group_edit` mediumint(8) unsigned NULL DEFAULT 0;
-- -----------------------------------------------------
-- Table `tgraph`

View File

@ -158,6 +158,7 @@ ALTER TABLE treport_content_item ADD FOREIGN KEY (id_report_content) REFERENCES
-- Table `treport`
-- -----------------------------------------------------
ALTER TABLE treport ADD (id_template NUMBER(10, 0) default 0 NOT NULL);
ALTER TABLE treport ADD (id_group_edit NUMBER(19, 0) default 0 NOT NULL);
-- -----------------------------------------------------
-- Table `tgraph`

View File

@ -150,6 +150,7 @@ INSERT INTO "tconfig" ("token", "value") VALUES ('event_fields', 'evento,id_agen
-- Table `treport`
-- -----------------------------------------------------
ALTER TABLE "treport" ADD COLUMN "id_template" INTEGER NOT NULL default 0;
ALTER TABLE "treport" ADD COLUMN "id_group_edit" BIGINT NOT NULL default 0;
-- -----------------------------------------------------
-- Table `tgraph`

View File

@ -29,12 +29,14 @@ $groups = users_get_groups ();
switch ($action) {
case 'new':
$actionButtonHtml = html_print_submit_button(__('Save'), 'add', false, 'class="sub wand"', true);
$actionButtonHtml = html_print_submit_button(__('Save'),
'add', false, 'class="sub wand"', true);
$hiddenFieldAction = 'save';
break;
case 'update':
case 'edit':
$actionButtonHtml = html_print_submit_button(__('Update'), 'edit', false, 'class="sub upd"', true);
$actionButtonHtml = html_print_submit_button(__('Update'),
'edit', false, 'class="sub upd"', true);
$hiddenFieldAction = 'update';
break;
}
@ -46,12 +48,13 @@ $table->head = array ();
$table->data = array ();
$table->size = array ();
$table->size = array ();
$table->size[0] = '10%';
$table->size[0] = '15%';
$table->size[1] = '90%';
$table->style[0] = 'font-weight: bold; vertical-align: top;';
$table->data['name'][0] = __('Name');
$table->data['name'][1] = html_print_input_text('name', $reportName, __('Name'), 80, 100, true);
$table->data['name'][1] = html_print_input_text('name', $reportName,
__('Name'), 80, 100, true);
$table->data['group'][0] = __('Group');
$own_info = get_user_info ($config['id_user']);
@ -61,6 +64,29 @@ else
$return_all_groups = false;
$table->data['group'][1] = html_print_select_groups(false, "AR", $return_all_groups, 'id_group', $idGroupReport, false, '', '', true);
if ($report_id_user == $config['id_user'] ||
is_user_admin ($config["id_user"])) {
//S/he is the creator of report (or admin) and s/he can change the access.
$type_access = array('group_view' => __('Only the group can view the report'),
'group_edit' => __('The next group can edit the report'),
'user_edit' => __('Only the user and admin user can edit the report')
);
$table->data['access'][0] = __('Write Access') .
ui_print_help_tip(__('For example, you want a report that the people of "All" groups can see but you want to edit only for you or your group.'), true);
$table->data['access'][1] = html_print_select ($type_access, 'type_access',
$type_access_selected, 'change_type_access(this)', '', 0, true);
$style = "display: none;";
if ($type_access_selected == 'group_edit')
$style = "";
$table->data['access'][1] .= '<span style="' . $style . '" class="access_subform" id="group_edit">
' .
html_print_select_groups(false, "AR", false,
'id_group_edit', $id_group_edit, false, '', '', true) . '
</span>';
}
$table->data['description'][0] = __('Description');
$table->data['description'][1] = html_print_textarea('description', 5, 15, $description, '', true);
@ -73,3 +99,17 @@ html_print_input_hidden('action', $hiddenFieldAction);
html_print_input_hidden('id_report', $idReport);
echo '</div></form>';
?>
<script type="text/javascript">
function change_type_access(select_item) {
$(".access_subform").hide();
switch ($(select_item).val()) {
case 'group_view':
break;
case 'group_edit':
$("#group_edit").show();
break;
case 'user_edit':
break;
}
}
</script>

View File

@ -42,6 +42,32 @@ $idReport = get_parameter('id_report', 0);
$offset = get_parameter('offset', 0);
$idItem = get_parameter('id_item', 0);
//Other Checks for the edit the reports
if ($idReport != 0) {
$report = db_get_row_filter('treport', array('id_report' => $idReport));
$type_access_selected = reports_get_type_access($report);
$edit = false;
switch ($type_access_selected) {
case 'group_view':
$edit = check_acl($config['id_user'], $report['id_group'], "IW");
break;
case 'group_edit':
$edit = check_acl($config['id_user'], $report['id_group_edit'], "IW");
break;
case 'user_edit':
if ($config['id_user'] == $report['id_user'] ||
is_user_admin ($config["id_user"]))
$edit = true;
break;
}
if (! $edit) {
db_pandora_audit("ACL Violation",
"Trying to access report builder");
require ("general/noaccess.php");
exit;
}
}
switch ($action) {
case 'sort_items':
switch ($activeTab) {
@ -325,7 +351,6 @@ switch ($action) {
}
foreach ($reports as $report) {
if (!is_user_admin ($config["id_user"])){
if ($report["private"] && $report["id_user"] != $config['id_user'])
if (!check_acl ($config["id_user"], $report["id_group"], "AR"))
@ -371,6 +396,23 @@ switch ($action) {
$data[$next] = ui_print_group_icon($report['id_group'], true);
$next++;
$type_access_selected = reports_get_type_access($report);
$edit = false;
switch ($type_access_selected) {
case 'group_view':
$edit = check_acl($config['id_user'], $report['id_group'], "IW");
break;
case 'group_edit':
$edit = check_acl($config['id_user'], $report['id_group_edit'], "IW");
break;
case 'user_edit':
if ($config['id_user'] == $report['id_user'] ||
is_user_admin ($config["id_user"]))
$edit = true;
break;
}
if ($edit) {
$data[$next] = '<form method="post" action="index.php?sec=reporting&sec2=godmode/reporting/reporting_builder&action=edit" style="display:inline">';
$data[$next] .= html_print_input_hidden ('id_report', $report['id_report'], true);
$data[$next] .= html_print_input_image ('edit', 'images/config.png', 1, '', true, array ('title' => __('Edit')));
@ -383,6 +425,7 @@ switch ($action) {
true, array ('title' => __('Delete')));
$data[$next] .= '</form>';
}
}
array_push ($table->data, $data);
@ -410,6 +453,9 @@ switch ($action) {
$idGroupReport = 0; //All groups
$description = '';
$resultOperationDB = null;
$report_id_user = 0;
$type_access_selected = reports_get_type_access(false);
$id_group_edit = 0;
break;
case 'item_editor':
$resultOperationDB = null;
@ -428,10 +474,45 @@ switch ($action) {
$reportName = get_parameter('name');
$idGroupReport = get_parameter('id_group');
$description = get_parameter('description');
$type_access_selected = get_parameter('type_access', 'group_view');
$id_group_edit_param = (int)get_parameter('id_group_edit', 0);
switch ($type_access_selected) {
case 'group_view':
$id_group_edit = 0;
$private = 0;
break;
case 'group_edit':
$id_group_edit = $id_group_edit_param;
$private = 0;
break;
case 'user_edit':
$id_group_edit = 0;
$private = 1;
break;
}
if ($action == 'update') {
if ($reportName != "" && $idGroupReport != ""){
$resultOperationDB = (bool)db_process_sql_update('treport', array('name' => $reportName, 'id_group' => $idGroupReport, 'description' => $description), array('id_report' => $idReport));
if ($reportName != "" && $idGroupReport != "") {
$new_values = array('name' => $reportName,
'id_group' => $idGroupReport,
'description' => $description,
'private' => $private,
'id_group_edit' => $id_group_edit);
$report = db_get_row_filter('treport',
array('id_report' => $idReport));
$report_id_user = $report['id_user'];
if ($report_id_user != $config['id_user'] &&
is_user_admin ($config["id_user"])) {
unset($new_values['private']);
unset($new_values['id_group_edit']);
}
$resultOperationDB = (bool)db_process_sql_update(
'treport', $new_values,
array('id_report' => $idReport));
if ($resultOperationDB !== false)
db_pandora_audit( "Report management", "Update report #$idReport");
else
@ -442,8 +523,14 @@ switch ($action) {
}
}
else if ($action == 'save') {
if($reportName != "" && $idGroupReport != "") {
$idOrResult = db_process_sql_insert('treport', array('name' => $reportName, 'id_group' => $idGroupReport, 'description' => $description));
if ($reportName != "" && $idGroupReport != "") {
$idOrResult = db_process_sql_insert('treport',
array('name' => $reportName,
'id_group' => $idGroupReport,
'description' => $description,
'private' => $private,
'id_group_edit' => $id_group_edit,
'id_user' => $config['id_user']));
if ($idOrResult !== false)
db_pandora_audit( "Report management", "Create report #$idOrResult");
else
@ -459,6 +546,7 @@ switch ($action) {
else {
$resultOperationDB = true;
$idReport = $idOrResult;
$report_id_user = $config['id_user'];
}
}
$action = 'edit';
@ -599,7 +687,6 @@ switch ($action) {
$agent_name = substr($agent_name_server, 0, $separator_pos);
}
}
}
@ -780,7 +867,7 @@ switch ($action) {
$style['show_in_landscape'] = get_parameter('show_in_landscape', 0);
$values['style'] = io_safe_input(json_encode($style));
if ($good_format){
if ($good_format) {
$result = db_process_sql_insert('treport_content', $values);
if ($result === false) {
@ -835,11 +922,15 @@ switch ($action) {
case 'filter':
case 'edit':
$resultOperationDB = null;
$report = db_get_row_filter('treport', array('id_report' => $idReport));
$report = db_get_row_filter('treport',
array('id_report' => $idReport));
$reportName = $report['name'];
$idGroupReport = $report['id_group'];
$description = $report['description'];
$type_access_selected = reports_get_type_access($report);
$id_group_edit = $report['id_group_edit'];
$report_id_user = $report['id_user'];
break;
case 'delete':
$idItem = get_parameter('id_item');

View File

@ -21,6 +21,20 @@
require_once ($config['homedir'].'/include/functions_users.php');
function reports_get_type_access($report) {
if (empty($report)) {
return 'group_view';
}
if ($report['private']) {
return 'user_edit';
}
else if ($report['id_group_edit'] != 0) {
return 'group_edit';
}
return 'group_view';
}
/**
* Get a custom user report.
*
@ -73,12 +87,15 @@ function reports_get_reports ($filter = false, $fields = false, $returnAllGroup
if (! is_array ($filter))
$filter = array ();
/*
if (!is_user_admin ($config["id_user"]))
$filter[] = sprintf ('private = 0 OR (private = 1 AND id_user = "%s")',
$config['id_user']);
*/
if (is_array ($fields)) {
$fields[] = 'id_group';
$fields[] = 'id_user';
$fields[] = 'id_group_edit';
}
$reports = array ();

View File

@ -43,8 +43,8 @@ require_once ('include/functions_groups.php');
enterprise_include("include/functions_reporting.php");
// Check if the report is a private report.
if ($report['private'] && ($report['id_user'] != $config['id_user'] && ! is_user_admin ($config['id_user']))) {
if ($report['id_group'] != 0 &&
!is_user_admin ($config['id_user'])) {
include ("general/noaccess.php");
return;
}

View File

@ -129,8 +129,9 @@ if (! check_acl ($config['id_user'], $report['id_group'], "AR")) {
exit;
}
/* Check if the user can see the graph */
if ($report['private'] && ($report['id_user'] != $config['id_user'] && ! is_user_admin($config['id_user']))) {
if ($report['id_group'] != 0 &&
!is_user_admin ($config['id_user'])) {
include ("general/noaccess.php");
return;
}

View File

@ -960,7 +960,8 @@ CREATE TABLE treport (
first_page CLOB default NULL,
footer CLOB default NULL,
custom_font VARCHAR2(200) default NULL,
id_template NUMBER(10, 0) default 0 NOT NULL
id_template NUMBER(10, 0) default 0 NOT NULL,
id_group_edit NUMBER(19, 0) default 0 NOT NULL
);
CREATE SEQUENCE treport_s INCREMENT BY 1 START WITH 1;

View File

@ -762,6 +762,9 @@ CREATE TABLE "tgraph_source" (
"weight" DOUBLE PRECISION default 0
);
-- -----------------------------------------------------
-- Table "treport"
-- -----------------------------------------------------
CREATE TABLE "treport" (
"id_report" SERIAL NOT NULL PRIMARY KEY,
"id_user" varchar(100) NOT NULL default '',
@ -774,7 +777,8 @@ CREATE TABLE "treport" (
"first_page" TEXT default NULL,
"footer" TEXT default NULL,
"custom_font" varchar(200) default NULL,
"id_template" BIGINT NOT NULL default 0
"id_template" BIGINT NOT NULL default 0,
"id_group_edit" BIGINT NOT NULL default 0
);
-- -----------------------------------------------------

View File

@ -149,6 +149,10 @@ CREATE TABLE `tagente_estado` (
-- Probably last_execution_try index is not useful and loads more than benefits
-- -----------------------------------------------------
-- Table `tagente_modulo`
-- -----------------------------------------------------
-- id_modulo now uses tmodule
-- ---------------------------
-- 1 - Data server modules (agent related modules)
@ -221,9 +225,11 @@ CREATE TABLE IF NOT EXISTS `tagente_modulo` (
KEY `nombre` (`nombre` (255)),
KEY `module_group` (`id_module_group`) using btree
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- snmp_oid is also used for WMI query
-- -----------------------------------------------------
-- Table `tagent_access`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tagent_access` (
`id_agent` int(10) unsigned NOT NULL default '0',
`utimestamp` bigint(20) NOT NULL default '0',
@ -231,6 +237,9 @@ CREATE TABLE IF NOT EXISTS `tagent_access` (
KEY `idx_utimestamp` USING BTREE (`utimestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `talert_snmp`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `talert_snmp` (
`id_as` int(10) unsigned NOT NULL auto_increment,
`id_alert` int(10) unsigned NOT NULL default '0',
@ -260,6 +269,9 @@ CREATE TABLE IF NOT EXISTS `talert_snmp` (
PRIMARY KEY (`id_as`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `talert_commands`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `talert_commands` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL default '',
@ -269,6 +281,9 @@ CREATE TABLE IF NOT EXISTS `talert_commands` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `talert_actions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `talert_actions` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` text,
@ -283,6 +298,9 @@ CREATE TABLE IF NOT EXISTS `talert_actions` (
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `talert_templates`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `talert_templates` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` text,
@ -320,6 +338,9 @@ CREATE TABLE IF NOT EXISTS `talert_templates` (
ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `talert_template_modules`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `talert_template_modules` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_agent_module` int(10) unsigned NOT NULL,
@ -343,6 +364,9 @@ CREATE TABLE IF NOT EXISTS `talert_template_modules` (
INDEX force_execution (`force_execution`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `talert_template_module_actions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `talert_template_module_actions` (
`id` int(10) unsigned NOT NULL auto_increment,
`id_alert_template_module` int(10) unsigned NOT NULL,
@ -358,6 +382,9 @@ CREATE TABLE IF NOT EXISTS `talert_template_module_actions` (
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `talert_compound`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `talert_compound` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) default '',
@ -858,6 +885,9 @@ CREATE TABLE IF NOT EXISTS `tgraph_source` (
PRIMARY KEY(`id_gs`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `treport`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `treport` (
`id_report` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`id_user` varchar(100) NOT NULL default '',
@ -871,6 +901,7 @@ CREATE TABLE IF NOT EXISTS `treport` (
`footer` MEDIUMTEXT,
`custom_font` varchar(200) default NULL,
`id_template` INTEGER UNSIGNED DEFAULT 0,
`id_group_edit` mediumint(8) unsigned NULL DEFAULT 0,
PRIMARY KEY(`id_report`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8;