Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Warden
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pavel Valach
Warden
Commits
f50d1104
Commit
f50d1104
authored
10 years ago
by
Michal Kostenec
Browse files
Options
Downloads
Patches
Plain Diff
Dynamic SQL query building fixed (negating conditions)
Auth for sending events fixed
parent
f83b3adb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
warden3/warden_client/warden_client_test.py
+7
-4
7 additions, 4 deletions
warden3/warden_client/warden_client_test.py
warden3/warden_server/warden_server.py
+20
-15
20 additions, 15 deletions
warden3/warden_server/warden_server.py
with
27 additions
and
19 deletions
warden3/warden_client/warden_client_test.py
+
7
−
4
View file @
f50d1104
...
...
@@ -76,6 +76,7 @@ def gen_random_idea(client_name="cz.example.warden.test"):
"
EventTime
"
:
get_precise_timestamp
(),
"
CeaseTime
"
:
get_precise_timestamp
(),
"
Category
"
:
[
"
Abusive.Spam
"
,
"
Fraud.Copyright
"
,
"
Test
"
],
# "Category": ["Abusive.Spam","Fraud.Copyright"],
"
Ref
"
:
[
"
cve:CVE-%s-%s
"
%
(
randstr
(
string
.
digits
,
4
),
randstr
()),
"
http://www.example.com/%s
"
%
randstr
()],
"
Confidence
"
:
random
(),
"
Note
"
:
"
Random event
"
,
...
...
@@ -143,8 +144,10 @@ def main():
print
"
=== Getting 10 events ===
"
start
=
time
()
cat
=
[
'
Availability
'
,
'
Abusive.Spam
'
,
'
Attempt.Login
'
]
nocat
=
[
'
Fraud.Scam
'
,
'
Malware.Virus
'
]
# cat = ['Availability', 'Abusive.Spam','Attempt.Login']
# cat = ['Attempt', 'Information','Fraud.Scam','Malware.Virus']
cat
=
[
'
Attempt
'
]
nocat
=
[
'
Availability
'
,
'
Information
'
,
'
Fraud.Scam
'
]
tag
=
[
'
Log
'
,
'
Data
'
]
notag
=
[
'
Flow
'
,
'
Datagram
'
]
...
...
@@ -152,8 +155,8 @@ def main():
group
=
[
'
cz.tul.ward.kippo
'
,
'
cz.vsb.buldog.kippo
'
]
nogroup
=
[
'
cz.zcu.civ.afrodita
'
,
'
cz.vutbr.net.bee.hpscan
'
]
ret
=
wclient
.
getEvents
(
count
=
10
,
cat
=
cat
,
nocat
=
None
,
tag
=
tag
,
notag
=
None
,
group
=
None
,
nogroup
=
nogroup
)
#
ret = wclient.getEvents(count=10)
ret
=
wclient
.
getEvents
(
count
=
10
,
cat
=
None
,
nocat
=
None
,
tag
=
None
,
notag
=
None
,
group
=
None
,
nogroup
=
nogroup
)
ret
=
wclient
.
getEvents
(
count
=
10
)
print
"
Time: %f
"
%
(
time
()
-
start
)
print
"
Got %i events
"
%
len
(
ret
)
for
e
in
ret
:
...
...
This diff is collapsed.
Click to expand it.
warden3/warden_server/warden_server.py
+
20
−
15
View file @
f50d1104
...
...
@@ -307,8 +307,10 @@ class X509Authenticator(NoAuthenticator):
return
None
test
=
'
Test
'
in
event
.
get
(
'
Category
'
,
[])
if
not
test
:
logging
.
info
(
"
authorize: failed, service %i (%s) does not send Test category in event
"
%
(
service
[
"
service_id
"
],
identity
))
# if not test:
# logging.info("authorize: failed, service %i (%s) does not send Test category in event" % (service["service_id"], identity))
if
test
and
not
service
[
'
test
'
]:
logging
.
info
(
"
authorize: failed, service %i (%s) is not allowed to send Test category in event
"
%
(
service
[
"
service_id
"
],
identity
))
return
None
return
client
...
...
@@ -442,8 +444,13 @@ class MySQL(ObjectReq):
else
:
parent_cats
.
append
(
mapped_id
)
format_strings
=
'
,
'
.
join
([
'
%s
'
]
*
len
(
variables_id
))
temp_string
=
query_string
%
format_strings
temp_string
=
""
if
len
(
variables_id
)
>
0
:
format_strings
=
'
,
'
.
join
([
'
%s
'
]
*
len
(
variables_id
))
logging
.
debug
(
"
query_string: %s
"
%
query_string
)
logging
.
debug
(
"
format_strings: %s
"
%
format_strings
)
temp_string
=
query_string
%
format_strings
return
temp_string
,
variables_id
...
...
@@ -472,20 +479,18 @@ class MySQL(ObjectReq):
sqlparams
.
append
(
id
or
0
)
if
cat
or
nocat
:
not_op
=
""
if
cat
else
"
NOT
"
parent_cats
=
[]
sqltemp
,
sqlpar
=
self
.
generateDynamicQuery
(
self
.
catmap
,
"
category_id
%s
IN (%
%
s)
"
%
not_op
,
(
cat
or
nocat
),
parent_cats
)
for
pcat
s
in
parent_cats
:
sqltemp
+=
"
%s category_id
DIV
%s
= 1
"
%
((
"
OR
"
if
sqltemp
else
""
),
pcat
s
)
sqlwhere
.
append
(
"
AND e.id IN (SELECT event_id FROM event_category_mapping WHERE %s)
"
%
sqltemp
)
sqltemp
,
sqlpar
=
self
.
generateDynamicQuery
(
self
.
catmap
,
"
category_id IN (%s)
"
,
(
cat
or
nocat
),
parent_cats
)
for
pcat
in
parent_cats
:
sqltemp
+=
"
%s
(
category_id
>
%s
AND category_id < %s)
"
%
((
"
OR
"
if
sqltemp
else
""
),
pcat
,
pcat
+
100
)
sqlwhere
.
append
(
"
AND e.id
%s
IN (SELECT event_id FROM event_category_mapping WHERE %s)
"
%
((
"
NOT
"
if
nocat
else
""
),
sqltemp
)
)
sqlparams
.
extend
(
sqlpar
)
if
tag
or
notag
:
not_op
=
""
if
tag
else
"
NOT
"
sqltemp
,
sqlpar
=
self
.
generateDynamicQuery
(
self
.
tagmap
,
"
tag_id %s IN (%%s)
"
%
not_op
,
(
tag
or
notag
))
sqlwhere
.
append
(
"
AND e.id IN (SELECT event_id FROM event_tag_mapping WHERE %s)
"
%
sqltemp
)
sqltemp
,
sqlpar
=
self
.
generateDynamicQuery
(
self
.
tagmap
,
"
tag_id IN (%s)
"
,
(
tag
or
notag
))
sqlwhere
.
append
(
"
AND e.id %s IN (SELECT event_id FROM event_tag_mapping WHERE %s)
"
%
((
"
NOT
"
if
notag
else
""
),
sqltemp
))
sqlparams
.
extend
(
sqlpar
)
if
group
or
nogroup
:
...
...
@@ -766,7 +771,7 @@ class WardenHandler(ObjectReq):
try
:
id
=
self
.
db
.
getLastReceivedId
(
self
.
req
.
client
)
except
Exception
,
e
:
logging
.
info
(
"
cannot getLastReceivedId -
"
+
type
(
e
).
__name__
+
"
:
"
+
e
)
logging
.
info
(
"
cannot getLastReceivedId -
"
+
type
(
e
).
__name__
+
"
:
"
+
str
(
e
)
)
if
id
is
None
:
# First access, remember the guy and get him last event
...
...
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