* Fixed #8492, removed unused formatting function in lua

* Fixed host pool doc #8487

---------

Co-authored-by: DGabri <gabriele.deri@gmail.com>
This commit is contained in:
GabrieleDeri 2024-07-05 10:34:09 +02:00 committed by GitHub
parent 51cb277850
commit e06896e58f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 133 additions and 30 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 KiB

After

Width:  |  Height:  |  Size: 124 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 KiB

After

Width:  |  Height:  |  Size: 143 KiB

Before After
Before After

View file

@ -3,8 +3,8 @@
Host Pools
##########
Host pools are logical groups of hosts. Pools can be created or managed from the *System* interface,
*Pools* menu. It is possible to add new pools using the “plus” button in the same page.
Host pools are logical groups of hosts. Pools can be created or managed from any ntopng interface (except System),
*Hosts* > *Host/Network/MAC Pools* menu entry. It is possible to add new pools using the "gear" button in the same page which will redirect to a new page to manage pools.
.. figure:: ../img/web_gui_interfaces_edit_pools.png
:align: center
@ -13,7 +13,7 @@ Host pools are logical groups of hosts. Pools can be created or managed from the
The Pools Page
Once an Host Pool is created, it is possible to add members to it. Host Pool members can be added
from the *Pools* > *Host Pool Members* page, using the “plus” button.
from the *Hosts* > *Host/Network/MAC Pools* page, clicking the gear icon which will redirect to a new page with a table. To add a new host click the “plus” button.
.. figure:: ../img/web_gui_interfaces_edit_host_pool.png
:align: center

View file

@ -61,6 +61,7 @@ import { default as PageSNMPQoS } from "./page-snmp-qos.vue"
import { default as PageGeoMap } from "./hosts-geomap.vue"
import { default as PageCountryStats } from "./page-country-stats.vue"
import { default as PageAsStats } from "./page-as-stats.vue"
import { default as PageChatbot } from "./page-chatbot.vue"
/* Config pages */
import { default as PageSNMPConfig } from "./page-snmp-config.vue"
@ -165,7 +166,7 @@ let ntopVue = {
NedgeRepeatersConfig: NedgeRepeatersConfig,
PageBlacklists: PageBlacklists,
PageChatbot: PageChatbot,
// Host details pages
PageHostDetailsApplications: PageHostDetailsApplications,
PageHostDetailsTraffic: PageHostDetailsTraffic,

View file

@ -311,6 +311,17 @@ else
}}
})
-- ##############################################
--[[
page_utils.add_menubar_section({
section = page_utils.menu_sections.chatbot,
hidden = is_system_interface or is_viewed,
entries = {{
entry = page_utils.menu_entries.chatbot,
url = '/lua/chatbot.lua'
}}})
]]--
-- ##############################################
local checks = require "checks"
local interface_config = checks.getConfigset()["config"]["interface"]

View file

