require 'dhcpd-lib.pl'; # acl_security_form(&options) # Output HTML for editing security options for the dhcpd module sub acl_security_form { print "\n$text{'acl_apply'} \n"; printf " $text{'yes'}\n", $_[0]->{'apply'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'apply'} ? "" : "checked"; print "\n"; print "\n$text{'acl_global'} \n"; printf " $text{'yes'}\n", $_[0]->{'global'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'global'} ? "" : "checked"; print "\n"; print "\n$text{'acl_r_leases'} \n"; printf " $text{'yes'}\n", $_[0]->{'r_leases'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'r_leases'} ? "" : "checked"; print "\n"; print "\n$text{'acl_w_leases'} \n"; printf " $text{'yes'}\n", $_[0]->{'w_leases'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'w_leases'} ? "" : "checked"; print "\n"; print "\n$text{'acl_zones'} \n"; printf " $text{'yes'}\n", $_[0]->{'zones'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'zones'} ? "" : "checked"; print "\n"; print "
\n"; # uniqs print "\n$text{'acl_uniq_hst'} \n"; printf " $text{'yes'}\n", $_[0]->{'uniq_hst'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'uniq_hst'} ? "" : "checked"; print "\n"; print "\n$text{'acl_uniq_sub'} \n"; printf " $text{'yes'}\n", $_[0]->{'uniq_sub'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'uniq_sub'} ? "" : "checked"; print "\n"; print "\n$text{'acl_uniq_sha'} \n"; printf " $text{'yes'}\n", $_[0]->{'uniq_sha'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'uniq_sha'} ? "" : "checked"; print "\n"; print "
\n"; # security mode settings print "\n$text{'acl_seclevel'} \n"; printf " 0\n", $_[0]->{'smode'} == 0 ? "checked" : ""; printf " 1\n", $_[0]->{'smode'} == 1 ? "checked" : ""; printf " 2\n", $_[0]->{'smode'} == 2 ? "checked" : ""; printf " 3\n", $_[0]->{'smode'} == 3 ? "checked" : ""; print "\n\n"; print "\n$text{'acl_hide'} \n"; printf " $text{'yes'}\n", $_[0]->{'hide'} == 1 ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'hide'} == 0 ? "checked" : ""; print "\n"; print "
\n"; # global acls print "\n$text{'acl_ahst'}\n"; print "\n"; printf " %s\n", $_[0]->{'c_hst'} ? "checked" : "", $text{"acl_c"}; printf " %s\n", $_[0]->{'r_hst'} ? "checked" : "", $text{"acl_r"}; printf " %s\n", $_[0]->{'w_hst'} ? "checked" : "", $text{"acl_w"}; print " \n"; print "\n$text{'acl_agrp'}\n"; print "\n"; printf " %s\n", $_[0]->{'c_grp'} ? "checked" : "", $text{"acl_c"}; printf " %s\n", $_[0]->{'r_grp'} ? "checked" : "", $text{"acl_r"}; printf " %s\n", $_[0]->{'w_grp'} ? "checked" : "", $text{"acl_w"}; print " \n"; print "\n$text{'acl_asub'}\n"; print "\n"; printf " %s\n", $_[0]->{'c_sub'} ? "checked" : "", $text{"acl_c"}; printf " %s\n", $_[0]->{'r_sub'} ? "checked" : "", $text{"acl_r"}; printf " %s\n", $_[0]->{'w_sub'} ? "checked" : "", $text{"acl_w"}; print " \n"; print "\n$text{'acl_asha'}\n"; print "\n"; printf " %s\n", $_[0]->{'c_sha'} ? "checked" : "", $text{"acl_c"}; printf " %s\n", $_[0]->{'r_sha'} ? "checked" : "", $text{"acl_r"}; printf " %s\n", $_[0]->{'w_sha'} ? "checked" : "", $text{"acl_w"}; print " \n"; print "
\n"; # per-subnet and per-host acls print "$text{'acl_per_sub_acls'} \n"; printf " $text{'yes'}\n", $_[0]->{'per_sub_acls'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'per_sub_acls'} ? "" : "checked"; print "\n"; print "$text{'acl_per_sha_acls'} \n"; printf " $text{'yes'}\n", $_[0]->{'per_sha_acls'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'per_sha_acls'} ? "" : "checked"; print "\n"; print "$text{'acl_per_hst_acls'} \n"; printf " $text{'yes'}\n", $_[0]->{'per_hst_acls'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'per_hst_acls'} ? "" : "checked"; print "\n"; print "$text{'acl_per_grp_acls'} \n"; printf " $text{'yes'}\n", $_[0]->{'per_grp_acls'} ? "checked" : ""; printf " $text{'no'}\n", $_[0]->{'per_grp_acls'} ? "" : "checked"; print "\n"; print "
\n"; print "\n$text{'acl_per_obj_acls'} \n"; &display_tree($_[0],&get_parent_config(),-2); } # acl_security_save(&options) # Parse the form for security options for the sendmail module sub acl_security_save { if ($in{'r_sub'} < $in{'w_sub'} || $in{'r_sha'} < $in{'w_sha'} || $in{'r_hst'} < $in{'w_hst'} || $in{'r_grp'} < $in{'w_grp'}) { &error($text{'acl_ernow'}); } $_[0]->{'apply'}=$in{'apply'}; $_[0]->{'global'}=$in{'global'}; $_[0]->{'r_leases'}=$in{'r_leases'}; $_[0]->{'w_leases'}=$in{'w_leases'}; $_[0]->{'zones'}=$in{'zones'}; $_[0]->{'uniq_hst'}=$in{'uniq_hst'}; $_[0]->{'uniq_sub'}=$in{'uniq_sub'}; $_[0]->{'uniq_sha'}=$in{'uniq_sha'}; $_[0]->{'smode'}=$in{'smode'}; $_[0]->{'hide'}=$in{'hide'}; $_[0]->{'per_hst_acls'}=$in{'per_hst_acls'}; $_[0]->{'per_sub_acls'}=$in{'per_sub_acls'}; $_[0]->{'per_grp_acls'}=$in{'per_grp_acls'}; $_[0]->{'per_sha_acls'}=$in{'per_sha_acls'}; $_[0]->{'c_sub'}=$in{'c_sub'}; $_[0]->{'r_sub'}=$in{'r_sub'}; $_[0]->{'w_sub'}=$in{'w_sub'}; $_[0]->{'c_sha'}=$in{'c_sha'}; $_[0]->{'r_sha'}=$in{'r_sha'}; $_[0]->{'w_sha'}=$in{'w_sha'}; $_[0]->{'c_hst'}=$in{'c_hst'}; $_[0]->{'r_hst'}=$in{'r_hst'}; $_[0]->{'w_hst'}=$in{'w_hst'}; $_[0]->{'c_grp'}=$in{'c_grp'}; $_[0]->{'r_grp'}=$in{'r_grp'}; $_[0]->{'w_grp'}=$in{'w_grp'}; foreach (keys %in) { $_[0]->{$_}=$in{$_} if /^ACL\w\w\w_/; } } # perm_to(permissions_string,obj_type,\%access,obj_name) # check per-object permissions: # permissions_string= 'rw' 'r' 'w' or you perm_to extend this system # obj_type= 'sub' for subnets, or 'hst' for hosts. sub perm_to { local $acl=$_[2]->{'ACL'.$_[1].'_'.$_[3]}; foreach (split //,$_[0]) { return 0 if index($acl,$_) == -1; } return 1; } # link config node names and acl categories %onames=qw(shared-network sha subnet sub group grp host hst); # display_tree(\%access,\%config_node,display_padding) sub display_tree { local ($acc, $node, $pad)=@_; if (defined($node->{'name'})) { &display_node($acc,$node,$pad) if exists $onames{$node->{'name'}} ; } $pad+=2; if($node->{'members'}) { # recursevly process this subtree foreach (@{$node->{'members'}}) { &display_tree($acc, $_, $pad); } } return 1; } # display_node(\%access, \%node, padding) sub display_node { local($acc,$node,$padding)=@_; local $name=$node->{'values'}->[0]; if (!$name && $node->{'name'} eq 'group') { # Name comes from option domain-name local @opts = &find("option", $node->{'members'}); local ($dn) = grep { $_->{'values'}->[0] eq 'domain-name' } @opts; if ($dn) { $name = $dn->{'values'}->[1]; } else { $name = $node->{'index'}; } } local $nodetype=$onames{$node->{'name'}}; local $aclname='ACL'.$nodetype.'_'.$name; print "\n"," "x$padding, " $node->{'name'}: $name\n"; if (($nodetype eq 'hst')||($nodetype eq 'sub')|| ($nodetype eq 'grp')||($nodetype eq 'sha')) { print "\n"; if($acc->{$aclname}) { printf " %s\n", !&perm_to('r',$nodetype,$acc,$name) ? "checked" : "", $text{"acl_na"}; printf " %s\n", &perm_to('r',$nodetype,$acc,$name) && !&perm_to('rw',$nodetype,$acc,$name) ? "checked" : "",$text{"acl_r1"}; printf " %s\n", &perm_to('rw',$nodetype,$acc,$name) ? "checked" : "", $text{"acl_rw"}; } else { printf " %s\n", $text{"acl_na"}; printf " %s\n", $text{"acl_r1"}; printf " %s\n", $text{"acl_rw"}; } print "\n"; } print "\n"; } 1;