use blade as conmmands template (#444)

* use blade as conmmands template

* fix lint

* fix ssl
This commit is contained in:
Saeed Vaziry 2025-01-27 21:27:58 +01:00 committed by GitHub
parent a73476c1dd
commit cdbde063f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
208 changed files with 1080 additions and 1012 deletions

View File

@ -12,3 +12,4 @@ sail
*.yml
!*.blade.php
!*.sh
resources/views/ssh/

View File

@ -6,6 +6,7 @@
use App\Models\Queue;
use App\Models\Server;
use App\Models\Site;
use App\SSH\Services\ProcessManager\ProcessManager;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
@ -29,7 +30,9 @@ public function create(mixed $queueable, array $input): void
$queue->save();
dispatch(function () use ($queue) {
$queue->server->processManager()->handler()->create(
/** @var ProcessManager $processManager */
$processManager = $queue->server->processManager()->handler();
$processManager->create(
$queue->id,
$queue->command,
$queue->user,

View File

@ -44,6 +44,7 @@ public function create(Site $site, array $input): void
$webserver->setupSSL($ssl);
$ssl->status = SslStatus::CREATED;
$ssl->save();
$webserver->updateVHost($site);
$site->type()->edit();
})->catch(function () use ($ssl) {
$ssl->status = SslStatus::FAILED;

View File

@ -2,6 +2,7 @@
namespace App\Actions\SSL;
use App\Enums\SslStatus;
use App\Models\Ssl;
use App\SSH\Services\Webserver\Webserver;
@ -9,6 +10,8 @@ class DeleteSSL
{
public function delete(Ssl $ssl): void
{
$ssl->status = SslStatus::DELETING;
$ssl->save();
/** @var Webserver $webserver */
$webserver = $ssl->site->server->webserver()->handler();
$webserver->removeSSL($ssl);

View File

@ -2,12 +2,16 @@
namespace App\Actions\Site;
use App\Exceptions\SSHError;
use App\Models\Site;
use App\SSH\Services\PHP\PHP;
use App\SSH\Services\Webserver\Webserver;
class DeleteSite
{
/**
* @throws SSHError
*/
public function delete(Site $site): void
{
/** @var Webserver $webserverHandler */

View File

@ -4,7 +4,7 @@
use App\Enums\DeploymentStatus;
use App\Exceptions\DeploymentScriptIsEmptyException;
use App\Exceptions\SourceControlIsNotConnected;
use App\Exceptions\SSHError;
use App\Models\Deployment;
use App\Models\ServerLog;
use App\Models\Site;
@ -12,8 +12,8 @@
class Deploy
{
/**
* @throws SourceControlIsNotConnected
* @throws DeploymentScriptIsEmptyException
* @throws SSHError
*/
public function run(Site $site): Deployment
{

View File

@ -14,7 +14,7 @@ public function update(Site $site, array $input): void
/** @var Webserver $webserver */
$webserver = $site->server->webserver()->handler();
$webserver->updateVHost($site, ! $site->hasSSL());
$webserver->updateVHost($site);
$site->save();
}

View File

@ -2,6 +2,7 @@
namespace App\Actions\Site;
use App\Exceptions\SSHError;
use App\Models\Site;
use App\SSH\Git\Git;
use Illuminate\Validation\ValidationException;
@ -10,6 +11,7 @@ class UpdateBranch
{
/**
* @throws ValidationException
* @throws SSHError
*/
public function update(Site $site, array $input): void
{

View File

@ -2,6 +2,7 @@
namespace App\Actions\Site;
use App\Exceptions\SSHError;
use App\Models\Site;
use Illuminate\Validation\Rule;
@ -19,6 +20,9 @@ public static function rules(Site $site): array
];
}
/**
* @throws SSHError
*/
public function update(Site $site, array $input): void
{
$site->changePHPVersion($input['version']);

View File

@ -5,11 +5,7 @@
use App\Actions\Service\Manage;
use App\Enums\ServiceStatus;
use App\Exceptions\ServiceInstallationFailed;
use App\SSH\Services\Database\Database as DatabaseAlias;
use App\SSH\Services\PHP\PHP as PHPAlias;
use App\SSH\Services\ProcessManager\ProcessManager;
use App\SSH\Services\ServiceInterface;
use App\SSH\Services\WebServer\WebServer as WebServerAlias;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
@ -79,9 +75,6 @@ public function server(): BelongsTo
return $this->belongsTo(Server::class);
}
/**
* @return ProcessManager|DatabaseAlias|PHPAlias|WebServerAlias
*/
public function handler(): ServiceInterface
{
$handler = config('core.service_handlers')[$this->name];

View File

@ -3,6 +3,7 @@
namespace App\Models;
use App\Enums\SiteStatus;
use App\Enums\SslStatus;
use App\Exceptions\FailedToDestroyGitHook;
use App\Exceptions\SourceControlIsNotConnected;
use App\Exceptions\SSHError;
@ -35,6 +36,7 @@
* @property int $port
* @property int $progress
* @property string $user
* @property bool $force_ssl
* @property Server $server
* @property ServerLog[] $logs
* @property Deployment[] $deployments
@ -198,6 +200,9 @@ public function php(): ?Service
return null;
}
/**
* @throws SSHError
*/
public function changePHPVersion($version): void
{
/** @var Webserver $handler */
@ -219,6 +224,7 @@ public function activeSsl(): HasOne
{
return $this->hasOne(Ssl::class)
->where('expires_at', '>=', now())
->where('status', SslStatus::CREATED)
->orderByDesc('id');
}
@ -301,11 +307,6 @@ public function getEnv(): string
}
}
public function hasSSL(): bool
{
return $this->ssls->isNotEmpty();
}
public function environmentVariables(?Deployment $deployment = null): array
{
return [
@ -319,30 +320,16 @@ public function environmentVariables(?Deployment $deployment = null): array
];
}
public function isolate(): void
{
if (! $this->isIsolated()) {
return;
}
$this->server->os()->createIsolatedUser(
$this->user,
Str::random(15),
$this->id
);
// Generate the FPM pool
/** @var PHP $php */
$php = $this->php()->handler();
$php->createFpmPool(
$this->user,
$this->php_version,
$this->id
);
}
public function isIsolated(): bool
{
return $this->user != $this->server->getSshUser();
}
public function webserver(): Webserver
{
/** @var Webserver $webserver */
$webserver = $this->server->webserver()->handler();
return $webserver;
}
}

View File

@ -2,19 +2,20 @@
namespace App\SSH\Composer;
use App\Exceptions\SSHError;
use App\Models\Site;
use App\SSH\HasScripts;
class Composer
{
use HasScripts;
/**
* @throws SSHError
*/
public function installDependencies(Site $site): void
{
$site->server->ssh($site->user)->exec(
$this->getScript('composer-install.sh', [
view('ssh.composer.composer-install', [
'path' => $site->path,
'php_version' => $site->php_version,
'phpVersion' => $site->php_version,
]),
'composer-install',
$site->id

View File

@ -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

View File

@ -2,26 +2,24 @@
namespace App\SSH\Cron;
use App\Exceptions\SSHError;
use App\Models\Server;
class Cron
{
public function __construct(protected Server $server) {}
/**
* @throws SSHError
*/
public function update(string $user, string $cron): void
{
$command = <<<EOD
if ! echo '$cron' | sudo -u $user crontab -; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo -u $user crontab -l; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo 'cron updated!'
EOD;
$this->server->ssh()->exec($command, 'update-cron');
$this->server->ssh()->exec(
view('ssh.cron.update', [
'cron' => $cron,
'user' => $user,
]),
'update-cron'
);
}
}

View File

@ -2,17 +2,18 @@
namespace App\SSH\Git;
use App\Exceptions\SSHError;
use App\Models\Site;
use App\SSH\HasScripts;
class Git
{
use HasScripts;
/**
* @throws SSHError
*/
public function clone(Site $site): void
{
$site->server->ssh($site->user)->exec(
$this->getScript('clone.sh', [
view('ssh.git.clone', [
'host' => str($site->getFullRepositoryUrl())->after('@')->before('-'),
'repo' => $site->getFullRepositoryUrl(),
'path' => $site->path,
@ -24,10 +25,13 @@ public function clone(Site $site): void
);
}
/**
* @throws SSHError
*/
public function checkout(Site $site): void
{
$site->server->ssh($site->user)->exec(
$this->getScript('checkout.sh', [
view('ssh.git.checkout', [
'path' => $site->path,
'branch' => $site->branch,
]),

View File

@ -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

View File

@ -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;
}
}

View File

@ -2,11 +2,11 @@
namespace App\SSH\OS;
use App\Exceptions\SSHError;
use App\Exceptions\SSHUploadFailed;
use App\Models\Server;
use App\Models\ServerLog;
use App\Models\Site;
use App\SSH\HasScripts;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
@ -14,30 +14,40 @@
class OS
{
use HasScripts;
public function __construct(protected Server $server) {}
/**
* @throws SSHError
*/
public function installDependencies(): void
{
$this->server->ssh()->exec(
$this->getScript('install-dependencies.sh'),
view('ssh.os.install-dependencies', [
'name' => $this->server->creator->name,
'email' => $this->server->creator->email,
]),
'install-dependencies'
);
}
/**
* @throws SSHError
*/
public function upgrade(): void
{
$this->server->ssh()->exec(
$this->getScript('upgrade.sh'),
view('ssh.os.upgrade'),
'upgrade'
);
}
/**
* @throws SSHError
*/
public function availableUpdates(): int
{
$result = $this->server->ssh()->exec(
$this->getScript('available-updates.sh'),
view('ssh.os.available-updates'),
'check-available-updates'
);
@ -47,10 +57,13 @@ public function availableUpdates(): int
return max($availableUpdates, 0);
}
/**
* @throws SSHError
*/
public function createUser(string $user, string $password, string $key): void
{
$this->server->ssh()->exec(
$this->getScript('create-user.sh', [
view('ssh.os.create-user', [
'user' => $user,
'password' => $password,
'key' => $key,
@ -59,12 +72,15 @@ public function createUser(string $user, string $password, string $key): void
);
}
/**
* @throws SSHError
*/
public function createIsolatedUser(string $user, string $password, int $site_id): void
{
$this->server->ssh()->exec(
$this->getScript('create-isolated-user.sh', [
view('ssh.os.create-isolated-user', [
'user' => $user,
'server_user' => $this->server->getSshUser(),
'serverUser' => $this->server->getSshUser(),
'password' => $password,
]),
'create-isolated-user',
@ -72,40 +88,52 @@ public function createIsolatedUser(string $user, string $password, int $site_id)
);
}
/**
* @throws SSHError
*/
public function deleteIsolatedUser(string $user): void
{
$this->server->ssh()->exec(
$this->getScript('delete-isolated-user.sh', [
view('ssh.os.delete-isolated-user', [
'user' => $user,
'server_user' => $this->server->getSshUser(),
'serverUser' => $this->server->getSshUser(),
]),
'delete-isolated-user'
);
}
/**
* @throws SSHError
*/
public function getPublicKey(string $user): string
{
return $this->server->ssh()->exec(
$this->getScript('read-file.sh', [
view('ssh.os.read-file', [
'path' => '/home/'.$user.'/.ssh/id_rsa.pub',
])
);
}
/**
* @throws SSHError
*/
public function deploySSHKey(string $key): void
{
$this->server->ssh()->exec(
$this->getScript('deploy-ssh-key.sh', [
view('ssh.os.deploy-ssh-key', [
'key' => $key,
]),
'deploy-ssh-key'
);
}
/**
* @throws SSHError
*/
public function deleteSSHKey(string $key): void
{
$this->server->ssh()->exec(
$this->getScript('delete-ssh-key.sh', [
view('ssh.os.delete-ssh-key', [
'key' => $key,
'user' => $this->server->getSshUser(),
]),
@ -113,10 +141,13 @@ public function deleteSSHKey(string $key): void
);
}
/**
* @throws SSHError
*/
public function generateSSHKey(string $name, ?Site $site = null): void
{
$site->server->ssh($site->user)->exec(
$this->getScript('generate-ssh-key.sh', [
view('ssh.os.generate-ssh-key', [
'name' => $name,
]),
'generate-ssh-key',
@ -124,19 +155,25 @@ public function generateSSHKey(string $name, ?Site $site = null): void
);
}
/**
* @throws SSHError
*/
public function readSSHKey(string $name, ?Site $site = null): string
{
return $site->server->ssh($site->user)->exec(
$this->getScript('read-ssh-key.sh', [
view('ssh.os.read-ssh-key', [
'name' => $name,
]),
);
}
/**
* @throws SSHError
*/
public function reboot(): void
{
$this->server->ssh()->exec(
$this->getScript('reboot.sh'),
view('ssh.os.reboot'),
);
}
@ -161,25 +198,34 @@ public function editFile(string $path, ?string $content = null): void
}
}
/**
* @throws SSHError
*/
public function readFile(string $path): string
{
return $this->server->ssh()->exec(
$this->getScript('read-file.sh', [
view('ssh.os.read-file', [
'path' => $path,
])
);
}
/**
* @throws SSHError
*/
public function tail(string $path, int $lines): string
{
return $this->server->ssh()->exec(
$this->getScript('tail.sh', [
view('ssh.os.tail', [
'path' => $path,
'lines' => $lines,
])
);
}
/**
* @throws SSHError
*/
public function runScript(string $path, string $script, ?ServerLog $serverLog, ?string $user = null, ?array $variables = []): ServerLog
{
$ssh = $this->server->ssh($user);
@ -190,7 +236,7 @@ public function runScript(string $path, string $script, ?ServerLog $serverLog, ?
foreach ($variables as $key => $variable) {
$command .= "$key=$variable\n";
}
$command .= $this->getScript('run-script.sh', [
$command .= view('ssh.os.run-script', [
'path' => $path,
'script' => $script,
]);
@ -201,16 +247,22 @@ public function runScript(string $path, string $script, ?ServerLog $serverLog, ?
return $ssh->log;
}
/**
* @throws SSHError
*/
public function download(string $url, string $path): string
{
return $this->server->ssh()->exec(
$this->getScript('download.sh', [
view('ssh.os.download', [
'url' => $url,
'path' => $path,
])
);
}
/**
* @throws SSHError
*/
public function unzip(string $path): string
{
return $this->server->ssh()->exec(
@ -218,18 +270,24 @@ public function unzip(string $path): string
);
}
/**
* @throws SSHError
*/
public function cleanup(): void
{
$this->server->ssh()->exec(
$this->getScript('cleanup.sh'),
view('ssh.os.cleanup'),
'cleanup'
);
}
/**
* @throws SSHError
*/
public function resourceInfo(): array
{
$info = $this->server->ssh()->exec(
$this->getScript('resource-info.sh'),
view('ssh.os.resource-info'),
);
return [
@ -243,10 +301,13 @@ public function resourceInfo(): array
];
}
/**
* @throws SSHError
*/
public function deleteFile(string $path): void
{
$this->server->ssh()->exec(
$this->getScript('delete-file.sh', [
view('ssh.os.delete-file', [
'path' => $path,
]),
'delete-file'

View 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__."

View File

@ -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

View File

@ -1 +0,0 @@
rm -f __path__

View File

@ -1,3 +0,0 @@
sudo gpasswd -d __server_user__ __user__
sudo userdel -r "__user__"
echo "User __user__ has been deleted."

View File

@ -1,3 +0,0 @@
if ! echo '__key__' | sudo tee -a ~/.ssh/authorized_keys; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -1,3 +0,0 @@
if ! wget __url__ -O __path__; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -1 +0,0 @@
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/__name__

View File

@ -1 +0,0 @@
[ -f __path__ ] && sudo cat __path__

View File

@ -1 +0,0 @@
cat ~/.ssh/__name__.pub

View File

@ -1 +0,0 @@
sudo tail -n __lines__ __path__

View File

@ -2,17 +2,18 @@
namespace App\SSH\PHPMyAdmin;
use App\Exceptions\SSHError;
use App\Models\Site;
use App\SSH\HasScripts;
class PHPMyAdmin
{
use HasScripts;
/**
* @throws SSHError
*/
public function install(Site $site): void
{
$site->server->ssh($site->user)->exec(
$this->getScript('install.sh', [
view('ssh.phpmyadmin.install', [
'version' => $site->type_data['version'],
'path' => $site->path,
]),

View File

@ -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!"

View File

@ -3,16 +3,18 @@
namespace App\SSH\Services\Database;
use App\Enums\BackupStatus;
use App\Exceptions\ServiceInstallationFailed;
use App\Exceptions\SSHError;
use App\Models\BackupFile;
use App\SSH\HasScripts;
use App\SSH\Services\AbstractService;
use Closure;
abstract class AbstractDatabase extends AbstractService implements Database
{
use HasScripts;
abstract protected function getScriptsDir(): string;
protected function getScriptView(string $script): string
{
return 'ssh.services.database.'.$this->service->name.'.'.$script;
}
public function creationRules(array $input): array
{
@ -29,10 +31,14 @@ function (string $attribute, mixed $value, Closure $fail) {
];
}
/**
* @throws ServiceInstallationFailed
* @throws SSHError
*/
public function install(): void
{
$version = $this->service->version;
$command = $this->getScript($this->service->name.'/install-'.$version.'.sh');
$version = str_replace('.', '', $this->service->version);
$command = view($this->getScriptView('install-'.$version));
$this->service->server->ssh()->exec($command, 'install-'.$this->service->name.'-'.$version);
$status = $this->service->server->systemd()->status($this->service->unit);
$this->service->validateInstall($status);
@ -63,38 +69,50 @@ function (string $attribute, mixed $value, Closure $fail) {
];
}
/**
* @throws SSHError
*/
public function uninstall(): void
{
$version = $this->service->version;
$command = $this->getScript($this->service->name.'/uninstall.sh');
$command = view($this->getScriptView('uninstall'));
$this->service->server->ssh()->exec($command, 'uninstall-'.$this->service->name.'-'.$version);
$this->service->server->os()->cleanup();
}
/**
* @throws SSHError
*/
public function create(string $name): void
{
$this->service->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/create.sh', [
view($this->getScriptView('create'), [
'name' => $name,
]),
'create-database'
);
}
/**
* @throws SSHError
*/
public function delete(string $name): void
{
$this->service->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/delete.sh', [
view($this->getScriptView('delete'), [
'name' => $name,
]),
'delete-database'
);
}
/**
* @throws SSHError
*/
public function createUser(string $username, string $password, string $host): void
{
$this->service->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/create-user.sh', [
view($this->getScriptView('create-user'), [
'username' => $username,
'password' => $password,
'host' => $host,
@ -103,10 +121,13 @@ public function createUser(string $username, string $password, string $host): vo
);
}
/**
* @throws SSHError
*/
public function deleteUser(string $username, string $host): void
{
$this->service->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/delete-user.sh', [
view($this->getScriptView('delete-user'), [
'username' => $username,
'host' => $host,
]),
@ -114,6 +135,9 @@ public function deleteUser(string $username, string $host): void
);
}
/**
* @throws SSHError
*/
public function link(string $username, string $host, array $databases): void
{
$ssh = $this->service->server->ssh();
@ -121,7 +145,7 @@ public function link(string $username, string $host, array $databases): void
foreach ($databases as $database) {
$ssh->exec(
$this->getScript($this->getScriptsDir().'/link.sh', [
view($this->getScriptView('link'), [
'username' => $username,
'host' => $host,
'database' => $database,
@ -132,12 +156,15 @@ public function link(string $username, string $host, array $databases): void
}
}
/**
* @throws SSHError
*/
public function unlink(string $username, string $host): void
{
$version = $this->service->version;
$this->service->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/unlink.sh', [
view($this->getScriptView('unlink'), [
'username' => $username,
'host' => $host,
'version' => $version,
@ -146,11 +173,14 @@ public function unlink(string $username, string $host): void
);
}
/**
* @throws SSHError
*/
public function runBackup(BackupFile $backupFile): void
{
// backup
$this->service->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/backup.sh', [
view($this->getScriptView('backup'), [
'file' => $backupFile->name,
'database' => $backupFile->backup->database->name,
]),
@ -170,6 +200,9 @@ public function runBackup(BackupFile $backupFile): void
$backupFile->save();
}
/**
* @throws SSHError
*/
public function restoreBackup(BackupFile $backupFile, string $database): void
{
// download
@ -179,7 +212,7 @@ public function restoreBackup(BackupFile $backupFile, string $database): void
);
$this->service->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/restore.sh', [
view($this->getScriptView('restore'), [
'database' => $database,
'file' => rtrim($backupFile->tempPath(), '.zip'),
]),

View File

@ -4,8 +4,5 @@
class Mariadb extends AbstractDatabase
{
protected function getScriptsDir(): string
{
return 'mysql';
}
//
}

View File

@ -4,8 +4,5 @@
class Mysql extends AbstractDatabase
{
protected function getScriptsDir(): string
{
return 'mysql';
}
//
}

View File

@ -2,26 +2,7 @@
namespace App\SSH\Services\Database;
use App\Exceptions\SSHError;
class Postgresql extends AbstractDatabase
{
protected function getScriptsDir(): string
{
return 'postgresql';
}
/**
* @throws SSHError
*/
public function create(string $name): void
{
$this->service->server->ssh()->exec(
$this->getScript($this->getScriptsDir().'/create.sh', [
'name' => $name,
'ssh_user' => $this->service->server->ssh_user,
]),
'create-database'
);
}
//
}

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -2,16 +2,17 @@
namespace App\SSH\Services\Firewall;
use App\SSH\HasScripts;
use App\Exceptions\SSHError;
class Ufw extends AbstractFirewall
{
use HasScripts;
/**
* @throws SSHError
*/
public function install(): void
{
$this->service->server->ssh()->exec(
$this->getScript('ufw/install-ufw.sh'),
view('ssh.services.firewall.ufw.install-ufw'),
'install-ufw'
);
$this->service->server->os()->cleanup();
@ -22,10 +23,13 @@ public function uninstall(): void
//
}
/**
* @throws SSHError
*/
public function addRule(string $type, string $protocol, int $port, string $source, ?string $mask): void
{
$this->service->server->ssh()->exec(
$this->getScript('ufw/add-rule.sh', [
view('ssh.services.firewall.ufw.add-rule', [
'type' => $type,
'protocol' => $protocol,
'port' => $port,
@ -36,10 +40,13 @@ public function addRule(string $type, string $protocol, int $port, string $sourc
);
}
/**
* @throws SSHError
*/
public function removeRule(string $type, string $protocol, int $port, string $source, ?string $mask): void
{
$this->service->server->ssh()->exec(
$this->getScript('ufw/remove-rule.sh', [
view('ssh.services.firewall.ufw.remove-rule', [
'type' => $type,
'protocol' => $protocol,
'port' => $port,

View File

@ -2,8 +2,9 @@
namespace App\SSH\Services\Monitoring\VitoAgent;
use App\Exceptions\ServiceInstallationFailed;
use App\Exceptions\SSHError;
use App\Models\Metric;
use App\SSH\HasScripts;
use App\SSH\Services\AbstractService;
use Closure;
use Illuminate\Support\Facades\Http;
@ -12,8 +13,6 @@
class VitoAgent extends AbstractService
{
use HasScripts;
const TAGS_URL = 'https://api.github.com/repos/vitodeploy/agent/tags';
const DOWNLOAD_URL = 'https://github.com/vitodeploy/agent/releases/download/%s';
@ -54,11 +53,15 @@ public function data(): array
];
}
/**
* @throws SSHError
* @throws ServiceInstallationFailed
*/
public function install(): void
{
$tags = Http::get(self::TAGS_URL)->json();
if (empty($tags)) {
throw new \Exception('Failed to fetch tags');
throw new ServiceInstallationFailed('Failed to fetch tags');
}
$this->service->version = $tags[0]['name'];
$this->service->save();
@ -71,10 +74,10 @@ public function install(): void
$this->service->refresh();
$this->service->server->ssh()->exec(
$this->getScript('install.sh', [
'download_url' => $downloadUrl,
'config_url' => $this->data()['url'],
'config_secret' => $this->data()['secret'],
view('ssh.services.monitoring.vito-agent.install', [
'downloadUrl' => $downloadUrl,
'configUrl' => $this->data()['url'],
'configSecret' => $this->data()['secret'],
]),
'install-vito-agent'
);
@ -82,12 +85,15 @@ public function install(): void
$this->service->validateInstall($status);
}
/**
* @throws SSHError
*/
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('uninstall.sh'),
view('ssh.services.monitoring.vito-agent.uninstall'),
'uninstall-vito-agent'
);
Metric::where('server_id', $this->service->server_id)->delete();
Metric::query()->where('server_id', $this->service->server_id)->delete();
}
}

View File

@ -2,15 +2,13 @@
namespace App\SSH\Services\NodeJS;
use App\SSH\HasScripts;
use App\Exceptions\SSHError;
use App\SSH\Services\AbstractService;
use Closure;
use Illuminate\Validation\Rule;
class NodeJS extends AbstractService
{
use HasScripts;
public function creationRules(array $input): array
{
return [
@ -41,34 +39,43 @@ function (string $attribute, mixed $value, Closure $fail) {
];
}
/**
* @throws SSHError
*/
public function install(): void
{
$server = $this->service->server;
$server->ssh()->exec(
$this->getScript('install-nodejs.sh', [
view('ssh.services.nodejs.install-nodejs', [
'version' => $this->service->version,
'user' => $server->getSshUser(),
]),
'install-nodejs-'.$this->service->version
);
$this->service->server->os()->cleanup();
}
/**
* @throws SSHError
*/
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('uninstall-nodejs.sh', [
view('ssh.services.nodejs.uninstall-nodejs', [
'version' => $this->service->version,
'default' => $this->service->is_default,
]),
'uninstall-nodejs-'.$this->service->version
);
$this->service->server->os()->cleanup();
}
/**
* @throws SSHError
*/
public function setDefaultCli(): void
{
$this->service->server->ssh()->exec(
$this->getScript('change-default-nodejs.sh', [
view('ssh.services.nodejs.change-default-nodejs', [
'version' => $this->service->version,
]),
'change-default-nodejs'

View File

@ -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

View File

@ -3,7 +3,7 @@
namespace App\SSH\Services\PHP;
use App\Exceptions\SSHCommandError;
use App\SSH\HasScripts;
use App\Exceptions\SSHError;
use App\SSH\Services\AbstractService;
use Closure;
use Illuminate\Support\Str;
@ -11,8 +11,6 @@
class PHP extends AbstractService
{
use HasScripts;
public function creationRules(array $input): array
{
return [
@ -43,11 +41,14 @@ function (string $attribute, mixed $value, Closure $fail) {
];
}
/**
* @throws SSHError
*/
public function install(): void
{
$server = $this->service->server;
$server->ssh()->exec(
$this->getScript('install-php.sh', [
view('ssh.services.php.install-php', [
'version' => $this->service->version,
'user' => $server->getSshUser(),
]),
@ -57,10 +58,13 @@ public function install(): void
$this->service->server->os()->cleanup();
}
/**
* @throws SSHError
*/
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('uninstall-php.sh', [
view('ssh.services.php.uninstall-php', [
'version' => $this->service->version,
]),
'uninstall-php-'.$this->service->version
@ -68,10 +72,13 @@ public function uninstall(): void
$this->service->server->os()->cleanup();
}
/**
* @throws SSHError
*/
public function setDefaultCli(): void
{
$this->service->server->ssh()->exec(
$this->getScript('change-default-php.sh', [
view('ssh.services.php.change-default-php', [
'version' => $this->service->version,
]),
'change-default-php'
@ -79,12 +86,12 @@ public function setDefaultCli(): void
}
/**
* @throws SSHCommandError
* @throws SSHError
*/
public function installExtension($name): void
{
$result = $this->service->server->ssh()->exec(
$this->getScript('install-php-extension.sh', [
view('ssh.services.php.install-php-extension', [
'version' => $this->service->version,
'name' => $name,
]),
@ -96,14 +103,20 @@ public function installExtension($name): void
}
}
/**
* @throws SSHError
*/
public function installComposer(): void
{
$this->service->server->ssh()->exec(
$this->getScript('install-composer.sh'),
view('ssh.services.php.install-composer'),
'install-composer'
);
}
/**
* @throws SSHError
*/
public function getPHPIni(string $type): string
{
return $this->service->server->os()->readFile(
@ -111,26 +124,30 @@ public function getPHPIni(string $type): string
);
}
/**
* @throws SSHError
*/
public function createFpmPool(string $user, string $version, $site_id): void
{
$this->service->server->ssh()->exec(
$this->getScript('create-fpm-pool.sh', [
'user' => $user,
'version' => $version,
'config' => $this->getScript('fpm-pool.conf', [
$this->service->server->ssh()->write(
"/etc/php/{$version}/fpm/pool.d/{$user}.conf",
view('ssh.services.php.fpm-pool', [
'user' => $user,
'version' => $version,
]),
]),
"create-{$version}fpm-pool-{$user}",
$site_id
true
);
$this->service->server->systemd()->restart($this->service->unit);
}
/**
* @throws SSHError
*/
public function removeFpmPool(string $user, string $version, $site_id): void
{
$this->service->server->ssh()->exec(
$this->getScript('remove-fpm-pool.sh', [
view('ssh.services.php.remove-fpm-pool', [
'user' => $user,
'version' => $version,
]),

View File

@ -1,2 +0,0 @@
echo '__config__' | sudo tee /etc/php/__version__/fpm/pool.d/__user__.conf
sudo service php__version__-fpm restart

View File

@ -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

View File

@ -1,5 +0,0 @@
sudo apt-get install -y php__version__-__name__
sudo service php__version__-fpm restart
php__version__ -m

View File

@ -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

View File

@ -1,2 +0,0 @@
sudo rm -f /etc/php/__version__/fpm/pool.d/__user__.conf
sudo service php__version__-fpm restart

View File

@ -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

View File

@ -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

View File

@ -2,33 +2,37 @@
namespace App\SSH\Services\ProcessManager;
use App\SSH\HasScripts;
use App\Exceptions\SSHError;
use Throwable;
class Supervisor extends AbstractProcessManager
{
use HasScripts;
/**
* @throws SSHError
*/
public function install(): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/install-supervisor.sh'),
view('ssh.services.process-manager.supervisor.install-supervisor'),
'install-supervisor'
);
$this->service->server->os()->cleanup();
}
/**
* @throws SSHError
*/
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/uninstall-supervisor.sh'),
view('ssh.services.process-manager.supervisor.uninstall-supervisor'),
'uninstall-supervisor'
);
$this->service->server->os()->cleanup();
}
/**
* @throws Throwable
* @throws SSHError
*/
public function create(
int $id,
@ -42,21 +46,22 @@ public function create(
): void {
$this->service->server->ssh()->write(
"/etc/supervisor/conf.d/$id.conf",
$this->generateConfigFile(
$id,
$command,
$user,
$autoStart,
$autoRestart,
$numprocs,
$logFile
),
view('ssh.services.process-manager.supervisor.worker', [
'name' => (string) $id,
'command' => $command,
'user' => $user,
'autoStart' => var_export($autoStart, true),
'autoRestart' => var_export($autoRestart, true),
'numprocs' => (string) $numprocs,
'logFile' => $logFile,
]),
true
);
$this->service->server->ssh()->exec(
$this->getScript('supervisor/create-worker.sh', [
view('ssh.services.process-manager.supervisor.create-worker', [
'id' => $id,
'log_file' => $logFile,
'logFile' => $logFile,
'user' => $user,
]),
'create-worker',
@ -70,7 +75,7 @@ public function create(
public function delete(int $id, ?int $siteId = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/delete-worker.sh', [
view('ssh.services.process-manager.supervisor.delete-worker', [
'id' => $id,
]),
'delete-worker',
@ -84,7 +89,7 @@ public function delete(int $id, ?int $siteId = null): void
public function restart(int $id, ?int $siteId = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/restart-worker.sh', [
view('ssh.services.process-manager.supervisor.restart-worker', [
'id' => $id,
]),
'restart-worker',
@ -98,7 +103,7 @@ public function restart(int $id, ?int $siteId = null): void
public function stop(int $id, ?int $siteId = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/stop-worker.sh', [
view('ssh.services.process-manager.supervisor.stop-worker', [
'id' => $id,
]),
'stop-worker',
@ -112,7 +117,7 @@ public function stop(int $id, ?int $siteId = null): void
public function start(int $id, ?int $siteId = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('supervisor/start-worker.sh', [
view('ssh.services.process-manager.supervisor.start-worker', [
'id' => $id,
]),
'start-worker',
@ -129,24 +134,4 @@ public function getLogs(string $user, string $logPath): string
"tail -100 $logPath"
);
}
private function generateConfigFile(
int $id,
string $command,
string $user,
bool $autoStart,
bool $autoRestart,
int $numprocs,
string $logFile
): string {
return $this->getScript('supervisor/worker.conf', [
'name' => (string) $id,
'command' => $command,
'user' => $user,
'auto_start' => var_export($autoStart, true),
'auto_restart' => var_export($autoRestart, true),
'numprocs' => (string) $numprocs,
'log_file' => $logFile,
]);
}
}

View File

@ -1,3 +0,0 @@
if ! sudo supervisorctl restart __id__:*; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -1,3 +0,0 @@
if ! sudo supervisorctl start __id__:*; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -1,3 +0,0 @@
if ! sudo supervisorctl stop __id__:*; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -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

View File

@ -2,14 +2,13 @@
namespace App\SSH\Services\Redis;
use App\SSH\HasScripts;
use App\Exceptions\ServiceInstallationFailed;
use App\Exceptions\SSHError;
use App\SSH\Services\AbstractService;
use Closure;
class Redis extends AbstractService
{
use HasScripts;
public function creationRules(array $input): array
{
return [
@ -25,10 +24,14 @@ function (string $attribute, mixed $value, Closure $fail) {
];
}
/**
* @throws ServiceInstallationFailed
* @throws SSHError
*/
public function install(): void
{
$this->service->server->ssh()->exec(
$this->getScript('install.sh'),
view('ssh.services.redis.install'),
'install-redis'
);
$status = $this->service->server->systemd()->status($this->service->unit);
@ -36,10 +39,13 @@ public function install(): void
$this->service->server->os()->cleanup();
}
/**
* @throws SSHError
*/
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('uninstall.sh'),
view('ssh.services.redis.uninstall'),
'uninstall-redis'
);
$this->service->server->os()->cleanup();

View File

@ -6,25 +6,31 @@
use App\Exceptions\SSLCreationException;
use App\Models\Site;
use App\Models\Ssl;
use App\SSH\HasScripts;
use Closure;
use Illuminate\Support\Str;
use Throwable;
class Nginx extends AbstractWebserver
{
use HasScripts;
/**
* @throws SSHError
*/
public function install(): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/install-nginx.sh', [
'config' => $this->getScript('nginx/nginx.conf', [
'user' => $this->service->server->getSshUser(),
]),
]),
view('ssh.services.webserver.nginx.install-nginx'),
'install-nginx'
);
$this->service->server->ssh()->write(
'/etc/nginx/nginx.conf',
view('ssh.services.webserver.nginx.nginx', [
'user' => $this->service->server->getSshUser(),
]),
true
);
$this->service->server->systemd()->restart('nginx');
$this->service->server->os()->cleanup();
}
@ -43,10 +49,13 @@ function (string $attribute, mixed $value, Closure $fail) {
];
}
/**
* @throws SSHError
*/
public function uninstall(): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/uninstall-nginx.sh'),
view('ssh.services.webserver.nginx.uninstall-nginx'),
'uninstall-nginx'
);
$this->service->server->os()->cleanup();
@ -62,50 +71,68 @@ public function createVHost(Site $site): void
$ssh = $this->service->server->ssh($site->user);
$ssh->exec(
$this->getScript('nginx/create-path.sh', [
view('ssh.services.webserver.nginx.create-path', [
'path' => $site->path,
]),
'create-path',
$site->id
);
$this->service->server->ssh()->write(
'/etc/nginx/sites-available/'.$site->domain,
view('ssh.services.webserver.nginx.vhost', [
'site' => $site,
]),
true
);
$this->service->server->ssh()->exec(
$this->getScript('nginx/create-vhost.sh', [
view('ssh.services.webserver.nginx.create-vhost', [
'domain' => $site->domain,
'path' => $site->path,
'vhost' => $this->generateVhost($site),
'vhost' => view('ssh.services.webserver.nginx.vhost', [
'site' => $site,
]),
]),
'create-vhost',
$site->id
);
}
public function updateVHost(Site $site, bool $noSSL = false, ?string $vhost = null): void
/**
* @throws SSHError
*/
public function updateVHost(Site $site, ?string $vhost = null): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/update-vhost.sh', [
'domain' => $site->domain,
'path' => $site->path,
'vhost' => $vhost ?? $this->generateVhost($site, $noSSL),
$this->service->server->ssh()->write(
'/etc/nginx/sites-available/'.$site->domain,
$vhost ?? view('ssh.services.webserver.nginx.vhost', [
'site' => $site,
]),
'update-vhost',
$site->id
true
);
$this->service->server->systemd()->restart('nginx');
}
/**
* @throws SSHError
*/
public function getVHost(Site $site): string
{
return $this->service->server->ssh()->exec(
$this->getScript('nginx/get-vhost.sh', [
view('ssh.services.webserver.nginx.get-vhost', [
'domain' => $site->domain,
]),
);
}
/**
* @throws SSHError
*/
public function deleteSite(Site $site): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/delete-site.sh', [
view('ssh.services.webserver.nginx.delete-site', [
'domain' => $site->domain,
'path' => $site->path,
]),
@ -115,13 +142,16 @@ public function deleteSite(Site $site): void
$this->service->restart();
}
/**
* @throws SSHError
*/
public function changePHPVersion(Site $site, $version): void
{
$this->service->server->ssh()->exec(
$this->getScript('nginx/change-php-version.sh', [
view('ssh.services.webserver.nginx.change-php-version', [
'domain' => $site->domain,
'old_version' => $site->php_version,
'new_version' => $version,
'oldVersion' => $site->php_version,
'newVersion' => $version,
]),
'change-php-version',
$site->id
@ -137,19 +167,18 @@ public function setupSSL(Ssl $ssl): void
foreach ($ssl->getDomains() as $domain) {
$domains .= ' -d '.$domain;
}
$command = $this->getScript('nginx/create-letsencrypt-ssl.sh', [
$command = view('ssh.services.webserver.nginx.create-letsencrypt-ssl', [
'email' => $ssl->site->server->creator->email,
'domain' => $ssl->site->domain,
'domains' => $domains,
'web_directory' => $ssl->site->getWebDirectoryPath(),
]);
if ($ssl->type == 'custom') {
$command = $this->getScript('nginx/create-custom-ssl.sh', [
$command = view('ssh.services.webserver.nginx.create-custom-ssl', [
'path' => $ssl->getCertsDirectoryPath(),
'certificate' => $ssl->certificate,
'pk' => $ssl->pk,
'certificate_path' => $ssl->getCertificatePath(),
'pk_path' => $ssl->getPkPath(),
'certificatePath' => $ssl->getCertificatePath(),
'pkPath' => $ssl->getPkPath(),
]);
}
$result = $this->service->server->ssh()->setLog($ssl->log)->exec(
@ -160,8 +189,6 @@ public function setupSSL(Ssl $ssl): void
if (! $ssl->validateSetup($result)) {
throw new SSLCreationException;
}
$this->updateVHost($ssl->site);
}
/**
@ -175,55 +202,6 @@ public function removeSSL(Ssl $ssl): void
$ssl->site_id
);
$this->updateVHost($ssl->site, true);
$this->service->server->systemd()->restart('nginx');
}
protected function generateVhost(Site $site, bool $noSSL = false): string
{
$ssl = $site->activeSsl;
if ($noSSL) {
$ssl = null;
}
$vhost = $this->getScript('nginx/vhost.conf');
if ($ssl) {
$vhost = $this->getScript('nginx/vhost-ssl.conf');
}
if ($site->type()->language() === 'php') {
$vhost = $this->getScript('nginx/php-vhost.conf');
if ($ssl) {
$vhost = $this->getScript('nginx/php-vhost-ssl.conf');
}
}
if ($site->port) {
$vhost = $this->getScript('nginx/reverse-vhost.conf');
if ($ssl) {
$vhost = $this->getScript('nginx/reverse-vhost-ssl.conf');
}
$vhost = Str::replace('__port__', (string) $site->port, $vhost);
}
$php_socket = 'unix:/var/run/php/php-fpm.sock';
if ($site->isIsolated()) {
$php_socket = "unix:/run/php/php{$site->php_version}-fpm-{$site->user}.sock";
}
$vhost = Str::replace('__domain__', $site->domain, $vhost);
$vhost = Str::replace('__aliases__', $site->getAliasesString(), $vhost);
$vhost = Str::replace('__path__', $site->path, $vhost);
$vhost = Str::replace('__web_directory__', $site->web_directory, $vhost);
$vhost = Str::replace('__php_socket__', $php_socket, $vhost);
if ($ssl) {
$vhost = Str::replace('__certificate__', $ssl->getCertificatePath(), $vhost);
$vhost = Str::replace('__private_key__', $ssl->getPkPath(), $vhost);
}
if ($site->php_version) {
$vhost = Str::replace('__php_version__', $site->php_version, $vhost);
}
return $vhost;
$this->updateVHost($ssl->site);
}
}

View File

@ -9,7 +9,7 @@ interface Webserver
{
public function createVHost(Site $site): void;
public function updateVHost(Site $site, bool $noSSL = false, ?string $vhost = null): void;
public function updateVHost(Site $site, ?string $vhost = null): void;
public function getVHost(Site $site): string;

View File

@ -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__"

View File

@ -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

View File

@ -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

View File

@ -1,7 +0,0 @@
rm -rf __path__
sudo rm /etc/nginx/sites-available/__domain__
sudo rm /etc/nginx/sites-enabled/__domain__
echo "Site deleted"

View File

@ -1 +0,0 @@
cat /etc/nginx/sites-available/__domain__

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,3 +0,0 @@
location __from__ {
return __mode__ __to__;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,3 +0,0 @@
echo '__vhost__' | sudo tee /etc/nginx/sites-available/__domain__
sudo service nginx restart

View File

@ -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;
}

View File

@ -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;
}

View File

@ -3,17 +3,18 @@
namespace App\SSH\Storage;
use App\Exceptions\SSHCommandError;
use App\SSH\HasScripts;
use App\Exceptions\SSHError;
use Illuminate\Support\Facades\Log;
class Dropbox extends AbstractStorage
{
use HasScripts;
/**
* @throws SSHError
*/
public function upload(string $src, string $dest): array
{
$upload = $this->server->ssh()->exec(
$this->getScript('dropbox/upload.sh', [
view('ssh.storage.dropbox.upload', [
'src' => $src,
'dest' => $dest,
'token' => $this->storageProvider->credentials['token'],
@ -33,10 +34,13 @@ public function upload(string $src, string $dest): array
];
}
/**
* @throws SSHError
*/
public function download(string $src, string $dest): void
{
$this->server->ssh()->exec(
$this->getScript('dropbox/download.sh', [
view('ssh.storage.dropbox.download', [
'src' => $src,
'dest' => $dest,
'token' => $this->storageProvider->credentials['token'],
@ -45,10 +49,13 @@ public function download(string $src, string $dest): void
);
}
/**
* @throws SSHError
*/
public function delete(string $src): void
{
$this->server->ssh()->exec(
$this->getScript('dropbox/delete-file.sh', [
view('ssh.storage.dropbox.delete-file', [
'src' => $src,
'token' => $this->storageProvider->credentials['token'],
]),

View File

@ -2,16 +2,17 @@
namespace App\SSH\Storage;
use App\SSH\HasScripts;
use App\Exceptions\SSHError;
class FTP extends AbstractStorage
{
use HasScripts;
/**
* @throws SSHError
*/
public function upload(string $src, string $dest): array
{
$this->server->ssh()->exec(
$this->getScript('ftp/upload.sh', [
view('ssh.storage.ftp.upload', [
'src' => $src,
'dest' => $dest,
'host' => $this->storageProvider->credentials['host'],
@ -29,10 +30,13 @@ public function upload(string $src, string $dest): array
];
}
/**
* @throws SSHError
*/
public function download(string $src, string $dest): void
{
$this->server->ssh()->exec(
$this->getScript('ftp/download.sh', [
view('ssh.storage.ftp.download', [
'src' => $src,
'dest' => $dest,
'host' => $this->storageProvider->credentials['host'],
@ -46,10 +50,13 @@ public function download(string $src, string $dest): void
);
}
/**
* @throws SSHError
*/
public function delete(string $src): void
{
$this->server->ssh()->exec(
$this->getScript('ftp/delete-file.sh', [
view('ssh.storage.ftp.delete-file', [
'src' => $src,
'host' => $this->storageProvider->credentials['host'],
'port' => $this->storageProvider->credentials['port'],

View File

@ -2,20 +2,21 @@
namespace App\SSH\Storage;
use App\SSH\HasScripts;
use App\Exceptions\SSHError;
class Local extends AbstractStorage
{
use HasScripts;
/**
* @throws SSHError
*/
public function upload(string $src, string $dest): array
{
$destDir = dirname($dest);
$this->server->ssh()->exec(
$this->getScript('local/upload.sh', [
view('ssh.storage.local.upload', [
'src' => $src,
'dest_dir' => $destDir,
'dest_file' => $dest,
'destDir' => $destDir,
'destFile' => $dest,
]),
'upload-to-local'
);
@ -25,10 +26,13 @@ public function upload(string $src, string $dest): array
];
}
/**
* @throws SSHError
*/
public function download(string $src, string $dest): void
{
$this->server->ssh()->exec(
$this->getScript('local/download.sh', [
view('ssh.storage.local.download', [
'src' => $src,
'dest' => $dest,
]),
@ -36,6 +40,9 @@ public function download(string $src, string $dest): void
);
}
/**
* @throws SSHError
*/
public function delete(string $src): void
{
$this->server->os()->deleteFile($src);

View File

@ -5,12 +5,11 @@
use App\Exceptions\SSHCommandError;
use App\Exceptions\SSHError;
use App\SSH\HasS3Storage;
use App\SSH\HasScripts;
use Illuminate\Support\Facades\Log;
class S3 extends AbstractStorage
{
use HasS3Storage, HasScripts;
use HasS3Storage;
/**
* @throws SSHError
@ -20,7 +19,7 @@ public function upload(string $src, string $dest): array
/** @var \App\StorageProviders\S3 $provider */
$provider = $this->storageProvider->provider();
$uploadCommand = $this->getScript('s3/upload.sh', [
$uploadCommand = view('ssh.storage.s3.upload', [
'src' => $src,
'bucket' => $this->storageProvider->credentials['bucket'],
'dest' => $this->prepareS3Path($dest),
@ -40,7 +39,6 @@ public function upload(string $src, string $dest): array
return [
'size' => null, // You can parse the size from the output if needed
];
}
/**
@ -51,7 +49,7 @@ public function download(string $src, string $dest): void
/** @var \App\StorageProviders\S3 $provider */
$provider = $this->storageProvider->provider();
$downloadCommand = $this->getScript('s3/download.sh', [
$downloadCommand = view('ssh.storage.s3.download', [
'src' => $this->prepareS3Path($src),
'dest' => $dest,
'bucket' => $this->storageProvider->credentials['bucket'],
@ -71,13 +69,16 @@ public function download(string $src, string $dest): void
}
}
/**
* @throws SSHError
*/
public function delete(string $src): void
{
/** @var \App\StorageProviders\S3 $provider */
$provider = $this->storageProvider->provider();
$this->server->ssh()->exec(
$this->getScript('s3/delete-file.sh', [
view('ssh.storage.s3.delete-file', [
'src' => $this->prepareS3Path($src),
'bucket' => $this->storageProvider->credentials['bucket'],
'key' => $this->storageProvider->credentials['key'],

View File

@ -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__'

View File

@ -1 +0,0 @@
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -Q "DELE /__src__"

View File

@ -1 +0,0 @@
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -o "__dest__"

View File

@ -1 +0,0 @@
curl __passive__ -T "__src__" -u "__username__:__password__" ftp__ssl__://__host__:__port__/__dest__

View File

@ -1 +0,0 @@
cp __src__ __dest__

View File

@ -1,2 +0,0 @@
mkdir -p __dest_dir__
cp __src__ __dest_file__

View File

@ -2,12 +2,16 @@
namespace App\SSH\Systemd;
use App\Exceptions\SSHError;
use App\Models\Server;
class Systemd
{
public function __construct(protected Server $server) {}
/**
* @throws SSHError
*/
public function status(string $unit): string
{
$command = <<<EOD
@ -17,6 +21,9 @@ public function status(string $unit): string
return $this->server->ssh()->exec($command, sprintf('status-%s', $unit));
}
/**
* @throws SSHError
*/
public function start(string $unit): string
{
$command = <<<EOD
@ -27,6 +34,9 @@ public function start(string $unit): string
return $this->server->ssh()->exec($command, sprintf('start-%s', $unit));
}
/**
* @throws SSHError
*/
public function stop(string $unit): string
{
$command = <<<EOD
@ -37,6 +47,9 @@ public function stop(string $unit): string
return $this->server->ssh()->exec($command, sprintf('stop-%s', $unit));
}
/**
* @throws SSHError
*/
public function restart(string $unit): string
{
$command = <<<EOD
@ -47,6 +60,9 @@ public function restart(string $unit): string
return $this->server->ssh()->exec($command, sprintf('restart-%s', $unit));
}
/**
* @throws SSHError
*/
public function enable(string $unit): string
{
$command = <<<EOD
@ -58,6 +74,9 @@ public function enable(string $unit): string
return $this->server->ssh()->exec($command, sprintf('enable-%s', $unit));
}
/**
* @throws SSHError
*/
public function disable(string $unit): string
{
$command = <<<EOD

View File

@ -2,26 +2,27 @@
namespace App\SSH\Wordpress;
use App\Exceptions\SSHError;
use App\Models\Site;
use App\SSH\HasScripts;
class Wordpress
{
use HasScripts;
/**
* @throws SSHError
*/
public function install(Site $site): void
{
$site->server->ssh($site->user)->exec(
$this->getScript('install.sh', [
view('ssh.wordpress.install', [
'path' => $site->path,
'domain' => $site->domain,
'is_isolated' => $site->isIsolated() ? 'true' : 'false',
'isolated_username' => $site->user,
'db_name' => $site->type_data['database'],
'db_user' => $site->type_data['database_user'],
'db_pass' => $site->type_data['database_password'],
'db_host' => 'localhost',
'db_prefix' => 'wp_',
'isIsolated' => $site->isIsolated() ? 'true' : 'false',
'isolatedUsername' => $site->user,
'dbName' => $site->type_data['database'],
'dbUser' => $site->type_data['database_user'],
'dbPass' => $site->type_data['database_password'],
'dbHost' => 'localhost',
'dbPrefix' => 'wp_',
'username' => $site->type_data['username'],
'password' => $site->type_data['password'],
'email' => $site->type_data['email'],

View File

@ -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

View File

@ -3,6 +3,7 @@
namespace App\ServerTypes;
use App\Enums\ServiceStatus;
use App\Exceptions\SSHError;
use App\Models\Server;
use App\SSH\Services\PHP\PHP;
@ -15,6 +16,9 @@ public function __construct(Server $server)
$this->server = $server;
}
/**
* @throws SSHError
*/
public function install(): void
{
$this->createUser();

View File

@ -3,7 +3,10 @@
namespace App\SiteTypes;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\SSHError;
use App\Models\Site;
use App\SSH\Services\PHP\PHP;
use Illuminate\Support\Str;
abstract class AbstractSiteType implements SiteType
{
@ -14,6 +17,26 @@ public function __construct(Site $site)
$this->site = $site;
}
public function createRules(array $input): array
{
return [];
}
public function createFields(array $input): array
{
return [];
}
public function data(array $input): array
{
return [];
}
public function editRules(array $input): array
{
return [];
}
protected function progress(int $percentage): void
{
$this->site->progress = $percentage;
@ -22,6 +45,7 @@ protected function progress(int $percentage): void
/**
* @throws FailedToDeployGitKey
* @throws SSHError
*/
protected function deployKey(): void
{
@ -35,4 +59,31 @@ protected function deployKey(): void
$this->site->ssh_key
);
}
/**
* @throws SSHError
*/
protected function isolate(): void
{
if (! $this->site->isIsolated()) {
return;
}
$this->site->server->os()->createIsolatedUser(
$this->site->user,
Str::random(15),
$this->site->id
);
// Generate the FPM pool
if ($this->site->php_version) {
/** @var PHP $php */
$php = $this->site->php()->handler();
$php->createFpmPool(
$this->site->user,
$this->site->php_version,
$this->site->id
);
}
}
}

View File

@ -3,6 +3,7 @@
namespace App\SiteTypes;
use App\Enums\SiteFeature;
use App\Exceptions\SSHError;
use App\SSH\Services\Webserver\Webserver;
use Illuminate\Validation\Rule;
@ -41,9 +42,12 @@ public function data(array $input): array
return [];
}
/**
* @throws SSHError
*/
public function install(): void
{
$this->site->isolate();
$this->isolate();
/** @var Webserver $webserver */
$webserver = $this->site->server->webserver()->handler();

View File

@ -3,6 +3,7 @@
namespace App\SiteTypes;
use App\Enums\SiteFeature;
use App\Exceptions\SSHError;
use App\SSH\Services\Webserver\Webserver;
use Illuminate\Validation\Rule;
@ -41,9 +42,12 @@ public function data(array $input): array
];
}
/**
* @throws SSHError
*/
public function install(): void
{
$this->site->isolate();
$this->isolate();
/** @var Webserver $webserver */
$webserver = $this->site->server->webserver()->handler();

View File

@ -4,6 +4,7 @@
use App\Enums\SiteFeature;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\SSHError;
use App\SSH\Composer\Composer;
use App\SSH\Git\Git;
use App\SSH\Services\Webserver\Webserver;
@ -73,10 +74,11 @@ public function data(array $input): array
/**
* @throws FailedToDeployGitKey
* @throws SSHError
*/
public function install(): void
{
$this->site->isolate();
$this->isolate();
/** @var Webserver $webserver */
$webserver = $this->site->server->webserver()->handler();

View File

@ -6,8 +6,10 @@
use App\Actions\Database\CreateDatabaseUser;
use App\Actions\Database\LinkUser;
use App\Enums\SiteFeature;
use App\Exceptions\SSHError;
use App\Models\Database;
use App\Models\DatabaseUser;
use App\SSH\Services\Webserver\Webserver;
use Closure;
use Illuminate\Validation\Rule;
@ -82,9 +84,12 @@ public function data(array $input): array
];
}
/**
* @throws SSHError
*/
public function install(): void
{
$this->site->isolate();
$this->isolate();
/** @var Webserver $webserver */
$webserver = $this->site->server->webserver()->handler();

View File

@ -11,6 +11,7 @@
use App\Enums\PHPIniType;
use App\Models\Server;
use App\Models\Service;
use App\Web\Pages\Servers\Logs\Index;
use Exception;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Select;
@ -102,6 +103,16 @@ private function installExtensionAction(): Action
try {
app(InstallPHPExtension::class)->install($this->server, $data);
Notification::make()
->success()
->title('PHP Extension is being installed!')
->body('You can check the logs for more information.')
->actions([
\Filament\Notifications\Actions\Action::make('View Logs')
->url(Index::getUrl(parameters: ['server' => $this->server->id])),
])
->send();
} catch (Exception $e) {
Notification::make()
->danger()

View File

@ -74,7 +74,7 @@ private function vhostAction(): Action
run_action($this, function () use ($data) {
/** @var Webserver $handler */
$handler = $this->server->webserver()->handler();
$handler->updateVHost($this->site, false, $data['vhost']);
$handler->updateVHost($this->site, $data['vhost']);
Notification::make()
->success()
->title('VHost updated!')

View File

@ -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