mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-07-18 10:46:29 +00:00
[Web] server-side search for syncjob datatable
This commit is contained in:
@@ -2150,7 +2150,7 @@ jQuery(function($){
|
|||||||
var table = $('#sync_job_table').DataTable({
|
var table = $('#sync_job_table').DataTable({
|
||||||
responsive: true,
|
responsive: true,
|
||||||
processing: true,
|
processing: true,
|
||||||
serverSide: false,
|
serverSide: true,
|
||||||
stateSave: true,
|
stateSave: true,
|
||||||
pageLength: pagination_size,
|
pageLength: pagination_size,
|
||||||
dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
|
dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
|
||||||
@@ -2162,10 +2162,15 @@ jQuery(function($){
|
|||||||
hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
|
hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
|
||||||
},
|
},
|
||||||
ajax: {
|
ajax: {
|
||||||
type: "GET",
|
type: "POST",
|
||||||
url: "/api/v1/get/syncjobs/all/no_log",
|
url: "/api/v1/search/syncjob",
|
||||||
|
contentType: "application/json",
|
||||||
|
processData: false,
|
||||||
|
data: function(d) {
|
||||||
|
return JSON.stringify(d);
|
||||||
|
},
|
||||||
dataSrc: function(json){
|
dataSrc: function(json){
|
||||||
$.each(json, function (i, item) {
|
$.each(json.data, function (i, item) {
|
||||||
item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
|
item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
|
||||||
item.user2 = escapeHtml(item.user2);
|
item.user2 = escapeHtml(item.user2);
|
||||||
if (!item.exclude > 0) {
|
if (!item.exclude > 0) {
|
||||||
@@ -2201,7 +2206,7 @@ jQuery(function($){
|
|||||||
item.exit_status = item.success + ' ' + item.exit_status;
|
item.exit_status = item.success + ' ' + item.exit_status;
|
||||||
});
|
});
|
||||||
|
|
||||||
return json;
|
return json.data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
columns: [
|
columns: [
|
||||||
@@ -2225,6 +2230,7 @@ jQuery(function($){
|
|||||||
{
|
{
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
data: 'id',
|
data: 'id',
|
||||||
|
searchable: false,
|
||||||
responsivePriority: 3,
|
responsivePriority: 3,
|
||||||
defaultContent: ''
|
defaultContent: ''
|
||||||
},
|
},
|
||||||
@@ -2242,21 +2248,27 @@ jQuery(function($){
|
|||||||
{
|
{
|
||||||
title: lang.last_run,
|
title: lang.last_run,
|
||||||
data: 'last_run',
|
data: 'last_run',
|
||||||
|
searchable: false,
|
||||||
defaultContent: ''
|
defaultContent: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: lang.syncjob_last_run_result,
|
title: lang.syncjob_last_run_result,
|
||||||
data: 'exit_status',
|
data: 'exit_status',
|
||||||
|
searchable: false,
|
||||||
|
orderable: false,
|
||||||
defaultContent: ''
|
defaultContent: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Log',
|
title: 'Log',
|
||||||
data: 'log',
|
data: 'log',
|
||||||
|
searchable: false,
|
||||||
|
orderable: false,
|
||||||
defaultContent: ''
|
defaultContent: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: lang.active,
|
title: lang.active,
|
||||||
data: 'active',
|
data: 'active',
|
||||||
|
searchable: false,
|
||||||
defaultContent: '',
|
defaultContent: '',
|
||||||
render: function (data, type) {
|
render: function (data, type) {
|
||||||
return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
|
return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
|
||||||
@@ -2265,23 +2277,31 @@ jQuery(function($){
|
|||||||
{
|
{
|
||||||
title: lang.status,
|
title: lang.status,
|
||||||
data: 'is_running',
|
data: 'is_running',
|
||||||
|
searchable: false,
|
||||||
|
orderable: false,
|
||||||
defaultContent: ''
|
defaultContent: ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: lang.excludes,
|
title: lang.excludes,
|
||||||
data: 'exclude',
|
data: 'exclude',
|
||||||
|
searchable: false,
|
||||||
|
orderable: false,
|
||||||
defaultContent: '',
|
defaultContent: '',
|
||||||
className: 'none'
|
className: 'none'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: lang.mins_interval,
|
title: lang.mins_interval,
|
||||||
data: 'mins_interval',
|
data: 'mins_interval',
|
||||||
|
searchable: false,
|
||||||
|
orderable: false,
|
||||||
defaultContent: '',
|
defaultContent: '',
|
||||||
className: 'none'
|
className: 'none'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: lang.action,
|
title: lang.action,
|
||||||
data: 'action',
|
data: 'action',
|
||||||
|
searchable: false,
|
||||||
|
orderable: false,
|
||||||
className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
|
className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
|
||||||
responsivePriority: 5,
|
responsivePriority: 5,
|
||||||
defaultContent: ''
|
defaultContent: ''
|
||||||
|
|||||||
@@ -1676,6 +1676,55 @@ if (isset($_GET['query'])) {
|
|||||||
process_search_return($data);
|
process_search_return($data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "syncjob":
|
||||||
|
$table = ['imapsync', 'i'];
|
||||||
|
$primaryKey = 'id';
|
||||||
|
$columns = [
|
||||||
|
['db' => 'id', 'dt' => 2],
|
||||||
|
['db' => 'user2', 'dt' => 3],
|
||||||
|
['db' => 'host1', 'dt' => 4, 'search' => ['where_column' => "CONCAT_WS(' ', `i`.`user1`, `i`.`host1`)"]],
|
||||||
|
['db' => 'last_run', 'dt' => 5],
|
||||||
|
['db' => 'active', 'dt' => 8],
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($_SESSION['mailcow_cc_role'] === 'admin') {
|
||||||
|
$data = SSP::simple($requestDecoded, $pdo, $table, $primaryKey, $columns);
|
||||||
|
} elseif ($_SESSION['mailcow_cc_role'] === 'domainadmin') {
|
||||||
|
$data = SSP::complex($requestDecoded, $pdo, $table, $primaryKey, $columns,
|
||||||
|
'INNER JOIN `mailbox` AS `mb` ON `mb`.`username` = `i`.`user2` ' .
|
||||||
|
'INNER JOIN `domain_admins` AS `da` ON `da`.`domain` = `mb`.`domain`',
|
||||||
|
[
|
||||||
|
'condition' => '`da`.`active` = 1 AND `da`.`username` = :username',
|
||||||
|
'bindings' => ['username' => $_SESSION['mailcow_cc_username']]
|
||||||
|
]);
|
||||||
|
} elseif ($_SESSION['mailcow_cc_role'] === 'user') {
|
||||||
|
$data = SSP::complex($requestDecoded, $pdo, $table, $primaryKey, $columns, null,
|
||||||
|
[
|
||||||
|
'condition' => '`i`.`user2` = :username',
|
||||||
|
'bindings' => ['username' => $_SESSION['mailcow_cc_username']]
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode(array(
|
||||||
|
'type' => 'error',
|
||||||
|
'msg' => 'Insufficient permissions'
|
||||||
|
));
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['data'])) {
|
||||||
|
$syncjobData = [];
|
||||||
|
foreach ($data['data'] as $row) {
|
||||||
|
if ($details = mailbox('get', 'syncjob_details', $row[2], array('no_log'))) {
|
||||||
|
$syncjobData[] = $details;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data['data'] = $syncjobData;
|
||||||
|
}
|
||||||
|
|
||||||
|
process_search_return($data);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
|
|||||||
Reference in New Issue
Block a user