54 lines
1.1 KiB
PHP
54 lines
1.1 KiB
PHP
<?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 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.'"';
|
|
$output .= ShellApi::exec($command);
|
|
|
|
$command = 'groupadd '.$username;
|
|
$output .= ShellApi::exec($command);
|
|
|
|
$command = 'usermod -a -G www-data ' . $username;
|
|
$output .= ShellApi::exec($command);
|
|
|
|
$command = 'echo '.$username.':'.$password.' | chpasswd -e';
|
|
$output .= ShellApi::exec($command);
|
|
|
|
return $output;
|
|
}
|
|
}
|