diff --git a/ci-build.sh b/ci-build.sh index 8e3a37e..a72ccde 100755 --- a/ci-build.sh +++ b/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 diff --git a/ipbl.ini.sample b/ipbl.ini.sample index 0f47973..2b54069 100644 --- a/ipbl.ini.sample +++ b/ipbl.ini.sample @@ -1,5 +1,6 @@ [ipbl] -db_hostname="hostname" -db_name="database" -db_username="username" -db_password="password" \ No newline at end of file +hostname="hostname" +username="username" +password="password" +database="database" +hidebanner="true" \ No newline at end of file diff --git a/src/config/main.go b/src/config/main.go index 0611b15..582d94d 100644 --- a/src/config/main.go +++ b/src/config/main.go @@ -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:"-"` } diff --git a/src/database/main.go b/src/database/main.go index f98e8d7..2576f70 100644 --- a/src/database/main.go +++ b/src/database/main.go @@ -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 } diff --git a/src/ipbl/ip.go b/src/ipbl/ip.go index 41eac16..52b7af4 100644 --- a/src/ipbl/ip.go +++ b/src/ipbl/ip.go @@ -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:"-"` +} diff --git a/src/ipblws/server.go b/src/ipblws/server.go index 010390c..7f338e0 100644 --- a/src/ipblws/server.go +++ b/src/ipblws/server.go @@ -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(