You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While this one does not (displayed on the server side, instead...)
#!/bin/bash
SCRIPT_DIR="$( dirname "${BASH_SOURCE[0]}")"# Function to display the main menushow_menu() {
whiptail --clear --backtitle "" --title "Main Menu" \
--menu "Choose a task:" 15 50 4 \
1 "Go to command line"
}
show_menu
Source Code
package main
import (
"flag""strconv""log"// "os/exec""github.com/charmbracelet/ssh""github.com/charmbracelet/wish""github.com/charmbracelet/wish/logging""github.com/charmbracelet/wish/activeterm"
)
funcmain() {
// Define command-line flagsserverPort:=flag.Int("p", 2222, "SSH Server port")
scriptPath:=flag.String("i", "", "Input script to be executed")
flag.Parse()
// Create the SSH server with a custom server configurationportStr:=strconv.Itoa(*serverPort)
s, err:=wish.NewServer(
wish.WithAddress("0.0.0.0:"+portStr),
ssh.AllocatePty(),
wish.WithMiddleware(
logging.Middleware(),
activeterm.Middleware(),
),
wish.WithPasswordAuth(func(ctx ssh.Context, passwordstring) bool {
// Implement your password authentication logic here// Example: only allow a specific username and passwordreturnctx.User() =="root"&&password=="root"
}),
wish.WithMiddleware(
func(next ssh.Handler) ssh.Handler {
returnfunc(sess ssh.Session) {
pty, _, _:=sess.Pty()
wish.Printf(sess, "Term: %s\r\n", pty.Term)
wish.Printf(sess, "PTY: %s\r\n", pty.Slave.Name())
wish.Printf(sess, "FD: %d\r\n", pty.Slave.Fd())
// wish.Println(sess, "Hello, world!")cmd:=wish.Command( sess, "/bin/bash", *scriptPath)
// cmd := exec.Command("/bin/bash", *scriptPath)// cmd.Stdout = sess// cmd.Stderr = sess// cmd.Stdin = pty.Slavecmd.Run()
next(sess)
}
},
// The last item in the chain is the first to be called.logging.Middleware(),
),
)
iferr!=nil {
log.Fatalln(err)
}
// Start the SSH server// log.Println("Starting SSH server on port 2222...")log.Printf( "Serving script %s on SSH server [port=%d]\n", *scriptPath, *serverPort)
log.Fatal(s.ListenAndServe())
}
Expected behavior
The script is displayed on the console of the client
The text was updated successfully, but these errors were encountered:
Buanderie
changed the title
Can't run bash script using dialog
wish.Command() : bash script is displayed in the server console, not the client console.
Aug 6, 2024
Describe the bug
Bash script using "dialog" is displayed on server side (on the console that launched my wish app)
Setup
Please complete the following information along with version numbers, if applicable.
To Reproduce
Use my app like so: ./myapp -i script.sh
This bash script works:
While this one does not (displayed on the server side, instead...)
Source Code
Expected behavior
The script is displayed on the console of the client
The text was updated successfully, but these errors were encountered: