@@ -15,6 +15,9 @@ class RunCommand extends Component
15
15
16
16
public function mount ($ servers )
17
17
{
18
+ if (! auth ()->user ()->isAdmin ()) {
19
+ abort (403 );
20
+ }
18
21
$ this ->servers = $ servers ;
19
22
$ this ->containers = $ this ->getAllActiveContainers ();
20
23
}
@@ -26,63 +29,25 @@ private function getAllActiveContainers()
26
29
return [];
27
30
}
28
31
29
- return $ server ->definedResources ()
30
- ->filter (function ($ resource ) {
31
- $ status = method_exists ($ resource , 'realStatus ' ) ? $ resource ->realStatus () : (method_exists ($ resource , 'status ' ) ? $ resource ->status () : 'exited ' );
32
-
33
- return str_starts_with ($ status , 'running: ' );
34
- })
35
- ->map (function ($ resource ) use ($ server ) {
36
- if (isDev ()) {
37
- if (data_get ($ resource , 'name ' ) === 'coolify-db ' ) {
38
- $ container_name = 'coolify-db ' ;
39
-
40
- return [
41
- 'name ' => $ resource ->name ,
42
- 'connection_name ' => $ container_name ,
43
- 'uuid ' => $ resource ->uuid ,
44
- 'status ' => 'running ' ,
45
- 'server ' => $ server ,
46
- 'server_uuid ' => $ server ->uuid ,
47
- ];
48
- }
49
- }
50
-
51
- if (class_basename ($ resource ) === 'Application ' ) {
52
- if (! $ server ->isSwarm ()) {
53
- $ current_containers = getCurrentApplicationContainerStatus ($ server , $ resource ->id , includePullrequests: true );
54
- }
55
- $ status = $ resource ->status ;
56
- } elseif (class_basename ($ resource ) === 'Service ' ) {
57
- $ current_containers = getCurrentServiceContainerStatus ($ server , $ resource ->id );
58
- $ status = $ resource ->status ();
59
- } else {
60
- $ status = getContainerStatus ($ server , $ resource ->uuid );
61
- if ($ status === 'running ' ) {
62
- $ current_containers = collect ([
63
- 'Names ' => $ resource ->name ,
64
- ]);
65
- }
66
- }
67
- if ($ server ->isSwarm ()) {
68
- $ container_name = $ resource ->uuid .'_ ' .$ resource ->uuid ;
69
- } else {
70
- $ container_name = data_get ($ current_containers ->first (), 'Names ' );
71
- }
72
-
32
+ return $ server ->loadAllContainers ()->map (function ($ container ) use ($ server ) {
33
+ $ state = data_get_str ($ container , 'State ' )->lower ();
34
+ if ($ state ->contains ('running ' )) {
73
35
return [
74
- 'name ' => $ resource -> name ,
75
- 'connection_name ' => $ container_name ,
76
- 'uuid ' => $ resource -> uuid ,
77
- 'status ' => $ status ,
36
+ 'name ' => data_get ( $ container , ' Names ' ) ,
37
+ 'connection_name ' => data_get ( $ container , ' Names ' ) ,
38
+ 'uuid ' => data_get ( $ container , ' Names ' ) ,
39
+ 'status ' => data_get_str ( $ container , ' State ' )-> lower () ,
78
40
'server ' => $ server ,
79
41
'server_uuid ' => $ server ->uuid ,
80
42
];
81
- });
43
+ }
44
+
45
+ return null ;
46
+ })->filter ();
82
47
});
83
48
}
84
49
85
- public function updatedSelectedUuid ($ value )
50
+ public function updatedSelectedUuid ()
86
51
{
87
52
$ this ->connectToContainer ();
88
53
}
@@ -95,9 +60,7 @@ public function connectToContainer()
95
60
96
61
return ;
97
62
}
98
-
99
63
$ container = collect ($ this ->containers )->firstWhere ('uuid ' , $ this ->selected_uuid );
100
-
101
64
$ this ->dispatch ('send-terminal-command ' ,
102
65
isset ($ container ),
103
66
$ container ['connection_name ' ] ?? $ this ->selected_uuid ,
0 commit comments