Merge branch 'master' of https://git.paulbsd.com/paulbsd/ipbl
Some checks reported errors
continuous-integration/drone/push Build encountered an error
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul 2022-02-27 01:17:35 +01:00
commit 1df597e1d6
6 changed files with 83 additions and 202 deletions

View File

@ -1,89 +1,49 @@
---
kind: pipeline
type: docker
name: cleanup-before
name: build-linux-amd64
steps:
- name: clean
image: alpine
commands:
- rm -rf /build/*
volumes:
- name: build
path: /build
when:
event: tag
volumes:
- name: build
host:
path: /tmp/ipbl/build
---
kind: pipeline
type: docker
name: default-linux-amd64
environment:
GOOS: linux
GOARCH: amd64
GOOPTIONS: -mod=vendor
SRCFILES: cmd/ipbl/*.go
PROJECTNAME: ipbl
steps:
- name: build
image: golang
commands:
- ./ci-build.sh build
environment:
GOOS: linux
GOARCH: amd64
volumes:
- name: build
path: /build
volumes:
- name: build
host:
path: /tmp/ipbl/build
depends_on:
- cleanup-before
- go generate $SRCFILES
- go build -o $PROJECTNAME $GOOPTIONS $SRCFILES
when:
event:
exclude:
- tag
---
kind: pipeline
type: docker
name: default-linux-arm64
name: gitea-release-linux-amd64
environment:
GOOS: linux
GOARCH: amd64
GOOPTIONS: -mod=vendor
SRCFILES: cmd/ipbl/*.go
PROJECTNAME: ipbl
steps:
- name: build
image: golang
commands:
- ./ci-build.sh build
environment:
GOOS: linux
GOARCH: arm64
volumes:
- name: build
path: /build
volumes:
- name: build
host:
path: /tmp/ipbl/build
depends_on:
- cleanup-before
---
kind: pipeline
type: docker
name: gitea-release
steps:
- name: move
image: alpine
commands:
- mv build/* ./
volumes:
- name: build
path: /drone/src/build
- go generate $SRCFILES
- go build -o $PROJECTNAME $GOOPTIONS $SRCFILES
- tar -czvf $PROJECTNAME-$DRONE_TAG-$GOOS-$GOARCH.tar.gz $PROJECTNAME
- echo $PROJECTNAME $DRONE_TAG > VERSION
when:
event: tag
event:
- tag
- name: release
image: plugins/gitea-release
settings:
@ -95,50 +55,6 @@ steps:
- sha256
- sha512
title: VERSION
volumes:
- name: build
path: /drone/src/build
when:
event: tag
- name: ls
image: alpine
commands:
- find .
volumes:
- name: build
path: /drone/src/build
when:
event: tag
volumes:
- name: build
host:
path: /tmp/ipbl/build
depends_on:
- default-linux-amd64
- default-linux-arm64
---
kind: pipeline
type: docker
name: cleanup-after
steps:
- name: clean
image: alpine
commands:
- rm -rf /build/*
volumes:
- name: build
path: /build
when:
event: tag
volumes:
- name: build
host:
path: /tmp/ipbl/build
depends_on:
- gitea-release
event:
- tag

View File

@ -1,18 +0,0 @@
# ipbl Makefile
GOCMD=go
GOBUILDCMD=${GOCMD} build
GOOPTIONS=-mod=vendor -ldflags="-s -w"
RMCMD=rm
BINNAME=ipbl
SRCFILES=cmd/ipbl/*.go
all: build
build:
${GOBUILDCMD} ${GOOPTIONS} ${SRCFILES}
clean:
${RMCMD} -f ${BINNAME}

View File

@ -1,63 +0,0 @@
#!/bin/bash
set -e
PROJECTNAME=ipbl
RELEASENAME=${PROJECTNAME}
VERSION="0"
GOOPTIONS="-mod=vendor"
SRCFILES=cmd/${PROJECTNAME}/*.go
build() {
echo "Begin of build"
if [[ ! -z ${DRONE_TAG} ]]
then
echo "Drone tag set, let's do a release"
export VERSION=${DRONE_TAG}
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
elif [[ ! -z ${DRONE_COMMIT} ]]
then
echo "Drone not set, let's only do a build"
export VERSION=${DRONE_COMMIT}
fi
if [[ ! -z ${VERSION} && ! -z ${GOOS} && ! -z ${GOARCH} ]]
then
echo "Let's set a release name"
RELEASENAME=${PROJECTNAME}-${VERSION}-${GOOS}-${GOARCH}
fi
echo "Building project"
go generate ${SRCFILES}
go build -o ${PROJECTNAME} ${GOOPTIONS} ${SRCFILES}
if [[ ! -z ${DRONE_TAG} ]]
then
echo "Let's make archives"
mkdir -p /build
tar -czvf /build/${RELEASENAME}.tar.gz ${PROJECTNAME}
fi
echo "Removing binary file"
rm ${PROJECTNAME}
echo "End of build"
}
clean() {
rm -rf ${RELEASEDIR}
}
case $1 in
"build")
build
;;
"clean")
clean
;;
*)
echo "No options choosen"
exit 1
;;
esac

View File

@ -1,6 +1,7 @@
package models
import (
"encoding/json"
"fmt"
"regexp"
"strings"
@ -59,10 +60,47 @@ func (wl Trustlist) Verify() bool {
return reg.MatchString(wl.IP)
}
// GetFolders ...
func GetFolders(cfg config.Config) (res []Folder, err error) {
var w = Cfg{Key: "folders"}
if exists, _ := cfg.Db.Get(&w); exists {
err = json.Unmarshal([]byte(w.Value), &res)
}
return
}
// InsertOrUpdateFolders ...
func InsertOrUpdateFolders(cfg config.Config, folders []Folder) (res string, err error) {
var w = Cfg{Key: "folders"}
if exists, _ := cfg.Db.Get(&w); exists {
resbytes, err := json.Marshal(folders)
if err != nil {
return "", err
}
w.Value = string(resbytes)
_, err = cfg.Db.ID(w.ID).Update(&w)
if err != nil {
return "", err
}
}
return
}
type Trustlist struct {
IP string `json:"ip"`
}
type Folder struct {
Path string `json:"path"`
Sets []Set `json:"sets"`
}
type Set struct {
Type string `json:"type"`
Filename string `json:"filename"`
Regex string `json:"regex"`
}
// Cfg is ipbl config
type Cfg struct {
ID int `xorm:"pk autoincr" json:"-"`

View File

@ -80,7 +80,7 @@ func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numupdates i
for _, ip := range searchips {
toupdateips = append(toupdateips, ip.IP)
}
cfg.Db.In("ip", toupdateips).Cols("updated").Update(&IP{})
numupdates, _ = cfg.Db.In("ip", toupdateips).Cols("updated").Update(&IP{})
var toinsertip, _ = differ(*ips, searchips)
numinserts, err = cfg.Db.Insert(toinsertip)
@ -95,13 +95,8 @@ func ScanIP(cfg *config.Config) (err error) {
if cfg.Db.Where("rdns IS NULL").Asc("ip").Find(&orphans); len(orphans) > 0 {
for _, i := range orphans {
reverse, _ := i.UpdateRDNS()
if reverse == "" {
log.Printf("Set \"none\" rdns to IP %s\n", i.IP)
i.Rdns.String = "none"
} else {
log.Printf("%s %s\n", i.IP, reverse)
i.Rdns.String = reverse
}
log.Printf("%s -> \"%s\"\n", i.IP, reverse)
i.Rdns.String = reverse
i.Rdns.Valid = true
_, err = cfg.Db.ID(i.ID).Cols("rdns").Update(&i)
if err != nil {

View File

@ -101,6 +101,19 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
}
return
})
e.GET("/ips/folders", func(c echo.Context) (err error) {
folders, err := models.GetFolders(*cfg)
return Result(c, err, folders)
})
e.POST("/ips/folders", func(c echo.Context) (err error) {
var folders []models.Folder
err = c.Bind(&folders)
if err != nil {
return Result(c, err, "Unable to parse JSON")
}
_, err = models.InsertOrUpdateFolders(*cfg, folders)
return Result(c, err, folders)
})
e.Logger.Fatal(
e.Start(