chore: add new formatter to .golangci.yml
All checks were successful
build / build (push) Successful in 2m23s
All checks were successful
build / build (push) Successful in 2m23s
This commit is contained in:
@@ -12,10 +12,12 @@ linters:
|
|||||||
- govet
|
- govet
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- gosec
|
- gosec
|
||||||
|
- nilerr
|
||||||
|
|
||||||
formatters:
|
formatters:
|
||||||
enable:
|
enable:
|
||||||
- gofmt
|
- gofmt
|
||||||
- goimports
|
- goimports
|
||||||
|
- golines
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,15 @@ var DaemonCmd = &cobra.Command{
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
for _, svc := range cfg.Service {
|
for _, svc := range cfg.Service {
|
||||||
log.Info("Processing service", "name", svc.Name, "enabled", svc.Enabled, "path", svc.LogPath)
|
log.Info(
|
||||||
|
"Processing service",
|
||||||
|
"name",
|
||||||
|
svc.Name,
|
||||||
|
"enabled",
|
||||||
|
svc.Enabled,
|
||||||
|
"path",
|
||||||
|
svc.LogPath,
|
||||||
|
)
|
||||||
|
|
||||||
if !svc.Enabled {
|
if !svc.Enabled {
|
||||||
log.Info("Service disabled, skipping", "name", svc.Name)
|
log.Info("Service disabled, skipping", "name", svc.Name)
|
||||||
|
|||||||
@@ -60,7 +60,14 @@ var ListCmd = &cobra.Command{
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
for _, rule := range r {
|
for _, rule := range r {
|
||||||
fmt.Printf("Name: %s\nService: %s\nPath: %s\nStatus: %s\nMethod: %s\n\n", rule.Name, rule.ServiceName, rule.Path, rule.Status, rule.Method)
|
fmt.Printf(
|
||||||
|
"Name: %s\nService: %s\nPath: %s\nStatus: %s\nMethod: %s\n\n",
|
||||||
|
rule.Name,
|
||||||
|
rule.ServiceName,
|
||||||
|
rule.Path,
|
||||||
|
rule.Status,
|
||||||
|
rule.Method,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,14 @@ func LoadRuleConfig() ([]Rule, error) {
|
|||||||
return cfg.Rules, nil
|
return cfg.Rules, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRule(Name string, ServiceName string, Path string, Status string, Method string, ttl string) error {
|
func NewRule(
|
||||||
|
Name string,
|
||||||
|
ServiceName string,
|
||||||
|
Path string,
|
||||||
|
Status string,
|
||||||
|
Method string,
|
||||||
|
ttl string,
|
||||||
|
) error {
|
||||||
r, err := LoadRuleConfig()
|
r, err := LoadRuleConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r = []Rule{}
|
r = []Rule{}
|
||||||
@@ -34,7 +41,17 @@ func NewRule(Name string, ServiceName string, Path string, Status string, Method
|
|||||||
fmt.Printf("Rule name can't be empty\n")
|
fmt.Printf("Rule name can't be empty\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
r = append(r, Rule{Name: Name, ServiceName: ServiceName, Path: Path, Status: Status, Method: Method, BanTime: ttl})
|
r = append(
|
||||||
|
r,
|
||||||
|
Rule{
|
||||||
|
Name: Name,
|
||||||
|
ServiceName: ServiceName,
|
||||||
|
Path: Path,
|
||||||
|
Status: Status,
|
||||||
|
Method: Method,
|
||||||
|
BanTime: ttl,
|
||||||
|
},
|
||||||
|
)
|
||||||
file, err := os.Create("/etc/banforge/rules.toml")
|
file, err := os.Create("/etc/banforge/rules.toml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -51,7 +51,16 @@ func (j *Judge) ProcessUnviewed() error {
|
|||||||
}()
|
}()
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var entry storage.LogEntry
|
var entry storage.LogEntry
|
||||||
err = rows.Scan(&entry.ID, &entry.Service, &entry.IP, &entry.Path, &entry.Status, &entry.Method, &entry.IsViewed, &entry.CreatedAt)
|
err = rows.Scan(
|
||||||
|
&entry.ID,
|
||||||
|
&entry.Service,
|
||||||
|
&entry.IP,
|
||||||
|
&entry.Path,
|
||||||
|
&entry.Status,
|
||||||
|
&entry.Method,
|
||||||
|
&entry.IsViewed,
|
||||||
|
&entry.CreatedAt,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
j.logger.Error(fmt.Sprintf("Failed to scan database row: %v", err))
|
j.logger.Error(fmt.Sprintf("Failed to scan database row: %v", err))
|
||||||
continue
|
continue
|
||||||
@@ -64,7 +73,13 @@ func (j *Judge) ProcessUnviewed() error {
|
|||||||
(rule.Status == "" || entry.Status == rule.Status) &&
|
(rule.Status == "" || entry.Status == rule.Status) &&
|
||||||
(rule.Path == "" || entry.Path == rule.Path) {
|
(rule.Path == "" || entry.Path == rule.Path) {
|
||||||
|
|
||||||
j.logger.Info(fmt.Sprintf("Rule matched for IP: %s, Service: %s", entry.IP, entry.Service))
|
j.logger.Info(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"Rule matched for IP: %s, Service: %s",
|
||||||
|
entry.IP,
|
||||||
|
entry.Service,
|
||||||
|
),
|
||||||
|
)
|
||||||
ban_status, err := j.db.IsBanned(entry.IP)
|
ban_status, err := j.db.IsBanned(entry.IP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
j.logger.Error(fmt.Sprintf("Failed to check ban status: %v", err))
|
j.logger.Error(fmt.Sprintf("Failed to check ban status: %v", err))
|
||||||
|
|||||||
@@ -42,7 +42,17 @@ func (p *NginxParser) Parse(eventCh <-chan Event, resultCh chan<- *storage.LogEn
|
|||||||
Method: method,
|
Method: method,
|
||||||
IsViewed: false,
|
IsViewed: false,
|
||||||
}
|
}
|
||||||
p.logger.Info("Parsed nginx log entry", "ip", matches[1], "path", path, "status", status, "method", method)
|
p.logger.Info(
|
||||||
|
"Parsed nginx log entry",
|
||||||
|
"ip",
|
||||||
|
matches[1],
|
||||||
|
"path",
|
||||||
|
path,
|
||||||
|
"status",
|
||||||
|
status,
|
||||||
|
"method",
|
||||||
|
method,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ type Scanner struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewScanner(path string) (*Scanner, error) {
|
func NewScanner(path string) (*Scanner, error) {
|
||||||
file, err := os.Open(path) // #nosec G304 -- admin tool, runs as root, path controlled by operator
|
file, err := os.Open(
|
||||||
|
path,
|
||||||
|
) // #nosec G304 -- admin tool, runs as root, path controlled by operator
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ type DB struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewDB() (*DB, error) {
|
func NewDB() (*DB, error) {
|
||||||
db, err := sql.Open("sqlite3", "/var/lib/banforge/storage.db?mode=rwc&_journal_mode=WAL&_busy_timeout=10000&cache=shared")
|
db, err := sql.Open(
|
||||||
|
"sqlite3",
|
||||||
|
"/var/lib/banforge/storage.db?mode=rwc&_journal_mode=WAL&_busy_timeout=10000&cache=shared",
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -52,7 +55,9 @@ func (d *DB) CreateTable() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DB) SearchUnViewed() (*sql.Rows, error) {
|
func (d *DB) SearchUnViewed() (*sql.Rows, error) {
|
||||||
rows, err := d.db.Query("SELECT id, service, ip, path, status, method, viewed, created_at FROM requests WHERE viewed = 0")
|
rows, err := d.db.Query(
|
||||||
|
"SELECT id, service, ip, path, status, method, viewed, created_at FROM requests WHERE viewed = 0",
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error("Failed to query database")
|
d.logger.Error("Failed to query database")
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -136,7 +141,10 @@ func (d *DB) BanList() error {
|
|||||||
|
|
||||||
func (d *DB) CheckExpiredBans() ([]string, error) {
|
func (d *DB) CheckExpiredBans() ([]string, error) {
|
||||||
var ips []string
|
var ips []string
|
||||||
rows, err := d.db.Query("SELECT ip FROM bans WHERE expired_at < ?", time.Now().Format(time.RFC3339))
|
rows, err := d.db.Query(
|
||||||
|
"SELECT ip FROM bans WHERE expired_at < ?",
|
||||||
|
time.Now().Format(time.RFC3339),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Error("Failed to get ban list", "error", err)
|
d.logger.Error("Failed to get ban list", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user