Handle hostnames with upper-case letters
[webmin.git] / ldap-useradmin / search_group.cgi
1 #!/usr/local/bin/perl
2 # search_group.cgi
3 # Ask the LDAP server to return groups matching some query
4
5 require './ldap-useradmin-lib.pl';
6 &ReadParse();
7 &useradmin::load_theme_library();       # So that ui functions work
8
9 # Do the search
10 $ldap = &ldap_connect();
11 $base = &get_group_base();
12 if ($in{'match'} == 0) {
13         $search = "($in{'field'}=$in{'what'})";
14         }
15 elsif ($in{'match'} == 1) {
16         $search = "($in{'field'}=*$in{'what'}*)";
17         }
18 elsif ($in{'match'} == 2) {
19         $search = "(!($in{'field'}=$in{'what'}))";
20         }
21 elsif ($in{'match'} == 3) {
22         $search = "(!($in{'field'}=*$in{'what'}*))";
23         }
24 $rv = $ldap->search(base => $base,
25                     filter => "(&".&group_filter().$search.")");
26 if ($rv->code) {
27         &error(&text('search_err', "<tt>$search</tt>",
28                      "<tt>$base</tt>", $rv->error));
29         }
30 @groups = $rv->all_entries;
31
32 if ($in{'match'} == 6) {
33         # Apply less-than filter manually
34         @groups = grep { $_->get_value($in{'field'}) < $in{'what'} } @groups;
35         }
36 elsif ($in{'match'} == 7) {
37         # Apply greater-than filter manually
38         @groups = grep { $_->get_value($in{'field'}) > $in{'what'} } @groups;
39         }
40
41 &ui_print_header(undef, $text{'search_title'}, "");
42 if (@groups == 0) {
43         print "<p><b>$text{'search_gnotfound'}</b>.<p>\n";
44         }
45 else {
46         @glist = map { { &dn_to_hash($_) } } @groups;
47         &useradmin::groups_table(\@glist, 0, 1);
48         }
49 &ui_print_footer("", $text{'index_return'});
50