Files
webmin/kea-dhcp/save_text.cgi
Ilia Ross 184887d365
Some checks failed
Tests / prove (push) Has been cancelled
Build / build (push) Has been cancelled
Close inactive / close-inactive (push) Has been cancelled
Fix to use direct ACL checks in Kea DHCP module
*Note: Removes Kea-specific ACL wrapper helpers and switches ACL editor/runtime checks to standard Webmin handling with direct supplied ACL values and get_module_acl checks.
2026-05-30 02:53:48 +02:00

49 lines
1.5 KiB
Perl
Executable File

#!/usr/local/bin/perl
# Save a raw Kea file.
use strict;
use warnings;
require './kea-dhcp-lib.pl'; ## no critic
&ReadParseMime();
our (%in, %text);
&error_setup($text{'eacl_aviol'});
my %access = &get_module_acl();
&error("$text{'eacl_np'} $text{'eacl_pmanual'}") if (!$access{'manual'});
my $info = &kea_manual_edit_file($in{'file'});
&error($text{'save_efile'}) if (!$info);
my $file = $info->{'file'};
&error($text{'save_efile'}) if (!$file);
&error_setup($text{'save_failsave'});
if ($info->{'type'} eq 'config') {
# Raw Kea config edits still get parsed before writing so a typo does
# not leave the daemon with unreadable JSON.
my $c = $info->{'component'};
my $data = eval { &kea_parse_config_text($in{'data'}, $file) };
&error(&text('save_eparse', $@)) if ($@);
&error(&text('parse_eroot', $c->{'root'}))
if (ref($data->{$c->{'root'}}) ne 'HASH');
}
# Write via Webmin's tempfile helpers to preserve the normal locking behavior.
my $existed = -e $file;
&lock_file($file);
my $fh;
&open_tempfile($fh, ">$file");
&print_tempfile($fh, $in{'data'});
&close_tempfile($fh);
&unlock_file($file);
if ($info->{'type'} eq 'password' && !$existed) {
# New Control Agent password files should inherit the config directory
# group and be readable only by root plus that group.
my @dst = stat(&kea_dirname($file));
chown(-1, $dst[5], $file) if (@dst);
chmod(0640, $file);
}
my %log = %in;
delete($log{'data'});
&webmin_log("modify", "config", $file, \%log);
&redirect("");