2012-10-09 18:05:32 +02:00
< ? php
2021-11-04 16:28:15 +01:00
// Pandora FMS - http://pandorafms.com
2012-10-09 18:05:32 +02:00
// ==================================================
2020-11-27 13:52:35 +01:00
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
2012-10-09 18:05:32 +02:00
// Please see http://pandorafms.org 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.
2015-06-08 13:13:09 +02:00
global $config ;
2012-10-09 18:05:32 +02:00
2019-01-30 16:18:44 +01:00
check_login ();
2012-10-09 18:05:32 +02:00
2019-01-30 16:18:44 +01:00
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'PM' )) {
db_pandora_audit (
2022-01-20 10:55:23 +01:00
AUDIT_LOG_ACL_VIOLATION ,
2019-01-30 16:18:44 +01:00
'Trying to access Group Management'
);
include 'general/noaccess.php' ;
return ;
2012-10-09 18:05:32 +02:00
}
2013-04-24 16:27:24 +02:00
$meta = false ;
2019-01-30 16:18:44 +01:00
if ( enterprise_installed () && defined ( 'METACONSOLE' )) {
$meta = true ;
2013-04-24 16:27:24 +02:00
}
$class_description = 'response_description' ;
if ( $meta ) {
2019-01-30 16:18:44 +01:00
$class_description = 'response_description_metaconsole' ;
2013-04-24 16:27:24 +02:00
}
2019-01-30 16:18:44 +01:00
$event_response_id = get_parameter ( 'id_response' , 0 );
2012-10-09 18:05:32 +02:00
2013-04-24 16:27:24 +02:00
if ( $event_response_id > 0 ) {
2019-01-30 16:18:44 +01:00
$event_response = db_get_row ( 'tevent_response' , 'id' , $event_response_id );
2020-10-22 12:00:44 +02:00
// ACL check for event response edition.
if ( ! check_acl_restricted_all ( $config [ 'id_user' ], $event_response [ 'id_group' ], 'PM' )) {
db_pandora_audit (
2022-01-20 10:55:23 +01:00
AUDIT_LOG_ACL_VIOLATION ,
2020-10-22 12:00:44 +02:00
'Trying to access Group Management'
);
include 'general/noaccess.php' ;
return ;
}
2019-01-30 16:18:44 +01:00
} else {
$event_response = [];
$event_response [ 'name' ] = '' ;
$event_response [ 'description' ] = '' ;
$event_response [ 'id_group' ] = 0 ;
$event_response [ 'type' ] = '' ;
$event_response [ 'target' ] = '' ;
$event_response [ 'id' ] = 0 ;
$event_response [ 'new_window' ] = 1 ;
$event_response [ 'modal_width' ] = 0 ;
$event_response [ 'modal_height' ] = 0 ;
$event_response [ 'params' ] = '' ;
$event_response [ 'server_to_exec' ] = '' ;
2019-12-10 11:54:30 +01:00
$event_response [ 'command_timeout' ] = 90 ;
2012-10-09 18:05:32 +02:00
}
2015-06-25 10:07:53 +02:00
$table = new stdClass ();
2015-06-16 16:09:50 +02:00
$table -> width = '100%' ;
$table -> class = 'databox filters' ;
2012-10-09 18:05:32 +02:00
2019-01-30 16:18:44 +01:00
if ( is_metaconsole ()) {
$table -> head [ 0 ] = __ ( 'Edit event responses' );
$table -> head_colspan [ 0 ] = 5 ;
$table -> headstyle [ 0 ] = 'text-align: center' ;
2015-03-06 12:28:05 +01:00
}
2019-01-30 16:18:44 +01:00
$table -> size = [];
2012-10-09 18:05:32 +02:00
$table -> style [ 0 ] = 'font-weight: bold;' ;
$table -> style [ 2 ] = 'font-weight: bold;' ;
2019-01-30 16:18:44 +01:00
$table -> data = [];
2012-10-09 18:05:32 +02:00
2019-01-30 16:18:44 +01:00
$data = [];
2012-10-09 18:05:32 +02:00
$data [ 0 ] = __ ( 'Name' );
2019-01-30 16:18:44 +01:00
$data [ 1 ] = html_print_input_text (
'name' ,
$event_response [ 'name' ],
'' ,
50 ,
255 ,
2022-02-08 10:58:23 +01:00
true ,
false ,
2019-01-30 16:18:44 +01:00
true
);
$data [ 1 ] .= html_print_input_hidden ( 'id_response' , $event_response [ 'id' ], true );
2012-10-09 18:05:32 +02:00
2020-10-22 12:00:44 +02:00
$return_all_group = false ;
if ( users_can_manage_group_all ( 'PM' ) === true ) {
$return_all_group = true ;
}
2012-10-09 18:05:32 +02:00
$data [ 2 ] = __ ( 'Group' );
2020-10-22 12:00:44 +02:00
$data [ 3 ] = html_print_select_groups ( false , 'PM' , $return_all_group , 'id_group' , $event_response [ 'id_group' ], '' , '' , '' , true );
2012-10-09 18:05:32 +02:00
$table -> data [ 0 ] = $data ;
2019-01-30 16:18:44 +01:00
$data = [];
2012-10-09 18:05:32 +02:00
$table -> colspan [ 1 ][ 1 ] = 3 ;
$data [ 0 ] = __ ( 'Description' );
2019-01-30 16:18:44 +01:00
$data [ 1 ] = html_print_textarea (
'description' ,
5 ,
40 ,
$event_response [ 'description' ],
'class="' . $class_description . '"' ,
true
);
2012-10-09 18:05:32 +02:00
$table -> data [ 1 ] = $data ;
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = __ ( 'Location' ) . ui_print_help_tip ( __ ( 'For Command type Modal Window mode is enforced' ), true );
$locations = [
__ ( 'Modal window' ),
__ ( 'New window' ),
];
$data [ 1 ] = html_print_select ( $locations , 'new_window' , $event_response [ 'new_window' ], '' , '' , '' , true );
2012-10-09 18:05:32 +02:00
$data [ 2 ] = '<span class="size">' . __ ( 'Size' ) . '</span>' ;
2013-04-24 16:27:24 +02:00
if ( $event_response [ 'modal_width' ] == 0 ) {
2019-01-30 16:18:44 +01:00
$event_response [ 'modal_width' ] = 620 ;
2012-10-09 18:05:32 +02:00
}
2019-01-30 16:18:44 +01:00
2013-04-24 16:27:24 +02:00
if ( $event_response [ 'modal_height' ] == 0 ) {
2019-01-30 16:18:44 +01:00
$event_response [ 'modal_height' ] = 500 ;
2012-10-09 18:05:32 +02:00
}
2019-01-30 16:18:44 +01:00
2012-10-09 18:05:32 +02:00
$data [ 3 ] = '<span class="size">' . __ ( 'Width' ) . ' (px) </span>' ;
2019-01-30 16:18:44 +01:00
$data [ 3 ] .= '<span class="size">' . html_print_input_text ( 'modal_width' , $event_response [ 'modal_width' ], '' , 4 , 5 , true ) . '</span>' ;
2012-10-09 18:05:32 +02:00
$data [ 3 ] .= '<span class="size">' . __ ( 'Height' ) . ' (px) </span>' ;
2019-01-30 16:18:44 +01:00
$data [ 3 ] .= '<span class="size">' . html_print_input_text ( 'modal_height' , $event_response [ 'modal_height' ], '' , 4 , 5 , true ) . '</span>' ;
2012-10-09 18:05:32 +02:00
$table -> data [ 2 ] = $data ;
2019-01-30 16:18:44 +01:00
$data = [];
2019-04-29 14:36:02 +02:00
$data [ 0 ] = __ ( 'Parameters' );
2019-01-30 16:18:44 +01:00
$data [ 1 ] = html_print_input_text (
'params' ,
$event_response [ 'params' ],
'' ,
50 ,
255 ,
true
);
$types = [
'url' => __ ( 'URL' ),
'command' => __ ( 'Command' ),
];
2012-10-09 18:05:32 +02:00
$data [ 2 ] = __ ( 'Type' );
2019-01-30 16:18:44 +01:00
$data [ 3 ] = html_print_select ( $types , 'type' , $event_response [ 'type' ], '' , '' , '' , true );
2012-10-09 18:05:32 +02:00
$table -> data [ 3 ] = $data ;
2019-01-30 16:18:44 +01:00
$data = [];
2021-03-11 15:40:23 +01:00
$data [ 0 ] = '<span id="command_label" class="labels">' . __ ( 'Command' ) . '</span><span id="url_label" class="labels invisible">' . __ ( 'URL' ) . '</span>' . ui_print_help_icon ( 'response_macros' , true );
2019-08-22 11:22:40 +02:00
$data [ 1 ] = html_print_textarea (
2019-01-30 16:18:44 +01:00
'target' ,
2019-08-22 11:22:40 +02:00
3 ,
1 ,
2019-01-30 16:18:44 +01:00
$event_response [ 'target' ],
2021-03-11 15:40:23 +01:00
'class="mh_initial"' ,
2019-01-30 16:18:44 +01:00
true
);
$servers_to_exec = [];
2017-08-24 12:34:06 +02:00
$servers_to_exec [ 0 ] = __ ( 'Local console' );
if ( enterprise_installed ()) {
2019-01-30 16:18:44 +01:00
enterprise_include_once ( 'include/functions_satellite.php' );
$rows = get_proxy_servers ();
foreach ( $rows as $row ) {
if ( $row [ 'server_type' ] != 13 ) {
$s_type = ' (Standard)' ;
} else {
$s_type = ' (Satellite)' ;
}
$servers_to_exec [ $row [ 'id_server' ]] = $row [ 'name' ] . $s_type ;
}
2017-08-24 12:34:06 +02:00
}
2021-03-11 15:40:23 +01:00
$data [ 2 ] = '<div id="server_to_exec_label" class="labels invisible">' . __ ( 'Server to execute command' ) . '</div>' ;
$data [ 3 ] = '<div id="server_to_exec_value" class="invisible" >' . html_print_select ( $servers_to_exec , 'server_to_exec' , $event_response [ 'server_to_exec' ], '' , '' , '' , true ) . '</div>' ;
2017-08-24 12:34:06 +02:00
2012-10-09 18:05:32 +02:00
$table -> data [ 4 ] = $data ;
2019-12-10 11:54:30 +01:00
$data = [];
2021-03-11 15:40:23 +01:00
$data [ 0 ] = '<div id="command_timeout_label" class="labels invisible">' . __ ( 'Command timeout (s)' );
$data [ 1 ] = '<div id="command_timeout_value" class="invisible">' . html_print_input_text ( 'command_timeout' , $event_response [ 'command_timeout' ], '' , 4 , 5 , true );
2019-12-10 11:54:30 +01:00
$table -> data [ 5 ] = $data ;
2022-02-01 14:30:25 +01:00
$data = [];
$data [ 0 ] = __ ( 'Display command' ) . ui_print_help_tip ( __ ( 'If enabled the command will be displayed to any user that can execute this event response' ), true );
$data [ 1 ] = html_print_checkbox_switch (
'display_command' ,
1 ,
$event_response [ 'display_command' ],
true
);
$table -> data [ 6 ] = $data ;
2013-04-24 16:27:24 +02:00
if ( $event_response_id == 0 ) {
2019-01-30 16:18:44 +01:00
echo '<form method="post" action="index.php?sec=geventos&sec2=godmode/events/events§ion=responses&mode=list&action=create_response&pure=' . $config [ 'pure' ] . '">' ;
html_print_table ( $table );
2021-03-26 14:40:55 +01:00
echo '<div class="w100p right_align">' ;
2019-01-30 16:18:44 +01:00
html_print_submit_button ( __ ( 'Create' ), 'create_response_button' , false , [ 'class' => 'sub next' ]);
echo '</div>' ;
echo '</form>' ;
} else {
echo '<form method="post" action="index.php?sec=geventos&sec2=godmode/events/events§ion=responses&mode=list&action=update_response&pure=' . $config [ 'pure' ] . '">' ;
html_print_table ( $table );
2021-03-26 14:40:55 +01:00
echo '<div class="w100p right_align">' ;
2019-01-30 16:18:44 +01:00
html_print_submit_button ( __ ( 'Update' ), 'update_response_button' , false , [ 'class' => 'sub next' ]);
echo '</div>' ;
echo '</form>' ;
2012-10-09 18:05:32 +02:00
}
?>
< script language = " javascript " type = " text/javascript " >
$ ( '#type' ) . change ( function () {
2019-01-30 16:18:44 +01:00
$ ( '.labels' ) . hide ();
$ ( '#' + $ ( this ) . val () + '_label' ) . show ();
switch ( $ ( this ) . val ()) {
case 'command' :
$ ( '#new_window option[value="0"]' )
. prop ( 'selected' , true );
$ ( '#new_window' ) . attr ( 'disabled' , 'disabled' );
$ ( '#server_to_exec_label' ) . css ( 'display' , '' );
$ ( '#server_to_exec_value' ) . css ( 'display' , '' );
2019-12-10 11:54:30 +01:00
$ ( '#command_timeout_label' ) . css ( 'display' , '' );
$ ( '#command_timeout_value' ) . css ( 'display' , '' );
2019-01-30 16:18:44 +01:00
break ;
case 'url' :
$ ( '#new_window' ) . removeAttr ( 'disabled' );
$ ( '#server_to_exec_label' ) . css ( 'display' , 'none' );
$ ( '#server_to_exec_value' ) . css ( 'display' , 'none' );
2019-12-10 11:54:30 +01:00
$ ( '#command_timeout_label' ) . css ( 'display' , 'none' );
$ ( '#command_timeout_value' ) . css ( 'display' , 'none' );
2019-01-30 16:18:44 +01:00
break ;
}
2012-10-09 18:05:32 +02:00
});
$ ( '#new_window' ) . change ( function () {
2019-01-30 16:18:44 +01:00
switch ( $ ( this ) . val ()) {
case '0' :
$ ( '.size' ) . css ( 'visibility' , 'visible' );
break ;
case '1' :
$ ( '.size' ) . css ( 'visibility' , 'hidden' );
break ;
}
2012-10-09 18:05:32 +02:00
});
function update_form () {
2019-01-30 16:18:44 +01:00
$ ( '#type' ) . trigger ( 'change' );
$ ( '#new_window' ) . trigger ( 'change' );
2012-10-09 18:05:32 +02:00
}
update_form ();
</ script >