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
32ab2367
Commit
32ab2367
authored
Oct 27, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Captiveportal, new) add session overview feature
parent
21d0227e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
292 additions
and
0 deletions
+292
-0
SessionController.php
...trollers/OPNsense/CaptivePortal/Api/SessionController.php
+102
-0
SessionController.php
.../controllers/OPNsense/CaptivePortal/SessionController.php
+43
-0
clients.volt
...pnsense/mvc/app/views/OPNsense/CaptivePortal/clients.volt
+147
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/CaptivePortal/Api/SessionController.php
0 → 100644
View file @
32ab2367
<?php
/**
* Copyright (C) 2015 Deciso B.V.
*
* 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.
*
*/
namespace
OPNsense\CaptivePortal\Api
;
use
\OPNsense\Base\ApiControllerBase
;
use
\OPNsense\Core\Backend
;
use
\OPNsense\CaptivePortal\CaptivePortal
;
/**
* Class SessionController
* @package OPNsense\CaptivePortal
*/
class
SessionController
extends
ApiControllerBase
{
/**
* list client sessions
* @param int $zoneid zone number
* @return array|mixed
*/
public
function
listAction
(
$zoneid
=
0
)
{
$mdlCP
=
new
CaptivePortal
();
$cpZone
=
$mdlCP
->
getByZoneID
(
$zoneid
);
if
(
$cpZone
!=
null
)
{
$backend
=
new
Backend
();
$allClientsRaw
=
$backend
->
configdpRun
(
"captiveportal list_clients"
,
array
(
$cpZone
->
zoneid
,
'json'
)
);
$allClients
=
json_decode
(
$allClientsRaw
,
true
);
return
$allClients
;
}
else
{
// illegal zone, return empty response
return
array
();
}
}
/**
* return list of available zones
* @return array available zones
*/
public
function
zonesAction
()
{
$response
=
array
();
$mdlCP
=
new
CaptivePortal
();
foreach
(
$mdlCP
->
zones
->
zone
->
__items
as
$zone
)
{
$response
[(
string
)
$zone
->
zoneid
]
=
(
string
)
$zone
->
description
;
}
asort
(
$response
);
return
$response
;
}
/**
* disconnect a client
* @param string|int $zoneid zoneid
* @return array|mixed
*/
public
function
disconnectAction
(
$zoneid
=
0
)
{
if
(
$this
->
request
->
isPost
()
&&
$this
->
request
->
hasPost
(
'sessionId'
))
{
$backend
=
new
Backend
();
$statusRAW
=
$backend
->
configdpRun
(
"captiveportal disconnect"
,
array
(
$zoneid
,
$this
->
request
->
getPost
(
'sessionId'
),
'json'
)
);
$status
=
json_decode
(
$statusRAW
,
true
);
if
(
$status
!=
null
)
{
return
$status
;
}
else
{
return
array
(
"status"
=>
"Illegal response"
);
}
}
return
array
();
}
}
src/opnsense/mvc/app/controllers/OPNsense/CaptivePortal/SessionController.php
0 → 100644
View file @
32ab2367
<?php
/**
* Copyright (C) 2015 Deciso B.V.
*
* 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.
*
*/
namespace
OPNsense\CaptivePortal
;
/**
* Class SessionController
* @package OPNsense\CaptivePortal
*/
class
SessionController
extends
\OPNsense\Base\IndexController
{
public
function
indexAction
()
{
$this
->
view
->
title
=
"Captive Portal / Sessions"
;
// choose template
$this
->
view
->
pick
(
'OPNsense/CaptivePortal/clients'
);
}
}
src/opnsense/mvc/app/views/OPNsense/CaptivePortal/clients.volt
0 → 100644
View file @
32ab2367
{#
OPNsense® is Copyright © 2014 – 2015 by Deciso B.V.
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.
#}
<script src="/ui/js/moment-with-locales.min.js" type="text/javascript"></script>
<script type="text/javascript">
$( document ).ready(function() {
/**
* update zone list
*/
function updateZones() {
ajaxGet(url="/api/captiveportal/session/zones/", sendData={}, callback=function(data, status) {
if (status == "success") {
$('#cp-zones').html("");
$.each(data, function(key, value) {
$('#cp-zones').append($("<option></option>").attr("value", key).text(value));
});
$('.selectpicker').selectpicker('refresh');
// link on change event
$('#cp-zones').on('change', function(){
loadSessions();
});
// initial load sessions
loadSessions();
}
});
}
/**
* load sessions for selected zone, hook events
*/
function loadSessions() {
var zoneid = $('#cp-zones').find("option:selected").val();
var gridopt = {
ajax: false,
selection: true,
multiSelect: true,
formatters: {
"commands": function (column, row) {
return "<button type=\"button\" class=\"btn btn-xs btn-default command-disconnect\" data-row-id=\"" + row.sessionid + "\"><span class=\"fa fa-trash-o\"></span></button>";
}
},
converters: {
// convert datetime type fields from unix timestamp to readable format
datetime: {
from: function (value) { return moment(parseInt(value)*1000); },
to: function (value) { return value.format("lll"); }
}
}
};
$("#grid-clients").bootgrid('destroy');
ajaxGet(url="/api/captiveportal/session/list/"+zoneid+"/", sendData={}, callback=function(data, status) {
if (status == "success") {
$("#grid-clients > tbody").html('');
$.each(data, function(key, value) {
var fields = ["sessionId", "userName", "macAddress", "ipAddress", "startTime"];
tr_str = '<tr>';
for (var i = 0; i < fields.length; i++) {
if (value[fields[i]] != null) {
tr_str += '<td>' + value[fields[i]] + '</td>';
} else {
tr_str += '<td></td>';
}
}
tr_str += '</tr>';
$("#grid-clients > tbody").append(tr_str);
});
// hook disconnect button
var grid_clients = $("#grid-clients").bootgrid(gridopt);
grid_clients.on("loaded.rs.jquery.bootgrid", function(){
grid_clients.find(".command-disconnect").on("click", function(e) {
var sessionId=$(this).data("row-id");
stdDialogRemoveItem('{{ lang._('Disconnect selected client?') }}',function() {
ajaxCall(url="/api/captiveportal/session/disconnect/" + zoneid + '/',
sendData={'sessionId': sessionId}, callback=function(data,status){
// reload grid after delete
loadSessions();
});
});
});
});
// hide actionBar on mobile
$('.actionBar').addClass('hidden-xs hidden-sm');
}
});
}
// init with first selected zone
updateZones();
});
</script>
<div class="content-box">
<div class="content-box-main">
<div class="table-responsive">
<div class="col-sm-12">
<div class="pull-right">
<select id="cp-zones" class="selectpicker" data-width="200px"></select>
<hr/>
</div>
</div>
<div>
<table id="grid-clients" class="table table-condensed table-hover table-striped table-responsive">
<thead>
<tr>
<th data-column-id="sessionid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('Session') }}</th>
<th data-column-id="userName" data-type="string">{{ lang._('userName') }}</th>
<th data-column-id="macAddress" data-type="string" data-css-class="hidden-xs hidden-sm" data-header-css-class="hidden-xs hidden-sm">{{ lang._('macAddress') }}</th>
<th data-column-id="ipAddress" data-type="string" data-css-class="hidden-xs hidden-sm" data-header-css-class="hidden-xs hidden-sm">{{ lang._('ipAddress') }}</th>
<th data-column-id="startTime" data-type="datetime">{{ lang._('connected since') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false"></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
</tfoot>
</table>
</div>
</div>
</div>
</div>
\ No newline at end of file
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