Permalink
Browse files

Differentiate remote and local mysql versions

  • Loading branch information...
1 parent 1004ced commit ad381d14479d593543f27d8cd4ee91c3f450dada @jcameron jcameron committed Dec 25, 2016
Showing with 29 additions and 10 deletions.
  1. +3 −1 mysql/edit_tpriv.cgi
  2. +3 −2 mysql/edit_user.cgi
  3. +4 −2 mysql/list_users.cgi
  4. +16 −3 mysql/mysql-lib.pl
  5. +3 −2 mysql/save_user.cgi
@@ -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
View
@@ -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,
@@ -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_'} ],
@@ -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'} }
@@ -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);
}
View
@@ -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");
@@ -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
@@ -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]);
}
@@ -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'}};
}
View
@@ -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,
@@ -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 = ? ".

0 comments on commit ad381d1

Please sign in to comment.