Commit 85c2b81b authored by Ad Schellevis's avatar Ad Schellevis

(captive portal) add option "drop expired vouchers", closes...

(captive portal) add option "drop expired vouchers", closes https://github.com/opnsense/core/issues/977
parent 2b026db8
......@@ -105,6 +105,24 @@ class VoucherController extends ApiControllerBase
return array("status" => "error");
}
/**
* drop expired vouchers from group
* @param string $provider auth provider
* @param string $group group name
* @return array status
*/
public function dropExpiredVouchersAction($provider, $group)
{
if ($this->request->isPost()) {
$authFactory = new AuthenticationFactory();
$auth = $authFactory->get($provider);
if ($auth != null && method_exists($auth, 'dropExpired')) {
return array("status" => "drop", "count" => $auth->dropExpired($group));
}
}
return array("status" => "error");
}
/**
* generate new vouchers
......
......@@ -307,6 +307,28 @@ class Voucher implements IAuthConnector
return $response;
}
/**
* drop vouchers in group
* @param $vouchergroup voucher group name
* @return int number of deleted vouchers
*/
public function dropExpired($vouchergroup)
{
$stmt = $this->dbHandle->prepare('
delete
from vouchers
where vouchergroup = :vouchergroup
and starttime is not null
and starttime + validity < :endtime
');
$stmt->bindParam(':vouchergroup', $vouchergroup);
$endtime = time();
$stmt->bindParam(':endtime', $endtime, SQLITE3_INTEGER);
$stmt->execute();
return $this->dbHandle->changes();
}
/**
* return session info
* @return array mixed named list of authentication properties
......
......@@ -219,6 +219,36 @@ POSSIBILITY OF SUCH DAMAGE.
});
$("#dropExpired").click(function(){
var voucher_group = $('#voucher-groups').find("option:selected").val();
var voucher_provider = $('#voucher-providers').find("option:selected").val();
if (voucher_group != undefined) {
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: '{{ lang._('Remove expired vouchers') }} "' + voucher_group + '" @ ' + voucher_provider,
message: '{{ lang._('All expired vouchers within this group will be deleted') }}',
buttons: [{
icon: 'fa fa-trash-o',
label: '{{ lang._('Yes') }}',
cssClass: 'btn-primary',
action: function(dlg){
ajaxCall(url="/api/captiveportal/voucher/dropExpiredVouchers/" + voucher_provider + "/" + voucher_group + '/',
sendData={}, callback=function(data,status){
// reload grid after delete
updateVoucherGroupList();
});
dlg.close();
}
}, {
label: 'Close',
action: function(dlg){
dlg.close();
}
}]
});
}
});
updateVoucherProviders();
$('.selectpicker').selectpicker('refresh');
});
......@@ -259,6 +289,11 @@ POSSIBILITY OF SUCH DAMAGE.
<div class="row">
<div class="col-sm-12">
<div class="pull-right">
<button id="dropExpired" type="button" class="btn btn-default">
<span>{{ lang._('Drop expired vouchers') }}</span>
<span class="fa fa-trash"></span>
</button>
<button id="showVoucherModal" type="button" class="btn btn-default">
<span>{{ lang._('Create vouchers') }}</span>
<span class="fa fa-ticket"></span>
......
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