daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Sep 20th, 2016 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use lib '/var/www/imscp/engine/PerlLib';
  6. use iMSCP::Bootstrapper;
  7. use iMSCP::Database;
  8. use iMSCP::Debug;
  9. use Servers::sqld;
  10.  
  11. iMSCP::Bootstrapper->getInstance()->boot();
  12.  
  13. my $password = shift;
  14. defined $password && $password ne '' or fatal('You must provide a password for the SQL root user');
  15.  
  16. my $sqlServer = Servers::sqld->factory();
  17. my $db = iMSCP::Database->factory();
  18.  
  19. for my $host('localhost', '127.0.0.1', '::1') {
  20.     my $db = iMSCP::Database->factory();
  21.     my $qrs = $db->doQuery( 1, 'SELECT 1 FROM mysql.user WHERE user = ? AND host = ?', 'root', $host );
  22.     ref $qrs eq 'HASH' or fatal( $qrs );
  23.  
  24.     if(%{$qrs}) {
  25.         $qrs = $db->doQuery( 'd', 'DROP USER ?@?', 'root', $host );
  26.         ref $qrs eq 'HASH' or fatal( sprintf( 'Could not drop the %s@%s SQL user: %s', 'root', $host, $qrs ) );
  27.     }
  28.  
  29.     $sqlServer->createUser('root', $host, $password);
  30.  
  31.     $qrs = $db->doQuery( 'g', 'GRANT ALL ON *.* TO ?@? WITH GRANT OPTION', 'root', $host );
  32.     unless (ref $qrs eq 'HASH') {
  33.         fatal( sprintf( 'Could not GRANT privileges: %s', $qrs ) );
  34.     }
  35. }
  36.  
  37. 1;
  38. __END__
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top