diff --git a/cmd/dsnet.go b/cmd/dsnet.go index 0941504..a9b1d16 100644 --- a/cmd/dsnet.go +++ b/cmd/dsnet.go @@ -29,6 +29,7 @@ func main() { dsnet.Sync() case "report": + dsnet.report() case "down": dsnet.Down() diff --git a/report.go b/report.go new file mode 100644 index 0000000..9113724 --- /dev/null +++ b/report.go @@ -0,0 +1,19 @@ +package dsnet + +import ( + "net" + + "github.com/vishvananda/netlink" + "golang.zx2c4.com/wireguard/wgctrl" + "golang.zx2c4.com/wireguard/wgctrl/wgtypes" +) + +func Up() { + conf := MustLoadDsnetConfig() + + dev, err := wgctrl.Device(conf.InterfaceName) + check(err) + + report := Report(dev, conf) + report.MustSave() +} diff --git a/reporttypes.go b/reporttypes.go index f733497..ac963b3 100644 --- a/reporttypes.go +++ b/reporttypes.go @@ -3,6 +3,8 @@ package dsnet import ( "net" "time" + + "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) type Status int @@ -52,6 +54,16 @@ type DsnetReport struct { Peers []PeerReport } +func Report(*wgtypes.Device, conf *DsnetConfig) DsnetReport { + +} + +func (report *DsnetReport) MustSave() { + _json, _ := json.MarshalIndent(report, "", " ") + err := ioutil.WriteFile(CONFIG_FILE, _json, 0644) + check(err) +} + type PeerReport struct { // Used to update DNS Hostname string