Skip to content

Commit

Permalink
Fixes assets filter and access control list preference
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBiscosi committed Jan 22, 2025
1 parent 53aa642 commit bd5a4db
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 64 deletions.
57 changes: 30 additions & 27 deletions http_src/vue/page-access-control-list.vue
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
<!-- (C) 2024 - ntop.org -->
<template>
<div class="m-2 mb-3">
<div class="card card-shadow">
<div class="card-body">
<TableWithConfig ref="table_access_control_list" :table_id="table_id" :csrf="context.csrf"
:f_map_columns="map_table_def_columns" :get_extra_params_obj="get_extra_params_obj"
:f_sort_rows="columns_sorting" @custom_event="on_table_custom_event">
<template v-slot:custom_buttons>
<button class="btn btn-link" type="button" @click="add_rule">
<i class="fas fa-plus" data-bs-toggle="tooltip" data-bs-placement="top"
:title="_i18n('policy.add_rule')"></i>
</button>
</template>
<template v-slot:custom_header>
<div class="dropdown me-3 d-inline-block" v-for="item in filter_table_array">
<span class="no-wrap d-flex align-items-center my-auto me-2 filters-label"><b>{{ item["basic_label"]
}}</b></span>
<SelectSearch v-model:selected_option="item['current_option']" theme="bootstrap-5" dropdown_size="small"
:options="item['options']" @select_option="add_table_filter">
</SelectSearch>
</div>
<div class="d-flex justify-content-center align-items-center">
<div class="btn btn-sm btn-primary mt-2 me-3" type="button" @click="reset_filters">
{{ _i18n('reset') }}
</div>
</div>
</template> <!-- Dropdown filters -->
</TableWithConfig>
<template v-if="(!props.context.is_check_enabled)">
<div class="alert alert-warning" role="alert" id='error-alert' v-html:="error_message">
</div>
</template>
<div :class="[(!props.context.is_check_enabled) ? 'ntopng-gray-out' : '']">
<TableWithConfig ref="table_access_control_list" :table_id="table_id" :csrf="context.csrf"
:f_map_columns="map_table_def_columns" :get_extra_params_obj="get_extra_params_obj"
:f_sort_rows="columns_sorting" @custom_event="on_table_custom_event">
<template v-slot:custom_buttons>
<button class="btn btn-link" type="button" @click="add_rule">
<i class="fas fa-plus" data-bs-toggle="tooltip" data-bs-placement="top"
:title="_i18n('policy.add_rule')"></i>
</button>
</template>
<template v-slot:custom_header>
<div class="dropdown me-3 d-inline-block" v-for="item in filter_table_array">
<span class="no-wrap d-flex align-items-center my-auto me-2 filters-label"><b>{{ item["basic_label"]
}}</b></span>
<SelectSearch v-model:selected_option="item['current_option']" theme="bootstrap-5" dropdown_size="small"
:options="item['options']" @select_option="add_table_filter">
</SelectSearch>
</div>
<div class="d-flex justify-content-center align-items-center">
<div class="btn btn-sm btn-primary mt-2 me-3" type="button" @click="reset_filters">
{{ _i18n('reset') }}
</div>
</div>
</template> <!-- Dropdown filters -->
</TableWithConfig>
<div class="card-footer mt-3">
<button type="button" ref="delete_all_rules" @click="delete_all_rules" class="btn btn-danger">
<i class="fas fa-trash"></i>
Expand All @@ -38,8 +40,8 @@
{{ _i18n("acl_page.export_rules") }}
</button>
</div>
<NoteList :note_list="notes"></NoteList>
</div>
<NoteList :note_list="notes"> </NoteList>
</div>
<ModalAddACLRule ref="modal_add" :context="context" :url_request="url_add_request" :l4_proto_list="l4_proto"
:l7_proto_list="l7_proto" @add="refresh_table">
Expand Down Expand Up @@ -78,6 +80,7 @@ const modal_edit = ref(null);
const modal_delete = ref(null);
const modal_delete_all = ref(null);
const filter_table_array = ref([]);
const error_message = i18n('acl_page.check_disabled') + " <a href='" + http_prefix + "/lua/admin/edit_configset.lua?subdir=all#disabled'><i class='fas fa-cog fa-sm'></i></a>";
const table_id = ref('access_control_list');
const url_add_request = '/lua/pro/rest/v2/add/system/access_control_list_rules.lua'
const url_edit_request = '/lua/pro/rest/v2/add/system/edit_access_control_list_rule.lua'
Expand Down
51 changes: 29 additions & 22 deletions http_src/vue/page-assets.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
<!-- (C) 2024 - ntop.org -->
<template>
<div class="m-2 mb-3">
<TableWithConfig ref="table_assets" :table_id="table_id" :csrf="context.csrf" :f_map_columns="map_table_def_columns"
:get_extra_params_obj="get_extra_params_obj" @custom_event="on_table_custom_event">
<template v-slot:custom_header>
<div class="dropdown me-3 d-inline-block" v-for="item in filter_table_array">
<span class="no-wrap d-flex align-items-center my-auto me-2 filters-label"><b>{{ item["basic_label"]
}}</b></span>
<!-- :key="host_filters_key" -->
<SelectSearch v-model:selected_option="item['current_option']" theme="bootstrap-5" dropdown_size="small"
:options="item['options']" @select_option="add_table_filter">
</SelectSearch>
</div>
</template> <!-- Dropdown filters -->
</TableWithConfig>
<div class="card-footer mt-3">
<button v-if="props.context.is_admin" type="button" @click="delete_assets()" class="btn btn-danger ms-1">
<i class="fas fa fa-trash"></i>
{{ _i18n("delete_all_entries") }}
</button>
<button v-if="props.context.is_admin" type="button" @click="delete_assets_epoch" class="btn btn-danger ms-1">
<i class="fas fa fa-trash"></i>
{{ _i18n("asset_details.delete_asset_older_title") }}
</button>
<template v-if="(!props.context.is_assets_collection_enabled)">
<div class="alert alert-warning" role="alert" id='error-alert' v-html:="error_message">
</div>
</template>
<div :class="[(!props.context.is_assets_collection_enabled) ? 'ntopng-gray-out' : '']">
<TableWithConfig ref="table_assets" :table_id="table_id" :csrf="context.csrf" :f_map_columns="map_table_def_columns"
:get_extra_params_obj="get_extra_params_obj" @custom_event="on_table_custom_event">
<template v-slot:custom_header>
<div class="dropdown me-3 d-inline-block" v-for="item in filter_table_array">
<span class="no-wrap d-flex align-items-center my-auto me-2 filters-label"><b>{{ item["basic_label"]
}}</b></span>
<!-- :key="host_filters_key" -->
<SelectSearch v-model:selected_option="item['current_option']" theme="bootstrap-5" dropdown_size="small"
:options="item['options']" @select_option="add_table_filter">
</SelectSearch>
</div>
</template> <!-- Dropdown filters -->
</TableWithConfig>
<div class="card-footer mt-3">
<button v-if="props.context.is_admin" type="button" @click="delete_assets()" class="btn btn-danger ms-1">
<i class="fas fa fa-trash"></i>
{{ _i18n("delete_all_entries") }}
</button>
<button v-if="props.context.is_admin" type="button" @click="delete_assets_epoch" class="btn btn-danger ms-1">
<i class="fas fa fa-trash"></i>
{{ _i18n("asset_details.delete_asset_older_title") }}
</button>
</div>
</div>
</div>
<ModalDeleteAssets ref="modal_delete_assets" :context="context" @delete="refresh_table">
Expand All @@ -49,6 +55,7 @@ const filter_table_array = ref([]);
const table_assets = ref();
const modal_delete_assets = ref();
const modal_delete_assets_epoch = ref();
const error_message = i18n('asset_details.preference_disabled')
const child_safe_icon = "<font color='#5cb85c'><i class='fas fa-lg fa-child' aria-hidden='true' title='" + i18n("host_pools.children_safe") + "'></i></font>"
const system_host_icon = "<i class='fas fa-flag' title='" + i18n("system_host") + "'></i>"
const hidden_from_top_icon = "<i class='fas fa-eye-slash' title='" + i18n("hidden_from_top_talkers") + "'></i>"
Expand Down
1 change: 0 additions & 1 deletion include/LocalHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class LocalHost : public Host {
if (network) network->updateRoundTripTime(rtt_msecs);
}

