Skip to content

Commit

Permalink
Merge branch 'master' into for_github
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Caillet committed Feb 8, 2021
2 parents bbdb372 + 990ffb6 commit 9373a41
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 365 deletions.
11 changes: 11 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variables:
BINARY_NAME: $CI_PROJECT_NAME

stages:
- build

build:
stage: build
image: golang:alpine
script:
- go build
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ build:
@notify-send 'Build Complete' 'Your project has been build successfully!' -u normal -t 7500 -i checkbox-checked-symbolic

release:
scp ${NAME}-${TAG} ${REMOTE_DESTINATION}
scp ${NAME}-${TAG} ${REMOTE_DESTINATION}
90 changes: 45 additions & 45 deletions cfgread.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
package main

import (
"bufio"
"fmt"
"os"
"strings"
)

var cfg map[string]string
var inblacklist map[string]bool
var inwhitelist map[string]bool

// InitCfg read cfgfile variable
func InitCfg(s string) {
cfg = make(map[string]string)
inblacklist = make(map[string]bool)
inwhitelist = make(map[string]bool)

f, err := os.Open(s)
if err != nil {
panic(fmt.Sprintf("Unable to read configuration file %s", s))
}
defer f.Close()
rd := bufio.NewReader(f)
for {
cfgline, err := rd.ReadString('\n')
if err != nil {
break
}
cfgline = strings.Trim(cfgline, " \n\r")
cfgval := strings.SplitN(cfgline, "=", 2)
if len(cfgval) < 2 {
continue
}
switch {
case cfgval[0] == "blacklist":
inblacklist[cfgval[1]] = true
case cfgval[0] == "whitelist":
inwhitelist[cfgval[1]] = true
default:
cfg[cfgval[0]] = cfgval[1]
}
}
}
package main

import (
"bufio"
"fmt"
"os"
"strings"
)

var cfg map[string]string
var inblacklist map[string]bool
var inwhitelist map[string]bool

// InitCfg read cfgfile variable
func InitCfg(s string) {
cfg = make(map[string]string)
inblacklist = make(map[string]bool)
inwhitelist = make(map[string]bool)

f, err := os.Open(s)
if err != nil {
panic(fmt.Sprintf("Unable to read configuration file %s", s))
}
defer f.Close()
rd := bufio.NewReader(f)
for {
cfgline, err := rd.ReadString('\n')
if err != nil {
break
}
cfgline = strings.Trim(cfgline, " \n\r")
cfgval := strings.SplitN(cfgline, "=", 2)
if len(cfgval) < 2 {
continue
}
switch {
case cfgval[0] == "blacklist":
inblacklist[cfgval[1]] = true
case cfgval[0] == "whitelist":
inwhitelist[cfgval[1]] = true
default:
cfg[cfgval[0]] = cfgval[1]
}
}
}
3 changes: 2 additions & 1 deletion contrib/policyd-top20.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ then
echo "must be root !"
exit -1
fi

## Attention au "\r" en fin de ligne si le fichier est edité sous windows...
##
## sed $'s/\r//' -i /etc/postfix/policyd.cfg (pour corriger)
## sed 's/\r//' -i /etc/postfix/policyd.cfg (pour corriger)

. /etc/postfix/policyd.cfg

Expand Down
62 changes: 31 additions & 31 deletions daemon.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// +build linux

package main

import (
"fmt"
"io/ioutil"
"log"
"log/syslog"
"os"
"time"
)

var xlog *syslog.Writer

func initSyslog(exe string) {
var e error
xlog, e = syslog.New(syslog.LOG_DAEMON|syslog.LOG_INFO, exe)
if e == nil {
log.SetOutput(xlog)
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime)) // remove timestamp
}
}

func writePidfile(pidfile string) {
err := ioutil.WriteFile(pidfile, []byte(fmt.Sprintf("%d", os.Getpid())), 0664)
if err != nil {
log.Output(1, "Unable to create pidfile "+pidfile)
time.Sleep(20 * time.Second)
}
}
// +build linux

package main

import (
"fmt"
"io/ioutil"
"log"
"log/syslog"
"os"
"time"
)

var xlog *syslog.Writer

func initSyslog(exe string) {
var e error
xlog, e = syslog.New(syslog.LOG_DAEMON|syslog.LOG_INFO, exe)
if e == nil {
log.SetOutput(xlog)
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime)) // remove timestamp
}
}

func writePidfile(pidfile string) {
err := ioutil.WriteFile(pidfile, []byte(fmt.Sprintf("%d", os.Getpid())), 0664)
if err != nil {
log.Output(1, "Unable to create pidfile "+pidfile)
time.Sleep(20 * time.Second)
}
}
28 changes: 14 additions & 14 deletions fakes_windows.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//+build windows

// Windows fake functions when editing on windows
// -- this is intended to work on Unix first.
package main

type myXlog int

var xlog myXlog

func (myXlog) Err(string) {}
func (myXlog) Info(string) {}
func initSyslog(s string) {}
func writePidfile(s string) {}
//+BUILD WINDOWS

// Windows fake functions when editing on windows
// -- this is intended to work on Unix first.
package main

type myXlog int

var xlog myXlog

func (myXlog) Err(string) {}
func (myXlog) Info(string) {}
func initSyslog(s string) {}
func writePidfile(s string) {}
Loading

0 comments on commit 9373a41

Please sign in to comment.