Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
noblogs-composer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noblogs
noblogs-composer
Commits
bbfbb827
Commit
bbfbb827
authored
1 year ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Use ai3/tools/modsec-logger
parent
b5eb35c4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#60929
passed
1 year ago
Stage: build
Stage: container-test
Stage: release
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Dockerfile
+3
-6
3 additions, 6 deletions
Dockerfile
docker/conf/apache2/conf-available/modsecurity-custom.conf
+1
-1
1 addition, 1 deletion
docker/conf/apache2/conf-available/modsecurity-custom.conf
modsec_logger.go
+0
-76
0 additions, 76 deletions
modsec_logger.go
with
4 additions
and
83 deletions
Dockerfile
+
3
−
6
View file @
bbfbb827
FROM
golang:1.20
AS
gobuild
COPY
modsec_logger.go /src/modsec_logger.go
WORKDIR
/src
RUN
go build
-tags
netgo
-o
modsec_logger modsec_logger.go
FROM
composer:2.5.5
as
build
FROM
composer:2.5.5
as
build
ADD
. /build
ADD
. /build
WORKDIR
/build
WORKDIR
/build
RUN
/build/install.sh
RUN
/build/install.sh
FROM
registry.git.autistici.org/ai3/tools/modsec-logger:master
AS
modseclogger
FROM
registry.git.autistici.org/ai3/docker/apache2-php-base:bookworm
FROM
registry.git.autistici.org/ai3/docker/apache2-php-base:bookworm
COPY
--from=build /build/app/ /opt/noblogs/www
COPY
--from=build /build/app/ /opt/noblogs/www
...
@@ -20,7 +17,7 @@ COPY docker/wp-config.php /opt/noblogs/www/wp-config.php
...
@@ -20,7 +17,7 @@ COPY docker/wp-config.php /opt/noblogs/www/wp-config.php
COPY
docker/wp-cache-config.php /opt/noblogs/www/wp-content/wp-cache-config.php
COPY
docker/wp-cache-config.php /opt/noblogs/www/wp-content/wp-cache-config.php
COPY
docker/conf /tmp/conf
COPY
docker/conf /tmp/conf
COPY
docker/build.sh /tmp/build.sh
COPY
docker/build.sh /tmp/build.sh
COPY
--from=
gobuild /src
/modsec
_
logger /usr/local/bin/modsec
_
logger
COPY
--from=
modseclogger
/modsec
-
logger /usr/local/bin/modsec
-
logger
# Install wp-cli in /usr/local/bin (aliased as "wp").
# Install wp-cli in /usr/local/bin (aliased as "wp").
ADD
https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar /usr/local/bin/wp-cli.phar
ADD
https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar /usr/local/bin/wp-cli.phar
...
...
This diff is collapsed.
Click to expand it.
docker/conf/apache2/conf-available/modsecurity-custom.conf
+
1
−
1
View file @
bbfbb827
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
SecRuleEngine
Off
SecRuleEngine
Off
</
Location
>
</
Location
>
ErrorLog
"|/usr/local/bin/modsec
_
logger"
ErrorLog
"|/usr/local/bin/modsec
-
logger"
</
IfModule
>
</
IfModule
>
</
IfModule
>
</
IfModule
>
This diff is collapsed.
Click to expand it.
modsec_logger.go
deleted
100644 → 0
+
0
−
76
View file @
b5eb35c4
// Tool to rewrite mod_security2 logs (very difficult to parse
// although they are in semi-structured format) to JSON.
package
main
import
(
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"os"
"regexp"
)
var
(
outerRx
=
regexp
.
MustCompile
(
`\[[^\]]+]`
)
innerRx
=
regexp
.
MustCompile
(
`\[([^ ]+) \"?(.*)\"\]$`
)
needle
=
[]
byte
(
"ModSecurity: "
)
)
func
parseModSec
(
w
io
.
Writer
,
line
[]
byte
)
bool
{
if
!
bytes
.
Contains
(
line
,
needle
)
{
return
false
}
fields
:=
make
(
map
[
string
]
interface
{})
var
tags
[]
string
for
_
,
inner
:=
range
outerRx
.
FindAll
(
line
,
-
1
)
{
for
_
,
matches
:=
range
innerRx
.
FindAllSubmatch
(
inner
,
-
1
)
{
field
:=
string
(
matches
[
1
])
value
:=
string
(
matches
[
2
])
switch
field
{
case
"tag"
:
tags
=
append
(
tags
,
value
)
case
"client"
,
"unique_id"
,
"file"
,
"line"
:
// Suppress these tags.
default
:
fields
[
field
]
=
value
}
}
}
if
len
(
fields
)
==
0
{
return
false
}
if
len
(
tags
)
>
0
{
fields
[
"tag"
]
=
tags
}
data
,
_
:=
json
.
Marshal
(
fields
)
fmt
.
Fprintf
(
w
,
"@cee:{
\"
modsec
\"
:%s}
\n
"
,
data
)
return
true
}
func
writeLine
(
w
io
.
Writer
,
line
[]
byte
)
error
{
if
_
,
err
:=
w
.
Write
(
line
);
err
!=
nil
{
return
err
}
_
,
err
:=
io
.
WriteString
(
w
,
"
\n
"
)
return
err
}
func
main
()
{
outw
:=
os
.
Stdout
scanner
:=
bufio
.
NewScanner
(
os
.
Stdin
)
for
scanner
.
Scan
()
{
line
:=
scanner
.
Bytes
()
if
parseModSec
(
outw
,
line
)
{
continue
}
if
err
:=
writeLine
(
outw
,
line
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment