zones: writeRingInfo [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -3,6 +3,7 @@ package zones
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"darvaza.org/core"
|
"darvaza.org/core"
|
||||||
@@ -147,5 +148,73 @@ func (m *Machine) createRingInfo(ring int, enabled bool) error {
|
|||||||
Keys: keys,
|
Keys: keys,
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.applyRingInfo(ring, ri)
|
err = m.applyRingInfo(ring, ri)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.writeRingInfo(ri)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Machine) writeRingInfo(ri *RingInfo) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if m == nil || ri == nil {
|
||||||
|
return fs.ErrInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
err = m.writeRingInfoPrivate(ri.Ring, ri.Keys.PrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = m.writeRingInfoPublic(ri.Ring, ri.Keys.PublicKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ri.Enabled {
|
||||||
|
return m.deleteRingInfoConf(ri.Ring)
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.writeRingInfoConf(ri.Ring, ri.Keys.PrivateKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Machine) writeRingInfoPrivate(ring int, _ wireguard.PrivateKey) error {
|
||||||
|
f, err := m.CreateTruncFile("wg%v.key", ring)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *Machine) writeRingInfoPublic(ring int, _ wireguard.PublicKey) error {
|
||||||
|
f, err := m.CreateTruncFile("wg%v.pub", ring)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *Machine) writeRingInfoConf(ring int, _ wireguard.PrivateKey) error {
|
||||||
|
f, err := m.CreateTruncFile("wg%v.conf", ring)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Machine) deleteRingInfoConf(ring int) error {
|
||||||
|
err := m.RemoveFile("wg%v.conf", ring)
|
||||||
|
|
||||||
|
switch err {
|
||||||
|
case os.ErrNotExist:
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user