Handle hostnames with upper-case letters
[webmin.git] / mysql / list_users.cgi
1 #!/usr/local/bin/perl
2 # list_users.cgi
3 # Display a list of all database users
4
5 require './mysql-lib.pl';
6 $access{'perms'} == 1 || &error($text{'perms_ecannot'});
7 &ui_print_header(undef, $text{'users_title'}, "", "users");
8
9 print &ui_form_start("delete_users.cgi");
10 @rowlinks = ( &select_all_link("d", 0),
11               &select_invert_link("d", 0),
12               "<a href='edit_user.cgi?new=1'>$text{'users_add'}</a>" );
13 print &ui_links_row(\@rowlinks);
14 @tds = ( "width=5" );
15 print &ui_columns_start([ "",
16                           $text{'users_user'},
17                           $text{'users_host'},
18                           $text{'users_pass'},
19                           $mysql_version >= 5 ? ( $text{'users_ssl'} ) : ( ),
20                           $text{'users_perms'} ], 100, 0, \@tds);
21 $d = &execute_sql_safe($master_db, "select * from user order by user");
22 %fieldmap = map { $_->{'field'}, $_->{'index'} }
23                 &table_structure($master_db, "user");
24 $i = 0;
25 foreach $u (@{$d->{'data'}}) {
26         local @cols;
27         push(@cols, "<a href='edit_user.cgi?idx=$i'>".
28                     ($u->[1] ? &html_escape($u->[1]) : $text{'users_anon'}).
29                     "</a>");
30         push(@cols, $u->[0] eq '' || $u->[0] eq '%' ?
31                       $text{'user_any'} : &html_escape($u->[0]));
32         push(@cols, &html_escape($u->[2]));
33         if ($mysql_version >= 5) {
34                 $ssl = $u->[$fieldmap{'ssl_type'}];
35                 push(@cols, $text{'user_ssl_'.lc($ssl)} || $ssl);
36                 }
37         local @priv;
38         for($j=3; $j<=&user_priv_cols()+3-1; $j++) {
39                 push(@priv, $text{"users_priv$j"}) if ($u->[$j] eq 'Y');
40                 }
41         push(@cols,
42                 scalar(@priv) == &user_priv_cols() ? $text{'users_all'} :
43                 !@priv ? $text{'users_none'} : join("&nbsp;| ", @priv));
44         print &ui_checked_columns_row(\@cols, \@tds, "d", $u->[0]." ".$u->[1]);
45         $i++;
46         }
47 print &ui_columns_end();
48 print &ui_links_row(\@rowlinks);
49 print &ui_form_end([ [ "delete", $text{'users_delete'} ] ]);
50
51 # Unix / MySQL user syncing
52 print &ui_hr();
53 print &ui_form_start("save_sync.cgi");
54 print "$text{'users_sync'}<p>\n";
55 print &ui_table_start(undef, undef, 2);
56
57 # When to sync
58 print &ui_table_row($text{'users_syncwhen'},
59         &ui_checkbox("sync_create", 1, $text{'users_sync_create'},
60                      $config{'sync_create'})."<br>\n".
61         &ui_checkbox("sync_modify", 1, $text{'users_sync_modify'},
62                      $config{'sync_modify'})."<br>\n".
63         &ui_checkbox("sync_delete", 1, $text{'users_sync_delete'},
64                      $config{'sync_delete'}));
65
66 # Privs for new users
67 print &ui_table_row($text{'users_sync_privs'},
68         &ui_select("sync_privs",
69                    [ split(/\s+/, $config{'sync_privs'}) ],
70                    [ map { [ $_, $text{"user_priv$_"} ] }
71                          ( 3 .. &user_priv_cols()+3-1 ) ],
72                    5, 1));
73
74 # Hosts for new users
75 print &ui_table_row($text{'users_sync_host'},
76         &ui_opt_textbox("host", $config{'sync_host'}, 30,
77                         $text{'users_sync_def'}, $text{'users_sync_sel'}));
78
79 print &ui_table_end();
80 print &ui_form_end([ [ undef, $text{'save'} ] ]);
81
82 &ui_print_footer("", $text{'index_return'});
83