Make priv fields function common

This commit is contained in:
Jamie Cameron
2015-12-22 16:30:08 -08:00
parent ba7b2a7cfa
commit 6330deb1bc
4 changed files with 15 additions and 27 deletions

View File

@@ -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');
}

View File

@@ -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

View File

@@ -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()

View File

@@ -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, ".