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
9dbf4dda
Commit
9dbf4dda
authored
Sep 29, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(captiveportal, new) style fixes
parent
7891a044
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
38 deletions
+39
-38
allow.py
src/opnsense/scripts/OPNsense/CaptivePortal/allow.py
+1
-1
disconnect.py
src/opnsense/scripts/OPNsense/CaptivePortal/disconnect.py
+2
-3
index.html
.../scripts/OPNsense/CaptivePortal/htdocs_default/index.html
+1
-1
db.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/db.py
+30
-28
ipfw.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/ipfw.py
+4
-4
listClients.py
src/opnsense/scripts/OPNsense/CaptivePortal/listClients.py
+1
-1
No files found.
src/opnsense/scripts/OPNsense/CaptivePortal/allow.py
View file @
9dbf4dda
...
...
@@ -35,7 +35,7 @@ from lib.arp import ARP
from
lib.ipfw
import
IPFW
# parse input parameters
parameters
=
{
'username'
:
''
,
'ip_address'
:
None
,
'zoneid'
:
None
,
'authenticated_via'
:
None
,
'output_type'
:
'plain'
}
parameters
=
{
'username'
:
''
,
'ip_address'
:
None
,
'zoneid'
:
None
,
'authenticated_via'
:
None
,
'output_type'
:
'plain'
}
current_param
=
None
for
param
in
sys
.
argv
[
1
:]:
if
len
(
param
)
>
1
and
param
[
0
]
==
'/'
:
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/disconnect.py
View file @
9dbf4dda
...
...
@@ -31,11 +31,10 @@
import
sys
import
ujson
from
lib.db
import
DB
from
lib.arp
import
ARP
from
lib.ipfw
import
IPFW
# parse input parameters
parameters
=
{
'sessionid'
:
None
,
'zoneid'
:
None
,
'output_type'
:
'plain'
}
parameters
=
{
'sessionid'
:
None
,
'zoneid'
:
None
,
'output_type'
:
'plain'
}
current_param
=
None
for
param
in
sys
.
argv
[
1
:]:
if
len
(
param
)
>
1
and
param
[
0
]
==
'/'
:
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/htdocs_default/index.html
View file @
9dbf4dda
...
...
@@ -29,7 +29,7 @@
// try to login
$
.
ajax
({
type
:
"
POST
"
,
url
:
"
http
://127.0.0.1:8888/api/captiveportal/access/logon
"
,
url
:
"
http
s://10.211.55.100/api/captiveportal/access/logon/0/
"
,
dataType
:
"
json
"
,
data
:{
user
:
$
(
"
#inputUsername
"
).
val
(),
password
:
$
(
"
#inputPassword
"
).
val
()
}
}).
done
(
function
(
data
)
{
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/lib/db.py
View file @
9dbf4dda
...
...
@@ -77,15 +77,15 @@ class DB(object):
cur
=
self
.
_connection
.
cursor
()
# set cp_client as deleted in case there's already a user logged-in at this ip address.
cur
.
execute
(
"""
update
cp_clients
set
deleted = 1
where
zoneid = :zoneid
and
ip_address = :ipAddress
cur
.
execute
(
"""
UPDATE
cp_clients
SET
deleted = 1
WHERE
zoneid = :zoneid
AND
ip_address = :ipAddress
"""
,
response
)
# add new session
cur
.
execute
(
"""
insert into
cp_clients(zoneid, authenticated_via, sessionid, username, ip_address, mac_address, created)
values
(:zoneid, :authenticated_via, :sessionId, :userName, :ipAddress, :macAddress, :startTime)
cur
.
execute
(
"""
INSERT INTO
cp_clients(zoneid, authenticated_via, sessionid, username, ip_address, mac_address, created)
VALUES
(:zoneid, :authenticated_via, :sessionId, :userName, :ipAddress, :macAddress, :startTime)
"""
,
response
)
self
.
_connection
.
commit
()
...
...
@@ -98,11 +98,11 @@ class DB(object):
:return: client info before removal or None if client not found
"""
cur
=
self
.
_connection
.
cursor
()
cur
.
execute
(
"""
select
*
from
cp_clients
where
sessionid = :sessionid
and
zoneid = :zoneid
and
deleted = 0
cur
.
execute
(
"""
SELECT
*
FROM
cp_clients
WHERE
sessionid = :sessionid
AND
zoneid = :zoneid
AND
deleted = 0
"""
,
{
'zoneid'
:
zoneid
,
'sessionid'
:
sessionid
})
data
=
cur
.
fetchall
()
if
len
(
data
)
>
0
:
...
...
@@ -110,7 +110,7 @@ class DB(object):
for
fields
in
cur
.
description
:
session_info
[
fields
[
0
]]
=
data
[
0
][
len
(
session_info
)]
# remove client
cur
.
execute
(
"
update cp_clients set deleted = 1 where sessionid = :sessionid and
zoneid = :zoneid"
,
cur
.
execute
(
"
UPDATE cp_clients SET deleted = 1 WHERE sessionid = :sessionid AND
zoneid = :zoneid"
,
{
'zoneid'
:
zoneid
,
'sessionid'
:
sessionid
})
self
.
_connection
.
commit
()
...
...
@@ -118,7 +118,6 @@ class DB(object):
else
:
return
None
def
list_clients
(
self
,
zoneid
):
""" return list of (administrative) connected clients and usage statistics
:param zoneid: zone id
...
...
@@ -128,22 +127,22 @@ class DB(object):
fieldnames
=
list
()
cur
=
self
.
_connection
.
cursor
()
# rename fields for API
cur
.
execute
(
"""
select
cc.zoneid
cur
.
execute
(
"""
SELECT
cc.zoneid
, cc.sessionid sessionId
, cc.authenticated_via authenticated_via
, cc.username userName
, cc.created startTime
, cc.ip_address ipAddress
, cc.mac_address macAddress
,
case when si.packets_in is null then 0 else si.packets_in end
packets_in
,
case when si.packets_out is null then 0 else si.packets_out end
packets_out
,
case when si.bytes_in is null then 0 else si.bytes_in end
bytes_in
,
case when si.bytes_out is null then 0 else si.bytes_out end
bytes_out
,
case when si.last_accessed is null then 0 else si.last_accessed end
last_accessed
from
cp_clients cc
left join session_info si on si.zoneid = cc.zoneid and
si.sessionid = cc.sessionid
where
cc.zoneid = :zoneid
and
cc.deleted = 0
,
CASE WHEN si.packets_in IS NULL THEN 0 ELSE si.packets_in END
packets_in
,
CASE WHEN si.packets_out IS NULL THEN 0 ELSE si.packets_out END
packets_out
,
CASE WHEN si.bytes_in IS NULL THEN 0 ELSE si.bytes_in END
bytes_in
,
CASE WHEN si.bytes_out IS NULL THEN 0 ELSE si.bytes_out END
bytes_out
,
CASE WHEN si.last_accessed IS NULL THEN 0 ELSE si.last_accessed END
last_accessed
FROM
cp_clients cc
LEFT JOIN session_info si ON si.zoneid = cc.zoneid AND
si.sessionid = cc.sessionid
WHERE
cc.zoneid = :zoneid
AND
cc.deleted = 0
"""
,
{
'zoneid'
:
zoneid
})
while
True
:
# fetch field names
...
...
@@ -220,10 +219,13 @@ class DB(object):
if
record
[
'prev_packets_in'
]
<=
details
[
record
[
'ip_address'
]][
'in_pkts'
]
and
\
record
[
'prev_packets_out'
]
<=
details
[
record
[
'ip_address'
]][
'out_pkts'
]:
# ipfw data is still valid, add difference to use
record
[
'packets_in'
]
=
(
details
[
record
[
'ip_address'
]][
'in_pkts'
]
-
record
[
'prev_packets_in'
])
record
[
'packets_out'
]
=
(
details
[
record
[
'ip_address'
]][
'out_pkts'
]
-
record
[
'prev_packets_out'
])
record
[
'packets_in'
]
=
(
details
[
record
[
'ip_address'
]][
'in_pkts'
]
-
record
[
'prev_packets_in'
])
record
[
'packets_out'
]
=
(
details
[
record
[
'ip_address'
]][
'out_pkts'
]
-
record
[
'prev_packets_out'
])
record
[
'bytes_in'
]
=
(
details
[
record
[
'ip_address'
]][
'in_bytes'
]
-
record
[
'prev_bytes_in'
])
record
[
'bytes_out'
]
=
(
details
[
record
[
'ip_address'
]][
'out_bytes'
]
-
record
[
'prev_bytes_out'
])
record
[
'bytes_out'
]
=
(
details
[
record
[
'ip_address'
]][
'out_bytes'
]
-
record
[
'prev_bytes_out'
])
else
:
# the data has been reset (reloading rules), add current packet count
record
[
'packets_in'
]
=
details
[
record
[
'ip_address'
]][
'in_pkts'
]
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/lib/ipfw.py
View file @
9dbf4dda
...
...
@@ -114,10 +114,10 @@ class IPFW(object):
if
ip_address
not
in
result
:
result
[
ip_address
]
=
{
'rule'
:
int
(
parts
[
0
]),
'last_accessed'
:
0
,
'in_pkts'
:
0
,
'in_bytes'
:
0
,
'out_pkts'
:
0
,
'out_bytes'
:
0
'in_pkts'
:
0
,
'in_bytes'
:
0
,
'out_pkts'
:
0
,
'out_bytes'
:
0
}
result
[
ip_address
][
'last_accessed'
]
=
max
(
result
[
ip_address
][
'last_accessed'
],
last_accessed
)
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/listClients.py
View file @
9dbf4dda
...
...
@@ -33,7 +33,7 @@ import ujson
from
lib.db
import
DB
# parse input parameters
parameters
=
{
'zoneid'
:
None
,
'output_type'
:
'plain'
}
parameters
=
{
'zoneid'
:
None
,
'output_type'
:
'plain'
}
current_param
=
None
for
param
in
sys
.
argv
[
1
:]:
if
len
(
param
)
>
1
and
param
[
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