@ -54,6 +54,7 @@ page_utils.menu_sections = {
device_exclusions = {key = "device_exclusions", i18n_title = "edit_check.device_exclusions", icon = "fas fa-bell-slash"},
dev = {key = "dev", i18n_title = "developer", icon = "fas fa-code"},
about = {key = "about", i18n_title = "help", icon = "fas fa-life-ring"},
chatbot = {key = "chatbot", i18n_title = "chatbot", icon = "fa-solid fa-headset"},
health = {key = "health", i18n_title = "health", icon = "fas fa-laptop-medical"},
pollers = {key = "pollers", i18n_title = "pollers", icon = "fas fa-heartbeat"},
tools = {key = "tools", i18n_title = "tools", icon = "fas fa-cogs"},
@ -108,6 +109,8 @@ page_utils.menu_entries = {
pods = {key = "pods", i18n_title = "containers_stats.pods", section = "hosts"},
host_rules = {key = "host_rules", i18n_title = "if_stats_config.traffic_rules", section = "hosts", help_link = "https://www.ntop.org/guides/ntopng/advanced_features/host_rules.html"},
-- Chatbot
chatbot = {key = "chatbot", i18n_title = "chatbot", section = "chatbot"},
-- Interface
interface = {key = "interface", i18n_title = "interface_details", section = "if_stats"},
ports_analysis = {key = "ports_analysis", i18n_title = "ports_analysis.server_ports", section = "if_stats"},

View file

@ -28,43 +28,131 @@ args = parser.parse_args()
input_file = args.input_file
output_file = args.output_file
translator = GoogleTranslator(source=args.input_language, target=args.output_language)
def translate_string(string_to_translate, max_retries=3):
return str(translator.translate(string_to_translate))
if (DEBUGGING):
# get file length in number of lines
with open(input_file, 'r', encoding='utf-8') as infile:
input_lines = infile.readlines()
with open(output_file, 'r', encoding='utf-8') as transfile:
translated_lines = transfile.readlines()
total_lines = len(input_lines)
if (DEBUGGING):
print(f"Total lines to process: {total_lines}")
done = 0
# pattern to retrieve i18n string content
pattern = r'\s*\[\s*\"[^\"]+\"\s*\]\s*=\s*\"((?:\\.|[^\"])*)\"\s*,'
# pattern to retrieve non escaped "
pattern_non_escaped = r'(?<!\\)"'
# translator initialization
translator = GoogleTranslator(source=args.input_language, target=args.output_language)
translator = GoogleTranslator(source="en", target="fr")
# function to translate a given string
def translate_string(string_to_translate):
return str(translator.translate(string_to_translate))
# function that given in input a list of regex matches and a line
# translated the source file value and substitutes the translated value in the original line, returning the output line
def translate_and_replace_line(regex_matches, line):
translated_value = translator.translate(str(regex_matches[0]))
return line.replace(matches[0], str(re.sub(pattern_non_escaped, r'\"', str(translated_value))))
input_file = "/home/data/develop/ntopng/scripts/locales/en.lua"
output_file = "/home/data/develop/ntopng/scripts/locales/test.lua"
with open(input_file, encoding='utf-8') as f1:
input_lines = f1.readlines()
with open(output_file, encoding='utf-8') as f2:
output_lines = f2.readlines()
output_index = 0
# Compare lines and insert mismatched lines
for lineno, (line1, line2) in enumerate(zip(input_lines, output_lines), 1):
matches_input = line1.split("=")[0].strip()
matches_output = line2.split("=")[0].strip()
print(matches_input)
print(matches_output)
print("******************")
if matches_input != matches_output:
print(f"Line {lineno} mismatch:")
print(f"Input file: {line1.strip()}")
print(f"Output file: {line2.strip()}")
# Insert the mismatched input line into the output file between current and next line
output_lines.insert(output_index + 1, line1)
output_index += 1
with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile:
for line in infile:
matches = re.findall(pattern, line)
if (len(matches) > 0):
translated_value = translator.translate(str(matches[0]))
line = line.replace(matches[0], str(re.sub(pattern_non_escaped, r'\"', str(translated_value))))
line = translate_and_replace_line(matches, line)
outfile.write(f"{str(line)}")
else:
outfile.write(line)
input_file = "/home/data/develop/ntopng/scripts/locales/en.lua"
output_file = "/home/data/develop/ntopng/scripts/locales/test.lua"
with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'r+', encoding='utf-8') as outfile:
input_line = infile.readline()
output_line = outfile.readline()
while input_line:
if output_line:
matches_input = input_line.split("=")[0].strip()
matches_output = output_line.split("=")[0].strip()
else:
matches_output = None
if matches_input == matches_output:
output_line = outfile.readline().strip() # Read next line from output
else:
print(f"Mismatch found. Input: '{input_line}', Output: '{output_line}'")
# Move the output file pointer back to insert the line
#current_pos = outfile.tell()
#remaining_output = outfile.read() # Read the rest of the file
#outfile.seek(current_pos) # Go back to the current position
#outfile.write(input_line + "\n") # Write the mismatched line
#outfile.write(remaining_output) # Append the rest of the file
#outfile.seek(current_pos) # Rewind to the current position for next comparison
#output_line = input_line # Consider the inserted line for next comparison
input_line = infile.readline() # Read next line from input
print("Synchronization complete.")
##################
with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'r+', encoding='utf-8') as outfile:
input_line = infile.readline().strip()
output_line = outfile.readline().strip()
output_lines = [] # To store updated lines
output_position = outfile.tell()
while input_line:
if output_line:
matches_input = input_line.split("=")[0].strip()
matches_output = output_line.split("=")[0].strip()
else:
matches_output = None
done += 1
if (DEBUGGING):
print(f"Translated: [{done}/{total_lines}]")
if matches_input == matches_output:
# If lines match, add the output line to the list and read the next output line
output_lines.append(output_line + "\n")
output_line = outfile.readline() # Read next line from output
output_position = outfile.tell()
input_line = infile.readline() # Move to the next input line
else:
print(f"Mismatch found. Input: '{input_line}', Output: '{output_line}'")
# Add the mismatched input line to the output list
output_lines.append(input_line + "\n")
# Skip to re-read the mismatched output line and keep input line the same
output_line = None # Reset to re-read the same input line on next loop
# Write the updated output lines back to the file
outfile.seek(0) # Go to the beginning of the file
outfile.truncate() # Clear the file content
outfile.writelines(output_lines) # Write all the lines