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
7c4f9c37
Commit
7c4f9c37
authored
Sep 29, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(captiveportal, new) work in progress script base
parent
9d81789c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
allow.py
src/opnsense/scripts/OPNsense/CaptivePortal/allow.py
+2
-2
db.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/db.py
+20
-11
No files found.
src/opnsense/scripts/OPNsense/CaptivePortal/allow.py
View file @
7c4f9c37
...
...
@@ -66,9 +66,9 @@ if parameters['ip_address'] is not None and parameters['zoneid'] is not None:
# add accounting for this ip address
cpIPFW
.
add_accounting
(
parameters
[
'ip_address'
])
response
[
'
s
tate'
]
=
'AUTHORIZED'
response
[
'
clientS
tate'
]
=
'AUTHORIZED'
else
:
response
=
{
'
s
tate'
:
'UNKNOWN'
}
response
=
{
'
clientS
tate'
:
'UNKNOWN'
}
# output result as plain text or json
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/lib/db.py
View file @
7c4f9c37
...
...
@@ -68,27 +68,27 @@ class DB(object):
"""
response
=
dict
()
response
[
'zoneid'
]
=
zoneid
response
[
'user
n
ame'
]
=
username
response
[
'ip
_a
ddress'
]
=
ip_address
response
[
'mac
_a
ddress'
]
=
mac_address
response
[
'
created
'
]
=
time
.
time
()
# record creation = sign-in time
response
[
'session
i
d'
]
=
base64
.
b64encode
(
os
.
urandom
(
16
))
# generate a new random session id
response
[
'user
N
ame'
]
=
username
response
[
'ip
A
ddress'
]
=
ip_address
response
[
'mac
A
ddress'
]
=
mac_address
response
[
'
startTime
'
]
=
time
.
time
()
# record creation = sign-in time
response
[
'session
I
d'
]
=
base64
.
b64encode
(
os
.
urandom
(
16
))
# generate a new random session id
cur
=
self
.
_connection
.
cursor
()
# update cp_clients in case there's already a user logged-in at this ip address.
# places an implicit lock on this client.
cur
.
execute
(
"""update cp_clients
set created = :
created
, username = :user
n
ame
, mac_address = :mac
_a
ddress
set created = :
startTime
, username = :user
N
ame
, mac_address = :mac
A
ddress
where zoneid = :zoneid
and ip_address = :ip
_a
ddress
and ip_address = :ip
A
ddress
"""
,
response
)
# normal operation, new user at this ip, add to host
if
cur
.
rowcount
==
0
:
cur
.
execute
(
"""insert into cp_clients(zoneid, sessionid, username, ip_address, mac_address, created)
values (:zoneid, :session
id, :username, :ip_address, :mac_address, :created
)
values (:zoneid, :session
Id, :userName, :ipAddress, :macAddress, :startTime
)
"""
,
response
)
self
.
_connection
.
commit
()
...
...
@@ -102,7 +102,16 @@ class DB(object):
result
=
list
()
fieldnames
=
list
()
cur
=
self
.
_connection
.
cursor
()
cur
.
execute
(
"select * from cp_clients where zoneid = :zoneid"
,
{
'zoneid'
:
zoneid
})
# rename fields for API
cur
.
execute
(
""" select zoneid
, sessionid sessionId
, username userName
, created startTime
, ip_address ipAddress
, mac_address macAddress
from cp_clients
where zoneid = :zoneid
"""
,
{
'zoneid'
:
zoneid
})
while
True
:
# fetch field names
if
len
(
fieldnames
)
==
0
:
...
...
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