Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
1fd5d463
Commit
1fd5d463
authored
Oct 03, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(captiveportal, new) work in progress scriptbase, idletimeout, hardtimeout, etc
parent
3677ab28
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
16 deletions
+24
-16
cp-background-process.py
...e/scripts/OPNsense/CaptivePortal/cp-background-process.py
+12
-8
db.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/db.py
+3
-2
ipfw.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/ipfw.py
+9
-6
No files found.
src/opnsense/scripts/OPNsense/CaptivePortal/cp-background-process.py
View file @
1fd5d463
...
@@ -62,10 +62,7 @@ def main():
...
@@ -62,10 +62,7 @@ def main():
expected_clients
=
db
.
list_clients
(
zoneid
)
expected_clients
=
db
.
list_clients
(
zoneid
)
# handle connected clients, timeouts, address changes, etc.
# handle connected clients, timeouts, address changes, etc.
for
db_client
in
expected_clients
:
for
db_client
in
expected_clients
:
# convert ip address to net, tables are registered as nets
# fetch ip address (or network) from database
if
db_client
[
'ipAddress'
]
.
strip
()
.
find
(
'/'
)
==
-
1
:
cpnet
=
'
%
s/32'
%
db_client
[
'ipAddress'
]
.
strip
()
else
:
cpnet
=
db_client
[
'ipAddress'
]
.
strip
()
cpnet
=
db_client
[
'ipAddress'
]
.
strip
()
# there are different reasons why a session should be removed, check for all reasons and
# there are different reasons why a session should be removed, check for all reasons and
...
@@ -75,10 +72,17 @@ def main():
...
@@ -75,10 +72,17 @@ def main():
# todo, static ip and addresses shouldn't be affected by the timeout rules below.
# todo, static ip and addresses shouldn't be affected by the timeout rules below.
# check if hardtimeout is set and overrun for this session
# check if hardtimeout is set and overrun for this session
if
'hardtimeout'
in
cpzones
[
zoneid
]
and
str
(
cpzones
[
zoneid
][
'hardtimeout'
])
.
isdigit
():
if
'hardtimeout'
in
cpzones
[
zoneid
]
and
str
(
cpzones
[
zoneid
][
'hardtimeout'
])
.
isdigit
():
if
int
(
cpzones
[
zoneid
][
'hardtimeout'
])
>
0
:
# hardtimeout should be set and we should have collected some session data from the client
if
time
.
time
()
-
float
(
db_client
[
'startTime'
])
/
60
>
int
(
cpzones
[
zoneid
][
'hardtimeout'
]):
if
int
(
cpzones
[
zoneid
][
'hardtimeout'
])
>
0
and
float
(
db_client
[
'startTime'
])
>
0
:
if
(
time
.
time
()
-
float
(
db_client
[
'startTime'
]))
/
60
>
int
(
cpzones
[
zoneid
][
'hardtimeout'
]):
drop_session
=
True
# check if idletimeout is set and overrun for this session
if
'idletimeout'
in
cpzones
[
zoneid
]
and
str
(
cpzones
[
zoneid
][
'idletimeout'
])
.
isdigit
():
# idletimeout should be set and we should have collected some session data from the client
if
int
(
cpzones
[
zoneid
][
'idletimeout'
])
>
0
and
float
(
db_client
[
'last_accessed'
])
>
0
:
if
(
time
.
time
()
-
float
(
db_client
[
'last_accessed'
]))
/
60
>
int
(
cpzones
[
zoneid
][
'idletimeout'
]):
drop_session
=
True
drop_session
=
True
drop_session
=
False
# check session, if it should be active, validate its properties
# check session, if it should be active, validate its properties
if
not
drop_session
:
if
not
drop_session
:
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/lib/db.py
View file @
1fd5d463
...
@@ -78,6 +78,7 @@ class DB(object):
...
@@ -78,6 +78,7 @@ class DB(object):
response
[
'ipAddress'
]
=
ip_address
response
[
'ipAddress'
]
=
ip_address
response
[
'macAddress'
]
=
mac_address
response
[
'macAddress'
]
=
mac_address
response
[
'startTime'
]
=
time
.
time
()
# record creation = sign-in time
response
[
'startTime'
]
=
time
.
time
()
# record creation = sign-in time
response
[
'last_accessed'
]
=
time
.
time
()
# last accessed_time = sign-in time
response
[
'sessionId'
]
=
base64
.
b64encode
(
os
.
urandom
(
16
))
# generate a new random session id
response
[
'sessionId'
]
=
base64
.
b64encode
(
os
.
urandom
(
16
))
# generate a new random session id
cur
=
self
.
_connection
.
cursor
()
cur
=
self
.
_connection
.
cursor
()
...
@@ -89,8 +90,8 @@ class DB(object):
...
@@ -89,8 +90,8 @@ class DB(object):
"""
,
response
)
"""
,
response
)
# add new session
# add new session
cur
.
execute
(
"""INSERT INTO cp_clients(zoneid, authenticated_via, sessionid, username, ip_address, mac_address, created)
cur
.
execute
(
"""INSERT INTO cp_clients(zoneid, authenticated_via, sessionid, username, ip_address, mac_address, created
, last_accessed
)
VALUES (:zoneid, :authenticated_via, :sessionId, :userName, :ipAddress, :macAddress, :startTime)
VALUES (:zoneid, :authenticated_via, :sessionId, :userName, :ipAddress, :macAddress, :startTime
, :last_accessed
)
"""
,
response
)
"""
,
response
)
self
.
_connection
.
commit
()
self
.
_connection
.
commit
()
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/lib/ipfw.py
View file @
1fd5d463
...
@@ -48,6 +48,13 @@ class IPFW(object):
...
@@ -48,6 +48,13 @@ class IPFW(object):
output_stream
.
seek
(
0
)
output_stream
.
seek
(
0
)
for
line
in
output_stream
.
read
()
.
split
(
'
\n
'
):
for
line
in
output_stream
.
read
()
.
split
(
'
\n
'
):
if
line
.
split
(
' '
)[
0
]
.
strip
()
!=
""
:
if
line
.
split
(
' '
)[
0
]
.
strip
()
!=
""
:
# process / 32 nets as single addresses to align better with the rule syntax
# and local administration.
if
line
.
split
(
' '
)[
0
]
.
split
(
'/'
)[
-
1
]
==
'32'
:
# single IPv4 address
result
.
append
(
line
.
split
(
' '
)[
0
]
.
split
(
'/'
)[
0
])
else
:
# network
result
.
append
(
line
.
split
(
' '
)[
0
])
result
.
append
(
line
.
split
(
' '
)[
0
])
return
result
return
result
...
@@ -58,11 +65,7 @@ class IPFW(object):
...
@@ -58,11 +65,7 @@ class IPFW(object):
:return: boolean
:return: boolean
"""
"""
ipfw_tbl
=
self
.
list_table
(
table_number
)
ipfw_tbl
=
self
.
list_table
(
table_number
)
if
address
.
find
(
'.'
)
>
-
1
and
address
.
find
(
'/'
)
==
-
1
:
if
address
.
strip
()
in
ipfw_tbl
:
# address given, search for /32 net in ipfw rules
if
'
%
s/32'
%
address
.
strip
()
in
ipfw_tbl
:
return
True
elif
address
.
strip
()
in
ipfw_tbl
:
return
True
return
True
return
False
return
False
...
...
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