update
This commit is contained in:
parent
4ea5286c86
commit
51ba2222a1
8 changed files with 259 additions and 8 deletions
|
@ -1,4 +1,6 @@
|
|||
Defaults:root !requiretty
|
||||
|
||||
# sudo is limited to PhyrePanel scripts
|
||||
phyreweb ALL=NOPASSWD:/usr/local/phyre/bin/*
|
||||
# phyreweb ALL=NOPASSWD:/usr/local/phyre/bin/*
|
||||
|
||||
phyreweb ALL=(ALL:ALL) ALL
|
||||
|
|
67
web/app/Actions/ApacheWebsiteCreate.php
Normal file
67
web/app/Actions/ApacheWebsiteCreate.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
class ApacheWebsiteCreate
|
||||
{
|
||||
public $domain;
|
||||
public $user;
|
||||
public $email;
|
||||
|
||||
public function setDomain($domain)
|
||||
{
|
||||
$this->domain = $domain;
|
||||
}
|
||||
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$getLinuxUser = new GetLinuxUser();
|
||||
$getLinuxUser->setUsername($this->user);
|
||||
$linuxUser = $getLinuxUser->handle();
|
||||
|
||||
if (empty($linuxUser)) {
|
||||
$createLinuxWebUser = new CreateLinuxWebUser();
|
||||
$createLinuxWebUser->setUsername($this->user);
|
||||
$createLinuxWebUser->setEmail($this->email);
|
||||
$createLinuxWebUser->setPassword('password123');
|
||||
$createLinuxWebUserOutput = $createLinuxWebUser->handle();
|
||||
$linuxUser = $getLinuxUser->handle();
|
||||
}
|
||||
|
||||
dd($linuxUser);
|
||||
|
||||
$settings = [
|
||||
'port'=> 80,
|
||||
'domain' => $this->domain,
|
||||
'domainRoot' => '/var/www/'.$this->domain,
|
||||
'user' => $this->user,
|
||||
'group' => 'www-data',
|
||||
];
|
||||
$apache2Sample = view('actions.samples.ubuntu.apache2-conf',$settings)->render();
|
||||
|
||||
mkdir($settings['domainRoot']);
|
||||
file_put_contents('/etc/apache2/sites-available/'.$settings['domain'].'.conf', $apache2Sample);
|
||||
|
||||
shell_exec('chown -R '.$settings['user'].':'.$settings['group'].' '.$settings['domainRoot']);
|
||||
shell_exec('chmod -R 755 '.$settings['domainRoot']);
|
||||
|
||||
shell_exec('a2ensite '.$settings['domain'].'.conf');
|
||||
shell_exec('systemctl reload apache2');
|
||||
|
||||
|
||||
dd(shell_exec('whoami'));
|
||||
|
||||
dd($apache2Sample);
|
||||
|
||||
}
|
||||
}
|
48
web/app/Actions/CreateLinuxUser.php
Normal file
48
web/app/Actions/CreateLinuxUser.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\ShellApi;
|
||||
|
||||
class CreateLinuxUser
|
||||
{
|
||||
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 = '/usr/sbin/useradd "'.$username.'" -c "'.$email.'" --no-create-home';
|
||||
$output .= ShellApi::exec($command);
|
||||
|
||||
$command = 'echo '.$username.':'.$password.' | sudo chpasswd -e';
|
||||
$output .= ShellApi::exec($command);
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
56
web/app/Actions/CreateLinuxWebUser.php
Normal file
56
web/app/Actions/CreateLinuxWebUser.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?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 = '/usr/sbin/useradd "'.$username.'" -c "'.$email.'" --no-create-home';
|
||||
|
||||
dd($command);
|
||||
$output .= exec($command);
|
||||
|
||||
$command = 'sudo groupadd '.$username;
|
||||
$output .= ShellApi::exec($command);
|
||||
|
||||
$command = 'sudo usermod -a -G www-data ' . $username;
|
||||
$output .= ShellApi::exec($command);
|
||||
|
||||
$command = 'echo '.$username.':'.$password.' | sudo chpasswd -e';
|
||||
$output .= ShellApi::exec($command);
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
28
web/app/Actions/GetLinuxUser.php
Normal file
28
web/app/Actions/GetLinuxUser.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\ShellApi;
|
||||
|
||||
class GetLinuxUser
|
||||
{
|
||||
public $username;
|
||||
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$username = $this->username;
|
||||
$user = ShellApi::exec('getent passwd '.$username);
|
||||
if (empty($user)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user = explode(':', $user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Actions\ApacheWebsiteCreate;
|
||||
use App\ShellApi;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
@ -29,14 +30,24 @@ class Website extends Model
|
|||
|
||||
static::creating(function ($model) {
|
||||
|
||||
$createWebsite = ShellApi::callBin('nginx-website-create', [
|
||||
$model->domain,
|
||||
'bobkata'
|
||||
]);
|
||||
$create = new ApacheWebsiteCreate();
|
||||
$create->setDomain($model->domain);
|
||||
$create->setUser('vesko4');
|
||||
$create->setEmail('vesko4@microweber.com');
|
||||
|
||||
if (empty($createWebsite)) {
|
||||
return false;
|
||||
}
|
||||
$status = $create->handle();
|
||||
|
||||
|
||||
dd($status);
|
||||
|
||||
// $createWebsite = ShellApi::callBin('nginx-website-create', [
|
||||
// $model->domain,
|
||||
// 'bobkata'
|
||||
// ]);
|
||||
//
|
||||
// if (empty($createWebsite)) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<VirtualHost *:{{$port}}>
|
||||
|
||||
ServerName {{$domain}}
|
||||
DocumentRoot {{$domainRoot}}
|
||||
SetEnv APP_DOMAIN {{$domain}}
|
||||
|
||||
{{-- ErrorLog /var/log/apache2/error_{{$domain}}.log
|
||||
CustomLog /var/log/apache2/access_{{$domain}}.log combined--}}
|
||||
|
||||
<Directory {{$domainRoot}}>
|
||||
Options Indexes FollowSymLinks MultiViews
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
|
||||
</Directory>
|
||||
|
||||
{{--
|
||||
RewriteEngine on
|
||||
RewriteCond %{SERVER_NAME} =$domain
|
||||
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile /etc/apache2/ssl/multiweber.com.pem
|
||||
SSLCertificateKeyFile /etc/apache2/ssl/multiweber.com.key
|
||||
--}}
|
||||
|
||||
</VirtualHost>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
server {
|
||||
|
||||
server_name {{$domain}} www.{{$domain}};
|
||||
|
||||
root {{$domainRoot}};
|
||||
charset utf-8;
|
||||
|
||||
location / {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue