Add definition of builtin labels

This commit is contained in:
Alfredo Cardigliano 2026-04-20 16:41:40 +02:00
parent c0ebc5d283
commit 1f9e505575
3 changed files with 40 additions and 5 deletions

View file

@ -296,6 +296,17 @@
#define HOST_LABEL_NAMES_KEY "ntopng.cache.host_labels.%s"
#define HOST_LABELS_BITMAP_KEY "ntopng.prefs.host_labels_bitmap.%s"
#define HOST_LABELS_BITMAP_PREFIX "ntopng.prefs.host_labels_bitmap."
/* Built-in host labels (bits 0-31)
* Note: bit 32-63 are user-defined */
typedef enum {
HOST_LABEL_DNS_SERVER = 0,
HOST_LABEL_NTP_SERVER = 1,
HOST_LABEL_DHCP_SERVER = 2,
HOST_LABEL_SMTP_SERVER = 3,
HOST_LABEL_NETWORK_GATEWAY = 4,
} HostLabelId;
#define IFACE_DHCP_RANGE_KEY "ntopng.prefs.ifid_%u.dhcp_ranges"
#define IFACE_BROADCAST_DOMAINS_KEY "ntopng.prefs.ifid_%u.broadcast_domains"
#define HOST_SERIALIZED_KEY "ntopng.serialized_hosts.ifid_%u_%s@%d"

View file

@ -521,6 +521,7 @@ local lang = {
["switch_port"] = "Switch Port",
["smtp_server"] = "SMTP Server",
["smtp_servers"] = "SMTP Servers",
["network_gateway"] = "Network Gateway",
["ssh_server"] = "SSH Server",
["ssid"] = "<a class='ntopng-external-link' href='https://en.wikipedia.org/wiki/Service_set_(802.11_network)'>SSID</A>",
["tcp_fingerprint"] = "TCP Fingerprint",

View file

@ -8,6 +8,18 @@ local label_badge_utils = {}
-- ##############################################
-- Built-in host labels (bits 0-31).
-- Keep in sync with include/ntop_defines.h
label_badge_utils.builtin_labels = {
[0] = { i18n = "checks.dns_server" }, -- HOST_LABEL_DNS_SERVER
[1] = { i18n = "checks.ntp_server" }, -- HOST_LABEL_NTP_SERVER
[2] = { i18n = "checks.dhcp_server" }, -- HOST_LABEL_DHCP_SERVER
[3] = { i18n = "checks.smtp_server" }, -- HOST_LABEL_SMTP_SERVER
[4] = { i18n = "checks.network_gateway" }, -- HOST_LABEL_NETWORK_GATEWAY
}
-- ##############################################
local function get_redis_key()
return "ntopng.prefs.labels"
end
@ -17,14 +29,25 @@ end
local function get_default_labels_table()
local labels = {}
-- Bits 0-31: ntop built-in labels (read-only, auto-assigned by ntopng)
for id, entry in pairs(label_badge_utils.builtin_labels) do
labels[id] = {
id = id,
color = "#0d6efd",
description = "",
name = i18n(entry.i18n),
reserved = "true"
}
end
-- Bits 32-63: user-customizable labels
for i = 32, 63 do
labels[i] = {
id = i,
color = "#000000",
id = i,
color = "#000000",
description = "",
name = "Customizable_Label_" .. i,
reserved = "false"
name = "Customizable_Label_" .. i,
reserved = "false"
}
end
return labels
@ -113,4 +136,4 @@ function label_badge_utils.deleteLabel(id)
return true, success_msg
end
return label_badge_utils
return label_badge_utils