This commit is contained in:
Bozhidar Slaveykov 2024-04-06 12:18:12 +03:00
parent e6e764b98d
commit da44186ca9
3 changed files with 3 additions and 56 deletions

View file

@ -20,24 +20,14 @@ class CreateLinuxWebUser
$this->password = $password; $this->password = $password;
} }
public function setEmail($email)
{
$this->email = $email;
}
public function setAsWebUser()
{
$this->isWebUser = true;
}
public function handle() public function handle()
{ {
$output = ''; $output = '';
$username = $this->username; $username = $this->username;
$password = $this->password; $password = $this->password;
$email = $this->email;
$command = 'adduser --disabled-password --gecos "" "'.$username.'" -c "'.$email.'"'; $command = 'adduser --disabled-password --gecos "" "'.$username;
$output .= ShellApi::exec($command); $output .= ShellApi::exec($command);
$command = 'groupadd '.$username; $command = 'groupadd '.$username;

View file

@ -1,43 +0,0 @@
<?php
namespace App\Listeners;
use App\Actions\CreateLinuxWebUser;
use App\Actions\GetLinuxUser;
use App\Events\ModelCustomerCreated;
use App\Events\ModelCustomerDeleting;
use App\Models\Customer;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
class ModelCustomerDeletingListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(ModelCustomerDeleting $event): void
{
$findCustomer = Customer::where('id', $event->model->id)->first();
if ($findCustomer) {
$getLinuxUser = new GetLinuxUser();
$getLinuxUser->setUsername($findCustomer->username);
$getLinuxUserStatus = $getLinuxUser->handle();
if (!empty($getLinuxUserStatus)) {
shell_exec('userdel ' . $findCustomer->username);
shell_exec('rm -rf /home/' . $findCustomer->username);
}
}
}
}

View file

@ -51,10 +51,9 @@ class ModelHostingSubscriptionCreatedListener
$createLinuxWebUser = new CreateLinuxWebUser(); $createLinuxWebUser = new CreateLinuxWebUser();
$createLinuxWebUser->setUsername($systemUsername); $createLinuxWebUser->setUsername($systemUsername);
$createLinuxWebUser->setEmail($findCustomer->email);
$createLinuxWebUser->setPassword($systemPassword); $createLinuxWebUser->setPassword($systemPassword);
$createLinuxWebUserOutput = $createLinuxWebUser->handle(); $createLinuxWebUserOutput = $createLinuxWebUser->handle();
if (strpos($createLinuxWebUserOutput, 'Creating home directory') !== false) { if (strpos($createLinuxWebUserOutput, 'Creating home directory') !== false) {
$findHostingSubscription->system_username = $systemUsername; $findHostingSubscription->system_username = $systemUsername;
@ -81,6 +80,7 @@ class ModelHostingSubscriptionCreatedListener
if (strlen($lowercased) > 10) { if (strlen($lowercased) > 10) {
$lowercased = substr($lowercased, 0, 10); $lowercased = substr($lowercased, 0, 10);
} }
$username = $lowercased . rand(1111,9999) . Str::random(4); $username = $lowercased . rand(1111,9999) . Str::random(4);
$username = strtolower($username); $username = strtolower($username);