diff --git a/.prettierignore b/.prettierignore index 8eddfc8..46ea115 100644 --- a/.prettierignore +++ b/.prettierignore @@ -12,3 +12,4 @@ sail *.yml !*.blade.php !*.sh +resources/views/ssh/ diff --git a/app/Actions/Queue/CreateQueue.php b/app/Actions/Queue/CreateQueue.php index eacc84c..b908856 100644 --- a/app/Actions/Queue/CreateQueue.php +++ b/app/Actions/Queue/CreateQueue.php @@ -6,6 +6,7 @@ use App\Models\Queue; use App\Models\Server; use App\Models\Site; +use App\SSH\Services\ProcessManager\ProcessManager; use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; @@ -29,7 +30,9 @@ public function create(mixed $queueable, array $input): void $queue->save(); dispatch(function () use ($queue) { - $queue->server->processManager()->handler()->create( + /** @var ProcessManager $processManager */ + $processManager = $queue->server->processManager()->handler(); + $processManager->create( $queue->id, $queue->command, $queue->user, diff --git a/app/Actions/SSL/CreateSSL.php b/app/Actions/SSL/CreateSSL.php index d67e126..11a025b 100644 --- a/app/Actions/SSL/CreateSSL.php +++ b/app/Actions/SSL/CreateSSL.php @@ -44,6 +44,7 @@ public function create(Site $site, array $input): void $webserver->setupSSL($ssl); $ssl->status = SslStatus::CREATED; $ssl->save(); + $webserver->updateVHost($site); $site->type()->edit(); })->catch(function () use ($ssl) { $ssl->status = SslStatus::FAILED; diff --git a/app/Actions/SSL/DeleteSSL.php b/app/Actions/SSL/DeleteSSL.php index 12a4caf..ff3e47c 100644 --- a/app/Actions/SSL/DeleteSSL.php +++ b/app/Actions/SSL/DeleteSSL.php @@ -2,6 +2,7 @@ namespace App\Actions\SSL; +use App\Enums\SslStatus; use App\Models\Ssl; use App\SSH\Services\Webserver\Webserver; @@ -9,6 +10,8 @@ class DeleteSSL { public function delete(Ssl $ssl): void { + $ssl->status = SslStatus::DELETING; + $ssl->save(); /** @var Webserver $webserver */ $webserver = $ssl->site->server->webserver()->handler(); $webserver->removeSSL($ssl); diff --git a/app/Actions/Site/DeleteSite.php b/app/Actions/Site/DeleteSite.php index e8de99b..be53f51 100644 --- a/app/Actions/Site/DeleteSite.php +++ b/app/Actions/Site/DeleteSite.php @@ -2,12 +2,16 @@ namespace App\Actions\Site; +use App\Exceptions\SSHError; use App\Models\Site; use App\SSH\Services\PHP\PHP; use App\SSH\Services\Webserver\Webserver; class DeleteSite { + /** + * @throws SSHError + */ public function delete(Site $site): void { /** @var Webserver $webserverHandler */ diff --git a/app/Actions/Site/Deploy.php b/app/Actions/Site/Deploy.php index 8b8781d..1c3faca 100644 --- a/app/Actions/Site/Deploy.php +++ b/app/Actions/Site/Deploy.php @@ -4,7 +4,7 @@ use App\Enums\DeploymentStatus; use App\Exceptions\DeploymentScriptIsEmptyException; -use App\Exceptions\SourceControlIsNotConnected; +use App\Exceptions\SSHError; use App\Models\Deployment; use App\Models\ServerLog; use App\Models\Site; @@ -12,8 +12,8 @@ class Deploy { /** - * @throws SourceControlIsNotConnected * @throws DeploymentScriptIsEmptyException + * @throws SSHError */ public function run(Site $site): Deployment { diff --git a/app/Actions/Site/UpdateAliases.php b/app/Actions/Site/UpdateAliases.php index 2d2f397..3da9c86 100644 --- a/app/Actions/Site/UpdateAliases.php +++ b/app/Actions/Site/UpdateAliases.php @@ -14,7 +14,7 @@ public function update(Site $site, array $input): void /** @var Webserver $webserver */ $webserver = $site->server->webserver()->handler(); - $webserver->updateVHost($site, ! $site->hasSSL()); + $webserver->updateVHost($site); $site->save(); } diff --git a/app/Actions/Site/UpdateBranch.php b/app/Actions/Site/UpdateBranch.php index bcf8cf8..94af0bf 100755 --- a/app/Actions/Site/UpdateBranch.php +++ b/app/Actions/Site/UpdateBranch.php @@ -2,6 +2,7 @@ namespace App\Actions\Site; +use App\Exceptions\SSHError; use App\Models\Site; use App\SSH\Git\Git; use Illuminate\Validation\ValidationException; @@ -10,6 +11,7 @@ class UpdateBranch { /** * @throws ValidationException + * @throws SSHError */ public function update(Site $site, array $input): void { diff --git a/app/Actions/Site/UpdatePHPVersion.php b/app/Actions/Site/UpdatePHPVersion.php index 1b41483..49720d2 100644 --- a/app/Actions/Site/UpdatePHPVersion.php +++ b/app/Actions/Site/UpdatePHPVersion.php @@ -2,6 +2,7 @@ namespace App\Actions\Site; +use App\Exceptions\SSHError; use App\Models\Site; use Illuminate\Validation\Rule; @@ -19,6 +20,9 @@ public static function rules(Site $site): array ]; } + /** + * @throws SSHError + */ public function update(Site $site, array $input): void { $site->changePHPVersion($input['version']); diff --git a/app/Models/Service.php b/app/Models/Service.php index a705f49..4ae3e95 100755 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -5,11 +5,7 @@ use App\Actions\Service\Manage; use App\Enums\ServiceStatus; use App\Exceptions\ServiceInstallationFailed; -use App\SSH\Services\Database\Database as DatabaseAlias; -use App\SSH\Services\PHP\PHP as PHPAlias; -use App\SSH\Services\ProcessManager\ProcessManager; use App\SSH\Services\ServiceInterface; -use App\SSH\Services\WebServer\WebServer as WebServerAlias; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Support\Str; @@ -79,9 +75,6 @@ public function server(): BelongsTo return $this->belongsTo(Server::class); } - /** - * @return ProcessManager|DatabaseAlias|PHPAlias|WebServerAlias - */ public function handler(): ServiceInterface { $handler = config('core.service_handlers')[$this->name]; diff --git a/app/Models/Site.php b/app/Models/Site.php index c4f3c4d..de7da74 100755 --- a/app/Models/Site.php +++ b/app/Models/Site.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Enums\SiteStatus; +use App\Enums\SslStatus; use App\Exceptions\FailedToDestroyGitHook; use App\Exceptions\SourceControlIsNotConnected; use App\Exceptions\SSHError; @@ -35,6 +36,7 @@ * @property int $port * @property int $progress * @property string $user + * @property bool $force_ssl * @property Server $server * @property ServerLog[] $logs * @property Deployment[] $deployments @@ -198,6 +200,9 @@ public function php(): ?Service return null; } + /** + * @throws SSHError + */ public function changePHPVersion($version): void { /** @var Webserver $handler */ @@ -219,6 +224,7 @@ public function activeSsl(): HasOne { return $this->hasOne(Ssl::class) ->where('expires_at', '>=', now()) + ->where('status', SslStatus::CREATED) ->orderByDesc('id'); } @@ -301,11 +307,6 @@ public function getEnv(): string } } - public function hasSSL(): bool - { - return $this->ssls->isNotEmpty(); - } - public function environmentVariables(?Deployment $deployment = null): array { return [ @@ -319,30 +320,16 @@ public function environmentVariables(?Deployment $deployment = null): array ]; } - public function isolate(): void - { - if (! $this->isIsolated()) { - return; - } - - $this->server->os()->createIsolatedUser( - $this->user, - Str::random(15), - $this->id - ); - - // Generate the FPM pool - /** @var PHP $php */ - $php = $this->php()->handler(); - $php->createFpmPool( - $this->user, - $this->php_version, - $this->id - ); - } - public function isIsolated(): bool { return $this->user != $this->server->getSshUser(); } + + public function webserver(): Webserver + { + /** @var Webserver $webserver */ + $webserver = $this->server->webserver()->handler(); + + return $webserver; + } } diff --git a/app/SSH/Composer/Composer.php b/app/SSH/Composer/Composer.php index cea0acb..cb262dc 100644 --- a/app/SSH/Composer/Composer.php +++ b/app/SSH/Composer/Composer.php @@ -2,19 +2,20 @@ namespace App\SSH\Composer; +use App\Exceptions\SSHError; use App\Models\Site; -use App\SSH\HasScripts; class Composer { - use HasScripts; - + /** + * @throws SSHError + */ public function installDependencies(Site $site): void { $site->server->ssh($site->user)->exec( - $this->getScript('composer-install.sh', [ + view('ssh.composer.composer-install', [ 'path' => $site->path, - 'php_version' => $site->php_version, + 'phpVersion' => $site->php_version, ]), 'composer-install', $site->id diff --git a/app/SSH/Composer/scripts/composer-install.sh b/app/SSH/Composer/scripts/composer-install.sh deleted file mode 100755 index 7628210..0000000 --- a/app/SSH/Composer/scripts/composer-install.sh +++ /dev/null @@ -1,7 +0,0 @@ -if ! cd __path__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! php__php_version__ /usr/local/bin/composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Cron/Cron.php b/app/SSH/Cron/Cron.php index 64b3ef5..7331692 100644 --- a/app/SSH/Cron/Cron.php +++ b/app/SSH/Cron/Cron.php @@ -2,26 +2,24 @@ namespace App\SSH\Cron; +use App\Exceptions\SSHError; use App\Models\Server; class Cron { public function __construct(protected Server $server) {} + /** + * @throws SSHError + */ public function update(string $user, string $cron): void { - $command = <<<EOD - if ! echo '$cron' | sudo -u $user crontab -; then - echo 'VITO_SSH_ERROR' && exit 1 - fi - - if ! sudo -u $user crontab -l; then - echo 'VITO_SSH_ERROR' && exit 1 - fi - - echo 'cron updated!' - EOD; - - $this->server->ssh()->exec($command, 'update-cron'); + $this->server->ssh()->exec( + view('ssh.cron.update', [ + 'cron' => $cron, + 'user' => $user, + ]), + 'update-cron' + ); } } diff --git a/app/SSH/Git/Git.php b/app/SSH/Git/Git.php index a02b58e..21ea0b1 100644 --- a/app/SSH/Git/Git.php +++ b/app/SSH/Git/Git.php @@ -2,17 +2,18 @@ namespace App\SSH\Git; +use App\Exceptions\SSHError; use App\Models\Site; -use App\SSH\HasScripts; class Git { - use HasScripts; - + /** + * @throws SSHError + */ public function clone(Site $site): void { $site->server->ssh($site->user)->exec( - $this->getScript('clone.sh', [ + view('ssh.git.clone', [ 'host' => str($site->getFullRepositoryUrl())->after('@')->before('-'), 'repo' => $site->getFullRepositoryUrl(), 'path' => $site->path, @@ -24,10 +25,13 @@ public function clone(Site $site): void ); } + /** + * @throws SSHError + */ public function checkout(Site $site): void { $site->server->ssh($site->user)->exec( - $this->getScript('checkout.sh', [ + view('ssh.git.checkout', [ 'path' => $site->path, 'branch' => $site->branch, ]), diff --git a/app/SSH/Git/scripts/clone.sh b/app/SSH/Git/scripts/clone.sh deleted file mode 100755 index a7fa140..0000000 --- a/app/SSH/Git/scripts/clone.sh +++ /dev/null @@ -1,29 +0,0 @@ -echo "Host __host__-__key__ - Hostname __host__ - IdentityFile=~/.ssh/__key__" >> ~/.ssh/config - -chmod 600 ~/.ssh/config - -ssh-keyscan -H __host__ >> ~/.ssh/known_hosts - -rm -rf __path__ - -if ! git config --global core.fileMode false; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! git clone -b __branch__ __repo__ __path__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! find __path__ -type d -exec chmod 755 {} \;; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! find __path__ -type f -exec chmod 644 {} \;; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! cd __path__ && git config core.fileMode false; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/HasScripts.php b/app/SSH/HasScripts.php deleted file mode 100644 index a74b97b..0000000 --- a/app/SSH/HasScripts.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -namespace App\SSH; - -use ReflectionClass; - -trait HasScripts -{ - protected function getScript(string $name, array $vars = []): string - { - $reflector = new ReflectionClass($this); - $scriptsDir = dirname($reflector->getFileName()).'/scripts'; - $script = file_get_contents($scriptsDir.'/'.$name); - foreach ($vars as $key => $value) { - $script = str_replace('__'.$key.'__', $value, $script); - } - - return $script; - } -} diff --git a/app/SSH/OS/OS.php b/app/SSH/OS/OS.php index 15e4bd3..15079ff 100644 --- a/app/SSH/OS/OS.php +++ b/app/SSH/OS/OS.php @@ -2,11 +2,11 @@ namespace App\SSH\OS; +use App\Exceptions\SSHError; use App\Exceptions\SSHUploadFailed; use App\Models\Server; use App\Models\ServerLog; use App\Models\Site; -use App\SSH\HasScripts; use Illuminate\Filesystem\FilesystemAdapter; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; @@ -14,30 +14,40 @@ class OS { - use HasScripts; - public function __construct(protected Server $server) {} + /** + * @throws SSHError + */ public function installDependencies(): void { $this->server->ssh()->exec( - $this->getScript('install-dependencies.sh'), + view('ssh.os.install-dependencies', [ + 'name' => $this->server->creator->name, + 'email' => $this->server->creator->email, + ]), 'install-dependencies' ); } + /** + * @throws SSHError + */ public function upgrade(): void { $this->server->ssh()->exec( - $this->getScript('upgrade.sh'), + view('ssh.os.upgrade'), 'upgrade' ); } + /** + * @throws SSHError + */ public function availableUpdates(): int { $result = $this->server->ssh()->exec( - $this->getScript('available-updates.sh'), + view('ssh.os.available-updates'), 'check-available-updates' ); @@ -47,10 +57,13 @@ public function availableUpdates(): int return max($availableUpdates, 0); } + /** + * @throws SSHError + */ public function createUser(string $user, string $password, string $key): void { $this->server->ssh()->exec( - $this->getScript('create-user.sh', [ + view('ssh.os.create-user', [ 'user' => $user, 'password' => $password, 'key' => $key, @@ -59,12 +72,15 @@ public function createUser(string $user, string $password, string $key): void ); } + /** + * @throws SSHError + */ public function createIsolatedUser(string $user, string $password, int $site_id): void { $this->server->ssh()->exec( - $this->getScript('create-isolated-user.sh', [ + view('ssh.os.create-isolated-user', [ 'user' => $user, - 'server_user' => $this->server->getSshUser(), + 'serverUser' => $this->server->getSshUser(), 'password' => $password, ]), 'create-isolated-user', @@ -72,40 +88,52 @@ public function createIsolatedUser(string $user, string $password, int $site_id) ); } + /** + * @throws SSHError + */ public function deleteIsolatedUser(string $user): void { $this->server->ssh()->exec( - $this->getScript('delete-isolated-user.sh', [ + view('ssh.os.delete-isolated-user', [ 'user' => $user, - 'server_user' => $this->server->getSshUser(), + 'serverUser' => $this->server->getSshUser(), ]), 'delete-isolated-user' ); } + /** + * @throws SSHError + */ public function getPublicKey(string $user): string { return $this->server->ssh()->exec( - $this->getScript('read-file.sh', [ + view('ssh.os.read-file', [ 'path' => '/home/'.$user.'/.ssh/id_rsa.pub', ]) ); } + /** + * @throws SSHError + */ public function deploySSHKey(string $key): void { $this->server->ssh()->exec( - $this->getScript('deploy-ssh-key.sh', [ + view('ssh.os.deploy-ssh-key', [ 'key' => $key, ]), 'deploy-ssh-key' ); } + /** + * @throws SSHError + */ public function deleteSSHKey(string $key): void { $this->server->ssh()->exec( - $this->getScript('delete-ssh-key.sh', [ + view('ssh.os.delete-ssh-key', [ 'key' => $key, 'user' => $this->server->getSshUser(), ]), @@ -113,10 +141,13 @@ public function deleteSSHKey(string $key): void ); } + /** + * @throws SSHError + */ public function generateSSHKey(string $name, ?Site $site = null): void { $site->server->ssh($site->user)->exec( - $this->getScript('generate-ssh-key.sh', [ + view('ssh.os.generate-ssh-key', [ 'name' => $name, ]), 'generate-ssh-key', @@ -124,19 +155,25 @@ public function generateSSHKey(string $name, ?Site $site = null): void ); } + /** + * @throws SSHError + */ public function readSSHKey(string $name, ?Site $site = null): string { return $site->server->ssh($site->user)->exec( - $this->getScript('read-ssh-key.sh', [ + view('ssh.os.read-ssh-key', [ 'name' => $name, ]), ); } + /** + * @throws SSHError + */ public function reboot(): void { $this->server->ssh()->exec( - $this->getScript('reboot.sh'), + view('ssh.os.reboot'), ); } @@ -161,25 +198,34 @@ public function editFile(string $path, ?string $content = null): void } } + /** + * @throws SSHError + */ public function readFile(string $path): string { return $this->server->ssh()->exec( - $this->getScript('read-file.sh', [ + view('ssh.os.read-file', [ 'path' => $path, ]) ); } + /** + * @throws SSHError + */ public function tail(string $path, int $lines): string { return $this->server->ssh()->exec( - $this->getScript('tail.sh', [ + view('ssh.os.tail', [ 'path' => $path, 'lines' => $lines, ]) ); } + /** + * @throws SSHError + */ public function runScript(string $path, string $script, ?ServerLog $serverLog, ?string $user = null, ?array $variables = []): ServerLog { $ssh = $this->server->ssh($user); @@ -190,7 +236,7 @@ public function runScript(string $path, string $script, ?ServerLog $serverLog, ? foreach ($variables as $key => $variable) { $command .= "$key=$variable\n"; } - $command .= $this->getScript('run-script.sh', [ + $command .= view('ssh.os.run-script', [ 'path' => $path, 'script' => $script, ]); @@ -201,16 +247,22 @@ public function runScript(string $path, string $script, ?ServerLog $serverLog, ? return $ssh->log; } + /** + * @throws SSHError + */ public function download(string $url, string $path): string { return $this->server->ssh()->exec( - $this->getScript('download.sh', [ + view('ssh.os.download', [ 'url' => $url, 'path' => $path, ]) ); } + /** + * @throws SSHError + */ public function unzip(string $path): string { return $this->server->ssh()->exec( @@ -218,18 +270,24 @@ public function unzip(string $path): string ); } + /** + * @throws SSHError + */ public function cleanup(): void { $this->server->ssh()->exec( - $this->getScript('cleanup.sh'), + view('ssh.os.cleanup'), 'cleanup' ); } + /** + * @throws SSHError + */ public function resourceInfo(): array { $info = $this->server->ssh()->exec( - $this->getScript('resource-info.sh'), + view('ssh.os.resource-info'), ); return [ @@ -243,10 +301,13 @@ public function resourceInfo(): array ]; } + /** + * @throws SSHError + */ public function deleteFile(string $path): void { $this->server->ssh()->exec( - $this->getScript('delete-file.sh', [ + view('ssh.os.delete-file', [ 'path' => $path, ]), 'delete-file' diff --git a/app/SSH/OS/scripts/create-isolated-user.sh b/app/SSH/OS/scripts/create-isolated-user.sh deleted file mode 100644 index 4396d25..0000000 --- a/app/SSH/OS/scripts/create-isolated-user.sh +++ /dev/null @@ -1,18 +0,0 @@ -export DEBIAN_FRONTEND=noninteractive -if ! sudo useradd -p $(openssl passwd -1 __password__) __user__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -sudo mkdir /home/__user__ -sudo mkdir /home/__user__/.logs -sudo mkdir /home/__user__/tmp -sudo mkdir /home/__user__/bin -sudo mkdir /home/__user__/.ssh -echo 'export PATH="/home/__user__/bin:$PATH"' | sudo tee -a /home/__user__/.bashrc -echo 'export PATH="/home/__user__/bin:$PATH"' | sudo tee -a /home/__user__/.profile -sudo usermod -a -G __user__ __server_user__ -sudo chown -R __user__:__user__ /home/__user__ -sudo chmod -R 755 /home/__user__ -sudo chmod -R 700 /home/__user__/.ssh -sudo chsh -s /bin/bash __user__ -echo "Created user __user__." diff --git a/app/SSH/OS/scripts/create-user.sh b/app/SSH/OS/scripts/create-user.sh deleted file mode 100755 index 3acf9c4..0000000 --- a/app/SSH/OS/scripts/create-user.sh +++ /dev/null @@ -1,11 +0,0 @@ -export DEBIAN_FRONTEND=noninteractive -echo "__key__" | sudo tee -a /root/.ssh/authorized_keys -sudo useradd -p $(openssl passwd -1 __password__) __user__ -sudo usermod -aG sudo __user__ -echo "__user__ ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers -sudo mkdir /home/__user__ -sudo mkdir /home/__user__/.ssh -echo "__key__" | sudo tee -a /home/__user__/.ssh/authorized_keys -sudo chown -R __user__:__user__ /home/__user__ -sudo chsh -s /bin/bash __user__ -sudo su - __user__ -c "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa" <<< y diff --git a/app/SSH/OS/scripts/delete-file.sh b/app/SSH/OS/scripts/delete-file.sh deleted file mode 100644 index 4a45e4a..0000000 --- a/app/SSH/OS/scripts/delete-file.sh +++ /dev/null @@ -1 +0,0 @@ -rm -f __path__ diff --git a/app/SSH/OS/scripts/delete-isolated-user.sh b/app/SSH/OS/scripts/delete-isolated-user.sh deleted file mode 100644 index d73f38c..0000000 --- a/app/SSH/OS/scripts/delete-isolated-user.sh +++ /dev/null @@ -1,3 +0,0 @@ -sudo gpasswd -d __server_user__ __user__ -sudo userdel -r "__user__" -echo "User __user__ has been deleted." diff --git a/app/SSH/OS/scripts/deploy-ssh-key.sh b/app/SSH/OS/scripts/deploy-ssh-key.sh deleted file mode 100644 index 6ea323a..0000000 --- a/app/SSH/OS/scripts/deploy-ssh-key.sh +++ /dev/null @@ -1,3 +0,0 @@ -if ! echo '__key__' | sudo tee -a ~/.ssh/authorized_keys; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/OS/scripts/download.sh b/app/SSH/OS/scripts/download.sh deleted file mode 100644 index c5a7c7b..0000000 --- a/app/SSH/OS/scripts/download.sh +++ /dev/null @@ -1,3 +0,0 @@ -if ! wget __url__ -O __path__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/OS/scripts/generate-ssh-key.sh b/app/SSH/OS/scripts/generate-ssh-key.sh deleted file mode 100644 index 7f41153..0000000 --- a/app/SSH/OS/scripts/generate-ssh-key.sh +++ /dev/null @@ -1 +0,0 @@ -ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/__name__ diff --git a/app/SSH/OS/scripts/read-file.sh b/app/SSH/OS/scripts/read-file.sh deleted file mode 100644 index 3e14507..0000000 --- a/app/SSH/OS/scripts/read-file.sh +++ /dev/null @@ -1 +0,0 @@ -[ -f __path__ ] && sudo cat __path__ diff --git a/app/SSH/OS/scripts/read-ssh-key.sh b/app/SSH/OS/scripts/read-ssh-key.sh deleted file mode 100644 index 9a723f0..0000000 --- a/app/SSH/OS/scripts/read-ssh-key.sh +++ /dev/null @@ -1 +0,0 @@ -cat ~/.ssh/__name__.pub diff --git a/app/SSH/OS/scripts/tail.sh b/app/SSH/OS/scripts/tail.sh deleted file mode 100644 index 0716fd5..0000000 --- a/app/SSH/OS/scripts/tail.sh +++ /dev/null @@ -1 +0,0 @@ -sudo tail -n __lines__ __path__ diff --git a/app/SSH/PHPMyAdmin/PHPMyAdmin.php b/app/SSH/PHPMyAdmin/PHPMyAdmin.php index 1ffbff8..35f9c7e 100644 --- a/app/SSH/PHPMyAdmin/PHPMyAdmin.php +++ b/app/SSH/PHPMyAdmin/PHPMyAdmin.php @@ -2,17 +2,18 @@ namespace App\SSH\PHPMyAdmin; +use App\Exceptions\SSHError; use App\Models\Site; -use App\SSH\HasScripts; class PHPMyAdmin { - use HasScripts; - + /** + * @throws SSHError + */ public function install(Site $site): void { $site->server->ssh($site->user)->exec( - $this->getScript('install.sh', [ + view('ssh.phpmyadmin.install', [ 'version' => $site->type_data['version'], 'path' => $site->path, ]), diff --git a/app/SSH/PHPMyAdmin/scripts/install.sh b/app/SSH/PHPMyAdmin/scripts/install.sh deleted file mode 100755 index 4e5d67c..0000000 --- a/app/SSH/PHPMyAdmin/scripts/install.sh +++ /dev/null @@ -1,29 +0,0 @@ -if ! rm -rf phpmyadmin; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! rm -rf __path__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! wget https://files.phpmyadmin.net/phpMyAdmin/__version__/phpMyAdmin-__version__-all-languages.zip; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! unzip phpMyAdmin-__version__-all-languages.zip; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! rm -rf phpMyAdmin-__version__-all-languages.zip; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! mv phpMyAdmin-__version__-all-languages __path__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! mv __path__/config.sample.inc.php __path__/config.inc.php; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "PHPMyAdmin installed!" diff --git a/app/SSH/Services/Database/AbstractDatabase.php b/app/SSH/Services/Database/AbstractDatabase.php index 2f9bddb..3f572a8 100755 --- a/app/SSH/Services/Database/AbstractDatabase.php +++ b/app/SSH/Services/Database/AbstractDatabase.php @@ -3,16 +3,18 @@ namespace App\SSH\Services\Database; use App\Enums\BackupStatus; +use App\Exceptions\ServiceInstallationFailed; +use App\Exceptions\SSHError; use App\Models\BackupFile; -use App\SSH\HasScripts; use App\SSH\Services\AbstractService; use Closure; abstract class AbstractDatabase extends AbstractService implements Database { - use HasScripts; - - abstract protected function getScriptsDir(): string; + protected function getScriptView(string $script): string + { + return 'ssh.services.database.'.$this->service->name.'.'.$script; + } public function creationRules(array $input): array { @@ -29,10 +31,14 @@ function (string $attribute, mixed $value, Closure $fail) { ]; } + /** + * @throws ServiceInstallationFailed + * @throws SSHError + */ public function install(): void { - $version = $this->service->version; - $command = $this->getScript($this->service->name.'/install-'.$version.'.sh'); + $version = str_replace('.', '', $this->service->version); + $command = view($this->getScriptView('install-'.$version)); $this->service->server->ssh()->exec($command, 'install-'.$this->service->name.'-'.$version); $status = $this->service->server->systemd()->status($this->service->unit); $this->service->validateInstall($status); @@ -63,38 +69,50 @@ function (string $attribute, mixed $value, Closure $fail) { ]; } + /** + * @throws SSHError + */ public function uninstall(): void { $version = $this->service->version; - $command = $this->getScript($this->service->name.'/uninstall.sh'); + $command = view($this->getScriptView('uninstall')); $this->service->server->ssh()->exec($command, 'uninstall-'.$this->service->name.'-'.$version); $this->service->server->os()->cleanup(); } + /** + * @throws SSHError + */ public function create(string $name): void { $this->service->server->ssh()->exec( - $this->getScript($this->getScriptsDir().'/create.sh', [ + view($this->getScriptView('create'), [ 'name' => $name, ]), 'create-database' ); } + /** + * @throws SSHError + */ public function delete(string $name): void { $this->service->server->ssh()->exec( - $this->getScript($this->getScriptsDir().'/delete.sh', [ + view($this->getScriptView('delete'), [ 'name' => $name, ]), 'delete-database' ); } + /** + * @throws SSHError + */ public function createUser(string $username, string $password, string $host): void { $this->service->server->ssh()->exec( - $this->getScript($this->getScriptsDir().'/create-user.sh', [ + view($this->getScriptView('create-user'), [ 'username' => $username, 'password' => $password, 'host' => $host, @@ -103,10 +121,13 @@ public function createUser(string $username, string $password, string $host): vo ); } + /** + * @throws SSHError + */ public function deleteUser(string $username, string $host): void { $this->service->server->ssh()->exec( - $this->getScript($this->getScriptsDir().'/delete-user.sh', [ + view($this->getScriptView('delete-user'), [ 'username' => $username, 'host' => $host, ]), @@ -114,6 +135,9 @@ public function deleteUser(string $username, string $host): void ); } + /** + * @throws SSHError + */ public function link(string $username, string $host, array $databases): void { $ssh = $this->service->server->ssh(); @@ -121,7 +145,7 @@ public function link(string $username, string $host, array $databases): void foreach ($databases as $database) { $ssh->exec( - $this->getScript($this->getScriptsDir().'/link.sh', [ + view($this->getScriptView('link'), [ 'username' => $username, 'host' => $host, 'database' => $database, @@ -132,12 +156,15 @@ public function link(string $username, string $host, array $databases): void } } + /** + * @throws SSHError + */ public function unlink(string $username, string $host): void { $version = $this->service->version; $this->service->server->ssh()->exec( - $this->getScript($this->getScriptsDir().'/unlink.sh', [ + view($this->getScriptView('unlink'), [ 'username' => $username, 'host' => $host, 'version' => $version, @@ -146,11 +173,14 @@ public function unlink(string $username, string $host): void ); } + /** + * @throws SSHError + */ public function runBackup(BackupFile $backupFile): void { // backup $this->service->server->ssh()->exec( - $this->getScript($this->getScriptsDir().'/backup.sh', [ + view($this->getScriptView('backup'), [ 'file' => $backupFile->name, 'database' => $backupFile->backup->database->name, ]), @@ -170,6 +200,9 @@ public function runBackup(BackupFile $backupFile): void $backupFile->save(); } + /** + * @throws SSHError + */ public function restoreBackup(BackupFile $backupFile, string $database): void { // download @@ -179,7 +212,7 @@ public function restoreBackup(BackupFile $backupFile, string $database): void ); $this->service->server->ssh()->exec( - $this->getScript($this->getScriptsDir().'/restore.sh', [ + view($this->getScriptView('restore'), [ 'database' => $database, 'file' => rtrim($backupFile->tempPath(), '.zip'), ]), diff --git a/app/SSH/Services/Database/Mariadb.php b/app/SSH/Services/Database/Mariadb.php index 813478a..df1e33e 100644 --- a/app/SSH/Services/Database/Mariadb.php +++ b/app/SSH/Services/Database/Mariadb.php @@ -4,8 +4,5 @@ class Mariadb extends AbstractDatabase { - protected function getScriptsDir(): string - { - return 'mysql'; - } + // } diff --git a/app/SSH/Services/Database/Mysql.php b/app/SSH/Services/Database/Mysql.php index cca160e..21a685e 100755 --- a/app/SSH/Services/Database/Mysql.php +++ b/app/SSH/Services/Database/Mysql.php @@ -4,8 +4,5 @@ class Mysql extends AbstractDatabase { - protected function getScriptsDir(): string - { - return 'mysql'; - } + // } diff --git a/app/SSH/Services/Database/Postgresql.php b/app/SSH/Services/Database/Postgresql.php index 2a6916c..6388b41 100644 --- a/app/SSH/Services/Database/Postgresql.php +++ b/app/SSH/Services/Database/Postgresql.php @@ -2,26 +2,7 @@ namespace App\SSH\Services\Database; -use App\Exceptions\SSHError; - class Postgresql extends AbstractDatabase { - protected function getScriptsDir(): string - { - return 'postgresql'; - } - - /** - * @throws SSHError - */ - public function create(string $name): void - { - $this->service->server->ssh()->exec( - $this->getScript($this->getScriptsDir().'/create.sh', [ - 'name' => $name, - 'ssh_user' => $this->service->server->ssh_user, - ]), - 'create-database' - ); - } + // } diff --git a/app/SSH/Services/Database/scripts/mysql/backup.sh b/app/SSH/Services/Database/scripts/mysql/backup.sh deleted file mode 100644 index 33197f3..0000000 --- a/app/SSH/Services/Database/scripts/mysql/backup.sh +++ /dev/null @@ -1,11 +0,0 @@ -if ! sudo DEBIAN_FRONTEND=noninteractive mysqldump -u root __database__ > __file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! DEBIAN_FRONTEND=noninteractive zip __file__.zip __file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! rm __file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/Database/scripts/mysql/create.sh b/app/SSH/Services/Database/scripts/mysql/create.sh deleted file mode 100755 index a318617..0000000 --- a/app/SSH/Services/Database/scripts/mysql/create.sh +++ /dev/null @@ -1,5 +0,0 @@ -if ! sudo mysql -e "CREATE DATABASE IF NOT EXISTS __name__ CHARACTER SET utf8 COLLATE utf8_general_ci"; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "Command executed" diff --git a/app/SSH/Services/Database/scripts/mysql/link.sh b/app/SSH/Services/Database/scripts/mysql/link.sh deleted file mode 100755 index adbc74b..0000000 --- a/app/SSH/Services/Database/scripts/mysql/link.sh +++ /dev/null @@ -1,9 +0,0 @@ -if ! sudo mysql -e "GRANT ALL PRIVILEGES ON __database__.* TO '__username__'@'__host__'"; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo mysql -e "FLUSH PRIVILEGES"; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "Linking to __database__ finished" diff --git a/app/SSH/Services/Database/scripts/mysql/restore.sh b/app/SSH/Services/Database/scripts/mysql/restore.sh deleted file mode 100644 index d90826f..0000000 --- a/app/SSH/Services/Database/scripts/mysql/restore.sh +++ /dev/null @@ -1,11 +0,0 @@ -if ! DEBIAN_FRONTEND=noninteractive unzip __file__.zip; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo DEBIAN_FRONTEND=noninteractive mysql -u root __database__ < __file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! rm __file__.sql __file__.zip; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/Database/scripts/mysql/unlink.sh b/app/SSH/Services/Database/scripts/mysql/unlink.sh deleted file mode 100755 index f1ac881..0000000 --- a/app/SSH/Services/Database/scripts/mysql/unlink.sh +++ /dev/null @@ -1,5 +0,0 @@ -if ! sudo mysql -e "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '__username__'@'__host__'"; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "Command executed" diff --git a/app/SSH/Services/Database/scripts/postgresql/backup.sh b/app/SSH/Services/Database/scripts/postgresql/backup.sh deleted file mode 100644 index f1a75e7..0000000 --- a/app/SSH/Services/Database/scripts/postgresql/backup.sh +++ /dev/null @@ -1,19 +0,0 @@ -if ! sudo -u postgres pg_dump -d __database__ -f /var/lib/postgresql/__file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo mv /var/lib/postgresql/__file__.sql /home/vito/__file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo chown vito:vito /home/vito/__file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! DEBIAN_FRONTEND=noninteractive zip __file__.zip __file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! rm __file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/Database/scripts/postgresql/create-user.sh b/app/SSH/Services/Database/scripts/postgresql/create-user.sh deleted file mode 100755 index 2547722..0000000 --- a/app/SSH/Services/Database/scripts/postgresql/create-user.sh +++ /dev/null @@ -1,5 +0,0 @@ -if ! sudo -u postgres psql -c "CREATE ROLE \"__username__\" WITH LOGIN PASSWORD '__password__';"; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "User __username__ created" diff --git a/app/SSH/Services/Database/scripts/postgresql/create.sh b/app/SSH/Services/Database/scripts/postgresql/create.sh deleted file mode 100644 index dbb827a..0000000 --- a/app/SSH/Services/Database/scripts/postgresql/create.sh +++ /dev/null @@ -1,5 +0,0 @@ -if ! sudo -u postgres psql -c "CREATE DATABASE \"__name__\""; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "Database __name__ created" diff --git a/app/SSH/Services/Database/scripts/postgresql/delete-user.sh b/app/SSH/Services/Database/scripts/postgresql/delete-user.sh deleted file mode 100755 index b596699..0000000 --- a/app/SSH/Services/Database/scripts/postgresql/delete-user.sh +++ /dev/null @@ -1,5 +0,0 @@ -if ! sudo -u postgres psql -c "DROP USER \"__username__\""; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "User __username__ deleted" diff --git a/app/SSH/Services/Database/scripts/postgresql/delete.sh b/app/SSH/Services/Database/scripts/postgresql/delete.sh deleted file mode 100755 index ab71c13..0000000 --- a/app/SSH/Services/Database/scripts/postgresql/delete.sh +++ /dev/null @@ -1,5 +0,0 @@ -if ! sudo -u postgres psql -c "DROP DATABASE \"__name__\""; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "Database __name__ deleted" diff --git a/app/SSH/Services/Database/scripts/postgresql/restore.sh b/app/SSH/Services/Database/scripts/postgresql/restore.sh deleted file mode 100644 index eaa0896..0000000 --- a/app/SSH/Services/Database/scripts/postgresql/restore.sh +++ /dev/null @@ -1,11 +0,0 @@ -if ! DEBIAN_FRONTEND=noninteractive unzip __file__.zip; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo -u postgres psql -d __database__ -f __file__.sql; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! rm __file__.sql __file__.zip; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/Firewall/Ufw.php b/app/SSH/Services/Firewall/Ufw.php index 0e68d0c..46a8a1e 100755 --- a/app/SSH/Services/Firewall/Ufw.php +++ b/app/SSH/Services/Firewall/Ufw.php @@ -2,16 +2,17 @@ namespace App\SSH\Services\Firewall; -use App\SSH\HasScripts; +use App\Exceptions\SSHError; class Ufw extends AbstractFirewall { - use HasScripts; - + /** + * @throws SSHError + */ public function install(): void { $this->service->server->ssh()->exec( - $this->getScript('ufw/install-ufw.sh'), + view('ssh.services.firewall.ufw.install-ufw'), 'install-ufw' ); $this->service->server->os()->cleanup(); @@ -22,10 +23,13 @@ public function uninstall(): void // } + /** + * @throws SSHError + */ public function addRule(string $type, string $protocol, int $port, string $source, ?string $mask): void { $this->service->server->ssh()->exec( - $this->getScript('ufw/add-rule.sh', [ + view('ssh.services.firewall.ufw.add-rule', [ 'type' => $type, 'protocol' => $protocol, 'port' => $port, @@ -36,10 +40,13 @@ public function addRule(string $type, string $protocol, int $port, string $sourc ); } + /** + * @throws SSHError + */ public function removeRule(string $type, string $protocol, int $port, string $source, ?string $mask): void { $this->service->server->ssh()->exec( - $this->getScript('ufw/remove-rule.sh', [ + view('ssh.services.firewall.ufw.remove-rule', [ 'type' => $type, 'protocol' => $protocol, 'port' => $port, diff --git a/app/SSH/Services/Monitoring/VitoAgent/VitoAgent.php b/app/SSH/Services/Monitoring/VitoAgent/VitoAgent.php index d834d8a..2273acb 100644 --- a/app/SSH/Services/Monitoring/VitoAgent/VitoAgent.php +++ b/app/SSH/Services/Monitoring/VitoAgent/VitoAgent.php @@ -2,8 +2,9 @@ namespace App\SSH\Services\Monitoring\VitoAgent; +use App\Exceptions\ServiceInstallationFailed; +use App\Exceptions\SSHError; use App\Models\Metric; -use App\SSH\HasScripts; use App\SSH\Services\AbstractService; use Closure; use Illuminate\Support\Facades\Http; @@ -12,8 +13,6 @@ class VitoAgent extends AbstractService { - use HasScripts; - const TAGS_URL = 'https://api.github.com/repos/vitodeploy/agent/tags'; const DOWNLOAD_URL = 'https://github.com/vitodeploy/agent/releases/download/%s'; @@ -54,11 +53,15 @@ public function data(): array ]; } + /** + * @throws SSHError + * @throws ServiceInstallationFailed + */ public function install(): void { $tags = Http::get(self::TAGS_URL)->json(); if (empty($tags)) { - throw new \Exception('Failed to fetch tags'); + throw new ServiceInstallationFailed('Failed to fetch tags'); } $this->service->version = $tags[0]['name']; $this->service->save(); @@ -71,10 +74,10 @@ public function install(): void $this->service->refresh(); $this->service->server->ssh()->exec( - $this->getScript('install.sh', [ - 'download_url' => $downloadUrl, - 'config_url' => $this->data()['url'], - 'config_secret' => $this->data()['secret'], + view('ssh.services.monitoring.vito-agent.install', [ + 'downloadUrl' => $downloadUrl, + 'configUrl' => $this->data()['url'], + 'configSecret' => $this->data()['secret'], ]), 'install-vito-agent' ); @@ -82,12 +85,15 @@ public function install(): void $this->service->validateInstall($status); } + /** + * @throws SSHError + */ public function uninstall(): void { $this->service->server->ssh()->exec( - $this->getScript('uninstall.sh'), + view('ssh.services.monitoring.vito-agent.uninstall'), 'uninstall-vito-agent' ); - Metric::where('server_id', $this->service->server_id)->delete(); + Metric::query()->where('server_id', $this->service->server_id)->delete(); } } diff --git a/app/SSH/Services/NodeJS/NodeJS.php b/app/SSH/Services/NodeJS/NodeJS.php index 1413f6c..fcc488a 100644 --- a/app/SSH/Services/NodeJS/NodeJS.php +++ b/app/SSH/Services/NodeJS/NodeJS.php @@ -2,15 +2,13 @@ namespace App\SSH\Services\NodeJS; -use App\SSH\HasScripts; +use App\Exceptions\SSHError; use App\SSH\Services\AbstractService; use Closure; use Illuminate\Validation\Rule; class NodeJS extends AbstractService { - use HasScripts; - public function creationRules(array $input): array { return [ @@ -41,34 +39,43 @@ function (string $attribute, mixed $value, Closure $fail) { ]; } + /** + * @throws SSHError + */ public function install(): void { $server = $this->service->server; $server->ssh()->exec( - $this->getScript('install-nodejs.sh', [ + view('ssh.services.nodejs.install-nodejs', [ 'version' => $this->service->version, - 'user' => $server->getSshUser(), ]), 'install-nodejs-'.$this->service->version ); $this->service->server->os()->cleanup(); } + /** + * @throws SSHError + */ public function uninstall(): void { $this->service->server->ssh()->exec( - $this->getScript('uninstall-nodejs.sh', [ + view('ssh.services.nodejs.uninstall-nodejs', [ 'version' => $this->service->version, + 'default' => $this->service->is_default, ]), 'uninstall-nodejs-'.$this->service->version ); $this->service->server->os()->cleanup(); } + /** + * @throws SSHError + */ public function setDefaultCli(): void { $this->service->server->ssh()->exec( - $this->getScript('change-default-nodejs.sh', [ + view('ssh.services.nodejs.change-default-nodejs', [ 'version' => $this->service->version, ]), 'change-default-nodejs' diff --git a/app/SSH/Services/NodeJS/scripts/uninstall-nodejs.sh b/app/SSH/Services/NodeJS/scripts/uninstall-nodejs.sh deleted file mode 100755 index adbed0b..0000000 --- a/app/SSH/Services/NodeJS/scripts/uninstall-nodejs.sh +++ /dev/null @@ -1,6 +0,0 @@ -export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - -if ! nvm uninstall __version__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/PHP/PHP.php b/app/SSH/Services/PHP/PHP.php index b8baa81..2c71a4c 100644 --- a/app/SSH/Services/PHP/PHP.php +++ b/app/SSH/Services/PHP/PHP.php @@ -3,7 +3,7 @@ namespace App\SSH\Services\PHP; use App\Exceptions\SSHCommandError; -use App\SSH\HasScripts; +use App\Exceptions\SSHError; use App\SSH\Services\AbstractService; use Closure; use Illuminate\Support\Str; @@ -11,8 +11,6 @@ class PHP extends AbstractService { - use HasScripts; - public function creationRules(array $input): array { return [ @@ -43,11 +41,14 @@ function (string $attribute, mixed $value, Closure $fail) { ]; } + /** + * @throws SSHError + */ public function install(): void { $server = $this->service->server; $server->ssh()->exec( - $this->getScript('install-php.sh', [ + view('ssh.services.php.install-php', [ 'version' => $this->service->version, 'user' => $server->getSshUser(), ]), @@ -57,10 +58,13 @@ public function install(): void $this->service->server->os()->cleanup(); } + /** + * @throws SSHError + */ public function uninstall(): void { $this->service->server->ssh()->exec( - $this->getScript('uninstall-php.sh', [ + view('ssh.services.php.uninstall-php', [ 'version' => $this->service->version, ]), 'uninstall-php-'.$this->service->version @@ -68,10 +72,13 @@ public function uninstall(): void $this->service->server->os()->cleanup(); } + /** + * @throws SSHError + */ public function setDefaultCli(): void { $this->service->server->ssh()->exec( - $this->getScript('change-default-php.sh', [ + view('ssh.services.php.change-default-php', [ 'version' => $this->service->version, ]), 'change-default-php' @@ -79,12 +86,12 @@ public function setDefaultCli(): void } /** - * @throws SSHCommandError + * @throws SSHError */ public function installExtension($name): void { $result = $this->service->server->ssh()->exec( - $this->getScript('install-php-extension.sh', [ + view('ssh.services.php.install-php-extension', [ 'version' => $this->service->version, 'name' => $name, ]), @@ -96,14 +103,20 @@ public function installExtension($name): void } } + /** + * @throws SSHError + */ public function installComposer(): void { $this->service->server->ssh()->exec( - $this->getScript('install-composer.sh'), + view('ssh.services.php.install-composer'), 'install-composer' ); } + /** + * @throws SSHError + */ public function getPHPIni(string $type): string { return $this->service->server->os()->readFile( @@ -111,26 +124,30 @@ public function getPHPIni(string $type): string ); } + /** + * @throws SSHError + */ public function createFpmPool(string $user, string $version, $site_id): void { - $this->service->server->ssh()->exec( - $this->getScript('create-fpm-pool.sh', [ + $this->service->server->ssh()->write( + "/etc/php/{$version}/fpm/pool.d/{$user}.conf", + view('ssh.services.php.fpm-pool', [ 'user' => $user, 'version' => $version, - 'config' => $this->getScript('fpm-pool.conf', [ - 'user' => $user, - 'version' => $version, - ]), ]), - "create-{$version}fpm-pool-{$user}", - $site_id + true ); + + $this->service->server->systemd()->restart($this->service->unit); } + /** + * @throws SSHError + */ public function removeFpmPool(string $user, string $version, $site_id): void { $this->service->server->ssh()->exec( - $this->getScript('remove-fpm-pool.sh', [ + view('ssh.services.php.remove-fpm-pool', [ 'user' => $user, 'version' => $version, ]), diff --git a/app/SSH/Services/PHP/scripts/create-fpm-pool.sh b/app/SSH/Services/PHP/scripts/create-fpm-pool.sh deleted file mode 100644 index 4eaee89..0000000 --- a/app/SSH/Services/PHP/scripts/create-fpm-pool.sh +++ /dev/null @@ -1,2 +0,0 @@ -echo '__config__' | sudo tee /etc/php/__version__/fpm/pool.d/__user__.conf -sudo service php__version__-fpm restart diff --git a/app/SSH/Services/PHP/scripts/fpm-pool.conf b/app/SSH/Services/PHP/scripts/fpm-pool.conf deleted file mode 100644 index da34b87..0000000 --- a/app/SSH/Services/PHP/scripts/fpm-pool.conf +++ /dev/null @@ -1,22 +0,0 @@ -[__user__] -user = __user__ -group = __user__ - -listen = /run/php/php__version__-fpm-__user__.sock -listen.owner = vito -listen.group = vito -listen.mode = 0660 - -pm = dynamic -pm.max_children = 5 -pm.start_servers = 2 -pm.min_spare_servers = 1 -pm.max_spare_servers = 3 -pm.max_requests = 500 - -php_admin_value[open_basedir] = /home/__user__/:/tmp/ -php_admin_value[upload_tmp_dir] = /home/__user__/tmp -php_admin_value[session.save_path] = /home/__user__/tmp -php_admin_value[display_errors] = off -php_admin_value[log_errors] = on -php_admin_value[error_log] = /home/__user__/.logs/php_errors.log diff --git a/app/SSH/Services/PHP/scripts/install-php-extension.sh b/app/SSH/Services/PHP/scripts/install-php-extension.sh deleted file mode 100644 index 726ed97..0000000 --- a/app/SSH/Services/PHP/scripts/install-php-extension.sh +++ /dev/null @@ -1,5 +0,0 @@ -sudo apt-get install -y php__version__-__name__ - -sudo service php__version__-fpm restart - -php__version__ -m diff --git a/app/SSH/Services/PHP/scripts/install-php.sh b/app/SSH/Services/PHP/scripts/install-php.sh deleted file mode 100755 index 0d1053b..0000000 --- a/app/SSH/Services/PHP/scripts/install-php.sh +++ /dev/null @@ -1,15 +0,0 @@ -sudo add-apt-repository ppa:ondrej/php -y - -sudo DEBIAN_FRONTEND=noninteractive apt-get update - -if ! sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php__version__ php__version__-fpm php__version__-mbstring php__version__-mysql php__version__-gd php__version__-xml php__version__-curl php__version__-gettext php__version__-zip php__version__-bcmath php__version__-soap php__version__-redis php__version__-sqlite3 php__version__-tokenizer php__version__-pgsql php__version__-pdo; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo sed -i 's/www-data/__user__/g' /etc/php/__version__/fpm/pool.d/www.conf; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -sudo service php__version__-fpm enable - -sudo service php__version__-fpm start diff --git a/app/SSH/Services/PHP/scripts/remove-fpm-pool.sh b/app/SSH/Services/PHP/scripts/remove-fpm-pool.sh deleted file mode 100644 index 924f3b6..0000000 --- a/app/SSH/Services/PHP/scripts/remove-fpm-pool.sh +++ /dev/null @@ -1,2 +0,0 @@ -sudo rm -f /etc/php/__version__/fpm/pool.d/__user__.conf -sudo service php__version__-fpm restart diff --git a/app/SSH/Services/PHP/scripts/uninstall-php.sh b/app/SSH/Services/PHP/scripts/uninstall-php.sh deleted file mode 100755 index 6bb5bde..0000000 --- a/app/SSH/Services/PHP/scripts/uninstall-php.sh +++ /dev/null @@ -1,5 +0,0 @@ -sudo service php__version__-fpm stop - -if ! sudo DEBIAN_FRONTEND=noninteractive apt-get remove -y php__version__ php__version__-fpm php__version__-mbstring php__version__-mysql php__version__-mcrypt php__version__-gd php__version__-xml php__version__-curl php__version__-gettext php__version__-zip php__version__-bcmath php__version__-soap php__version__-redis php__version__-sqlite3; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/PHP/scripts/update-php-settings.sh b/app/SSH/Services/PHP/scripts/update-php-settings.sh deleted file mode 100644 index 5cb8585..0000000 --- a/app/SSH/Services/PHP/scripts/update-php-settings.sh +++ /dev/null @@ -1,11 +0,0 @@ -if ! sudo sed -i 's,^__variable__ =.*$,__variable__ = __value__,' /etc/php/__version__/cli/php.ini; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo sed -i 's,^__variable__ =.*$,__variable__ = __value__,' /etc/php/__version__/fpm/php.ini; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo service php__version__-fpm restart; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/ProcessManager/Supervisor.php b/app/SSH/Services/ProcessManager/Supervisor.php index 04dcf6e..c2d81d2 100644 --- a/app/SSH/Services/ProcessManager/Supervisor.php +++ b/app/SSH/Services/ProcessManager/Supervisor.php @@ -2,33 +2,37 @@ namespace App\SSH\Services\ProcessManager; -use App\SSH\HasScripts; +use App\Exceptions\SSHError; use Throwable; class Supervisor extends AbstractProcessManager { - use HasScripts; - + /** + * @throws SSHError + */ public function install(): void { $this->service->server->ssh()->exec( - $this->getScript('supervisor/install-supervisor.sh'), + view('ssh.services.process-manager.supervisor.install-supervisor'), 'install-supervisor' ); $this->service->server->os()->cleanup(); } + /** + * @throws SSHError + */ public function uninstall(): void { $this->service->server->ssh()->exec( - $this->getScript('supervisor/uninstall-supervisor.sh'), + view('ssh.services.process-manager.supervisor.uninstall-supervisor'), 'uninstall-supervisor' ); $this->service->server->os()->cleanup(); } /** - * @throws Throwable + * @throws SSHError */ public function create( int $id, @@ -42,21 +46,22 @@ public function create( ): void { $this->service->server->ssh()->write( "/etc/supervisor/conf.d/$id.conf", - $this->generateConfigFile( - $id, - $command, - $user, - $autoStart, - $autoRestart, - $numprocs, - $logFile - ), + view('ssh.services.process-manager.supervisor.worker', [ + 'name' => (string) $id, + 'command' => $command, + 'user' => $user, + 'autoStart' => var_export($autoStart, true), + 'autoRestart' => var_export($autoRestart, true), + 'numprocs' => (string) $numprocs, + 'logFile' => $logFile, + ]), true ); + $this->service->server->ssh()->exec( - $this->getScript('supervisor/create-worker.sh', [ + view('ssh.services.process-manager.supervisor.create-worker', [ 'id' => $id, - 'log_file' => $logFile, + 'logFile' => $logFile, 'user' => $user, ]), 'create-worker', @@ -70,7 +75,7 @@ public function create( public function delete(int $id, ?int $siteId = null): void { $this->service->server->ssh()->exec( - $this->getScript('supervisor/delete-worker.sh', [ + view('ssh.services.process-manager.supervisor.delete-worker', [ 'id' => $id, ]), 'delete-worker', @@ -84,7 +89,7 @@ public function delete(int $id, ?int $siteId = null): void public function restart(int $id, ?int $siteId = null): void { $this->service->server->ssh()->exec( - $this->getScript('supervisor/restart-worker.sh', [ + view('ssh.services.process-manager.supervisor.restart-worker', [ 'id' => $id, ]), 'restart-worker', @@ -98,7 +103,7 @@ public function restart(int $id, ?int $siteId = null): void public function stop(int $id, ?int $siteId = null): void { $this->service->server->ssh()->exec( - $this->getScript('supervisor/stop-worker.sh', [ + view('ssh.services.process-manager.supervisor.stop-worker', [ 'id' => $id, ]), 'stop-worker', @@ -112,7 +117,7 @@ public function stop(int $id, ?int $siteId = null): void public function start(int $id, ?int $siteId = null): void { $this->service->server->ssh()->exec( - $this->getScript('supervisor/start-worker.sh', [ + view('ssh.services.process-manager.supervisor.start-worker', [ 'id' => $id, ]), 'start-worker', @@ -129,24 +134,4 @@ public function getLogs(string $user, string $logPath): string "tail -100 $logPath" ); } - - private function generateConfigFile( - int $id, - string $command, - string $user, - bool $autoStart, - bool $autoRestart, - int $numprocs, - string $logFile - ): string { - return $this->getScript('supervisor/worker.conf', [ - 'name' => (string) $id, - 'command' => $command, - 'user' => $user, - 'auto_start' => var_export($autoStart, true), - 'auto_restart' => var_export($autoRestart, true), - 'numprocs' => (string) $numprocs, - 'log_file' => $logFile, - ]); - } } diff --git a/app/SSH/Services/ProcessManager/scripts/supervisor/restart-worker.sh b/app/SSH/Services/ProcessManager/scripts/supervisor/restart-worker.sh deleted file mode 100644 index ad31160..0000000 --- a/app/SSH/Services/ProcessManager/scripts/supervisor/restart-worker.sh +++ /dev/null @@ -1,3 +0,0 @@ -if ! sudo supervisorctl restart __id__:*; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/ProcessManager/scripts/supervisor/start-worker.sh b/app/SSH/Services/ProcessManager/scripts/supervisor/start-worker.sh deleted file mode 100644 index d4e6cbc..0000000 --- a/app/SSH/Services/ProcessManager/scripts/supervisor/start-worker.sh +++ /dev/null @@ -1,3 +0,0 @@ -if ! sudo supervisorctl start __id__:*; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/ProcessManager/scripts/supervisor/stop-worker.sh b/app/SSH/Services/ProcessManager/scripts/supervisor/stop-worker.sh deleted file mode 100644 index 5fa8bfa..0000000 --- a/app/SSH/Services/ProcessManager/scripts/supervisor/stop-worker.sh +++ /dev/null @@ -1,3 +0,0 @@ -if ! sudo supervisorctl stop __id__:*; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/ProcessManager/scripts/supervisor/worker.conf b/app/SSH/Services/ProcessManager/scripts/supervisor/worker.conf deleted file mode 100644 index c21ece5..0000000 --- a/app/SSH/Services/ProcessManager/scripts/supervisor/worker.conf +++ /dev/null @@ -1,10 +0,0 @@ -[program:__name__] -process_name=%(program_name)s_%(process_num)02d -command=__command__ -autostart=__auto_start__ -autorestart=__auto_restart__ -user=__user__ -numprocs=__numprocs__ -redirect_stderr=true -stdout_logfile=__log_file__ -stopwaitsecs=3600 diff --git a/app/SSH/Services/Redis/Redis.php b/app/SSH/Services/Redis/Redis.php index 552f219..779f762 100644 --- a/app/SSH/Services/Redis/Redis.php +++ b/app/SSH/Services/Redis/Redis.php @@ -2,14 +2,13 @@ namespace App\SSH\Services\Redis; -use App\SSH\HasScripts; +use App\Exceptions\ServiceInstallationFailed; +use App\Exceptions\SSHError; use App\SSH\Services\AbstractService; use Closure; class Redis extends AbstractService { - use HasScripts; - public function creationRules(array $input): array { return [ @@ -25,10 +24,14 @@ function (string $attribute, mixed $value, Closure $fail) { ]; } + /** + * @throws ServiceInstallationFailed + * @throws SSHError + */ public function install(): void { $this->service->server->ssh()->exec( - $this->getScript('install.sh'), + view('ssh.services.redis.install'), 'install-redis' ); $status = $this->service->server->systemd()->status($this->service->unit); @@ -36,10 +39,13 @@ public function install(): void $this->service->server->os()->cleanup(); } + /** + * @throws SSHError + */ public function uninstall(): void { $this->service->server->ssh()->exec( - $this->getScript('uninstall.sh'), + view('ssh.services.redis.uninstall'), 'uninstall-redis' ); $this->service->server->os()->cleanup(); diff --git a/app/SSH/Services/Webserver/Nginx.php b/app/SSH/Services/Webserver/Nginx.php index 63463c6..3b08356 100755 --- a/app/SSH/Services/Webserver/Nginx.php +++ b/app/SSH/Services/Webserver/Nginx.php @@ -6,25 +6,31 @@ use App\Exceptions\SSLCreationException; use App\Models\Site; use App\Models\Ssl; -use App\SSH\HasScripts; use Closure; -use Illuminate\Support\Str; use Throwable; class Nginx extends AbstractWebserver { - use HasScripts; - + /** + * @throws SSHError + */ public function install(): void { $this->service->server->ssh()->exec( - $this->getScript('nginx/install-nginx.sh', [ - 'config' => $this->getScript('nginx/nginx.conf', [ - 'user' => $this->service->server->getSshUser(), - ]), - ]), + view('ssh.services.webserver.nginx.install-nginx'), 'install-nginx' ); + + $this->service->server->ssh()->write( + '/etc/nginx/nginx.conf', + view('ssh.services.webserver.nginx.nginx', [ + 'user' => $this->service->server->getSshUser(), + ]), + true + ); + + $this->service->server->systemd()->restart('nginx'); + $this->service->server->os()->cleanup(); } @@ -43,10 +49,13 @@ function (string $attribute, mixed $value, Closure $fail) { ]; } + /** + * @throws SSHError + */ public function uninstall(): void { $this->service->server->ssh()->exec( - $this->getScript('nginx/uninstall-nginx.sh'), + view('ssh.services.webserver.nginx.uninstall-nginx'), 'uninstall-nginx' ); $this->service->server->os()->cleanup(); @@ -62,50 +71,68 @@ public function createVHost(Site $site): void $ssh = $this->service->server->ssh($site->user); $ssh->exec( - $this->getScript('nginx/create-path.sh', [ + view('ssh.services.webserver.nginx.create-path', [ 'path' => $site->path, ]), 'create-path', $site->id ); + $this->service->server->ssh()->write( + '/etc/nginx/sites-available/'.$site->domain, + view('ssh.services.webserver.nginx.vhost', [ + 'site' => $site, + ]), + true + ); + $this->service->server->ssh()->exec( - $this->getScript('nginx/create-vhost.sh', [ + view('ssh.services.webserver.nginx.create-vhost', [ 'domain' => $site->domain, - 'path' => $site->path, - 'vhost' => $this->generateVhost($site), + 'vhost' => view('ssh.services.webserver.nginx.vhost', [ + 'site' => $site, + ]), ]), 'create-vhost', $site->id ); } - public function updateVHost(Site $site, bool $noSSL = false, ?string $vhost = null): void + /** + * @throws SSHError + */ + public function updateVHost(Site $site, ?string $vhost = null): void { - $this->service->server->ssh()->exec( - $this->getScript('nginx/update-vhost.sh', [ - 'domain' => $site->domain, - 'path' => $site->path, - 'vhost' => $vhost ?? $this->generateVhost($site, $noSSL), + $this->service->server->ssh()->write( + '/etc/nginx/sites-available/'.$site->domain, + $vhost ?? view('ssh.services.webserver.nginx.vhost', [ + 'site' => $site, ]), - 'update-vhost', - $site->id + true ); + + $this->service->server->systemd()->restart('nginx'); } + /** + * @throws SSHError + */ public function getVHost(Site $site): string { return $this->service->server->ssh()->exec( - $this->getScript('nginx/get-vhost.sh', [ + view('ssh.services.webserver.nginx.get-vhost', [ 'domain' => $site->domain, ]), ); } + /** + * @throws SSHError + */ public function deleteSite(Site $site): void { $this->service->server->ssh()->exec( - $this->getScript('nginx/delete-site.sh', [ + view('ssh.services.webserver.nginx.delete-site', [ 'domain' => $site->domain, 'path' => $site->path, ]), @@ -115,13 +142,16 @@ public function deleteSite(Site $site): void $this->service->restart(); } + /** + * @throws SSHError + */ public function changePHPVersion(Site $site, $version): void { $this->service->server->ssh()->exec( - $this->getScript('nginx/change-php-version.sh', [ + view('ssh.services.webserver.nginx.change-php-version', [ 'domain' => $site->domain, - 'old_version' => $site->php_version, - 'new_version' => $version, + 'oldVersion' => $site->php_version, + 'newVersion' => $version, ]), 'change-php-version', $site->id @@ -137,19 +167,18 @@ public function setupSSL(Ssl $ssl): void foreach ($ssl->getDomains() as $domain) { $domains .= ' -d '.$domain; } - $command = $this->getScript('nginx/create-letsencrypt-ssl.sh', [ + $command = view('ssh.services.webserver.nginx.create-letsencrypt-ssl', [ 'email' => $ssl->site->server->creator->email, 'domain' => $ssl->site->domain, 'domains' => $domains, - 'web_directory' => $ssl->site->getWebDirectoryPath(), ]); if ($ssl->type == 'custom') { - $command = $this->getScript('nginx/create-custom-ssl.sh', [ + $command = view('ssh.services.webserver.nginx.create-custom-ssl', [ 'path' => $ssl->getCertsDirectoryPath(), 'certificate' => $ssl->certificate, 'pk' => $ssl->pk, - 'certificate_path' => $ssl->getCertificatePath(), - 'pk_path' => $ssl->getPkPath(), + 'certificatePath' => $ssl->getCertificatePath(), + 'pkPath' => $ssl->getPkPath(), ]); } $result = $this->service->server->ssh()->setLog($ssl->log)->exec( @@ -160,8 +189,6 @@ public function setupSSL(Ssl $ssl): void if (! $ssl->validateSetup($result)) { throw new SSLCreationException; } - - $this->updateVHost($ssl->site); } /** @@ -175,55 +202,6 @@ public function removeSSL(Ssl $ssl): void $ssl->site_id ); - $this->updateVHost($ssl->site, true); - - $this->service->server->systemd()->restart('nginx'); - } - - protected function generateVhost(Site $site, bool $noSSL = false): string - { - $ssl = $site->activeSsl; - if ($noSSL) { - $ssl = null; - } - $vhost = $this->getScript('nginx/vhost.conf'); - if ($ssl) { - $vhost = $this->getScript('nginx/vhost-ssl.conf'); - } - if ($site->type()->language() === 'php') { - $vhost = $this->getScript('nginx/php-vhost.conf'); - if ($ssl) { - $vhost = $this->getScript('nginx/php-vhost-ssl.conf'); - } - } - if ($site->port) { - $vhost = $this->getScript('nginx/reverse-vhost.conf'); - if ($ssl) { - $vhost = $this->getScript('nginx/reverse-vhost-ssl.conf'); - } - $vhost = Str::replace('__port__', (string) $site->port, $vhost); - } - - $php_socket = 'unix:/var/run/php/php-fpm.sock'; - if ($site->isIsolated()) { - $php_socket = "unix:/run/php/php{$site->php_version}-fpm-{$site->user}.sock"; - } - - $vhost = Str::replace('__domain__', $site->domain, $vhost); - $vhost = Str::replace('__aliases__', $site->getAliasesString(), $vhost); - $vhost = Str::replace('__path__', $site->path, $vhost); - $vhost = Str::replace('__web_directory__', $site->web_directory, $vhost); - $vhost = Str::replace('__php_socket__', $php_socket, $vhost); - - if ($ssl) { - $vhost = Str::replace('__certificate__', $ssl->getCertificatePath(), $vhost); - $vhost = Str::replace('__private_key__', $ssl->getPkPath(), $vhost); - } - - if ($site->php_version) { - $vhost = Str::replace('__php_version__', $site->php_version, $vhost); - } - - return $vhost; + $this->updateVHost($ssl->site); } } diff --git a/app/SSH/Services/Webserver/Webserver.php b/app/SSH/Services/Webserver/Webserver.php index 4137d32..f8dee75 100755 --- a/app/SSH/Services/Webserver/Webserver.php +++ b/app/SSH/Services/Webserver/Webserver.php @@ -9,7 +9,7 @@ interface Webserver { public function createVHost(Site $site): void; - public function updateVHost(Site $site, bool $noSSL = false, ?string $vhost = null): void; + public function updateVHost(Site $site, ?string $vhost = null): void; public function getVHost(Site $site): string; diff --git a/app/SSH/Services/Webserver/scripts/nginx/change-php-version.sh b/app/SSH/Services/Webserver/scripts/nginx/change-php-version.sh deleted file mode 100755 index c5e0a91..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/change-php-version.sh +++ /dev/null @@ -1,9 +0,0 @@ -if ! sudo sed -i 's/php__old_version__/php__new_version__/g' /etc/nginx/sites-available/__domain__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo service nginx restart; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -echo "PHP Version Changed to __new_version__" diff --git a/app/SSH/Services/Webserver/scripts/nginx/create-path.sh b/app/SSH/Services/Webserver/scripts/nginx/create-path.sh deleted file mode 100644 index aa9dd18..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/create-path.sh +++ /dev/null @@ -1,16 +0,0 @@ -export DEBIAN_FRONTEND=noninteractive - -if ! rm -rf __path__; then - echo 'VITO_SSH_ERROR' - exit 1 -fi - -if ! mkdir __path__; then - echo 'VITO_SSH_ERROR' - exit 1 -fi - -if ! chmod -R 755 __path__; then - echo 'VITO_SSH_ERROR' - exit 1 -fi diff --git a/app/SSH/Services/Webserver/scripts/nginx/create-vhost.sh b/app/SSH/Services/Webserver/scripts/nginx/create-vhost.sh deleted file mode 100755 index b7f44df..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/create-vhost.sh +++ /dev/null @@ -1,15 +0,0 @@ -if ! echo '' | sudo tee /etc/nginx/conf.d/__domain___redirects; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! echo '__vhost__' | sudo tee /etc/nginx/sites-available/__domain__; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo ln -s /etc/nginx/sites-available/__domain__ /etc/nginx/sites-enabled/; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! sudo service nginx restart; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/SSH/Services/Webserver/scripts/nginx/delete-site.sh b/app/SSH/Services/Webserver/scripts/nginx/delete-site.sh deleted file mode 100755 index 51adfbf..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/delete-site.sh +++ /dev/null @@ -1,7 +0,0 @@ -rm -rf __path__ - -sudo rm /etc/nginx/sites-available/__domain__ - -sudo rm /etc/nginx/sites-enabled/__domain__ - -echo "Site deleted" diff --git a/app/SSH/Services/Webserver/scripts/nginx/get-vhost.sh b/app/SSH/Services/Webserver/scripts/nginx/get-vhost.sh deleted file mode 100755 index 8cd571f..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/get-vhost.sh +++ /dev/null @@ -1 +0,0 @@ -cat /etc/nginx/sites-available/__domain__ diff --git a/app/SSH/Services/Webserver/scripts/nginx/php-vhost-ssl.conf b/app/SSH/Services/Webserver/scripts/nginx/php-vhost-ssl.conf deleted file mode 100755 index 596bd81..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/php-vhost-ssl.conf +++ /dev/null @@ -1,38 +0,0 @@ -server { - listen 80; - listen 443 ssl; - server_name __domain__ __aliases__; - root __path__/__web_directory__; - - ssl_certificate __certificate__; - ssl_certificate_key __private_key__; - - add_header X-Frame-Options "SAMEORIGIN"; - add_header X-Content-Type-Options "nosniff"; - - index index.php; - - charset utf-8; - - location / { - try_files $uri $uri/ /index.php?$query_string; - } - - location = /favicon.ico { access_log off; log_not_found off; } - location = /robots.txt { access_log off; log_not_found off; } - - error_page 404 /index.php; - - location ~ \.php$ { - fastcgi_pass __php_socket__; - fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; - include fastcgi_params; - fastcgi_hide_header X-Powered-By; - } - - location ~ /\.(?!well-known).* { - deny all; - } - - include conf.d/__domain___redirects; -} diff --git a/app/SSH/Services/Webserver/scripts/nginx/php-vhost.conf b/app/SSH/Services/Webserver/scripts/nginx/php-vhost.conf deleted file mode 100755 index 80f33e5..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/php-vhost.conf +++ /dev/null @@ -1,34 +0,0 @@ -server { - listen 80; - server_name __domain__ __aliases__; - root __path__/__web_directory__; - - add_header X-Frame-Options "SAMEORIGIN"; - add_header X-Content-Type-Options "nosniff"; - - index index.php; - - charset utf-8; - - location / { - try_files $uri $uri/ /index.php?$query_string; - } - - location = /favicon.ico { access_log off; log_not_found off; } - location = /robots.txt { access_log off; log_not_found off; } - - error_page 404 /index.php; - - location ~ \.php$ { - fastcgi_pass __php_socket__; - fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; - include fastcgi_params; - fastcgi_hide_header X-Powered-By; - } - - location ~ /\.(?!well-known).* { - deny all; - } - - include conf.d/__domain___redirects; -} diff --git a/app/SSH/Services/Webserver/scripts/nginx/redirect.conf b/app/SSH/Services/Webserver/scripts/nginx/redirect.conf deleted file mode 100644 index bd4f246..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/redirect.conf +++ /dev/null @@ -1,3 +0,0 @@ -location __from__ { - return __mode__ __to__; -} diff --git a/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost-ssl.conf b/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost-ssl.conf deleted file mode 100755 index 070bdd4..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost-ssl.conf +++ /dev/null @@ -1,35 +0,0 @@ -server { - listen 80; - listen 443 ssl; - server_name __domain__ __aliases__; - root __path__; - - ssl_certificate __certificate__; - ssl_certificate_key __private_key__; - - add_header X-Frame-Options "SAMEORIGIN"; - add_header X-Content-Type-Options "nosniff"; - - index index.php; - - charset utf-8; - - location / { - proxy_pass http://127.0.0.1:__port__/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header X-Forwarded-For $remote_addr; - } - - location = /favicon.ico { access_log off; log_not_found off; } - location = /robots.txt { access_log off; log_not_found off; } - - error_page 404 /index.php; - - location ~ /\.(?!well-known).* { - deny all; - } - - include conf.d/__domain___redirects; -} diff --git a/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost.conf b/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost.conf deleted file mode 100755 index e31a3ae..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost.conf +++ /dev/null @@ -1,31 +0,0 @@ -server { - listen 80; - server_name __domain__ __aliases__; - root __path__; - - add_header X-Frame-Options "SAMEORIGIN"; - add_header X-Content-Type-Options "nosniff"; - - index index.php; - - charset utf-8; - - location / { - proxy_pass http://127.0.0.1:__port__/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header X-Forwarded-For $remote_addr; - } - - location = /favicon.ico { access_log off; log_not_found off; } - location = /robots.txt { access_log off; log_not_found off; } - - error_page 404 /index.php; - - location ~ /\.(?!well-known).* { - deny all; - } - - include conf.d/__domain___redirects; -} diff --git a/app/SSH/Services/Webserver/scripts/nginx/update-vhost.sh b/app/SSH/Services/Webserver/scripts/nginx/update-vhost.sh deleted file mode 100755 index 3bf6094..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/update-vhost.sh +++ /dev/null @@ -1,3 +0,0 @@ -echo '__vhost__' | sudo tee /etc/nginx/sites-available/__domain__ - -sudo service nginx restart diff --git a/app/SSH/Services/Webserver/scripts/nginx/vhost-ssl.conf b/app/SSH/Services/Webserver/scripts/nginx/vhost-ssl.conf deleted file mode 100755 index 1cf8334..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/vhost-ssl.conf +++ /dev/null @@ -1,31 +0,0 @@ -server { - listen 80; - listen 443 ssl; - server_name __domain__ __aliases__; - root __path__/__web_directory__; - - ssl_certificate __certificate__; - ssl_certificate_key __private_key__; - - add_header X-Frame-Options "SAMEORIGIN"; - add_header X-Content-Type-Options "nosniff"; - - index index.html; - - charset utf-8; - - location / { - try_files $uri $uri/ /index.html; - } - - location = /favicon.ico { access_log off; log_not_found off; } - location = /robots.txt { access_log off; log_not_found off; } - - error_page 404 /index.html; - - location ~ /\.(?!well-known).* { - deny all; - } - - include conf.d/__domain___redirects; -} diff --git a/app/SSH/Services/Webserver/scripts/nginx/vhost.conf b/app/SSH/Services/Webserver/scripts/nginx/vhost.conf deleted file mode 100755 index 631e3c6..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/vhost.conf +++ /dev/null @@ -1,27 +0,0 @@ -server { - listen 80; - server_name __domain__ __aliases__; - root __path__/__web_directory__; - - add_header X-Frame-Options "SAMEORIGIN"; - add_header X-Content-Type-Options "nosniff"; - - index index.html; - - charset utf-8; - - location / { - try_files $uri $uri/ /index.html; - } - - location = /favicon.ico { access_log off; log_not_found off; } - location = /robots.txt { access_log off; log_not_found off; } - - error_page 404 /index.html; - - location ~ /\.(?!well-known).* { - deny all; - } - - include conf.d/__domain___redirects; -} diff --git a/app/SSH/Storage/Dropbox.php b/app/SSH/Storage/Dropbox.php index 5ea570d..4aba989 100644 --- a/app/SSH/Storage/Dropbox.php +++ b/app/SSH/Storage/Dropbox.php @@ -3,17 +3,18 @@ namespace App\SSH\Storage; use App\Exceptions\SSHCommandError; -use App\SSH\HasScripts; +use App\Exceptions\SSHError; use Illuminate\Support\Facades\Log; class Dropbox extends AbstractStorage { - use HasScripts; - + /** + * @throws SSHError + */ public function upload(string $src, string $dest): array { $upload = $this->server->ssh()->exec( - $this->getScript('dropbox/upload.sh', [ + view('ssh.storage.dropbox.upload', [ 'src' => $src, 'dest' => $dest, 'token' => $this->storageProvider->credentials['token'], @@ -33,10 +34,13 @@ public function upload(string $src, string $dest): array ]; } + /** + * @throws SSHError + */ public function download(string $src, string $dest): void { $this->server->ssh()->exec( - $this->getScript('dropbox/download.sh', [ + view('ssh.storage.dropbox.download', [ 'src' => $src, 'dest' => $dest, 'token' => $this->storageProvider->credentials['token'], @@ -45,10 +49,13 @@ public function download(string $src, string $dest): void ); } + /** + * @throws SSHError + */ public function delete(string $src): void { $this->server->ssh()->exec( - $this->getScript('dropbox/delete-file.sh', [ + view('ssh.storage.dropbox.delete-file', [ 'src' => $src, 'token' => $this->storageProvider->credentials['token'], ]), diff --git a/app/SSH/Storage/FTP.php b/app/SSH/Storage/FTP.php index c988b03..4c2091c 100644 --- a/app/SSH/Storage/FTP.php +++ b/app/SSH/Storage/FTP.php @@ -2,16 +2,17 @@ namespace App\SSH\Storage; -use App\SSH\HasScripts; +use App\Exceptions\SSHError; class FTP extends AbstractStorage { - use HasScripts; - + /** + * @throws SSHError + */ public function upload(string $src, string $dest): array { $this->server->ssh()->exec( - $this->getScript('ftp/upload.sh', [ + view('ssh.storage.ftp.upload', [ 'src' => $src, 'dest' => $dest, 'host' => $this->storageProvider->credentials['host'], @@ -29,10 +30,13 @@ public function upload(string $src, string $dest): array ]; } + /** + * @throws SSHError + */ public function download(string $src, string $dest): void { $this->server->ssh()->exec( - $this->getScript('ftp/download.sh', [ + view('ssh.storage.ftp.download', [ 'src' => $src, 'dest' => $dest, 'host' => $this->storageProvider->credentials['host'], @@ -46,10 +50,13 @@ public function download(string $src, string $dest): void ); } + /** + * @throws SSHError + */ public function delete(string $src): void { $this->server->ssh()->exec( - $this->getScript('ftp/delete-file.sh', [ + view('ssh.storage.ftp.delete-file', [ 'src' => $src, 'host' => $this->storageProvider->credentials['host'], 'port' => $this->storageProvider->credentials['port'], diff --git a/app/SSH/Storage/Local.php b/app/SSH/Storage/Local.php index 50c9d8a..2b91779 100644 --- a/app/SSH/Storage/Local.php +++ b/app/SSH/Storage/Local.php @@ -2,20 +2,21 @@ namespace App\SSH\Storage; -use App\SSH\HasScripts; +use App\Exceptions\SSHError; class Local extends AbstractStorage { - use HasScripts; - + /** + * @throws SSHError + */ public function upload(string $src, string $dest): array { $destDir = dirname($dest); $this->server->ssh()->exec( - $this->getScript('local/upload.sh', [ + view('ssh.storage.local.upload', [ 'src' => $src, - 'dest_dir' => $destDir, - 'dest_file' => $dest, + 'destDir' => $destDir, + 'destFile' => $dest, ]), 'upload-to-local' ); @@ -25,10 +26,13 @@ public function upload(string $src, string $dest): array ]; } + /** + * @throws SSHError + */ public function download(string $src, string $dest): void { $this->server->ssh()->exec( - $this->getScript('local/download.sh', [ + view('ssh.storage.local.download', [ 'src' => $src, 'dest' => $dest, ]), @@ -36,6 +40,9 @@ public function download(string $src, string $dest): void ); } + /** + * @throws SSHError + */ public function delete(string $src): void { $this->server->os()->deleteFile($src); diff --git a/app/SSH/Storage/S3.php b/app/SSH/Storage/S3.php index 547258c..c3d4e2c 100644 --- a/app/SSH/Storage/S3.php +++ b/app/SSH/Storage/S3.php @@ -5,12 +5,11 @@ use App\Exceptions\SSHCommandError; use App\Exceptions\SSHError; use App\SSH\HasS3Storage; -use App\SSH\HasScripts; use Illuminate\Support\Facades\Log; class S3 extends AbstractStorage { - use HasS3Storage, HasScripts; + use HasS3Storage; /** * @throws SSHError @@ -20,7 +19,7 @@ public function upload(string $src, string $dest): array /** @var \App\StorageProviders\S3 $provider */ $provider = $this->storageProvider->provider(); - $uploadCommand = $this->getScript('s3/upload.sh', [ + $uploadCommand = view('ssh.storage.s3.upload', [ 'src' => $src, 'bucket' => $this->storageProvider->credentials['bucket'], 'dest' => $this->prepareS3Path($dest), @@ -40,7 +39,6 @@ public function upload(string $src, string $dest): array return [ 'size' => null, // You can parse the size from the output if needed ]; - } /** @@ -51,7 +49,7 @@ public function download(string $src, string $dest): void /** @var \App\StorageProviders\S3 $provider */ $provider = $this->storageProvider->provider(); - $downloadCommand = $this->getScript('s3/download.sh', [ + $downloadCommand = view('ssh.storage.s3.download', [ 'src' => $this->prepareS3Path($src), 'dest' => $dest, 'bucket' => $this->storageProvider->credentials['bucket'], @@ -71,13 +69,16 @@ public function download(string $src, string $dest): void } } + /** + * @throws SSHError + */ public function delete(string $src): void { /** @var \App\StorageProviders\S3 $provider */ $provider = $this->storageProvider->provider(); $this->server->ssh()->exec( - $this->getScript('s3/delete-file.sh', [ + view('ssh.storage.s3.delete-file', [ 'src' => $this->prepareS3Path($src), 'bucket' => $this->storageProvider->credentials['bucket'], 'key' => $this->storageProvider->credentials['key'], diff --git a/app/SSH/Storage/scripts/dropbox/download.sh b/app/SSH/Storage/scripts/dropbox/download.sh deleted file mode 100644 index eafa63d..0000000 --- a/app/SSH/Storage/scripts/dropbox/download.sh +++ /dev/null @@ -1,4 +0,0 @@ -curl -o __dest__ --location --request POST 'https://content.dropboxapi.com/2/files/download' \ ---header 'Accept: application/json' \ ---header 'Dropbox-API-Arg: {"path":"__src__"}' \ ---header 'Authorization: Bearer __token__' diff --git a/app/SSH/Storage/scripts/ftp/delete-file.sh b/app/SSH/Storage/scripts/ftp/delete-file.sh deleted file mode 100644 index c756e83..0000000 --- a/app/SSH/Storage/scripts/ftp/delete-file.sh +++ /dev/null @@ -1 +0,0 @@ -curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -Q "DELE /__src__" diff --git a/app/SSH/Storage/scripts/ftp/download.sh b/app/SSH/Storage/scripts/ftp/download.sh deleted file mode 100644 index 2bf591b..0000000 --- a/app/SSH/Storage/scripts/ftp/download.sh +++ /dev/null @@ -1 +0,0 @@ -curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -o "__dest__" diff --git a/app/SSH/Storage/scripts/ftp/upload.sh b/app/SSH/Storage/scripts/ftp/upload.sh deleted file mode 100644 index d26d5de..0000000 --- a/app/SSH/Storage/scripts/ftp/upload.sh +++ /dev/null @@ -1 +0,0 @@ -curl __passive__ -T "__src__" -u "__username__:__password__" ftp__ssl__://__host__:__port__/__dest__ diff --git a/app/SSH/Storage/scripts/local/download.sh b/app/SSH/Storage/scripts/local/download.sh deleted file mode 100644 index e3b5b34..0000000 --- a/app/SSH/Storage/scripts/local/download.sh +++ /dev/null @@ -1 +0,0 @@ -cp __src__ __dest__ diff --git a/app/SSH/Storage/scripts/local/upload.sh b/app/SSH/Storage/scripts/local/upload.sh deleted file mode 100644 index 34d885f..0000000 --- a/app/SSH/Storage/scripts/local/upload.sh +++ /dev/null @@ -1,2 +0,0 @@ -mkdir -p __dest_dir__ -cp __src__ __dest_file__ diff --git a/app/SSH/Systemd/Systemd.php b/app/SSH/Systemd/Systemd.php index 13c3c39..fcab26e 100644 --- a/app/SSH/Systemd/Systemd.php +++ b/app/SSH/Systemd/Systemd.php @@ -2,12 +2,16 @@ namespace App\SSH\Systemd; +use App\Exceptions\SSHError; use App\Models\Server; class Systemd { public function __construct(protected Server $server) {} + /** + * @throws SSHError + */ public function status(string $unit): string { $command = <<<EOD @@ -17,6 +21,9 @@ public function status(string $unit): string return $this->server->ssh()->exec($command, sprintf('status-%s', $unit)); } + /** + * @throws SSHError + */ public function start(string $unit): string { $command = <<<EOD @@ -27,6 +34,9 @@ public function start(string $unit): string return $this->server->ssh()->exec($command, sprintf('start-%s', $unit)); } + /** + * @throws SSHError + */ public function stop(string $unit): string { $command = <<<EOD @@ -37,6 +47,9 @@ public function stop(string $unit): string return $this->server->ssh()->exec($command, sprintf('stop-%s', $unit)); } + /** + * @throws SSHError + */ public function restart(string $unit): string { $command = <<<EOD @@ -47,6 +60,9 @@ public function restart(string $unit): string return $this->server->ssh()->exec($command, sprintf('restart-%s', $unit)); } + /** + * @throws SSHError + */ public function enable(string $unit): string { $command = <<<EOD @@ -58,6 +74,9 @@ public function enable(string $unit): string return $this->server->ssh()->exec($command, sprintf('enable-%s', $unit)); } + /** + * @throws SSHError + */ public function disable(string $unit): string { $command = <<<EOD diff --git a/app/SSH/Wordpress/Wordpress.php b/app/SSH/Wordpress/Wordpress.php index 134ff68..4a9dfe9 100644 --- a/app/SSH/Wordpress/Wordpress.php +++ b/app/SSH/Wordpress/Wordpress.php @@ -2,26 +2,27 @@ namespace App\SSH\Wordpress; +use App\Exceptions\SSHError; use App\Models\Site; -use App\SSH\HasScripts; class Wordpress { - use HasScripts; - + /** + * @throws SSHError + */ public function install(Site $site): void { $site->server->ssh($site->user)->exec( - $this->getScript('install.sh', [ + view('ssh.wordpress.install', [ 'path' => $site->path, 'domain' => $site->domain, - 'is_isolated' => $site->isIsolated() ? 'true' : 'false', - 'isolated_username' => $site->user, - 'db_name' => $site->type_data['database'], - 'db_user' => $site->type_data['database_user'], - 'db_pass' => $site->type_data['database_password'], - 'db_host' => 'localhost', - 'db_prefix' => 'wp_', + 'isIsolated' => $site->isIsolated() ? 'true' : 'false', + 'isolatedUsername' => $site->user, + 'dbName' => $site->type_data['database'], + 'dbUser' => $site->type_data['database_user'], + 'dbPass' => $site->type_data['database_password'], + 'dbHost' => 'localhost', + 'dbPrefix' => 'wp_', 'username' => $site->type_data['username'], 'password' => $site->type_data['password'], 'email' => $site->type_data['email'], diff --git a/app/SSH/Wordpress/scripts/install.sh b/app/SSH/Wordpress/scripts/install.sh deleted file mode 100644 index 6180870..0000000 --- a/app/SSH/Wordpress/scripts/install.sh +++ /dev/null @@ -1,40 +0,0 @@ -if ! curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! chmod +x wp-cli.phar; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if [ "__is_isolated__" == "true" ]; then - mv wp-cli.phar /home/__isolated_username__/bin/ - ln -s /home/__isolated_username__/bin/wp-cli.phar /home/__isolated_username__/bin/wp -else - if ! sudo mv wp-cli.phar /usr/local/bin/wp; then - echo 'VITO_SSH_ERROR' && exit 1 - fi -fi - -rm -rf __path__ - -if ! wp --path=__path__ core download; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! wp --path=__path__ core config \ - --dbname="__db_name__" \ - --dbuser="__db_user__" \ - --dbpass="__db_pass__" \ - --dbhost="__db_host__" \ - --dbprefix="__db_prefix__"; then - echo 'VITO_SSH_ERROR' && exit 1 -fi - -if ! wp --path=__path__ core install \ - --url="http://__domain__" \ - --title="__title__" \ - --admin_user="__username__" \ - --admin_password="__password__" \ - --admin_email="__email__"; then - echo 'VITO_SSH_ERROR' && exit 1 -fi diff --git a/app/ServerTypes/AbstractType.php b/app/ServerTypes/AbstractType.php index 2143d76..47de255 100755 --- a/app/ServerTypes/AbstractType.php +++ b/app/ServerTypes/AbstractType.php @@ -3,6 +3,7 @@ namespace App\ServerTypes; use App\Enums\ServiceStatus; +use App\Exceptions\SSHError; use App\Models\Server; use App\SSH\Services\PHP\PHP; @@ -15,6 +16,9 @@ public function __construct(Server $server) $this->server = $server; } + /** + * @throws SSHError + */ public function install(): void { $this->createUser(); diff --git a/app/SiteTypes/AbstractSiteType.php b/app/SiteTypes/AbstractSiteType.php index 7450200..f07aae9 100755 --- a/app/SiteTypes/AbstractSiteType.php +++ b/app/SiteTypes/AbstractSiteType.php @@ -3,7 +3,10 @@ namespace App\SiteTypes; use App\Exceptions\FailedToDeployGitKey; +use App\Exceptions\SSHError; use App\Models\Site; +use App\SSH\Services\PHP\PHP; +use Illuminate\Support\Str; abstract class AbstractSiteType implements SiteType { @@ -14,6 +17,26 @@ public function __construct(Site $site) $this->site = $site; } + public function createRules(array $input): array + { + return []; + } + + public function createFields(array $input): array + { + return []; + } + + public function data(array $input): array + { + return []; + } + + public function editRules(array $input): array + { + return []; + } + protected function progress(int $percentage): void { $this->site->progress = $percentage; @@ -22,6 +45,7 @@ protected function progress(int $percentage): void /** * @throws FailedToDeployGitKey + * @throws SSHError */ protected function deployKey(): void { @@ -35,4 +59,31 @@ protected function deployKey(): void $this->site->ssh_key ); } + + /** + * @throws SSHError + */ + protected function isolate(): void + { + if (! $this->site->isIsolated()) { + return; + } + + $this->site->server->os()->createIsolatedUser( + $this->site->user, + Str::random(15), + $this->site->id + ); + + // Generate the FPM pool + if ($this->site->php_version) { + /** @var PHP $php */ + $php = $this->site->php()->handler(); + $php->createFpmPool( + $this->site->user, + $this->site->php_version, + $this->site->id + ); + } + } } diff --git a/app/SiteTypes/PHPBlank.php b/app/SiteTypes/PHPBlank.php index ad9c01d..e55fcce 100755 --- a/app/SiteTypes/PHPBlank.php +++ b/app/SiteTypes/PHPBlank.php @@ -3,6 +3,7 @@ namespace App\SiteTypes; use App\Enums\SiteFeature; +use App\Exceptions\SSHError; use App\SSH\Services\Webserver\Webserver; use Illuminate\Validation\Rule; @@ -41,9 +42,12 @@ public function data(array $input): array return []; } + /** + * @throws SSHError + */ public function install(): void { - $this->site->isolate(); + $this->isolate(); /** @var Webserver $webserver */ $webserver = $this->site->server->webserver()->handler(); diff --git a/app/SiteTypes/PHPMyAdmin.php b/app/SiteTypes/PHPMyAdmin.php index 6520bed..4c2cec5 100755 --- a/app/SiteTypes/PHPMyAdmin.php +++ b/app/SiteTypes/PHPMyAdmin.php @@ -3,6 +3,7 @@ namespace App\SiteTypes; use App\Enums\SiteFeature; +use App\Exceptions\SSHError; use App\SSH\Services\Webserver\Webserver; use Illuminate\Validation\Rule; @@ -41,9 +42,12 @@ public function data(array $input): array ]; } + /** + * @throws SSHError + */ public function install(): void { - $this->site->isolate(); + $this->isolate(); /** @var Webserver $webserver */ $webserver = $this->site->server->webserver()->handler(); diff --git a/app/SiteTypes/PHPSite.php b/app/SiteTypes/PHPSite.php index 04b8339..a0eda32 100755 --- a/app/SiteTypes/PHPSite.php +++ b/app/SiteTypes/PHPSite.php @@ -4,6 +4,7 @@ use App\Enums\SiteFeature; use App\Exceptions\FailedToDeployGitKey; +use App\Exceptions\SSHError; use App\SSH\Composer\Composer; use App\SSH\Git\Git; use App\SSH\Services\Webserver\Webserver; @@ -73,10 +74,11 @@ public function data(array $input): array /** * @throws FailedToDeployGitKey + * @throws SSHError */ public function install(): void { - $this->site->isolate(); + $this->isolate(); /** @var Webserver $webserver */ $webserver = $this->site->server->webserver()->handler(); diff --git a/app/SiteTypes/Wordpress.php b/app/SiteTypes/Wordpress.php index 9884aa0..c502215 100755 --- a/app/SiteTypes/Wordpress.php +++ b/app/SiteTypes/Wordpress.php @@ -6,8 +6,10 @@ use App\Actions\Database\CreateDatabaseUser; use App\Actions\Database\LinkUser; use App\Enums\SiteFeature; +use App\Exceptions\SSHError; use App\Models\Database; use App\Models\DatabaseUser; +use App\SSH\Services\Webserver\Webserver; use Closure; use Illuminate\Validation\Rule; @@ -82,9 +84,12 @@ public function data(array $input): array ]; } + /** + * @throws SSHError + */ public function install(): void { - $this->site->isolate(); + $this->isolate(); /** @var Webserver $webserver */ $webserver = $this->site->server->webserver()->handler(); diff --git a/app/Web/Pages/Servers/PHP/Widgets/PHPList.php b/app/Web/Pages/Servers/PHP/Widgets/PHPList.php index 1ba5f82..eb164c5 100644 --- a/app/Web/Pages/Servers/PHP/Widgets/PHPList.php +++ b/app/Web/Pages/Servers/PHP/Widgets/PHPList.php @@ -11,6 +11,7 @@ use App\Enums\PHPIniType; use App\Models\Server; use App\Models\Service; +use App\Web\Pages\Servers\Logs\Index; use Exception; use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Select; @@ -102,6 +103,16 @@ private function installExtensionAction(): Action try { app(InstallPHPExtension::class)->install($this->server, $data); + + Notification::make() + ->success() + ->title('PHP Extension is being installed!') + ->body('You can check the logs for more information.') + ->actions([ + \Filament\Notifications\Actions\Action::make('View Logs') + ->url(Index::getUrl(parameters: ['server' => $this->server->id])), + ]) + ->send(); } catch (Exception $e) { Notification::make() ->danger() diff --git a/app/Web/Pages/Servers/Sites/Settings.php b/app/Web/Pages/Servers/Sites/Settings.php index e887eb8..9ea454f 100644 --- a/app/Web/Pages/Servers/Sites/Settings.php +++ b/app/Web/Pages/Servers/Sites/Settings.php @@ -74,7 +74,7 @@ private function vhostAction(): Action run_action($this, function () use ($data) { /** @var Webserver $handler */ $handler = $this->server->webserver()->handler(); - $handler->updateVHost($this->site, false, $data['vhost']); + $handler->updateVHost($this->site, $data['vhost']); Notification::make() ->success() ->title('VHost updated!') diff --git a/database/migrations/2025_01_27_181512_add_force_ssl_to_sites_table.php b/database/migrations/2025_01_27_181512_add_force_ssl_to_sites_table.php new file mode 100644 index 0000000..5aff87d --- /dev/null +++ b/database/migrations/2025_01_27_181512_add_force_ssl_to_sites_table.php @@ -0,0 +1,22 @@ +<?php + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +return new class extends Migration +{ + public function up(): void + { + Schema::table('sites', function (Blueprint $table) { + $table->boolean('force_ssl')->default(false); + }); + } + + public function down(): void + { + Schema::table('sites', function (Blueprint $table) { + $table->dropColumn('force_ssl'); + }); + } +}; diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..96a4e6e --- /dev/null +++ b/pint.json @@ -0,0 +1,4 @@ +{ + "preset": "laravel", + "exclude": ["resources/views/ssh"] +} diff --git a/resources/views/ssh/composer/composer-install.blade.php b/resources/views/ssh/composer/composer-install.blade.php new file mode 100755 index 0000000..04c2895 --- /dev/null +++ b/resources/views/ssh/composer/composer-install.blade.php @@ -0,0 +1,7 @@ +if ! cd {{ $path }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! php{{ $phpVersion }} /usr/local/bin/composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/resources/views/ssh/cron/update.blade.php b/resources/views/ssh/cron/update.blade.php new file mode 100644 index 0000000..f6ae216 --- /dev/null +++ b/resources/views/ssh/cron/update.blade.php @@ -0,0 +1,9 @@ +if ! echo '{{ $cron }}' | sudo -u {{ $user }} crontab -; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo -u {{ $user }} crontab -l; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo 'cron updated!' diff --git a/app/SSH/Git/scripts/checkout.sh b/resources/views/ssh/git/checkout.blade.php similarity index 54% rename from app/SSH/Git/scripts/checkout.sh rename to resources/views/ssh/git/checkout.blade.php index bfaf9b7..279a941 100644 --- a/app/SSH/Git/scripts/checkout.sh +++ b/resources/views/ssh/git/checkout.blade.php @@ -1,7 +1,7 @@ -if ! cd __path__; then +if ! cd {{ $path }}; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! git checkout -f __branch__; then +if ! git checkout -f {{ $branch }}; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/resources/views/ssh/git/clone.blade.php b/resources/views/ssh/git/clone.blade.php new file mode 100755 index 0000000..b1efcc5 --- /dev/null +++ b/resources/views/ssh/git/clone.blade.php @@ -0,0 +1,29 @@ +echo "Host {{ $host }}-{{ $key }} + Hostname {{ $host }} + IdentityFile=~/.ssh/{{ $key }}" >> ~/.ssh/config + +chmod 600 ~/.ssh/config + +ssh-keyscan -H {{ $host }} >> ~/.ssh/known_hosts + +rm -rf {{ $path }} + +if ! git config --global core.fileMode false; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! git clone -b {{ $branch }} {{ $repo }} {{ $path }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! find {{ $path }} -type d -exec chmod 755 {} \;; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! find {{ $path }} -type f -exec chmod 644 {} \;; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! cd {{ $path }} && git config core.fileMode false; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/app/SSH/OS/scripts/available-updates.sh b/resources/views/ssh/os/available-updates.blade.php similarity index 100% rename from app/SSH/OS/scripts/available-updates.sh rename to resources/views/ssh/os/available-updates.blade.php diff --git a/app/SSH/OS/scripts/cleanup.sh b/resources/views/ssh/os/cleanup.blade.php similarity index 100% rename from app/SSH/OS/scripts/cleanup.sh rename to resources/views/ssh/os/cleanup.blade.php diff --git a/resources/views/ssh/os/create-isolated-user.blade.php b/resources/views/ssh/os/create-isolated-user.blade.php new file mode 100644 index 0000000..cd86097 --- /dev/null +++ b/resources/views/ssh/os/create-isolated-user.blade.php @@ -0,0 +1,18 @@ +export DEBIAN_FRONTEND=noninteractive +if ! sudo useradd -p $(openssl passwd -1 {{ $password }}) {{ $user }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +sudo mkdir /home/{{ $user }} +sudo mkdir /home/{{ $user }}/.logs +sudo mkdir /home/{{ $user }}/tmp +sudo mkdir /home/{{ $user }}/bin +sudo mkdir /home/{{ $user }}/.ssh +echo 'export PATH="/home/{{ $user }}/bin:$PATH"' | sudo tee -a /home/{{ $user }}/.bashrc +echo 'export PATH="/home/{{ $user }}/bin:$PATH"' | sudo tee -a /home/{{ $user }}/.profile +sudo usermod -a -G {{ $user }} {{ $serverUser }} +sudo chown -R {{ $user }}:{{ $user }} /home/{{ $user }} +sudo chmod -R 755 /home/{{ $user }} +sudo chmod -R 700 /home/{{ $user }}/.ssh +sudo chsh -s /bin/bash {{ $user }} +echo "Created user {{ $user }}." diff --git a/resources/views/ssh/os/create-user.blade.php b/resources/views/ssh/os/create-user.blade.php new file mode 100755 index 0000000..364d3b0 --- /dev/null +++ b/resources/views/ssh/os/create-user.blade.php @@ -0,0 +1,11 @@ +export DEBIAN_FRONTEND=noninteractive +echo "{{ $key }}" | sudo tee -a /root/.ssh/authorized_keys +sudo useradd -p $(openssl passwd -1 {{ $password }}) {{ $user }} +sudo usermod -aG sudo {{ $user }} +echo "{{ $user }} ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers +sudo mkdir /home/{{ $user }} +sudo mkdir /home/{{ $user }}/.ssh +echo "{{ $key }}" | sudo tee -a /home/{{ $user }}/.ssh/authorized_keys +sudo chown -R {{ $user }}:{{ $user }} /home/{{ $user }} +sudo chsh -s /bin/bash {{ $user }} +sudo su - {{ $user }} -c "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa" <<< y diff --git a/resources/views/ssh/os/delete-file.blade.php b/resources/views/ssh/os/delete-file.blade.php new file mode 100644 index 0000000..974e2a8 --- /dev/null +++ b/resources/views/ssh/os/delete-file.blade.php @@ -0,0 +1 @@ +rm -f {{ $path }} diff --git a/resources/views/ssh/os/delete-isolated-user.blade.php b/resources/views/ssh/os/delete-isolated-user.blade.php new file mode 100644 index 0000000..6cf1780 --- /dev/null +++ b/resources/views/ssh/os/delete-isolated-user.blade.php @@ -0,0 +1,3 @@ +sudo gpasswd -d {{ $serverUser }} {{ $user }} +sudo userdel -r "{{ $user }}" +echo "User {{ $user }} has been deleted." diff --git a/app/SSH/OS/scripts/delete-ssh-key.sh b/resources/views/ssh/os/delete-ssh-key.blade.php similarity index 50% rename from app/SSH/OS/scripts/delete-ssh-key.sh rename to resources/views/ssh/os/delete-ssh-key.blade.php index 5a86e04..a1f73f5 100644 --- a/app/SSH/OS/scripts/delete-ssh-key.sh +++ b/resources/views/ssh/os/delete-ssh-key.blade.php @@ -1 +1 @@ -bash -c 'ssh_key_to_delete="$1"; sed -i "\#${ssh_key_to_delete//\//\\/}#d" /home/vito/.ssh/authorized_keys' bash '__key__' +bash -c 'ssh_key_to_delete="$1"; sed -i "\#${ssh_key_to_delete//\//\\/}#d" /home/vito/.ssh/authorized_keys' bash '{{ $key }}' diff --git a/resources/views/ssh/os/deploy-ssh-key.blade.php b/resources/views/ssh/os/deploy-ssh-key.blade.php new file mode 100644 index 0000000..57abc85 --- /dev/null +++ b/resources/views/ssh/os/deploy-ssh-key.blade.php @@ -0,0 +1,3 @@ +if ! echo '{{ $key }}' | sudo tee -a ~/.ssh/authorized_keys; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/resources/views/ssh/os/download.blade.php b/resources/views/ssh/os/download.blade.php new file mode 100644 index 0000000..72dff4e --- /dev/null +++ b/resources/views/ssh/os/download.blade.php @@ -0,0 +1,3 @@ +if ! wget {{ $url }} -O {{ $path }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/resources/views/ssh/os/generate-ssh-key.blade.php b/resources/views/ssh/os/generate-ssh-key.blade.php new file mode 100644 index 0000000..0371d02 --- /dev/null +++ b/resources/views/ssh/os/generate-ssh-key.blade.php @@ -0,0 +1 @@ +ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/{{ $name }} diff --git a/app/SSH/OS/scripts/get-public-key.sh b/resources/views/ssh/os/get-public-key.blade.php similarity index 100% rename from app/SSH/OS/scripts/get-public-key.sh rename to resources/views/ssh/os/get-public-key.blade.php diff --git a/app/SSH/OS/scripts/install-dependencies.sh b/resources/views/ssh/os/install-dependencies.blade.php similarity index 77% rename from app/SSH/OS/scripts/install-dependencies.sh rename to resources/views/ssh/os/install-dependencies.blade.php index 10a868e..d58e55d 100755 --- a/app/SSH/OS/scripts/install-dependencies.sh +++ b/resources/views/ssh/os/install-dependencies.blade.php @@ -1,6 +1,6 @@ sudo DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common curl zip unzip git gcc openssl ufw -git config --global user.email "__email__" -git config --global user.name "__name__" +git config --global user.email "{{ $email }}" +git config --global user.name "{{ $name }}" # Install Node.js curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - diff --git a/resources/views/ssh/os/read-file.blade.php b/resources/views/ssh/os/read-file.blade.php new file mode 100644 index 0000000..8b2778e --- /dev/null +++ b/resources/views/ssh/os/read-file.blade.php @@ -0,0 +1 @@ +[ -f {{ $path }} ] && sudo cat {{ $path }} diff --git a/resources/views/ssh/os/read-ssh-key.blade.php b/resources/views/ssh/os/read-ssh-key.blade.php new file mode 100644 index 0000000..627654c --- /dev/null +++ b/resources/views/ssh/os/read-ssh-key.blade.php @@ -0,0 +1 @@ +cat ~/.ssh/{{ $name }}.pub diff --git a/app/SSH/OS/scripts/reboot.sh b/resources/views/ssh/os/reboot.blade.php similarity index 100% rename from app/SSH/OS/scripts/reboot.sh rename to resources/views/ssh/os/reboot.blade.php diff --git a/app/SSH/OS/scripts/resource-info.sh b/resources/views/ssh/os/resource-info.blade.php similarity index 100% rename from app/SSH/OS/scripts/resource-info.sh rename to resources/views/ssh/os/resource-info.blade.php diff --git a/app/SSH/OS/scripts/run-script.sh b/resources/views/ssh/os/run-script.blade.php similarity index 50% rename from app/SSH/OS/scripts/run-script.sh rename to resources/views/ssh/os/run-script.blade.php index 7ecdab1..08f5bb1 100644 --- a/app/SSH/OS/scripts/run-script.sh +++ b/resources/views/ssh/os/run-script.blade.php @@ -1,5 +1,5 @@ -if ! cd __path__; then +if ! cd {{ $path }}; then echo 'VITO_SSH_ERROR' && exit 1 fi -__script__ +{{ $script }} diff --git a/resources/views/ssh/os/tail.blade.php b/resources/views/ssh/os/tail.blade.php new file mode 100644 index 0000000..42532f7 --- /dev/null +++ b/resources/views/ssh/os/tail.blade.php @@ -0,0 +1 @@ +sudo tail -n {{ $lines }} {{ $path }} diff --git a/app/SSH/OS/scripts/upgrade.sh b/resources/views/ssh/os/upgrade.blade.php similarity index 100% rename from app/SSH/OS/scripts/upgrade.sh rename to resources/views/ssh/os/upgrade.blade.php diff --git a/resources/views/ssh/phpmyadmin/install.blade.php b/resources/views/ssh/phpmyadmin/install.blade.php new file mode 100644 index 0000000..9cb16a5 --- /dev/null +++ b/resources/views/ssh/phpmyadmin/install.blade.php @@ -0,0 +1,29 @@ +if ! rm -rf phpmyadmin; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! rm -rf {{ $path }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! wget https://files.phpmyadmin.net/phpMyAdmin/{{ $version }}/phpMyAdmin-{{ $version }}-all-languages.zip; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! unzip phpMyAdmin-{{ $version }}-all-languages.zip; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! rm -rf phpMyAdmin-{{ $version }}-all-languages.zip; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! mv phpMyAdmin-{{ $version }}-all-languages {{ $path }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! mv {{ $path }}/config.sample.inc.php {{ $path }}/config.inc.php; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "PHPMyAdmin installed!" diff --git a/app/SSH/Services/Database/scripts/mariadb/install-10.11.sh b/resources/views/ssh/services/database/mariadb/install-1011.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mariadb/install-10.11.sh rename to resources/views/ssh/services/database/mariadb/install-1011.blade.php diff --git a/app/SSH/Services/Database/scripts/mariadb/install-10.3.sh b/resources/views/ssh/services/database/mariadb/install-103.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mariadb/install-10.3.sh rename to resources/views/ssh/services/database/mariadb/install-103.blade.php diff --git a/app/SSH/Services/Database/scripts/mariadb/install-10.4.sh b/resources/views/ssh/services/database/mariadb/install-104.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mariadb/install-10.4.sh rename to resources/views/ssh/services/database/mariadb/install-104.blade.php diff --git a/app/SSH/Services/Database/scripts/mariadb/install-10.6.sh b/resources/views/ssh/services/database/mariadb/install-106.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mariadb/install-10.6.sh rename to resources/views/ssh/services/database/mariadb/install-106.blade.php diff --git a/app/SSH/Services/Database/scripts/mariadb/install-11.4.sh b/resources/views/ssh/services/database/mariadb/install-114.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mariadb/install-11.4.sh rename to resources/views/ssh/services/database/mariadb/install-114.blade.php diff --git a/app/SSH/Services/Database/scripts/mariadb/uninstall.sh b/resources/views/ssh/services/database/mariadb/uninstall.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mariadb/uninstall.sh rename to resources/views/ssh/services/database/mariadb/uninstall.blade.php diff --git a/resources/views/ssh/services/database/mysql/backup.blade.php b/resources/views/ssh/services/database/mysql/backup.blade.php new file mode 100644 index 0000000..64a9e27 --- /dev/null +++ b/resources/views/ssh/services/database/mysql/backup.blade.php @@ -0,0 +1,11 @@ +if ! sudo DEBIAN_FRONTEND=noninteractive mysqldump -u root {{ $database }} > {{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! DEBIAN_FRONTEND=noninteractive zip {{ $file }}.zip {{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! rm {{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/app/SSH/Services/Database/scripts/mysql/create-user.sh b/resources/views/ssh/services/database/mysql/create-user.blade.php similarity index 55% rename from app/SSH/Services/Database/scripts/mysql/create-user.sh rename to resources/views/ssh/services/database/mysql/create-user.blade.php index 8eb6271..e186365 100755 --- a/app/SSH/Services/Database/scripts/mysql/create-user.sh +++ b/resources/views/ssh/services/database/mysql/create-user.blade.php @@ -1,4 +1,4 @@ -if ! sudo mysql -e "CREATE USER IF NOT EXISTS '__username__'@'__host__' IDENTIFIED BY '__password__'"; then +if ! sudo mysql -e "CREATE USER IF NOT EXISTS '{{ $username }}'@'{{ $host }}' IDENTIFIED BY '{{ $password }}'"; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/resources/views/ssh/services/database/mysql/create.blade.php b/resources/views/ssh/services/database/mysql/create.blade.php new file mode 100755 index 0000000..14c43f2 --- /dev/null +++ b/resources/views/ssh/services/database/mysql/create.blade.php @@ -0,0 +1,5 @@ +if ! sudo mysql -e "CREATE DATABASE IF NOT EXISTS {{ $name }} CHARACTER SET utf8 COLLATE utf8_general_ci"; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "Command executed" diff --git a/app/SSH/Services/Database/scripts/mysql/delete-user.sh b/resources/views/ssh/services/database/mysql/delete-user.blade.php similarity index 65% rename from app/SSH/Services/Database/scripts/mysql/delete-user.sh rename to resources/views/ssh/services/database/mysql/delete-user.blade.php index 5a82b9b..59c3d52 100755 --- a/app/SSH/Services/Database/scripts/mysql/delete-user.sh +++ b/resources/views/ssh/services/database/mysql/delete-user.blade.php @@ -1,4 +1,4 @@ -if ! sudo mysql -e "DROP USER IF EXISTS '__username__'@'__host__'"; then +if ! sudo mysql -e "DROP USER IF EXISTS '{{ $username }}'@'{{ $host }}'"; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/Database/scripts/mysql/delete.sh b/resources/views/ssh/services/database/mysql/delete.blade.php similarity index 50% rename from app/SSH/Services/Database/scripts/mysql/delete.sh rename to resources/views/ssh/services/database/mysql/delete.blade.php index 54c06fd..0130f47 100755 --- a/app/SSH/Services/Database/scripts/mysql/delete.sh +++ b/resources/views/ssh/services/database/mysql/delete.blade.php @@ -1,4 +1,4 @@ -if ! sudo mysql -e "DROP DATABASE IF EXISTS __name__"; then +if ! sudo mysql -e "DROP DATABASE IF EXISTS {{ $name }}"; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/Database/scripts/mysql/install-5.7.sh b/resources/views/ssh/services/database/mysql/install-57.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mysql/install-5.7.sh rename to resources/views/ssh/services/database/mysql/install-57.blade.php diff --git a/app/SSH/Services/Database/scripts/mysql/install-8.0.sh b/resources/views/ssh/services/database/mysql/install-80.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mysql/install-8.0.sh rename to resources/views/ssh/services/database/mysql/install-80.blade.php diff --git a/app/SSH/Services/Database/scripts/mysql/install-8.4.sh b/resources/views/ssh/services/database/mysql/install-84.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mysql/install-8.4.sh rename to resources/views/ssh/services/database/mysql/install-84.blade.php diff --git a/resources/views/ssh/services/database/mysql/link.blade.php b/resources/views/ssh/services/database/mysql/link.blade.php new file mode 100755 index 0000000..ce547f2 --- /dev/null +++ b/resources/views/ssh/services/database/mysql/link.blade.php @@ -0,0 +1,9 @@ +if ! sudo mysql -e "GRANT ALL PRIVILEGES ON {{ $database }}.* TO '{{ $username }}'@'{{ $host }}'"; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo mysql -e "FLUSH PRIVILEGES"; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "Linking to {{ $database }} finished" diff --git a/resources/views/ssh/services/database/mysql/restore.blade.php b/resources/views/ssh/services/database/mysql/restore.blade.php new file mode 100644 index 0000000..c158f58 --- /dev/null +++ b/resources/views/ssh/services/database/mysql/restore.blade.php @@ -0,0 +1,11 @@ +if ! DEBIAN_FRONTEND=noninteractive unzip {{ $file }}.zip; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo DEBIAN_FRONTEND=noninteractive mysql -u root {{ $database }} < {{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! rm {{ $file }}.sql {{ $file }}.zip; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/app/SSH/Services/Database/scripts/mysql/uninstall.sh b/resources/views/ssh/services/database/mysql/uninstall.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/mysql/uninstall.sh rename to resources/views/ssh/services/database/mysql/uninstall.blade.php diff --git a/resources/views/ssh/services/database/mysql/unlink.blade.php b/resources/views/ssh/services/database/mysql/unlink.blade.php new file mode 100755 index 0000000..ff2a879 --- /dev/null +++ b/resources/views/ssh/services/database/mysql/unlink.blade.php @@ -0,0 +1,5 @@ +if ! sudo mysql -e "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '{{ $username }}'@'{{ $host }}'"; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "Command executed" diff --git a/resources/views/ssh/services/database/postgresql/backup.blade.php b/resources/views/ssh/services/database/postgresql/backup.blade.php new file mode 100644 index 0000000..b9319d0 --- /dev/null +++ b/resources/views/ssh/services/database/postgresql/backup.blade.php @@ -0,0 +1,19 @@ +if ! sudo -u postgres pg_dump -d {{ $database }} -f /var/lib/postgresql/{{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo mv /var/lib/postgresql/{{ $file }}.sql /home/vito/{{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo chown vito:vito /home/vito/{{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! DEBIAN_FRONTEND=noninteractive zip {{ $file }}.zip {{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! rm {{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/resources/views/ssh/services/database/postgresql/create-user.blade.php b/resources/views/ssh/services/database/postgresql/create-user.blade.php new file mode 100755 index 0000000..ff39ec9 --- /dev/null +++ b/resources/views/ssh/services/database/postgresql/create-user.blade.php @@ -0,0 +1,5 @@ +if ! sudo -u postgres psql -c "CREATE ROLE \"{{ $username }}\" WITH LOGIN PASSWORD '{{ $password }}';"; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "User {{ $username }} created" diff --git a/resources/views/ssh/services/database/postgresql/create.blade.php b/resources/views/ssh/services/database/postgresql/create.blade.php new file mode 100644 index 0000000..e5ada6d --- /dev/null +++ b/resources/views/ssh/services/database/postgresql/create.blade.php @@ -0,0 +1,5 @@ +if ! sudo -u postgres psql -c "CREATE DATABASE \"{{ $name }}\""; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "Database {{ $name }} created" diff --git a/resources/views/ssh/services/database/postgresql/delete-user.blade.php b/resources/views/ssh/services/database/postgresql/delete-user.blade.php new file mode 100755 index 0000000..54f1dfd --- /dev/null +++ b/resources/views/ssh/services/database/postgresql/delete-user.blade.php @@ -0,0 +1,5 @@ +if ! sudo -u postgres psql -c "DROP USER \"{{ $username }}\""; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "User {{ $username }} deleted" diff --git a/resources/views/ssh/services/database/postgresql/delete.blade.php b/resources/views/ssh/services/database/postgresql/delete.blade.php new file mode 100755 index 0000000..900fc3a --- /dev/null +++ b/resources/views/ssh/services/database/postgresql/delete.blade.php @@ -0,0 +1,5 @@ +if ! sudo -u postgres psql -c "DROP DATABASE \"{{ $name }}\""; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "Database {{ $name }} deleted" diff --git a/app/SSH/Services/Database/scripts/postgresql/install-12.sh b/resources/views/ssh/services/database/postgresql/install-12.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/postgresql/install-12.sh rename to resources/views/ssh/services/database/postgresql/install-12.blade.php diff --git a/app/SSH/Services/Database/scripts/postgresql/install-13.sh b/resources/views/ssh/services/database/postgresql/install-13.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/postgresql/install-13.sh rename to resources/views/ssh/services/database/postgresql/install-13.blade.php diff --git a/app/SSH/Services/Database/scripts/postgresql/install-14.sh b/resources/views/ssh/services/database/postgresql/install-14.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/postgresql/install-14.sh rename to resources/views/ssh/services/database/postgresql/install-14.blade.php diff --git a/app/SSH/Services/Database/scripts/postgresql/install-15.sh b/resources/views/ssh/services/database/postgresql/install-15.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/postgresql/install-15.sh rename to resources/views/ssh/services/database/postgresql/install-15.blade.php diff --git a/app/SSH/Services/Database/scripts/postgresql/install-16.sh b/resources/views/ssh/services/database/postgresql/install-16.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/postgresql/install-16.sh rename to resources/views/ssh/services/database/postgresql/install-16.blade.php diff --git a/app/SSH/Services/Database/scripts/postgresql/link.sh b/resources/views/ssh/services/database/postgresql/link.blade.php similarity index 83% rename from app/SSH/Services/Database/scripts/postgresql/link.sh rename to resources/views/ssh/services/database/postgresql/link.blade.php index f1a0414..22122ea 100755 --- a/app/SSH/Services/Database/scripts/postgresql/link.sh +++ b/resources/views/ssh/services/database/postgresql/link.blade.php @@ -1,6 +1,6 @@ -USER_TO_LINK='__username__' -DB_NAME='__database__' -DB_VERSION='__version__' +USER_TO_LINK='{{ $username }}' +DB_NAME='{{ $database }}' +DB_VERSION='{{ $version }}' if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE \"$DB_NAME\" TO $USER_TO_LINK;"; then echo 'VITO_SSH_ERROR' && exit 1 diff --git a/resources/views/ssh/services/database/postgresql/restore.blade.php b/resources/views/ssh/services/database/postgresql/restore.blade.php new file mode 100644 index 0000000..8404be8 --- /dev/null +++ b/resources/views/ssh/services/database/postgresql/restore.blade.php @@ -0,0 +1,11 @@ +if ! DEBIAN_FRONTEND=noninteractive unzip {{ $file }}.zip; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo -u postgres psql -d {{ $database }} -f {{ $file }}.sql; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! rm {{ $file }}.sql {{ $file }}.zip; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/app/SSH/Services/Database/scripts/postgresql/uninstall.sh b/resources/views/ssh/services/database/postgresql/uninstall.blade.php similarity index 100% rename from app/SSH/Services/Database/scripts/postgresql/uninstall.sh rename to resources/views/ssh/services/database/postgresql/uninstall.blade.php diff --git a/app/SSH/Services/Database/scripts/postgresql/unlink.sh b/resources/views/ssh/services/database/postgresql/unlink.blade.php similarity index 89% rename from app/SSH/Services/Database/scripts/postgresql/unlink.sh rename to resources/views/ssh/services/database/postgresql/unlink.blade.php index c7bd302..56413d3 100755 --- a/app/SSH/Services/Database/scripts/postgresql/unlink.sh +++ b/resources/views/ssh/services/database/postgresql/unlink.blade.php @@ -1,5 +1,5 @@ -USER_TO_REVOKE='__username__' -DB_VERSION='__version__' +USER_TO_REVOKE='{{ $username }}' +DB_VERSION='{{ $version }}' DATABASES=$(sudo -u postgres psql -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;") diff --git a/app/SSH/Services/Firewall/scripts/ufw/remove-rule.sh b/resources/views/ssh/services/firewall/ufw/add-rule.blade.php similarity index 62% rename from app/SSH/Services/Firewall/scripts/ufw/remove-rule.sh rename to resources/views/ssh/services/firewall/ufw/add-rule.blade.php index d7d0da1..88c904f 100755 --- a/app/SSH/Services/Firewall/scripts/ufw/remove-rule.sh +++ b/resources/views/ssh/services/firewall/ufw/add-rule.blade.php @@ -1,4 +1,4 @@ -if ! sudo ufw delete __type__ from __source____mask__ to any proto __protocol__ port __port__; then +if ! sudo ufw {{ $type }} from {{ $source }}{{ $mask }} to any proto {{ $protocol }} port {{ $port }}; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/Firewall/scripts/ufw/install-ufw.sh b/resources/views/ssh/services/firewall/ufw/install-ufw.blade.php similarity index 100% rename from app/SSH/Services/Firewall/scripts/ufw/install-ufw.sh rename to resources/views/ssh/services/firewall/ufw/install-ufw.blade.php diff --git a/app/SSH/Services/Firewall/scripts/ufw/add-rule.sh b/resources/views/ssh/services/firewall/ufw/remove-rule.blade.php similarity index 61% rename from app/SSH/Services/Firewall/scripts/ufw/add-rule.sh rename to resources/views/ssh/services/firewall/ufw/remove-rule.blade.php index b211a2c..8bd0e90 100755 --- a/app/SSH/Services/Firewall/scripts/ufw/add-rule.sh +++ b/resources/views/ssh/services/firewall/ufw/remove-rule.blade.php @@ -1,4 +1,4 @@ -if ! sudo ufw __type__ from __source____mask__ to any proto __protocol__ port __port__; then +if ! sudo ufw delete {{ $type }} from {{ $source }}{{ $mask }} to any proto {{ $protocol }} port {{ $port }}; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/Monitoring/VitoAgent/scripts/install.sh b/resources/views/ssh/services/monitoring/vito-agent/install.blade.php similarity index 90% rename from app/SSH/Services/Monitoring/VitoAgent/scripts/install.sh rename to resources/views/ssh/services/monitoring/vito-agent/install.blade.php index 6c7ae32..8dbb300 100644 --- a/app/SSH/Services/Monitoring/VitoAgent/scripts/install.sh +++ b/resources/views/ssh/services/monitoring/vito-agent/install.blade.php @@ -12,7 +12,7 @@ executable="vitoagent-linux-amd64" fi -wget __download_url__/$executable +wget {{ $downloadUrl }}/$executable chmod +x ./$executable @@ -39,8 +39,8 @@ export VITO_AGENT_CONFIG=" { - \"url\": \"__config_url__\", - \"secret\": \"__config_secret__\" + \"url\": \"{{ $configUrl }}\", + \"secret\": \"{{ $configSecret }}\" } " diff --git a/app/SSH/Services/Monitoring/VitoAgent/scripts/uninstall.sh b/resources/views/ssh/services/monitoring/vito-agent/uninstall.blade.php similarity index 100% rename from app/SSH/Services/Monitoring/VitoAgent/scripts/uninstall.sh rename to resources/views/ssh/services/monitoring/vito-agent/uninstall.blade.php diff --git a/app/SSH/Services/NodeJS/scripts/change-default-nodejs.sh b/resources/views/ssh/services/nodejs/change-default-nodejs.blade.php similarity index 83% rename from app/SSH/Services/NodeJS/scripts/change-default-nodejs.sh rename to resources/views/ssh/services/nodejs/change-default-nodejs.blade.php index fa8b39b..7914eb6 100755 --- a/app/SSH/Services/NodeJS/scripts/change-default-nodejs.sh +++ b/resources/views/ssh/services/nodejs/change-default-nodejs.blade.php @@ -1,7 +1,7 @@ export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" -if ! nvm alias default __version__; then +if ! nvm alias default {{ $version }}; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/NodeJS/scripts/install-nodejs.sh b/resources/views/ssh/services/nodejs/install-nodejs.blade.php similarity index 94% rename from app/SSH/Services/NodeJS/scripts/install-nodejs.sh rename to resources/views/ssh/services/nodejs/install-nodejs.blade.php index 53a8998..aea93fa 100755 --- a/app/SSH/Services/NodeJS/scripts/install-nodejs.sh +++ b/resources/views/ssh/services/nodejs/install-nodejs.blade.php @@ -57,11 +57,11 @@ fi # Install the requested Node.js version -if ! nvm install __version__; then +if ! nvm install {{ $version }}; then echo 'VITO_SSH_ERROR' && exit 1 fi -echo "Node.js version __version__ installed successfully!" +echo "Node.js version {{ $version }} installed successfully!" echo "Node version:" && node -v echo "NPM version:" && npm -v diff --git a/resources/views/ssh/services/nodejs/uninstall-nodejs.blade.php b/resources/views/ssh/services/nodejs/uninstall-nodejs.blade.php new file mode 100755 index 0000000..6b022dd --- /dev/null +++ b/resources/views/ssh/services/nodejs/uninstall-nodejs.blade.php @@ -0,0 +1,15 @@ +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + +@if ($default) +if ! nvm unalias default; then + echo 'VITO_SSH_ERROR' && exit 1 +fi +if ! nvm deactivate; then + echo 'VITO_SSH_ERROR' && exit 1 +fi +@endif + +if ! nvm uninstall {{ $version }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/app/SSH/Services/PHP/scripts/change-default-php.sh b/resources/views/ssh/services/php/change-default-php.blade.php similarity index 69% rename from app/SSH/Services/PHP/scripts/change-default-php.sh rename to resources/views/ssh/services/php/change-default-php.blade.php index c3b131f..e89fe13 100755 --- a/app/SSH/Services/PHP/scripts/change-default-php.sh +++ b/resources/views/ssh/services/php/change-default-php.blade.php @@ -2,7 +2,7 @@ echo 'VITO_SSH_ERROR' && exit 1 fi -if ! sudo ln -s /usr/bin/php__version__ /usr/bin/php; then +if ! sudo ln -s /usr/bin/php{{ $version }} /usr/bin/php; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/resources/views/ssh/services/php/fpm-pool.blade.php b/resources/views/ssh/services/php/fpm-pool.blade.php new file mode 100644 index 0000000..5eea283 --- /dev/null +++ b/resources/views/ssh/services/php/fpm-pool.blade.php @@ -0,0 +1,22 @@ +[{{ $user }}] +user = {{ $user }} +group = {{ $user }} + +listen = /run/php/php{{ $version }}-fpm-{{ $user }}.sock +listen.owner = vito +listen.group = vito +listen.mode = 0660 + +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +pm.max_requests = 500 + +php_admin_value[open_basedir] = /home/{{ $user }}/:/tmp/ +php_admin_value[upload_tmp_dir] = /home/{{ $user }}/tmp +php_admin_value[session.save_path] = /home/{{ $user }}/tmp +php_admin_value[display_errors] = off +php_admin_value[log_errors] = on +php_admin_value[error_log] = /home/{{ $user }}/.logs/php_errors.log diff --git a/app/SSH/Services/PHP/scripts/install-composer.sh b/resources/views/ssh/services/php/install-composer.blade.php similarity index 100% rename from app/SSH/Services/PHP/scripts/install-composer.sh rename to resources/views/ssh/services/php/install-composer.blade.php diff --git a/resources/views/ssh/services/php/install-php-extension.blade.php b/resources/views/ssh/services/php/install-php-extension.blade.php new file mode 100644 index 0000000..380c97f --- /dev/null +++ b/resources/views/ssh/services/php/install-php-extension.blade.php @@ -0,0 +1,5 @@ +sudo apt-get install -y php{{ $version }}-{{ $name }} + +sudo service php{{ $version }}-fpm restart + +php{{ $version }} -m diff --git a/resources/views/ssh/services/php/install-php.blade.php b/resources/views/ssh/services/php/install-php.blade.php new file mode 100755 index 0000000..a377b00 --- /dev/null +++ b/resources/views/ssh/services/php/install-php.blade.php @@ -0,0 +1,15 @@ +sudo add-apt-repository ppa:ondrej/php -y + +sudo DEBIAN_FRONTEND=noninteractive apt-get update + +if ! sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php{{ $version }} php{{ $version }}-fpm php{{ $version }}-mbstring php{{ $version }}-mysql php{{ $version }}-gd php{{ $version }}-xml php{{ $version }}-curl php{{ $version }}-gettext php{{ $version }}-zip php{{ $version }}-bcmath php{{ $version }}-soap php{{ $version }}-redis php{{ $version }}-sqlite3 php{{ $version }}-tokenizer php{{ $version }}-pgsql php{{ $version }}-pdo; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo sed -i 's/www-data/{{ $user }}/g' /etc/php/{{ $version }}/fpm/pool.d/www.conf; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +sudo service php{{ $version }}-fpm enable + +sudo service php{{ $version }}-fpm start diff --git a/resources/views/ssh/services/php/remove-fpm-pool.blade.php b/resources/views/ssh/services/php/remove-fpm-pool.blade.php new file mode 100644 index 0000000..2fe3840 --- /dev/null +++ b/resources/views/ssh/services/php/remove-fpm-pool.blade.php @@ -0,0 +1,2 @@ +sudo rm -f /etc/php/{{ $version }}/fpm/pool.d/{{ $user }}.conf +sudo service php{{ $version }}-fpm restart diff --git a/resources/views/ssh/services/php/uninstall-php.blade.php b/resources/views/ssh/services/php/uninstall-php.blade.php new file mode 100755 index 0000000..98628c9 --- /dev/null +++ b/resources/views/ssh/services/php/uninstall-php.blade.php @@ -0,0 +1,5 @@ +sudo service php{{ $version }}-fpm stop + +if ! sudo DEBIAN_FRONTEND=noninteractive apt-get remove -y php{{ $version }} php{{ $version }}-fpm php{{ $version }}-mbstring php{{ $version }}-mysql php{{ $version }}-mcrypt php{{ $version }}-gd php{{ $version }}-xml php{{ $version }}-curl php{{ $version }}-gettext php{{ $version }}-zip php{{ $version }}-bcmath php{{ $version }}-soap php{{ $version }}-redis php{{ $version }}-sqlite3; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/resources/views/ssh/services/php/update-php-settings.blade.php b/resources/views/ssh/services/php/update-php-settings.blade.php new file mode 100644 index 0000000..e1aaa48 --- /dev/null +++ b/resources/views/ssh/services/php/update-php-settings.blade.php @@ -0,0 +1,11 @@ +if ! sudo sed -i 's,^{{ $variable }} =.*$,{{ $variable }} = {{ $value }},' /etc/php/{{ $version }}/cli/php.ini; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo sed -i 's,^{{ $variable }} =.*$,{{ $variable }} = {{ $value }},' /etc/php/{{ $version }}/fpm/php.ini; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo service php{{ $version }}-fpm restart; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/app/SSH/Services/ProcessManager/scripts/supervisor/create-worker.sh b/resources/views/ssh/services/process-manager/supervisor/create-worker.blade.php similarity index 61% rename from app/SSH/Services/ProcessManager/scripts/supervisor/create-worker.sh rename to resources/views/ssh/services/process-manager/supervisor/create-worker.blade.php index 846a20d..727a4f8 100644 --- a/app/SSH/Services/ProcessManager/scripts/supervisor/create-worker.sh +++ b/resources/views/ssh/services/process-manager/supervisor/create-worker.blade.php @@ -1,12 +1,12 @@ -if ! sudo mkdir -p "$(dirname __log_file__)"; then +if ! sudo mkdir -p "$(dirname {{ $logFile }})"; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! sudo touch __log_file__; then +if ! sudo touch {{ $logFile }}; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! sudo chown __user__:__user__ __log_file__; then +if ! sudo chown {{ $user }}:{{ $user }} {{ $logFile }}; then echo 'VITO_SSH_ERROR' && exit 1 fi @@ -18,6 +18,6 @@ echo 'VITO_SSH_ERROR' && exit 1 fi -if ! sudo supervisorctl start __id__:*; then +if ! sudo supervisorctl start {{ $id }}:*; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/ProcessManager/scripts/supervisor/delete-worker.sh b/resources/views/ssh/services/process-manager/supervisor/delete-worker.blade.php similarity index 62% rename from app/SSH/Services/ProcessManager/scripts/supervisor/delete-worker.sh rename to resources/views/ssh/services/process-manager/supervisor/delete-worker.blade.php index 3fae91c..c459aec 100644 --- a/app/SSH/Services/ProcessManager/scripts/supervisor/delete-worker.sh +++ b/resources/views/ssh/services/process-manager/supervisor/delete-worker.blade.php @@ -1,12 +1,12 @@ -if ! sudo supervisorctl stop __id__:*; then +if ! sudo supervisorctl stop {{ $id }}:*; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! sudo rm -rf ~/.logs/workers/__id__.log; then +if ! sudo rm -rf ~/.logs/workers/{{ $id }}.log; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! sudo rm -rf /etc/supervisor/conf.d/__id__.conf; then +if ! sudo rm -rf /etc/supervisor/conf.d/{{ $id }}.conf; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/ProcessManager/scripts/supervisor/install-supervisor.sh b/resources/views/ssh/services/process-manager/supervisor/install-supervisor.blade.php similarity index 100% rename from app/SSH/Services/ProcessManager/scripts/supervisor/install-supervisor.sh rename to resources/views/ssh/services/process-manager/supervisor/install-supervisor.blade.php diff --git a/resources/views/ssh/services/process-manager/supervisor/restart-worker.blade.php b/resources/views/ssh/services/process-manager/supervisor/restart-worker.blade.php new file mode 100644 index 0000000..bf1dc39 --- /dev/null +++ b/resources/views/ssh/services/process-manager/supervisor/restart-worker.blade.php @@ -0,0 +1,3 @@ +if ! sudo supervisorctl restart {{ $id }}:*; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/resources/views/ssh/services/process-manager/supervisor/start-worker.blade.php b/resources/views/ssh/services/process-manager/supervisor/start-worker.blade.php new file mode 100644 index 0000000..fd52a60 --- /dev/null +++ b/resources/views/ssh/services/process-manager/supervisor/start-worker.blade.php @@ -0,0 +1,3 @@ +if ! sudo supervisorctl start {{ $id }}:*; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/resources/views/ssh/services/process-manager/supervisor/stop-worker.blade.php b/resources/views/ssh/services/process-manager/supervisor/stop-worker.blade.php new file mode 100644 index 0000000..3c004db --- /dev/null +++ b/resources/views/ssh/services/process-manager/supervisor/stop-worker.blade.php @@ -0,0 +1,3 @@ +if ! sudo supervisorctl stop {{ $id }}:*; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/app/SSH/Services/ProcessManager/scripts/supervisor/uninstall-supervisor.sh b/resources/views/ssh/services/process-manager/supervisor/uninstall-supervisor.blade.php similarity index 100% rename from app/SSH/Services/ProcessManager/scripts/supervisor/uninstall-supervisor.sh rename to resources/views/ssh/services/process-manager/supervisor/uninstall-supervisor.blade.php diff --git a/resources/views/ssh/services/process-manager/supervisor/worker.blade.php b/resources/views/ssh/services/process-manager/supervisor/worker.blade.php new file mode 100644 index 0000000..3ea70db --- /dev/null +++ b/resources/views/ssh/services/process-manager/supervisor/worker.blade.php @@ -0,0 +1,10 @@ +[program:{{ $name }}] +process_name=%(program_name)s_%(process_num)02d +command={{ $command }} +autostart={{ $autoStart }} +autorestart={{ $autoRestart }} +user={{ $user }} +numprocs={{ $numprocs }} +redirect_stderr=true +stdout_logfile={{ $logFile }} +stopwaitsecs=3600 diff --git a/app/SSH/Services/Redis/scripts/install.sh b/resources/views/ssh/services/redis/install.blade.php similarity index 100% rename from app/SSH/Services/Redis/scripts/install.sh rename to resources/views/ssh/services/redis/install.blade.php diff --git a/app/SSH/Services/Redis/scripts/uninstall.sh b/resources/views/ssh/services/redis/uninstall.blade.php similarity index 100% rename from app/SSH/Services/Redis/scripts/uninstall.sh rename to resources/views/ssh/services/redis/uninstall.blade.php diff --git a/resources/views/ssh/services/webserver/nginx/change-php-version.blade.php b/resources/views/ssh/services/webserver/nginx/change-php-version.blade.php new file mode 100755 index 0000000..46e7dc9 --- /dev/null +++ b/resources/views/ssh/services/webserver/nginx/change-php-version.blade.php @@ -0,0 +1,9 @@ +if ! sudo sed -i 's/php{{ $oldVersion }}/php{{ $newVersion }}/g' /etc/nginx/sites-available/{{ $domain }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo service nginx restart; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +echo "PHP Version Changed to {{ $newVersion }}" diff --git a/app/SSH/Services/Webserver/scripts/nginx/create-custom-ssl.sh b/resources/views/ssh/services/webserver/nginx/create-custom-ssl.blade.php similarity index 50% rename from app/SSH/Services/Webserver/scripts/nginx/create-custom-ssl.sh rename to resources/views/ssh/services/webserver/nginx/create-custom-ssl.blade.php index fb2a156..e5d5556 100644 --- a/app/SSH/Services/Webserver/scripts/nginx/create-custom-ssl.sh +++ b/resources/views/ssh/services/webserver/nginx/create-custom-ssl.blade.php @@ -1,12 +1,12 @@ -if ! sudo mkdir -p __path__; then +if ! sudo mkdir -p {{ $path }}; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! echo "__certificate__" | sudo tee __certificate_path__; then +if ! echo "{{ $certificate }}" | sudo tee {{ $certificatePath }}; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! echo "__pk__" | sudo tee __pk_path__; then +if ! echo "{{ $pk }}" | sudo tee {{ $pkPath }}; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/Webserver/scripts/nginx/create-letsencrypt-ssl.sh b/resources/views/ssh/services/webserver/nginx/create-letsencrypt-ssl.blade.php similarity index 53% rename from app/SSH/Services/Webserver/scripts/nginx/create-letsencrypt-ssl.sh rename to resources/views/ssh/services/webserver/nginx/create-letsencrypt-ssl.blade.php index 3f543d2..032ac6a 100644 --- a/app/SSH/Services/Webserver/scripts/nginx/create-letsencrypt-ssl.sh +++ b/resources/views/ssh/services/webserver/nginx/create-letsencrypt-ssl.blade.php @@ -1,3 +1,3 @@ -if ! sudo certbot certonly --force-renewal --nginx --noninteractive --agree-tos --cert-name __domain__ -m __email__ __domains__ --verbose; then +if ! sudo certbot certonly --force-renewal --nginx --noninteractive --agree-tos --cert-name {{ $domain }} -m {{ $email }} {{ $domains }} --verbose; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/resources/views/ssh/services/webserver/nginx/create-path.blade.php b/resources/views/ssh/services/webserver/nginx/create-path.blade.php new file mode 100644 index 0000000..6fd38a9 --- /dev/null +++ b/resources/views/ssh/services/webserver/nginx/create-path.blade.php @@ -0,0 +1,7 @@ +export DEBIAN_FRONTEND=noninteractive + +rm -rf {{ $path }} + +mkdir {{ $path }} + +chmod -R 755 {{ $path }} diff --git a/resources/views/ssh/services/webserver/nginx/create-vhost.blade.php b/resources/views/ssh/services/webserver/nginx/create-vhost.blade.php new file mode 100755 index 0000000..31f095f --- /dev/null +++ b/resources/views/ssh/services/webserver/nginx/create-vhost.blade.php @@ -0,0 +1,7 @@ +if ! sudo ln -s /etc/nginx/sites-available/{{ $domain }} /etc/nginx/sites-enabled/; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! sudo service nginx restart; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/resources/views/ssh/services/webserver/nginx/delete-site.blade.php b/resources/views/ssh/services/webserver/nginx/delete-site.blade.php new file mode 100755 index 0000000..dadab5c --- /dev/null +++ b/resources/views/ssh/services/webserver/nginx/delete-site.blade.php @@ -0,0 +1,7 @@ +rm -rf {{ $path }} + +sudo rm /etc/nginx/sites-available/{{ $domain }} + +sudo rm /etc/nginx/sites-enabled/{{ $domain }} + +echo "Site deleted" diff --git a/resources/views/ssh/services/webserver/nginx/get-vhost.blade.php b/resources/views/ssh/services/webserver/nginx/get-vhost.blade.php new file mode 100755 index 0000000..776eef5 --- /dev/null +++ b/resources/views/ssh/services/webserver/nginx/get-vhost.blade.php @@ -0,0 +1 @@ +cat /etc/nginx/sites-available/{{ $domain }} diff --git a/app/SSH/Services/Webserver/scripts/nginx/install-nginx.sh b/resources/views/ssh/services/webserver/nginx/install-nginx.blade.php similarity index 56% rename from app/SSH/Services/Webserver/scripts/nginx/install-nginx.sh rename to resources/views/ssh/services/webserver/nginx/install-nginx.blade.php index abf3f4d..c8f22b0 100755 --- a/app/SSH/Services/Webserver/scripts/nginx/install-nginx.sh +++ b/resources/views/ssh/services/webserver/nginx/install-nginx.blade.php @@ -1,8 +1,4 @@ sudo DEBIAN_FRONTEND=noninteractive apt-get install nginx -y -if ! echo '__config__' | sudo tee /etc/nginx/nginx.conf; then - echo 'VITO_SSH_ERROR' && exit 1 -fi -sudo service nginx start # install certbot sudo DEBIAN_FRONTEND=noninteractive apt-get install certbot python3-certbot-nginx -y diff --git a/app/SSH/Services/Webserver/scripts/nginx/nginx.conf b/resources/views/ssh/services/webserver/nginx/nginx.blade.php similarity index 98% rename from app/SSH/Services/Webserver/scripts/nginx/nginx.conf rename to resources/views/ssh/services/webserver/nginx/nginx.blade.php index 77df99a..e75e6dd 100755 --- a/app/SSH/Services/Webserver/scripts/nginx/nginx.conf +++ b/resources/views/ssh/services/webserver/nginx/nginx.blade.php @@ -1,4 +1,4 @@ -user __user__; +user {{ $user }}; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; diff --git a/resources/views/ssh/services/webserver/nginx/redirect.blade.php b/resources/views/ssh/services/webserver/nginx/redirect.blade.php new file mode 100644 index 0000000..420e9ec --- /dev/null +++ b/resources/views/ssh/services/webserver/nginx/redirect.blade.php @@ -0,0 +1,3 @@ +location {{ $from }} { + return {{ $mode }} {{ $to }}; +} diff --git a/app/SSH/Services/Webserver/scripts/nginx/uninstall-nginx.sh b/resources/views/ssh/services/webserver/nginx/uninstall-nginx.blade.php similarity index 100% rename from app/SSH/Services/Webserver/scripts/nginx/uninstall-nginx.sh rename to resources/views/ssh/services/webserver/nginx/uninstall-nginx.blade.php diff --git a/app/SSH/Services/Webserver/scripts/nginx/update-redirects.sh b/resources/views/ssh/services/webserver/nginx/update-redirects.blade.php similarity index 57% rename from app/SSH/Services/Webserver/scripts/nginx/update-redirects.sh rename to resources/views/ssh/services/webserver/nginx/update-redirects.blade.php index 9b5d66a..4ae738d 100644 --- a/app/SSH/Services/Webserver/scripts/nginx/update-redirects.sh +++ b/resources/views/ssh/services/webserver/nginx/update-redirects.blade.php @@ -1,4 +1,4 @@ -if ! echo '__redirects__' | sudo tee /etc/nginx/conf.d/__domain___redirects; then +if ! echo '{{ $redirects }}' | sudo tee /etc/nginx/conf.d/{{ $domain }}_redirects; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/resources/views/ssh/services/webserver/nginx/vhost.blade.php b/resources/views/ssh/services/webserver/nginx/vhost.blade.php new file mode 100755 index 0000000..4e8ca00 --- /dev/null +++ b/resources/views/ssh/services/webserver/nginx/vhost.blade.php @@ -0,0 +1,66 @@ +@if ($site->activeSsl && $site->force_ssl) + server { + listen 80; + server_name {{ $site->domain }} {{ $site->getAliasesString() }}; + return 301 https://$host$request_uri; + } +@endif + +server { + @if (!$site->activeSsl || !$site->force_ssl) + listen 80; + @endif + @if ($site->activeSsl) + listen 443 ssl; + ssl_certificate {{ $site->activeSsl->getCertificatePath() }}; + ssl_certificate_key {{ $site->activeSsl->getPkPath() }}; + @endif + + server_name {{ $site->domain }} {{ $site->getAliasesString() }}; + root {{ $site->getWebDirectoryPath() }}; + + add_header X-Frame-Options "SAMEORIGIN"; + add_header X-Content-Type-Options "nosniff"; + + index index.html index.php; + + charset utf-8; + + @if ($site->port) + location / { + try_files $uri $uri/ /index.html; + } + location / { + proxy_pass http://127.0.0.1:{{ $site->port }}/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header X-Forwarded-For $remote_addr; + } + @elseif ($site->php_version) + @php + $phpSocket = 'unix:/var/run/php/php-fpm.sock'; + if ($site->isIsolated()) { + $phpSocket = "unix:/run/php/php{$site->php_version}-fpm-{$site->user}.sock"; + } + @endphp + location / { + try_files $uri $uri/ /index.php?$query_string; + } + location ~ \.php$ { + fastcgi_pass {{ $phpSocket }}; + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + include fastcgi_params; + fastcgi_hide_header X-Powered-By; + } + @endif + + location = /favicon.ico { access_log off; log_not_found off; } + location = /robots.txt { access_log off; log_not_found off; } + + error_page 404 /index.html; + + location ~ /\.(?!well-known).* { + deny all; + } +} diff --git a/app/SSH/Storage/scripts/dropbox/delete-file.sh b/resources/views/ssh/storage/dropbox/delete-file.blade.php similarity index 65% rename from app/SSH/Storage/scripts/dropbox/delete-file.sh rename to resources/views/ssh/storage/dropbox/delete-file.blade.php index 5b81eea..2a6896c 100644 --- a/app/SSH/Storage/scripts/dropbox/delete-file.sh +++ b/resources/views/ssh/storage/dropbox/delete-file.blade.php @@ -1,6 +1,6 @@ curl --location --request POST 'https://api.dropboxapi.com/2/files/delete_v2' \ ---header 'Authorization: Bearer __token__' \ +--header 'Authorization: Bearer {{ $token }}' \ --header 'Content-Type: application/json' \ --data-raw '{ - "path": "__src__" + "path": "{{ $src }}" }' diff --git a/resources/views/ssh/storage/dropbox/download.blade.php b/resources/views/ssh/storage/dropbox/download.blade.php new file mode 100644 index 0000000..d33770f --- /dev/null +++ b/resources/views/ssh/storage/dropbox/download.blade.php @@ -0,0 +1,4 @@ +curl -o {{ $dest }} --location --request POST 'https://content.dropboxapi.com/2/files/download' \ +--header 'Accept: application/json' \ +--header 'Dropbox-API-Arg: {"path":"{{ $src }}"}' \ +--header 'Authorization: Bearer {{ $token }}' diff --git a/app/SSH/Storage/scripts/dropbox/upload.sh b/resources/views/ssh/storage/dropbox/upload.blade.php similarity index 59% rename from app/SSH/Storage/scripts/dropbox/upload.sh rename to resources/views/ssh/storage/dropbox/upload.blade.php index 82971a7..4f139af 100644 --- a/app/SSH/Storage/scripts/dropbox/upload.sh +++ b/resources/views/ssh/storage/dropbox/upload.blade.php @@ -1,6 +1,6 @@ curl -sb --location --request POST 'https://content.dropboxapi.com/2/files/upload' \ --header 'Accept: application/json' \ ---header 'Dropbox-API-Arg: {"path":"__dest__"}' \ +--header 'Dropbox-API-Arg: {"path":"{{ $dest }}"}' \ --header 'Content-Type: text/plain; charset=dropbox-cors-hack' \ ---header 'Authorization: Bearer __token__' \ ---data-binary '@__src__' +--header 'Authorization: Bearer {{ $token }}' \ +--data-binary '@{{ $src }}' diff --git a/resources/views/ssh/storage/ftp/delete-file.blade.php b/resources/views/ssh/storage/ftp/delete-file.blade.php new file mode 100644 index 0000000..22f4e0c --- /dev/null +++ b/resources/views/ssh/storage/ftp/delete-file.blade.php @@ -0,0 +1 @@ +curl {{ $passive }} -u "{{ $username }}:{{ $password }}" ftp{{ $ssl }}://{{ $host }}:{{ $port }}/{{ $src }} -Q "DELE /{{ $src }}" diff --git a/resources/views/ssh/storage/ftp/download.blade.php b/resources/views/ssh/storage/ftp/download.blade.php new file mode 100644 index 0000000..1158f9b --- /dev/null +++ b/resources/views/ssh/storage/ftp/download.blade.php @@ -0,0 +1 @@ +curl {{ $passive }} -u "{{ $username }}:{{ $password }}" ftp{{ $ssl }}://{{ $host }}:{{ $port }}/{{ $src }} -o "{{ $dest }}" diff --git a/resources/views/ssh/storage/ftp/upload.blade.php b/resources/views/ssh/storage/ftp/upload.blade.php new file mode 100644 index 0000000..fa245dc --- /dev/null +++ b/resources/views/ssh/storage/ftp/upload.blade.php @@ -0,0 +1 @@ +curl {{ $passive }} -T "{{ $src }}" -u "{{ $username }}:{{ $password }}" ftp{{ $ssl }}://{{ $host }}:{{ $port }}/{{ $dest }} diff --git a/resources/views/ssh/storage/local/download.blade.php b/resources/views/ssh/storage/local/download.blade.php new file mode 100644 index 0000000..eb2a723 --- /dev/null +++ b/resources/views/ssh/storage/local/download.blade.php @@ -0,0 +1 @@ +cp {{ $src }} {{ $dest }} diff --git a/resources/views/ssh/storage/local/upload.blade.php b/resources/views/ssh/storage/local/upload.blade.php new file mode 100644 index 0000000..9a4a0cf --- /dev/null +++ b/resources/views/ssh/storage/local/upload.blade.php @@ -0,0 +1,2 @@ +mkdir -p {{ $destDir }} +cp {{ $src }} {{ $destFile }} diff --git a/app/SSH/Storage/scripts/s3/delete-file.sh b/resources/views/ssh/storage/s3/delete-file.blade.php similarity index 71% rename from app/SSH/Storage/scripts/s3/delete-file.sh rename to resources/views/ssh/storage/s3/delete-file.blade.php index b607c2d..8c58ad9 100644 --- a/app/SSH/Storage/scripts/s3/delete-file.sh +++ b/resources/views/ssh/storage/s3/delete-file.blade.php @@ -22,9 +22,9 @@ exit 1 fi -export AWS_ACCESS_KEY_ID=__key__ -export AWS_SECRET_ACCESS_KEY=__secret__ -export AWS_DEFAULT_REGION=__region__ -export AWS_ENDPOINT_URL=__endpoint__ +export AWS_ACCESS_KEY_ID={{ $key }} +export AWS_SECRET_ACCESS_KEY={{ $secret }} +export AWS_DEFAULT_REGION={{ $region }} +export AWS_ENDPOINT_URL={{ $endpoint }} -aws s3 rm s3://__bucket__/__src__ +aws s3 rm s3://{{ $bucket }}/{{ $src }} diff --git a/app/SSH/Storage/scripts/s3/download.sh b/resources/views/ssh/storage/s3/download.blade.php similarity index 71% rename from app/SSH/Storage/scripts/s3/download.sh rename to resources/views/ssh/storage/s3/download.blade.php index 7c2ddcc..29f0dfd 100644 --- a/app/SSH/Storage/scripts/s3/download.sh +++ b/resources/views/ssh/storage/s3/download.blade.php @@ -22,11 +22,11 @@ exit 1 fi -export AWS_ACCESS_KEY_ID=__key__ -export AWS_SECRET_ACCESS_KEY=__secret__ -export AWS_DEFAULT_REGION=__region__ -export AWS_ENDPOINT_URL=__endpoint__ +export AWS_ACCESS_KEY_ID={{ $key }} +export AWS_SECRET_ACCESS_KEY={{ $secret }} +export AWS_DEFAULT_REGION={{ $region }} +export AWS_ENDPOINT_URL={{ $endpoint }} -if aws s3 cp s3://__bucket__/__src__ __dest__; then +if aws s3 cp s3://{{ $bucket }}/{{ $src }} {{ $dest }}; then echo "Download successful" fi diff --git a/app/SSH/Storage/scripts/s3/upload.sh b/resources/views/ssh/storage/s3/upload.blade.php similarity index 70% rename from app/SSH/Storage/scripts/s3/upload.sh rename to resources/views/ssh/storage/s3/upload.blade.php index 4d6892a..dff29fa 100644 --- a/app/SSH/Storage/scripts/s3/upload.sh +++ b/resources/views/ssh/storage/s3/upload.blade.php @@ -22,11 +22,11 @@ exit 1 fi -export AWS_ACCESS_KEY_ID=__key__ -export AWS_SECRET_ACCESS_KEY=__secret__ -export AWS_DEFAULT_REGION=__region__ -export AWS_ENDPOINT_URL=__endpoint__ +export AWS_ACCESS_KEY_ID={{ $key }} +export AWS_SECRET_ACCESS_KEY={{ $secret }} +export AWS_DEFAULT_REGION={{ $region }} +export AWS_ENDPOINT_URL={{ $endpoint }} -if aws s3 cp __src__ s3://__bucket__/__dest__; then +if aws s3 cp {{ $src }} s3://{{ $bucket }}/{{ $dest }}; then echo "Upload successful" fi diff --git a/resources/views/ssh/wordpress/install.blade.php b/resources/views/ssh/wordpress/install.blade.php new file mode 100644 index 0000000..0e18dfc --- /dev/null +++ b/resources/views/ssh/wordpress/install.blade.php @@ -0,0 +1,40 @@ +if ! curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! chmod +x wp-cli.phar; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if [ "{{ $isIsolated }}" == "true" ]; then + mv wp-cli.phar /home/{{ $isolatedUsername }}/bin/ + ln -s /home/{{ $isolatedUsername }}/bin/wp-cli.phar /home/{{ $isolatedUsername }}/bin/wp +else + if ! sudo mv wp-cli.phar /usr/local/bin/wp; then + echo 'VITO_SSH_ERROR' && exit 1 + fi +fi + +rm -rf {{ $path }} + +if ! wp --path={{ $path }} core download; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! wp --path={{ $path }} core config \ + --dbname="{{ $dbName }}" \ + --dbuser="{{ $dbUser }}" \ + --dbpass="{{ $dbPass }}" \ + --dbhost="{{ $dbHost }}" \ + --dbprefix="{{ $dbPrefix }}"; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! wp --path={{ $path }} core install \ + --url="http://{{ $domain }}" \ + --title="{{ $title }}" \ + --admin_user="{{ $username }}" \ + --admin_password="{{ $password }}" \ + --admin_email="{{ $email }}"; then + echo 'VITO_SSH_ERROR' && exit 1 +fi