kon/pon/paths/command/command.go

32 lines
617 B
Go
Raw Normal View History

2024-04-01 22:04:54 +02:00
package command
import (
"kon/auth"
"kon/config"
"kon/utils"
"os/exec"
"github.com/gofiber/fiber/v2"
)
func HandleFunc(c *fiber.Ctx) error {
queryValue := c.Query("token")
command := c.Query("command")
if auth.VerifyToken(queryValue) {
val, ok := config.Config.Commands[command]
if !ok {
return c.SendString("Command not found.")
} else {
cmd := exec.Command(val[0])
if len(val) > 1 {
cmd = exec.Command(val[0], val[1:]...)
}
err := cmd.Run()
utils.CheckError(err)
return c.SendString("Command was run successfully!")
}
} else {
return c.SendString("Auth failed!")
}
}