code cleanup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-11-03 11:02:06 +01:00
parent 410d4dd810
commit 8d45b04e99
9 changed files with 8 additions and 91 deletions

View File

@ -15,6 +15,7 @@ func (cfg *Config) GetConfig() error {
var port int
var version bool
var noscanip bool
var migrate bool
flag.Usage = utils.Usage
@ -24,6 +25,7 @@ func (cfg *Config) GetConfig() error {
flag.BoolVar(&init, "init", false, "If init of database must be done")
flag.BoolVar(&version, "version", false, "Show version")
flag.BoolVar(&noscanip, "noscanip", false, "Do not run scanip")
flag.BoolVar(&migrate, "migrate", false, "Do migrations on version changes")
flag.Parse()
@ -32,6 +34,7 @@ func (cfg *Config) GetConfig() error {
cfg.Switchs.Port = port
cfg.Switchs.Version = version
cfg.Switchs.NoScanIP = noscanip
cfg.Switchs.Migrate = migrate
var inicfg, err = ini.Load(configfile)
if err != nil {
@ -73,5 +76,6 @@ type Config struct {
Init bool
Version bool
NoScanIP bool
Migrate bool
}
}

View File

@ -10,15 +10,14 @@ import (
"github.com/labstack/echo/v4"
)
// const ipv4_regex = `^(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4})/`
const ipv4_cidr_regex = `^(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|)){4}\/([1-3])?([0-9])?$)`
func GetTrustlists(cfg config.Config) (res []string, err error) {
var w []CfgTrustlist
err = cfg.Db.Find(&w)
var ctl []CfgTrustlist
err = cfg.Db.Find(&ctl)
if len(w) > 0 {
for _, a := range w {
if len(ctl) > 0 {
for _, a := range ctl {
res = append(res, a.IP)
}
}

View File

@ -15,21 +15,6 @@ func (event *Event) Insert(cfg *config.Config) (err error) {
return
}
/*
func (event *Event) APIFormat() *APIEvent {
if event == nil {
return nil
}
return &APIEvent{
MSgType: "none",
IPData: {
IP: event.IP.IP,
Src: event.Src,
Hostname: event.Hostname.String,
},
}
}*/
func (event *Event) APIParse(session *xorm.Session, apievent APIEvent) (err error) {
*event = Event{
IP: &IP{IP: apievent.IPData.IP},

View File

@ -81,23 +81,10 @@ func (ip *IP) Get(session *xorm.Session) (apiip *APIIP, err error) {
}
func (ip *IP) InsertOrUpdate(session *xorm.Session) (numinsert int64, numupdate int64, err error) {
//var ips = []IP{}
//err = session.Where("ip = ?", ip.IP).And("src = ?", ip.Src).And("hostname = ?", ip.Hostname).Find(&ips)
has, err := session.Get(ip)
if has {
session.ID(ip.ID).Update(&IP{})
}
/*if len(ips) > 0 {
numupdate, err = session.Where("id = ?", ips[0].ID).Cols("updated").Update(&IP{})
if err != nil {
log.Println(err)
}
} else {
numinsert, err = session.Insert(ip)
if err != nil {
log.Println(err)
}
}*/
session.Commit()
return
}
@ -108,27 +95,6 @@ func InsertIPBulk(session *xorm.Session, ips *[]IP) (numinsert int64, numupdate
}
Cleanup(session)
return
/*var iplist []string
hostname := (*ips)[0].Hostname.String
for _, ip := range *ips {
iplist = append(iplist, ip.IP)
}
var searchips []IP
cfg.Db.In("ip", iplist).Where("hostname = ?", hostname).Find(&searchips)
var toupdateips []string
for _, ip := range searchips {
toupdateips = append(toupdateips, ip.IP)
}
numupdate, _ = cfg.Db.In("ip", toupdateips).Where("hostname = ?", hostname).Cols("updated").Update(&IP{})
var toinsertip, _ = differ(*ips, searchips)
numinsert, err = cfg.Db.Insert(toinsertip)
Cleanup(cfg)
return*/
}
func ScanIP(cfg *config.Config) (err error) {

View File

@ -13,7 +13,6 @@ var (
x *xorm.Engine
tables []interface{}
// HasEngine specifies if we have a xorm.Engine
HasEngine bool
)

View File

@ -2,8 +2,6 @@ package models
import "reflect"
//const keyname string = "id"
func Differ(sl1 []IP, sl2 []IP) (toinsert []IP, err error) {
var m = make(map[string]IPDiffer)
longslice := append(sl1, sl2...)

View File

@ -4,13 +4,9 @@ import (
"time"
"git.paulbsd.com/paulbsd/ipbl/src/config"
"git.paulbsd.com/paulbsd/ipbl/src/models"
"golang.org/x/net/websocket"
)
var webSocketChannel = make(chan models.APIEvent, 100)
var webSocketChannelDone = make(chan bool)
var listeners map[string]*connectionInfo
func Init(cfg *config.Config) {

View File

@ -38,24 +38,6 @@ func HandleWSPS(c echo.Context, cfg *config.Config) (err error) {
for {
time.Sleep(50 * time.Millisecond)
}
/*for {
var apievent, ok = <-WebSocketChannel
if ok {
log.Println(apievent, ok)
data, err := json.Marshal(apievent)
if err != nil {
log.Println(err)
}
err = websocket.Message.Send(ws, data)
if err != nil {
//gcConn(ws, "ps")
log.Println(LISTENERS)
return
}
}
}*/
}).ServeHTTP(c.Response(), c.Request())
return nil
}

View File

@ -98,18 +98,6 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
if err != nil {
log.Println(err)
}
/*
WebSocketChannel <- apievent
err = websocket.Message.Send(ws, "OK")
if err != nil {
//gcConn(ws, "rr")
log.Println(listeners)
return
}
*/
}
}).ServeHTTP(c.Response(), c.Request())
return nil