new: Mass enable/disable feeds

- protecting the sanity of MISP admins since 2012!
pull/2831/head
iglocska 2018-01-15 17:25:11 +01:00
parent 0b99498f67
commit dedfea3610
6 changed files with 93 additions and 6 deletions

View File

@ -46,7 +46,7 @@ class AppController extends Controller {
public $helpers = array('Utility');
private $__queryVersion = '27';
private $__queryVersion = '28';
public $pyMispVersion = '2.4.85';
public $phpmin = '5.6.5';
public $phprec = '7.0.16';

View File

@ -153,6 +153,7 @@ class ACLComponent extends Component {
'index' => array(),
'previewEvent' => array(),
'previewIndex' => array(),
'toggleSelected' => array('perm_site_admin'),
'view' => array(),
),
'galaxies' => array(

View File

@ -632,4 +632,40 @@ class FeedsController extends AppController {
$this->set('feeds', $feeds);
}
}
public function toggleSelected($enable = false, $feedList = false) {
if (!empty($enable)) $enable = 1;
else $enable = 0;
try {
$feedIds = json_decode($feedList, true);
} catch (Exception $e) {
$this->Session->setFlash('Invalid feed list received.');
$this->redirect(array('controller' => 'feeds', 'action' => 'index'));
}
if ($this->request->is('post')) {
$feeds = $this->Feed->find('all', array(
'conditions' => array('Feed.id' => $feedIds),
'recursive' => -1
));
$count = 0;
foreach ($feeds as $feed) {
if ($feed['Feed']['enabled'] != $enable) {
$feed['Feed']['enabled'] = $enable;
$this->Feed->save($feed);
$count++;
}
}
if ($count > 0) {
$this->Session->setFlash($count . ' feeds ' . array('disabled', 'enabled')[$enable] . '.');
$this->redirect(array('controller' => 'feeds', 'action' => 'index'));
} else {
$this->Session->setFlash('All selected feeds are already ' . array('disabled', 'enabled')[$enable] . ', nothing to update.');
$this->redirect(array('controller' => 'feeds', 'action' => 'index'));
}
} else {
$this->set('feedList', $feedList);
$this->set('enable', $enable);
$this->render('ajax/feedToggleConfirmation');
}
}
}

View File

@ -240,7 +240,7 @@
<script type="text/javascript">
$(document).ready(function() {
$('.select').on('change', function() {
eventListCheckboxesChecked();
listCheckboxesChecked();
});
});
</script>

View File

