| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package config
- import (
- "encoding/json"
- "goseg/defaults"
- "goseg/structs"
- "os"
- "path/filepath"
- )
- // write a hardcoded default conf to disk
- func CreateDefaultWGConf() error {
- defaultConfig := defaults.WgConfig
- path := filepath.Join(BasePath, "settings", "wireguard.json")
- if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
- return err
- }
- file, err := os.Create(path)
- if err != nil {
- return err
- }
- defer file.Close()
- encoder := json.NewEncoder(file)
- encoder.SetIndent("", " ")
- if err := encoder.Encode(&defaultConfig); err != nil {
- return err
- }
- return nil
- }
- // write a conf to disk from version server info
- func UpdateWGConf() error {
- conf := Conf()
- releaseChannel := conf.UpdateBranch
- wgRepo := VersionInfo.Wireguard.Repo
- amdHash := VersionInfo.Wireguard.Amd64Sha256
- armHash := VersionInfo.Wireguard.Arm64Sha256
- newConfig := structs.WgConfig{
- WireguardName: "wireguard",
- WireguardVersion: releaseChannel,
- Repo: wgRepo,
- Amd64Sha256: amdHash,
- Arm64Sha256: armHash,
- CapAdd: []string{"NET_ADMIN", "SYS_MODULE"},
- Volumes: []string{"/lib/modules:/lib/modules"},
- Sysctls: struct {
- NetIpv4ConfAllSrcValidMark int `json:"net.ipv4.conf.all.src_valid_mark"`
- }{
- NetIpv4ConfAllSrcValidMark: 1,
- },
- }
- path := filepath.Join(BasePath, "settings", "wireguard.json")
- if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
- return err
- }
- file, err := os.Create(path)
- if err != nil {
- return err
- }
- defer file.Close()
- encoder := json.NewEncoder(file)
- encoder.SetIndent("", " ")
- if err := encoder.Encode(&newConfig); err != nil {
- return err
- }
- return nil
- }
|