vaulterm/server/main.go

40 lines
738 B
Go
Raw Normal View History

2024-11-05 18:43:59 +07:00
package main
2024-11-06 06:24:14 +00:00
import (
2024-11-06 09:50:41 +00:00
"fmt"
2024-11-06 06:24:14 +00:00
2024-11-06 09:50:41 +00:00
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
"rul.sh/vaulterm/lib"
2024-11-06 06:24:14 +00:00
)
2024-11-06 09:50:41 +00:00
func main() {
app := fiber.New()
2024-11-06 06:24:14 +00:00
2024-11-06 09:50:41 +00:00
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
2024-11-06 06:24:14 +00:00
})
2024-11-06 09:50:41 +00:00
app.Use("/ws", func(c *fiber.Ctx) error {
if websocket.IsWebSocketUpgrade(c) {
return c.Next()
2024-11-06 06:24:14 +00:00
}
2024-11-06 09:50:41 +00:00
return fiber.ErrUpgradeRequired
})
2024-11-06 14:53:07 +07:00
2024-11-06 09:50:41 +00:00
app.Get("/ws/ssh", websocket.New(func(c *websocket.Conn) {
err := lib.NewSSHWebsocketSession(c, &lib.SSHConfig{
HostName: "10.0.0.102",
User: "root",
Password: "ausya2",
})
2024-11-06 06:24:14 +00:00
2024-11-06 09:50:41 +00:00
if err != nil {
msg := fmt.Sprintf("\r\n%s\r\n", err.Error())
c.WriteMessage(websocket.TextMessage, []byte(msg))
2024-11-06 06:24:14 +00:00
}
2024-11-06 09:50:41 +00:00
}))
2024-11-06 06:24:14 +00:00
2024-11-06 09:50:41 +00:00
app.Listen(":3000")
2024-11-05 18:43:59 +07:00
}