klugerama / webmin-dnsmasq

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

Attempt to fix dhcp_range_apply.cgi #63

Open behrlevi opened 1 day ago

behrlevi commented 1 day ago

I'm trying to fix this script.

Started with a very simple approach which should write only the start address:

!/usr/bin/perl

use strict; use warnings; use Data::Dumper; require 'dnsmasq-lib.pl'; our (%in, %config, %dnsmconfig); my $config_filename = $config{config_file}; my $config_file = &read_file_lines($config_filename); &parse_config_file(\%dnsmconfig, \$config_file, $config_filename); my $val = $in{"new_dhcp_range_start_4"}; &add_to_list("dhcp-range", $val); &redirect("dhcp_range.cgi");

The issue is that the the $in variable is empty.

I'm trying to consult dhcp_reseravations_apply which is working and using the exact same mechanism.

I managed to gather information about the form objects:

$VAR1 = { 'dhcp_range_end' => '', 'new_dhcp_range_end' => '', 'dhcp_range_leasetime' => '', 'dhcp_range_ipversion' => '', 'dhcp_range_start' => '', 'dhcp_range_static' => '', 'new_dhcp_range_static' => '', 'new_dhcp_range_settag' => '', 'dhcp_range_broadcast' => '', 'new_dhcp_range_mask' => '', 'dhcp_range_tag' => '', 'dhcp_range_proxy' => '', 'dhcp_range_mask' => '', 'new_dhcp_range_proxy' => '', 'new_dhcp_range_tag' => '', 'ipversion' => 'ip4', 'new_dhcp_range_start' => '', 'dhcp_range_settag' => '', 'dhcp_range_cfg_idx' => '', 'new_dhcp_range_ipversion' => '4', 'new_dhcp_range_leasetime' => '', 'new_dhcp_range_broadcast' => '' };

And also inserted debug prints in list_item_edit_chooser.cgi to see what is coming out of the form.

It seems that the value from the field is recorded:

Form data received: $VAR1 = { '-----------------------------300632090316617847232446898661 Content-Disposition: form-data; name' => '"new_dhcp_range_ipversion"

4 -----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="new_dhcp_range_tag_4"

-----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="new_dhcp_range_settag_4"

-----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="new_dhcp_range_start_4"

192.168.102.1 -----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="new_dhcp_range_end_4"

-----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="new_dhcp_range_mask_4"

-----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="new_dhcp_range_broadcast_4"

-----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="new_dhcp_range_leasetime_4"

-----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="cancel"

-----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="submit_4"

Save -----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="submit_4"

Save -----------------------------300632090316617847232446898661 Content-Disposition: form-data; name="submit_4"

Save -----------------------------300632090316617847232446898661-- ' };

The value is recorded in new_dhcp_range_start_4 which I'm trying to access , but getting an error: Use of uninitialized value $dnsmasq::in{"submit_4"} in string eq at /usr/share/webmin/dnsmasq/dhcp_range_apply.cgi line 26.

Seems to me that the data is not sent over to the apply script.

What do you think about this? Got any tips what to check?

behrlevi commented 1 day ago

I also tried:

if ($in{"submit_4"} eq "Save") { my $val = $in{"new_dhcp_range_start_4"};

if ($in{"new_dhcp_range_end_4"}) {
    $val .= "," . $in{"new_dhcp_range_end_4"};
}
if ($in{"new_dhcp_range_leasetime_4"}) {
    $val .= "," . $in{"new_dhcp_range_leasetime_4"};
}

# Only add if we have at least a start address
if ($val && $val ne "") {
    &add_to_list("dhcp-range", $val);
}

}

Which looks for the the submission, but did not work either.

Maybe I'm making some rookie mistake as I'm not proficient in Perl and software development in general.