mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
refactoring
This commit is contained in:
@ -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)));
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
19
app/SSHCommands/Firewall/InstallUfwCommand.php
Executable file
19
app/SSHCommands/Firewall/InstallUfwCommand.php
Executable 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();
|
||||
}
|
||||
}
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user