Daemon that listens for AMQP messages to add IP addresses and ports to FirewallD. IP addresses expire and are removed automatically after a configurable timeout.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
955 B

package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
"strings"
"github.com/google/uuid"
)
func readJsonFile(filePath string) (jsonBytes []byte, err error) {
jsonFile, err := os.Open(filePath)
if err != nil {
log.Println("Could not open JSON file: " + filePath + "\n" + err.Error())
return jsonBytes, err
}
defer jsonFile.Close()
fileBytes, _ := ioutil.ReadAll(jsonFile)
//strip out // comments from file:
re := regexp.MustCompile(`([\s]//.*)|(^//.*)`)
fileCleanedBytes := re.ReplaceAll(fileBytes, nil)
return fileCleanedBytes, err
}
func generateUUID() string {
return strings.Replace(uuid.New().String(), "-", "", -1)
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func logit(level int, message string) {
if appconf.LogLevel >= int(level) {
log.Println(message)
}
if appconf.LogLevel >= 8 {
fmt.Println(message)
}
}