#!/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 "\n"; print "\n"; print "\n"; print "
$text{'ehost_tabhdr'}
\n"; print "\n"; printf "\n", &html_escape($host->{'comment'}); print "\n"; printf "\n", $host ? $host->{'values'}->[0] : ""; $assign = $in{'gidx'} ne "" ? "3" : $in{'uidx'} ne "" ? "2" : $in{'sidx'} ne "" ? "1" : "0"; if (!defined($in{'ret'})) { local @labels = ( $text{'ehost_toplevel'}, $text{'ehost_inshared'}, $text{'ehost_insubnet'}, $text{'ehost_ingroup'} ); print "\n"; print "\n"; } else { print "\n"; print "\n"; } $hard = $hconf ? &find("hardware", $hconf) : undef; print "\n"; print "\n", $hard ? $hard->{'values'}->[1] : ""; $fixed = $host ? &find("fixed-address", $hconf) : ""; print "\n", $fixed ? join(" ", grep { $_ ne "," } @{$fixed->{'values'}}) : ""; &display_params($hconf, "host"); print "
$text{'ehost_desc'}
$text{'ehost_hname'}"; print "\n" if ($in{'assign'}); print "\n"; print "\n"; print "\n"; } else { print "\n"; } print "\n"; print "
$text{'ehost_nojavascr'}
$text{'ehost_assign'}
\n"; if ($in{'assign'}) { $assign = $in{'assign'}; print "$labels[$assign]
$text{'ehost_hwaddr'}"; printf "
$text{'ehost_fixedip'} \n"; printf "
\n"; print "\n"; print "\n"; print "\n"; if (!$in{'new'}) { print "\n"; print "\n"; print "\n" if &can('rw', \%access, $host); print "\n"; print "\n" if &can('rw', \%access, $host, 1); print "
\n"; } else { print "\n"; print "\n"; } 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 < function setparent(sel) { var idx = document.forms[0].assign.selectedIndex; var v = document.forms[0].assign.options[idx].value; var vv = v.split(";"); var parent = document.forms[0].parent; parent.length = 0; if (v==1) { $script1 } if (v==2) { $script2 } if (v==3) { $script3 } if (parent.length > 0) { parent.options[sel].selected = true; } } setparent($sel_parent); EOF }