|
|
|
@ -3,6 +3,7 @@ package zones
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"fmt" |
|
|
|
|
"io/fs" |
|
|
|
|
"os" |
|
|
|
|
|
|
|
|
|
"darvaza.org/core" |
|
|
|
@ -72,6 +73,38 @@ func (m *Machine) tryReadWireguardKeys(ring int) error {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WriteWireguardKeys writes the wgN.key/wgN.pub files
|
|
|
|
|
func (m *Machine) WriteWireguardKeys(ring int) error { |
|
|
|
|
var err error |
|
|
|
|
var key, pub string |
|
|
|
|
var ri *RingInfo |
|
|
|
|
|
|
|
|
|
ri, _ = m.getRingInfo(ring) |
|
|
|
|
if ri != nil { |
|
|
|
|
key = ri.Keys.PrivateKey.String() |
|
|
|
|
pub = ri.Keys.PublicKey.String() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch { |
|
|
|
|
case key == "": |
|
|
|
|
return fs.ErrNotExist |
|
|
|
|
case pub == "": |
|
|
|
|
pub = ri.Keys.PrivateKey.Public().String() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = m.WriteStringFile(key, "wg%v.key", ring) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = m.WriteStringFile(pub, "wg%v.pub", ring) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetWireguardConfig reads a wgN.conf file
|
|
|
|
|
func (m *Machine) GetWireguardConfig(ring int) (*wireguard.Config, error) { |
|
|
|
|
data, err := m.ReadFile("wg%v.conf", ring) |
|
|
|
|