updated ipbl

This commit is contained in:
Paul 2021-12-11 12:59:43 +01:00
parent a81caa6918
commit 7cff022c29
6 changed files with 39 additions and 28 deletions

View File

@ -11,18 +11,18 @@ SRCFILES=cmd/${PROJECTNAME}/*.go
build() { build() {
echo "Begin of build" echo "Begin of build"
if [[ ! -z $DRONE_TAG ]] if [[ ! -z ${DRONE_TAG} ]]
then then
echo "Drone tag set, let's do a release" echo "Drone tag set, let's do a release"
VERSION=$DRONE_TAG VERSION=${DRONE_TAG}
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
elif [[ ! -z $DRONE_TAG ]] elif [[ ! -z ${DRONE_COMMIT} ]]
then then
echo "Drone not set, let's only do a build" echo "Drone not set, let's only do a build"
VERSION=$DRONE_COMMIT VERSION=${DRONE_COMMIT}
fi fi
if [[ ! -z $VERSION && ! -z $GOOS && ! -z $GOARCH ]] if [[ ! -z ${VERSION} && ! -z ${GOOS} && ! -z ${GOARCH} ]]
then then
echo "Let's set a release name" echo "Let's set a release name"
RELEASENAME=${PROJECTNAME}-${VERSION}-${GOOS}-${GOARCH} RELEASENAME=${PROJECTNAME}-${VERSION}-${GOOS}-${GOARCH}
@ -31,7 +31,7 @@ build() {
echo "Building project" echo "Building project"
go build -o ${PROJECTNAME} ${GOOPTIONS} ${SRCFILES} go build -o ${PROJECTNAME} ${GOOPTIONS} ${SRCFILES}
if [[ ! -z $DRONE_TAG ]] if [[ ! -z ${DRONE_TAG} ]]
then then
echo "Let's make archives" echo "Let's make archives"
mkdir -p /build mkdir -p /build
@ -45,7 +45,7 @@ build() {
} }
clean() { clean() {
rm -rf $RELEASEDIR rm -rf ${RELEASEDIR}
} }
case $1 in case $1 in

View File

@ -1,5 +1,6 @@
[ipbl] [ipbl]
db_hostname="hostname" hostname="hostname"
db_name="database" username="username"
db_username="username" password="password"
db_password="password" database="database"
hidebanner="true"

View File

@ -13,8 +13,8 @@ func (cfg *Config) GetConfig() error {
var configfile string var configfile string
var debug bool var debug bool
var drop bool var drop bool
var port int
var init bool var init bool
var port int
flag.Usage = utils.Usage flag.Usage = utils.Usage
@ -26,10 +26,10 @@ func (cfg *Config) GetConfig() error {
flag.Parse() flag.Parse()
cfg.Switchs.Port = port
cfg.Switchs.Debug = debug cfg.Switchs.Debug = debug
cfg.Switchs.Drop = drop cfg.Switchs.Drop = drop
cfg.Switchs.Init = init cfg.Switchs.Init = init
cfg.Switchs.Port = port
inicfg, err := ini.Load(configfile) inicfg, err := ini.Load(configfile)
if err != nil { if err != nil {
@ -38,10 +38,10 @@ func (cfg *Config) GetConfig() error {
ipblsection := inicfg.Section("ipbl") ipblsection := inicfg.Section("ipbl")
cfg.DbParams.DbHostname = ipblsection.Key("db_hostname").MustString("localhost") cfg.DbParams.DbHostname = ipblsection.Key("hostname").MustString("localhost")
cfg.DbParams.DbName = ipblsection.Key("db_name").MustString("database") cfg.DbParams.DbUsername = ipblsection.Key("username").MustString("username")
cfg.DbParams.DbUsername = ipblsection.Key("db_username").MustString("username") cfg.DbParams.DbPassword = ipblsection.Key("password").MustString("password")
cfg.DbParams.DbPassword = ipblsection.Key("db_password").MustString("password") cfg.DbParams.DbDatabase = ipblsection.Key("database").MustString("database")
cfg.Options.HideBanner = ipblsection.Key("hidebanner").MustBool(false) cfg.Options.HideBanner = ipblsection.Key("hidebanner").MustBool(false)
return nil return nil
@ -52,9 +52,9 @@ type Config struct {
Db *xorm.Engine `json:"-"` Db *xorm.Engine `json:"-"`
DbParams struct { DbParams struct {
DbHostname string `json:"dbhostname"` DbHostname string `json:"dbhostname"`
DbName string `json:"dbname"`
DbUsername string `json:"dbusername"` DbUsername string `json:"dbusername"`
DbPassword string `json:"dbpassword"` DbPassword string `json:"dbpassword"`
DbDatabase string `json:"dbdatabase"`
} `json:"dbparams"` } `json:"dbparams"`
Options struct { Options struct {
Version string `json:"version"` Version string `json:"version"`
@ -67,9 +67,4 @@ type Config struct {
Drop bool `json:"drop"` Drop bool `json:"drop"`
Init bool `json:"init"` Init bool `json:"init"`
} `json:"-"` } `json:"-"`
Init struct {
Email string `json:"email"`
Username string `json:"username"`
Password string `json:"password"`
} `json:"-"`
} }

View File

@ -23,7 +23,7 @@ func Init(cfg *config.Config) (err error) {
cfg.DbParams.DbUsername, cfg.DbParams.DbUsername,
cfg.DbParams.DbPassword, cfg.DbParams.DbPassword,
cfg.DbParams.DbHostname, cfg.DbParams.DbHostname,
cfg.DbParams.DbName)) cfg.DbParams.DbDatabase))
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
@ -31,9 +31,8 @@ func Init(cfg *config.Config) (err error) {
cfg.Db.ShowSQL(cfg.Switchs.Debug) cfg.Db.ShowSQL(cfg.Switchs.Debug)
if cfg.Switchs.Drop { if cfg.Switchs.Drop {
for _, table := range tables { log.Println("Dropping tables")
cfg.Db.DropTables(table) cfg.Db.DropTables(tables)
}
os.Exit(0) os.Exit(0)
} }
@ -41,7 +40,6 @@ func Init(cfg *config.Config) (err error) {
for _, table := range tables { for _, table := range tables {
cfg.Db.CreateTables(table) cfg.Db.CreateTables(table)
err = cfg.Db.Sync2(table) err = cfg.Db.Sync2(table)
fmt.Println(err)
} }
return return
} }

View File

@ -49,3 +49,13 @@ type IP struct {
Created time.Time `xorm:"created notnull" json:"-"` Created time.Time `xorm:"created notnull" json:"-"`
Updated time.Time `xorm:"updated notnull" json:"-"` Updated time.Time `xorm:"updated notnull" json:"-"`
} }
// User describe accounts
type IPBLCfg struct {
ID int `xorm:"pk autoincr" json:"-"`
IP string `xorm:"text notnull unique(ipsrc)" json:"ip"`
Rdns string `xorm:"text default" json:"rdns"`
Src string `xorm:"text notnull unique(ipsrc)" json:"src"`
Created time.Time `xorm:"created notnull" json:"-"`
Updated time.Time `xorm:"updated notnull" json:"-"`
}

View File

@ -28,6 +28,9 @@ func RunServer(cfg *config.Config) (err error) {
} }
return c.String(http.StatusNotFound, "IP not found") return c.String(http.StatusNotFound, "IP not found")
}) })
e.POST("/ip", func(c echo.Context) (err error) {
return c.String(http.StatusNotImplemented, "")
})
e.GET("/ips", func(c echo.Context) (err error) { e.GET("/ips", func(c echo.Context) (err error) {
var ips = []ipbl.IP{} var ips = []ipbl.IP{}
var limit int = 50 var limit int = 50
@ -40,6 +43,10 @@ func RunServer(cfg *config.Config) (err error) {
cfg.Db.Limit(limit).Desc("created").Find(&ips) cfg.Db.Limit(limit).Desc("created").Find(&ips)
return c.JSON(http.StatusOK, ips) return c.JSON(http.StatusOK, ips)
}) })
e.POST("/ips", func(c echo.Context) (err error) {
var ips = []ipbl.IP{}
return c.JSON(http.StatusOK, ips)
})
e.Logger.Fatal( e.Logger.Fatal(
e.Start( e.Start(