CreateLinuxWebUser.php 926 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Actions;
  3. use App\ShellApi;
  4. class CreateLinuxWebUser
  5. {
  6. public $username;
  7. public $email;
  8. public $password;
  9. public function setUsername($username)
  10. {
  11. $this->username = $username;
  12. }
  13. public function setPassword($password)
  14. {
  15. $this->password = $password;
  16. }
  17. public function handle()
  18. {
  19. $output = '';
  20. $username = $this->username;
  21. $password = $this->password;
  22. $command = 'adduser --disabled-password --gecos "" "'.$username.'"';
  23. $output .= ShellApi::exec($command);
  24. // $command = 'groupadd '.$username;
  25. // $output .= ShellApi::exec($command);
  26. $command = 'usermod -a -G www-data '.$username;
  27. $output .= ShellApi::exec($command);
  28. $command = 'echo '.$username.':'.$password.' | chpasswd -e';
  29. $output .= ShellApi::exec($command);
  30. return $output;
  31. }
  32. }