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
ecf96ebf
Commit
ecf96ebf
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
e6c1bf49
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
291 additions
and
35 deletions
+291
-35
disconnect.py
src/opnsense/scripts/OPNsense/CaptivePortal/disconnect.py
+65
-0
db.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/db.py
+128
-19
ipfw.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/ipfw.py
+17
-9
listClients.py
src/opnsense/scripts/OPNsense/CaptivePortal/listClients.py
+8
-6
init.sql
src/opnsense/scripts/OPNsense/CaptivePortal/sql/init.sql
+10
-1
update_stats.py
src/opnsense/scripts/OPNsense/CaptivePortal/update_stats.py
+63
-0
No files found.
src/opnsense/scripts/OPNsense/CaptivePortal/disconnect.py
0 → 100755
View file @
ecf96ebf
#!/usr/local/bin/python2.7
"""
Copyright (c) 2015 Deciso B.V. - Ad Schellevis
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------
disconnect client
"""
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'
}
current_param
=
None
for
param
in
sys
.
argv
[
1
:]:
if
len
(
param
)
>
1
and
param
[
0
]
==
'/'
:
current_param
=
param
[
1
:]
.
lower
()
elif
current_param
is
not
None
:
if
current_param
in
parameters
:
parameters
[
current_param
]
=
param
.
strip
()
current_param
=
None
# disconnect client
response
=
{
'terminateCause'
:
'UNKNOWN'
}
if
parameters
[
'sessionid'
]
is
not
None
and
parameters
[
'zoneid'
]
is
not
None
:
cp_db
=
DB
()
# remove client
client_session_info
=
cp_db
.
del_client
(
parameters
[
'zoneid'
],
parameters
[
'sessionid'
])
if
client_session_info
is
not
None
:
cpIPFW
=
IPFW
()
cpIPFW
.
delete_from_table
(
parameters
[
'zoneid'
],
client_session_info
[
'ip_address'
])
client_session_info
[
'terminateCause'
]
=
'User-Request'
response
=
client_session_info
# output result as plain text or json
if
parameters
[
'output_type'
]
!=
'json'
:
for
item
in
response
:
print
'
%20
s
%
s'
%
(
item
,
response
[
item
])
else
:
print
(
ujson
.
dumps
(
response
))
src/opnsense/scripts/OPNsense/CaptivePortal/lib/db.py
View file @
ecf96ebf
This diff is collapsed.
Click to expand it.
src/opnsense/scripts/OPNsense/CaptivePortal/lib/ipfw.py
View file @
ecf96ebf
...
...
@@ -103,8 +103,8 @@ class IPFW(object):
parts
=
line
.
split
()
if
len
(
parts
)
>
5
:
if
30001
<=
int
(
parts
[
0
])
<=
50000
and
parts
[
4
]
==
'count'
:
in
_pkts
=
int
(
parts
[
1
])
out_pkt
s
=
int
(
parts
[
2
])
line
_pkts
=
int
(
parts
[
1
])
line_byte
s
=
int
(
parts
[
2
])
last_accessed
=
int
(
parts
[
3
])
if
parts
[
7
]
!=
'any'
:
ip_address
=
parts
[
7
]
...
...
@@ -113,15 +113,23 @@ class IPFW(object):
if
ip_address
not
in
result
:
result
[
ip_address
]
=
{
'rule'
:
int
(
parts
[
0
]),
'last_accessed'
:
last_accessed
,
'in_pkts'
:
in_pkts
,
'out_pkts'
:
out_pkts
'last_accessed'
:
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
)
if
parts
[
7
]
!=
'any'
:
# count input
result
[
ip_address
][
'in_pkts'
]
=
line_pkts
result
[
ip_address
][
'in_bytes'
]
=
line_bytes
else
:
result
[
ip_address
][
'in_pkts'
]
+=
in_pkts
result
[
ip_address
][
'out_pkts'
]
+=
out
_pkts
result
[
ip_address
][
'
last_accessed'
]
=
max
(
result
[
ip_address
][
'last_accessed'
],
last_accessed
)
# count output
result
[
ip_address
][
'out_pkts'
]
=
line
_pkts
result
[
ip_address
][
'
out_bytes'
]
=
line_bytes
return
result
def
add_accounting
(
self
,
address
):
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/listClients.py
View file @
ecf96ebf
...
...
@@ -51,13 +51,15 @@ else:
# output result as plain text or json
if
parameters
[
'output_type'
]
!=
'json'
:
heading
=
{
'sessionid'
:
'sessionid'
,
'username'
:
'username'
,
'ip_address'
:
'ip_address'
,
'mac_address'
:
'mac_address'
heading
=
{
'sessionId'
:
'sessionid'
,
'userName'
:
'username'
,
'ipAddress'
:
'ip_address'
,
'macAddress'
:
'mac_address'
,
'total_bytes'
:
'total_bytes'
}
print
'
%(session
id)-30
s
%(username)-20
s
%(ip_address)-20
s
%(mac_addres
s)-20
s'
%
heading
print
'
%(session
Id)-30
s
%(userName)-20
s
%(ipAddress)-20
s
%(macAddress)-20
s
%(total_byte
s)-20
s'
%
heading
for
item
in
response
:
print
'
%(sessionid)-30
s
%(username)-20
s
%(ip_address)-20
s
%(mac_address)-20
s'
%
item
item
[
'total_bytes'
]
=
(
item
[
'bytes_out'
]
+
item
[
'bytes_in'
])
print
'
%(sessionId)-30
s
%(userName)-20
s
%(ipAddress)-20
s
%(macAddress)-20
s
%(total_bytes)-20
s'
%
item
else
:
print
(
ujson
.
dumps
(
response
))
src/opnsense/scripts/OPNsense/CaptivePortal/sql/init.sql
View file @
ecf96ebf
...
...
@@ -10,6 +10,7 @@ create table cp_clients (
,
ip_address
varchar
,
mac_address
varchar
,
created
number
,
deleted
integer
default
(
0
)
,
primary
key
(
zoneid
,
sessionid
)
);
...
...
@@ -20,6 +21,14 @@ create index cp_clients_zone ON cp_clients (zoneid);
create
table
session_info
(
zoneid
int
,
sessionid
varchar
,
prev_packets_in
integer
,
prev_bytes_in
integer
,
prev_packets_out
integer
,
prev_bytes_out
integer
,
packets_in
integer
default
(
0
)
,
packets_out
integer
default
(
0
)
,
bytes_in
integer
default
(
0
)
,
bytes_out
integer
default
(
0
)
,
last_accessed
integer
,
primary
key
(
zoneid
,
sessionid
)
);
src/opnsense/scripts/OPNsense/CaptivePortal/update_stats.py
0 → 100755
View file @
ecf96ebf
#!/usr/local/bin/python2.7
"""
Copyright (c) 2015 Deciso B.V. - Ad Schellevis
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------
update captive portal statistics
"""
import
sys
import
ujson
from
lib.db
import
DB
from
lib.arp
import
ARP
from
lib.ipfw
import
IPFW
db
=
DB
()
cur
=
db
.
_connection
.
cursor
();
# update accounting
ipfw
=
IPFW
()
#print ipfw.list_accounting_info()
db
.
update_accounting_info
(
ipfw
.
list_accounting_info
())
# tmp = """
# create table session_info (
# zoneid int
# , sessionid varchar
# , prev_packets_in integer
# , prev_bytes_in integer
# , prev_packets_out integer
# , prev_bytes_out integer
# , packets_in integer default (0)
# , packets_out integer default (0)
# , bytes_in integer default (0)
# , bytes_out integer default (0)
# , last_accessed integer
# , primary key (zoneid, sessionid)
# );
# """
# cur.execute("drop table session_info");
# cur.execute(tmp);
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