klugerama / webmin-dnsmasq

A Webmin module for managing dnsmasq
6 stars 1 forks source link

Can't use an undefined value as a HASH reference at /usr/share/webmin/dnsmasq/error.cgi #61

Open tomachinz opened 3 months ago

tomachinz commented 3 months ago

Thank you for writing this useful module!

To get the error I am:

  1. Running Kubuntu and webmin, no DNSmasq installed as yet
  2. Install your module from https link from github
  3. I note it said it could not find dnsmasq config file so just at that point I...
  4. apt install dnsmasq (cant remember if before or after viewing page below)
  5. click to see some config. at /dnsmasq/?xnavigation=1 which shows error it offers a detail page at
  6. /dnsmasq/error.cgi?returnto=index.cgi&returnlabel=DNS settings&xnavigation=1

HTTP/1.0 500 Perl execution failed Server: MiniServ/2.111 Date: Tue, 16 Jul 2024 03:19:30 GMT Content-type: text/html; Charset=utf-8 Connection: close

Error — Perl execution failed. Can't use an undefined value as a HASH reference at /usr/share/webmin/dnsmasq/error.cgi line 70.

Line 70: my $nav = %{%dnsmnav{$fd->{"section"}}}{$fd->{"page"}};

cat /usr/share/webmin/dnsmasq/error.cgi


#!/usr/bin/perl
#
#    DNSMasq Webmin Module - # TODO error.cgi; report errors
#    Copyright (C) 2023 by Loren Cress
#    
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    This module based on the DNSMasq Webmin module by Neil Fisher

require 'dnsmasq-lib.pl';
## put in ACL checks here if needed

my $config_filename = $config{config_file};
my $config_file = &read_file_lines( $config_filename );

&parse_config_file( \%dnsmconfig, \$config_file, $config_filename );
# read posted data
&ReadParse();

&ui_print_header($text{"configuration_errors_heading"}, $text{"index_title"}, "", "intro", 1, 0, 0, &restart_button());
print &header_js(\%dnsmconfig);

# output as web page
&ReadParse();

my $returnto = $in{"returnto"} || "index.cgi?tab=dns";
my $returnlabel = $in{"returnlabel"} || $text{"index_dns_settings"};

## Insert Output code here

print &ui_form_start($returnto, "post");
print &ui_hidden("returnto", $returnto);
print &ui_hidden("forced_edit", 1);
my $count = 0;
foreach my $error ( @{$dnsmconfig{"error"}} ) {
    print &ui_hidden( "file_" . $count, $error->{"file"} );
    print &ui_hidden( "line_" . $count, $error->{"line"} );
    print &ui_hidden( "configfield_" . $count, $error->{"configfield"} );
    $count++;
}
my @list_link_buttons = &list_links( "sel", 1 );
print &ui_links_row(\@list_link_buttons);
my @error_fields = ( "configfield", "param", "file", "line", "desc" );
my @column_headers = ( "" );
foreach my $key ( @error_fields ) {
    push ( @column_headers, $text{"err_" . $key} );
}
push ( @column_headers, "" ); # for the manual edit button
print &ui_columns_start( \@column_headers, );
$count = 0;
my @fs = ( "file", "path", "dir" );
foreach my $error ( @{$dnsmconfig{"error"}} ) {
    my @cols;
    my $link_target = "";
    my $configfield = $error->{"configfield"};
    my $internalfield = &config_to_internal($configfield);
    my $param = $error->{"param"};
    my $fd = $dnsmconfigvals{"$configfield"};
    my $fdef = $configfield_fields{$internalfield};
    my $pdef = \%{ $fdef->{"$param"} };
    my $type = $pdef->{"valtype"};
    my $nav = %{%dnsmnav{$fd->{"section"}}}{$fd->{"page"}};
    $link_target = $nav->{"cgi_name"} . "?" . ($nav->{"cgi_params"} ? $nav->{"cgi_params"} . "&" : "") . "forced_edit=1&bad_ifield=$internalfield&line=" . $error->{"line"} . "&show_validation=" . $internalfield . "_" . $error->{"param"} . "&custom_error=" . $error->{"custom_error"};
    if ($nav->{"tab"}) {
        $link_target .= "&tab=" . $nav->{"tab"}->{$fd->{"tab"}};
    }
    if ($error->{"cfg_idx"} ne "-1") {
        $link_target .= "&cfg_idx=" . $error->{"cfg_idx"};
    }
    foreach my $key ( @error_fields ) {
        my $link = "<a href=\"" . $link_target . "\">" . $error->{$key} . "</a>";
        push ( @cols, $link );
    }
    my $buttons = "<a href=\"manual_edit.cgi?file=" . $error->{"file"} . "&line=" . $error->{"line"} . "\" class=\"btn btn-tiny\"><i class='fa fa-fw fa-files-o -cs' style='margin-right:5px;'></i>" . $text{"button_manual_edit"} . "</a>";
    # webmin_debug_log("--------ERROR", "configfield: $configfield type: $type param: $param error_type: ". $error->{"error_type"} . " ERR_FILE_PERMS: " . ERR_FILE_PERMS());
    if ((grep { /^$type$/ } ( @fs )) && $error->{"error_type"} == ERR_FILE_PERMS() && $access{"change_perms"}) {
        $buttons .= "<a href=\"$returnto" . ($returnto =~ /\?/ ? "&" : "?") . "forced_edit=1&fix_perms=1&ifield=" . $internalfield . "&cfg_idx=" . $error->{"cfg_idx"} . "&param=" . $param . "&foruser=" . $error->{"foruser"} . "&forgroup=" . $error->{"forgroup"} . "&perms_failed=" . $error->{"perms_failed"} . "\" class=\"btn btn-tiny\"><i class='fa fa-fw fa-files-o -cs' style='margin-right:5px;'></i>" . $text{"button_fix_permissions"} . "</a>";
    }
    push ( @cols, $buttons );
    print &ui_clickable_checked_columns_row( \@cols, undef, "sel", $count, 1 );
    $count++;
}
print &ui_columns_end();
print &ui_links_row(\@list_link_buttons);
print "<p>" . $text{"with_selected"} . "</p>";
print &ui_submit($text{"button_disable_sel"}, "button_disable_sel");
print &ui_submit($text{"button_delete_sel"}, "button_delete_sel");
print &ui_form_end();

print &add_js();

&ui_print_footer($returnto, $returnlabel);

### END of error.cgi ###.

Maybe I should have used the .deb file?