mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-20 02:11:36 +00:00
use blade as conmmands template (#444)
* use blade as conmmands template * fix lint * fix ssl
This commit is contained in:
parent
a73476c1dd
commit
cdbde063f0
@ -12,3 +12,4 @@ sail
|
|||||||
*.yml
|
*.yml
|
||||||
!*.blade.php
|
!*.blade.php
|
||||||
!*.sh
|
!*.sh
|
||||||
|
resources/views/ssh/
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
use App\Models\Queue;
|
use App\Models\Queue;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
|
use App\SSH\Services\ProcessManager\ProcessManager;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
@ -29,7 +30,9 @@ public function create(mixed $queueable, array $input): void
|
|||||||
$queue->save();
|
$queue->save();
|
||||||
|
|
||||||
dispatch(function () use ($queue) {
|
dispatch(function () use ($queue) {
|
||||||
$queue->server->processManager()->handler()->create(
|
/** @var ProcessManager $processManager */
|
||||||
|
$processManager = $queue->server->processManager()->handler();
|
||||||
|
$processManager->create(
|
||||||
$queue->id,
|
$queue->id,
|
||||||
$queue->command,
|
$queue->command,
|
||||||
$queue->user,
|
$queue->user,
|
||||||
|
@ -44,6 +44,7 @@ public function create(Site $site, array $input): void
|
|||||||
$webserver->setupSSL($ssl);
|
$webserver->setupSSL($ssl);
|
||||||
$ssl->status = SslStatus::CREATED;
|
$ssl->status = SslStatus::CREATED;
|
||||||
$ssl->save();
|
$ssl->save();
|
||||||
|
$webserver->updateVHost($site);
|
||||||
$site->type()->edit();
|
$site->type()->edit();
|
||||||
})->catch(function () use ($ssl) {
|
})->catch(function () use ($ssl) {
|
||||||
$ssl->status = SslStatus::FAILED;
|
$ssl->status = SslStatus::FAILED;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Actions\SSL;
|
namespace App\Actions\SSL;
|
||||||
|
|
||||||
|
use App\Enums\SslStatus;
|
||||||
use App\Models\Ssl;
|
use App\Models\Ssl;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
|
|
||||||
@ -9,6 +10,8 @@ class DeleteSSL
|
|||||||
{
|
{
|
||||||
public function delete(Ssl $ssl): void
|
public function delete(Ssl $ssl): void
|
||||||
{
|
{
|
||||||
|
$ssl->status = SslStatus::DELETING;
|
||||||
|
$ssl->save();
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $ssl->site->server->webserver()->handler();
|
$webserver = $ssl->site->server->webserver()->handler();
|
||||||
$webserver->removeSSL($ssl);
|
$webserver->removeSSL($ssl);
|
||||||
|
@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\Services\PHP\PHP;
|
use App\SSH\Services\PHP\PHP;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
|
|
||||||
class DeleteSite
|
class DeleteSite
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function delete(Site $site): void
|
public function delete(Site $site): void
|
||||||
{
|
{
|
||||||
/** @var Webserver $webserverHandler */
|
/** @var Webserver $webserverHandler */
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use App\Enums\DeploymentStatus;
|
use App\Enums\DeploymentStatus;
|
||||||
use App\Exceptions\DeploymentScriptIsEmptyException;
|
use App\Exceptions\DeploymentScriptIsEmptyException;
|
||||||
use App\Exceptions\SourceControlIsNotConnected;
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Deployment;
|
use App\Models\Deployment;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
@ -12,8 +12,8 @@
|
|||||||
class Deploy
|
class Deploy
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws SourceControlIsNotConnected
|
|
||||||
* @throws DeploymentScriptIsEmptyException
|
* @throws DeploymentScriptIsEmptyException
|
||||||
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function run(Site $site): Deployment
|
public function run(Site $site): Deployment
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ public function update(Site $site, array $input): void
|
|||||||
|
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $site->server->webserver()->handler();
|
$webserver = $site->server->webserver()->handler();
|
||||||
$webserver->updateVHost($site, ! $site->hasSSL());
|
$webserver->updateVHost($site);
|
||||||
|
|
||||||
$site->save();
|
$site->save();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\Git\Git;
|
use App\SSH\Git\Git;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
@ -10,6 +11,7 @@ class UpdateBranch
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function update(Site $site, array $input): void
|
public function update(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Actions\Site;
|
namespace App\Actions\Site;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use Illuminate\Validation\Rule;
|
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
|
public function update(Site $site, array $input): void
|
||||||
{
|
{
|
||||||
$site->changePHPVersion($input['version']);
|
$site->changePHPVersion($input['version']);
|
||||||
|
@ -5,11 +5,7 @@
|
|||||||
use App\Actions\Service\Manage;
|
use App\Actions\Service\Manage;
|
||||||
use App\Enums\ServiceStatus;
|
use App\Enums\ServiceStatus;
|
||||||
use App\Exceptions\ServiceInstallationFailed;
|
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\ServiceInterface;
|
||||||
use App\SSH\Services\WebServer\WebServer as WebServerAlias;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -79,9 +75,6 @@ public function server(): BelongsTo
|
|||||||
return $this->belongsTo(Server::class);
|
return $this->belongsTo(Server::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return ProcessManager|DatabaseAlias|PHPAlias|WebServerAlias
|
|
||||||
*/
|
|
||||||
public function handler(): ServiceInterface
|
public function handler(): ServiceInterface
|
||||||
{
|
{
|
||||||
$handler = config('core.service_handlers')[$this->name];
|
$handler = config('core.service_handlers')[$this->name];
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\SiteStatus;
|
use App\Enums\SiteStatus;
|
||||||
|
use App\Enums\SslStatus;
|
||||||
use App\Exceptions\FailedToDestroyGitHook;
|
use App\Exceptions\FailedToDestroyGitHook;
|
||||||
use App\Exceptions\SourceControlIsNotConnected;
|
use App\Exceptions\SourceControlIsNotConnected;
|
||||||
use App\Exceptions\SSHError;
|
use App\Exceptions\SSHError;
|
||||||
@ -35,6 +36,7 @@
|
|||||||
* @property int $port
|
* @property int $port
|
||||||
* @property int $progress
|
* @property int $progress
|
||||||
* @property string $user
|
* @property string $user
|
||||||
|
* @property bool $force_ssl
|
||||||
* @property Server $server
|
* @property Server $server
|
||||||
* @property ServerLog[] $logs
|
* @property ServerLog[] $logs
|
||||||
* @property Deployment[] $deployments
|
* @property Deployment[] $deployments
|
||||||
@ -198,6 +200,9 @@ public function php(): ?Service
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function changePHPVersion($version): void
|
public function changePHPVersion($version): void
|
||||||
{
|
{
|
||||||
/** @var Webserver $handler */
|
/** @var Webserver $handler */
|
||||||
@ -219,6 +224,7 @@ public function activeSsl(): HasOne
|
|||||||
{
|
{
|
||||||
return $this->hasOne(Ssl::class)
|
return $this->hasOne(Ssl::class)
|
||||||
->where('expires_at', '>=', now())
|
->where('expires_at', '>=', now())
|
||||||
|
->where('status', SslStatus::CREATED)
|
||||||
->orderByDesc('id');
|
->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
|
public function environmentVariables(?Deployment $deployment = null): array
|
||||||
{
|
{
|
||||||
return [
|
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
|
public function isIsolated(): bool
|
||||||
{
|
{
|
||||||
return $this->user != $this->server->getSshUser();
|
return $this->user != $this->server->getSshUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function webserver(): Webserver
|
||||||
|
{
|
||||||
|
/** @var Webserver $webserver */
|
||||||
|
$webserver = $this->server->webserver()->handler();
|
||||||
|
|
||||||
|
return $webserver;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,20 @@
|
|||||||
|
|
||||||
namespace App\SSH\Composer;
|
namespace App\SSH\Composer;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
|
|
||||||
class Composer
|
class Composer
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function installDependencies(Site $site): void
|
public function installDependencies(Site $site): void
|
||||||
{
|
{
|
||||||
$site->server->ssh($site->user)->exec(
|
$site->server->ssh($site->user)->exec(
|
||||||
$this->getScript('composer-install.sh', [
|
view('ssh.composer.composer-install', [
|
||||||
'path' => $site->path,
|
'path' => $site->path,
|
||||||
'php_version' => $site->php_version,
|
'phpVersion' => $site->php_version,
|
||||||
]),
|
]),
|
||||||
'composer-install',
|
'composer-install',
|
||||||
$site->id
|
$site->id
|
||||||
|
@ -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
|
|
@ -2,26 +2,24 @@
|
|||||||
|
|
||||||
namespace App\SSH\Cron;
|
namespace App\SSH\Cron;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
|
||||||
class Cron
|
class Cron
|
||||||
{
|
{
|
||||||
public function __construct(protected Server $server) {}
|
public function __construct(protected Server $server) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function update(string $user, string $cron): void
|
public function update(string $user, string $cron): void
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$this->server->ssh()->exec(
|
||||||
if ! echo '$cron' | sudo -u $user crontab -; then
|
view('ssh.cron.update', [
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
'cron' => $cron,
|
||||||
fi
|
'user' => $user,
|
||||||
|
]),
|
||||||
if ! sudo -u $user crontab -l; then
|
'update-cron'
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
);
|
||||||
fi
|
|
||||||
|
|
||||||
echo 'cron updated!'
|
|
||||||
EOD;
|
|
||||||
|
|
||||||
$this->server->ssh()->exec($command, 'update-cron');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
namespace App\SSH\Git;
|
namespace App\SSH\Git;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
|
|
||||||
class Git
|
class Git
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function clone(Site $site): void
|
public function clone(Site $site): void
|
||||||
{
|
{
|
||||||
$site->server->ssh($site->user)->exec(
|
$site->server->ssh($site->user)->exec(
|
||||||
$this->getScript('clone.sh', [
|
view('ssh.git.clone', [
|
||||||
'host' => str($site->getFullRepositoryUrl())->after('@')->before('-'),
|
'host' => str($site->getFullRepositoryUrl())->after('@')->before('-'),
|
||||||
'repo' => $site->getFullRepositoryUrl(),
|
'repo' => $site->getFullRepositoryUrl(),
|
||||||
'path' => $site->path,
|
'path' => $site->path,
|
||||||
@ -24,10 +25,13 @@ public function clone(Site $site): void
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function checkout(Site $site): void
|
public function checkout(Site $site): void
|
||||||
{
|
{
|
||||||
$site->server->ssh($site->user)->exec(
|
$site->server->ssh($site->user)->exec(
|
||||||
$this->getScript('checkout.sh', [
|
view('ssh.git.checkout', [
|
||||||
'path' => $site->path,
|
'path' => $site->path,
|
||||||
'branch' => $site->branch,
|
'branch' => $site->branch,
|
||||||
]),
|
]),
|
||||||
|
@ -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
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace App\SSH\OS;
|
namespace App\SSH\OS;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Exceptions\SSHUploadFailed;
|
use App\Exceptions\SSHUploadFailed;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
use Illuminate\Filesystem\FilesystemAdapter;
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -14,30 +14,40 @@
|
|||||||
|
|
||||||
class OS
|
class OS
|
||||||
{
|
{
|
||||||
use HasScripts;
|
|
||||||
|
|
||||||
public function __construct(protected Server $server) {}
|
public function __construct(protected Server $server) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function installDependencies(): void
|
public function installDependencies(): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$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'
|
'install-dependencies'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function upgrade(): void
|
public function upgrade(): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('upgrade.sh'),
|
view('ssh.os.upgrade'),
|
||||||
'upgrade'
|
'upgrade'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function availableUpdates(): int
|
public function availableUpdates(): int
|
||||||
{
|
{
|
||||||
$result = $this->server->ssh()->exec(
|
$result = $this->server->ssh()->exec(
|
||||||
$this->getScript('available-updates.sh'),
|
view('ssh.os.available-updates'),
|
||||||
'check-available-updates'
|
'check-available-updates'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -47,10 +57,13 @@ public function availableUpdates(): int
|
|||||||
return max($availableUpdates, 0);
|
return max($availableUpdates, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function createUser(string $user, string $password, string $key): void
|
public function createUser(string $user, string $password, string $key): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('create-user.sh', [
|
view('ssh.os.create-user', [
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'key' => $key,
|
'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
|
public function createIsolatedUser(string $user, string $password, int $site_id): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('create-isolated-user.sh', [
|
view('ssh.os.create-isolated-user', [
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'server_user' => $this->server->getSshUser(),
|
'serverUser' => $this->server->getSshUser(),
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
]),
|
]),
|
||||||
'create-isolated-user',
|
'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
|
public function deleteIsolatedUser(string $user): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('delete-isolated-user.sh', [
|
view('ssh.os.delete-isolated-user', [
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'server_user' => $this->server->getSshUser(),
|
'serverUser' => $this->server->getSshUser(),
|
||||||
]),
|
]),
|
||||||
'delete-isolated-user'
|
'delete-isolated-user'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function getPublicKey(string $user): string
|
public function getPublicKey(string $user): string
|
||||||
{
|
{
|
||||||
return $this->server->ssh()->exec(
|
return $this->server->ssh()->exec(
|
||||||
$this->getScript('read-file.sh', [
|
view('ssh.os.read-file', [
|
||||||
'path' => '/home/'.$user.'/.ssh/id_rsa.pub',
|
'path' => '/home/'.$user.'/.ssh/id_rsa.pub',
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function deploySSHKey(string $key): void
|
public function deploySSHKey(string $key): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('deploy-ssh-key.sh', [
|
view('ssh.os.deploy-ssh-key', [
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
]),
|
]),
|
||||||
'deploy-ssh-key'
|
'deploy-ssh-key'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function deleteSSHKey(string $key): void
|
public function deleteSSHKey(string $key): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('delete-ssh-key.sh', [
|
view('ssh.os.delete-ssh-key', [
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'user' => $this->server->getSshUser(),
|
'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
|
public function generateSSHKey(string $name, ?Site $site = null): void
|
||||||
{
|
{
|
||||||
$site->server->ssh($site->user)->exec(
|
$site->server->ssh($site->user)->exec(
|
||||||
$this->getScript('generate-ssh-key.sh', [
|
view('ssh.os.generate-ssh-key', [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
]),
|
]),
|
||||||
'generate-ssh-key',
|
'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
|
public function readSSHKey(string $name, ?Site $site = null): string
|
||||||
{
|
{
|
||||||
return $site->server->ssh($site->user)->exec(
|
return $site->server->ssh($site->user)->exec(
|
||||||
$this->getScript('read-ssh-key.sh', [
|
view('ssh.os.read-ssh-key', [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function reboot(): void
|
public function reboot(): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$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
|
public function readFile(string $path): string
|
||||||
{
|
{
|
||||||
return $this->server->ssh()->exec(
|
return $this->server->ssh()->exec(
|
||||||
$this->getScript('read-file.sh', [
|
view('ssh.os.read-file', [
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function tail(string $path, int $lines): string
|
public function tail(string $path, int $lines): string
|
||||||
{
|
{
|
||||||
return $this->server->ssh()->exec(
|
return $this->server->ssh()->exec(
|
||||||
$this->getScript('tail.sh', [
|
view('ssh.os.tail', [
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'lines' => $lines,
|
'lines' => $lines,
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function runScript(string $path, string $script, ?ServerLog $serverLog, ?string $user = null, ?array $variables = []): ServerLog
|
public function runScript(string $path, string $script, ?ServerLog $serverLog, ?string $user = null, ?array $variables = []): ServerLog
|
||||||
{
|
{
|
||||||
$ssh = $this->server->ssh($user);
|
$ssh = $this->server->ssh($user);
|
||||||
@ -190,7 +236,7 @@ public function runScript(string $path, string $script, ?ServerLog $serverLog, ?
|
|||||||
foreach ($variables as $key => $variable) {
|
foreach ($variables as $key => $variable) {
|
||||||
$command .= "$key=$variable\n";
|
$command .= "$key=$variable\n";
|
||||||
}
|
}
|
||||||
$command .= $this->getScript('run-script.sh', [
|
$command .= view('ssh.os.run-script', [
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'script' => $script,
|
'script' => $script,
|
||||||
]);
|
]);
|
||||||
@ -201,16 +247,22 @@ public function runScript(string $path, string $script, ?ServerLog $serverLog, ?
|
|||||||
return $ssh->log;
|
return $ssh->log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function download(string $url, string $path): string
|
public function download(string $url, string $path): string
|
||||||
{
|
{
|
||||||
return $this->server->ssh()->exec(
|
return $this->server->ssh()->exec(
|
||||||
$this->getScript('download.sh', [
|
view('ssh.os.download', [
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function unzip(string $path): string
|
public function unzip(string $path): string
|
||||||
{
|
{
|
||||||
return $this->server->ssh()->exec(
|
return $this->server->ssh()->exec(
|
||||||
@ -218,18 +270,24 @@ public function unzip(string $path): string
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function cleanup(): void
|
public function cleanup(): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('cleanup.sh'),
|
view('ssh.os.cleanup'),
|
||||||
'cleanup'
|
'cleanup'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function resourceInfo(): array
|
public function resourceInfo(): array
|
||||||
{
|
{
|
||||||
$info = $this->server->ssh()->exec(
|
$info = $this->server->ssh()->exec(
|
||||||
$this->getScript('resource-info.sh'),
|
view('ssh.os.resource-info'),
|
||||||
);
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -243,10 +301,13 @@ public function resourceInfo(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function deleteFile(string $path): void
|
public function deleteFile(string $path): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('delete-file.sh', [
|
view('ssh.os.delete-file', [
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
]),
|
]),
|
||||||
'delete-file'
|
'delete-file'
|
||||||
|
@ -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__."
|
|
@ -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
|
|
@ -1 +0,0 @@
|
|||||||
rm -f __path__
|
|
@ -1,3 +0,0 @@
|
|||||||
sudo gpasswd -d __server_user__ __user__
|
|
||||||
sudo userdel -r "__user__"
|
|
||||||
echo "User __user__ has been deleted."
|
|
@ -1,3 +0,0 @@
|
|||||||
if ! echo '__key__' | sudo tee -a ~/.ssh/authorized_keys; then
|
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
|
||||||
fi
|
|
@ -1,3 +0,0 @@
|
|||||||
if ! wget __url__ -O __path__; then
|
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
|
||||||
fi
|
|
@ -1 +0,0 @@
|
|||||||
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/__name__
|
|
@ -1 +0,0 @@
|
|||||||
[ -f __path__ ] && sudo cat __path__
|
|
@ -1 +0,0 @@
|
|||||||
cat ~/.ssh/__name__.pub
|
|
@ -1 +0,0 @@
|
|||||||
sudo tail -n __lines__ __path__
|
|
@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
namespace App\SSH\PHPMyAdmin;
|
namespace App\SSH\PHPMyAdmin;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
|
|
||||||
class PHPMyAdmin
|
class PHPMyAdmin
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(Site $site): void
|
public function install(Site $site): void
|
||||||
{
|
{
|
||||||
$site->server->ssh($site->user)->exec(
|
$site->server->ssh($site->user)->exec(
|
||||||
$this->getScript('install.sh', [
|
view('ssh.phpmyadmin.install', [
|
||||||
'version' => $site->type_data['version'],
|
'version' => $site->type_data['version'],
|
||||||
'path' => $site->path,
|
'path' => $site->path,
|
||||||
]),
|
]),
|
||||||
|
@ -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!"
|
|
@ -3,16 +3,18 @@
|
|||||||
namespace App\SSH\Services\Database;
|
namespace App\SSH\Services\Database;
|
||||||
|
|
||||||
use App\Enums\BackupStatus;
|
use App\Enums\BackupStatus;
|
||||||
|
use App\Exceptions\ServiceInstallationFailed;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\BackupFile;
|
use App\Models\BackupFile;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
use App\SSH\Services\AbstractService;
|
use App\SSH\Services\AbstractService;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
|
||||||
abstract class AbstractDatabase extends AbstractService implements Database
|
abstract class AbstractDatabase extends AbstractService implements Database
|
||||||
{
|
{
|
||||||
use HasScripts;
|
protected function getScriptView(string $script): string
|
||||||
|
{
|
||||||
abstract protected function getScriptsDir(): string;
|
return 'ssh.services.database.'.$this->service->name.'.'.$script;
|
||||||
|
}
|
||||||
|
|
||||||
public function creationRules(array $input): array
|
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
|
public function install(): void
|
||||||
{
|
{
|
||||||
$version = $this->service->version;
|
$version = str_replace('.', '', $this->service->version);
|
||||||
$command = $this->getScript($this->service->name.'/install-'.$version.'.sh');
|
$command = view($this->getScriptView('install-'.$version));
|
||||||
$this->service->server->ssh()->exec($command, 'install-'.$this->service->name.'-'.$version);
|
$this->service->server->ssh()->exec($command, 'install-'.$this->service->name.'-'.$version);
|
||||||
$status = $this->service->server->systemd()->status($this->service->unit);
|
$status = $this->service->server->systemd()->status($this->service->unit);
|
||||||
$this->service->validateInstall($status);
|
$this->service->validateInstall($status);
|
||||||
@ -63,38 +69,50 @@ function (string $attribute, mixed $value, Closure $fail) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function uninstall(): void
|
public function uninstall(): void
|
||||||
{
|
{
|
||||||
$version = $this->service->version;
|
$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->ssh()->exec($command, 'uninstall-'.$this->service->name.'-'.$version);
|
||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function create(string $name): void
|
public function create(string $name): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript($this->getScriptsDir().'/create.sh', [
|
view($this->getScriptView('create'), [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
]),
|
]),
|
||||||
'create-database'
|
'create-database'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function delete(string $name): void
|
public function delete(string $name): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript($this->getScriptsDir().'/delete.sh', [
|
view($this->getScriptView('delete'), [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
]),
|
]),
|
||||||
'delete-database'
|
'delete-database'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function createUser(string $username, string $password, string $host): void
|
public function createUser(string $username, string $password, string $host): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript($this->getScriptsDir().'/create-user.sh', [
|
view($this->getScriptView('create-user'), [
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'host' => $host,
|
'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
|
public function deleteUser(string $username, string $host): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript($this->getScriptsDir().'/delete-user.sh', [
|
view($this->getScriptView('delete-user'), [
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'host' => $host,
|
'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
|
public function link(string $username, string $host, array $databases): void
|
||||||
{
|
{
|
||||||
$ssh = $this->service->server->ssh();
|
$ssh = $this->service->server->ssh();
|
||||||
@ -121,7 +145,7 @@ public function link(string $username, string $host, array $databases): void
|
|||||||
|
|
||||||
foreach ($databases as $database) {
|
foreach ($databases as $database) {
|
||||||
$ssh->exec(
|
$ssh->exec(
|
||||||
$this->getScript($this->getScriptsDir().'/link.sh', [
|
view($this->getScriptView('link'), [
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
'database' => $database,
|
'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
|
public function unlink(string $username, string $host): void
|
||||||
{
|
{
|
||||||
$version = $this->service->version;
|
$version = $this->service->version;
|
||||||
|
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript($this->getScriptsDir().'/unlink.sh', [
|
view($this->getScriptView('unlink'), [
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
@ -146,11 +173,14 @@ public function unlink(string $username, string $host): void
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function runBackup(BackupFile $backupFile): void
|
public function runBackup(BackupFile $backupFile): void
|
||||||
{
|
{
|
||||||
// backup
|
// backup
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript($this->getScriptsDir().'/backup.sh', [
|
view($this->getScriptView('backup'), [
|
||||||
'file' => $backupFile->name,
|
'file' => $backupFile->name,
|
||||||
'database' => $backupFile->backup->database->name,
|
'database' => $backupFile->backup->database->name,
|
||||||
]),
|
]),
|
||||||
@ -170,6 +200,9 @@ public function runBackup(BackupFile $backupFile): void
|
|||||||
$backupFile->save();
|
$backupFile->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function restoreBackup(BackupFile $backupFile, string $database): void
|
public function restoreBackup(BackupFile $backupFile, string $database): void
|
||||||
{
|
{
|
||||||
// download
|
// download
|
||||||
@ -179,7 +212,7 @@ public function restoreBackup(BackupFile $backupFile, string $database): void
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript($this->getScriptsDir().'/restore.sh', [
|
view($this->getScriptView('restore'), [
|
||||||
'database' => $database,
|
'database' => $database,
|
||||||
'file' => rtrim($backupFile->tempPath(), '.zip'),
|
'file' => rtrim($backupFile->tempPath(), '.zip'),
|
||||||
]),
|
]),
|
||||||
|
@ -4,8 +4,5 @@
|
|||||||
|
|
||||||
class Mariadb extends AbstractDatabase
|
class Mariadb extends AbstractDatabase
|
||||||
{
|
{
|
||||||
protected function getScriptsDir(): string
|
//
|
||||||
{
|
|
||||||
return 'mysql';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,5 @@
|
|||||||
|
|
||||||
class Mysql extends AbstractDatabase
|
class Mysql extends AbstractDatabase
|
||||||
{
|
{
|
||||||
protected function getScriptsDir(): string
|
//
|
||||||
{
|
|
||||||
return 'mysql';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,26 +2,7 @@
|
|||||||
|
|
||||||
namespace App\SSH\Services\Database;
|
namespace App\SSH\Services\Database;
|
||||||
|
|
||||||
use App\Exceptions\SSHError;
|
|
||||||
|
|
||||||
class Postgresql extends AbstractDatabase
|
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'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
@ -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"
|
|
@ -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"
|
|
@ -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
|
|
@ -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"
|
|
@ -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
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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
|
|
@ -2,16 +2,17 @@
|
|||||||
|
|
||||||
namespace App\SSH\Services\Firewall;
|
namespace App\SSH\Services\Firewall;
|
||||||
|
|
||||||
use App\SSH\HasScripts;
|
use App\Exceptions\SSHError;
|
||||||
|
|
||||||
class Ufw extends AbstractFirewall
|
class Ufw extends AbstractFirewall
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('ufw/install-ufw.sh'),
|
view('ssh.services.firewall.ufw.install-ufw'),
|
||||||
'install-ufw'
|
'install-ufw'
|
||||||
);
|
);
|
||||||
$this->service->server->os()->cleanup();
|
$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
|
public function addRule(string $type, string $protocol, int $port, string $source, ?string $mask): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('ufw/add-rule.sh', [
|
view('ssh.services.firewall.ufw.add-rule', [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'protocol' => $protocol,
|
'protocol' => $protocol,
|
||||||
'port' => $port,
|
'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
|
public function removeRule(string $type, string $protocol, int $port, string $source, ?string $mask): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('ufw/remove-rule.sh', [
|
view('ssh.services.firewall.ufw.remove-rule', [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'protocol' => $protocol,
|
'protocol' => $protocol,
|
||||||
'port' => $port,
|
'port' => $port,
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
namespace App\SSH\Services\Monitoring\VitoAgent;
|
namespace App\SSH\Services\Monitoring\VitoAgent;
|
||||||
|
|
||||||
|
use App\Exceptions\ServiceInstallationFailed;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Metric;
|
use App\Models\Metric;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
use App\SSH\Services\AbstractService;
|
use App\SSH\Services\AbstractService;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
@ -12,8 +13,6 @@
|
|||||||
|
|
||||||
class VitoAgent extends AbstractService
|
class VitoAgent extends AbstractService
|
||||||
{
|
{
|
||||||
use HasScripts;
|
|
||||||
|
|
||||||
const TAGS_URL = 'https://api.github.com/repos/vitodeploy/agent/tags';
|
const TAGS_URL = 'https://api.github.com/repos/vitodeploy/agent/tags';
|
||||||
|
|
||||||
const DOWNLOAD_URL = 'https://github.com/vitodeploy/agent/releases/download/%s';
|
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
|
public function install(): void
|
||||||
{
|
{
|
||||||
$tags = Http::get(self::TAGS_URL)->json();
|
$tags = Http::get(self::TAGS_URL)->json();
|
||||||
if (empty($tags)) {
|
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->version = $tags[0]['name'];
|
||||||
$this->service->save();
|
$this->service->save();
|
||||||
@ -71,10 +74,10 @@ public function install(): void
|
|||||||
$this->service->refresh();
|
$this->service->refresh();
|
||||||
|
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('install.sh', [
|
view('ssh.services.monitoring.vito-agent.install', [
|
||||||
'download_url' => $downloadUrl,
|
'downloadUrl' => $downloadUrl,
|
||||||
'config_url' => $this->data()['url'],
|
'configUrl' => $this->data()['url'],
|
||||||
'config_secret' => $this->data()['secret'],
|
'configSecret' => $this->data()['secret'],
|
||||||
]),
|
]),
|
||||||
'install-vito-agent'
|
'install-vito-agent'
|
||||||
);
|
);
|
||||||
@ -82,12 +85,15 @@ public function install(): void
|
|||||||
$this->service->validateInstall($status);
|
$this->service->validateInstall($status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function uninstall(): void
|
public function uninstall(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('uninstall.sh'),
|
view('ssh.services.monitoring.vito-agent.uninstall'),
|
||||||
'uninstall-vito-agent'
|
'uninstall-vito-agent'
|
||||||
);
|
);
|
||||||
Metric::where('server_id', $this->service->server_id)->delete();
|
Metric::query()->where('server_id', $this->service->server_id)->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,13 @@
|
|||||||
|
|
||||||
namespace App\SSH\Services\NodeJS;
|
namespace App\SSH\Services\NodeJS;
|
||||||
|
|
||||||
use App\SSH\HasScripts;
|
use App\Exceptions\SSHError;
|
||||||
use App\SSH\Services\AbstractService;
|
use App\SSH\Services\AbstractService;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class NodeJS extends AbstractService
|
class NodeJS extends AbstractService
|
||||||
{
|
{
|
||||||
use HasScripts;
|
|
||||||
|
|
||||||
public function creationRules(array $input): array
|
public function creationRules(array $input): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -41,34 +39,43 @@ function (string $attribute, mixed $value, Closure $fail) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$server = $this->service->server;
|
$server = $this->service->server;
|
||||||
$server->ssh()->exec(
|
$server->ssh()->exec(
|
||||||
$this->getScript('install-nodejs.sh', [
|
view('ssh.services.nodejs.install-nodejs', [
|
||||||
'version' => $this->service->version,
|
'version' => $this->service->version,
|
||||||
'user' => $server->getSshUser(),
|
|
||||||
]),
|
]),
|
||||||
'install-nodejs-'.$this->service->version
|
'install-nodejs-'.$this->service->version
|
||||||
);
|
);
|
||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function uninstall(): void
|
public function uninstall(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('uninstall-nodejs.sh', [
|
view('ssh.services.nodejs.uninstall-nodejs', [
|
||||||
'version' => $this->service->version,
|
'version' => $this->service->version,
|
||||||
|
'default' => $this->service->is_default,
|
||||||
]),
|
]),
|
||||||
'uninstall-nodejs-'.$this->service->version
|
'uninstall-nodejs-'.$this->service->version
|
||||||
);
|
);
|
||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function setDefaultCli(): void
|
public function setDefaultCli(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('change-default-nodejs.sh', [
|
view('ssh.services.nodejs.change-default-nodejs', [
|
||||||
'version' => $this->service->version,
|
'version' => $this->service->version,
|
||||||
]),
|
]),
|
||||||
'change-default-nodejs'
|
'change-default-nodejs'
|
||||||
|
@ -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
|
|
@ -3,7 +3,7 @@
|
|||||||
namespace App\SSH\Services\PHP;
|
namespace App\SSH\Services\PHP;
|
||||||
|
|
||||||
use App\Exceptions\SSHCommandError;
|
use App\Exceptions\SSHCommandError;
|
||||||
use App\SSH\HasScripts;
|
use App\Exceptions\SSHError;
|
||||||
use App\SSH\Services\AbstractService;
|
use App\SSH\Services\AbstractService;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
class PHP extends AbstractService
|
class PHP extends AbstractService
|
||||||
{
|
{
|
||||||
use HasScripts;
|
|
||||||
|
|
||||||
public function creationRules(array $input): array
|
public function creationRules(array $input): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -43,11 +41,14 @@ function (string $attribute, mixed $value, Closure $fail) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$server = $this->service->server;
|
$server = $this->service->server;
|
||||||
$server->ssh()->exec(
|
$server->ssh()->exec(
|
||||||
$this->getScript('install-php.sh', [
|
view('ssh.services.php.install-php', [
|
||||||
'version' => $this->service->version,
|
'version' => $this->service->version,
|
||||||
'user' => $server->getSshUser(),
|
'user' => $server->getSshUser(),
|
||||||
]),
|
]),
|
||||||
@ -57,10 +58,13 @@ public function install(): void
|
|||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function uninstall(): void
|
public function uninstall(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('uninstall-php.sh', [
|
view('ssh.services.php.uninstall-php', [
|
||||||
'version' => $this->service->version,
|
'version' => $this->service->version,
|
||||||
]),
|
]),
|
||||||
'uninstall-php-'.$this->service->version
|
'uninstall-php-'.$this->service->version
|
||||||
@ -68,10 +72,13 @@ public function uninstall(): void
|
|||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function setDefaultCli(): void
|
public function setDefaultCli(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('change-default-php.sh', [
|
view('ssh.services.php.change-default-php', [
|
||||||
'version' => $this->service->version,
|
'version' => $this->service->version,
|
||||||
]),
|
]),
|
||||||
'change-default-php'
|
'change-default-php'
|
||||||
@ -79,12 +86,12 @@ public function setDefaultCli(): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws SSHCommandError
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function installExtension($name): void
|
public function installExtension($name): void
|
||||||
{
|
{
|
||||||
$result = $this->service->server->ssh()->exec(
|
$result = $this->service->server->ssh()->exec(
|
||||||
$this->getScript('install-php-extension.sh', [
|
view('ssh.services.php.install-php-extension', [
|
||||||
'version' => $this->service->version,
|
'version' => $this->service->version,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
]),
|
]),
|
||||||
@ -96,14 +103,20 @@ public function installExtension($name): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function installComposer(): void
|
public function installComposer(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('install-composer.sh'),
|
view('ssh.services.php.install-composer'),
|
||||||
'install-composer'
|
'install-composer'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function getPHPIni(string $type): string
|
public function getPHPIni(string $type): string
|
||||||
{
|
{
|
||||||
return $this->service->server->os()->readFile(
|
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
|
public function createFpmPool(string $user, string $version, $site_id): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->write(
|
||||||
$this->getScript('create-fpm-pool.sh', [
|
"/etc/php/{$version}/fpm/pool.d/{$user}.conf",
|
||||||
|
view('ssh.services.php.fpm-pool', [
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'config' => $this->getScript('fpm-pool.conf', [
|
|
||||||
'user' => $user,
|
|
||||||
'version' => $version,
|
|
||||||
]),
|
|
||||||
]),
|
]),
|
||||||
"create-{$version}fpm-pool-{$user}",
|
true
|
||||||
$site_id
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->service->server->systemd()->restart($this->service->unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function removeFpmPool(string $user, string $version, $site_id): void
|
public function removeFpmPool(string $user, string $version, $site_id): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('remove-fpm-pool.sh', [
|
view('ssh.services.php.remove-fpm-pool', [
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
]),
|
]),
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
echo '__config__' | sudo tee /etc/php/__version__/fpm/pool.d/__user__.conf
|
|
||||||
sudo service php__version__-fpm restart
|
|
@ -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
|
|
@ -1,5 +0,0 @@
|
|||||||
sudo apt-get install -y php__version__-__name__
|
|
||||||
|
|
||||||
sudo service php__version__-fpm restart
|
|
||||||
|
|
||||||
php__version__ -m
|
|
@ -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
|
|
@ -1,2 +0,0 @@
|
|||||||
sudo rm -f /etc/php/__version__/fpm/pool.d/__user__.conf
|
|
||||||
sudo service php__version__-fpm restart
|
|
@ -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
|
|
@ -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
|
|
@ -2,33 +2,37 @@
|
|||||||
|
|
||||||
namespace App\SSH\Services\ProcessManager;
|
namespace App\SSH\Services\ProcessManager;
|
||||||
|
|
||||||
use App\SSH\HasScripts;
|
use App\Exceptions\SSHError;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Supervisor extends AbstractProcessManager
|
class Supervisor extends AbstractProcessManager
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('supervisor/install-supervisor.sh'),
|
view('ssh.services.process-manager.supervisor.install-supervisor'),
|
||||||
'install-supervisor'
|
'install-supervisor'
|
||||||
);
|
);
|
||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function uninstall(): void
|
public function uninstall(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('supervisor/uninstall-supervisor.sh'),
|
view('ssh.services.process-manager.supervisor.uninstall-supervisor'),
|
||||||
'uninstall-supervisor'
|
'uninstall-supervisor'
|
||||||
);
|
);
|
||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Throwable
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function create(
|
public function create(
|
||||||
int $id,
|
int $id,
|
||||||
@ -42,21 +46,22 @@ public function create(
|
|||||||
): void {
|
): void {
|
||||||
$this->service->server->ssh()->write(
|
$this->service->server->ssh()->write(
|
||||||
"/etc/supervisor/conf.d/$id.conf",
|
"/etc/supervisor/conf.d/$id.conf",
|
||||||
$this->generateConfigFile(
|
view('ssh.services.process-manager.supervisor.worker', [
|
||||||
$id,
|
'name' => (string) $id,
|
||||||
$command,
|
'command' => $command,
|
||||||
$user,
|
'user' => $user,
|
||||||
$autoStart,
|
'autoStart' => var_export($autoStart, true),
|
||||||
$autoRestart,
|
'autoRestart' => var_export($autoRestart, true),
|
||||||
$numprocs,
|
'numprocs' => (string) $numprocs,
|
||||||
$logFile
|
'logFile' => $logFile,
|
||||||
),
|
]),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('supervisor/create-worker.sh', [
|
view('ssh.services.process-manager.supervisor.create-worker', [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'log_file' => $logFile,
|
'logFile' => $logFile,
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
]),
|
]),
|
||||||
'create-worker',
|
'create-worker',
|
||||||
@ -70,7 +75,7 @@ public function create(
|
|||||||
public function delete(int $id, ?int $siteId = null): void
|
public function delete(int $id, ?int $siteId = null): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('supervisor/delete-worker.sh', [
|
view('ssh.services.process-manager.supervisor.delete-worker', [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
]),
|
]),
|
||||||
'delete-worker',
|
'delete-worker',
|
||||||
@ -84,7 +89,7 @@ public function delete(int $id, ?int $siteId = null): void
|
|||||||
public function restart(int $id, ?int $siteId = null): void
|
public function restart(int $id, ?int $siteId = null): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('supervisor/restart-worker.sh', [
|
view('ssh.services.process-manager.supervisor.restart-worker', [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
]),
|
]),
|
||||||
'restart-worker',
|
'restart-worker',
|
||||||
@ -98,7 +103,7 @@ public function restart(int $id, ?int $siteId = null): void
|
|||||||
public function stop(int $id, ?int $siteId = null): void
|
public function stop(int $id, ?int $siteId = null): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('supervisor/stop-worker.sh', [
|
view('ssh.services.process-manager.supervisor.stop-worker', [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
]),
|
]),
|
||||||
'stop-worker',
|
'stop-worker',
|
||||||
@ -112,7 +117,7 @@ public function stop(int $id, ?int $siteId = null): void
|
|||||||
public function start(int $id, ?int $siteId = null): void
|
public function start(int $id, ?int $siteId = null): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('supervisor/start-worker.sh', [
|
view('ssh.services.process-manager.supervisor.start-worker', [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
]),
|
]),
|
||||||
'start-worker',
|
'start-worker',
|
||||||
@ -129,24 +134,4 @@ public function getLogs(string $user, string $logPath): string
|
|||||||
"tail -100 $logPath"
|
"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,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
if ! sudo supervisorctl restart __id__:*; then
|
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
|
||||||
fi
|
|
@ -1,3 +0,0 @@
|
|||||||
if ! sudo supervisorctl start __id__:*; then
|
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
|
||||||
fi
|
|
@ -1,3 +0,0 @@
|
|||||||
if ! sudo supervisorctl stop __id__:*; then
|
|
||||||
echo 'VITO_SSH_ERROR' && exit 1
|
|
||||||
fi
|
|
@ -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
|
|
@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
namespace App\SSH\Services\Redis;
|
namespace App\SSH\Services\Redis;
|
||||||
|
|
||||||
use App\SSH\HasScripts;
|
use App\Exceptions\ServiceInstallationFailed;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\SSH\Services\AbstractService;
|
use App\SSH\Services\AbstractService;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
|
||||||
class Redis extends AbstractService
|
class Redis extends AbstractService
|
||||||
{
|
{
|
||||||
use HasScripts;
|
|
||||||
|
|
||||||
public function creationRules(array $input): array
|
public function creationRules(array $input): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -25,10 +24,14 @@ function (string $attribute, mixed $value, Closure $fail) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ServiceInstallationFailed
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('install.sh'),
|
view('ssh.services.redis.install'),
|
||||||
'install-redis'
|
'install-redis'
|
||||||
);
|
);
|
||||||
$status = $this->service->server->systemd()->status($this->service->unit);
|
$status = $this->service->server->systemd()->status($this->service->unit);
|
||||||
@ -36,10 +39,13 @@ public function install(): void
|
|||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function uninstall(): void
|
public function uninstall(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('uninstall.sh'),
|
view('ssh.services.redis.uninstall'),
|
||||||
'uninstall-redis'
|
'uninstall-redis'
|
||||||
);
|
);
|
||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
|
@ -6,25 +6,31 @@
|
|||||||
use App\Exceptions\SSLCreationException;
|
use App\Exceptions\SSLCreationException;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\Models\Ssl;
|
use App\Models\Ssl;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Nginx extends AbstractWebserver
|
class Nginx extends AbstractWebserver
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('nginx/install-nginx.sh', [
|
view('ssh.services.webserver.nginx.install-nginx'),
|
||||||
'config' => $this->getScript('nginx/nginx.conf', [
|
|
||||||
'user' => $this->service->server->getSshUser(),
|
|
||||||
]),
|
|
||||||
]),
|
|
||||||
'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();
|
$this->service->server->os()->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,10 +49,13 @@ function (string $attribute, mixed $value, Closure $fail) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function uninstall(): void
|
public function uninstall(): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('nginx/uninstall-nginx.sh'),
|
view('ssh.services.webserver.nginx.uninstall-nginx'),
|
||||||
'uninstall-nginx'
|
'uninstall-nginx'
|
||||||
);
|
);
|
||||||
$this->service->server->os()->cleanup();
|
$this->service->server->os()->cleanup();
|
||||||
@ -62,50 +71,68 @@ public function createVHost(Site $site): void
|
|||||||
$ssh = $this->service->server->ssh($site->user);
|
$ssh = $this->service->server->ssh($site->user);
|
||||||
|
|
||||||
$ssh->exec(
|
$ssh->exec(
|
||||||
$this->getScript('nginx/create-path.sh', [
|
view('ssh.services.webserver.nginx.create-path', [
|
||||||
'path' => $site->path,
|
'path' => $site->path,
|
||||||
]),
|
]),
|
||||||
'create-path',
|
'create-path',
|
||||||
$site->id
|
$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->service->server->ssh()->exec(
|
||||||
$this->getScript('nginx/create-vhost.sh', [
|
view('ssh.services.webserver.nginx.create-vhost', [
|
||||||
'domain' => $site->domain,
|
'domain' => $site->domain,
|
||||||
'path' => $site->path,
|
'vhost' => view('ssh.services.webserver.nginx.vhost', [
|
||||||
'vhost' => $this->generateVhost($site),
|
'site' => $site,
|
||||||
|
]),
|
||||||
]),
|
]),
|
||||||
'create-vhost',
|
'create-vhost',
|
||||||
$site->id
|
$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->service->server->ssh()->write(
|
||||||
$this->getScript('nginx/update-vhost.sh', [
|
'/etc/nginx/sites-available/'.$site->domain,
|
||||||
'domain' => $site->domain,
|
$vhost ?? view('ssh.services.webserver.nginx.vhost', [
|
||||||
'path' => $site->path,
|
'site' => $site,
|
||||||
'vhost' => $vhost ?? $this->generateVhost($site, $noSSL),
|
|
||||||
]),
|
]),
|
||||||
'update-vhost',
|
true
|
||||||
$site->id
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->service->server->systemd()->restart('nginx');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function getVHost(Site $site): string
|
public function getVHost(Site $site): string
|
||||||
{
|
{
|
||||||
return $this->service->server->ssh()->exec(
|
return $this->service->server->ssh()->exec(
|
||||||
$this->getScript('nginx/get-vhost.sh', [
|
view('ssh.services.webserver.nginx.get-vhost', [
|
||||||
'domain' => $site->domain,
|
'domain' => $site->domain,
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function deleteSite(Site $site): void
|
public function deleteSite(Site $site): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('nginx/delete-site.sh', [
|
view('ssh.services.webserver.nginx.delete-site', [
|
||||||
'domain' => $site->domain,
|
'domain' => $site->domain,
|
||||||
'path' => $site->path,
|
'path' => $site->path,
|
||||||
]),
|
]),
|
||||||
@ -115,13 +142,16 @@ public function deleteSite(Site $site): void
|
|||||||
$this->service->restart();
|
$this->service->restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function changePHPVersion(Site $site, $version): void
|
public function changePHPVersion(Site $site, $version): void
|
||||||
{
|
{
|
||||||
$this->service->server->ssh()->exec(
|
$this->service->server->ssh()->exec(
|
||||||
$this->getScript('nginx/change-php-version.sh', [
|
view('ssh.services.webserver.nginx.change-php-version', [
|
||||||
'domain' => $site->domain,
|
'domain' => $site->domain,
|
||||||
'old_version' => $site->php_version,
|
'oldVersion' => $site->php_version,
|
||||||
'new_version' => $version,
|
'newVersion' => $version,
|
||||||
]),
|
]),
|
||||||
'change-php-version',
|
'change-php-version',
|
||||||
$site->id
|
$site->id
|
||||||
@ -137,19 +167,18 @@ public function setupSSL(Ssl $ssl): void
|
|||||||
foreach ($ssl->getDomains() as $domain) {
|
foreach ($ssl->getDomains() as $domain) {
|
||||||
$domains .= ' -d '.$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,
|
'email' => $ssl->site->server->creator->email,
|
||||||
'domain' => $ssl->site->domain,
|
'domain' => $ssl->site->domain,
|
||||||
'domains' => $domains,
|
'domains' => $domains,
|
||||||
'web_directory' => $ssl->site->getWebDirectoryPath(),
|
|
||||||
]);
|
]);
|
||||||
if ($ssl->type == 'custom') {
|
if ($ssl->type == 'custom') {
|
||||||
$command = $this->getScript('nginx/create-custom-ssl.sh', [
|
$command = view('ssh.services.webserver.nginx.create-custom-ssl', [
|
||||||
'path' => $ssl->getCertsDirectoryPath(),
|
'path' => $ssl->getCertsDirectoryPath(),
|
||||||
'certificate' => $ssl->certificate,
|
'certificate' => $ssl->certificate,
|
||||||
'pk' => $ssl->pk,
|
'pk' => $ssl->pk,
|
||||||
'certificate_path' => $ssl->getCertificatePath(),
|
'certificatePath' => $ssl->getCertificatePath(),
|
||||||
'pk_path' => $ssl->getPkPath(),
|
'pkPath' => $ssl->getPkPath(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$result = $this->service->server->ssh()->setLog($ssl->log)->exec(
|
$result = $this->service->server->ssh()->setLog($ssl->log)->exec(
|
||||||
@ -160,8 +189,6 @@ public function setupSSL(Ssl $ssl): void
|
|||||||
if (! $ssl->validateSetup($result)) {
|
if (! $ssl->validateSetup($result)) {
|
||||||
throw new SSLCreationException;
|
throw new SSLCreationException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->updateVHost($ssl->site);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,55 +202,6 @@ public function removeSSL(Ssl $ssl): void
|
|||||||
$ssl->site_id
|
$ssl->site_id
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->updateVHost($ssl->site, true);
|
$this->updateVHost($ssl->site);
|
||||||
|
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ interface Webserver
|
|||||||
{
|
{
|
||||||
public function createVHost(Site $site): void;
|
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;
|
public function getVHost(Site $site): string;
|
||||||
|
|
||||||
|
@ -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__"
|
|
@ -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
|
|
@ -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
|
|
@ -1,7 +0,0 @@
|
|||||||
rm -rf __path__
|
|
||||||
|
|
||||||
sudo rm /etc/nginx/sites-available/__domain__
|
|
||||||
|
|
||||||
sudo rm /etc/nginx/sites-enabled/__domain__
|
|
||||||
|
|
||||||
echo "Site deleted"
|
|
@ -1 +0,0 @@
|
|||||||
cat /etc/nginx/sites-available/__domain__
|
|
@ -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;
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
location __from__ {
|
|
||||||
return __mode__ __to__;
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
echo '__vhost__' | sudo tee /etc/nginx/sites-available/__domain__
|
|
||||||
|
|
||||||
sudo service nginx restart
|
|
@ -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;
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -3,17 +3,18 @@
|
|||||||
namespace App\SSH\Storage;
|
namespace App\SSH\Storage;
|
||||||
|
|
||||||
use App\Exceptions\SSHCommandError;
|
use App\Exceptions\SSHCommandError;
|
||||||
use App\SSH\HasScripts;
|
use App\Exceptions\SSHError;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class Dropbox extends AbstractStorage
|
class Dropbox extends AbstractStorage
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function upload(string $src, string $dest): array
|
public function upload(string $src, string $dest): array
|
||||||
{
|
{
|
||||||
$upload = $this->server->ssh()->exec(
|
$upload = $this->server->ssh()->exec(
|
||||||
$this->getScript('dropbox/upload.sh', [
|
view('ssh.storage.dropbox.upload', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'dest' => $dest,
|
'dest' => $dest,
|
||||||
'token' => $this->storageProvider->credentials['token'],
|
'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
|
public function download(string $src, string $dest): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('dropbox/download.sh', [
|
view('ssh.storage.dropbox.download', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'dest' => $dest,
|
'dest' => $dest,
|
||||||
'token' => $this->storageProvider->credentials['token'],
|
'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
|
public function delete(string $src): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('dropbox/delete-file.sh', [
|
view('ssh.storage.dropbox.delete-file', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'token' => $this->storageProvider->credentials['token'],
|
'token' => $this->storageProvider->credentials['token'],
|
||||||
]),
|
]),
|
||||||
|
@ -2,16 +2,17 @@
|
|||||||
|
|
||||||
namespace App\SSH\Storage;
|
namespace App\SSH\Storage;
|
||||||
|
|
||||||
use App\SSH\HasScripts;
|
use App\Exceptions\SSHError;
|
||||||
|
|
||||||
class FTP extends AbstractStorage
|
class FTP extends AbstractStorage
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function upload(string $src, string $dest): array
|
public function upload(string $src, string $dest): array
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('ftp/upload.sh', [
|
view('ssh.storage.ftp.upload', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'dest' => $dest,
|
'dest' => $dest,
|
||||||
'host' => $this->storageProvider->credentials['host'],
|
'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
|
public function download(string $src, string $dest): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('ftp/download.sh', [
|
view('ssh.storage.ftp.download', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'dest' => $dest,
|
'dest' => $dest,
|
||||||
'host' => $this->storageProvider->credentials['host'],
|
'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
|
public function delete(string $src): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('ftp/delete-file.sh', [
|
view('ssh.storage.ftp.delete-file', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'host' => $this->storageProvider->credentials['host'],
|
'host' => $this->storageProvider->credentials['host'],
|
||||||
'port' => $this->storageProvider->credentials['port'],
|
'port' => $this->storageProvider->credentials['port'],
|
||||||
|
@ -2,20 +2,21 @@
|
|||||||
|
|
||||||
namespace App\SSH\Storage;
|
namespace App\SSH\Storage;
|
||||||
|
|
||||||
use App\SSH\HasScripts;
|
use App\Exceptions\SSHError;
|
||||||
|
|
||||||
class Local extends AbstractStorage
|
class Local extends AbstractStorage
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function upload(string $src, string $dest): array
|
public function upload(string $src, string $dest): array
|
||||||
{
|
{
|
||||||
$destDir = dirname($dest);
|
$destDir = dirname($dest);
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('local/upload.sh', [
|
view('ssh.storage.local.upload', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'dest_dir' => $destDir,
|
'destDir' => $destDir,
|
||||||
'dest_file' => $dest,
|
'destFile' => $dest,
|
||||||
]),
|
]),
|
||||||
'upload-to-local'
|
'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
|
public function download(string $src, string $dest): void
|
||||||
{
|
{
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('local/download.sh', [
|
view('ssh.storage.local.download', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'dest' => $dest,
|
'dest' => $dest,
|
||||||
]),
|
]),
|
||||||
@ -36,6 +40,9 @@ public function download(string $src, string $dest): void
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function delete(string $src): void
|
public function delete(string $src): void
|
||||||
{
|
{
|
||||||
$this->server->os()->deleteFile($src);
|
$this->server->os()->deleteFile($src);
|
||||||
|
@ -5,12 +5,11 @@
|
|||||||
use App\Exceptions\SSHCommandError;
|
use App\Exceptions\SSHCommandError;
|
||||||
use App\Exceptions\SSHError;
|
use App\Exceptions\SSHError;
|
||||||
use App\SSH\HasS3Storage;
|
use App\SSH\HasS3Storage;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class S3 extends AbstractStorage
|
class S3 extends AbstractStorage
|
||||||
{
|
{
|
||||||
use HasS3Storage, HasScripts;
|
use HasS3Storage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws SSHError
|
* @throws SSHError
|
||||||
@ -20,7 +19,7 @@ public function upload(string $src, string $dest): array
|
|||||||
/** @var \App\StorageProviders\S3 $provider */
|
/** @var \App\StorageProviders\S3 $provider */
|
||||||
$provider = $this->storageProvider->provider();
|
$provider = $this->storageProvider->provider();
|
||||||
|
|
||||||
$uploadCommand = $this->getScript('s3/upload.sh', [
|
$uploadCommand = view('ssh.storage.s3.upload', [
|
||||||
'src' => $src,
|
'src' => $src,
|
||||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||||
'dest' => $this->prepareS3Path($dest),
|
'dest' => $this->prepareS3Path($dest),
|
||||||
@ -40,7 +39,6 @@ public function upload(string $src, string $dest): array
|
|||||||
return [
|
return [
|
||||||
'size' => null, // You can parse the size from the output if needed
|
'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 */
|
/** @var \App\StorageProviders\S3 $provider */
|
||||||
$provider = $this->storageProvider->provider();
|
$provider = $this->storageProvider->provider();
|
||||||
|
|
||||||
$downloadCommand = $this->getScript('s3/download.sh', [
|
$downloadCommand = view('ssh.storage.s3.download', [
|
||||||
'src' => $this->prepareS3Path($src),
|
'src' => $this->prepareS3Path($src),
|
||||||
'dest' => $dest,
|
'dest' => $dest,
|
||||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
'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
|
public function delete(string $src): void
|
||||||
{
|
{
|
||||||
/** @var \App\StorageProviders\S3 $provider */
|
/** @var \App\StorageProviders\S3 $provider */
|
||||||
$provider = $this->storageProvider->provider();
|
$provider = $this->storageProvider->provider();
|
||||||
|
|
||||||
$this->server->ssh()->exec(
|
$this->server->ssh()->exec(
|
||||||
$this->getScript('s3/delete-file.sh', [
|
view('ssh.storage.s3.delete-file', [
|
||||||
'src' => $this->prepareS3Path($src),
|
'src' => $this->prepareS3Path($src),
|
||||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||||
'key' => $this->storageProvider->credentials['key'],
|
'key' => $this->storageProvider->credentials['key'],
|
||||||
|
@ -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__'
|
|
@ -1 +0,0 @@
|
|||||||
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -Q "DELE /__src__"
|
|
@ -1 +0,0 @@
|
|||||||
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -o "__dest__"
|
|
@ -1 +0,0 @@
|
|||||||
curl __passive__ -T "__src__" -u "__username__:__password__" ftp__ssl__://__host__:__port__/__dest__
|
|
@ -1 +0,0 @@
|
|||||||
cp __src__ __dest__
|
|
@ -1,2 +0,0 @@
|
|||||||
mkdir -p __dest_dir__
|
|
||||||
cp __src__ __dest_file__
|
|
@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
namespace App\SSH\Systemd;
|
namespace App\SSH\Systemd;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
|
||||||
class Systemd
|
class Systemd
|
||||||
{
|
{
|
||||||
public function __construct(protected Server $server) {}
|
public function __construct(protected Server $server) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function status(string $unit): string
|
public function status(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
@ -17,6 +21,9 @@ public function status(string $unit): string
|
|||||||
return $this->server->ssh()->exec($command, sprintf('status-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('status-%s', $unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function start(string $unit): string
|
public function start(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
@ -27,6 +34,9 @@ public function start(string $unit): string
|
|||||||
return $this->server->ssh()->exec($command, sprintf('start-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('start-%s', $unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function stop(string $unit): string
|
public function stop(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
@ -37,6 +47,9 @@ public function stop(string $unit): string
|
|||||||
return $this->server->ssh()->exec($command, sprintf('stop-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('stop-%s', $unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function restart(string $unit): string
|
public function restart(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
@ -47,6 +60,9 @@ public function restart(string $unit): string
|
|||||||
return $this->server->ssh()->exec($command, sprintf('restart-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('restart-%s', $unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function enable(string $unit): string
|
public function enable(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
@ -58,6 +74,9 @@ public function enable(string $unit): string
|
|||||||
return $this->server->ssh()->exec($command, sprintf('enable-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('enable-%s', $unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function disable(string $unit): string
|
public function disable(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
|
@ -2,26 +2,27 @@
|
|||||||
|
|
||||||
namespace App\SSH\Wordpress;
|
namespace App\SSH\Wordpress;
|
||||||
|
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
use App\SSH\HasScripts;
|
|
||||||
|
|
||||||
class Wordpress
|
class Wordpress
|
||||||
{
|
{
|
||||||
use HasScripts;
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(Site $site): void
|
public function install(Site $site): void
|
||||||
{
|
{
|
||||||
$site->server->ssh($site->user)->exec(
|
$site->server->ssh($site->user)->exec(
|
||||||
$this->getScript('install.sh', [
|
view('ssh.wordpress.install', [
|
||||||
'path' => $site->path,
|
'path' => $site->path,
|
||||||
'domain' => $site->domain,
|
'domain' => $site->domain,
|
||||||
'is_isolated' => $site->isIsolated() ? 'true' : 'false',
|
'isIsolated' => $site->isIsolated() ? 'true' : 'false',
|
||||||
'isolated_username' => $site->user,
|
'isolatedUsername' => $site->user,
|
||||||
'db_name' => $site->type_data['database'],
|
'dbName' => $site->type_data['database'],
|
||||||
'db_user' => $site->type_data['database_user'],
|
'dbUser' => $site->type_data['database_user'],
|
||||||
'db_pass' => $site->type_data['database_password'],
|
'dbPass' => $site->type_data['database_password'],
|
||||||
'db_host' => 'localhost',
|
'dbHost' => 'localhost',
|
||||||
'db_prefix' => 'wp_',
|
'dbPrefix' => 'wp_',
|
||||||
'username' => $site->type_data['username'],
|
'username' => $site->type_data['username'],
|
||||||
'password' => $site->type_data['password'],
|
'password' => $site->type_data['password'],
|
||||||
'email' => $site->type_data['email'],
|
'email' => $site->type_data['email'],
|
||||||
|
@ -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
|
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\ServerTypes;
|
namespace App\ServerTypes;
|
||||||
|
|
||||||
use App\Enums\ServiceStatus;
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\SSH\Services\PHP\PHP;
|
use App\SSH\Services\PHP\PHP;
|
||||||
|
|
||||||
@ -15,6 +16,9 @@ public function __construct(Server $server)
|
|||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->createUser();
|
$this->createUser();
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
namespace App\SiteTypes;
|
namespace App\SiteTypes;
|
||||||
|
|
||||||
use App\Exceptions\FailedToDeployGitKey;
|
use App\Exceptions\FailedToDeployGitKey;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
|
use App\SSH\Services\PHP\PHP;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
abstract class AbstractSiteType implements SiteType
|
abstract class AbstractSiteType implements SiteType
|
||||||
{
|
{
|
||||||
@ -14,6 +17,26 @@ public function __construct(Site $site)
|
|||||||
$this->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
|
protected function progress(int $percentage): void
|
||||||
{
|
{
|
||||||
$this->site->progress = $percentage;
|
$this->site->progress = $percentage;
|
||||||
@ -22,6 +45,7 @@ protected function progress(int $percentage): void
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws FailedToDeployGitKey
|
* @throws FailedToDeployGitKey
|
||||||
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
protected function deployKey(): void
|
protected function deployKey(): void
|
||||||
{
|
{
|
||||||
@ -35,4 +59,31 @@ protected function deployKey(): void
|
|||||||
$this->site->ssh_key
|
$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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\SiteTypes;
|
namespace App\SiteTypes;
|
||||||
|
|
||||||
use App\Enums\SiteFeature;
|
use App\Enums\SiteFeature;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
@ -41,9 +42,12 @@ public function data(array $input): array
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->site->isolate();
|
$this->isolate();
|
||||||
|
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $this->site->server->webserver()->handler();
|
$webserver = $this->site->server->webserver()->handler();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\SiteTypes;
|
namespace App\SiteTypes;
|
||||||
|
|
||||||
use App\Enums\SiteFeature;
|
use App\Enums\SiteFeature;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
@ -41,9 +42,12 @@ public function data(array $input): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->site->isolate();
|
$this->isolate();
|
||||||
|
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $this->site->server->webserver()->handler();
|
$webserver = $this->site->server->webserver()->handler();
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Enums\SiteFeature;
|
use App\Enums\SiteFeature;
|
||||||
use App\Exceptions\FailedToDeployGitKey;
|
use App\Exceptions\FailedToDeployGitKey;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\SSH\Composer\Composer;
|
use App\SSH\Composer\Composer;
|
||||||
use App\SSH\Git\Git;
|
use App\SSH\Git\Git;
|
||||||
use App\SSH\Services\Webserver\Webserver;
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
@ -73,10 +74,11 @@ public function data(array $input): array
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws FailedToDeployGitKey
|
* @throws FailedToDeployGitKey
|
||||||
|
* @throws SSHError
|
||||||
*/
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->site->isolate();
|
$this->isolate();
|
||||||
|
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $this->site->server->webserver()->handler();
|
$webserver = $this->site->server->webserver()->handler();
|
||||||
|
@ -6,8 +6,10 @@
|
|||||||
use App\Actions\Database\CreateDatabaseUser;
|
use App\Actions\Database\CreateDatabaseUser;
|
||||||
use App\Actions\Database\LinkUser;
|
use App\Actions\Database\LinkUser;
|
||||||
use App\Enums\SiteFeature;
|
use App\Enums\SiteFeature;
|
||||||
|
use App\Exceptions\SSHError;
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\DatabaseUser;
|
use App\Models\DatabaseUser;
|
||||||
|
use App\SSH\Services\Webserver\Webserver;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
@ -82,9 +84,12 @@ public function data(array $input): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SSHError
|
||||||
|
*/
|
||||||
public function install(): void
|
public function install(): void
|
||||||
{
|
{
|
||||||
$this->site->isolate();
|
$this->isolate();
|
||||||
|
|
||||||
/** @var Webserver $webserver */
|
/** @var Webserver $webserver */
|
||||||
$webserver = $this->site->server->webserver()->handler();
|
$webserver = $this->site->server->webserver()->handler();
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
use App\Enums\PHPIniType;
|
use App\Enums\PHPIniType;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
|
use App\Web\Pages\Servers\Logs\Index;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Filament\Forms\Components\Hidden;
|
use Filament\Forms\Components\Hidden;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
@ -102,6 +103,16 @@ private function installExtensionAction(): Action
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
app(InstallPHPExtension::class)->install($this->server, $data);
|
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) {
|
} catch (Exception $e) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->danger()
|
->danger()
|
||||||
|
@ -74,7 +74,7 @@ private function vhostAction(): Action
|
|||||||
run_action($this, function () use ($data) {
|
run_action($this, function () use ($data) {
|
||||||
/** @var Webserver $handler */
|
/** @var Webserver $handler */
|
||||||
$handler = $this->server->webserver()->handler();
|
$handler = $this->server->webserver()->handler();
|
||||||
$handler->updateVHost($this->site, false, $data['vhost']);
|
$handler->updateVHost($this->site, $data['vhost']);
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->success()
|
->success()
|
||||||
->title('VHost updated!')
|
->title('VHost updated!')
|
||||||
|
@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user