#!/usr/local/bin/perl # edit_host.cgi # Edit or create a host require './dhcpd-lib.pl'; require './params-lib.pl'; &ReadParse(); $conf = &get_config(); ($par, $host) = &get_branch('hst'); $hconf = $host->{'members'}; # check acls %access = &get_module_acl(); &error_setup($text{'eacl_aviol'}); if ($in{'new'} ) { &error("$text{'eacl_np'} $text{'eacl_pih'}") unless &can('c', \%access, $host) && &can('rw', \%access, $par); } else { &error("$text{'eacl_np'} $text{'eacl_psh'}") if !&can('r', \%access, $host); } # display if ($in{'uidx'} ne '') { local $s = $in{'sidx'} eq '' ? $conf->[$in{'uidx'}] : $conf->[$in{'sidx'}]->{'members'}->[$in{'uidx'}]; $desc = &text('ehost_subnet', $s->{'values'}->[0], $s->{'values'}->[2]); } elsif ($in{'sidx'} ne '') { local $s = $conf->[$in{'sidx'}]; $desc = &text('ehost_shared', $s->{'values'}->[0]); } &ui_print_header($desc, $in{'new'} ? $text{'ehost_crheader'} : $text{'ehost_eheader'}, ""); @shar = &find("shared-network", $conf); @subn = &find("subnet", $conf); @group = &find("group", $conf); $iu = 0; $is = 0; $ig = 0; foreach $g (@group) { $gm = 0; foreach $h (&find("host", $g->{'members'})) { $gm++; }; push(@group_desc, &group_name($gm, $g)); $group_desc[$#group_desc-1] =~ s/ / /g; $script3 .= "parent.options[$ig] = " ."new Option(\"$group_desc[$ig]\", $ig)\n" ."parent.options[$ig].value = " ."new String(\"$g->{'index'}\")\n" if &can('rw', \%access, $g); if ($in{'sidx'} eq '' && $in{'uidx'} eq '' && $in{'gidx'} eq $g->{'index'}) { $sel_parent = $ig; $currpar = "$g->{'index'}"; } $ig ++; } foreach $u (@subn) { push(@subn_desc, $u->{'values'}->[0]); $script2 .= "parent.options[$iu] = " ."new Option(\"$subn_desc[$iu]\", $iu)\n" ."parent.options[$iu].value = " ."new String(\"$u->{'index'}\")\n" if &can('rw', \%access, $u); if ($in{'sidx'} eq '' && $in{'uidx'} eq $u->{'index'} && $in{'gidx'} eq '') { $sel_parent = $iu; $currpar = "$u->{'index'}"; } foreach $g (&find("group", $u->{'members'})) { push(@group, $g); $gm = 0; foreach $h (&find("host", $g->{'members'})) { $gm ++; }; push(@group_desc, &group_name($gm, $g). " $text{'ehost_in'} $u->{'values'}->[0]"); $group_desc[$#group_desc-1] =~ s/ / /g; $subnet{$g} = $u->{'index'}; $script3 .= "parent.options[$ig] = " ."new Option(\"$group_desc[$ig]\", $ig)\n" ."parent.options[$ig].value = " ."new String(\"$u->{'index'},$g->{'index'}\")\n" if &can('rw', \%access, $g); if ($in{'sidx'} eq '' && $in{'uidx'} eq $u->{'index'} && $in{'gidx'} eq $g->{'index'}) { $sel_parent = $ig; $currpar = "$u->{'index'},$g->{'index'}"; } $ig ++; } $iu ++; } foreach $s (@shar) { push(@shar_desc, $s->{'values'}->[0]); $script1 .= "parent.options[$is] = " ."new Option(\"$shar_desc[$is]\", $is)\n" ."parent.options[$is].value = " ."new String(\"$s->{'index'}\")\n" if &can('rw', \%access, $s); if ($in{'sidx'} eq $s->{'index'} && $in{'uidx'} eq '' && $in{'gidx'} eq '') { $sel_parent = $is; $currpar = "$s->{'index'}"; } foreach $g (&find("group", $s->{'members'})) { push(@group, $g); $gm = 0; foreach $h (&find("host", $g->{'members'})) { $gm ++; }; push(@group_desc, &group_name($gm, $g). " $text{'ehost_in'} $s->{'values'}->[0]"); $group_desc[$#group_desc-1] =~ s/ / /g; $shared{$g} = $s->{'index'}; $script3 .= "parent.options[$ig] = " ."new Option(\"$group_desc[$ig]\", $ig)\n" ."parent.options[$ig].value = " ."new String(\"$s->{'index'},$g->{'index'}\")\n" if &can('rw', \%access, $g); if ($in{'sidx'} eq $s->{'index'} && $in{'uidx'} eq '' && $in{'gidx'} eq $g->{'index'}) { $sel_parent = $ig; $currpar = "$s->{'index'},$g->{'index'}"; } $ig ++; } foreach $u (&find("subnet", $s->{'members'})) { push(@subn, $u); push(@subn_desc, "$u->{'values'}->[0] $text{'ehost_in'} $s->{'values'}->[0]"); $shared{$u} = $s->{'index'}; $script2 .= "parent.options[$iu] = " ."new Option(\"$subn_desc[$iu]\", $iu)\n" ."parent.options[$iu].value = " ."new String(\"$s->{'index'},$u->{'index'}\")\n" if &can('rw', \%access, $u); if ($in{'sidx'} eq $s->{'index'} && $in{'uidx'} eq $u->{'index'} && $in{'gidx'} eq '') { $sel_parent = $iu; $currpar = "$s->{'index'},$u->{'index'}"; } foreach $g (&find("group", $u->{'members'})) { push(@group, $g); $gm = 0; foreach $h (&find("host", $g->{'members'})) { $gm ++; }; push(@group_desc, &group_name($gm, $g). " $text{'ehost_in'} $u->{'values'}->[0] ". "$text{'ehost_in'} $s->{'values'}->[0]"); $group_desc[$#group_desc-1] =~ s/ / /g; $shared{$g} = $s->{'index'}; $subnet{$g} = $u->{'index'}; $script3 .= "parent.options[$ig] = " ."new Option(\"$group_desc[$ig]\", $ig)\n" ."parent.options[$ig].value = " ."new String(\"$s->{'index'},$u->{'index'},$g->{'index'}\")\n" if &can('rw', \%access, $g); if ($in{'sidx'} eq $s->{'index'} && $in{'uidx'} eq $u->{'index'} && $in{'gidx'} eq $g->{'index'}) { $sel_parent = $ig; $currpar = "$s->{'index'},$u->{'index'},$g->{'index'}"; } $ig ++; } $iu ++; } $is ++; } print "
\n"; print &script_fn() if (!defined($in{'ret'})); if ($in{'ret'} eq "group") { &ui_print_footer("edit_group.cgi?sidx=$in{'sidx'}&uidx=$in{'uidx'}&idx=$in{'gidx'}", $text{'ehost_retgroup'}); } elsif ($in{'ret'} eq "subnet") { &ui_print_footer("edit_subnet.cgi?sidx=$in{'sidx'}&idx=$in{'uidx'}", $text{'ehost_retsubn'}); } elsif ($in{'ret'} eq "shared") { &ui_print_footer("edit_shared.cgi?idx=$in{'sidx'}", $text{'ehost_retshar'}); } else { &ui_print_footer($ret, $text{'ehost_return'}); } sub script_fn { return <