#87 change password single quote to double quote and small fixes

This commit is contained in:
Mohammad 2016-02-20 18:07:19 +02:00
parent 15333e4a58
commit ffbab547a1

View file

@ -90,9 +90,8 @@ GetOptions(
'host=s', 'socket=s', 'port=i', 'user=s',
'pass=s', 'skipsize', 'checkversion', 'mysqladmin=s',
'mysqlcmd=s', 'help', 'buffers', 'skippassword',
'passwordfile=s', 'outputfile=s', 'silent', 'dbstat',
'json', 'idxstat', 'noask', 'template=s',
'reportfile=s', 'cvefile=s',
'passwordfile=s', 'outputfile=s', 'silent', 'dbstat', 'json',
'idxstat', 'noask', 'template=s', 'reportfile=s', 'cvefile=s',
);
if ( defined $opt{'help'} && $opt{'help'} == 1 ) { usage(); }
@ -188,7 +187,6 @@ sub goodprint { prettyprint $good. " " . $_[0] unless ( $opt{nogood} == 1 ); }
sub infoprint { prettyprint $info. " " . $_[0] unless ( $opt{noinfo} == 1 ); }
sub badprint { prettyprint $bad. " " . $_[0] unless ( $opt{nobad} == 1 ); }
sub debugprint { prettyprint $deb. " " . $_[0] unless ( $opt{debug} == 0 ); }
sub redwrap {
return ( $opt{nocolor} == 0 ) ? "\e[0;31m" . $_[0] . "\e[0m" : $_[0];
}
@ -284,7 +282,6 @@ sub pretty_uptime {
my ( $physical_memory, $swap_memory, $duflags );
sub os_setup {
sub memerror {
badprint
"Unable to determine total memory/swap; use '--forcemem' and '--forceswap'";
@ -301,7 +298,8 @@ sub os_setup {
}
else {
$swap_memory = 0;
badprint "Assuming 0 MB of swap space (use --forceswap to specify)";
badprint
"Assuming 0 MB of swap space (use --forceswap to specify)";
}
}
else {
@ -384,33 +382,30 @@ sub validate_tuner_version {
}
my $update;
my $url =
"https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl";
my $url = "https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl";
my $httpcli=`which curl`;
chomp($httpcli);
if ( 1 != 1 and defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";
debugprint
"$httpcli --connect-timeout 5 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2";
$update =
`$httpcli --connect-timeout 5 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2`;
debugprint "$httpcli --connect-timeout 5 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2";
$update = `$httpcli --connect-timeout 5 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2`;
chomp($update);
debugprint "VERSION: $update";
compare_tuner_version($update);
return;
}
$httpcli=`which wget`;
chomp($httpcli);
if ( defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";
debugprint
"$httpcli -e timestamping=off -T 5 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2";
$update =
`$httpcli -e timestamping=off -T 5 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2`;
debugprint "$httpcli -e timestamping=off -T 5 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2";
$update = `$httpcli -e timestamping=off -T 5 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2`;
chomp($update);
compare_tuner_version($update);
return;
@ -422,11 +417,9 @@ sub validate_tuner_version {
sub compare_tuner_version {
my $remoteversion=shift;
debugprint "Remote data: $remoteversion";
#exit 0;
if ($remoteversion ne $tunerversion) {
badprint
"There is a new version of MySQLTuner available ($remoteversion)";
badprint "There is a new version of MySQLTuner available ($remoteversion)";
return;
}
goodprint "You have the latest version of MySQLTuner($tunerversion)";
@ -441,10 +434,8 @@ if ( $osname eq 'MSWin32' ) {
eval { require Win32; } or last;
$osname = Win32::GetOSName();
infoprint "* Windows OS($osname) is not fully supported.\n";
#exit 1;
}
sub mysql_setup {
$doremote = 0;
$remotestring = '';
@ -461,7 +452,8 @@ sub mysql_setup {
exit 1;
}
elsif ( !-e $mysqladmincmd ) {
badprint "Couldn't find mysqladmin in your \$PATH. Is MySQL installed?";
badprint
"Couldn't find mysqladmin in your \$PATH. Is MySQL installed?";
exit 1;
}
if ( $opt{mysqlcmd} ) {
@ -484,8 +476,7 @@ sub mysql_setup {
my $mysqlclidefaults=`$mysqlcmd --print-defaults`;
debugprint "MySQL Client: $mysqlclidefaults";
if ( $mysqlclidefaults=~/auto-vertical-output/ ) {
badprint
"Avoid auto-vertical-output in configuration file(s) for MySQL like";
badprint "Avoid auto-vertical-output in configuration file(s) for MySQL like";
exit 1;
}
@ -502,11 +493,9 @@ sub mysql_setup {
$opt{port} = ( $opt{port} eq 0 ) ? 3306 : $opt{port};
# If we're doing a remote connection, but forcemem wasn't specified, we need to exit
if ( $opt{'forcemem'} eq 0
&& ( $opt{host} ne "127.0.0.1" )
&& ( $opt{host} ne "localhost" ) )
{
badprint "The --forcemem option is required for remote connections";
if ( $opt{'forcemem'} eq 0 && ($opt{host} ne "127.0.0.1") && ($opt{host} ne "localhost")) {
badprint
"The --forcemem option is required for remote connections";
exit 1;
}
infoprint "Performing tests on $opt{host}:$opt{port}";
@ -521,7 +510,8 @@ sub mysql_setup {
$mysqllogin = "-u $opt{user} -p\"$opt{pass}\"" . $remotestring;
my $loginstatus = `$mysqladmincmd ping $mysqllogin 2>&1`;
if ( $loginstatus =~ /mysqld is alive/ ) {
goodprint "Logged in using credentials passed on the command line";
goodprint
"Logged in using credentials passed on the command line";
return 1;
}
else {
@ -546,7 +536,8 @@ sub mysql_setup {
$mysqllogin = "-u $mysql_login -p$mysql_pass";
my $loginstatus = `mysqladmin $mysqllogin ping 2>&1`;
if ( $loginstatus =~ /mysqld is alive/ ) {
goodprint "Logged in using credentials from mysql-quickbackup.";
goodprint
"Logged in using credentials from mysql-quickbackup.";
return 1;
}
else {
@ -629,28 +620,26 @@ sub mysql_setup {
}
else {
if ( $opt{'noask'}==1 ) {
badprint
"Attempted to use login credentials, but they were invalid";
badprint "Attempted to use login credentials, but they were invalid";
exit 1;
}
my ($name, $password);
# If --user is defined no need to ask for username
if ( $opt{user} ne 0 ) {
if( $opt{user} ne 0 )
{
$name = $opt{user};
}
else{
print STDERR "Please enter your MySQL administrative login: ";
$name = <STDIN>;
}
# If --pass is defined no need to ask for password
if ( $opt{pass} ne 0 ) {
if( $opt{pass} ne 0 )
{
$password = $opt{pass};
}
else{
print STDERR
"Please enter your MySQL administrative password: ";
print STDERR "Please enter your MySQL administrative password: ";
system("stty -echo >$devnull 2>&1");
$password = <STDIN>;
system("stty echo >$devnull 2>&1");
@ -664,8 +653,7 @@ sub mysql_setup {
}
$mysqllogin .= $remotestring;
my $loginstatus = `$mysqladmincmd ping $mysqllogin 2>&1`;
debugprint
"Login status command: $mysqladmincmd ping $mysqllogin 2>&1";
debugprint "Login status command: $mysqladmincmd ping $mysqllogin 2>&1";
if ( $loginstatus =~ /mysqld is alive/ ) {
print STDERR "";
if ( !length($password) ) {
@ -681,8 +669,7 @@ sub mysql_setup {
return 1;
}
else {
badprint
"Attempted to use login credentials, but they were invalid.";
badprint "Attempted to use login credentials, but they were invalid.";
exit 1;
}
exit 1;
@ -819,7 +806,8 @@ sub cve_recommendations {
#prettyprint "Look for related CVE for $myvar{'version'} or lower in $opt{cvefile}";
my $cvefound=0;
open( FH, "<$opt{cvefile}" ) or die "Can't open $opt{cvefile} for read: $!";
while ( my $cveline = <FH> ) {
while (my $cveline = <FH>)
{
my @cve=split (';', $cveline);
if (mysql_micro_version_le ($cve[1], $cve[2], $cve[3])) {
badprint "$cve[4] : $cve[5]";
@ -833,12 +821,10 @@ sub cve_recommendations {
return;
}
badprint $cvefound . " CVE(s) found for your MySQL release.";
push( @generalrec,
$cvefound
. " CVE(s) found for your MySQL release. Consider upgrading your version !"
);
push( @generalrec, $cvefound . " CVE(s) found for your MySQL release. Consider upgrading your version !" );
}
sub security_recommendations {
prettyprint
"\n-------- Security Recommendations -------------------------------------------";
@ -852,7 +838,6 @@ sub security_recommendations {
$PASS_COLUMN_NAME='authentication_string';
}
debugprint "Password column = $PASS_COLUMN_NAME";
#exit(0);
# Looking for Anonymous users
my @mysqlstatlist = select_array
@ -1025,13 +1010,10 @@ sub validate_mysql_version {
. $myvar{'version'}
. " is EOL software! Upgrade soon!";
}
elsif ( ( mysql_version_ge(6) and mysql_version_le(9) )
or mysql_version_ge(12) )
{
elsif ( ( mysql_version_ge(6) and mysql_version_le(9) ) or mysql_version_ge(12) ) {
badprint "Currently running unsupported MySQL version "
. $myvar{'version'} . "";
}
else {
} else {
goodprint "Currently running supported MySQL version "
. $myvar{'version'} . "";
}
@ -1043,7 +1025,8 @@ sub mysql_version_ge {
$min ||= 0;
$mic ||= 0;
return $mysqlvermajor > $maj
|| $mysqlvermajor == $maj && ( $mysqlverminor > $min
|| $mysqlvermajor == $maj
&& ( $mysqlverminor > $min
|| $mysqlverminor == $min && $mysqlvermicro >= $mic );
}
@ -1053,7 +1036,8 @@ sub mysql_version_le {
$min ||= 0;
$mic ||= 0;
return $mysqlvermajor < $maj
|| $mysqlvermajor == $maj && ( $mysqlverminor < $min
|| $mysqlvermajor == $maj
&& ( $mysqlverminor < $min
|| $mysqlverminor == $min && $mysqlvermicro <= $mic );
}
@ -1109,7 +1093,8 @@ sub check_architecture {
"Switch to 64-bit OS - MySQL cannot currently use all of your RAM";
}
else {
goodprint "Operating on 32-bit architecture with less than 2GB RAM";
goodprint
"Operating on 32-bit architecture with less than 2GB RAM";
}
}
$result{'OS'}{'Architecture'} = "$arch bits";
@ -1776,10 +1761,8 @@ sub mysql_stats {
. (
$myvar{'query_cache_type'} eq 0 |
$myvar{'query_cache_type'} eq 'OFF' ? "DISABLED"
: (
$myvar{'query_cache_type'} eq 1 ? "ALL REQUESTS"
: "ON DEMAND"
)
: ( $myvar{'query_cache_type'} eq 1 ? "ALL REQUESTS"
: "ON DEMAND" )
) . "";
infoprint " +-- Query Cache Size: "
. hr_bytes( $myvar{'query_cache_size'} ) . "";
@ -2024,8 +2007,7 @@ sub mysql_stats {
"When making adjustments, make tmp_table_size/max_heap_table_size equal"
);
push( @generalrec,
"Reduce your SELECT DISTINCT queries which have no LIMIT clause"
);
"Reduce your SELECT DISTINCT queries which have no LIMIT clause" );
}
elsif ($mycalc{'pct_temp_disk'} > 25
&& $mycalc{'max_tmp_table_size'} >= 256 * 1024 * 1024 )
@ -2213,7 +2195,6 @@ sub mysql_stats {
sub mysql_myisam {
prettyprint
"\n-------- MyISAM Metrics ------------------------------------------------------";
# Key buffer usage
if ( defined( $mycalc{'pct_key_buffer_used'} ) ) {
if ( $mycalc{'pct_key_buffer_used'} < 90 ) {
@ -2422,6 +2403,7 @@ sub mariadb_ariadb {
}
}
# Recommendations for TokuDB
sub mariadb_tokudb {
prettyprint
@ -2454,7 +2436,6 @@ sub mariadb_galera {
return;
}
infoprint "Galera is enabled.";
# All is to done here
}
@ -2863,7 +2844,8 @@ sub make_recommendations {
foreach (@adjvars) { prettyprint " " . $_ . ""; }
}
if ( @generalrec == 0 && @adjvars == 0 ) {
prettyprint "No additional performance recommendations are available.";
prettyprint
"No additional performance recommendations are available.";
}
}
@ -2882,8 +2864,7 @@ sub string2file {
my $filename=shift;
my $content=shift;
open my $fh, q(>), $filename
or die
"Unable to open $filename in write mode. Please check permissions for this file or directory";
or die "Unable to open $filename in write mode. Please check permissions for this file or directory";
print $fh $content if defined($content);
close $fh;
debugprint $content if ($opt{'debug'});
@ -2907,8 +2888,7 @@ sub file2string {
my $templateModel;
if ($opt{'template'} ne 0 ) {
$templateModel=file2string ($opt{'template'});
}
else {
}else {
# DEFAULT REPORT TEMPLATE
$templateModel=<<'END_TEMPLATE';
<!DOCTYPE html>
@ -2928,7 +2908,6 @@ else {
</html>
END_TEMPLATE
}
sub dump_result {
if ($opt{'debug'}) {
debugprint Dumper( \%result );
@ -2948,15 +2927,11 @@ sub dump_result {
my $template;
{
no warnings 'once';
$template = Text::Template->new(
TYPE => 'STRING',
PREPEND => q{;},
SOURCE => $templateModel
) or die "Couldn't construct template: $Text::Template::ERROR";
$template = Text::Template->new(TYPE => 'STRING', PREPEND => q{;}, SOURCE => $templateModel)
or die "Couldn't construct template: $Text::Template::ERROR";
}
open my $fh, q(>), $opt{'reportfile'}
or die
"Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory";
or die "Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory";
$template->fill_in(HASH =>$vars, OUTPUT=>$fh );
close $fh;
}