2024-04-22 11:14:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Actions;
|
|
|
|
|
|
|
|
use App\ShellApi;
|
|
|
|
|
|
|
|
class CreateLinuxWebUser
|
|
|
|
{
|
|
|
|
public $username;
|
|
|
|
|
|
|
|
public $email;
|
|
|
|
|
|
|
|
public $password;
|
|
|
|
|
|
|
|
public function setUsername($username)
|
|
|
|
{
|
|
|
|
$this->username = $username;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPassword($password)
|
|
|
|
{
|
|
|
|
$this->password = $password;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
$username = $this->username;
|
|
|
|
$password = $this->password;
|
|
|
|
|
2024-04-23 14:44:34 +00:00
|
|
|
$command = 'sudo adduser --disabled-password --gecos "" "'.$username.'"';
|
2024-04-22 13:56:29 +00:00
|
|
|
$output .= shell_exec($command);
|
2024-04-22 11:14:05 +00:00
|
|
|
|
2024-04-23 14:44:34 +00:00
|
|
|
$command = 'sudo usermod -a -G www-data '.$username;
|
2024-04-22 13:56:29 +00:00
|
|
|
$output .= shell_exec($command);
|
2024-04-22 11:14:05 +00:00
|
|
|
|
2024-04-23 14:44:34 +00:00
|
|
|
$command = 'sudo echo '.$username.':'.$password.' | chpasswd -e';
|
2024-04-22 13:56:29 +00:00
|
|
|
$output .= shell_exec($command);
|
|
|
|
|
2024-04-24 13:44:19 +00:00
|
|
|
$homeDir = '/home';
|
|
|
|
if (substr(sprintf('%o', fileperms($homeDir)), -4) !== '0711') {
|
|
|
|
$command = 'sudo chmod 711 /home';
|
|
|
|
$output .= shell_exec($command);
|
|
|
|
}
|
|
|
|
|
2024-04-23 14:44:34 +00:00
|
|
|
$command = 'sudo chmod 711 /home/'.$username;
|
2024-04-22 13:56:29 +00:00
|
|
|
$output .= shell_exec($command);
|
2024-04-22 11:14:05 +00:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|