Skip to content

Commit

Permalink
Differentiate remote and local mysql versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed Dec 25, 2016
1 parent 1004ced commit ad381d1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
4 changes: 3 additions & 1 deletion mysql/edit_tpriv.cgi
Expand Up @@ -48,11 +48,13 @@ print &ui_table_row($text{'tpriv_host'},
$text{'tpriv_any'}));

# Table permissions
$remote_mysql_version = &get_remote_mysql_version();
print &ui_table_row($text{'tpriv_perms1'},
&ui_select("perms1", [ split(/,/, $u->[6]) ],
[ 'Select','Insert','Update','Delete','Create',
'Drop','Grant','References','Index','Alter',
($mysql_version >= 5 ? ('Create View','Show view') : ( )) ],
($remote_mysql_version >= 5 ?
('Create View', 'Show view') : ( )) ],
4, 1));

# Field permissions
Expand Down
5 changes: 3 additions & 2 deletions mysql/edit_user.cgi
Expand Up @@ -78,9 +78,10 @@ print &ui_table_row($text{'user_perms'},
&ui_select("perms", \@sel, \@opts, 10, 1, 1));

# Various per-user limits
$remote_mysql_version = &get_remote_mysql_version();
foreach $f ('max_user_connections', 'max_connections',
'max_questions', 'max_updates') {
if ($mysql_version >= 5 && $fieldmap{$f}) {
if ($remote_mysql_version >= 5 && $fieldmap{$f}) {
print &ui_table_row($text{'user_'.$f},
&ui_opt_textbox($f,
$u->[$fieldmap{$f}] || undef,
Expand All @@ -90,7 +91,7 @@ foreach $f ('max_user_connections', 'max_connections',
}

# SSL needed?
if ($mysql_version >= 5 && $fieldmap{'ssl_type'}) {
if ($remote_mysql_version >= 5 && $fieldmap{'ssl_type'}) {
print &ui_table_row($text{'user_ssl'},
&ui_select("ssl_type", uc($u->[$fieldmap{'ssl_type'}]),
[ [ '', $text{'user_ssl_'} ],
Expand Down
6 changes: 4 additions & 2 deletions mysql/list_users.cgi
Expand Up @@ -12,10 +12,12 @@ print &ui_form_start("delete_users.cgi");
&ui_link("edit_user.cgi?new=1",$text{'users_add'}) );
print &ui_links_row(\@rowlinks);
@tds = ( "width=5" );
$remote_mysql_version = &get_remote_mysql_version();
print &ui_columns_start([ "",
$text{'users_user'},
$text{'users_host'},
$mysql_version >= 5 ? ( $text{'users_ssl'} ) : ( ),
$remote_mysql_version >= 5 ? ( $text{'users_ssl'} )
: ( ),
$text{'users_perms'} ], 100, 0, \@tds);
$d = &execute_sql_safe($master_db, "select * from user order by user");
%fieldmap = map { $_->{'field'}, $_->{'index'} }
Expand All @@ -28,7 +30,7 @@ foreach $u (@{$d->{'data'}}) {
"</a>");
push(@cols, $u->[0] eq '' || $u->[0] eq '%' ?
$text{'user_any'} : &html_escape($u->[0]));
if ($mysql_version >= 5) {
if ($remote_mysql_version >= 5) {
$ssl = $u->[$fieldmap{'ssl_type'}];
push(@cols, $text{'user_ssl_'.lc($ssl)} || $ssl);
}
Expand Down
19 changes: 16 additions & 3 deletions mysql/mysql-lib.pl
Expand Up @@ -786,7 +786,8 @@ sub is_blob

# get_mysql_version(&out)
# Returns a version number, undef if one cannot be found, or -1 for a .so
# problem
# problem. This is the version of the *local* mysql command, not necessarily
# the remote server.
sub get_mysql_version
{
local $out = &backquote_command("\"$config{'mysql'}\" -V 2>&1");
Expand All @@ -802,6 +803,18 @@ sub get_mysql_version
}
}

# get_remote_mysql_version()
# Returns the version of the MySQL server, or -1 if unknown
sub get_remote_mysql_version
{
local $main::error_must_die = 1;
local $data;
eval { $data = &execute_sql_safe(undef, "select version()"); };
return -1 if ($@);
return -1 if (!@{$data->{'data'}});
return $data->{'data'}->[0]->[0];
}

# date_subs(filename)
# Does strftime-style date substitutions on a filename, if enabled
sub date_subs
Expand Down Expand Up @@ -1295,7 +1308,7 @@ sub list_character_sets
{
local @rv;
local $db = $_[0] || $master_db;
if ($mysql_version < 4.1) {
if (&get_remote_mysql_version() < 4.1) {
local $d = &execute_sql($db, "show variables like 'character_sets'");
@rv = map { [ $_, $_ ] } split(/\s+/, $d->{'data'}->[0]->[1]);
}
Expand All @@ -1313,7 +1326,7 @@ sub list_collation_orders
{
local @rv;
local $db = $_[0] || $master_db;
if ($mysql_version >= 5) {
if (&get_remote_mysql_version() >= 5) {
local $d = &execute_sql($db, "show collation");
@rv = map { [ $_->[0], $_->[1] ] } @{$d->{'data'}};
}
Expand Down
5 changes: 3 additions & 2 deletions mysql/save_user.cgi
Expand Up @@ -71,9 +71,10 @@ else {
}

# Save various limits
$remote_mysql_version = &get_remote_mysql_version();
foreach $f ('max_user_connections', 'max_connections',
'max_questions', 'max_updates') {
next if ($mysql_version < 5 || !defined($in{$f.'_def'}));
next if ($remote_mysql_version < 5 || !defined($in{$f.'_def'}));
$in{$f.'_def'} || $in{$f} =~ /^\d+$/ ||
&error($text{'user_e'.$f});
&execute_sql_logged($master_db,
Expand All @@ -83,7 +84,7 @@ else {
}

# Set SSL fields
if ($mysql_version >= 5 && defined($in{'ssl_type'}) &&
if ($remote_mysql_version >= 5 && defined($in{'ssl_type'}) &&
(!$in{'new'} || $in{'ssl_type'} || $in{'ssl_cipher'})) {
&execute_sql_logged($master_db,
"update user set ssl_type = ? ".
Expand Down

0 comments on commit ad381d1

Please sign in to comment.