Handle hostnames with upper-case letters
[webmin.git] / nis / save_netgroup.cgi
1 #!/usr/local/bin/perl
2 # save_netgroup.cgi
3 # Create, update or delete a netgroup
4
5 require './nis-lib.pl';
6 &ReadParse();
7
8 ($t, $lnums, $netgroup) = &table_edit_setup($in{'table'}, $in{'line'}, '\s+');
9 if ($in{'delete'}) {
10         # Just delete the netgroup
11         &table_delete($t, $lnums);
12         }
13 else {
14         # Validate inputs and save the netgroup
15         &error_setup($text{'netgroup_err'});
16         $in{'name'} =~ /^[A-Za-z0-9\.\-]+$/ || &error($text{'netgroup_ename'});
17         @netgroup = ( $in{'name'} );
18         HOST: for($i=0; defined($in{"host_$i"}); $i++) {
19                 local @h;
20                 foreach $v ('host', 'user', 'dom') {
21                         if ($in{"${v}_def_$i"} == 1) { push(@h, ""); }
22                         elsif ($in{"${v}_def_$i"} == 2) { next HOST; }
23                         elsif ($in{"${v}_$i"} !~ /^\S+$/) {
24                                 &error(&text("netgroup_e$v", $i+1));
25                                 }
26                         else { push(@h, $in{"${v}_$i"}); }
27                         }
28                 push(@netgroup, "($h[0],$h[1],$h[2])");
29                 }
30         if ($in{'line'} eq '') {
31                 &table_add($t, "\t", \@netgroup);
32                 }
33         else {
34                 &table_update($t, $lnums, "\t", \@netgroup);
35                 }
36         }
37 &apply_table_changes() if (!$config{'manual_build'});
38 &redirect("edit_tables.cgi?table=$in{'table'}");
39