mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 23:29:08 +00:00
initial nftables config generation test
This commit is contained in:
parent
ba99844ae4
commit
b279746017
17 changed files with 215 additions and 0 deletions
27
api/config.go
Normal file
27
api/config.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.con/speatzle/nfsense/pkg/definitions"
|
||||
)
|
||||
|
||||
func LoadConfiguration(file string) (*definitions.Config, error) {
|
||||
var config definitions.Config
|
||||
configFile, err := os.Open(file)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("opening Config File %w", err)
|
||||
}
|
||||
defer configFile.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
jsonParser := json.NewDecoder(configFile)
|
||||
err = jsonParser.Decode(&config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decoding Config File %w", err)
|
||||
}
|
||||
return &config, nil
|
||||
}
|
29
api/main.go
Normal file
29
api/main.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.con/speatzle/nfsense/pkg/nftables"
|
||||
"golang.org/x/exp/slog"
|
||||
)
|
||||
|
||||
func main() {
|
||||
slog.Info("Starting...")
|
||||
conf, err := LoadConfiguration("config.json")
|
||||
if err != nil {
|
||||
slog.Error("Loading Config", err)
|
||||
return
|
||||
}
|
||||
slog.Info("Config Loaded", "config", conf)
|
||||
|
||||
fileContent, err := nftables.GenerateNfTablesFile(*conf)
|
||||
if err != nil {
|
||||
slog.Error("Generating nftables file", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = nftables.ApplyNfTablesFile(fileContent)
|
||||
if err != nil {
|
||||
slog.Error("Applying nftables", err)
|
||||
return
|
||||
}
|
||||
slog.Info("Wrote nftables File!")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue