diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 4e639416be..8ca516c602 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.765-221102 +Version: 7.0NG.765-221104 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 28de5d9b56..9203c0d24e 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.765-221102" +pandora_version="7.0NG.765-221104" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 90be56ff87..88ad5761f9 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1015,7 +1015,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.765'; -use constant AGENT_BUILD => '221102'; +use constant AGENT_BUILD => '221104'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index b0015ae550..c799332756 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.765 -%define release 221102 +%define release 221104 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index ad8db52707..d09b72f922 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.765 -%define release 221102 +%define release 221104 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 1d2c20d79b..e5b8cf774d 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.765" -PI_BUILD="221102" +PI_BUILD="221104" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index ee97698f1c..5c5408c63b 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{221102} +{221104} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index f77dc7dfaa..a79990463d 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.765 Build 221102") +#define PANDORA_VERSION ("7.0NG.765 Build 221104") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 628e7cbf79..aea5c55009 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.765(Build 221102))" + VALUE "ProductVersion", "(7.0NG.765(Build 221104))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 6d7d4e45f9..74927b95f7 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.765-221102 +Version: 7.0NG.765-221104 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index c47f55275b..2e6e565b5b 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.765-221102" +pandora_version="7.0NG.765-221104" package_pear=0 package_pandora=1 diff --git a/pandora_console/godmode/groups/configure_modu_group.php b/pandora_console/godmode/groups/configure_modu_group.php index 0ea11d117f..9330aa1320 100644 --- a/pandora_console/godmode/groups/configure_modu_group.php +++ b/pandora_console/godmode/groups/configure_modu_group.php @@ -59,7 +59,7 @@ if ($id_group) { } } - +$table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters'; $table->style[0] = 'font-weight: bold'; diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index 34524c6aa7..17f2020d13 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -137,7 +137,13 @@ if (isset($_GET['server'])) { if ($server_type === SERVER_TYPE_ENTERPRISE_SATELLITE) { $buttons['agent_editor'] = [ 'active' => false, - 'text' => ''.html_print_image('images/agent.png', true, ['title' => __('Advanced editor')]).'', + 'text' => ''.html_print_image('images/agent.png', true, ['title' => __('Manage agents')]).'', + + ]; + + $buttons['collections'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/collection.png', true, ['title' => __('Collections')]).'', ]; } @@ -160,6 +166,8 @@ if (isset($_GET['server'])) { } } else if ($tab === 'agent_editor' && $server_type === SERVER_TYPE_ENTERPRISE_SATELLITE) { $advanced_editor = 'agent_editor'; + } else if ($tab === 'collections' && $server_type === SERVER_TYPE_ENTERPRISE_SATELLITE) { + $advanced_editor = 'collections'; } enterprise_include('godmode/servers/server_disk_conf_editor.php'); diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index b0dd7da0e3..d7d4498fb3 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -549,6 +549,43 @@ if ($create_user) { $password_new = ''; $password_confirm = ''; $new_user = true; + } else { + $pm = db_get_value_filter('pandora_management', 'tperfil', ['id_perfil' => $profile2]); + + if ((int) $pm === 1) { + $user_source = db_get_value_filter( + 'id_source', + 'tnotification_source_user', + [ + 'id_source' => $notification['id'], + 'id_user' => $id, + ] + ); + if ($user_source === false) { + $notificationSources = db_get_all_rows_filter('tnotification_source', [], 'id'); + foreach ($notificationSources as $notification) { + if ((int) $notification['id'] === 1 || (int) $notification['id'] === 5) { + $notification_user = db_get_value_filter( + 'id_source', + 'tnotification_source_user', + [ + 'id_source' => $notification['id'], + 'id_user' => $id, + ] + ); + if ($notification_user === false) { + @db_process_sql_insert( + 'tnotification_source_user', + [ + 'id_source' => $notification['id'], + 'id_user' => $id, + ] + ); + } + } + } + } + } } ui_print_result_message( @@ -845,6 +882,43 @@ if ($add_profile && empty($json_profile)) { $return = profile_create_user_profile($id2, $profile2, $group2, false, $tags, $no_hierarchy); if ($return === false) { $is_err = true; + } else { + $pm = db_get_value_filter('pandora_management', 'tperfil', ['id_perfil' => $profile2]); + + if ((int) $pm === 1) { + $user_source = db_get_value_filter( + 'id_source', + 'tnotification_source_user', + [ + 'id_source' => $notification['id'], + 'id_user' => $id, + ] + ); + if ($user_source === false) { + $notificationSources = db_get_all_rows_filter('tnotification_source', [], 'id'); + foreach ($notificationSources as $notification) { + if ((int) $notification['id'] === 1 || (int) $notification['id'] === 5) { + $notification_user = db_get_value_filter( + 'id_source', + 'tnotification_source_user', + [ + 'id_source' => $notification['id'], + 'id_user' => $id, + ] + ); + if ($notification_user === false) { + @db_process_sql_insert( + 'tnotification_source_user', + [ + 'id_source' => $notification['id'], + 'id_user' => $id, + ] + ); + } + } + } + } + } } ui_print_result_message( diff --git a/pandora_console/include/auth/mysql.php b/pandora_console/include/auth/mysql.php index 13bd0428a0..cbc7ad37a0 100644 --- a/pandora_console/include/auth/mysql.php +++ b/pandora_console/include/auth/mysql.php @@ -809,7 +809,44 @@ function update_user(string $id_user, array $values) return false; } - return db_process_sql_update('tusuario', $values, ['id_user' => $id_user]); + $output = db_process_sql_update('tusuario', $values, ['id_user' => $id_user]); + + if (isset($values['is_admin']) === true && (bool) $values['is_admin'] === true) { + // Administrator user must be activated in all notifications sections. + $notificationSources = db_get_all_rows_filter('tnotification_source', [], 'id'); + + foreach ($notificationSources as $notification) { + $user_source = db_get_value_filter( + 'id_source', + 'tnotification_source_user', + [ + 'id_source' => $notification['id'], + 'id_user' => $id_user, + ] + ); + + if ($user_source !== false) { + @db_process_sql_update( + 'tnotification_source_user', + ['enabled' => 1], + [ + 'id_source' => $notification['id'], + 'id_user' => $id_user, + ] + ); + } else if ((int) $notification['id'] === 1 || (int) $notification['id'] === 5) { + @db_process_sql_insert( + 'tnotification_source_user', + [ + 'id_source' => $notification['id'], + 'id_user' => $id_user, + ] + ); + } + } + } + + return $output; } diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 7b20d49a51..df0210c64e 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -679,7 +679,6 @@ class ConsoleSupervisor $max_age = 0; break; - case 'NOTIF.LICENSE.EXPIRATION': case 'NOTIF.FILES.ATTACHMENT': case 'NOTIF.FILES.DATAIN': case 'NOTIF.FILES.DATAIN.BADXML': @@ -846,7 +845,9 @@ class ConsoleSupervisor } // Expiry. - if (($days_to_expiry <= 15) && ($days_to_expiry > 0)) { + if (($days_to_expiry <= 15) && ($days_to_expiry > 0) + && ((is_user_admin($config['id_user'])) || (check_acl($config['id_user'], 0, 'PM'))) + ) { if ($config['license_mode'] == 1) { $title = __('License is about to expire'); $msg = 'Your license will expire in %d days. Please, contact our sales department.'; @@ -867,7 +868,7 @@ class ConsoleSupervisor 'url' => '__url__/index.php?sec=gsetup&sec2=godmode/setup/license', ] ); - } else if ($days_to_expiry < 0) { + } else if (($days_to_expiry <= 0) && ((is_user_admin($config['id_user'])) || (check_acl($config['id_user'], 0, 'PM')))) { if ($config['license_mode'] == 1) { $title = __('Expired license'); $msg = __('Your license has expired. Please, contact our sales department.'); diff --git a/pandora_console/include/class/SatelliteCollection.class.php b/pandora_console/include/class/SatelliteCollection.class.php new file mode 100644 index 0000000000..34348fdc7a --- /dev/null +++ b/pandora_console/include/class/SatelliteCollection.class.php @@ -0,0 +1,689 @@ +ajaxController = $ajaxController; + // Capture all parameters before start. + $this->satellite_server = (int) get_parameter('server_remote'); + if ($this->satellite_server !== 0) { + $this->satellite_name = servers_get_name($this->satellite_server); + $this->satellite_config = (array) config_satellite_get_config_file($this->satellite_name); + } + } + + + /** + * Run view + * + * @return void + */ + public function run() + { + // Javascript. + ui_require_jquery_file('pandora'); + // CSS. + ui_require_css_file('wizard'); + ui_require_css_file('discovery'); + + $this->createBlock(); + + if (is_metaconsole() === true) { + // Only in case of Metaconsole, format the frame. + open_meta_frame(); + } + + // Datatables list. + try { + $columns = [ + 'name', + 'dir', + 'description', + 'actions', + ]; + + $column_names = [ + __('Name'), + __('Dir'), + __('Description'), + __('Actions'), + ]; + + $this->tableId = 'satellite_collections'; + + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => $this->tableId, + 'class' => 'info_table', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $column_names, + 'ajax_url' => $this->ajaxController, + 'ajax_data' => [ + 'method' => 'draw', + 'server_remote' => $this->satellite_server, + ], + 'ajax_postprocces' => 'process_datatables_item(item)', + 'no_sortable_columns' => [ + 0, + 1, + 2, + 3, + ], + 'search_button_class' => 'sub filter float-right', + 'form' => [ + 'inputs' => [ + [ + 'label' => __('Search'), + 'type' => 'text', + 'name' => 'filter_search', + 'size' => 12, + ], + ], + ], + ] + ); + } catch (Exception $e) { + echo $e->getMessage(); + } + + if (is_metaconsole() === true) { + // Close the frame. + close_meta_frame(); + } + + echo '
'; + echo ''; + + // Load own javascript file. + echo $this->loadJS(); + } + + + /** + * Get the data for draw the table. + * + * @return void. + */ + public function draw() + { + global $config; + + // Init data. + $data = []; + // Count of total records. + $count = 0; + // Catch post parameters. + $start = get_parameter('start', 0); + $length = get_parameter('length', $config['block_size']); + $order = get_datatable_order(true); + $filters = get_parameter('filter', []); + + try { + ob_start(); + + // Gets all collections (database). + $collections = collection_get_collections(null, $filters['filter_search']); + if (empty($collections) === false) { + $data = $collections; + } + + // All satellite conf collections. + foreach ($this->satellite_config as $line) { + $regex = '/^file_collection\s(\S+)/m'; + + if (preg_match($regex, $line, $matches, PREG_OFFSET_CAPTURE, 0) > 0) { + $key = array_search($matches[1][0], array_column($data, 'short_name')); + if ($key !== false) { + $data[$key]['delete'] = true; + } + } + } + + if (empty($data) === false) { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + + $delete = (int) isset($tmp->delete); + + $tmp->dir = $tmp->short_name; + + $tmp->actions = ''; + $tmp->actions .= html_print_image( + ($delete === 0) ? 'images/add.png' : 'images/cross.png', + true, + [ + 'border' => '0', + 'class' => 'action_button_img mrgn_lft_05em invert_filter', + 'onclick' => ($delete === 0) + ? 'add_collection(\''.$tmp->short_name.'\')' + : 'delete_collection(\''.$tmp->short_name.'\')', + ] + ); + + $carry[] = $tmp; + return $carry; + } + ); + } + + if (empty($data) === true) { + $total = 0; + $data = []; + } else { + $total = count($data); + $data = array_slice($data, $start, $length, false); + } + + echo json_encode( + [ + 'data' => $data, + 'recordsTotal' => $total, + 'recordsFiltered' => $total, + ] + ); + // Capture output. + $response = ob_get_clean(); + } catch (Exception $e) { + echo json_encode(['error' => $e->getMessage()]); + exit; + } + + // If not valid, show error with issue. + json_decode($response); + if (json_last_error() === JSON_ERROR_NONE) { + // If valid dump. + echo $response; + } else { + echo json_encode( + ['error' => $response] + ); + } + + exit; + } + + + /** + * Add collection to satellite conf. + * + * @return void + */ + public function addCollection() + { + $short_name = get_parameter('short_name'); + + if ($this->parseSatelliteConf('add', $short_name) === false) { + $this->ajaxMsg('error', __('Error adding collection')); + } else { + $this->ajaxMsg('result', _('Collection '.$short_name.' added.')); + } + + exit; + } + + + /** + * Delete collection to satellite conf. + * + * @return void + */ + public function deleteCollection() + { + $short_name = get_parameter('short_name'); + + if ($this->parseSatelliteConf('delete', $short_name) === false) { + $this->ajaxMsg('error', __('Error deleting collection')); + } else { + $this->ajaxMsg('result', _('Collection '.$short_name.' deleted.')); + } + + exit; + } + + + /** + * Parse satellite configuration . + * + * @param string $action Action to perform (add, delete). + * @param string $short_name Short name. + * + * @return boolean + */ + private function parseSatelliteConf(string $action, string $short_name) + { + switch ($action) { + case 'delete': + $pos = preg_grep('/^file_collection '.$short_name.'/', $this->satellite_config); + if (empty($pos) === false) { + $key_pos = 0; + foreach ($pos as $key => $value) { + $key_pos = $key; + break; + } + + unset($this->satellite_config[$key_pos]); + } + + $conf = implode('', $this->satellite_config); + break; + + default: + case 'add': + $pos = preg_grep('/^file_collection/', $this->satellite_config); + if (empty($pos) === false) { + $string_collection = 'file_collection '.$short_name."\n"; + + $key_pos = array_keys($pos)[(count($pos) - 1)]; + $array1 = array_slice($this->satellite_config, 0, ($key_pos + 1)); + $array2 = array_slice($this->satellite_config, ($key_pos + 1)); + $array_merge = array_merge($array1, [$string_collection], $array2); + $this->satellite_config = $array_merge; + + // Check config. + if (empty($this->satellite_config) === true) { + return false; + } + } else { + $pos = preg_grep('/^\#\sFile\scollections/', $this->satellite_config); + $string_collection = 'file_collection '.$short_name."\n"; + + $key_pos = 0; + foreach ($pos as $key => $value) { + $key_pos = $key; + break; + } + + $key_pos++; + + $array1 = array_slice($this->satellite_config, 0, $key_pos); + $array2 = array_slice($this->satellite_config, $key_pos); + // Add collection to conf. + $array_merge = array_merge($array1, [$string_collection], $array2); + $this->satellite_config = $array_merge; + + // Check config. + if (empty($this->satellite_config) === true) { + return false; + } + } + + $conf = implode('', $this->satellite_config); + break; + } + + return $this->saveAgent($conf); + } + + + /** + * Saves agent to satellite cofiguration file. + * + * @param string $new_conf Config file. + * + * @return boolean|void + */ + private function saveAgent(string $new_conf) + { + global $config; + + if (empty($new_conf) === true) { + return false; + } + + db_pandora_audit( + AUDIT_LOG_SYSTEM, + 'Update remote config for server '.$this->satellite_name + ); + + // Convert to config file encoding. + $encoding = config_satellite_get_encoding($new_conf); + if ($encoding !== false) { + $converted_server_config = mb_convert_encoding($new_conf, $encoding, 'UTF-8'); + if ($converted_server_config !== false) { + $new_conf = $converted_server_config; + } + } + + // Get filenames. + if ($this->satellite_server !== false) { + $files = config_satellite_get_satellite_config_filenames($this->satellite_name); + } else { + $files = []; + $files['conf'] = $config['remote_config'].'/conf/'.md5($this->satellite_name).'.srv.conf'; + $files['md5'] = $config['remote_config'].'/md5/'.md5($this->satellite_name).'.srv.md5'; + } + + // Save configuration. + $result = file_put_contents($files['conf'], $new_conf); + + if ($result === false) { + return false; + } + + // Save configuration md5. + $result = file_put_contents($files['md5'], md5($new_conf)); + } + + + /** + * Checks if target method is available to be called using AJAX. + * + * @param string $method Target method. + * + * @return boolean True allowed, false not. + */ + public function ajaxMethod(string $method) + { + return in_array($method, $this->AJAXMethods); + } + + + /** + * Minor function to dump json message as ajax response. + * + * @param string $type Type: result || error. + * @param string $msg Message. + * + * @return void + */ + private function ajaxMsg(string $type, string $msg) + { + if ($type === 'error') { + echo json_encode( + [ + $type => ui_print_error_message( + __($msg), + '', + true + ), + ] + ); + } else { + echo json_encode( + [ + $type => ui_print_success_message( + __($msg), + '', + true + ), + ] + ); + } + + exit; + } + + + /** + * Create file_collections blocks + * + * @return void + */ + public function createBlock() + { + $init = preg_grep('/^\#\sFile\scollections/', $this->satellite_config); + + if (empty($init) === true) { + $collection = "# File collections\n"; + + array_push($this->satellite_config, "\n"); + array_push($this->satellite_config, $collection); + array_push($this->satellite_config, "\n"); + + $conf = implode('', $this->satellite_config); + $this->saveAgent($conf); + } + } + + + /** + * Load Javascript code. + * + * @return string. + */ + public function loadJS() + { + // Nothing for this moment. + ob_start(); + + // Javascript content. + ?> + + [ 'NOTIF.LICENSE.LIMITED', - 'NOTIF.LICENSE.EXPIRATION', 'NOTIF.FILES.ATTACHMENT', 'NOTIF.FILES.DATAIN', 'NOTIF.FILES.DATAIN.BADXML', diff --git a/pandora_console/install.php b/pandora_console/install.php index 0047ad1376..79c2b8ed06 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -129,7 +129,7 @@