Commit 7c4f9c37 authored by Ad Schellevis's avatar Ad Schellevis

(captiveportal, new) work in progress script base

parent 9d81789c
...@@ -66,9 +66,9 @@ if parameters['ip_address'] is not None and parameters['zoneid'] is not None: ...@@ -66,9 +66,9 @@ if parameters['ip_address'] is not None and parameters['zoneid'] is not None:
# add accounting for this ip address # add accounting for this ip address
cpIPFW.add_accounting(parameters['ip_address']) cpIPFW.add_accounting(parameters['ip_address'])
response['state'] = 'AUTHORIZED' response['clientState'] = 'AUTHORIZED'
else: else:
response = {'state': 'UNKNOWN'} response = {'clientState': 'UNKNOWN'}
# output result as plain text or json # output result as plain text or json
......
...@@ -68,27 +68,27 @@ class DB(object): ...@@ -68,27 +68,27 @@ class DB(object):
""" """
response = dict() response = dict()
response['zoneid'] = zoneid response['zoneid'] = zoneid
response['username'] = username response['userName'] = username
response['ip_address'] = ip_address response['ipAddress'] = ip_address
response['mac_address'] = mac_address response['macAddress'] = mac_address
response['created'] = time.time() # record creation = sign-in time response['startTime'] = time.time() # record creation = 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()
# update cp_clients in case there's already a user logged-in at this ip address. # update cp_clients in case there's already a user logged-in at this ip address.
# places an implicit lock on this client. # places an implicit lock on this client.
cur.execute("""update cp_clients cur.execute("""update cp_clients
set created = :created set created = :startTime
, username = :username , username = :userName
, mac_address = :mac_address , mac_address = :macAddress
where zoneid = :zoneid where zoneid = :zoneid
and ip_address = :ip_address and ip_address = :ipAddress
""", response) """, response)
# normal operation, new user at this ip, add to host # normal operation, new user at this ip, add to host
if cur.rowcount == 0: if cur.rowcount == 0:
cur.execute("""insert into cp_clients(zoneid, sessionid, username, ip_address, mac_address, created) cur.execute("""insert into cp_clients(zoneid, sessionid, username, ip_address, mac_address, created)
values (:zoneid, :sessionid, :username, :ip_address, :mac_address, :created) values (:zoneid, :sessionId, :userName, :ipAddress, :macAddress, :startTime)
""", response) """, response)
self._connection.commit() self._connection.commit()
...@@ -102,7 +102,16 @@ class DB(object): ...@@ -102,7 +102,16 @@ class DB(object):
result = list() result = list()
fieldnames = list() fieldnames = list()
cur = self._connection.cursor() 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: while True:
# fetch field names # fetch field names
if len(fieldnames) == 0: if len(fieldnames) == 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment