mirror of
https://github.com/webmin/webmin.git
synced 2026-02-03 14:13:29 +00:00
Make priv fields function common
This commit is contained in:
@@ -57,7 +57,7 @@ print &ui_table_row($text{'user_host'},
|
||||
$text{'user_any'}));
|
||||
|
||||
# User's permissions
|
||||
foreach my $f (&user_priv_fields()) {
|
||||
foreach my $f (&priv_fields('user')) {
|
||||
push(@opts, $f);
|
||||
push(@sel, $f->[0]) if ($u->[$fieldmap{$f->[0]}] eq 'Y');
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ foreach $u (@{$d->{'data'}}) {
|
||||
}
|
||||
my @priv;
|
||||
my ($allprivs, $noprivs) = (1, 1);
|
||||
foreach my $f (&user_priv_fields()) {
|
||||
foreach my $f (&priv_fields('user')) {
|
||||
if ($u->[$fieldmap{$f->[0]}] eq 'Y') {
|
||||
push(@priv, $f->[1]);
|
||||
$noprivs = 0;
|
||||
@@ -73,7 +73,7 @@ print &ui_table_row($text{'users_syncwhen'},
|
||||
print &ui_table_row($text{'users_sync_privs'},
|
||||
&ui_select("sync_privs",
|
||||
[ split(/\s+/, $config{'sync_privs'}) ],
|
||||
[ &user_priv_fields() ],
|
||||
[ &priv_fields('user') ],
|
||||
5, 1));
|
||||
|
||||
# Hosts for new users
|
||||
|
||||
@@ -753,34 +753,22 @@ eval { $data = &execute_sql_safe(undef, "select version()") };
|
||||
return $@ || !$data ? 0 : 1;
|
||||
}
|
||||
|
||||
# user_priv_fields()
|
||||
# Returns the names and descriptions of fields for user privileges
|
||||
sub user_priv_fields
|
||||
# priv_fields(type)
|
||||
# Returns the names and descriptions of fields for user/db/host privileges
|
||||
sub priv_fields
|
||||
{
|
||||
if (!@user_priv_fields) {
|
||||
foreach my $s (&table_structure("mysql", "user")) {
|
||||
my ($type) = @_;
|
||||
if (!$priv_fields{$type}) {
|
||||
$priv_fields{$type} = [];
|
||||
foreach my $s (&table_structure("mysql", $type)) {
|
||||
if ($s->{'field'} =~ /^(.*)_priv/i) {
|
||||
push(@user_priv_fields,
|
||||
[ $s->{'field'}, $text{'user_priv_'.lc($1)} ||
|
||||
$s->{'field'} ]);
|
||||
push(@{$priv_fields{$type}},
|
||||
[ $s->{'field'}, $text{'user_priv_'.lc($1)} ||
|
||||
$s->{'field'} ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return @user_priv_fields;
|
||||
}
|
||||
|
||||
# user_priv_cols()
|
||||
# Returns the number of columns used for privileges in the user table
|
||||
sub user_priv_cols
|
||||
{
|
||||
if (!$user_priv_cols) {
|
||||
local @str = &table_structure("mysql", "user");
|
||||
local $s;
|
||||
foreach $s (@str) {
|
||||
$user_priv_cols++ if ($s->{'field'} =~ /_priv/i);
|
||||
}
|
||||
}
|
||||
return $user_priv_cols;
|
||||
return @{$priv_fields{$type}};
|
||||
}
|
||||
|
||||
# db_priv_cols()
|
||||
|
||||
@@ -25,7 +25,7 @@ else {
|
||||
%fieldmap = map { $_->{'field'}, $_->{'index'} } @desc;
|
||||
$host = $in{'host_def'} ? '%' : $in{'host'};
|
||||
$user = $in{'mysqluser_def'} ? '' : $in{'mysqluser'};
|
||||
@pfields = map { $_->[0] } &user_priv_fields();
|
||||
@pfields = map { $_->[0] } &priv_fields('user');
|
||||
if ($in{'new'}) {
|
||||
# Create a new user
|
||||
$sql = "insert into user (host, user, ".
|
||||
|
||||
Reference in New Issue
Block a user