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

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