MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/proc/self/root/scripts.20110531.215904.25158/unsuspendmysqlusers
#!/usr/bin/perl
# cpanel - unsuspendmysqlusers                    Copyright(c) 2010 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN { unshift @INC, '/usr/local/cpanel'; }

use strict;
use Cpanel::DB::Map    ();
use Cpanel::MysqlUtils ();
use Cpanel::Logger     ();

my $user = shift @ARGV;

if ( !$user ) {
    print "USAGE: $0 <user>\n";
    exit 1;
}

my $logger = Cpanel::Logger->new();

my $map = Cpanel::DB::Map->new({ 'cpuser' => $user, 'db' => 'MYSQL' });
my $owner = $map->get_owner();

my @user_list = map { "'$_'" } map { $_->name() } $owner->dbusers();

if (!scalar @user_list) {
    $logger->warn("$user has no databases.");
    exit;
}

my $user_list = join ',', @user_list;

my $result = Cpanel::MysqlUtils::sqlcmd("SELECT User, Host, Password from mysql.user WHERE user IN ($user_list);");

my @lines = split /\n/, $result;
my %result;
foreach my $line (@lines) {
    my ( $key, $host, $value ) = split /\s+/, $line, 3;
    $result{$key}{$host} = $value || '*' x 41;
}

foreach my $user ( keys %result ) {
    foreach my $host ( keys %{ $result{$user} } ) {
        if ( length( $result{$user}{$host} ) == 41 ) {

            # New style suspension
            if ( $result{$user}{$host} =~ m/^\-/ ) {
                $result{$user}{$host} =~ s/\-//;

                # Handling for NULL passwords
                if ( $result{$user}{$host} =~ m/^\*+$/ ) {
                    $logger->info("MySQL user $user has a blank password!");
                    $result{$user}{$host} = '';
                }
                else {
                    $result{$user}{$host} = reverse $result{$user}{$host};
                    $result{$user}{$host} = '*' . $result{$user}{$host};
                }
            }

            # Legacy suspension
            elsif ( $result{$user}{$host} =~ m/^\+/ ) {
                $result{$user}{$host} =~ s/\+/\*/;
            }
        }
        elsif ( length( $result{$user}{$host} ) == 40 ) {
            $result{$user}{$host} = '*' . $result{$user}{$host};
            if ( $result{$user}{$host} =~ m/^\*+$/ ) {
                $result{$user}{$host} = '';
            }
        }
    }
}

foreach my $user ( keys %result ) {
    foreach my $host ( keys %{ $result{$user} } ) {
        my $pass   = $result{$user}{$host};
        my $dbuser = Cpanel::MysqlUtils::safesqlstring($user);
        my $dbhost = Cpanel::MysqlUtils::safesqlstring($host);
        $pass      = Cpanel::MysqlUtils::safesqlstring($pass);
        Cpanel::MysqlUtils::sqlcmd("UPDATE mysql.user SET Password='$pass' WHERE user='$dbuser' AND host='$dbhost';");
    }
}

Cpanel::MysqlUtils::sqlcmd('FLUSH PRIVILEGES;');