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
0fd14066
Commit
0fd14066
authored
Oct 12, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Captive portal) add expire voucher option, closes
https://github.com/opnsense/core/issues/899
parent
25d8428c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
VoucherController.php
...trollers/OPNsense/CaptivePortal/Api/VoucherController.php
+21
-0
Voucher.php
src/opnsense/mvc/app/library/OPNsense/Auth/Voucher.php
+20
-0
vouchers.volt
...nsense/mvc/app/views/OPNsense/CaptivePortal/vouchers.volt
+41
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/CaptivePortal/Api/VoucherController.php
View file @
0fd14066
...
...
@@ -150,4 +150,25 @@ class VoucherController extends ApiControllerBase
}
return
$response
;
}
/**
* expire a voucher
* @param string $provider auth provider
* @return array status
*/
public
function
expireVoucherAction
(
$provider
)
{
$response
=
array
(
"status"
=>
"error"
);
$username
=
$this
->
request
->
getPost
(
'username'
,
'string'
,
null
);
if
(
$this
->
request
->
isPost
()
&&
$username
!=
null
)
{
$authFactory
=
new
AuthenticationFactory
();
$auth
=
$authFactory
->
get
(
$provider
);
if
(
$auth
!=
null
&&
method_exists
(
$auth
,
'expireVoucher'
))
{
$auth
->
expireVoucher
(
$username
);
$response
[
'status'
]
=
'ok'
;
}
}
return
$response
;
}
}
src/opnsense/mvc/app/library/OPNsense/Auth/Voucher.php
View file @
0fd14066
...
...
@@ -325,6 +325,26 @@ class Voucher implements IAuthConnector
return
$response
;
}
/**
* expire voucher
* @param string $username username
*/
public
function
expireVoucher
(
$username
)
{
if
(
$this
->
dbHandle
!=
null
)
{
$stmt
=
$this
->
dbHandle
->
prepare
(
'
update vouchers
set validity = 0,
starttime = :starttime
where username = :username
'
);
$stmt
->
bindParam
(
':username'
,
$username
);
$starttime
=
time
();
$stmt
->
bindParam
(
':starttime'
,
$starttime
,
SQLITE3_INTEGER
);
$stmt
->
execute
();
}
}
/**
* drop expired vouchers in group
* @param $vouchergroup voucher group name
...
...
src/opnsense/mvc/app/views/OPNsense/CaptivePortal/vouchers.volt
View file @
0fd14066
...
...
@@ -249,6 +249,42 @@ POSSIBILITY OF SUCH DAMAGE.
}
});
/**
* Expire selected vouchers
*/
$("#expireVouchers").click(function(){
var voucher_provider = $('#voucher-providers').find("option:selected").val();
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: voucher_provider,
message: '{{ lang._('Expire all selected vouchers?') }}',
buttons: [{
icon: 'fa fa-trash-o',
label: '{{ lang._('Yes') }}',
cssClass: 'btn-primary',
action: function(dlg){
var rows =$("#grid-vouchers").bootgrid('getSelectedRows');
if (rows != undefined) {
var deferreds = [];
$.each(rows, function (key, username) {
deferreds.push(ajaxCall(url="/api/captiveportal/voucher/expireVoucher/" + voucher_provider + "/",
sendData={username:username}, null));
});
$.when.apply(null, deferreds).done(function(){
updateVoucherGroupList();
});
}
dlg.close();
}
}, {
label: 'Close',
action: function(dlg){
dlg.close();
}
}]
});
});
updateVoucherProviders();
$('.selectpicker').selectpicker('refresh');
});
...
...
@@ -289,6 +325,11 @@ POSSIBILITY OF SUCH DAMAGE.
<div class="row">
<div class="col-sm-12">
<div class="pull-right">
<button id="expireVouchers" type="button" class="btn btn-default">
<span>{{ lang._('Expire selected vouchers') }}</span>
<span class="fa fa-trash"></span>
</button>
<button id="dropExpired" type="button" class="btn btn-default">
<span>{{ lang._('Drop expired vouchers') }}</span>
<span class="fa fa-trash"></span>
...
...
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