mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 08:40:24 +00:00
Port host permissions to new privilege column implementation
This commit is contained in:
@@ -26,6 +26,8 @@ else {
|
||||
print &ui_hidden("olddb", $u->[1]);
|
||||
}
|
||||
print &ui_table_start($text{'host_header'}, undef, 2);
|
||||
%fieldmap = map { $_->{'field'}, $_->{'index'} }
|
||||
&table_structure($master_db, "host");
|
||||
|
||||
# Database name
|
||||
print &ui_table_row($text{'host_db'}, &select_db($u->[1]));
|
||||
@@ -36,9 +38,9 @@ print &ui_table_row($text{'host_host'},
|
||||
$text{'host_any'}));
|
||||
|
||||
# Host's permissions
|
||||
for($i=2; $i<=&host_priv_cols()+2-1; $i++) {
|
||||
push(@opts, [ $i, $text{"host_priv$i"} ]);
|
||||
push(@sel, $i) if ($u->[$i] eq 'Y');
|
||||
foreach my $f (&priv_fields('host')) {
|
||||
push(@opts, $f);
|
||||
push(@sel, $f->[0]) if ($u->[$fieldmap{$f->[0]}] eq 'Y');
|
||||
}
|
||||
print &ui_table_row($text{'host_perms'},
|
||||
&ui_select("perms", \@sel, \@opts, 10, 1, 1));
|
||||
|
||||
@@ -351,23 +351,6 @@ hosts_host=Hosts
|
||||
hosts_perms=Permissions
|
||||
hosts_any=Any
|
||||
hosts_all=All
|
||||
hosts_priv2=Select
|
||||
hosts_priv3=Insert
|
||||
hosts_priv4=Update
|
||||
hosts_priv5=Delete
|
||||
hosts_priv6=Create
|
||||
hosts_priv7=Drop
|
||||
hosts_priv8=Grant
|
||||
hosts_priv9=References
|
||||
hosts_priv10=Index
|
||||
hosts_priv11=Alter
|
||||
hosts_priv12=Create temp
|
||||
hosts_priv13=Lock
|
||||
hosts_priv14=Create View
|
||||
hosts_priv15=Show View
|
||||
hosts_priv16=Create Routine
|
||||
hosts_priv17=Alter Routine
|
||||
hosts_priv18=Execute
|
||||
hosts_none=None
|
||||
hosts_add=Create new host permissions.
|
||||
hosts_empty=No host permissions defined
|
||||
@@ -376,6 +359,7 @@ hosts_enone=No hosts selected
|
||||
hosts_dtitle=Delete Host Permissions
|
||||
hosts_drusure=Are you sure you want to delete the $1 selected MySQL host permissions?
|
||||
hosts_dok=Delete Permissions
|
||||
hosts_return=host permissions
|
||||
|
||||
host_title1=Create Host Permissions
|
||||
host_title2=Edit Host Permissions
|
||||
@@ -384,24 +368,6 @@ host_db=Databases
|
||||
host_any=Any
|
||||
host_sel=Selected
|
||||
host_otherdb=Matching pattern
|
||||
host_priv2=Select table data
|
||||
host_priv3=Insert table data
|
||||
host_priv4=Update table data
|
||||
host_priv5=Delete table data
|
||||
host_priv6=Create tables
|
||||
host_priv7=Drop tables
|
||||
host_priv8=Grant privileges
|
||||
host_priv9=Reference operations
|
||||
host_priv10=Manage indexes
|
||||
host_priv11=Alter tables
|
||||
host_priv12=Create temp tables
|
||||
host_priv13=Lock tables
|
||||
host_priv14=Create View
|
||||
host_priv15=Show View
|
||||
host_priv16=Create Routine
|
||||
host_priv17=Alter Routine
|
||||
host_priv18=Execute
|
||||
host_priv19=Create Trigger
|
||||
host_host=Hosts
|
||||
host_perms=Permissions
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ $access{'perms'} || &error($text{'perms_ecannot'});
|
||||
&ui_print_header(undef, $text{'hosts_title'}, "");
|
||||
|
||||
$d = &execute_sql_safe($master_db, "select * from host order by host");
|
||||
%fieldmap = map { $_->{'field'}, $_->{'index'} }
|
||||
&table_structure($master_db, "host");
|
||||
@rowlinks = ( &ui_link("edit_host.cgi?new=1",$text{'hosts_add'}) );
|
||||
if (@{$d->{'data'}}) {
|
||||
print &ui_form_start("delete_hosts.cgi");
|
||||
@@ -28,13 +30,20 @@ if (@{$d->{'data'}}) {
|
||||
: &html_escape($u->[1]))."</a>");
|
||||
push(@cols, $u->[0] eq '%' || $u->[0] eq '' ?
|
||||
$text{'hosts_any'} : &html_escape($u->[0]));
|
||||
local @priv;
|
||||
for($j=2; $j<=&host_priv_cols()+2-1; $j++) {
|
||||
push(@priv, $text{"hosts_priv$j"}) if ($u->[$j] eq 'Y');
|
||||
my @priv;
|
||||
my ($allprivs, $noprivs) = (1, 1);
|
||||
foreach my $f (&priv_fields('host')) {
|
||||
if ($u->[$fieldmap{$f->[0]}] eq 'Y') {
|
||||
push(@priv, $f->[1]);
|
||||
$noprivs = 0;
|
||||
}
|
||||
else {
|
||||
$allprivs = 0;
|
||||
}
|
||||
}
|
||||
push(@cols,
|
||||
scalar(@priv) == &host_priv_cols() ? $text{'hosts_all'} :
|
||||
!@priv ? $text{'hosts_none'} : join(" | ", @priv));
|
||||
push(@cols, $allprivs ? $text{'users_all'} :
|
||||
$noprivs ? $text{'users_none'} :
|
||||
join(" | ", @priv));
|
||||
print &ui_checked_columns_row(\@cols, \@tds,
|
||||
"d", $u->[0]." ".$u->[1]);
|
||||
}
|
||||
|
||||
@@ -33,30 +33,30 @@ else {
|
||||
&can_edit_db($db) || &error($text{'perms_edb'});
|
||||
}
|
||||
|
||||
map { $perms[$_]++ } split(/\0/, $in{'perms'});
|
||||
%perms = map { $_, 1 } split(/\0/, $in{'perms'});
|
||||
@desc = &table_structure($master_db, 'host');
|
||||
@pfields = map { $_->[0] } &priv_fields('host');
|
||||
$host = $in{'host_def'} ? '%' : $in{'host'};
|
||||
if ($in{'new'}) {
|
||||
# Create a new host
|
||||
for($i=2; $i<=&host_priv_cols()+2-1; $i++) {
|
||||
push(@yesno, $perms[$i] ? "'Y'" : "'N'");
|
||||
}
|
||||
$sql = sprintf "insert into host (%s) values ('%s', '%s', %s)",
|
||||
join(",", map { $desc[$_]->{'field'} } (0 .. &host_priv_cols()+2-1)),
|
||||
$in{'host_def'} ? '%' : $in{'host'}, $db,
|
||||
join(",", @yesno);
|
||||
$sql = "insert into host (host, db, ".
|
||||
join(", ", @pfields).
|
||||
") values (?, ?, ".
|
||||
join(", ", map { "?" } @pfields).")";
|
||||
&execute_sql_logged($master_db, $sql,
|
||||
$host, $db,
|
||||
(map { $perms{$_} ? 'Y' : 'N' } @pfields));
|
||||
}
|
||||
else {
|
||||
# Update existing host
|
||||
for($i=2; $i<=&host_priv_cols()+2-1; $i++) {
|
||||
push(@yesno, $desc[$i]->{'field'}."=".
|
||||
($perms[$i] ? "'Y'" : "'N'"));
|
||||
}
|
||||
$sql = sprintf "update host set host = '%s', db = '%s', %s ".
|
||||
"where host = '%s' and db = '%s'",
|
||||
$in{'host_def'} ? '%' : $in{'host'}, $db,
|
||||
join(" , ", @yesno), $in{'oldhost'}, $in{'olddb'};
|
||||
$sql = "update host set host = ?, db = ?, ".
|
||||
join(", ",map { "$_ = ?" } @pfields).
|
||||
" where host = ? and db = ?";
|
||||
&execute_sql_logged($master_db, $sql,
|
||||
$host, $db,
|
||||
(map { $perms{$_} ? 'Y' : 'N' } @pfields),
|
||||
$in{'oldhost'}, $in{'olddb'});
|
||||
}
|
||||
&execute_sql_logged($master_db, $sql);
|
||||
}
|
||||
&execute_sql_logged($master_db, 'flush privileges');
|
||||
if ($in{'delete'}) {
|
||||
|
||||
Reference in New Issue
Block a user