2021-12-17 07:52:32 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2021-12-17 08:22:04 +00:00
|
|
|
"strings"
|
2021-12-17 07:52:32 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"kumoly.io/kumoly/app/auth"
|
2021-12-17 08:22:04 +00:00
|
|
|
"kumoly.io/kumoly/app/email"
|
|
|
|
"kumoly.io/kumoly/app/errors"
|
2021-12-17 07:52:32 +00:00
|
|
|
"kumoly.io/kumoly/app/server"
|
|
|
|
"kumoly.io/kumoly/app/system"
|
|
|
|
"kumoly.io/kumoly/app/task"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Service struct{}
|
|
|
|
|
|
|
|
func (srv Service) GetName() string { return "ctrl.Service" }
|
|
|
|
func (srv Service) GetDependencies() []string { return []string{"server.Service", "auth.Auth"} }
|
|
|
|
func (srv Service) IsService() bool { return true }
|
|
|
|
func (srv Service) Init() error { return nil }
|
|
|
|
func (srv Service) Main() error { return nil }
|
|
|
|
func (srv Service) Del() {}
|
|
|
|
func (srv Service) Health() error { return nil }
|
|
|
|
|
|
|
|
func (srv Service) Load() error {
|
|
|
|
ctlAPI := server.API.Group("ctrl")
|
|
|
|
ctlAPI.GET("prof", auth.ACAdmin(), func(c *gin.Context) {
|
|
|
|
server.OK(c, system.GetProfile())
|
|
|
|
})
|
|
|
|
ctlAPI.GET("config", auth.ACAdmin(), func(c *gin.Context) {
|
|
|
|
conf, err := system.ConfigShow("json")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
data := map[string]interface{}{}
|
2021-12-17 08:22:04 +00:00
|
|
|
if err := json.Unmarshal([]byte(conf), &data); err != nil {
|
2021-12-17 07:52:32 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
server.OK(c, data)
|
|
|
|
})
|
|
|
|
|
2021-12-17 08:26:09 +00:00
|
|
|
ctlAPI.POST("test_email", auth.ACAdmin(), func(c *gin.Context) {
|
2021-12-17 08:22:04 +00:00
|
|
|
tos := c.Query("to")
|
|
|
|
if tos == "" {
|
|
|
|
panic(errors.ErrorBadRequest)
|
|
|
|
}
|
|
|
|
to := strings.Split(tos, ",")
|
|
|
|
if err := email.Send("test@kumoly.io", to, "Test Email", &email.Body{
|
|
|
|
Greeting: "Dear",
|
|
|
|
Receiver: "Administrator",
|
|
|
|
Intros: []string{
|
|
|
|
"This is a test email.",
|
|
|
|
},
|
|
|
|
}); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
server.OK(c, "email sent.")
|
|
|
|
})
|
|
|
|
|
|
|
|
// this should be in task service
|
2021-12-17 07:52:32 +00:00
|
|
|
ctlAPI.GET("tasks", auth.ACAdmin(), func(c *gin.Context) {
|
|
|
|
server.OK(c, task.GetProfile())
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|