#!/usr/local/bin/perl # edit_class.cgi # Edit options for a class in some section require './cfengine-lib.pl'; use Config; &ReadParse(); $conf = $in{'cfd'} ? &get_cfd_config() : &get_config(); $sec = $conf->[$in{'idx'}] if ($in{'idx'} ne ''); if ($in{'new'}) { &ui_print_header(undef, $sec ? $text{'edit_create2'} : $text{'edit_create1'}, "", "edit"); $cls = { 'name' => 'any' }; } else { &ui_print_header(undef, $text{'edit_title'}, "", "edit"); $cls = $sec->{'cls'}->[$in{'cidx'}]; } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$text{'edit_header'}
\n"; $type = $in{'type'} ? $in{'type'} : $sec->{'name'}; $t = $text{"section_".$type."_".$in{'cfd'}}; $t = $text{"section_".$type} if (!$t); print "\n"; print "\n", $cls->{'name'} eq 'any' ? '' : $cls->{'name'}; $type = undef if ($in{'manual'}); if ($text{"type_".$type."_".$in{'cfd'}}) { print "\n"; } elsif ($text{"type_".$type}) { print "\n"; } if ($type eq 'links') { # Show links that would be created local @links = &parse_links($cls); print "\n"; print "\n"; } elsif ($type eq 'directories') { # Show directories that would be created local @dirs = &parse_directories($cls); print "\n"; } elsif ($type eq "control" && !$in{'cfd'}) { # Show actionsequence definition local ($as) = &find("actionsequence", $cls->{'defs'}); print "\n"; print "\n"; # Show other global definitions print " ", "\n"; $i = 0; foreach $d (@{$cls->{'defs'}}, { }) { next if ($d->{'name'} eq 'actionsequence'); print "\n"; printf "\n", $d->{'name'}; printf "\n", join(" ", @{$d->{'valuequoted'}}); print "\n"; $i++; } } elsif ($type eq "control" && $in{'cfd'}) { # Show cfd-specific control options local $run = &find_value("cfrunCommand", $cls->{'defs'}); print "\n", $run; local $elapsed = &find_value("IfElapsed", $cls->{'defs'}); print "\n", $elapsed; local $max = &find_value("MaxConnections", $cls->{'defs'}); print "\n", $max; print "\n"; local $auto = &find_value("AutoExecCommand", $cls->{'defs'}); print "\n", $auto; local $interval = &find_value("AutoExecInterval", $cls->{'defs'}); print "\n",$interval; print "\n"; local $dom = &find_value("domain", $cls->{'defs'}); print "\n", $dom; local $log = &find_value("LogAllConnections", $cls->{'defs'}); print "\n"; printf "\n", $log ? "" : "checked", $text{'default'}; local @allow = &find_value("AllowConnectionsFrom", $cls->{'defs'}); print "\n"; printf "\n", join(" ", @allow); local @deny = &find_value("DenyConnectionsFrom", $cls->{'defs'}); print "\n"; printf "\n", join(" ", @deny); local @skip = &find_value("SkipVerify", $cls->{'defs'}); print "\n"; printf "\n", join(" ", @skip); } elsif ($type eq "grant" || $type eq "admit" || $type eq "deny") { # Allow editing of allowed or denied directories local (@grants, $grant); foreach $v (@{$cls->{'values'}}) { if ($v =~ /\//) { push(@grants, $grant = { 'dir' => $v }); } else { push(@{$grant->{'hosts'}}, $v); } } print "\n"; print "\n"; } elsif ($type eq "groups" || $type eq "classes") { # Allow editing of group definitions print "\n"; print "\n"; } elsif ($type eq "files") { # Allow editing of file permission settings local @files = &parse_directories($cls); local $i = 0; foreach $f (@files, $in{'newfiles'} || $in{'new'} ? ( { } ) : ( ) ) { print "\n"; print "\n"; print "\n", $f->{'_dir'}; local $owner = &sname("owner", $f); print "\n", $owner; local $group = &sname("group", $f); print "\n", $group; local $mode = &sname("mode", $f); print "\n", $mode; local $rec = &sname("recurse", $f); print "\n", $rec eq 'inf' ? '' : $rec; local $include = &sname("include", $f); print "\n", $include; local $exclude = &sname("exclude", $f); print "\n", $exclude; local $acl = &sname("acl", $f); print "\n", $acl; local $action = &sname("action", $f); local @acts = ( "fixall", "fixdirs", "fixplain", "warnall", "warndirs", "warnplain", "touch", "linkchildren", "create", "compress", "alert" ); print "\n"; print "\n"; $i++; } if (!$in{'newfiles'} && !$in{'new'}) { print "\n"; } } elsif ($type eq "copy") { # Allow editing of file copy options local @copies = &parse_directories($cls); local $i = 0; foreach $f (@copies, $in{'newcopy'} || $in{'new'} ? ( { } ) : ( ) ) { print "\n"; print "\n"; print "\n", $f->{'_dir'}; print "\n"; print "\n", &sname("dest", $f); local $server = &sname("server", $f); print "\n"; print "\n", $server; local $owner = &sname("owner", $f); print "\n", $owner; local $group = &sname("group", $f); print "\n", $group; local $mode = &sname("mode", $f); print "\n", $mode; local $rec = &sname("recurse", $f); print "\n", $rec eq 'inf' ? '' : $rec; local $size = &sname("size", $f); local $smode = $size =~ /^>/ ? 3 : $size =~ /^\n"; print "\n", $backup eq "false" ? "checked" : "", $text{'no'}; local $force = &sname("force", $f); print "\n", $force eq "true" ? "" : "checked", $text{'no'}; print "\n"; local $purge = &sname("purge", $f); print "\n", $purge eq "true" ? "" : "checked", $text{'no'}; local $action = &sname("action", $f); local @acts = ( "fix", "silent", "warn" ); print "\n"; print "\n"; $i++; } if (!$in{'newcopy'} && !$in{'new'}) { print "\n"; } } elsif ($type eq "disable") { # Editing files to disable or delete local @dis = &parse_directories($cls); local $i = 0; foreach $f (@dis, $in{'newdis'} || $in{'new'} ? ( { } ) : ( ) ) { print "\n"; print "\n"; print "\n", $f->{'_dir'}; local $rot = &sname("rotate", $f); print "\n"; print "\n"; local $type = &sname("type", $f); local @types = ( "plain", "file", "link" ); print "\n"; print "\n"; local $size = &sname("size", $f); local $smode = $size =~ /^>/ ? 3 : $size =~ /^\n"; print "\n"; } } elsif ($type eq "editfiles") { # Allow editing of file-editor script local $i = 0; foreach $e (@{$cls->{'lists'}}, $in{'newedit'} || $in{'new'} ? ( { } ) : ( ) ) { print "\n"; local $ef = $e->{'values'}->[0]; print "\n"; print "\n", $ef; print "\n"; $i++; } if (!$in{'newedit'} && !$in{'new'}) { print "\n"; } } elsif ($type eq "ignore") { # Display list of ignored files print "\n"; print "\n"; } elsif ($type eq "processes") { # Show processes to kill local @procs = &parse_processes($cls); local $i = 0; foreach $p (@procs, $in{'newproc'} || $in{'new'} ? ( { } ) : ( ) ) { if ($p->{'_options'}) { # Don't edit SetOptionString lines $i++; next; } print "\n"; print "\n"; print "\n", $p->{'_match'}; local $sig = &sname("signal", $p); print "\n"; print "\n"; local $act = &sname("action", $p); print "\n"; print "\n"; local $mat = &sname("matches", $p); local $smode = $mat =~ /^>/ ? 3 : $mat =~ /^\n"; print "\n"; print "\n", $p->{'_restart'}; local $owner = &sname("owner", $p); print "\n", $owner; local $group = &sname("group", $p); print "\n", $group; $i++; } if (!$in{'newproc'} && !$in{'new'}) { print "\n"; } } elsif ($type eq "shellcommands") { # Edit list of executed shell commands local @cmds = &parse_directories($cls); print "\n"; } elsif ($type eq "tidy") { # Allow editing of directories to tidy up local @dirs = &parse_directories($cls); local $i = 0; foreach $d (@dirs, $in{'newtidy'} || $in{'new'} ? ( { } ) : ( ) ) { print "\n"; print "\n"; print "\n", $d->{'_dir'}; local $pat = &sname("pattern", $d); print "\n"; print "\n", $pat; local $size = &sname("size", $d); print "\n"; print "\n", $size eq 'empty' ? "" : $size; local $age = &sname("age", $d); local $type = &sname("type", $d); print "\n"; print "\n"; local $rec = &sname("recurse", $d); print "\n", $rec eq 'inf' ? '' : $rec; $i++; } if (!$in{'newtidy'} && !$in{'new'}) { print "\n"; } } elsif ($type eq "miscmounts") { # Display filesystems to mount local @mnts = &parse_miscmounts($cls); print "\n"; } elsif ($type eq "resolve") { # Display nameserver options local (@ns, @other); for($i=0; $i<@{$cls->{'values'}}; $i++) { if ($cls->{'valuequotes'}->[$i]) { push(@other, $cls->{'values'}->[$i]); } else { push(@ns, $cls->{'values'}->[$i]); } } print "\n"; print "\n"; print "\n"; print "\n"; } elsif ($type eq "defaultroute") { # Display the default route printf "\n"; printf "\n", $cls->{'values'}->[0]; } elsif ($type eq "required" || $type eq "disks") { # Display filesystems to check local @reqs = &parse_directories($cls); print "\n"; } else { # Allow editing of class manually if (!$in{'new'}) { $lref = &read_file_lines($cls->{'file'}); local $st = $cls->{'line'}; local $en = $cls->{'eline'}; if ($lref->[$st] =~ /^\s*(\S+)::\s*$/ && $1 eq $cls->{'name'}) { $st++; } print "\n"; } else { print "\n"; } } print "
$text{'edit_section'} \n"; print $t ? "$t ($type)" : $type,"
$text{'edit_class'} \n"; printf " %s\n", $cls->{'name'} eq 'any' ? 'checked' : '', $text{'edit_all'}; printf "\n", $cls->{'name'} eq 'any' ? '' : 'checked'; printf "
",$text{"type_".$type."_".$in{'cfd'}}, "
",$text{"type_".$type},"
$text{'edit_links'}\n"; print " ", " ", " ", "\n"; $i = 0; foreach $l (@links, { }) { print "\n"; printf "\n", $l->{'_linkfrom'}; printf "\n", $l->{'_linktype'} =~ /^\+/ ? "checked" : "", $text{'yes'}; printf "\n", $l->{'_linktype'} =~ /!$/ ? "checked" : "", $text{'yes'}; printf "\n", $l->{'_linkto'}; print "\n"; $i++; } print "
$text{'edit_linkfrom'}$text{'edit_linktype'}$text{'edit_linkover'}$text{'edit_linkto'}
%s %s
\n"; print " ", " ", " ", "\n"; $i = 0; foreach $d (@dirs, { }) { print "\n"; printf "\n", $d->{'_dir'}; printf "\n", &sname("mode", $d); printf "\n", &sname("owner", $d); printf "\n", &sname("group", $d); print "\n"; $i++; } print "
$text{'edit_dir'}$text{'edit_dirmode'}$text{'edit_dirowner'}$text{'edit_dirgroup'}
$text{'edit_actionseq'}\n"; print "\n"; print "

\n"; print "\n"; print "
$text{'edit_controldef'}$text{'edit_controlvalue'}
$text{'edit_controlrun'} \n"; printf " %s\n", $run ? "" : "checked", $text{'edit_none'}; printf "\n", $run ? "checked" : ""; printf "
$text{'edit_controlelapsed'} \n"; printf " %s\n", defined($elapsed) ? "" : "checked", $text{'default'}; printf "\n", defined($elapsed) ? "checked" : ""; printf "$text{'edit_controlmax'} \n"; printf " %s\n", defined($max) ? "" : "checked", $text{'default'}; printf "\n", defined($max) ? "checked" : ""; printf "

$text{'edit_controlauto'} \n"; printf " %s\n", $auto ? "" : "checked", $text{'edit_none'}; printf "\n", $auto ? "checked" : ""; printf "
$text{'edit_controlinterval'} \n"; printf " %s\n", defined($interval) ? "" : "checked", $text{'default'}; printf "\n", defined($interval) ? "checked" : ""; printf "

$text{'edit_controldom'} \n"; printf " %s\n", $dom ? "" : "checked", $text{'edit_none'}; printf "\n", $dom ? "checked" : ""; printf "$text{'edit_controllog'} %s\n", lc($log) eq "true" ? "checked" : "", $text{'yes'}; printf " %s\n", lc($log) eq "false" ? "checked" : "", $text{'no'}; printf " %s
$text{'edit_controlallow'} %s ", @allow ? "" : "checked", $text{'edit_controlall'}; printf "\n", @allow ? "checked" : ""; printf "
$text{'edit_controldeny'} %s ", @deny ? "" : "checked", $text{'edit_controlnone'}; printf "\n", @deny ? "checked" : ""; printf "
$text{'edit_controlskip'} %s ", @skip ? "" : "checked", $text{'edit_controlnone'}; printf "\n", @skip ? "checked" : ""; printf "
",$text{'edit_'.$type},"\n"; print " ", "\n"; $i = 0; foreach $g (@grants, { }) { print "\n"; printf "\n", $g->{'dir'}; printf "\n", join(" ", @{$g->{'hosts'}}); print "\n"; $i++; } print "
$text{'edit_grantdir'}$text{'edit_granthosts'}
$text{'edit_groups'}\n"; print " ", "\n"; $i = 0; foreach $g (@{$cls->{'defs'}}, { }) { print "\n"; printf "\n", $g->{'name'}; printf "\n", join(" ", @{$g->{'valuequoted'}}); print "\n"; $i++; } print "
$text{'edit_groupname'}$text{'edit_groupmems'}

$text{'edit_filesdir'}"; printf " %s\n", $f->{'_dir'} ? "" : "checked", $text{'edit_none'}; printf "\n", $f->{'_dir'} ? "checked" : ""; printf "
$text{'edit_filesowner'} \n"; printf " %s\n", $owner ? "" : "checked", $text{'edit_nochange'}; printf "\n", $owner ? "checked" : ""; printf "$text{'edit_filesgroup'} \n"; printf " %s\n", $group ? "" : "checked", $text{'edit_nochange'}; printf "\n", $group ? "checked" : ""; printf "
$text{'edit_filesmode'} \n"; printf " %s\n", $mode ? "" : "checked", $text{'edit_nochange'}; printf "\n", $mode ? "checked" : ""; printf "$text{'edit_filesrec'} \n"; printf " %s\n", $rec ? "" : "checked", $text{'edit_none'}; printf " %s\n", $rec eq 'inf' ? "checked" : "", $text{'edit_filesinf'}; printf "\n", $rec && $rec ne 'inf' ? "checked" : ""; printf "
$text{'edit_filesinclude'} \n"; printf " %s\n", $include ? "" : "checked", $text{'edit_filesall'}; printf "\n", $include ? "checked" : ""; printf "$text{'edit_filesexclude'} \n"; printf " %s\n", $exclude ? "" : "checked", $text{'edit_filesnone'}; printf "\n", $exclude ? "checked" : ""; printf "
$text{'edit_filesacl'} \n"; printf " %s\n", $acl ? "" : "checked", $text{'edit_nochange'}; printf "\n", $acl ? "checked" : ""; printf "$text{'edit_filesact'}

$text{'edit_filesnew'}

$text{'edit_copydir'}"; printf " %s\n", $f->{'_dir'} ? "" : "checked", $text{'edit_none'}; printf "\n", $f->{'_dir'} ? "checked" : ""; printf "
$text{'edit_copydest'}"; printf "
$text{'edit_copyserver'}"; printf " %s\n", $server ? "" : "checked", $text{'edit_local'}; printf "\n", $server ? "checked" : ""; printf "
$text{'edit_filesowner'} \n"; printf " %s\n", $owner ? "" : "checked", $text{'edit_nochange'}; printf "\n", $owner ? "checked" : ""; printf "$text{'edit_filesgroup'} \n"; printf " %s\n", $group ? "" : "checked", $text{'edit_nochange'}; printf "\n", $group ? "checked" : ""; printf "
$text{'edit_filesmode'} \n"; printf " %s\n", $mode ? "" : "checked", $text{'edit_nochange'}; printf "\n", $mode ? "checked" : ""; printf "$text{'edit_filesrec'} \n"; printf " %s\n", $rec ? "" : "checked", $text{'edit_none'}; printf " %s\n", $rec eq 'inf' ? "checked" : "", $text{'edit_filesinf'}; printf "\n", $rec && $rec ne 'inf' ? "checked" : ""; printf "
$text{'edit_copysize'}\n"; printf " %s\n", $smode == 0 ? "checked" : "", $text{'edit_none'}; printf " %s\n", $smode == 2 ? "checked" : "", $text{'edit_copysize2'}; printf "\n", $smode == 2 ? substr($size, 1) : ""; printf " %s\n", $smode == 1 ? "checked" : "", $text{'edit_copysize1'}; printf "\n", $smode == 1 ? $size : ""; printf " %s\n", $smode == 3 ? "checked" : "", $text{'edit_copysize3'}; printf "\n", $smode == 3 ? substr($size, 1) : ""; local $backup = &sname("backup", $f); print "
$text{'edit_copybackup'} \n"; printf " %s\n", $backup eq "false" ? "" : "checked", $text{'yes'}; printf " %s$text{'edit_copyforce'} \n"; printf " %s\n", $force eq "true" ? "checked" : "", $text{'yes'}; printf" %s
$text{'edit_copypurge'} \n"; printf " %s\n", $purge eq "true" ? "checked" : "", $text{'yes'}; printf" %s$text{'edit_copyact'}

$text{'edit_copynew'}

$text{'edit_disfile'}"; printf " %s\n", $f->{'_dir'} ? "" : "checked", $text{'edit_none'}; printf "\n", $f->{'_dir'} ? "checked" : ""; printf "
$text{'edit_disrot'}\n"; printf " %s\n", $rot eq '' ? "checked" : "", $text{'edit_disrot0'}; printf " %s\n", $rot eq 'empty' || $rot eq 'truncate' ? "checked" : "", $text{'edit_disrot1'}; printf "\n", $rot =~ /\d/ ? "checked" : ""; print &text('edit_disrot2', sprintf("", $rot =~ /\d/ ? $rot : undef)),"
$text{'edit_distype'} $text{'edit_dissize'}\n"; printf " %s\n", $smode == 0 ? "checked" : "", $text{'edit_none'}; printf " %s\n", $smode == 2 ? "checked" : "", $text{'edit_copysize2'}; printf "\n", $smode == 2 ? substr($size, 1) : ""; printf " %s\n", $smode == 1 ? "checked" : "", $text{'edit_copysize1'}; printf "\n", $smode == 1 ? $size : ""; printf " %s\n", $smode == 3 ? "checked" : "", $text{'edit_copysize3'}; printf "\n", $smode == 3 ? substr($size, 1) : ""; $i++; } if (!$in{'newdis'} && !$in{'new'}) { print "

$text{'edit_disnew'}

$text{'edit_editfile'}"; printf " %s\n", $ef ? "" : "checked", $text{'edit_none'}; printf "\n", $ef ? "checked" : ""; printf "
$text{'edit_editscript'}", " \n"; print "

$text{'edit_editnew'}
$text{'edit_ignore'}

$text{'edit_proc'}"; printf " %s\n", $p->{'_match'} ? "" : "checked", $text{'edit_none'}; printf "\n", $p->{'_match'} ? "checked" : ""; printf "
$text{'edit_procsig'}$text{'edit_procact'}
$text{'edit_procmat'}\n"; printf " %s\n", $smode == 0 ? "checked" : "", $text{'edit_procmat0'}; printf " %s\n", $smode == 2 ? "checked" : "", $text{'edit_procmat2'}; printf "\n", $smode == 2 ? substr($mat, 1) : ""; printf " %s\n", $smode == 1 ? "checked" : "", $text{'edit_procmat1'}; printf "\n", $smode == 1 ? $mat : ""; printf " %s\n", $smode == 3 ? "checked" : "", $text{'edit_procmat3'}; printf "\n", $smode == 3 ? substr($mat, 1) : ""; print "
$text{'edit_procrestart'}"; printf " %s\n", $p->{'_restart'} ? "" : "checked", $text{'edit_none'}; printf "\n", $p->{'_restart'} ? "checked" : ""; printf "
$text{'edit_procowner'} \n"; printf " %s\n", $owner ? "" : "checked", "root"; printf "\n", $owner ? "checked" : ""; printf "$text{'edit_procgroup'} \n"; printf " %s\n", $group ? "" : "checked", "root"; printf "\n", $group ? "checked" : ""; printf "

$text{'edit_procnew'}
\n"; print " ", " ", " ", "\n"; $i = 0; foreach $c (@cmds, { }) { print "\n"; printf "\n", $c->{'_dir'}; printf "\n", &sname("owner", $c); printf "\n", &sname("group", $c); printf"\n", &sname("timeout", $c), "secs"; print "\n"; $i++; } print "
$text{'edit_cmd'}$text{'edit_cmdowner'}$text{'edit_cmdgroup'}$text{'edit_cmdtimeout'}
%s

$text{'edit_tidydir'}"; printf " %s\n", $d->{'_dir'} ? "" : "checked", $text{'edit_none'}; printf "\n", $d->{'_dir'} ? "checked" : ""; printf "
$text{'edit_tidypat'}"; printf " %s\n", $pat ? "" : "checked", $text{'edit_filesall'}; printf "\n", $pat ? "checked" : ""; printf "
$text{'edit_tidysize'}"; printf " %s\n", $size eq '' ? "checked" : "", $text{'edit_tidysize0'}; printf " %s\n", $size eq 'empty' ? "checked" : "", $text{'edit_tidysize1'}; printf " %s\n", $size eq 'empty' || $size eq '' ? "" : "checked", $text{'edit_tidysize2'}; printf "
$text{'edit_tidyage'}"; printf " %s\n", $age eq '' ? "checked" : "", $text{'edit_tidyage1'}; printf "\n", $age eq '' ? "" : "checked"; local $asel = "\n"; local $afield = "\n"; print &text('edit_tidyage0', $asel, $afield),"
$text{'edit_filesrec'} \n"; printf " %s\n", $rec ? "" : "checked", $text{'edit_none'}; printf " %s\n", $rec eq 'inf' ? "checked" : "", $text{'edit_filesinf'}; printf "\n", $rec && $rec ne 'inf' ? "checked" : ""; printf "

$text{'edit_tidynew'}
\n"; print " ", " ", "\n"; local $i = 0; foreach $m (@mnts, { }) { print "\n"; printf "\n", $m->{'_src'}; printf "\n", $m->{'_dest'}; printf "\n", &sname("mode", $m); print "\n"; $i++; } print "
$text{'edit_miscsrc'}$text{'edit_miscdest'}$text{'edit_miscmode'}
$text{'edit_resns'}$text{'edit_resother'}
$text{'edit_route'}
\n"; print " ", "\n"; local $i = 0; foreach $r (@reqs, { }) { print "\n"; printf "\n", $free; print "\n"; print "\n"; $i++; } print "
$text{'edit_reqfs'}$text{'edit_reqfree'}
\n", $r->{'_dir'}; local $free = &sname("freespace", $r); printf " %s\n", $free eq '' ? "checked" : "", $text{'edit_none'}; printf "\n", $free eq '' ? "" : "checked"; printf "
",&text('edit_manualtext2', $st, $en, "$cls->{'file'}"),"\n"; print "
$text{'edit_manualtext'}\n"; print "
\n"; print "\n"; if ($in{'new'}) { print "\n"; } else { print "\n"; print "\n" if (!$in{'manual'}); print "\n"; } print "
\n"; print "
\n"; if ($in{'cfd'}) { &ui_print_footer("edit_cfd.cgi", $text{'cfd_return'}, "", $text{'index_return'}); } else { &ui_print_footer("", $text{'index_return'}); } # sname(name, &hash) sub sname { local $i; for($i=length($_[0]); $i>0; $i--) { local $s = substr($_[0], 0, $i); return $_[1]->{$s} if (defined($_[1]->{$s})); } return undef; }