Merge remote-tracking branch 'origin/main'

This commit is contained in:
Saeed Vaziry 2023-08-06 18:32:13 +02:00
commit 6e0b502e3b
362 changed files with 3402 additions and 2769 deletions

View File

@ -14,8 +14,8 @@ DB_DATABASE=vito
DB_USERNAME=root DB_USERNAME=root
DB_PASSWORD= DB_PASSWORD=
BROADCAST_DRIVER=log BROADCAST_DRIVER=null
CACHE_DRIVER=file CACHE_DRIVER=redis
FILESYSTEM_DRIVER=local FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync QUEUE_CONNECTION=sync
SESSION_DRIVER=database SESSION_DRIVER=database

View File

@ -13,7 +13,7 @@ class CreateDatabaseUser
/** /**
* @throws ValidationException * @throws ValidationException
*/ */
public function create(Server $server, array $input): DatabaseUser public function create(Server $server, array $input, array $links = []): DatabaseUser
{ {
$this->validate($server, $input); $this->validate($server, $input);
@ -22,6 +22,7 @@ public function create(Server $server, array $input): DatabaseUser
'username' => $input['username'], 'username' => $input['username'],
'password' => $input['password'], 'password' => $input['password'],
'host' => isset($input['remote']) && $input['remote'] ? $input['host'] : 'localhost', 'host' => isset($input['remote']) && $input['remote'] ? $input['host'] : 'localhost',
'databases' => $links,
]); ]);
$databaseUser->save(); $databaseUser->save();
$databaseUser->createOnServer(); $databaseUser->createOnServer();

View File

@ -21,7 +21,7 @@ public function create(Server $server, array $input): FirewallRule
'protocol' => $input['protocol'], 'protocol' => $input['protocol'],
'port' => $input['port'], 'port' => $input['port'],
'source' => $input['source'], 'source' => $input['source'],
'mask' => $input['mask'], 'mask' => $input['mask'] ?? null,
'status' => FirewallRuleStatus::CREATING, 'status' => FirewallRuleStatus::CREATING,
]); ]);
$rule->save(); $rule->save();
@ -49,14 +49,12 @@ private function validate(Server $server, array $input): void
'numeric', 'numeric',
'min:1', 'min:1',
'max:65535', 'max:65535',
Rule::unique('firewall_rules', 'port')->where('server_id', $server->id),
], ],
'source' => [ 'source' => [
'required', 'required',
'ip', 'ip',
], ],
'mask' => [ 'mask' => [
'required',
'numeric', 'numeric',
], ],
])->validateWithBag('createRule'); ])->validateWithBag('createRule');

View File

@ -3,6 +3,7 @@
namespace App\Actions\PHP; namespace App\Actions\PHP;
use App\Models\Server; use App\Models\Server;
use App\Models\Service;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
class UninstallPHP class UninstallPHP
@ -11,6 +12,7 @@ public function uninstall(Server $server, string $version): void
{ {
$this->validate($server, $version); $this->validate($server, $version);
/** @var Service $php */
$php = $server->services()->where('type', 'php')->where('version', $version)->first(); $php = $server->services()->where('type', 'php')->where('version', $version)->first();
$php->uninstall(); $php->uninstall();

View File

@ -29,6 +29,8 @@ public function update(Service $service, string $ini): void
'ini' => __("Couldn't update php.ini file!"), 'ini' => __("Couldn't update php.ini file!"),
]); ]);
} }
$service->restart();
} }
private function deleteTempFile(string $name): void private function deleteTempFile(string $name): void

View File

@ -36,8 +36,8 @@ public function create(User $creator, array $input): Server
'provider' => $input['provider'], 'provider' => $input['provider'],
'authentication' => [ 'authentication' => [
'user' => config('core.ssh_user'), 'user' => config('core.ssh_user'),
'pass' => Str::random(10), 'pass' => Str::random(15),
'root_pass' => Str::random(10), 'root_pass' => Str::random(15),
], ],
'progress' => 0, 'progress' => 0,
'progress_step' => 'Initializing', 'progress_step' => 'Initializing',
@ -77,8 +77,7 @@ public function create(User $creator, array $input): Server
$server->progress_step = __('Installation will begin in 3 minutes!'); $server->progress_step = __('Installation will begin in 3 minutes!');
$server->save(); $server->save();
dispatch(new ContinueInstallation($server)) dispatch(new ContinueInstallation($server))
->delay(now()->addMinutes(3)) ->delay(now()->addMinutes(2));
->onQueue('default');
} }
DB::commit(); DB::commit();

View File

@ -6,7 +6,7 @@
class UpdateEnv class UpdateEnv
{ {
public function handle(Site $site, array $input): void public function update(Site $site, array $input): void
{ {
$typeData = $site->type_data; $typeData = $site->type_data;
$typeData['env'] = $input['env']; $typeData['env'] = $input['env'];

View File

@ -3,33 +3,48 @@
namespace App\Actions\SourceControl; namespace App\Actions\SourceControl;
use App\Models\SourceControl; use App\Models\SourceControl;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
class ConnectSourceControl class ConnectSourceControl
{ {
public function connect(string $provider, array $input): void public function connect(array $input): void
{ {
$sourceControl = SourceControl::query() $this->validate($input);
->where('provider', $provider) $sourceControl = new SourceControl([
->first(); 'provider' => $input['provider'],
if (! $sourceControl) { 'profile' => $input['name'],
$sourceControl = new SourceControl([ 'access_token' => $input['token']
'provider' => $provider, ]);
]);
}
if (! $input['token']) {
$sourceControl->delete();
return;
}
$sourceControl->access_token = $input['token'];
if (! $sourceControl->provider()->connect()) { if (! $sourceControl->provider()->connect()) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $provider]), 'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $sourceControl->provider]
),
]); ]);
} }
$sourceControl->save(); $sourceControl->save();
} }
/**
* @throws ValidationException
*/
private function validate(array $input): void
{
$rules = [
'provider' => [
'required',
Rule::in(\App\Enums\SourceControl::getValues())
],
'name' => [
'required',
],
'token' => [
'required'
]
];
Validator::make($input, $rules)->validate();
}
} }

View File

@ -4,7 +4,7 @@
interface Firewall interface Firewall
{ {
public function addRule(string $type, string $protocol, int $port, string $source, string $mask): void; public function addRule(string $type, string $protocol, int $port, string $source, ?string $mask): void;
public function removeRule(string $type, string $protocol, int $port, string $source, string $mask): void; public function removeRule(string $type, string $protocol, int $port, string $source, ?string $mask): void;
} }

View File

@ -4,7 +4,7 @@
interface SSHCommand interface SSHCommand
{ {
public function file(string $os): string; public function file(): string;
public function content(string $os): string; public function content(): string;
} }

View File

@ -8,11 +8,13 @@ public function connect(): bool;
public function getRepo(string $repo = null): mixed; public function getRepo(string $repo = null): mixed;
public function fullRepoUrl(string $repo): string; public function fullRepoUrl(string $repo, string $key): string;
public function deployHook(string $repo, array $events, string $secret): array; public function deployHook(string $repo, array $events, string $secret): array;
public function destroyHook(string $repo, string $hookId): void; public function destroyHook(string $repo, string $hookId): void;
public function getLastCommit(string $repo, string $branch): ?array; public function getLastCommit(string $repo, string $branch): ?array;
public function deployKey(string $title, string $repo, string $key): void;
} }

View File

@ -3,23 +3,14 @@
namespace App\Events; namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class Broadcast implements ShouldBroadcast class Broadcast
{ {
use Dispatchable, InteractsWithSockets, SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(public string $type, public array $data) public function __construct(public string $type, public array $data)
{ {
} }
public function broadcastOn(): array
{
return [
new PrivateChannel('app'),
];
}
} }

View File

@ -0,0 +1,10 @@
<?php
namespace App\Exceptions;
use Exception;
class FailedToDeployGitKey extends Exception
{
//
}

View File

@ -9,7 +9,7 @@
/** /**
* Class SSH * Class SSH
* *
* @method static \App\Helpers\SSH init(Server $server, string $asUser = null, bool $defaultKeys = false) * @method static \App\Helpers\SSH init(Server $server, string $asUser = null)
* @method static setLog(string $logType, int $siteId = null) * @method static setLog(string $logType, int $siteId = null)
* @method static connect() * @method static connect()
* @method static exec($commands, string $log = '', int $siteId = null) * @method static exec($commands, string $log = '', int $siteId = null)

View File

@ -4,11 +4,15 @@
use App\Contracts\SSHCommand; use App\Contracts\SSHCommand;
use App\Exceptions\SSHAuthenticationError; use App\Exceptions\SSHAuthenticationError;
use App\Exceptions\SSHConnectionError;
use App\Models\Server; use App\Models\Server;
use App\Models\ServerLog; use App\Models\ServerLog;
use Exception; use Exception;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use phpseclib3\Crypt\Common\PrivateKey;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Net\SFTP;
use phpseclib3\Net\SSH2;
use Throwable; use Throwable;
class SSH class SSH
@ -17,7 +21,7 @@ class SSH
public ?ServerLog $log; public ?ServerLog $log;
protected mixed $connection; protected SSH2|SFTP|null $connection;
protected ?string $user; protected ?string $user;
@ -25,9 +29,9 @@ class SSH
protected string $publicKey; protected string $publicKey;
protected string $privateKey; protected PrivateKey $privateKey;
public function init(Server $server, string $asUser = null, bool $defaultKeys = false): self public function init(Server $server, string $asUser = null): self
{ {
$this->connection = null; $this->connection = null;
$this->log = null; $this->log = null;
@ -38,8 +42,9 @@ public function init(Server $server, string $asUser = null, bool $defaultKeys =
$this->user = $asUser; $this->user = $asUser;
$this->asUser = $asUser; $this->asUser = $asUser;
} }
$this->publicKey = $this->server->sshKey($defaultKeys)['public_key_path']; $this->privateKey = PublicKeyLoader::loadPrivateKey(
$this->privateKey = $this->server->sshKey($defaultKeys)['private_key_path']; file_get_contents($this->server->sshKey()['private_key_path'])
);
return $this; return $this;
} }
@ -57,29 +62,30 @@ public function setLog(string $logType, $siteId = null): void
/** /**
* @throws Throwable * @throws Throwable
*/ */
public function connect(): void public function connect(bool $sftp = false): void
{ {
$defaultTimeout = ini_get('default_socket_timeout');
ini_set('default_socket_timeout', 7);
try { try {
if (! ($this->connection = ssh2_connect($this->server->ip, $this->server->port))) { if ($sftp) {
throw new SSHConnectionError('Cannot connect to the server'); $this->connection = new SFTP($this->server->ip, $this->server->port);
} else {
$this->connection = new SSH2($this->server->ip, $this->server->port);
} }
if (! ssh2_auth_pubkey_file($this->connection, $this->user, $this->publicKey, $this->privateKey)) { $login = $this->connection->login($this->user, $this->privateKey);
throw new SSHAuthenticationError('Authentication failed');
if (! $login) {
throw new SSHAuthenticationError("Error authenticating");
} }
Log::info("Login status", [
'status' => $login
]);
} catch (Throwable $e) { } catch (Throwable $e) {
ini_set('default_socket_timeout', $defaultTimeout); Log::error("Error connecting", [
if ($this->server->status == 'ready') { "msg" => $e->getMessage()
$this->server->status = 'disconnected'; ]);
$this->server->save();
}
throw $e; throw $e;
} }
ini_set('default_socket_timeout', $defaultTimeout);
} }
/** /**
@ -114,31 +120,17 @@ public function exec(string|array|SSHCommand $commands, string $log = '', int $s
*/ */
public function upload(string $local, string $remote): void public function upload(string $local, string $remote): void
{ {
$this->log = null;
Log::info("Starting to upload");
if (! $this->connection) { if (! $this->connection) {
$this->connect(); $this->connect(true);
} }
Log::info("Uploading");
$sftp = @ssh2_sftp($this->connection); $uploaded = $this->connection->put($remote, $local, SFTP::SOURCE_LOCAL_FILE);
if (! $sftp) { Log::info("Upload finished", [
throw new Exception('Could not initialize SFTP'); 'status' => $uploaded
} ]);
$stream = @fopen("ssh2.sftp://$sftp$remote", 'w');
if (! $stream) {
throw new Exception("Could not open file: $remote");
}
$data_to_send = @file_get_contents($local);
if ($data_to_send === false) {
throw new Exception("Could not open local file: $local.");
}
if (@fwrite($stream, $data_to_send) === false) {
throw new Exception("Could not send data from file: $local.");
}
@fclose($stream);
} }
/** /**
@ -152,31 +144,30 @@ protected function executeCommand(string|SSHCommand $command): string
$commandContent = $command; $commandContent = $command;
} }
Log::info("command", [
"asUser" => $this->asUser,
"content" => $commandContent
]);
if ($this->asUser) { if ($this->asUser) {
$commandContent = 'sudo su - '.$this->asUser.' -c '.'"'.addslashes($commandContent).'"'; $commandContent = 'sudo su - '.$this->asUser.' -c '.'"'.addslashes($commandContent).'"';
} }
if (! ($stream = ssh2_exec($this->connection, $commandContent, 'vt102', [], 100, 30))) { Log::info("Running command", [
throw new Exception('SSH command failed'); "cmd" => $commandContent
} ]);
$data = ''; $output = $this->connection->exec($commandContent);
try {
stream_set_blocking($stream, true);
while ($buf = fread($stream, 1024)) {
$data .= $buf;
$this->log?->write($buf);
}
fclose($stream);
} catch (Throwable) {
$data = 'Error reading data';
}
if (Str::contains($data, 'VITO_SSH_ERROR')) { Log::info("Command executed");
$this->log?->write($output);
if (Str::contains($output, 'VITO_SSH_ERROR')) {
throw new Exception('SSH command failed with an error'); throw new Exception('SSH command failed with an error');
} }
return $data; return $output;
} }
/** /**
@ -185,11 +176,7 @@ protected function executeCommand(string|SSHCommand $command): string
public function disconnect(): void public function disconnect(): void
{ {
if ($this->connection) { if ($this->connection) {
try { $this->connection->disconnect();
ssh2_disconnect($this->connection);
} catch (Exception) {
//
}
$this->connection = null; $this->connection = null;
} }
} }

View File

@ -2,6 +2,7 @@
namespace App\Http; namespace App\Http;
use App\Http\Middleware\ServerIsReadyMiddleware;
use Illuminate\Foundation\Http\Kernel as HttpKernel; use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel class Kernel extends HttpKernel
@ -63,5 +64,6 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class, 'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'server-is-ready' => ServerIsReadyMiddleware::class
]; ];
} }

View File

@ -0,0 +1,37 @@
<?php
namespace App\Http\Livewire\Application;
use App\Actions\Site\UpdateEnv;
use App\Models\Site;
use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class Env extends Component
{
use RefreshComponentOnBroadcast;
public Site $site;
public string $env;
public function mount(): void
{
$this->env = $this->site->env;
}
public function save(): void
{
app(UpdateEnv::class)->update($this->site, $this->all());
session()->flash('status', 'updating-env');
$this->emit(Deploy::class, '$refresh');
}
public function render(): View
{
return view('livewire.application.env');
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Http\Livewire;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Cache;
use Livewire\Component;
class Broadcast extends Component
{
public function render(): View
{
$event = Cache::get('broadcast');
if ($event) {
Cache::forget('broadcast');
$this->emit('broadcast', $event);
}
return view('livewire.broadcast');
}
}

View File

@ -32,10 +32,10 @@ class DatabaseList extends Component
public function create(): void public function create(): void
{ {
app(CreateDatabase::class)->create($this->server, $this->all()); $database = app(CreateDatabase::class)->create($this->server, $this->all());
if ($this->all()['user']) { if ($this->all()['user']) {
app(CreateDatabaseUser::class)->create($this->server, $this->all()); app(CreateDatabaseUser::class)->create($this->server, $this->all(), [$database->name]);
} }
$this->refreshComponent([]); $this->refreshComponent([]);
@ -45,6 +45,7 @@ public function create(): void
public function delete(): void public function delete(): void
{ {
/** @var Database $database */
$database = Database::query()->findOrFail($this->deleteId); $database = Database::query()->findOrFail($this->deleteId);
$database->deleteFromServer(); $database->deleteFromServer();

View File

@ -43,6 +43,7 @@ public function create(): void
public function delete(): void public function delete(): void
{ {
/** @var DatabaseUser $databaseUser */
$databaseUser = DatabaseUser::query()->findOrFail($this->deleteId); $databaseUser = DatabaseUser::query()->findOrFail($this->deleteId);
$databaseUser->deleteFromServer(); $databaseUser->deleteFromServer();
@ -56,6 +57,7 @@ public function delete(): void
public function viewPassword(int $id): void public function viewPassword(int $id): void
{ {
/** @var DatabaseUser $databaseUser */
$databaseUser = DatabaseUser::query()->findOrFail($id); $databaseUser = DatabaseUser::query()->findOrFail($id);
$this->viewPassword = $databaseUser->password; $this->viewPassword = $databaseUser->password;
@ -65,6 +67,7 @@ public function viewPassword(int $id): void
public function showLink(int $id): void public function showLink(int $id): void
{ {
/** @var DatabaseUser $databaseUser */
$databaseUser = DatabaseUser::query()->findOrFail($id); $databaseUser = DatabaseUser::query()->findOrFail($id);
$this->linkId = $id; $this->linkId = $id;
@ -75,6 +78,7 @@ public function showLink(int $id): void
public function link(): void public function link(): void
{ {
/** @var DatabaseUser $databaseUser */
$databaseUser = DatabaseUser::query()->findOrFail($this->linkId); $databaseUser = DatabaseUser::query()->findOrFail($this->linkId);
app(LinkUser::class)->link($databaseUser, $this->link); app(LinkUser::class)->link($databaseUser, $this->link);

View File

@ -22,7 +22,7 @@ class CreateFirewallRule extends Component
public string $source = '0.0.0.0'; public string $source = '0.0.0.0';
public string $mask = '0'; public string $mask = '';
public function create(): void public function create(): void
{ {

View File

@ -18,6 +18,7 @@ class FirewallRulesList extends Component
public function delete(): void public function delete(): void
{ {
/** @var FirewallRule $rule */
$rule = FirewallRule::query()->findOrFail($this->deleteId); $rule = FirewallRule::query()->findOrFail($this->deleteId);
$rule->removeFromServer(); $rule->removeFromServer();

View File

@ -6,7 +6,7 @@
use App\Actions\PHP\UpdatePHPIni; use App\Actions\PHP\UpdatePHPIni;
use App\Models\Server; use App\Models\Server;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\GetPHPIniCommand; use App\SSHCommands\PHP\GetPHPIniCommand;
use App\Traits\RefreshComponentOnBroadcast; use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Livewire\Component; use Livewire\Component;

View File

@ -0,0 +1,20 @@
<?php
namespace App\Http\Livewire\Servers;
use App\Models\Server;
use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class ServerStatus extends Component
{
use RefreshComponentOnBroadcast;
public Server $server;
public function render(): View
{
return view('livewire.servers.server-status');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Http\Livewire\Sites;
use App\Models\Site;
use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class SiteStatus extends Component
{
use RefreshComponentOnBroadcast;
public Site $site;
public function render(): View
{
return view('livewire.sites.site-status');
}
}

View File

@ -11,8 +11,12 @@ class Bitbucket extends Component
{ {
public string $token; public string $token;
public ?string $url;
public function mount(): void public function mount(): void
{ {
$this->url = request()->input('redirect') ?? null;
$this->token = SourceControl::query() $this->token = SourceControl::query()
->where('provider', \App\Enums\SourceControl::BITBUCKET) ->where('provider', \App\Enums\SourceControl::BITBUCKET)
->first()?->access_token ?? ''; ->first()?->access_token ?? '';
@ -23,6 +27,10 @@ public function connect(): void
app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::BITBUCKET, $this->all()); app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::BITBUCKET, $this->all());
session()->flash('status', 'bitbucket-updated'); session()->flash('status', 'bitbucket-updated');
if ($this->url) {
$this->redirect($this->url);
}
} }
public function render(): View public function render(): View

View File

@ -0,0 +1,38 @@
<?php
namespace App\Http\Livewire\SourceControls;
use App\Actions\SourceControl\ConnectSourceControl;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class Connect extends Component
{
public string $provider = '';
public string $name;
public string $token;
public string $url;
public function connect(): void
{
app(ConnectSourceControl::class)->connect($this->all());
$this->emitTo(SourceControlsList::class, '$refresh');
$this->dispatchBrowserEvent('connected', true);
}
public function render(): View
{
if (request()->query('provider')) {
$this->provider = request()->query('provider');
}
return view('livewire.source-controls.connect', [
'open' => ! is_null(request()->query('provider')),
]);
}
}

View File

@ -11,8 +11,12 @@ class Github extends Component
{ {
public string $token; public string $token;
public ?string $url;
public function mount(): void public function mount(): void
{ {
$this->url = request()->input('redirect') ?? null;
$this->token = SourceControl::query() $this->token = SourceControl::query()
->where('provider', \App\Enums\SourceControl::GITHUB) ->where('provider', \App\Enums\SourceControl::GITHUB)
->first()?->access_token ?? ''; ->first()?->access_token ?? '';
@ -20,9 +24,13 @@ public function mount(): void
public function connect(): void public function connect(): void
{ {
app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::GITHUB, $this->all()); app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::GITHUB, array_merge($this->all()));
session()->flash('status', 'github-updated'); session()->flash('status', 'github-updated');
if ($this->url) {
$this->redirect($this->url);
}
} }
public function render(): View public function render(): View

View File

@ -11,8 +11,12 @@ class Gitlab extends Component
{ {
public string $token; public string $token;
public ?string $url;
public function mount(): void public function mount(): void
{ {
$this->url = request()->input('redirect') ?? null;
$this->token = SourceControl::query() $this->token = SourceControl::query()
->where('provider', \App\Enums\SourceControl::GITLAB) ->where('provider', \App\Enums\SourceControl::GITLAB)
->first()?->access_token ?? ''; ->first()?->access_token ?? '';
@ -23,6 +27,10 @@ public function connect(): void
app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::GITLAB, $this->all()); app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::GITLAB, $this->all());
session()->flash('status', 'gitlab-updated'); session()->flash('status', 'gitlab-updated');
if ($this->url) {
$this->redirect($this->url);
}
} }
public function render(): View public function render(): View

View File

@ -0,0 +1,37 @@
<?php
namespace App\Http\Livewire\SourceControls;
use App\Models\SourceControl;
use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class SourceControlsList extends Component
{
use RefreshComponentOnBroadcast;
public int $deleteId;
protected $listeners = [
'$refresh',
];
public function delete(): void
{
$provider = SourceControl::query()->findOrFail($this->deleteId);
$provider->delete();
$this->refreshComponent([]);
$this->dispatchBrowserEvent('confirmed', true);
}
public function render(): View
{
return view('livewire.source-controls.source-controls-list', [
'sourceControls' => SourceControl::query()->latest()->get(),
]);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Http\Middleware;
use App\Models\Server;
use Closure;
use Illuminate\Http\Request;
class ServerIsReadyMiddleware
{
public function handle(Request $request, Closure $next)
{
/** @var Server $server */
$server = $request->route('server');
if (! $server->isReady()) {
return redirect()->route('servers.show', ['server' => $server]);
}
return $next($request);
}
}

View File

@ -6,7 +6,7 @@
use App\Events\Broadcast; use App\Events\Broadcast;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\CronJob; use App\Models\CronJob;
use App\SSHCommands\UpdateCronJobsCommand; use App\SSHCommands\CronJob\UpdateCronJobsCommand;
use Throwable; use Throwable;
class AddToServer extends Job class AddToServer extends Job

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast; use App\Events\Broadcast;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\CronJob; use App\Models\CronJob;
use App\SSHCommands\UpdateCronJobsCommand; use App\SSHCommands\CronJob\UpdateCronJobsCommand;
use Throwable; use Throwable;
class RemoveFromServer extends Job class RemoveFromServer extends Job

View File

@ -25,6 +25,11 @@ public function handle(): void
); );
$this->databaseUser->status = DatabaseUserStatus::READY; $this->databaseUser->status = DatabaseUserStatus::READY;
$this->databaseUser->save(); $this->databaseUser->save();
if (count($this->databaseUser->databases) > 0) {
(new LinkUser($this->databaseUser))->handle();
}
event( event(
new Broadcast('create-database-user-finished', [ new Broadcast('create-database-user-finished', [
'id' => $this->databaseUser->id, 'id' => $this->databaseUser->id,

View File

@ -3,8 +3,8 @@
namespace App\Jobs\Installation; namespace App\Jobs\Installation;
use App\Models\Server; use App\Models\Server;
use App\SSHCommands\CreateUserCommand; use App\SSHCommands\System\CreateUserCommand;
use App\SSHCommands\GetPublicKeyCommand; use App\SSHCommands\System\GetPublicKeyCommand;
use Throwable; use Throwable;
class Initialize extends InstallationJob class Initialize extends InstallationJob
@ -13,13 +13,10 @@ class Initialize extends InstallationJob
protected ?string $asUser; protected ?string $asUser;
protected bool $defaultKeys; public function __construct(Server $server, string $asUser = null)
public function __construct(Server $server, string $asUser = null, bool $defaultKeys = false)
{ {
$this->server = $server->refresh(); $this->server = $server->refresh();
$this->asUser = $asUser; $this->asUser = $asUser;
$this->defaultKeys = $defaultKeys;
} }
/** /**
@ -38,7 +35,7 @@ public function handle(): void
protected function authentication(): void protected function authentication(): void
{ {
$this->server $this->server
->ssh($this->asUser ?? $this->server->ssh_user, $this->defaultKeys) ->ssh($this->asUser ?? $this->server->ssh_user)
->exec( ->exec(
new CreateUserCommand( new CreateUserCommand(
$this->server->authentication['user'], $this->server->authentication['user'],

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation; namespace App\Jobs\Installation;
use App\Models\Server; use App\Models\Server;
use App\SSHCommands\InstallCertbotCommand; use App\SSHCommands\SSL\InstallCertbotCommand;
use Throwable; use Throwable;
class InstallCertbot extends InstallationJob class InstallCertbot extends InstallationJob

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation; namespace App\Jobs\Installation;
use App\Models\Server; use App\Models\Server;
use App\SSHCommands\InstallComposerCommand; use App\SSHCommands\PHP\InstallComposerCommand;
use Throwable; use Throwable;
class InstallComposer extends InstallationJob class InstallComposer extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus; use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed; use App\Exceptions\InstallationFailed;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\InstallMariadbCommand; use App\SSHCommands\Database\InstallMariadbCommand;
use App\SSHCommands\ServiceStatusCommand; use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable; use Throwable;
class InstallMariadb extends InstallationJob class InstallMariadb extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus; use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed; use App\Exceptions\InstallationFailed;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\InstallMysqlCommand; use App\SSHCommands\Database\InstallMysqlCommand;
use App\SSHCommands\ServiceStatusCommand; use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable; use Throwable;
class InstallMysql extends InstallationJob class InstallMysql extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus; use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed; use App\Exceptions\InstallationFailed;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\InstallNginxCommand; use App\SSHCommands\Nginx\InstallNginxCommand;
use App\SSHCommands\ServiceStatusCommand; use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable; use Throwable;
class InstallNginx extends InstallationJob class InstallNginx extends InstallationJob

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation; namespace App\Jobs\Installation;
use App\Models\Server; use App\Models\Server;
use App\SSHCommands\InstallNodejsCommand; use App\SSHCommands\Installation\InstallNodejsCommand;
use Throwable; use Throwable;
class InstallNodejs extends InstallationJob class InstallNodejs extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus; use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed; use App\Exceptions\InstallationFailed;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\InstallPHPCommand; use App\SSHCommands\PHP\InstallPHPCommand;
use App\SSHCommands\ServiceStatusCommand; use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable; use Throwable;
class InstallPHP extends InstallationJob class InstallPHP extends InstallationJob

View File

@ -6,8 +6,8 @@
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\FirewallRule; use App\Models\FirewallRule;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\CreateNginxPHPMyAdminVHostCommand; use App\SSHCommands\PHPMyAdmin\CreateNginxPHPMyAdminVHostCommand;
use App\SSHCommands\DownloadPHPMyAdminCommand; use App\SSHCommands\PHPMyAdmin\DownloadPHPMyAdminCommand;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Throwable; use Throwable;
@ -76,7 +76,7 @@ private function downloadSource(): void
*/ */
private function setUpVHost(): void private function setUpVHost(): void
{ {
$vhost = File::get(base_path('system/command-templates/nginx/phpmyadmin-vhost.conf')); $vhost = File::get(resource_path('commands/webserver/nginx/phpmyadmin-vhost.conf'));
$vhost = Str::replace('__php_version__', $this->service->server->defaultService('php')->version, $vhost); $vhost = Str::replace('__php_version__', $this->service->server->defaultService('php')->version, $vhost);
$this->service->server->ssh()->exec( $this->service->server->ssh()->exec(
new CreateNginxPHPMyAdminVHostCommand($vhost), new CreateNginxPHPMyAdminVHostCommand($vhost),

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus; use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed; use App\Exceptions\InstallationFailed;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\InstallRedisCommand; use App\SSHCommands\Installation\InstallRedisCommand;
use App\SSHCommands\ServiceStatusCommand; use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable; use Throwable;
class InstallRedis extends InstallationJob class InstallRedis extends InstallationJob

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation; namespace App\Jobs\Installation;
use App\Models\Server; use App\Models\Server;
use App\SSHCommands\InstallRequirementsCommand; use App\SSHCommands\Installation\InstallRequirementsCommand;
use Throwable; use Throwable;
class InstallRequirements extends InstallationJob class InstallRequirements extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus; use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed; use App\Exceptions\InstallationFailed;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\InstallSupervisorCommand; use App\SSHCommands\Service\ServiceStatusCommand;
use App\SSHCommands\ServiceStatusCommand; use App\SSHCommands\Supervisor\InstallSupervisorCommand;
use Throwable; use Throwable;
class InstallSupervisor extends InstallationJob class InstallSupervisor extends InstallationJob

View File

@ -5,8 +5,8 @@
use App\Enums\ServiceStatus; use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed; use App\Exceptions\InstallationFailed;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\InstallUfwCommand; use App\SSHCommands\Firewall\InstallUfwCommand;
use App\SSHCommands\ServiceStatusCommand; use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable; use Throwable;
class InstallUfw extends InstallationJob class InstallUfw extends InstallationJob

View File

@ -4,7 +4,7 @@
use App\Exceptions\InstallationFailed; use App\Exceptions\InstallationFailed;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\UninstallPHPCommand; use App\SSHCommands\PHP\UninstallPHPCommand;
use Throwable; use Throwable;
class UninstallPHP extends InstallationJob class UninstallPHP extends InstallationJob

View File

@ -5,7 +5,7 @@
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\FirewallRule; use App\Models\FirewallRule;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\DeleteNginxPHPMyAdminVHost; use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHost;
use Exception; use Exception;
use Throwable; use Throwable;

View File

@ -3,7 +3,7 @@
namespace App\Jobs\Installation; namespace App\Jobs\Installation;
use App\Models\Server; use App\Models\Server;
use App\SSHCommands\UpgradeCommand; use App\SSHCommands\System\UpgradeCommand;
use Throwable; use Throwable;
class Upgrade extends InstallationJob class Upgrade extends InstallationJob

View File

@ -6,7 +6,7 @@
use App\Exceptions\ProcessFailed; use App\Exceptions\ProcessFailed;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\InstallPHPExtensionCommand; use App\SSHCommands\PHP\InstallPHPExtensionCommand;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Throwable; use Throwable;

View File

@ -6,7 +6,7 @@
use App\Events\Broadcast; use App\Events\Broadcast;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\ChangeDefaultPHPCommand; use App\SSHCommands\PHP\ChangeDefaultPHPCommand;
use Throwable; use Throwable;
class SetDefaultCli extends Job class SetDefaultCli extends Job

View File

@ -1,58 +0,0 @@
<?php
namespace App\Jobs\PHP;
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\Service;
use App\SSHCommands\UpdatePHPSettingsCommand;
use Throwable;
class UpdatePHPSettings extends Job
{
protected Service $service;
protected array $settings;
public function __construct(Service $service, array $settings)
{
$this->service = $service;
$this->settings = $settings;
}
/**
* Execute the job.
*
* @throws Throwable
*/
public function handle(): void
{
$commands = [];
foreach ($this->settings as $key => $value) {
$commands[] = new UpdatePHPSettingsCommand(
$this->service->version,
$key,
$value.' '.config('core.php_settings_unit')[$key]
);
}
$this->service->server->ssh()->exec($commands, 'update-php-settings');
$typeData = $this->service->type_data;
$typeData['settings'] = $this->settings;
$this->service->type_data = $typeData;
$this->service->save();
event(
new Broadcast('update-php-settings-finished', [
'service' => $this->service,
])
);
}
public function failed(): void
{
event(
new Broadcast('update-php-settings-failed', [
'service' => $this->service,
])
);
}
}

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast; use App\Events\Broadcast;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Server; use App\Models\Server;
use App\SSHCommands\RebootCommand; use App\SSHCommands\System\RebootCommand;
use Throwable; use Throwable;
class RebootServer extends Job class RebootServer extends Job

View File

@ -5,9 +5,9 @@
use App\Events\Broadcast; use App\Events\Broadcast;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\RestartServiceCommand; use App\SSHCommands\Service\RestartServiceCommand;
use App\SSHCommands\StartServiceCommand; use App\SSHCommands\Service\StartServiceCommand;
use App\SSHCommands\StopServiceCommand; use App\SSHCommands\Service\StopServiceCommand;
use Exception; use Exception;
use Throwable; use Throwable;

View File

@ -4,7 +4,7 @@
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Site; use App\Models\Site;
use App\SSHCommands\CloneRepositoryCommand; use App\SSHCommands\Website\CloneRepositoryCommand;
use Throwable; use Throwable;
class CloneRepository extends Job class CloneRepository extends Job
@ -25,7 +25,8 @@ public function handle(): void
new CloneRepositoryCommand( new CloneRepositoryCommand(
$this->site->full_repository_url, $this->site->full_repository_url,
$this->site->path, $this->site->path,
$this->site->branch $this->site->branch,
$this->site->ssh_key_name
), ),
'clone-repository', 'clone-repository',
$this->site->id $this->site->id

View File

@ -5,7 +5,7 @@
use App\Exceptions\ComposerInstallFailed; use App\Exceptions\ComposerInstallFailed;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Site; use App\Models\Site;
use App\SSHCommands\ComposerInstallCommand; use App\SSHCommands\Website\ComposerInstallCommand;
use Throwable; use Throwable;
class ComposerInstall extends Job class ComposerInstall extends Job

View File

@ -7,7 +7,7 @@
use App\Helpers\SSH; use App\Helpers\SSH;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Deployment; use App\Models\Deployment;
use App\SSHCommands\RunScript; use App\SSHCommands\System\RunScript;
use Throwable; use Throwable;
class Deploy extends Job class Deploy extends Job

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast; use App\Events\Broadcast;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Site; use App\Models\Site;
use App\SSHCommands\EditFileCommand; use App\SSHCommands\System\EditFileCommand;
use Throwable; use Throwable;
class DeployEnv extends Job class DeployEnv extends Job
@ -26,7 +26,9 @@ public function handle(): void
new EditFileCommand( new EditFileCommand(
$this->site->path.'/.env', $this->site->path.'/.env',
$this->site->env $this->site->env
) ),
'update-env',
$this->site->id
); );
event( event(
new Broadcast('deploy-site-env-finished', [ new Broadcast('deploy-site-env-finished', [

42
app/Jobs/Site/DeployKey.php Executable file
View File

@ -0,0 +1,42 @@
<?php
namespace App\Jobs\Site;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\System\GenerateSshKeyCommand;
use App\SSHCommands\System\ReadSshKeyCommand;
use Throwable;
class DeployKey extends Job
{
protected Site $site;
public function __construct(Site $site)
{
$this->site = $site;
}
/**
* @throws Throwable
*/
public function handle(): void
{
$this->site->server->ssh()->exec(
new GenerateSshKeyCommand($this->site->ssh_key_name),
'generate-ssh-key',
$this->site->id
);
$this->site->ssh_key = $this->site->server->ssh()->exec(
new ReadSshKeyCommand($this->site->ssh_key_name),
'read-public-key',
$this->site->id
);
$this->site->save();
$this->site->sourceControl()->provider()->deployKey(
$this->site->domain.'-key-' . $this->site->id,
$this->site->repository,
$this->site->ssh_key
);
}
}

View File

@ -7,7 +7,7 @@
use App\Models\Database; use App\Models\Database;
use App\Models\DatabaseUser; use App\Models\DatabaseUser;
use App\Models\Site; use App\Models\Site;
use App\SSHCommands\InstallWordpressCommand; use App\SSHCommands\Wordpress\InstallWordpressCommand;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use Throwable; use Throwable;

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast; use App\Events\Broadcast;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Site; use App\Models\Site;
use App\SSHCommands\UpdateBranchCommand; use App\SSHCommands\Website\UpdateBranchCommand;
use Throwable; use Throwable;
class UpdateBranch extends Job class UpdateBranch extends Job

View File

@ -1,41 +0,0 @@
<?php
namespace App\Jobs\Site;
use App\Jobs\Job;
use App\Models\Site;
use App\Models\SourceControl;
use Throwable;
class UpdateSourceControlsRemote extends Job
{
protected SourceControl $sourceControl;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(SourceControl $sourceControl)
{
$this->sourceControl = $sourceControl;
}
/**
* Execute the job.
*
* @throws Throwable
*/
public function handle(): void
{
$sites = Site::query()
->where('user_id', $this->sourceControl->user_id)
->where('source_control', $this->sourceControl->provider)
->get();
foreach ($sites as $site) {
$site->server->ssh()->exec(
'cd '.$site->path.' && git remote set-url origin '.$site->full_repository_url
);
}
}
}

View File

@ -6,7 +6,7 @@
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Server; use App\Models\Server;
use App\Models\SshKey; use App\Models\SshKey;
use App\SSHCommands\DeleteSshKeyCommand; use App\SSHCommands\System\DeleteSshKeyCommand;
use Throwable; use Throwable;
class DeleteSshKeyFromServer extends Job class DeleteSshKeyFromServer extends Job

View File

@ -7,7 +7,7 @@
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Server; use App\Models\Server;
use App\Models\SshKey; use App\Models\SshKey;
use App\SSHCommands\DeploySshKeyCommand; use App\SSHCommands\System\DeploySshKeyCommand;
use Throwable; use Throwable;
class DeploySshKeyToServer extends Job class DeploySshKeyToServer extends Job

View File

@ -0,0 +1,21 @@
<?php
namespace App\Listeners;
use App\Events\Broadcast;
use Illuminate\Support\Facades\Cache;
class BroadcastListener
{
public function __construct()
{
}
public function handle(Broadcast $event): void
{
Cache::set('broadcast', [
'type' => $event->type,
'data' => $event->data
], now()->addMinutes(5));
}
}

View File

@ -15,7 +15,7 @@
* @property string $real_protocol * @property string $real_protocol
* @property int $port * @property int $port
* @property string $source * @property string $source
* @property string $mask * @property ?string $mask
* @property string $note * @property string $note
* @property string $status * @property string $status
* @property Server $server * @property Server $server

View File

@ -3,6 +3,7 @@
namespace App\Models; namespace App\Models;
use App\Contracts\ServerType; use App\Contracts\ServerType;
use App\Enums\ServerStatus;
use App\Facades\SSH; use App\Facades\SSH;
use App\Jobs\Installation\Upgrade; use App\Jobs\Installation\Upgrade;
use App\Jobs\Server\CheckConnection; use App\Jobs\Server\CheckConnection;
@ -232,9 +233,9 @@ public function install(): void
// $this->team->notify(new ServerInstallationStarted($this)); // $this->team->notify(new ServerInstallationStarted($this));
} }
public function ssh(string $user = null, bool $defaultKeys = false): \App\Helpers\SSH|SSHFake public function ssh(string $user = null): \App\Helpers\SSH|SSHFake
{ {
return SSH::init($this, $user, $defaultKeys); return SSH::init($this, $user);
} }
public function installedPHPVersions(): array public function installedPHPVersions(): array
@ -323,7 +324,7 @@ public function getSshUserAttribute(string $value): string
return config('core.ssh_user'); return config('core.ssh_user');
} }
public function sshKey(bool $default = false): array public function sshKey(): array
{ {
if (app()->environment() == 'testing') { if (app()->environment() == 'testing') {
return [ return [
@ -333,14 +334,6 @@ public function sshKey(bool $default = false): array
]; ];
} }
if ($default) {
return [
'public_key' => Str::replace("\n", '', File::get(storage_path(config('core.ssh_public_key_name')))),
'public_key_path' => storage_path(config('core.ssh_public_key_name')),
'private_key_path' => storage_path(config('core.ssh_private_key_name')),
];
}
return [ return [
'public_key' => Str::replace("\n", '', Storage::disk(config('core.key_pairs_disk'))->get($this->id.'.pub')), 'public_key' => Str::replace("\n", '', Storage::disk(config('core.key_pairs_disk'))->get($this->id.'.pub')),
'public_key_path' => Storage::disk(config('core.key_pairs_disk'))->path($this->id.'.pub'), 'public_key_path' => Storage::disk(config('core.key_pairs_disk'))->path($this->id.'.pub'),
@ -385,4 +378,9 @@ public function getHostnameAttribute(): string
{ {
return Str::of($this->name)->slug(); return Str::of($this->name)->slug();
} }
public function isReady(): bool
{
return $this->status == ServerStatus::READY;
}
} }

View File

@ -14,6 +14,7 @@
use App\Jobs\Site\UpdateBranch; use App\Jobs\Site\UpdateBranch;
use Exception; use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOne;
@ -32,7 +33,9 @@
* @property string $path * @property string $path
* @property string $php_version * @property string $php_version
* @property string $source_control * @property string $source_control
* @property int $source_control_id
* @property string $repository * @property string $repository
* @property string $ssh_key
* @property string $branch * @property string $branch
* @property string $status * @property string $status
* @property int $port * @property int $port
@ -52,6 +55,7 @@
* @property string $aliases_string * @property string $aliases_string
* @property string $deployment_script_text * @property string $deployment_script_text
* @property string $env * @property string $env
* @property string $ssh_key_name
*/ */
class Site extends AbstractModel class Site extends AbstractModel
{ {
@ -67,7 +71,9 @@ class Site extends AbstractModel
'path', 'path',
'php_version', 'php_version',
'source_control', 'source_control',
'source_control_id',
'repository', 'repository',
'ssh_key',
'branch', 'branch',
'status', 'status',
'port', 'port',
@ -81,6 +87,7 @@ class Site extends AbstractModel
'progress' => 'integer', 'progress' => 'integer',
'auto_deployment' => 'boolean', 'auto_deployment' => 'boolean',
'aliases' => 'array', 'aliases' => 'array',
'source_control_id' => 'integer',
]; ];
protected $appends = [ protected $appends = [
@ -151,22 +158,21 @@ public function ssls(): HasMany
/** /**
* @throws SourceControlIsNotConnected * @throws SourceControlIsNotConnected
*/ */
public function sourceControl(): SourceControl|HasOne|null public function sourceControl(): SourceControl|HasOne|null|Model
{ {
if (! $this->source_control) { $sourceControl = null;
if (! $this->source_control && ! $this->source_control_id) {
return null; return null;
} }
if ($this->source_control == 'custom') { if ($this->source_control) {
return new SourceControl([ $sourceControl = SourceControl::query()->where('provider', $this->source_control)->first();
'user_id' => $this->id,
'provider' => 'custom',
'token' => '',
'connected' => true,
]);
} }
$sourceControl = SourceControl::query()->where('provider', $this->source_control)->first(); if ($this->source_control_id) {
$sourceControl = SourceControl::query()->find($this->source_control_id);
}
if (! $sourceControl) { if (! $sourceControl) {
throw new SourceControlIsNotConnected($this->source_control); throw new SourceControlIsNotConnected($this->source_control);
@ -180,7 +186,7 @@ public function sourceControl(): SourceControl|HasOne|null
*/ */
public function getFullRepositoryUrlAttribute() public function getFullRepositoryUrlAttribute()
{ {
return $this->sourceControl()->provider()->fullRepoUrl($this->repository); return $this->sourceControl()->provider()->fullRepoUrl($this->repository, $this->ssh_key_name);
} }
public function getAliasesStringAttribute(): string public function getAliasesStringAttribute(): string
@ -394,4 +400,9 @@ public function updateBranch(string $branch): void
{ {
dispatch(new UpdateBranch($this, $branch))->onConnection('ssh'); dispatch(new UpdateBranch($this, $branch))->onConnection('ssh');
} }
public function getSshKeyNameAttribute(): string
{
return str('site_'.$this->id)->toString();
}
} }

View File

@ -7,6 +7,8 @@
/** /**
* @property string $provider * @property string $provider
* @property ?string $profile
* @property ?string $url
* @property string $access_token * @property string $access_token
*/ */
class SourceControl extends AbstractModel class SourceControl extends AbstractModel
@ -15,6 +17,8 @@ class SourceControl extends AbstractModel
protected $fillable = [ protected $fillable = [
'provider', 'provider',
'profile',
'url',
'access_token', 'access_token',
]; ];

View File

@ -43,7 +43,7 @@ public function sendMessage(string $subject, string $text): void
Http::post($data['webhook_url'], [ Http::post($data['webhook_url'], [
'content' => '*'.$subject.'*'."\n".$text, 'content' => '*'.$subject.'*'."\n".$text,
]); ]);
})->onQueue('default'); });
} }
private function checkConnection(string $subject, string $text): bool private function checkConnection(string $subject, string $text): bool

View File

@ -43,7 +43,7 @@ public function sendMessage(string $subject, string $text): void
Http::post($data['webhook_url'], [ Http::post($data['webhook_url'], [
'text' => '*'.$subject.'*'."\n".$text, 'text' => '*'.$subject.'*'."\n".$text,
]); ]);
})->onQueue('default'); });
} }
private function checkConnection(string $subject, string $text): bool private function checkConnection(string $subject, string $text): bool

View File

@ -2,6 +2,8 @@
namespace App\Providers; namespace App\Providers;
use App\Events\Broadcast;
use App\Listeners\BroadcastListener;
use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@ -18,6 +20,9 @@ class EventServiceProvider extends ServiceProvider
Registered::class => [ Registered::class => [
SendEmailVerificationNotification::class, SendEmailVerificationNotification::class,
], ],
Broadcast::class => [
BroadcastListener::class,
],
]; ];
/** /**

View File

@ -1,32 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class ChangeDefaultPHPCommand extends Command
{
/**
* @var string
*/
protected $version;
/**
* InstallPHPCommand constructor.
*/
public function __construct($version)
{
$this->version = $version;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/change-default-php.sh'));
}
public function content(string $os): string
{
return Str::replace('__version__', $this->version, $this->file($os));
}
}

View File

@ -1,47 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class ChangeNginxPHPVersionCommand extends Command
{
/**
* @var string
*/
protected $domain;
/**
* @var string
*/
protected $oldVersion;
/**
* @var string
*/
protected $newVersion;
/**
* CreateVHostCommand constructor.
*/
public function __construct(string $domain, string $oldVersion, string $newVersion)
{
$this->domain = $domain;
$this->oldVersion = $oldVersion;
$this->newVersion = $newVersion;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/webserver/nginx/change-php-version.sh'));
}
public function content(string $os): string
{
$command = Str::replace('__domain__', $this->domain, $this->file($os));
$command = Str::replace('__old_version__', $this->oldVersion, $command);
return Str::replace('__new_version__', $this->newVersion, $command);
}
}

View File

@ -1,45 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class CloneRepositoryCommand extends Command
{
/**
* @var string
*/
protected $repository;
/**
* @var string
*/
protected $path;
protected $branch;
/**
* CloneRepositoryCommand constructor.
*/
public function __construct($repository, $path, $branch)
{
$this->repository = $repository;
$this->path = $path;
$this->branch = $branch;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/common/clone-repository.sh'));
}
public function content(string $os): string
{
$command = Str::replace('__repo__', $this->repository, $this->file($os));
$command = Str::replace('__host__', get_hostname_from_repo($this->repository), $command);
$command = Str::replace('__branch__', $this->branch, $command);
return Str::replace('__path__', $this->path, $command);
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class ComposerInstallCommand extends Command
{
protected $path;
/**
* ComposerInstallCommand constructor.
*/
public function __construct($path)
{
$this->path = $path;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/common/composer-install.sh'));
}
public function content(string $os): string
{
return Str::replace('__path__', $this->path, $this->file($os));
}
}

View File

@ -1,43 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
class CreateCustomSSLCommand extends Command
{
protected $path;
protected $certificate;
protected $pk;
protected $certificatePath;
protected $pkPath;
public function __construct($path, $certificate, $pk, $certificatePath, $pkPath)
{
$this->path = $path;
$this->certificate = $certificate;
$this->pk = $pk;
$this->certificatePath = $certificatePath;
$this->pkPath = $pkPath;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/common/create-custom-ssl.sh'));
}
public function content(string $os): string
{
$content = $this->file($os);
$content = str_replace('__path__', $this->path, $content);
$content = str_replace('__certificate__', $this->certificate, $content);
$content = str_replace('__pk__', $this->pk, $content);
$content = str_replace('__certificate_path__', $this->certificatePath, $content);
return str_replace('__pk_path__', $this->pkPath, $content);
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class CreateLetsencryptSSLCommand extends Command
{
protected $email;
protected $domain;
protected $webDirectory;
public function __construct($email, $domain, $webDirectory)
{
$this->email = $email;
$this->domain = $domain;
$this->webDirectory = $webDirectory;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/common/create-letsencrypt-ssl.sh'));
}
public function content(string $os): string
{
$command = Str::replace('__email__', $this->email, $this->file($os));
$command = Str::replace('__web_directory__', $this->webDirectory, $command);
return Str::replace('__domain__', $this->domain, $command);
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class CreateNginxPHPMyAdminVHostCommand extends Command
{
/**
* @var string
*/
protected $vhost;
public function __construct(string $vhost)
{
$this->vhost = $vhost;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/webserver/nginx/create-phpmyadmin-vhost.sh'));
}
public function content(string $os): string
{
return Str::replace('__vhost__', $this->vhost, $this->file($os));
}
}

View File

@ -1,50 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class CreateNginxVHostCommand extends Command
{
/**
* @var string
*/
protected $domain;
/**
* @var string
*/
protected $path;
/**
* @var string
*/
protected $vhost;
/**
* CreateVHostCommand constructor.
*/
public function __construct(
string $domain,
string $path,
string $vhost
) {
$this->domain = $domain;
$this->path = $path;
$this->vhost = $vhost;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/webserver/nginx/create-vhost.sh'));
}
public function content(string $os): string
{
$command = Str::replace('__path__', $this->path, $this->file($os));
$command = Str::replace('__domain__', $this->domain, $command);
return Str::replace('__vhost__', $this->vhost, $command);
}
}

View File

@ -1,39 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class CreateUserCommand extends Command
{
protected $user;
protected $password;
protected $key;
/**
* CreateUserCommand constructor.
*/
public function __construct($user, $password, $key)
{
$this->user = $user;
$this->password = $password;
$this->key = $key;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/create-user.sh'));
}
public function content(string $os): string
{
$command = $this->file($os);
$command = Str::replace('__user__', $this->user, $command);
$command = Str::replace('__key__', $this->key, $command);
return Str::replace('__password__', $this->password, $command);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\CronJob;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class UpdateCronJobsCommand extends Command
{
public function __construct(protected string $user, protected string $data)
{
}
public function file(): string
{
return File::get(resource_path('commands/cronjobs/update-cron-jobs.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__user__', $this->user)
->replace('__data__', $this->data)
->toString();
}
}

View File

@ -4,33 +4,23 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class BackupDatabaseCommand extends Command class BackupDatabaseCommand extends Command
{ {
protected $provider; public function __construct(protected string $provider, protected string $database, protected string $fileName)
protected $database;
protected $fileName;
public function __construct($provider, $database, $fileName)
{ {
$this->provider = $provider;
$this->database = $database;
$this->fileName = $fileName;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/database/'.$this->provider.'/backup.sh')); return File::get(resource_path(sprintf("commands/database/%s/backup.sh", $this->provider)));
} }
public function content(string $os): string public function content(): string
{ {
$command = $this->file($os); return str($this->file())
$command = Str::replace('__database__', $this->database, $command); ->replace('__database__', $this->database)
->replace('__file__', $this->fileName)
return Str::replace('__file__', $this->fileName, $command); ->toString();
} }
} }

View File

@ -4,33 +4,22 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class CreateCommand extends Command class CreateCommand extends Command
{ {
/** public function __construct(protected string $provider, protected string $name)
* @var string
*/
protected $provider;
/**
* @var string
*/
protected $name;
public function __construct($provider, $name)
{ {
$this->provider = $provider;
$this->name = $name;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/database/'.$this->provider.'/create.sh')); return File::get(resource_path(sprintf("commands/database/%s/create.sh", $this->provider)));
} }
public function content(string $os): string public function content(): string
{ {
return Str::replace('__name__', $this->name, $this->file($os)); return str($this->file())
->replace('__name__', $this->name)
->toString();
} }
} }

View File

@ -4,48 +4,28 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class CreateUserCommand extends Command class CreateUserCommand extends Command
{ {
/** public function __construct(
* @var string protected string $provider,
*/ protected string $username,
protected $provider; protected string $password,
protected string $host
/** ) {
* @var string
*/
protected $username;
/**
* @var string
*/
protected $password;
/**
* @var string
*/
protected $host;
public function __construct($provider, $username, $password, $host)
{
$this->provider = $provider;
$this->username = $username;
$this->password = $password;
$this->host = $host;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/database/'.$this->provider.'/create-user.sh')); return File::get(resource_path(sprintf("commands/database/%s/create-user.sh", $this->provider)));
} }
public function content(string $os): string public function content(): string
{ {
$command = Str::replace('__username__', $this->username, $this->file($os)); return str($this->file())
$command = Str::replace('__password__', $this->password, $command); ->replace('__username__', $this->username)
->replace('__password__', $this->password)
return Str::replace('__host__', $this->host, $command); ->replace('__host__', $this->host)
->toString();
} }
} }

View File

@ -4,33 +4,22 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class DeleteCommand extends Command class DeleteCommand extends Command
{ {
/** public function __construct(protected string $provider, protected string $name)
* @var string
*/
protected $provider;
/**
* @var string
*/
protected $name;
public function __construct($provider, $name)
{ {
$this->provider = $provider;
$this->name = $name;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/database/'.$this->provider.'/delete.sh')); return File::get(resource_path(sprintf("commands/database/%s/delete.sh", $this->provider)));
} }
public function content(string $os): string public function content(): string
{ {
return Str::replace('__name__', $this->name, $this->file($os)); return str($this->file())
->replace('__name__', $this->name)
->toString();
} }
} }

View File

@ -4,41 +4,23 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class DeleteUserCommand extends Command class DeleteUserCommand extends Command
{ {
/** public function __construct(protected string $provider, protected string $username, protected string $host)
* @var string
*/
protected $provider;
/**
* @var string
*/
protected $username;
/**
* @var string
*/
protected $host;
public function __construct($provider, $username, $host)
{ {
$this->provider = $provider;
$this->username = $username;
$this->host = $host;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/database/'.$this->provider.'/delete-user.sh')); return File::get(resource_path(sprintf("commands/database/%s/delete-user.sh", $this->provider)));
} }
public function content(string $os): string public function content(): string
{ {
$command = Str::replace('__username__', $this->username, $this->file($os)); return str($this->file())
->replace('__username__', $this->username)
return Str::replace('__host__', $this->host, $command); ->replace('__host__', $this->host)
->toString();
} }
} }

View File

@ -0,0 +1,19 @@
<?php
namespace App\SSHCommands\Database;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class InstallMariadbCommand extends Command
{
public function file(): string
{
return File::get(resource_path('commands/database/install-mariadb.sh'));
}
public function content(): string
{
return $this->file();
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\SSHCommands\Database;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class InstallMysqlCommand extends Command
{
public function __construct(protected string $version)
{
}
public function file(): string
{
if ($this->version == '8.0') {
return File::get(resource_path('commands/database/install-mysql-8.sh'));
}
return File::get(resource_path('commands/database/install-mysql.sh'));
}
public function content(): string
{
return $this->file();
}
}

View File

@ -4,45 +4,28 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class LinkCommand extends Command class LinkCommand extends Command
{ {
/** public function __construct(
* @var string protected string $provider,
*/ protected string $username,
protected $provider; protected string $host,
protected string $database
/** ) {
* @var string
*/
protected $username;
protected $host;
/**
* @var string
*/
protected $database;
public function __construct($provider, $username, $host, $database)
{
$this->provider = $provider;
$this->username = $username;
$this->host = $host;
$this->database = $database;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/database/'.$this->provider.'/link.sh')); return File::get(resource_path(sprintf("commands/database/%s/link.sh", $this->provider)));
} }
public function content(string $os): string public function content(): string
{ {
$command = Str::replace('__username__', $this->username, $this->file($os)); return str($this->file())
$command = Str::replace('__host__', $this->host, $command); ->replace('__username__', $this->username)
->replace('__host__', $this->host)
return Str::replace('__database__', $this->database, $command); ->replace('__database__', $this->database)
->toString();
} }
} }

View File

@ -4,33 +4,23 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class RestoreDatabaseCommand extends Command class RestoreDatabaseCommand extends Command
{ {
protected $provider; public function __construct(protected string $provider, protected string $database, protected string $fileName)
protected $database;
protected $fileName;
public function __construct($provider, $database, $fileName)
{ {
$this->provider = $provider;
$this->database = $database;
$this->fileName = $fileName;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/database/'.$this->provider.'/restore.sh')); return File::get(resource_path(sprintf("commands/database/%s/restore.sh", $this->provider)));
} }
public function content(string $os): string public function content(): string
{ {
$command = $this->file($os); return str($this->file())
$command = Str::replace('__database__', $this->database, $command); ->replace('__database__', $this->database)
->replace('__file__', $this->fileName)
return Str::replace('__file__', $this->fileName, $command); ->toString();
} }
} }

View File

@ -4,38 +4,26 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class UnlinkCommand extends Command class UnlinkCommand extends Command
{ {
/** public function __construct(
* @var string protected string $provider,
*/ protected string $username,
protected $provider; protected string $host
) {
/**
* @var string
*/
protected $username;
protected $host;
public function __construct($provider, $username, $host)
{
$this->provider = $provider;
$this->username = $username;
$this->host = $host;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/database/'.$this->provider.'/unlink.sh')); return File::get(resource_path(sprintf("commands/database/%s/unlink.sh", $this->provider)));
} }
public function content(string $os): string public function content(): string
{ {
$command = Str::replace('__username__', $this->username, $this->file($os)); return str($this->file())
->replace('__username__', $this->username)
return Str::replace('__host__', $this->host, $command); ->replace('__host__', $this->host)
->toString();
} }
} }

View File

@ -1,30 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class DeleteNginxPHPMyAdminVHost extends Command
{
/**
* @var string
*/
protected $path;
public function __construct(
string $path,
) {
$this->path = $path;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/webserver/nginx/delete-phpmyadmin-vhost.sh'));
}
public function content(string $os): string
{
return Str::replace('__path__', $this->path, $this->file($os));
}
}

View File

@ -1,40 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class DeleteNginxSiteCommand extends Command
{
/**
* @var string
*/
protected $domain;
/**
* @var string
*/
protected $path;
/**
* CloneRepositoryCommand constructor.
*/
public function __construct($domain, $path)
{
$this->domain = $domain;
$this->path = $path;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/webserver/nginx/delete-site.sh'));
}
public function content(string $os): string
{
$command = Str::replace('__domain__', $this->domain, $this->file($os));
return Str::replace('__path__', $this->path, $command);
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class DeleteSshKeyCommand extends Command
{
/**
* @var string
*/
protected $key;
/**
* InstallPHPCommand constructor.
*/
public function __construct($key)
{
$this->key = $key;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/delete-ssh-key.sh'));
}
public function content(string $os): string
{
return Str::replace('__key__', Str::replace('/', '\/', $this->key), $this->file($os));
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class DeploySshKeyCommand extends Command
{
/**
* @var string
*/
protected $key;
/**
* InstallPHPCommand constructor.
*/
public function __construct($key)
{
$this->key = $key;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/deploy-ssh-key.sh'));
}
public function content(string $os): string
{
return Str::replace('__key__', addslashes($this->key), $this->file($os));
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
class DownloadPHPMyAdminCommand extends Command
{
public function file(string $os): string
{
return File::get(base_path('system/commands/common/download-phpmyadmin.sh'));
}
public function content(string $os): string
{
return $this->file($os);
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class EditFileCommand extends Command
{
protected $path;
protected $content;
public function __construct($path, $content)
{
$this->path = $path;
$this->content = $content;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/common/edit-file.sh'));
}
public function content(string $os): string
{
$command = Str::replace('__path__', $this->path, $this->file($os));
return Str::replace('__content__', addslashes($this->content), $command);
}
}

View File

@ -9,48 +9,18 @@ class AddRuleCommand extends Command
{ {
use CommandContent; use CommandContent;
/** public function __construct(
* @var string protected string $provider,
*/ protected string $type,
protected $provider; protected string $protocol,
protected string $port,
/** protected string $source,
* @var string protected ?string $mask = null
*/ ) {
protected $type;
/**
* @var string
*/
protected $protocol;
/**
* @var string
*/
protected $port;
/**
* @var string
*/
protected $source;
/**
* @var string
*/
protected $mask;
public function __construct($provider, $type, $protocol, $port, $source, $mask)
{
$this->provider = $provider;
$this->type = $type;
$this->protocol = $protocol;
$this->port = $port;
$this->source = $source;
$this->mask = $mask;
} }
public function file(string $os): string public function file(): string
{ {
return File::get(base_path('system/commands/firewall/'.$this->provider.'/add-rule.sh')); return File::get(resource_path(sprintf("commands/firewall/%s/add-rule.sh", $this->provider)));
} }
} }

Some files were not shown because too many files have changed in this diff Show More