Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
modsec-ml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GSI
modsec-ml
Commits
b73631ca
Commit
b73631ca
authored
7 years ago
by
Juan Diego Campo
Browse files
Options
Downloads
Patches
Plain Diff
Saco dependencia a una lib json
parent
b5c0aec8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ml.lua
+16
-15
16 additions, 15 deletions
ml.lua
with
16 additions
and
15 deletions
ml.lua
+
16
−
15
View file @
b73631ca
...
@@ -18,16 +18,15 @@ function split(str, pat)
...
@@ -18,16 +18,15 @@ function split(str, pat)
end
end
function
main
()
function
main
()
local
json
=
require
(
"json"
)
local
JSON
=
(
loadfile
"JSON.lua"
)()
local
JSON
=
(
loadfile
"JSON.lua"
)()
local
input
=
"{\n"
local
input
=
"{\n"
input
=
input
..
"
\t\"
unique_id\"
:
"..
json.encode(
m.getvar("
UNIQUE_ID
")
)
.."
,
\
n
"
input
=
input
..
"
\t\"
unique_id\"
:
\
"
"
..
m
.
getvar
(
"UNIQUE_ID"
)
..
"
\"
,\n"
input = input.."
\
t
\
"method\"
:
"..
json.encode(
m.getvar("
REQUEST_METHOD
")
)
.."
,
\
n
"
input
=
input
..
"
\t\"
method\"
:
\
"
"
..
m
.
getvar
(
"REQUEST_METHOD"
)
..
"
\"
,\n"
input = input.."
\
t
\
"protocol\"
:
"..
json.encode(
m.getvar("
REQUEST_PROTOCOL
")
)
.."
,
\
n
"
input
=
input
..
"
\t\"
protocol\"
:
\
"
"
..
m
.
getvar
(
"REQUEST_PROTOCOL"
)
..
"
\"
,\n"
input = input.."
\
t
\
"uri\"
:
"..
json.encode(
m.getvar("
REQUEST_URI
")
)
.."
,
\
n
"
input
=
input
..
"
\t\"
uri\"
:
\
"
"
..
m
.
getvar
(
"REQUEST_URI"
)
..
"
\"
,\n"
if
m
.
getvar
(
"REQUEST_BODY"
)
then
if
m
.
getvar
(
"REQUEST_BODY"
)
then
input = input.."
\
t
\
"body\"
:
"..
json.encode(
m.getvar("
REQUEST_BODY
")
)
.."
,
\
n
"
input
=
input
..
"
\t\"
body\"
:
\
"
"
..
m
.
getvar
(
"REQUEST_BODY"
)
..
"
\"
,\n"
else
else
input
=
input
..
"
\t\"
body\"
:
\
"
\"
,\n"
input
=
input
..
"
\t\"
body\"
:
\
"
\"
,\n"
end
end
...
@@ -40,8 +39,8 @@ function main()
...
@@ -40,8 +39,8 @@ function main()
args_get = split(args_get[#args_get],"
&
")
args_get = split(args_get[#args_get],"
&
")
for i = 1, #args_get do
for i = 1, #args_get do
arg = split(args_get[i],"
=
")
arg = split(args_get[i],"
=
")
input = input.."
\
t
\
t
"..
json.encode(
arg[1]
)
.."
:
"
input = input.."
\
t
\
t
\
"
"
..
arg
[
1
]
..
"
\"
: "
input = input..
json.encode(arg[2])
input
=
input
..
"
\"
"
..
arg
[
2
]
..
"
\"
"
if
i
<
#
args_get
then
if
i
<
#
args_get
then
input
=
input
..
",\n"
input
=
input
..
",\n"
end
end
...
@@ -54,8 +53,8 @@ function main()
...
@@ -54,8 +53,8 @@ function main()
headers = split(headers,"
\
n
")
headers = split(headers,"
\
n
")
for i = 1, #headers do
for i = 1, #headers do
header = split(headers[i],"
:
")
header = split(headers[i],"
:
")
input = input.."
\
t
\
t
"..
json.encode(
header[1]
)
.."
:
"
input = input.."
\
t
\
t
\
"
"
..
header
[
1
]
..
"
\"
: "
input = input..
json.encode(
header[2]
)
input
=
input
..
"
\"
"
..
header
[
2
]
..
"
\"
"
if
i
<
#
headers
then
if
i
<
#
headers
then
input
=
input
..
",\n"
input
=
input
..
",\n"
end
end
...
@@ -66,8 +65,8 @@ function main()
...
@@ -66,8 +65,8 @@ function main()
-- local args_post = m.getvars("
ARGS_POST
")
-- local args_post = m.getvars("
ARGS_POST
")
local args_post = {}
local args_post = {}
for i = 1, #args_post do
for i = 1, #args_post do
input = input.."
\
t
\
t
"..
json.encode(
args_post[i].name
)
.."
:
"
input = input.."
\
t
\
t
\
"
"
..
args_post
[
i
].
name
..
"
\"
: "
input = input..
json.encode(
args_post[i].value
)
input
=
input
..
"
\"
"
..
args_post
[
i
].
value
..
"
\"
"
if
i
<
#
args_post
then
if
i
<
#
args_post
then
input
=
input
..
",\n"
input
=
input
..
",\n"
end
end
...
@@ -91,7 +90,9 @@ function main()
...
@@ -91,7 +90,9 @@ function main()
for
line
in
p
:
lines
()
do
for
line
in
p
:
lines
()
do
output
=
output
..
line
..
"
\n
"
output
=
output
..
line
..
"
\n
"
end
end
os.remove(tmpfile)
-- os.remove(tmpfile)
print
(
output
)
local
result
=
JSON
:
decode
(
output
)
local
result
=
JSON
:
decode
(
output
)
m
.
log
(
3
,
"ML - res:\n"
)
m
.
log
(
3
,
"ML - res:\n"
)
...
@@ -100,7 +101,7 @@ function main()
...
@@ -100,7 +101,7 @@ function main()
end
end
p
:
close
()
p
:
close
()
m
.
setvar
(
"tx.pepe"
,
"pepe"
)
return
"ERROR"
return nil
end
end
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