mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-24 09:05:49 +00:00
Replace ad-hoc ticker loops with named cron-based scheduled tasks for cleanup, minute reporting, and expiration checks. Add scheduler shutdown handling and log errors when schedules fail to reload or register. Update imports to use the relocated pkg/config package across affected code.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package test
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/komari-monitor/komari/database/models"
|
|
"github.com/komari-monitor/komari/pkg/config"
|
|
"github.com/komari-monitor/komari/utils/geoip"
|
|
"github.com/komari-monitor/komari/utils/messageSender"
|
|
"github.com/komari-monitor/komari/web/api"
|
|
)
|
|
|
|
func TestSendMessage(c *gin.Context) {
|
|
err := messageSender.SendEvent(models.EventMessage{
|
|
Event: "Test",
|
|
Message: "This is a test message from Komari.",
|
|
})
|
|
if err != nil {
|
|
api.RespondError(c, 500, "Failed to send message: "+err.Error())
|
|
return
|
|
}
|
|
api.RespondSuccess(c, nil)
|
|
}
|
|
|
|
func TestGeoIp(c *gin.Context) {
|
|
ip := c.Query("ip")
|
|
if ip == "" {
|
|
if cfIP := c.GetHeader("CF-Connecting-IP"); cfIP != "" {
|
|
ip = cfIP
|
|
} else {
|
|
ip = c.ClientIP()
|
|
}
|
|
}
|
|
cfg, err := config.GetAs[bool](config.GeoIpEnabledKey, false)
|
|
if err != nil {
|
|
api.RespondError(c, 500, "Failed to get configuration: "+err.Error())
|
|
return
|
|
}
|
|
if !cfg {
|
|
api.RespondError(c, 400, "GeoIP is not enabled in the configuration.")
|
|
return
|
|
}
|
|
GeoIpRecord, err := geoip.GetGeoInfo(net.ParseIP(ip))
|
|
if err != nil {
|
|
api.RespondError(c, 500, "Failed to get GeoIP record: "+err.Error())
|
|
return
|
|
}
|
|
api.RespondSuccess(c, GeoIpRecord)
|
|
}
|