@ -23,6 +23,8 @@
</ul>
</div>
<div class="tabMenuFixedContainer" style="display:inline-block;">
<span id="multi-delete-button" role="button" tabindex="0" aria-label="Default feeds filter" title="Default feeds" class=" hidden tabMenuFixed mass-select tabMenuFixedCenter tabMenuSides useCursorPointer <?php echo $scope == 'default' ? 'tabMenuActive' : ''; ?>" onClick="multiSelectToggleFeeds(1);">Enable Selected</span>
<span id="multi-delete-button" role="button" tabindex="0" aria-label="Default feeds filter" title="Default feeds" class=" hidden tabMenuFixed mass-select tabMenuFixedCenter tabMenuSides useCursorPointer <?php echo $scope == 'default' ? 'tabMenuActive' : ''; ?>" onClick="multiSelectToggleFeeds(0);">Disable Selected</span>
<span role="button" tabindex="0" aria-label="Default feeds filter" title="Default feeds" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer <?php echo $scope == 'default' ? 'tabMenuActive' : ''; ?>" onclick="window.location='/feeds/index/scope:default'">Default feeds</span>
<span role="button" tabindex="0" aria-label="Custom feeds filter" title="Custom feeds" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer <?php echo $scope == 'custom' ? 'tabMenuActive' : ''; ?> " onclick="window.location='/feeds/index/scope:custom'">Custom Feeds</span>
<span role="button" tabindex="0" aria-label="All feeds" title="All feeds" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer <?php echo $scope == 'all' ? 'tabMenuActive' : ''; ?> " onclick="window.location='/feeds/index/scope:all'">All Feeds</span>
@ -30,7 +32,15 @@
</div>
<table class="table table-striped table-hover table-condensed">
<tr>
<?php if ($isSiteAdmin): ?>
<th>
<input class="select_all select" type="checkbox" title="Select all" role="button" tabindex="0" aria-label="Select all eventson current page" onClick="toggleAllCheckboxes();" />&nbsp;
</th>
<?php else: ?>
<th style="padding-left:0px;padding-right:0px;">&nbsp;</th>
<?php endif;?>
<th><?php echo $this->Paginator->sort('id');?></th>
<th><?php echo $this->Paginator->sort('enabled');?></th>
<th><?php echo $this->Paginator->sort('name');?></th>
<th><?php echo $this->Paginator->sort('source_format', 'Feed Format');?></th>
<th><?php echo $this->Paginator->sort('provider');?></th>
@ -42,7 +52,6 @@
<th>Override IDS</th>
<th><?php echo $this->Paginator->sort('distribution');?></th>
<th><?php echo $this->Paginator->sort('tag');?></th>
<th><?php echo $this->Paginator->sort('enabled');?></th>
<th><?php echo $this->Paginator->sort('lookup_visible');?></th>
<th class="actions"><?php echo __('Caching');?></th>
<th class="actions"><?php echo __('Actions');?></th>
@ -70,7 +79,30 @@ foreach ($feeds as $item):
}
?>
<tr>
<?php
if ($isSiteAdmin):
?>
<td style="width:10px;" data-id="<?php echo h($item['Feed']['id']); ?>">
<input class="select" type="checkbox" data-id="<?php echo $item['Feed']['id'];?>" />
</td>
<?php
else:
?>
<td style="padding-left:0px;padding-right:0px;"></td>
<?php
endif;
?>
<td class="short"><?php echo h($item['Feed']['id']); ?>&nbsp;</td>
<td class="short">
<span class="<?php echo ($item['Feed']['enabled'] ? 'icon-ok' : 'icon-remove'); ?>"></span>
<span
class="short <?php if (!$item['Feed']['enabled'] || empty($ruleDescription)) echo "hidden"; ?>"
data-toggle="popover"
title="Filter rules"
data-content="<?php echo $ruleDescription; ?>"
>
(Rules)
</span>
<td>
<?php
echo h($item['Feed']['name']);
@ -135,8 +167,7 @@ foreach ($feeds as $item):
&nbsp;
<?php endif;?>
</td>
<td class="short"><span class="<?php echo ($item['Feed']['enabled'] ? 'icon-ok' : 'icon-remove'); ?>"></span><span class="short <?php if (!$item['Feed']['enabled'] || empty($ruleDescription)) echo "hidden"; ?>" data-toggle="popover" title="Filter rules" data-content="<?php echo $ruleDescription; ?>"> (Rules)</span>
<td class="short"><span class="<?php echo ($item['Feed']['lookup_visible'] ? 'icon-ok' : 'icon-remove'); ?>"></span>
<td class="short"><span class="<?php echo ($item['Feed']['lookup_visible'] ? 'icon-ok' : 'icon-remove'); ?>"></span>
<td class="short action-links <?php echo !empty($item['Feed']['cache_timestamp']) ? 'bold' : 'bold red';?>">
<?php
if (!empty($item['Feed']['cache_timestamp'])):
@ -197,6 +228,9 @@ endforeach; ?>
<script type="text/javascript">
$(document).ready(function(){
popoverStartup();
$('.select').on('change', function() {
listCheckboxesChecked();
});
});
</script>
<?php

View File

@ -600,7 +600,7 @@ function attributeListAnyAttributeCheckBoxesChecked() {
else $('.mass-select').addClass('hidden');
}
function eventListCheckboxesChecked() {
function listCheckboxesChecked() {
if ($('.select:checked').length > 0) $('.mass-select').removeClass('hidden');
else $('.mass-select').addClass('hidden');
}
@ -631,6 +631,22 @@ function multiSelectDeleteEvents() {
});
}
function multiSelectToggleFeeds(on) {
var selected = [];
$(".select").each(function() {
if ($(this).is(":checked")) {
var temp = $(this).data("id");
if (temp != null) {
selected.push(temp);
}
}
});
$.get("/feeds/toggleSelected/" + on + "/" + JSON.stringify(selected), function(data) {
$("#confirmation_box").html(data);
openPopup("#confirmation_box");
});
}
function multiSelectAction(event, context) {
var settings = {
deleteAttributes: {