mirror of
https://github.com/syssecfsu/witty.git
synced 2024-11-01 09:39:26 +01:00
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// command line options
|
|
var cmdToExec = []string{"bash"}
|
|
|
|
func main() {
|
|
fp, err := os.OpenFile("web_term.log", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
|
|
|
if err == nil {
|
|
defer fp.Close()
|
|
log.SetOutput(fp)
|
|
gin.DefaultWriter = fp
|
|
}
|
|
|
|
// parse the arguments. User can pass the command to execute
|
|
// by default, we use bash, but macos users might want to use zsh
|
|
// you can also run single program, such as pstree, htop...
|
|
// but program might misbehave (htop seems to be fine)
|
|
args := os.Args
|
|
|
|
if len(args) > 1 {
|
|
cmdToExec = args[1:]
|
|
log.Println(cmdToExec)
|
|
}
|
|
|
|
registry.init()
|
|
|
|
rt := gin.Default()
|
|
|
|
rt.SetTrustedProxies(nil)
|
|
rt.LoadHTMLGlob("./assets/*.html")
|
|
|
|
rt.GET("/view/*sname", func(c *gin.Context) {
|
|
c.HTML(http.StatusOK, "index.html", gin.H{
|
|
"title": "Watcher terminal",
|
|
"path": "/ws_view",
|
|
})
|
|
})
|
|
|
|
rt.GET("/ws_do", func(c *gin.Context) {
|
|
wsHandler(c.Writer, c.Request, false)
|
|
})
|
|
|
|
rt.GET("/ws_view", func(c *gin.Context) {
|
|
wsHandler(c.Writer, c.Request, true)
|
|
})
|
|
|
|
// handle static files
|
|
rt.Static("/assets", "./assets")
|
|
|
|
rt.GET("/", func(c *gin.Context) {
|
|
c.HTML(http.StatusOK, "index.html", gin.H{
|
|
"title": "Master terminal",
|
|
"path": "/ws_do",
|
|
})
|
|
host = &c.Request.Host
|
|
})
|
|
|
|
rt.RunTLS(":8080", "./tls/cert.pem", "./tls/private-key.pem")
|
|
}
|