#!/usr/bin/perl # index.cgi # Display current nftables configuration require './nftables-lib.pl'; ## no critic use strict; use warnings; our (%in, %text, %config); ReadParse(); my $can_view_saved = check_acl('view'); if (!$can_view_saved && !check_acl('active') && !check_acl('create') && !check_acl('setup') && !check_manual_acl()) { error($text{'acl_ecannot'}); } my $partial = $in{'partial'}; if (!$partial) { ui_print_header(nft_version_text() || "", $text{'index_title'}, "", "intro", 1, 1, undef, restart_button()); } # quick_hidden_fields(table-index, &table, selected-view) # Returns hidden table selectors for quick action forms sub quick_hidden_fields { my ($idx, $table, $view) = @_; return ui_hidden("table", $idx). ui_hidden("table_family", $table->{'family'}). ui_hidden("table_name", $table->{'name'}). ui_hidden("view", $view); } # quick_service_autocomplete() # Returns the quick service textbox and JavaScript-backed matcher sub quick_service_autocomplete { my $placeholder = quote_escape($text{'quick_service_placeholder'}); my $results_style = "display: none; position: absolute; z-index: 1000; ". "left: 0; right: auto; width: 100%; min-width: 0; ". "max-height: 18em; overflow: auto; ". "border: 1px solid var(--border-color-input-results, ". "var(--border-color-input, #3f4855)); ". "border-radius: var(--border-radius-input, 3px); ". "background-color: var(--bg-color-input, #fff); ". "color: var(--text-color, inherit);"; my $results = ui_tag('div', undef, { 'id' => 'nftables_quick_service_results', 'role' => 'listbox', 'style' => $results_style, }); my $input = ui_textbox( "service_text", "", 32, undef, undef, "autocomplete='off' placeholder='".$placeholder."'" ); my $wrap = ui_tag('span', $input.$results, { 'id' => 'nftables_quick_service_wrap', 'style' => 'position: relative; display: inline-block; max-width: 100%;', }); return ui_hidden("service", ""). $wrap. quick_service_autocomplete_javascript(); } # quick_service_autocomplete_javascript() # Returns JavaScript for the quick service autocomplete widget sub quick_service_autocomplete_javascript { my $labels = convert_to_json({ 'no_matches' => $text{'quick_service_nomatch'}, 'failed' => $text{'quick_service_searchfail'}, }); my $js = <