From b0c181cd8dcb667aaee5100a21657eb41e4cb6e0 Mon Sep 17 00:00:00 2001 From: Yann Stepienik Date: Mon, 7 Oct 2024 21:10:25 +0100 Subject: [PATCH] [release] v0.17.0-unstable10 --- .../Header/HeaderContent/terminal.jsx | 9 +++--- src/terminal.go | 29 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/src/layout/MainLayout/Header/HeaderContent/terminal.jsx b/client/src/layout/MainLayout/Header/HeaderContent/terminal.jsx index 811fda2..5b0c533 100644 --- a/client/src/layout/MainLayout/Header/HeaderContent/terminal.jsx +++ b/client/src/layout/MainLayout/Header/HeaderContent/terminal.jsx @@ -5,11 +5,14 @@ import TerminalComponent from "../../../../components/terminal"; import * as API from '../../../../api'; import { useTranslation } from "react-i18next"; +import { useClientInfos } from "../../../../utils/hooks"; const TerminalHeader = () => { const [open, setOpen] = React.useState(false); const [status, setStatus] = React.useState(false); const { t, Trans } = useTranslation(); + const {role} = useClientInfos(); + const isAdmin = role === "2"; useEffect(() => { API.getStatus().then((res) => { @@ -21,8 +24,7 @@ const TerminalHeader = () => { setOpen((prevOpen) => !prevOpen); }; - return ( - <> + return isAdmin ? (<> { }}>Close - - ); + ) : null } export default TerminalHeader; \ No newline at end of file diff --git a/src/terminal.go b/src/terminal.go index 3edda81..442f490 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1,14 +1,11 @@ package main import ( - // "context" "net/http" "os/exec" - // "syscall" + "syscall" "time" "io" - // "os" - // "os/signal" "github.com/creack/pty" "github.com/gorilla/websocket" @@ -56,6 +53,19 @@ func HostTerminalRoute(w http.ResponseWriter, r *http.Request) { // Create arbitrary command. c := exec.Command("bash") + + // Specify the UID + + uid := uint32(1000) // Replace with the desired UID + gid := uint32(1000) // Replace with the primary GID of the user + + c.SysProcAttr = &syscall.SysProcAttr{ + Credential: &syscall.Credential{ + Uid: uid, + Gid: gid, + }, + } + // Set environment variables for better terminal emulation // env := os.Environ() env := []string{} @@ -101,17 +111,6 @@ func HostTerminalRoute(w http.ResponseWriter, r *http.Request) { // go func() { _, _ = io.Copy(ptmx, os.Stdin) }() // _, _ = io.Copy(os.Stdout, ptmx) - // Specify the UID you want to run the command as - - // uid := uint32(1000) // Replace with the desired UID - // gid := uint32(1000) // Replace with the primary GID of the user - // Set the user and group ID of the process - // cmd.SysProcAttr = &syscall.SysProcAttr{ - // Credential: &syscall.Credential{ - // Uid: uid, - // Gid: gid, - // }, - // } // stdin, err := cmd.StdinPipe() // if err != nil {