2019-01-30 16:18:44 +01:00
|
|
|
<?php
|
2021-05-18 10:57:21 +02:00
|
|
|
/**
|
|
|
|
* Os.
|
|
|
|
*
|
|
|
|
* @category Os
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Community
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
2023-06-08 12:42:10 +02:00
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
2021-05-18 10:57:21 +02:00
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
2023-06-08 11:53:13 +02:00
|
|
|
* Copyright (c) 2005-2023 Pandora FMS
|
2023-06-08 13:19:01 +02:00
|
|
|
* Please see https://pandorafms.com/community/ for full contribution list
|
2021-05-18 10:57:21 +02:00
|
|
|
* 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 for 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.
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Load global vars.
|
2010-09-09 14:19:11 +02:00
|
|
|
global $config;
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
check_login();
|
2020-09-16 17:40:18 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
|
2022-02-01 13:39:18 +01:00
|
|
|
db_pandora_audit(
|
|
|
|
AUDIT_LOG_ACL_VIOLATION,
|
|
|
|
'Trying to access Setup Management'
|
|
|
|
);
|
2019-01-30 16:18:44 +01:00
|
|
|
include 'general/noaccess.php';
|
|
|
|
return;
|
2010-09-09 14:19:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$action = get_parameter('action', 'new');
|
|
|
|
$idOS = get_parameter('id_os', 0);
|
2020-06-23 14:45:04 +02:00
|
|
|
$id_message = get_parameter('message', 0);
|
2021-05-18 10:57:21 +02:00
|
|
|
if (is_metaconsole() === true) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$tab = get_parameter('tab2', 'list');
|
|
|
|
} else {
|
|
|
|
$tab = get_parameter('tab', 'list');
|
|
|
|
}
|
2010-09-09 14:19:11 +02:00
|
|
|
|
|
|
|
if ($idOS) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$os = db_get_row_filter('tconfig_os', ['id_os' => $idOS]);
|
|
|
|
$name = $os['name'];
|
|
|
|
$description = $os['description'];
|
|
|
|
$icon = $os['icon_name'];
|
|
|
|
} else {
|
2020-09-09 15:28:11 +02:00
|
|
|
$name = io_safe_input(strip_tags(io_safe_output((string) get_parameter('name'))));
|
|
|
|
$description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description'))));
|
2019-01-30 16:18:44 +01:00
|
|
|
$icon = get_parameter('icon', 0);
|
2010-09-09 14:19:11 +02:00
|
|
|
}
|
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
$is_management_allowed = true;
|
|
|
|
if (is_management_allowed() === false) {
|
|
|
|
$is_management_allowed = false;
|
|
|
|
}
|
|
|
|
|
2010-09-09 16:07:21 +02:00
|
|
|
$message = '';
|
2021-05-18 10:57:21 +02:00
|
|
|
if ($is_management_allowed === true) {
|
|
|
|
switch ($action) {
|
|
|
|
case 'edit':
|
|
|
|
$actionHidden = 'update';
|
|
|
|
$textButton = __('Update');
|
2023-02-20 13:02:24 +01:00
|
|
|
$classButton = ['icon' => 'wand'];
|
2021-05-18 10:57:21 +02:00
|
|
|
break;
|
2010-09-09 14:19:11 +02:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
case 'save':
|
|
|
|
$values = [];
|
|
|
|
$values['name'] = $name;
|
|
|
|
$values['description'] = $description;
|
2020-06-23 14:45:04 +02:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
if (($icon !== 0) && ($icon != '')) {
|
|
|
|
$values['icon_name'] = $icon;
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
$resultOrId = false;
|
|
|
|
if ($name != '') {
|
|
|
|
$resultOrId = db_process_sql_insert('tconfig_os', $values);
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
if ($resultOrId === false) {
|
|
|
|
$message = 2;
|
|
|
|
$tab = 'builder';
|
|
|
|
$actionHidden = 'save';
|
|
|
|
$textButton = __('Create');
|
2023-02-20 13:02:24 +01:00
|
|
|
$classButton = ['icon' => 'wand'];
|
2021-05-18 10:57:21 +02:00
|
|
|
} else {
|
|
|
|
$tab = 'list';
|
|
|
|
$message = 1;
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
if (is_metaconsole() === true) {
|
|
|
|
header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message);
|
|
|
|
} else {
|
|
|
|
header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message);
|
|
|
|
}
|
|
|
|
break;
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
case 'update':
|
|
|
|
$name = io_safe_input(strip_tags(io_safe_output((string) get_parameter('name'))));
|
|
|
|
$description = io_safe_input(strip_tags(io_safe_output((string) get_parameter('description'))));
|
|
|
|
$icon = get_parameter('icon', 0);
|
|
|
|
|
|
|
|
$values = [];
|
|
|
|
$values['name'] = $name;
|
|
|
|
$values['description'] = $description;
|
|
|
|
// Only for Metaconsole. Save the previous name for synchronizing.
|
|
|
|
if (is_metaconsole() === true) {
|
|
|
|
$values['previous_name'] = db_get_value('name', 'tconfig_os', 'id_os', $idOS);
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
if (($icon !== 0) && ($icon != '')) {
|
|
|
|
$values['icon_name'] = $icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = false;
|
|
|
|
if ($name != '') {
|
|
|
|
$result = db_process_sql_update('tconfig_os', $values, ['id_os' => $idOS]);
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
if ($result !== false) {
|
|
|
|
$message = 3;
|
|
|
|
$tab = 'list';
|
2020-06-23 14:45:04 +02:00
|
|
|
} else {
|
2021-05-18 10:57:21 +02:00
|
|
|
$message = 4;
|
|
|
|
$tab = 'builder';
|
|
|
|
$os = db_get_row_filter('tconfig_os', ['id_os' => $idOS]);
|
|
|
|
$name = $os['name'];
|
2020-06-23 14:45:04 +02:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
$actionHidden = 'update';
|
|
|
|
$textButton = __('Update');
|
2023-02-20 13:02:24 +01:00
|
|
|
$classButton = ['icon' => 'wand'];
|
2021-05-18 10:57:21 +02:00
|
|
|
if (is_metaconsole() === true) {
|
|
|
|
header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message);
|
|
|
|
} else {
|
|
|
|
header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
$sql = 'SELECT COUNT(id_os) AS count FROM tagente WHERE id_os = '.$idOS;
|
|
|
|
$count = db_get_all_rows_sql($sql);
|
|
|
|
$count = $count[0]['count'];
|
|
|
|
|
|
|
|
if ($count > 0) {
|
|
|
|
$message = 5;
|
|
|
|
} else {
|
|
|
|
$result = (bool) db_process_sql_delete('tconfig_os', ['id_os' => $idOS]);
|
|
|
|
if ($result) {
|
|
|
|
$message = 6;
|
|
|
|
} else {
|
|
|
|
$message = 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_metaconsole() === true) {
|
|
|
|
header('Location:'.$config['homeurl'].'index.php?sec=advanced&sec2=advanced/component_management&tab=os_manage&tab2='.$tab.'&message='.$message);
|
|
|
|
} else {
|
|
|
|
header('Location:'.$config['homeurl'].'index.php?sec=gsetup&sec2=godmode/setup/os&tab='.$tab.'&message='.$message);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case 'new':
|
|
|
|
$actionHidden = 'save';
|
|
|
|
$textButton = __('Create');
|
2023-02-20 13:02:24 +01:00
|
|
|
$classButton = ['icon' => 'next'];
|
2021-05-18 10:57:21 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-09-09 14:19:11 +02:00
|
|
|
}
|
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
$buttons = [];
|
|
|
|
$buttons['list'] = [
|
|
|
|
'active' => false,
|
|
|
|
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/setup/os&tab=list">'.html_print_image(
|
2023-02-20 13:02:24 +01:00
|
|
|
'images/logs@svg.svg',
|
2021-05-18 10:57:21 +02:00
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('List OS'),
|
2023-02-20 13:02:24 +01:00
|
|
|
'class' => 'invert_filter main_menu_icon',
|
2021-05-18 10:57:21 +02:00
|
|
|
]
|
|
|
|
).'</a>',
|
|
|
|
];
|
|
|
|
if ($is_management_allowed === true) {
|
|
|
|
$buttons['builder'] = [
|
2019-01-30 16:18:44 +01:00
|
|
|
'active' => false,
|
2021-03-11 15:40:23 +01:00
|
|
|
'text' => '<a href="index.php?sec=gsetup&sec2=godmode/setup/os&tab=builder">'.html_print_image(
|
2023-02-20 13:02:24 +01:00
|
|
|
'images/edit.svg',
|
2021-03-11 15:40:23 +01:00
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Builder OS'),
|
2023-02-20 13:02:24 +01:00
|
|
|
'class' => 'invert_filter main_menu_icon',
|
2021-03-11 15:40:23 +01:00
|
|
|
]
|
|
|
|
).'</a>',
|
2021-05-18 10:57:21 +02:00
|
|
|
];
|
|
|
|
}
|
2010-09-09 14:19:11 +02:00
|
|
|
|
2010-09-09 16:07:21 +02:00
|
|
|
$buttons[$tab]['active'] = true;
|
2010-09-09 14:19:11 +02:00
|
|
|
|
2022-08-25 14:01:08 +02:00
|
|
|
$headerTitle = ($tab === 'builder') ? __('Edit OS') : __('List of Operating Systems');
|
2021-04-30 14:35:54 +02:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
if (is_metaconsole() === false) {
|
2020-06-23 14:45:04 +02:00
|
|
|
// Header.
|
2021-04-30 14:35:54 +02:00
|
|
|
ui_print_standard_header(
|
|
|
|
$headerTitle,
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
'',
|
|
|
|
true,
|
|
|
|
$buttons,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'link' => '',
|
|
|
|
'label' => __('Servers'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'link' => '',
|
|
|
|
'label' => __('Edit OS'),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
2016-06-06 13:05:25 +02:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
if (empty($id_message) === false) {
|
2020-06-23 14:45:04 +02:00
|
|
|
switch ($id_message) {
|
|
|
|
case 1:
|
|
|
|
echo ui_print_success_message(__('Success creating OS'), '', true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
echo ui_print_error_message(__('Fail creating OS'), '', true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
echo ui_print_success_message(__('Success updating OS'), '', true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
echo ui_print_error_message(__('Error updating OS'), '', true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
echo ui_print_error_message(__('There are agents with this OS.'), '', true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
echo ui_print_success_message(__('Success deleting'), '', true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
echo ui_print_error_message(__('Error deleting'), '', true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Default.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-09 14:19:11 +02:00
|
|
|
|
2010-09-09 16:07:21 +02:00
|
|
|
switch ($tab) {
|
2019-01-30 16:18:44 +01:00
|
|
|
case 'list':
|
|
|
|
include_once $config['homedir'].'/godmode/setup/os.list.php';
|
2021-05-18 10:57:21 +02:00
|
|
|
break;
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
case 'builder':
|
|
|
|
include_once $config['homedir'].'/godmode/setup/os.builder.php';
|
2021-05-18 10:57:21 +02:00
|
|
|
break;
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2021-05-18 10:57:21 +02:00
|
|
|
default:
|
|
|
|
// Default.
|
|
|
|
break;
|
2010-09-09 14:19:11 +02:00
|
|
|
}
|