Merge branch 'master' of https://git.paulbsd.com/paulbsd/ipbl
This commit is contained in:
commit
1df597e1d6
142
.drone.yml
142
.drone.yml
@ -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
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- ./ci-build.sh build
|
||||
environment:
|
||||
environment:
|
||||
GOOS: linux
|
||||
GOARCH: amd64
|
||||
volumes:
|
||||
- name: build
|
||||
path: /build
|
||||
|
||||
volumes:
|
||||
- name: build
|
||||
host:
|
||||
path: /tmp/ipbl/build
|
||||
|
||||
depends_on:
|
||||
- cleanup-before
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default-linux-arm64
|
||||
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
|
||||
- go generate $SRCFILES
|
||||
- go build -o $PROJECTNAME $GOOPTIONS $SRCFILES
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- tag
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: gitea-release
|
||||
name: gitea-release-linux-amd64
|
||||
|
||||
environment:
|
||||
GOOS: linux
|
||||
GOARCH: amd64
|
||||
GOOPTIONS: -mod=vendor
|
||||
SRCFILES: cmd/ipbl/*.go
|
||||
PROJECTNAME: ipbl
|
||||
|
||||
steps:
|
||||
- name: move
|
||||
image: alpine
|
||||
commands:
|
||||
- mv build/* ./
|
||||
volumes:
|
||||
- name: build
|
||||
path: /drone/src/build
|
||||
image: golang
|
||||
commands:
|
||||
- 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
|
||||
|
18
Makefile
18
Makefile
@ -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}
|
63
ci-build.sh
63
ci-build.sh
@ -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
|
@ -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:"-"`
|
||||
|
@ -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)
|
||||
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 {
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user