From 8712062cccf2e9fa12cc6901ac883153d330ae6d Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Thu, 19 Mar 2009 22:02:04 +0000 Subject: [PATCH] Option for separate config file to add new top-level objects to --- dhcpd/CHANGELOG | 2 ++ dhcpd/config.info | 1 + dhcpd/dhcpd-lib.pl | 33 ++++++++++++++++++++------------- dhcpd/save_group.cgi | 2 +- dhcpd/save_host.cgi | 2 +- dhcpd/save_shared.cgi | 2 +- dhcpd/save_subnet.cgi | 10 +--------- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/dhcpd/CHANGELOG b/dhcpd/CHANGELOG index 5ae96d089..57fd025cd 100644 --- a/dhcpd/CHANGELOG +++ b/dhcpd/CHANGELOG @@ -28,3 +28,5 @@ Fixed bug that can cause option definitions and values to be incorrectly ordered Custom option types defined at a higher level (such as in a subnet) can be used in the Edit Options page at lower levels (such as in a host). ---- Changes since 1.440 ---- When a subnet or host is renamed, the user's ACL is updated to match. +---- Changes since 1.470 ---- +Added a Module Config option to specify an alternate file to add new top-level objects (like subnets) to. This must be referenced by an include directive in the main dhcpd.conf though. diff --git a/dhcpd/config.info b/dhcpd/config.info index 4c7d12b68..9f102bd0c 100644 --- a/dhcpd/config.info +++ b/dhcpd/config.info @@ -8,6 +8,7 @@ show_mac=Show MAC addresses for hosts?,1,1-Yes,0-No group_name=Show group names as,1,1-domain-name option,0-Name or member count,2-Description desc_name=Show other object descriptions instead of names?,1,1-Yes,0-No display_max=Maximum number of subnets and hosts to display,3,Unlimited +add_file=Add new subnets, hosts and groups to file,3,Main configuration file line2=System configuration,11 dhcpd_conf=DHCP server config file,0 dhcpd_path=DHCP server executable,0 diff --git a/dhcpd/dhcpd-lib.pl b/dhcpd/dhcpd-lib.pl index a5845673d..7083bb60a 100755 --- a/dhcpd/dhcpd-lib.pl +++ b/dhcpd/dhcpd-lib.pl @@ -5,27 +5,31 @@ BEGIN { push(@INC, ".."); }; use WebminCore; &init_config(); -# get_parent_config() +# get_parent_config([file]) # Returns a dummy parent structure for the DHCP config sub get_parent_config { -return $get_parent_config_cache if ($get_parent_config_cache); -return $get_parent_config_cache = { - 'file' => $config{'dhcpd_conf'}, - 'members' => &get_config(), +local ($file) = @_; +$file ||= $config{'dhcpd_conf'}; +return $get_parent_config_cache{$file} if ($get_parent_config_cache{$file}); +return $get_parent_config_cache{$file} = { + 'file' => $file, + 'members' => &get_config($file), 'line' => -1, 'fline' => -1, 'eline' => $get_config_lines }; } -# get_config() +# get_config([file]) # Parses the DHCPD config file into a data structure sub get_config { -return \@get_config_cache if (@get_config_cache); -local @rv = &get_config_file($config{'dhcpd_conf'}, \$get_config_lines); -@get_config_cache = @rv; -return \@get_config_cache; +local ($file) = @_; +$file ||= $config{'dhcpd_conf'}; +return $get_config_cache{$file} if ($get_config_cache{$file}); +local @rv = &get_config_file($file, \$get_config_lines); +$get_config_cache{$file} = \@rv; +return $get_config_cache{$file}; } # get_config_file(file, [&lines]) @@ -591,7 +595,7 @@ return @{$hr}; # hash that links objtypes shortcuts with object names %obj_names2types = qw(host hst group grp subnet sub shared-network sha); -# get_branch($objtype) +# get_branch(objtype, [addmode]) # usefull for edit_*.cgi and save_*.cgi scripts # $objtype = one of 'hst' 'grp' 'sub' 'sha' sub get_branch @@ -599,7 +603,9 @@ sub get_branch local %obj_types2names = reverse %obj_names2types; local $name = $obj_types2names{$_[0]}; local ($parnode, $nparnode, $node, $indent, $nindent); -$parnode = $nparnode = &get_parent_config(); +$parnode = $nparnode = &get_parent_config( + $_[1] && $in{'sidx'} eq '' && $in{'uidx'} eq '' && $in{'gidx'} eq '' && + $in{'parent'} eq '' ? $config{'add_file'} : undef); $indent = $nindent = 0; foreach ($in{'sidx'}, $in{'uidx'}, $in{'gidx'}) { if ($_ ne '') { @@ -671,7 +677,8 @@ local $acl; local ($perm, $acc, $node, $smode) = @_; local @perm = split(//, $perm); -if ($node ne get_parent_config()) { +if ($node ne get_parent_config() && + $node ne get_parent_config($config{'add_file'})) { foreach (@perm) { next if ($_ ne 'c') && ($_ ne 'r') && ($_ ne 'w'); return 0 unless $acc->{$_ . '_' . $obj_names2types{$node->{'name'}} }; diff --git a/dhcpd/save_group.cgi b/dhcpd/save_group.cgi index ab6f77e3d..ac8655f88 100755 --- a/dhcpd/save_group.cgi +++ b/dhcpd/save_group.cgi @@ -6,7 +6,7 @@ require './dhcpd-lib.pl'; require './params-lib.pl'; &ReadParse(); &lock_file($config{'dhcpd_conf'}); -($par, $group, $indent, $npar, $nindent) = get_branch('grp'); +($par, $group, $indent, $npar, $nindent) = get_branch('grp', $in{'new'}); $parconf = $par->{'members'}; # check acls diff --git a/dhcpd/save_host.cgi b/dhcpd/save_host.cgi index fc10238ed..77fcec625 100755 --- a/dhcpd/save_host.cgi +++ b/dhcpd/save_host.cgi @@ -6,7 +6,7 @@ require './dhcpd-lib.pl'; require './params-lib.pl'; &ReadParse(); &lock_file($config{'dhcpd_conf'}); -($par, $host, $indent, $npar, $nindent) = get_branch('hst'); +($par, $host, $indent, $npar, $nindent) = get_branch('hst', $in{'new'}); # check acls %access = &get_module_acl(); diff --git a/dhcpd/save_shared.cgi b/dhcpd/save_shared.cgi index aae3f8360..e4b11b67c 100755 --- a/dhcpd/save_shared.cgi +++ b/dhcpd/save_shared.cgi @@ -6,7 +6,7 @@ require './dhcpd-lib.pl'; require './params-lib.pl'; &ReadParse(); &lock_file($config{'dhcpd_conf'}); -($par, $sha, $indent) = &get_branch('sha'); +($par, $sha, $indent) = &get_branch('sha', $in{'new'}); $parconf = $par->{'members'}; # check acls diff --git a/dhcpd/save_subnet.cgi b/dhcpd/save_subnet.cgi index 2dd9db0d8..b98b51ddd 100755 --- a/dhcpd/save_subnet.cgi +++ b/dhcpd/save_subnet.cgi @@ -6,7 +6,7 @@ require './dhcpd-lib.pl'; require './params-lib.pl'; &ReadParse(); &lock_file($config{'dhcpd_conf'}); -($par, $sub, $indent, $npar, $nindent) = get_branch('sub'); +($par, $sub, $indent, $npar, $nindent) = get_branch('sub', $in{'new'}); $parconf = $par->{'members'}; # check acls @@ -160,14 +160,6 @@ else { $sub->{'comment'} = $in{'desc'}; &parse_params($sub, 0); -# $npar = &get_parent_config(); -# $nindent = 0; -# if ($in{'parent'} ne "") { -# $nindent = 1; -# if ($in{'parent'} < @{$npar->{'members'}}) { -# $npar = $npar->{'members'}->[$in{'parent'}]; -# } -# } if (!npar || $in{'assign'} > 0 && $npar->{'name'} ne "shared-network") { &error($text{'sgroup_echanged'}); }