Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Add timestamp to config (#44)
Browse files Browse the repository at this point in the history
* Add 'Created' ad an timestamp when the config is created.

* Add field 'Modified' on ClientConfig

This field updates when the user changes name or label on their config.
  • Loading branch information
spetzreborn authored Mar 16, 2020
1 parent 9bcd558 commit f412ebb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"os"
"path/filepath"
"time"

log "github.com/sirupsen/logrus"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
Expand All @@ -32,6 +33,8 @@ type ClientConfig struct {
PublicKey string
IP net.IP
Notes string
Created string
Modified string
}

// NewServerConfig creates and returns a reference to a new ServerConfig
Expand Down Expand Up @@ -102,6 +105,8 @@ func NewClientConfig(ip net.IP) *ClientConfig {
PublicKey: key.PublicKey().String(),
IP: ip,
Notes: "",
Created: time.Now().Format(time.RFC3339),
Modified: time.Now().Format(time.RFC3339),
}

return &cfg
Expand Down
3 changes: 3 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strconv"
"strings"
"sync"
"time"

assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/google/nftables"
Expand Down Expand Up @@ -545,6 +546,8 @@ func (s *Server) EditClient(w http.ResponseWriter, r *http.Request, ps httproute
client.Notes = cfg.Notes
}

client.Modified = time.Now().Format(time.RFC3339)

s.reconfigure()

w.WriteHeader(http.StatusOK)
Expand Down

0 comments on commit f412ebb

Please sign in to comment.