diff --git a/web/app/Console/Commands/RunRepair.php b/web/app/Console/Commands/RunRepair.php index 87c1948..8134392 100644 --- a/web/app/Console/Commands/RunRepair.php +++ b/web/app/Console/Commands/RunRepair.php @@ -6,8 +6,11 @@ use App\Actions\GetLinuxUser; use App\ApacheParser; use App\Jobs\ApacheBuild; use App\Models\Backup; +use App\Models\Database; use App\Models\Domain; use App\Models\HostingSubscription; +use App\PhyreConfig; +use App\UniversalDatabaseExecutor; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Database\Schema\Blueprint; @@ -45,6 +48,8 @@ class RunRepair extends Command // } // } + $this->fixDatabaseRootUsers(); + $this->fixPhpMyAdmin(); // Overwrite supervisor config file @@ -85,6 +90,48 @@ class RunRepair extends Command } } + public function fixDatabaseRootUsers() + { + $findDatabases = Database::all(); + if ($findDatabases->count() > 0) { + foreach ($findDatabases as $database) { + if ($database->is_remote_database_server == 1) { + // TODO + continue; + } + + $findHostingSubscription = HostingSubscription::where('id', $database->hosting_subscription_id)->first(); + if (!$findHostingSubscription) { + continue; + } + + $universalDatabaseExecutor = new UniversalDatabaseExecutor( + PhyreConfig::get('MYSQL_HOST', '127.0.0.1'), + PhyreConfig::get('MYSQL_PORT', 3306), + PhyreConfig::get('MYSQL_ROOT_USERNAME'), + PhyreConfig::get('MYSQL_ROOT_PASSWORD'), + ); + $universalDatabaseExecutor->fixPasswordPolicy(); + + // Check main database user exists + $mainDatabaseUser = $universalDatabaseExecutor->getUserByUsername($findHostingSubscription->system_username); + if (!$mainDatabaseUser) { + $createMainDatabaseUser = $universalDatabaseExecutor->createUser($findHostingSubscription->system_username, $findHostingSubscription->system_password); + if (!isset($createMainDatabaseUser['success'])) { + throw new \Exception($createMainDatabaseUser['message']); + } + } + + $databaseName = Str::slug($database->database_name, '_'); + $databaseName = $database->database_name_prefix . $databaseName; + $databaseName = strtolower($databaseName); + + $universalDatabaseExecutor->userGrantPrivilegesToDatabase($findHostingSubscription->system_username, [$databaseName]); + + } + } + } + public function fixApacheErrors() { $findHostingSubscriptions = HostingSubscription::get();