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;
}
public function setEmail($email)
{
$this->email = $email;
}
public function setAsWebUser()
{
$this->isWebUser = true;
}
public function handle()
{
$output = '';
$username = $this->username;
$password = $this->password;
$email = $this->email;
$command = 'adduser --disabled-password --gecos "" "'.$username.'" -c "'.$email.'"';
$command = 'adduser --disabled-password --gecos "" "'.$username;
$output .= ShellApi::exec($command);
$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,7 +51,6 @@ class ModelHostingSubscriptionCreatedListener
$createLinuxWebUser = new CreateLinuxWebUser();
$createLinuxWebUser->setUsername($systemUsername);
$createLinuxWebUser->setEmail($findCustomer->email);
$createLinuxWebUser->setPassword($systemPassword);
$createLinuxWebUserOutput = $createLinuxWebUser->handle();
@ -81,6 +80,7 @@ class ModelHostingSubscriptionCreatedListener
if (strlen($lowercased) > 10) {
$lowercased = substr($lowercased, 0, 10);
}
$username = $lowercased . rand(1111,9999) . Str::random(4);
$username = strtolower($username);