working (empty) report generation
This commit is contained in:
parent
e7fe33fe76
commit
5a71debc59
@ -29,7 +29,7 @@ func main() {
|
|||||||
dsnet.Sync()
|
dsnet.Sync()
|
||||||
|
|
||||||
case "report":
|
case "report":
|
||||||
dsnet.report()
|
dsnet.Report()
|
||||||
|
|
||||||
case "down":
|
case "down":
|
||||||
dsnet.Down()
|
dsnet.Down()
|
||||||
|
19
report.go
19
report.go
@ -1,19 +1,22 @@
|
|||||||
package dsnet
|
package dsnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
"golang.zx2c4.com/wireguard/wgctrl"
|
"golang.zx2c4.com/wireguard/wgctrl"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Up() {
|
func Report() {
|
||||||
conf := MustLoadDsnetConfig()
|
conf := MustLoadDsnetConfig()
|
||||||
|
|
||||||
dev, err := wgctrl.Device(conf.InterfaceName)
|
wg, err := wgctrl.New()
|
||||||
check(err)
|
check(err)
|
||||||
|
defer wg.Close()
|
||||||
|
|
||||||
report := Report(dev, conf)
|
dev, err := wg.Device(conf.InterfaceName)
|
||||||
report.MustSave()
|
|
||||||
|
if err != nil {
|
||||||
|
ExitFail("Could not retrieve device '%s' (%v)", conf.InterfaceName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
report := GenerateReport(dev, conf)
|
||||||
|
report.MustSave(conf.ReportFile)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package dsnet
|
package dsnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -54,13 +56,13 @@ type DsnetReport struct {
|
|||||||
Peers []PeerReport
|
Peers []PeerReport
|
||||||
}
|
}
|
||||||
|
|
||||||
func Report(*wgtypes.Device, conf *DsnetConfig) DsnetReport {
|
func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig) DsnetReport {
|
||||||
|
return DsnetReport{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (report *DsnetReport) MustSave() {
|
func (report *DsnetReport) MustSave(filename string) {
|
||||||
_json, _ := json.MarshalIndent(report, "", " ")
|
_json, _ := json.MarshalIndent(report, "", " ")
|
||||||
err := ioutil.WriteFile(CONFIG_FILE, _json, 0644)
|
err := ioutil.WriteFile(filename, _json, 0644)
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user