mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 01:54:49 +00:00
(captiveportal, new) style fixes
This commit is contained in:
parent
7891a04426
commit
9dbf4dda65
@ -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] == '/':
|
||||
|
||||
@ -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] == '/':
|
||||
@ -47,7 +46,7 @@ for param in sys.argv[1:]:
|
||||
|
||||
# disconnect client
|
||||
response = {'terminateCause': 'UNKNOWN'}
|
||||
if parameters['sessionid'] is not None and parameters['zoneid'] is not None:
|
||||
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'])
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
// try to login
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "http://127.0.0.1:8888/api/captiveportal/access/logon",
|
||||
url: "https://10.211.55.100/api/captiveportal/access/logon/0/",
|
||||
dataType:"json",
|
||||
data:{ user: $("#inputUsername").val(), password: $("#inputPassword").val() }
|
||||
}).done(function(data) {
|
||||
|
||||
@ -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
|
||||
@ -218,12 +217,15 @@ class DB(object):
|
||||
# add usage to session
|
||||
record['last_accessed'] = details[record['ip_address']]['last_accessed']
|
||||
if record['prev_packets_in'] <= details[record['ip_address']]['in_pkts'] and \
|
||||
record['prev_packets_out'] <= details[record['ip_address']]['out_pkts']:
|
||||
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['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['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'])
|
||||
else:
|
||||
# the data has been reset (reloading rules), add current packet count
|
||||
record['packets_in'] = details[record['ip_address']]['in_pkts']
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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] == '/':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user