Commit f8290c82 authored by Ad Schellevis's avatar Ad Schellevis

(captiveportal, new) add authenticated_via metadata to allow action

parent ebc96f66
...@@ -35,7 +35,7 @@ from lib.arp import ARP ...@@ -35,7 +35,7 @@ from lib.arp import ARP
from lib.ipfw import IPFW from lib.ipfw import IPFW
# parse input parameters # parse input parameters
parameters = {'username': '', 'ip_address': None, 'zoneid': None, 'output_type':'plain'} parameters = {'username': '', 'ip_address': None, 'zoneid': None,'authenticated_via': None, 'output_type':'plain'}
current_param = None current_param = None
for param in sys.argv[1:]: for param in sys.argv[1:]:
if len(param) > 1 and param[0] == '/': if len(param) > 1 and param[0] == '/':
...@@ -56,6 +56,7 @@ if parameters['ip_address'] is not None and parameters['zoneid'] is not None: ...@@ -56,6 +56,7 @@ if parameters['ip_address'] is not None and parameters['zoneid'] is not None:
mac_address = None mac_address = None
response = cpDB.add_client(zoneid=parameters['zoneid'], response = cpDB.add_client(zoneid=parameters['zoneid'],
authenticated_via=parameters['authenticated_via'],
username=parameters['username'], username=parameters['username'],
ip_address=parameters['ip_address'], ip_address=parameters['ip_address'],
mac_address=mac_address mac_address=mac_address
...@@ -77,4 +78,3 @@ if parameters['output_type'] != 'json': ...@@ -77,4 +78,3 @@ if parameters['output_type'] != 'json':
print '%20s %s' % (item, response[item]) print '%20s %s' % (item, response[item])
else: else:
print(ujson.dumps(response)) print(ujson.dumps(response))
...@@ -58,7 +58,7 @@ class DB(object): ...@@ -58,7 +58,7 @@ class DB(object):
cur.executescript(open(init_script_filename, 'rb').read()) cur.executescript(open(init_script_filename, 'rb').read())
cur.close() cur.close()
def add_client(self, zoneid, username, ip_address, mac_address): def add_client(self, zoneid, authenticated_via, username, ip_address, mac_address):
""" add a new client to the captive portal administration """ add a new client to the captive portal administration
:param zoneid: cp zone number :param zoneid: cp zone number
:param username: username, maybe empty :param username: username, maybe empty
...@@ -68,6 +68,7 @@ class DB(object): ...@@ -68,6 +68,7 @@ class DB(object):
""" """
response = dict() response = dict()
response['zoneid'] = zoneid response['zoneid'] = zoneid
response['authenticated_via'] = authenticated_via
response['userName'] = username response['userName'] = username
response['ipAddress'] = ip_address response['ipAddress'] = ip_address
response['macAddress'] = mac_address response['macAddress'] = mac_address
...@@ -83,8 +84,8 @@ class DB(object): ...@@ -83,8 +84,8 @@ class DB(object):
""", response) """, response)
# add new session # add new session
cur.execute("""insert into cp_clients(zoneid, sessionid, username, ip_address, mac_address, created) cur.execute("""insert into cp_clients(zoneid, authenticated_via, sessionid, username, ip_address, mac_address, created)
values (:zoneid, :sessionId, :userName, :ipAddress, :macAddress, :startTime) values (:zoneid, :authenticated_via, :sessionId, :userName, :ipAddress, :macAddress, :startTime)
""", response) """, response)
self._connection.commit() self._connection.commit()
...@@ -129,6 +130,7 @@ class DB(object): ...@@ -129,6 +130,7 @@ class DB(object):
# rename fields for API # rename fields for API
cur.execute(""" select cc.zoneid cur.execute(""" select cc.zoneid
, cc.sessionid sessionId , cc.sessionid sessionId
, cc.authenticated_via authenticated_via
, cc.username userName , cc.username userName
, cc.created startTime , cc.created startTime
, cc.ip_address ipAddress , cc.ip_address ipAddress
......
...@@ -6,7 +6,7 @@ message:list registered clients ...@@ -6,7 +6,7 @@ message:list registered clients
[allow] [allow]
command:/usr/local/opnsense/scripts/OPNsense/CaptivePortal/allow.py command:/usr/local/opnsense/scripts/OPNsense/CaptivePortal/allow.py
parameters:/zoneid %s /username %s /ip_address %s /output_type %s parameters:/zoneid %s /username %s /ip_address %s /authenticated_via %s /output_type %s
type:script_output type:script_output
message:allow client access to captive portal message:allow client access to captive portal
......
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