Skip to content

Commit 076f5d0

Browse files
authored
feat: adds shell behind a flag or env var (#3737)
1 parent b8a8781 commit 076f5d0

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

assets/components/ContainerViewer/ContainerActionsToolbar.vue

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,21 @@
135135
</li>
136136
</template>
137137

138-
<li class="line" v-if="host.type === 'local'"></li>
139-
<li v-if="host.type === 'local'">
140-
<a @click.prevent="showDrawer(Terminal, { container, action: 'attach' }, 'lg')">
141-
<ri:terminal-window-fill /> Attach
142-
<KeyShortcut char="a" :modifiers="['shift', 'meta']" />
143-
</a>
144-
</li>
145-
<li v-if="host.type === 'local'">
146-
<a @click.prevent="showDrawer(Terminal, { container, action: 'exec' }, 'lg')">
147-
<material-symbols:terminal /> Shell
148-
<KeyShortcut char="e" :modifiers="['shift', 'meta']" />
149-
</a>
150-
</li>
138+
<template v-if="enableShell && host.type === 'local'">
139+
<li class="line"></li>
140+
<li>
141+
<a @click.prevent="showDrawer(Terminal, { container, action: 'attach' }, 'lg')">
142+
<ri:terminal-window-fill /> Attach
143+
<KeyShortcut char="a" :modifiers="['shift', 'meta']" />
144+
</a>
145+
</li>
146+
<li>
147+
<a @click.prevent="showDrawer(Terminal, { container, action: 'exec' }, 'lg')">
148+
<material-symbols:terminal /> Shell
149+
<KeyShortcut char="e" :modifiers="['shift', 'meta']" />
150+
</a>
151+
</li>
152+
</template>
151153
</ul>
152154
</div>
153155
</template>
@@ -160,7 +162,7 @@ import LogAnalytics from "../LogViewer/LogAnalytics.vue";
160162
import Terminal from "@/components/Terminal.vue";
161163
162164
const { showSearch } = useSearchFilter();
163-
const { enableActions } = config;
165+
const { enableActions, enableShell } = config;
164166
const { streamConfig, hasComplexLogs, levels } = useLoggingContext();
165167
const showDrawer = useDrawer();
166168
@@ -177,20 +179,21 @@ onKeyStroke("f", (e) => {
177179
}
178180
}
179181
});
182+
if (enableShell) {
183+
onKeyStroke("a", (e) => {
184+
if ((e.ctrlKey || e.metaKey) && e.shiftKey) {
185+
showDrawer(Terminal, { container, action: "attach" }, "lg");
186+
e.preventDefault();
187+
}
188+
});
180189
181-
onKeyStroke("a", (e) => {
182-
if ((e.ctrlKey || e.metaKey) && e.shiftKey) {
183-
showDrawer(Terminal, { container, action: "attach" }, "lg");
184-
e.preventDefault();
185-
}
186-
});
187-
188-
onKeyStroke("e", (e) => {
189-
if ((e.ctrlKey || e.metaKey) && e.shiftKey) {
190-
showDrawer(Terminal, { container, action: "exec" }, "lg");
191-
e.preventDefault();
192-
}
193-
});
190+
onKeyStroke("e", (e) => {
191+
if ((e.ctrlKey || e.metaKey) && e.shiftKey) {
192+
showDrawer(Terminal, { container, action: "exec" }, "lg");
193+
e.preventDefault();
194+
}
195+
});
196+
}
194197
195198
const downloadParams = computed(() =>
196199
Object.entries(toValue(streamConfig))

assets/stores/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface Config {
1111
hosts: Host[];
1212
authProvider: "simple" | "none" | "forward-proxy";
1313
enableActions: boolean;
14+
enableShell: boolean;
1415
user?: {
1516
username: string;
1617
email: string;

internal/support/cli/args.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Args struct {
2222
AuthHeaderName string `arg:"--auth-header-name,env:DOZZLE_AUTH_HEADER_NAME" default:"Remote-Name" help:"sets the HTTP Header to use for name in Forward Proxy configuration."`
2323
AuthHeaderFilter string `arg:"--auth-header-filter,env:DOZZLE_AUTH_HEADER_FILTER" default:"Remote-Filter" help:"sets the HTTP Header to use for filtering in Forward Proxy configuration."`
2424
EnableActions bool `arg:"--enable-actions,env:DOZZLE_ENABLE_ACTIONS" default:"false" help:"enables essential actions on containers from the web interface."`
25+
EnableShell bool `arg:"--enable-shell,env:DOZZLE_ENABLE_SHELL" default:"false" help:"enables shell access to containers from the web interface."`
2526
FilterStrings []string `arg:"env:DOZZLE_FILTER,--filter,separate" help:"filters docker containers using Docker syntax."`
2627
Filter map[string][]string `arg:"-"`
2728
RemoteHost []string `arg:"env:DOZZLE_REMOTE_HOST,--remote-host,separate" help:"list of hosts to connect remotely"`

internal/web/index.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (h *handler) executeTemplate(w http.ResponseWriter, req *http.Request) {
6060
config["hostname"] = h.config.Hostname
6161
config["hosts"] = hosts
6262
config["enableActions"] = h.config.EnableActions
63+
config["enableShell"] = h.config.EnableShell
6364
}
6465

6566
if user != nil {

internal/web/routes.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Config struct {
3535
Dev bool
3636
Authorization Authorization
3737
EnableActions bool
38+
EnableShell bool
3839
Labels container.ContainerLabels
3940
}
4041

@@ -107,8 +108,6 @@ func createRouter(h *handler) *chi.Mux {
107108
r.Get("/hosts/{host}/containers/{id}/logs/stream", h.streamContainerLogs)
108109
r.Get("/hosts/{host}/logs/stream", h.streamHostLogs)
109110
r.Get("/hosts/{host}/containers/{id}/logs", h.fetchLogsBetweenDates)
110-
r.Get("/hosts/{host}/containers/{id}/attach", h.attach)
111-
r.Get("/hosts/{host}/containers/{id}/exec", h.exec)
112111
r.Get("/hosts/{host}/logs/mergedStream/{ids}", h.streamLogsMerged)
113112
r.Get("/containers/{hostIds}/download", h.downloadLogs) // formatted as host:container,host:container
114113
r.Get("/stacks/{stack}/logs/stream", h.streamStackLogs)
@@ -118,6 +117,10 @@ func createRouter(h *handler) *chi.Mux {
118117
if h.config.EnableActions {
119118
r.Post("/hosts/{host}/containers/{id}/actions/{action}", h.containerActions)
120119
}
120+
if h.config.EnableShell {
121+
r.Get("/hosts/{host}/containers/{id}/attach", h.attach)
122+
r.Get("/hosts/{host}/containers/{id}/exec", h.exec)
123+
}
121124
r.Get("/releases", h.releases)
122125
r.Get("/profile/avatar", h.avatar)
123126
r.Patch("/profile", h.updateProfile)

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func createServer(args cli.Args, hostService web.HostService) *http.Server {
191191
TTL: authTTL,
192192
},
193193
EnableActions: args.EnableActions,
194+
EnableShell: args.EnableShell,
194195
Labels: args.Filter,
195196
}
196197

0 commit comments

Comments
 (0)