Handle hostnames with upper-case letters
[webmin.git] / cluster-useradmin / search_user.cgi
1 #!/usr/local/bin/perl
2 # search_user.cgi
3 # Search the list of users across all servers, and display the results
4
5 require './cluster-useradmin-lib.pl';
6 &ReadParse();
7
8 $m = $in{'match'};
9 $w = $in{'what'};
10 @hosts = &list_useradmin_hosts();
11 @servers = &list_servers();
12 foreach $h (@hosts) {
13         ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
14         foreach $u (@{$h->{'users'}}) {
15                 $f = $u->{$in{'field'}};
16                 if ($m == 0 && $f eq $w ||
17                     $m == 1 && eval { $f =~ /$w/i } ||
18                     $m == 4 && index($f, $w) >= 0 ||
19                     $m == 2 && $f ne $w ||
20                     $m == 3 && eval { $f !~ /$w/i } ||
21                     $m == 5 && index($f, $w) < 0) {
22                         push(@{$hosts{$u->{'user'}}},
23                              $s->{'desc'} ? $s->{'desc'} : $s->{'host'});
24                         push(@match, $u) if (!$found{$u->{'user'}}++);
25                         }
26                 }
27         }
28 if (@match == 1) {
29         &redirect("edit_user.cgi?user=".$match[0]->{'user'});
30         }
31 else {
32         &ui_print_header(undef, $text{'search_title'}, "");
33         if (@match == 0) {
34                 print "<p><b>$text{'search_notfound'}</b>. <p>\n";
35                 }
36         else {
37                 print "<table border width=100%>\n";
38                 print "<tr $tb> <td><b>$text{'user'}</b></td>\n";
39                 print "<td><b>$text{'uid'}</b></td>\n";
40                 print "<td><b>$text{'real'}</b></td>\n";
41                 print "<td><b>$text{'home'}</b></td>\n";
42                 print "<td><b>$text{'search_hosts'}</b></td> </tr>\n";
43                 foreach $m (@match) {
44                         $m->{'real'} =~ s/,.*$// if ($uconfig{'extra_real'});
45                         print "<tr $cb>\n";
46                         print "<td><a href=\"edit_user.cgi?user=$m->{'user'}\">$m->{'user'}</a></td>\n";
47                         print "<td>$m->{'uid'}</td>\n";
48                         print "<td>$m->{'real'}&nbsp;</td>\n";
49                         print "<td>$m->{'home'}</td>\n";
50                         @h = @{$hosts{$m->{'user'}}};
51                         @h = @h[0 .. 10], ".." if (@h > 10);
52                         print "<td>",join(", ", @h),"</td>\n";
53                         print "</tr>\n";
54                         }
55                 print "</table><p>\n";
56                 }
57         &ui_print_footer("", $text{'index_return'});
58         }
59