Handle hostnames with upper-case letters
[webmin.git] / mysql / list_cprivs.cgi
1 #!/usr/local/bin/perl
2 # list_cprivs.cgi
3 # Display a list of column priviliges
4
5 require './mysql-lib.pl';
6 $access{'perms'} || &error($text{'perms_ecannot'});
7 &ui_print_header(undef, $text{'cprivs_title'}, "", "cprivs");
8
9 $d = &execute_sql_safe($master_db, "select * from columns_priv order by table_name,column_name");
10 if (@{$d->{'data'}}) {
11         print &ui_form_start("delete_cprivs.cgi", "post");
12         @rowlinks = ( &select_all_link("d", 0),
13                       &select_invert_link("d", 0) );
14         print &ui_links_row(\@rowlinks);
15         @tds = ( "width=5" );
16         print &ui_columns_start([ "",
17                                   $text{'cprivs_field'},
18                                   $text{'cprivs_table'},
19                                   $text{'cprivs_db'},
20                                   $text{'cprivs_host'},
21                                   $text{'cprivs_user'},
22                                   $text{'cprivs_privs'} ], 100, 0, \@tds);
23         $i = -1;
24         foreach $u (@{$d->{'data'}}) {
25                 $i++;
26                 next if ($access{'perms'} == 2 && !&can_edit_db($u->[1]));
27                 local @cols;
28                 push(@cols, "<a href='edit_cpriv.cgi?idx=$i'>".
29                             &html_escape($u->[4])."</a>");
30                 push(@cols, &html_escape($u->[3]));
31                 push(@cols, &html_escape($u->[1]));
32                 push(@cols, $u->[0] eq '' || $u->[0] eq '%' ?
33                       $text{'cprivs_all'} : &html_escape($u->[0]));
34                 push(@cols, $u->[2] ? &html_escape($u->[2])
35                                      : $text{'cprivs_anon'});
36                 push(@cols, !$u->[6] ? $text{'cprivs_none'} :
37                      join("&nbsp;| ",split(/[, ]+/, $u->[6])));
38                 print &ui_checked_columns_row(\@cols, \@tds, 
39                                               "d", join(" ", @$u[0..4]));
40                 }
41         print &ui_columns_end();
42         print &ui_links_row(\@rowlinks);
43         print &ui_form_end([ [ "delete", $text{'users_delete'} ] ]);
44         }
45 else {
46         print "<b>$text{'cprivs_norows'}</b><p>\n";
47         }
48 &show_button();
49
50 &ui_print_footer("", $text{'index_return'});
51
52 sub show_button
53 {
54 print &ui_form_start("edit_cpriv.cgi");
55 local @opts = ( );
56 local @dbs = sort { $a cmp $b } &list_databases();
57 if (@dbs > $max_dbs) {
58         # Show DB and table fields
59         print &ui_submit($text{'cprivs_add2'});
60         print $text{'cprivs_db'}," ",&ui_textbox("db", undef, 20)," ",
61               $text{'cprivs_table'}," ",&ui_textbox("table", undef, 20);
62         }
63 else {
64         # Show selector
65         print &ui_submit($text{'cprivs_add'});
66         foreach $d (@dbs) {
67                 if ($access{'perms'} == 1 || &can_edit_db($d)) {
68                         foreach $t (&list_tables($d)) {
69                                 push(@opts, "$d.$t");
70                                 }
71                         }
72                 }
73         print &ui_select("table", undef, \@opts);
74         }
75 print &ui_form_end();
76 }
77