refactoring

This commit is contained in:
Saeed Vaziry
2023-08-04 18:28:04 +02:00
parent 8444323cf4
commit 643318fcfc
349 changed files with 3189 additions and 2729 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,17 +2,16 @@
namespace App\SSHCommands\Firewall;
use Illuminate\Support\Str;
trait CommandContent
{
public function content(string $os): string
public function content(): string
{
$command = Str::replace('__type__', $this->type, $this->file($os));
$command = Str::replace('__protocol__', $this->protocol, $command);
$command = Str::replace('__source__', $this->source, $command);
$command = Str::replace('__mask__', $this->mask, $command);
return Str::replace('__port__', $this->port, $command);
return str($this->file())
->replace('__type__', $this->type)
->replace('__protocol__', $this->protocol)
->replace('__source__', $this->source)
->replace('__mask__', $this->mask || $this->mask == 0 ? '/'.$this->mask : '')
->replace('__port__', $this->port)
->toString();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,29 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class InstallNginxCommand extends Command
{
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/install-nginx.sh'));
}
public function content(string $os): string
{
return Str::replace('__config__', $this->config(), $this->file($os));
}
/**
* @return string
*/
protected function config()
{
$config = File::get(base_path('system/command-templates/nginx/nginx.conf'));
return Str::replace('__user__', config('core.ssh_user'), $config);
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,28 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
class InstallRequirementsCommand extends Command
{
protected $email;
protected $name;
public function __construct($email, $name)
{
$this->email = $email;
$this->name = $name;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/install-requirements.sh'));
}
public function content(string $os): string
{
return $this->file($os);
}
}

View File

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

View File

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

View File

@ -1,71 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
class InstallWordpressCommand extends Command
{
protected $path;
protected $domain;
protected $dbName;
protected $dbUser;
protected $dbPass;
protected $dbHost;
protected $dbPrefix;
protected $username;
protected $password;
protected $email;
protected $title;
/**
* ComposerInstallCommand constructor.
*/
public function __construct($path, $domain, $dbName, $dbUser, $dbPass, $dbHost, $dbPrefix, $username, $password, $email, $title)
{
$this->path = $path;
$this->domain = $domain;
$this->dbName = $dbName;
$this->dbUser = $dbUser;
$this->dbPass = $dbPass;
$this->dbHost = $dbHost;
$this->dbPrefix = $dbPrefix;
$this->username = $username;
$this->password = $password;
$this->email = $email;
$this->title = $title;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/common/wordpress/install.sh'));
}
public function content(string $os): string
{
$command = $this->file($os);
$command = str_replace('__path__', $this->path, $command);
$command = str_replace('__domain__', $this->domain, $command);
$command = str_replace('__db_name__', $this->dbName, $command);
$command = str_replace('__db_user__', $this->dbUser, $command);
$command = str_replace('__db_pass__', $this->dbPass, $command);
$command = str_replace('__db_host__', $this->dbHost, $command);
$command = str_replace('__db_prefix__', $this->dbPrefix, $command);
$command = str_replace('__username__', $this->username, $command);
$command = str_replace('__password__', $this->password, $command);
$command = str_replace('__title__', $this->title, $command);
return str_replace('__email__', $this->email, $command);
}
}

View File

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

View File

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

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\Installation;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class InstallRequirementsCommand extends Command
{
public function __construct(protected string $email, protected string $name)
{
}
public function file(): string
{
return File::get(resource_path('commands/installation/install-requirements.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__email__', $this->email)
->replace('__name__', $this->name)
->toString();
}
}

View File

@ -1,40 +0,0 @@
<?php
namespace App\SSHCommands;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class ManageServiceCommand extends Command
{
/**
* @var string
*/
protected $unit;
/**
* @var string
*/
protected $action;
/**
* ServiceStatusCommand constructor.
*/
public function __construct($unit, $action)
{
$this->unit = $unit;
$this->action = $action;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/manage-service.sh'));
}
public function content(string $os): string
{
$command = Str::replace('__service__', $this->unit, $this->file($os));
return Str::replace('__action__', $this->action, $command);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\SSHCommands\Nginx;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class ChangeNginxPHPVersionCommand extends Command
{
public function __construct(protected string $domain, protected string $oldVersion, protected string $newVersion)
{
}
public function file(): string
{
return File::get(resource_path('commands/webserver/nginx/change-php-version.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__domain__', $this->domain)
->replace('__old_version__', $this->oldVersion)
->replace('__new_version__', $this->newVersion)
->toString();
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\SSHCommands\Nginx;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class CreateNginxVHostCommand extends Command
{
public function __construct(
protected string $domain,
protected string $path,
protected string $vhost
) {
}
public function file(): string
{
return File::get(resource_path('commands/webserver/nginx/create-vhost.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__domain__', $this->domain)
->replace('__path__', $this->path)
->replace('__vhost__', $this->vhost)
->toString();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\Nginx;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class DeleteNginxSiteCommand extends Command
{
public function __construct(protected string $domain, protected string $path)
{
}
public function file(): string
{
return File::get(resource_path('commands/webserver/nginx/delete-site.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__domain__', $this->domain)
->replace('__path__', $this->path)
->toString();
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\SSHCommands\Nginx;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class InstallNginxCommand extends Command
{
public function file(): string
{
return File::get(resource_path('commands/webserver/nginx/install-nginx.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__config__', $this->config())
->toString();
}
protected function config(): string
{
$config = File::get(resource_path('commands/webserver/nginx/nginx.conf'));
/** TODO: change user to server user */
return str($config)
->replace('__user__', config('core.ssh_user'))
->toString();
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\SSHCommands\Nginx;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class UpdateNginxRedirectsCommand extends Command
{
public function __construct(
protected string $domain,
protected string $redirects
) {
}
public function file(): string
{
return File::get(resource_path('commands/webserver/nginx/update-redirects.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__redirects__', addslashes($this->redirects))
->replace('__domain__', $this->domain)
->toString();
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\SSHCommands\Nginx;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class UpdateNginxVHostCommand extends Command
{
public function __construct(
protected string $domain,
protected string $path,
protected string $vhost
) {
}
public function file(): string
{
return File::get(resource_path('commands/webserver/nginx/update-vhost.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__domain__', $this->domain)
->replace('__path__', $this->path)
->replace('__vhost__', $this->vhost)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\PHP;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class ChangeDefaultPHPCommand extends Command
{
public function __construct(protected string $version)
{
}
public function file(): string
{
return File::get(resource_path('commands/php/change-default-php.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__version__', $this->version)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\PHP;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class GetPHPIniCommand extends Command
{
public function __construct(protected string $version)
{
}
public function file(): string
{
return File::get(resource_path('commands/php/get-php-ini.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__version__', $this->version)
->toString();
}
}

View File

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

View File

@ -0,0 +1,28 @@
<?php
namespace App\SSHCommands\PHP;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class InstallPHPCommand extends Command
{
public function __construct(protected string $version)
{
}
public function file(): string
{
return File::get(resource_path('commands/php/install-php.sh'));
}
public function content(): string
{
/** TODO: change user to server default user */
return str($this->file())
->replace('__version__', $this->version)
->replace('__user__', config('core.ssh_user'))
->toString();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\PHP;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class InstallPHPExtensionCommand extends Command
{
public function __construct(protected string $version, protected string $name)
{
}
public function file(): string
{
return File::get(resource_path('commands/php/install-php-extension.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__version__', $this->version)
->replace('__name__', $this->name)
->toString();
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\SSHCommands\PHP;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class UninstallPHPCommand extends Command
{
public function __construct(protected string $version)
{
}
public function file(): string
{
return File::get(resource_path('commands/php/uninstall-php.sh'));
}
public function content(): string
{
/** TODO: change user to server default user */
return str($this->file())
->replace('__version__', $this->version)
->replace('__user__', config('core.ssh_user'))
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\PHPMyAdmin;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class CreateNginxPHPMyAdminVHostCommand extends Command
{
public function __construct(protected string $vhost)
{
}
public function file(): string
{
return File::get(resource_path('commands/phpmyadmin/create-phpmyadmin-vhost.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__vhost__', $this->vhost)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\PHPMyAdmin;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class DeleteNginxPHPMyAdminVHost extends Command
{
public function __construct(protected string $path)
{
}
public function file(): string
{
return File::get(resource_path('commands/phpmyadmin/delete-phpmyadmin-vhost.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__path__', $this->path)
->toString();
}
}

View File

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

View File

@ -1,33 +0,0 @@
<?php
namespace App\SSHCommands\ProcessManager\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class CreateWorkerCommand extends Command
{
protected $id;
protected $config;
public function __construct($id, $config)
{
$this->id = $id;
$this->config = $config;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/process-manager/supervisor/create-worker.sh'));
}
public function content(string $os): string
{
$command = $this->file($os);
$command = Str::replace('__id__', $this->id, $command);
return Str::replace('__config__', $this->config, $command);
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\SSHCommands\ProcessManager\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class DeleteWorkerCommand extends Command
{
protected $id;
public function __construct($id)
{
$this->id = $id;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/process-manager/supervisor/delete-worker.sh'));
}
public function content(string $os): string
{
$command = $this->file($os);
return Str::replace('__id__', $this->id, $command);
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\SSHCommands\ProcessManager\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class RestartWorkerCommand extends Command
{
protected $id;
public function __construct($id)
{
$this->id = $id;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/process-manager/supervisor/restart-worker.sh'));
}
public function content(string $os): string
{
$command = $this->file($os);
return Str::replace('__id__', $this->id, $command);
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\SSHCommands\ProcessManager\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class StartWorkerCommand extends Command
{
protected $id;
public function __construct($id)
{
$this->id = $id;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/process-manager/supervisor/start-worker.sh'));
}
public function content(string $os): string
{
$command = $this->file($os);
return Str::replace('__id__', $this->id, $command);
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\SSHCommands\ProcessManager\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class StopWorkerCommand extends Command
{
protected $id;
public function __construct($id)
{
$this->id = $id;
}
public function file(string $os): string
{
return File::get(base_path('system/commands/ubuntu/process-manager/supervisor/stop-worker.sh'));
}
public function content(string $os): string
{
$command = $this->file($os);
return Str::replace('__id__', $this->id, $command);
}
}

View File

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

View File

@ -1,23 +0,0 @@
<?php
namespace App\SSHCommands;
class RemoveSSLCommand extends Command
{
protected $path;
public function __construct($path)
{
$this->path = $path;
}
public function file(string $os): string
{
return '';
}
public function content(string $os): string
{
return 'sudo rm -rf '.$this->path.'*'."\n";
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,22 @@
<?php
namespace App\SSHCommands\SSL;
use App\SSHCommands\Command;
class RemoveSSLCommand extends Command
{
public function __construct(protected string $path)
{
}
public function file(): string
{
return '';
}
public function content(): string
{
return 'sudo rm -rf '.$this->path.'*'."\n";
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\Service;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class RestartServiceCommand extends Command
{
public function __construct(protected string $unit)
{
}
public function file(): string
{
return File::get(resource_path('commands/service/restart-service.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__service__', $this->unit)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\Service;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class ServiceStatusCommand extends Command
{
public function __construct(protected string $unit)
{
}
public function file(): string
{
return File::get(resource_path('commands/service/service-status.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__service__', $this->unit)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\Service;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class StartServiceCommand extends Command
{
public function __construct(protected string $unit)
{
}
public function file(): string
{
return File::get(resource_path('commands/service/start-service.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__service__', $this->unit)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\Service;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class StopServiceCommand extends Command
{
public function __construct(protected string $unit)
{
}
public function file(): string
{
return File::get(resource_path('commands/service/stop-service.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__service__', $this->unit)
->toString();
}
}

View File

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

View File

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

View File

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

View File

@ -4,34 +4,24 @@
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class DownloadFromDropboxCommand extends Command
{
protected $src;
protected $dest;
protected $token;
public function __construct($src, $dest, $token)
public function __construct(protected string $src, protected string $dest, protected string $token)
{
$this->src = $src;
$this->dest = $dest;
$this->token = $token;
}
public function file(string $os): string
public function file(): string
{
return File::get(base_path('system/commands/common/storage/download-from-dropbox.sh'));
return File::get(resource_path('commands/storage/download-from-dropbox.sh'));
}
public function content(string $os): string
public function content(): string
{
$command = $this->file($os);
$command = Str::replace('__src__', $this->src, $command);
$command = Str::replace('__dest__', $this->dest, $command);
return Str::replace('__token__', $this->token, $command);
return str($this->file())
->replace('__src__', $this->src)
->replace('__dest__', $this->dest)
->replace('__token__', $this->token)
->toString();
}
}

View File

@ -4,34 +4,24 @@
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class UploadToDropboxCommand extends Command
{
protected $src;
protected $dest;
protected $token;
public function __construct($src, $dest, $token)
public function __construct(protected string $src, protected string $dest, protected string $token)
{
$this->src = $src;
$this->dest = $dest;
$this->token = $token;
}
public function file(string $os): string
public function file(): string
{
return File::get(base_path('system/commands/common/storage/upload-to-dropbox.sh'));
return File::get(resource_path('commands/storage/upload-to-dropbox.sh'));
}
public function content(string $os): string
public function content(): string
{
$command = $this->file($os);
$command = Str::replace('__src__', $this->src, $command);
$command = Str::replace('__dest__', $this->dest, $command);
return Str::replace('__token__', $this->token, $command);
return str($this->file())
->replace('__src__', $this->src)
->replace('__dest__', $this->dest)
->replace('__token__', $this->token)
->toString();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class CreateWorkerCommand extends Command
{
public function __construct(protected string $id, protected string $config)
{
}
public function file(): string
{
return File::get(resource_path('commands/supervisor/create-worker.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__id__', $this->id)
->replace('__config__', $this->config)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class DeleteWorkerCommand extends Command
{
public function __construct(protected string $id)
{
}
public function file(): string
{
return File::get(resource_path('commands/supervisor/delete-worker.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__id__', $this->id)
->toString();
}
}

View File

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

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class RestartWorkerCommand extends Command
{
public function __construct(protected string $id)
{
}
public function file(): string
{
return File::get(resource_path('commands/supervisor/restart-worker.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__id__', $this->id)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class StartWorkerCommand extends Command
{
public function __construct(protected string $id)
{
}
public function file(): string
{
return File::get(resource_path('commands/supervisor/start-worker.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__id__', $this->id)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\Supervisor;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class StopWorkerCommand extends Command
{
public function __construct(protected string $id)
{
}
public function file(): string
{
return File::get(resource_path('commands/supervisor/stop-worker.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__id__', $this->id)
->toString();
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class CreateUserCommand extends Command
{
public function __construct(protected string $user, protected string $password, protected string $key)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/create-user.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__user__', $this->user)
->replace('__key__', $this->key)
->replace('__password__', $this->password)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class DeleteSshKeyCommand extends Command
{
public function __construct(protected string $key)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/delete-ssh-key.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__key__', str($this->key)->replace('/', '\/'))
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class DeploySshKeyCommand extends Command
{
public function __construct(protected string $key)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/deploy-ssh-key.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__key__', addslashes($this->key))
->toString();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class EditFileCommand extends Command
{
public function __construct(protected string $path, protected string $content)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/edit-file.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__path__', $this->path)
->replace('__content__', $this->content)
->toString();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class GenerateSshKeyCommand extends Command
{
public function __construct(protected string $name)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/generate-ssh-key.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__name__', $this->name)
->toString();
}
}

View File

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

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class ReadSshKeyCommand extends Command
{
public function __construct(protected string $name)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/read-ssh-key.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__name__', $this->name)
->toString();
}
}

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