#!/usr/local/bin/perl # edit_tables.cgi # Allow the selection of and display a NIS table for editing require './nis-lib.pl'; &ui_print_header(undef, $text{'tables_title'}, ""); &ReadParse(); $mode = &get_server_mode(); if ($mode == 0 || !(&get_nis_support() & 2)) { print "

$text{'tables_emaster'}

\n"; &ui_print_footer("", $text{'index'}); exit; } elsif ($mode == 2) { print "

$text{'tables_eslave'}

\n"; &ui_print_footer("", $text{'index'}); exit; } @tables = &list_nis_tables(); @domains = &unique(map { $_->{'domain'} } @tables); $in{'table'} = int($in{'table'}); print "

\n"; print "\n"; print "
\n"; $t = $tables[$in{'table'}]; $type = $in{'text'} ? undef : $t->{'type'}; print "",&text('tables_header', $t->{'desc'}, "".join(" ", @{$t->{'files'}}).""),"

\n"; if ($type eq 'hosts') { &show_nis_table([ $text{'hosts_ip'}, $text{'hosts_name'} ], $t, '\s+', [ 0, 1 ]); } elsif ($type eq 'networks') { &show_nis_table([ $text{'networks_name'}, $text{'networks_ip'} ], $t, '\s+', [ 0, 1 ]); } elsif ($type eq 'group' || $type eq 'group_shadow') { &show_nis_table([ $text{'group_name'}, $text{'group_gid'}, $text{'group_members'} ], $t, ':', [ 0, 2, 3 ], "width=100%"); } elsif ($type eq 'passwd_shadow' || $type eq 'passwd_shadow_full' || $type eq 'passwd') { &show_nis_table([ $text{'passwd_name'}, $text{'passwd_uid'}, $text{'passwd_real'}, $text{'passwd_home'}, $text{'passwd_shell'} ], $t, ':', [ 0, 2, 4, 5, 6 ], "width=100%"); } elsif ($type eq 'services') { &show_nis_table([ $text{'services_name'}, $text{'services_proto'}, $text{'services_port'} ], $t, '[\s/]+', [ 0, 2, 1 ]); } elsif ($type eq 'services2') { &show_nis_table([ $text{'services_name'}, $text{'services_proto'}, $text{'services_port'} ], $t, '[\s/]+', [ 0, 1, 2 ]); } elsif ($type eq 'protocols') { &show_nis_table([ $text{'protocols_name'}, $text{'protocols_number'}, $text{'protocols_aliases'} ], $t, '\s+', [ 0, 1, -2 ]); } elsif ($type eq 'netgroup') { &show_nis_table([ $text{'netgroup_name'}, $text{'netgroup_members'} ], $t, '\s+', [ 0, -1 ]); } elsif ($type eq 'ethers') { &show_nis_table([ $text{'ethers_mac'}, $text{'ethers_ip'} ], $t, '\s+', [ 0, 1 ]); } elsif ($type eq 'rpc') { &show_nis_table([ $text{'rpc_name'}, $text{'rpc_number'}, $text{'rpc_aliases'} ], $t, '\s+', [ 0, 1, -2 ]); } elsif ($type eq 'netmasks') { &show_nis_table([ $text{'netmasks_net'}, $text{'netmasks_mask'} ], $t, '\s+', [ 0, 1 ]); } elsif ($type eq 'aliases') { &show_nis_table([ $text{'aliases_from'}, $text{'aliases_to'} ], $t, '[\s:]+', [ 0, 1 ]); } else { # Allow editing of file directly print "

\n"; print "\n"; $fnum = 0; foreach $f (@{$t->{'files'}}) { print "\n"; print "\n"; print "
",&text('tables_file', "$f"), "

\n"; $fnum++; } print "
\n"; } if ($config{'manual_build'}) { print &ui_hr(); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$text{'tables_buildmsg'}
\n"; } &ui_print_footer("", $text{'index_return'}); # show_nis_table(&headers, &table, splitter, &columns, params) sub show_nis_table { local @f = @{$_[1]->{'files'}}; local $lines = 0; open(FILE, $f[0]); while() { s/\r|\n//g; s/^\s*#.*$//; push(@lines, $_); $lines++ if (/\S/); $empty = 0 if (/\S/); } close(FILE); if ($config{'max_size'} && $lines > $config{'max_size'}) { # Display a search form print "
\n"; print "\n"; local $sel = "\n"; print &text('tables_find', $t->{'desc'}, $sel, ""), "   \n"; print "
\n"; } if ($lines && (defined($in{'field'}) || !$config{'max_size'} || $lines <= $config{'max_size'})) { # Show table records print "", "$text{'tables_add'}
\n"; print "\n"; print " ",(map { "" } @{$_[0]}),"\n"; local ($c, @c) = @{$_[3]}; local $lnum = 0; local $matches = 0; foreach $l (@lines) { local @r = split($_[2], $l); if ($l =~ /\S/ && (!defined($in{'field'}) || $r[$_[3]->[$in{'field'}]] =~ /$in{'what'}/i)) { print "\n"; foreach $i (@c) { if ($i < 0) { print "\n"; } else { print "\n"; } } $matches++; } $lnum++; } if (!$matches) { print "\n"; } print "
$_
", &html_escape($r[$c]),"",&html_escape(join(" ", @r[-$i .. $#r])),"
",&html_escape($r[$i]),"
", "$text{'tables_nomatch'}
\n"; } else { print "",&text('tables_none', $t->{'desc'}),"

\n"; } print "", "$text{'tables_add'}  \n"; print "", "$text{'tables_text'}

\n"; }