3 # Allow the selection of and display a NIS table for editing
5 require './nis-lib.pl';
6 &ui_print_header(undef, $text{'tables_title'}, "");
9 $mode = &get_server_mode();
10 if ($mode == 0 || !(&get_nis_support() & 2)) {
11 print "<p>$text{'tables_emaster'}<p>\n";
12 &ui_print_footer("", $text{'index'});
16 print "<p>$text{'tables_eslave'}<p>\n";
17 &ui_print_footer("", $text{'index'});
21 @tables = &list_nis_tables();
22 @domains = &unique(map { $_->{'domain'} } @tables);
23 $in{'table'} = int($in{'table'});
25 print "<form action=edit_tables.cgi method=post>\n";
26 print "<input type=submit value='$text{'tables_switch'}'>\n";
27 print "<select name=table>\n";
28 foreach $t (@tables) {
29 $t->{'desc'} = $text{"desc_".$t->{'table'}};
30 $t->{'desc'} = $t->{'table'} if (!$t->{'desc'});
31 $t->{'desc'} .= " ($t->{'domain'})" if (@domains > 1);
32 printf "<option value=%d %s>%s\n",
33 $t->{'index'}, $in{'table'} eq $t->{'index'} ? 'selected' : '',
36 print "</select></form>\n";
38 $t = $tables[$in{'table'}];
39 $type = $in{'text'} ? undef : $t->{'type'};
40 print "<b>",&text('tables_header', $t->{'desc'},
41 "<tt>".join(" ", @{$t->{'files'}})."</tt>"),"</b><p>\n";
42 if ($type eq 'hosts') {
43 &show_nis_table([ $text{'hosts_ip'},
44 $text{'hosts_name'} ],
47 elsif ($type eq 'networks') {
48 &show_nis_table([ $text{'networks_name'},
49 $text{'networks_ip'} ],
52 elsif ($type eq 'group' || $type eq 'group_shadow') {
53 &show_nis_table([ $text{'group_name'},
55 $text{'group_members'} ],
56 $t, ':', [ 0, 2, 3 ], "width=100%");
58 elsif ($type eq 'passwd_shadow' || $type eq 'passwd_shadow_full' ||
60 &show_nis_table([ $text{'passwd_name'},
64 $text{'passwd_shell'} ],
65 $t, ':', [ 0, 2, 4, 5, 6 ], "width=100%");
67 elsif ($type eq 'services') {
68 &show_nis_table([ $text{'services_name'},
69 $text{'services_proto'},
70 $text{'services_port'} ],
71 $t, '[\s/]+', [ 0, 2, 1 ]);
73 elsif ($type eq 'services2') {
74 &show_nis_table([ $text{'services_name'},
75 $text{'services_proto'},
76 $text{'services_port'} ],
77 $t, '[\s/]+', [ 0, 1, 2 ]);
79 elsif ($type eq 'protocols') {
80 &show_nis_table([ $text{'protocols_name'},
81 $text{'protocols_number'},
82 $text{'protocols_aliases'} ],
83 $t, '\s+', [ 0, 1, -2 ]);
85 elsif ($type eq 'netgroup') {
86 &show_nis_table([ $text{'netgroup_name'},
87 $text{'netgroup_members'} ],
88 $t, '\s+', [ 0, -1 ]);
90 elsif ($type eq 'ethers') {
91 &show_nis_table([ $text{'ethers_mac'},
95 elsif ($type eq 'rpc') {
96 &show_nis_table([ $text{'rpc_name'},
98 $text{'rpc_aliases'} ],
99 $t, '\s+', [ 0, 1, -2 ]);
101 elsif ($type eq 'netmasks') {
102 &show_nis_table([ $text{'netmasks_net'},
103 $text{'netmasks_mask'} ],
104 $t, '\s+', [ 0, 1 ]);
106 elsif ($type eq 'aliases') {
107 &show_nis_table([ $text{'aliases_from'},
108 $text{'aliases_to'} ],
109 $t, '[\s:]+', [ 0, 1 ]);
112 # Allow editing of file directly
113 print "<form method=post action=save_file.cgi enctype=multipart/form-data>\n";
114 print "<input type=hidden name=table value='$in{'table'}'>\n";
116 foreach $f (@{$t->{'files'}}) {
117 print "<table border>\n";
118 print "<tr $tb> <td><b>",&text('tables_file', "<tt>$f</tt>"),
120 print "<tr $cb> <td><textarea name=data_$fnum rows=20 cols=80>";
124 print "</textarea></td></tr></table><br>\n";
127 print "<input type=submit value='$text{'tables_ok'}'></form>\n";
130 if ($config{'manual_build'}) {
132 print "<table width=100%><tr>\n";
133 print "<form action=build.cgi>\n";
134 print "<input type=hidden name=table value='$in{'table'}'>\n";
135 print "<td><input type=submit value='$text{'tables_build'}'></td>\n";
136 print "<td>$text{'tables_buildmsg'}</td>\n";
137 print "</form></tr></table>\n";
140 &ui_print_footer("", $text{'index_return'});
142 # show_nis_table(&headers, &table, splitter, &columns, params)
145 local @f = @{$_[1]->{'files'}};
153 $empty = 0 if (/\S/);
156 if ($config{'max_size'} && $lines > $config{'max_size'}) {
157 # Display a search form
158 print "<form action=edit_tables.cgi>\n";
159 print "<input type=hidden name=table value='$in{'table'}'>\n";
160 local $sel = "<select name=field>\n";
162 foreach $f (@{$_[0]}) {
163 $sel .= sprintf "<option value=%s %s>%s\n",
164 $n, $in{'field'} == $n ? 'selected' : '', $f;
167 $sel .= "</select>\n";
168 print &text('tables_find', $t->{'desc'}, $sel,
169 "<input name=what size=15 value='$in{'what'}'>"),
170 " \n";
171 print "<input type=submit value='$text{'tables_search'}'></form>\n";
173 if ($lines && (defined($in{'field'}) || !$config{'max_size'} ||
174 $lines <= $config{'max_size'})) {
176 print "<a href='edit_$t->{'type'}.cgi?table=$in{'table'}'>",
177 "$text{'tables_add'}</a><br>\n";
178 print "<table border $_[4]>\n";
179 print "<tr $tb> ",(map { "<td><b>$_</b></td>" } @{$_[0]}),"</tr>\n";
180 local ($c, @c) = @{$_[3]};
183 foreach $l (@lines) {
184 local @r = split($_[2], $l);
185 if ($l =~ /\S/ && (!defined($in{'field'}) ||
186 $r[$_[3]->[$in{'field'}]] =~ /$in{'what'}/i)) {
187 print "<tr $cb><td><a href='edit_$t->{'type'}.cgi?",
188 "line=$lnum&table=$in{'table'}'>",
189 &html_escape($r[$c]),"</a></td>\n";
192 print "<td>",&html_escape(join(" ", @r[-$i .. $#r])),"<br></td>\n";
195 print "<td>",&html_escape($r[$i]),"<br></td>\n";
203 print "<tr $cb> <td colspan=",scalar(@{$_[3]}),">",
204 "$text{'tables_nomatch'}</td> </tr>\n";
209 print "<b>",&text('tables_none', $t->{'desc'}),"</b><p>\n";
211 print "<a href='edit_$t->{'type'}.cgi?table=$in{'table'}'>",
212 "$text{'tables_add'}</a> \n";
213 print "<a href='edit_tables.cgi?table=$in{'table'}&text=1'>",
214 "$text{'tables_text'}</a><p>\n";