Option for separate config file to add new top-level objects to
authorJamie Cameron <jcameron@webmin.com>
Thu, 19 Mar 2009 22:02:04 +0000 (22:02 +0000)
committerJamie Cameron <jcameron@webmin.com>
Thu, 19 Mar 2009 22:02:04 +0000 (22:02 +0000)
dhcpd/CHANGELOG
dhcpd/config.info
dhcpd/dhcpd-lib.pl
dhcpd/save_group.cgi
dhcpd/save_host.cgi
dhcpd/save_shared.cgi
dhcpd/save_subnet.cgi

index 5ae96d0..57fd025 100644 (file)
@@ -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.
index 4c7d12b..9f102bd 100644 (file)
@@ -8,6 +8,7 @@ show_mac=Show MAC addresses for hosts?,1,1-Yes,0-No
 group_name=Show group names as,1,1-<tt>domain&#45;name</tt> 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&#44; 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
index a584567..7083bb6 100755 (executable)
@@ -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'}} };
index ab6f77e..ac8655f 100755 (executable)
@@ -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
index fc10238..77fcec6 100755 (executable)
@@ -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();
index aae3f83..e4b11b6 100755 (executable)
@@ -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
index 2dd9db0..b98b51d 100755 (executable)
@@ -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'});
                        }