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
208 changed files with 1080 additions and 1012 deletions

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

@ -1,11 +0,0 @@
if ! sudo ufw __type__ from __source____mask__ to any proto __protocol__ port __port__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service ufw restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -1,27 +0,0 @@
if ! sudo ufw default deny incoming; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw default allow outgoing; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 22; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 80; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 443; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw --force enable; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -1,11 +0,0 @@
if ! sudo ufw delete __type__ from __source____mask__ to any proto __protocol__ port __port__; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service ufw restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi