updated ipbl
This commit is contained in:
parent
a81caa6918
commit
7cff022c29
14
ci-build.sh
14
ci-build.sh
@ -11,18 +11,18 @@ SRCFILES=cmd/${PROJECTNAME}/*.go
|
||||
|
||||
build() {
|
||||
echo "Begin of build"
|
||||
if [[ ! -z $DRONE_TAG ]]
|
||||
if [[ ! -z ${DRONE_TAG} ]]
|
||||
then
|
||||
echo "Drone tag set, let's do a release"
|
||||
VERSION=$DRONE_TAG
|
||||
VERSION=${DRONE_TAG}
|
||||
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
|
||||
elif [[ ! -z $DRONE_TAG ]]
|
||||
elif [[ ! -z ${DRONE_COMMIT} ]]
|
||||
then
|
||||
echo "Drone not set, let's only do a build"
|
||||
VERSION=$DRONE_COMMIT
|
||||
VERSION=${DRONE_COMMIT}
|
||||
fi
|
||||
|
||||
if [[ ! -z $VERSION && ! -z $GOOS && ! -z $GOARCH ]]
|
||||
if [[ ! -z ${VERSION} && ! -z ${GOOS} && ! -z ${GOARCH} ]]
|
||||
then
|
||||
echo "Let's set a release name"
|
||||
RELEASENAME=${PROJECTNAME}-${VERSION}-${GOOS}-${GOARCH}
|
||||
@ -31,7 +31,7 @@ build() {
|
||||
echo "Building project"
|
||||
go build -o ${PROJECTNAME} ${GOOPTIONS} ${SRCFILES}
|
||||
|
||||
if [[ ! -z $DRONE_TAG ]]
|
||||
if [[ ! -z ${DRONE_TAG} ]]
|
||||
then
|
||||
echo "Let's make archives"
|
||||
mkdir -p /build
|
||||
@ -45,7 +45,7 @@ build() {
|
||||
}
|
||||
|
||||
clean() {
|
||||
rm -rf $RELEASEDIR
|
||||
rm -rf ${RELEASEDIR}
|
||||
}
|
||||
|
||||
case $1 in
|
||||
|
@ -1,5 +1,6 @@
|
||||
[ipbl]
|
||||
db_hostname="hostname"
|
||||
db_name="database"
|
||||
db_username="username"
|
||||
db_password="password"
|
||||
hostname="hostname"
|
||||
username="username"
|
||||
password="password"
|
||||
database="database"
|
||||
hidebanner="true"
|
@ -13,8 +13,8 @@ func (cfg *Config) GetConfig() error {
|
||||
var configfile string
|
||||
var debug bool
|
||||
var drop bool
|
||||
var port int
|
||||
var init bool
|
||||
var port int
|
||||
|
||||
flag.Usage = utils.Usage
|
||||
|
||||
@ -26,10 +26,10 @@ func (cfg *Config) GetConfig() error {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
cfg.Switchs.Port = port
|
||||
cfg.Switchs.Debug = debug
|
||||
cfg.Switchs.Drop = drop
|
||||
cfg.Switchs.Init = init
|
||||
cfg.Switchs.Port = port
|
||||
|
||||
inicfg, err := ini.Load(configfile)
|
||||
if err != nil {
|
||||
@ -38,10 +38,10 @@ func (cfg *Config) GetConfig() error {
|
||||
|
||||
ipblsection := inicfg.Section("ipbl")
|
||||
|
||||
cfg.DbParams.DbHostname = ipblsection.Key("db_hostname").MustString("localhost")
|
||||
cfg.DbParams.DbName = ipblsection.Key("db_name").MustString("database")
|
||||
cfg.DbParams.DbUsername = ipblsection.Key("db_username").MustString("username")
|
||||
cfg.DbParams.DbPassword = ipblsection.Key("db_password").MustString("password")
|
||||
cfg.DbParams.DbHostname = ipblsection.Key("hostname").MustString("localhost")
|
||||
cfg.DbParams.DbUsername = ipblsection.Key("username").MustString("username")
|
||||
cfg.DbParams.DbPassword = ipblsection.Key("password").MustString("password")
|
||||
cfg.DbParams.DbDatabase = ipblsection.Key("database").MustString("database")
|
||||
cfg.Options.HideBanner = ipblsection.Key("hidebanner").MustBool(false)
|
||||
|
||||
return nil
|
||||
@ -52,9 +52,9 @@ type Config struct {
|
||||
Db *xorm.Engine `json:"-"`
|
||||
DbParams struct {
|
||||
DbHostname string `json:"dbhostname"`
|
||||
DbName string `json:"dbname"`
|
||||
DbUsername string `json:"dbusername"`
|
||||
DbPassword string `json:"dbpassword"`
|
||||
DbDatabase string `json:"dbdatabase"`
|
||||
} `json:"dbparams"`
|
||||
Options struct {
|
||||
Version string `json:"version"`
|
||||
@ -67,9 +67,4 @@ type Config struct {
|
||||
Drop bool `json:"drop"`
|
||||
Init bool `json:"init"`
|
||||
} `json:"-"`
|
||||
Init struct {
|
||||
Email string `json:"email"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
} `json:"-"`
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func Init(cfg *config.Config) (err error) {
|
||||
cfg.DbParams.DbUsername,
|
||||
cfg.DbParams.DbPassword,
|
||||
cfg.DbParams.DbHostname,
|
||||
cfg.DbParams.DbName))
|
||||
cfg.DbParams.DbDatabase))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@ -31,9 +31,8 @@ func Init(cfg *config.Config) (err error) {
|
||||
cfg.Db.ShowSQL(cfg.Switchs.Debug)
|
||||
|
||||
if cfg.Switchs.Drop {
|
||||
for _, table := range tables {
|
||||
cfg.Db.DropTables(table)
|
||||
}
|
||||
log.Println("Dropping tables")
|
||||
cfg.Db.DropTables(tables)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
@ -41,7 +40,6 @@ func Init(cfg *config.Config) (err error) {
|
||||
for _, table := range tables {
|
||||
cfg.Db.CreateTables(table)
|
||||
err = cfg.Db.Sync2(table)
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -49,3 +49,13 @@ type IP struct {
|
||||
Created time.Time `xorm:"created 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:"-"`
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ func RunServer(cfg *config.Config) (err error) {
|
||||
}
|
||||
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) {
|
||||
var ips = []ipbl.IP{}
|
||||
var limit int = 50
|
||||
@ -40,6 +43,10 @@ func RunServer(cfg *config.Config) (err error) {
|
||||
cfg.Db.Limit(limit).Desc("created").Find(&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.Start(
|
||||
|
Loading…
Reference in New Issue
Block a user