Save updated ip to host entry

This commit is contained in:
Benjamin Bärthlein 2024-05-20 14:09:48 +02:00
parent f7f84557f6
commit 71411eedf5
2 changed files with 9 additions and 3 deletions

View File

@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Prepare - name: Prepare
id: prep id: prep
run: | run: |

View File

@ -237,7 +237,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
log.SentIP = c.QueryParam(("myip")) log.SentIP = c.QueryParam(("myip"))
// Get caller IP // Get caller IP
log.CallerIP, err = nswrapper.GetCallerIP(c.Request()) log.CallerIP, _ = nswrapper.GetCallerIP(c.Request())
if log.CallerIP == "" { if log.CallerIP == "" {
log.CallerIP, _, err = net.SplitHostPort(c.Request().RemoteAddr) log.CallerIP, _, err = net.SplitHostPort(c.Request().RemoteAddr)
if err != nil { if err != nil {
@ -276,7 +276,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
} }
} }
// add/update DNS record // Add/update DNS record
if err = nswrapper.UpdateRecord(log.Host.Hostname, log.SentIP, ipType, log.Host.Domain, log.Host.Ttl, h.AllowWildcard); err != nil { if err = nswrapper.UpdateRecord(log.Host.Hostname, log.SentIP, ipType, log.Host.Domain, log.Host.Ttl, h.AllowWildcard); err != nil {
log.Message = fmt.Sprintf("DNS error: %v", err) log.Message = fmt.Sprintf("DNS error: %v", err)
l.Error(log.Message) l.Error(log.Message)
@ -286,8 +286,14 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) {
return c.String(http.StatusBadRequest, "dnserr\n") return c.String(http.StatusBadRequest, "dnserr\n")
} }
// Update DB host entry
log.Host.Ip = log.SentIP log.Host.Ip = log.SentIP
log.Host.LastUpdate = log.TimeStamp log.Host.LastUpdate = log.TimeStamp
if err = h.DB.Save(log.Host).Error; err != nil {
return c.JSON(http.StatusBadRequest, "badrequest\n")
}
log.Status = true log.Status = true
log.Message = "No errors occurred" log.Message = "No errors occurred"
if err = h.CreateLogEntry(log); err != nil { if err = h.CreateLogEntry(log); err != nil {