void toggleRxOnlyHost(bool rx_only);
virtual NetworkStats *getNetworkStats(int32_t networkId) {
return (iface->getNetworkStats(networkId));
};
Expand Down
2 changes: 1 addition & 1 deletion include/ntop_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
#define CONST_INTERFACE_TYPE_DB "db"
#define CONST_INTERFACE_TYPE_UNKNOWN "unknown"

#define CONST_ASSETS_PERIODIC_UPDATE 600 /* 10 min */
#define CONST_DEMO_MODE_DURATION 600 /* 10 min */
#define CONST_MAX_DUMP_DURATION 300 /* 5 min */
#define CONST_MAX_NUM_PACKETS_PER_LIVE 100000 /* live captures via HTTP */
Expand Down Expand Up @@ -573,7 +574,6 @@
#define HASHKEY_IFACE_TOP_OS "ntopng.cache.top_os"
#define HASHKEY_IFACE_TOP_OS_HOUR_KEYS_PUSHED "ntopng.cache.top_os_hour_done"
#define HASHKEY_IFACE_TOP_OS_DAY_KEYS_PUSHED "ntopng.cache.top_os_day_done"
#define HASHKEY_LOCALHOST_RX_ONLY "ntopng.cache.localhost_host_rx_only"

#define CONST_DEFAULT_DOCS_DIR "httpdocs"
#define CONST_DEFAULT_SCRIPTS_DIR "scripts"
Expand Down
2 changes: 2 additions & 0 deletions scripts/locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ local lang = {
["delete_asset"] = "Are you sure to delete the selected host from Assets? This action cannot be undone.",
["delete_asset_title"] = "Delete Assets",
["last_time_seen"] = "Last Time Seen",
["preference_disabled"] = "Assets collection is disabled by preferences. Please enable it <a href='" .. ntop.getHttpPrefix() .. "/lua/admin/prefs.lua?tab=in_memory'><i class='fas fa-cog fa-sm'></i></a>",
["delete_asset_older_title"] = "Delete Older Than",
["delete_asset_older"] = "Please select a date. All Assets not seen since the selected date are going to be removed. This action cannot be undone.",
["delete_all_assets"] = "Are you sure to delete all Assets? This action cannot be undone.",
Expand Down Expand Up @@ -935,6 +936,7 @@ local lang = {
["advanced_settings"] = "Advanced Settings",
["created_rule_time"] = "Creation Date",
["delete_acl_rule"] = "Delete Rule",
["check_disabled"] = "The ACL Violation checks are disabled. Please enable at least one between ACL Violation (ARP) and ACL Violation (ICMP/TCP/UDP).",
["delete_all_rules"] = "Delete All Rules",
["delete_confirmation"] = "Are you sure you want to delete the selected rule",
["delete_all_confirmation"] = "Are you sure you want to delete all the rules configured?",
Expand Down
1 change: 1 addition & 0 deletions scripts/lua/assets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ local json_context = json.encode({
historical_available = hasClickHouseSupport(),
csrf = ntop.getRandomCSRFValue(),
is_admin = isAdministrator(),
is_assets_collection_enabled = (ntop.getPref('ntopng.prefs.enable_assets_collection') ~= '0')
})
template_utils.render("pages/vue_page.template", {
vue_page_name = "PageAssets",
Expand Down
12 changes: 1 addition & 11 deletions scripts/lua/inc/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ if (interface_config) then
end
end

if (flow_config) then
-- Interface alerts
if (flow_config["access_control_list"]) and
(flow_config["access_control_list"]["all"]["enabled"]) or
(interface_config["acl_violation_arp"]) and
(interface_config["acl_violation_arp"]["min"]["enabled"]) then
acl_violation_enabled = true
end
end

-- Infrastructure
local infrastructure_view = false
local infrastructure_instances = {}
Expand Down Expand Up @@ -693,7 +683,7 @@ page_utils.add_menubar_section({
entries = {
{
entry = page_utils.menu_entries.access_control_list,
hidden = not is_admin or not ntop.isEnterpriseL() or not acl_violation_enabled,
hidden = not is_admin or not ntop.isEnterpriseL(),
url = '/lua/pro/admin/access_control_list.lua'
}, {
entry = page_utils.menu_entries.device_protocols,
Expand Down
6 changes: 4 additions & 2 deletions scripts/lua/rest/v2/get/host/assets_filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ for _, value in pairs(available_filters or {}) do
if not filters[value.filter] then
filters[value.filter] = {}
end

filters[value.filter][value.value] = value.count

if value.value then
filters[value.filter][value.value] = value.count
end
end

for key, value in pairsByKeys(filters or {}, asc) do
Expand Down

0 comments on commit bd5a4db

Please sign in to comment.