Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
url-checker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
url-checker
Commits
c702d4fc
Commit
c702d4fc
authored
Dec 04, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Report http
parent
1e26ad2b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
9 deletions
+52
-9
urlchecker_http.py
urlchecker_http.py
+48
-8
urlchecker_network.py
urlchecker_network.py
+4
-1
No files found.
urlchecker_http.py
View file @
c702d4fc
import
requests
import
requests
from
urllib.parse
import
urlparse
,
urlunsplit
from
urllib.parse
import
urlparse
,
urlunsplit
from
forcediphttpsadapter.adapters
import
ForcedIPHTTPSAdapter
from
forcediphttpsadapter.adapters
import
ForcedIPHTTPSAdapter
from
peewee
import
fn
PREFERRED_TYPE
=
"text/html"
PREFERRED_TYPE
=
"text/html"
...
@@ -62,19 +63,58 @@ def request(url, headers=None, session=requests, version=0):
...
@@ -62,19 +63,58 @@ def request(url, headers=None, session=requests, version=0):
return
response
return
response
def
reportHttp
(
db
,
ip
=
None
,
url
=
None
):
# http://charlesleifer.com/blog/techniques-for-querying-lists-of-objects-and-determining-the-top-related-item/
HttpCodeChangeAlias
=
db
.
HttpCodeChange
.
alias
()
subquery
=
(
HttpCodeChangeAlias
.
select
(
HttpCodeChangeAlias
.
ip
,
HttpCodeChangeAlias
.
url
,
fn
.
MAX
(
HttpCodeChangeAlias
.
status_id
).
alias
(
"max_status_id"
),
)
.
group_by
(
HttpCodeChangeAlias
.
ip
,
HttpCodeChangeAlias
.
url
)
.
alias
(
"http_change_max_subquery"
)
)
StatusAlias
=
db
.
Status
.
alias
()
query
=
(
db
.
HttpCodeChange
.
select
(
db
.
HttpCodeChange
,
StatusAlias
)
.
join
(
StatusAlias
)
.
switch
(
db
.
HttpCodeChange
)
.
join
(
subquery
,
on
=
(
(
db
.
HttpCodeChange
.
status_id
==
subquery
.
c
.
max_status_id
)
&
(
db
.
HttpCodeChange
.
ip
==
subquery
.
c
.
ip
)
&
(
db
.
HttpCodeChange
.
url
==
subquery
.
c
.
url
)
),
)
.
order_by
(
db
.
HttpCodeChange
.
url
.
asc
(),
db
.
HttpCodeChange
.
ip
.
asc
())
)
if
ip
is
not
None
:
if
type
(
ip
)
==
list
:
query
=
query
.
where
(
db
.
HttpCodeChange
.
ip
<<
ip
)
else
:
query
=
query
.
where
(
db
.
HttpCodeChange
.
ip
==
ip
)
if
url
is
not
None
:
if
type
(
url
)
==
list
:
query
=
query
.
where
(
db
.
HttpCodeChange
.
url
<<
url
)
else
:
query
=
query
.
where
(
db
.
HttpCodeChange
.
url
==
url
)
return
query
def
logHttpStatus
(
db
,
ip
,
url
,
code
,
status_id
):
def
logHttpStatus
(
db
,
ip
,
url
,
code
,
status_id
):
with
db
.
_db
.
atomic
():
with
db
.
_db
.
atomic
():
try
:
try
:
# Check previous parameter value
# Check previous parameter value
previous_entry
=
(
previous_entry
=
reportHttp
(
db
,
ip
=
ip
,
url
=
url
).
get
()
db
.
HttpCodeChange
.
select
()
.
where
(
db
.
HttpCodeChange
.
ip
==
ip
,
db
.
HttpCodeChange
.
url
==
url
)
.
order_by
(
db
.
HttpCodeChange
.
status
.
desc
())
.
get
()
)
except
db
.
HttpCodeChange
.
DoesNotExist
:
except
db
.
HttpCodeChange
.
DoesNotExist
:
previous_entry
=
None
previous_entry
=
None
...
...
urlchecker_network.py
View file @
c702d4fc
...
@@ -52,6 +52,9 @@ def reportNetwork(db, ip=None, transport=None, port=None):
...
@@ -52,6 +52,9 @@ def reportNetwork(db, ip=None, transport=None, port=None):
else
:
else
:
query
=
query
.
where
(
db
.
NetworkChange
.
transport
==
transport
)
query
=
query
.
where
(
db
.
NetworkChange
.
transport
==
transport
)
if
port
is
not
None
:
if
port
is
not
None
:
if
type
(
port
)
==
list
:
query
=
query
.
where
(
db
.
NetworkChange
.
port
<<
port
)
else
:
query
=
query
.
where
(
db
.
NetworkChange
.
port
==
port
)
query
=
query
.
where
(
db
.
NetworkChange
.
port
==
port
)
if
ip
is
not
None
:
if
ip
is
not
None
:
if
type
(
ip
)
==
list
:
if
type
(
ip
)
==
list
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment