Skip to content

Commit b13a952

Browse files
authored
Merge branch '3.x' into add-ubuntu-26-suppor
2 parents 31e0ba4 + 4e629ff commit b13a952

6 files changed

Lines changed: 94 additions & 5 deletions

File tree

app/Services/Firewall/AbstractFirewall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected function createBasicFirewallRules(): void
1414
'type' => 'allow',
1515
'name' => 'SSH',
1616
'protocol' => 'tcp',
17-
'port' => 22,
17+
'port' => $this->service->server->port ?? 22,
1818
'source' => null,
1919
'mask' => null,
2020
'status' => FirewallRuleStatus::READY,

app/Services/Firewall/Ufw.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public function install(): void
3030
$this->createBasicFirewallRules();
3131

3232
$this->service->server->ssh()->exec(
33-
view('ssh.services.firewall.ufw.install-ufw'),
33+
view('ssh.services.firewall.ufw.install-ufw', [
34+
'sshPort' => $this->service->server->port ?? 22,
35+
]),
3436
'install-ufw'
3537
);
3638
event('service.installed', $this->service);

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
// 'ExampleClass' => App\Example\ExampleClass::class,
256256
])->toArray(),
257257

258-
'version' => '3.21.3',
258+
'version' => '3.22.0',
259259

260260
'demo' => env('APP_DEMO', false),
261261

resources/views/ssh/services/firewall/ufw/install-ufw.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
echo 'VITO_SSH_ERROR' && exit 1
77
fi
88

9-
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 22; then
9+
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port {{ $sshPort }}; then
1010
echo 'VITO_SSH_ERROR' && exit 1
1111
fi
1212

resources/views/ssh/storage/dropbox/upload.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
--header 'Dropbox-API-Arg: {"path":"{{ $dest }}"}' \
44
--header 'Content-Type: text/plain; charset=dropbox-cors-hack' \
55
--header 'Authorization: Bearer {{ $token }}' \
6-
--data-binary '@{{ $src }}'
6+
--data-binary '{{ "@" . $src }}'
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Tests\Unit\SSH\Services\Firewall;
4+
5+
use App\Facades\SSH;
6+
use App\Services\Firewall\Ufw;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Tests\TestCase;
9+
10+
class UfwInstallTest extends TestCase
11+
{
12+
use RefreshDatabase;
13+
14+
public function test_install_seeds_ssh_rule_with_custom_server_port(): void
15+
{
16+
SSH::fake();
17+
18+
$this->server->update(['port' => 22022]);
19+
20+
/** @var Ufw $ufw */
21+
$ufw = $this->server->services()
22+
->where('type', Ufw::type())
23+
->firstOrFail()
24+
->handler();
25+
26+
$ufw->install();
27+
28+
$this->assertDatabaseHas('firewall_rules', [
29+
'server_id' => $this->server->id,
30+
'name' => 'SSH',
31+
'port' => 22022,
32+
]);
33+
34+
$this->assertDatabaseMissing('firewall_rules', [
35+
'server_id' => $this->server->id,
36+
'name' => 'SSH',
37+
'port' => 22,
38+
]);
39+
}
40+
41+
public function test_install_seeds_ssh_rule_with_default_port_when_unchanged(): void
42+
{
43+
SSH::fake();
44+
45+
$this->server->update(['port' => 22]);
46+
47+
/** @var Ufw $ufw */
48+
$ufw = $this->server->services()
49+
->where('type', Ufw::type())
50+
->firstOrFail()
51+
->handler();
52+
53+
$ufw->install();
54+
55+
$this->assertDatabaseHas('firewall_rules', [
56+
'server_id' => $this->server->id,
57+
'name' => 'SSH',
58+
'port' => 22,
59+
]);
60+
}
61+
62+
public function test_install_seeds_http_and_https_rules_unchanged(): void
63+
{
64+
SSH::fake();
65+
66+
$this->server->update(['port' => 22022]);
67+
68+
/** @var Ufw $ufw */
69+
$ufw = $this->server->services()
70+
->where('type', Ufw::type())
71+
->firstOrFail()
72+
->handler();
73+
74+
$ufw->install();
75+
76+
$this->assertDatabaseHas('firewall_rules', [
77+
'server_id' => $this->server->id,
78+
'name' => 'HTTP',
79+
'port' => 80,
80+
]);
81+
$this->assertDatabaseHas('firewall_rules', [
82+
'server_id' => $this->server->id,
83+
'name' => 'HTTPS',
84+
'port' => 443,
85+
]);
86+
}
87+
}

0 commit comments

Comments
 (0)