mirror of https://github.com/MISP/MISP
new: Added a way to disable cached exports server wide for low disk space instnaces
- But please consider just adding some more space instead..pull/2019/head
parent
e79ba76c43
commit
62cb2b66b6
|
@ -1649,7 +1649,7 @@ class EventsController extends AppController {
|
|||
$filesize_units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
if ($this->_isSiteAdmin()) $this->Session->setFlash('Warning, you are logged in as a site admin, any export that you generate will contain the FULL UNRESTRICTED data-set. If you would like to generate an export for your own organisation, please log in with a different user.');
|
||||
// Check if the background jobs are enabled - if not, fall back to old export page.
|
||||
if (Configure::read('MISP.background_jobs')) {
|
||||
if (Configure::read('MISP.background_jobs') && !Configure::read('MISP.disable_cached_exports')) {
|
||||
$now = time();
|
||||
|
||||
// as a site admin we'll use the ADMIN identifier, not to overwrite the cached files of our own org with a file that includes too much data.
|
||||
|
@ -1746,6 +1746,9 @@ class EventsController extends AppController {
|
|||
}
|
||||
|
||||
public function downloadExport($type, $extra = null) {
|
||||
if (Configure::read('MISP.disable_cached_exports')) {
|
||||
throw new MethodNotAllowedException('This feature is currently disabled');
|
||||
}
|
||||
if ($this->_isSiteAdmin()) $org = 'ADMIN';
|
||||
else $org = $this->Auth->user('Organisation')['name'];
|
||||
$this->autoRender = false;
|
||||
|
|
|
@ -101,6 +101,9 @@ class JobsController extends AppController {
|
|||
}
|
||||
|
||||
public function cache($type) {
|
||||
if (Configure::read('MISP.disable_cached_exports')) {
|
||||
throw new MethodNotAllowedException('This feature is currently disabled');
|
||||
}
|
||||
if ($this->_isSiteAdmin()) {
|
||||
$target = 'All events.';
|
||||
} else {
|
||||
|
|
|
@ -161,6 +161,16 @@ class Server extends AppModel {
|
|||
'test' => 'testForEmpty',
|
||||
'type' => 'string',
|
||||
),
|
||||
'disable_cached_exports' => array(
|
||||
'level' => 1,
|
||||
'description' => 'Cached exports can take up a considerable amount of space and can be disabled instance wide using this setting. Disabling the cached exports is not recommended as it\'s a valuable feature, however, if your server is having free space issues it might make sense to take this step.',
|
||||
'value' => false,
|
||||
'null' => true,
|
||||
'errorMessage' => '',
|
||||
'test' => 'testDisableCache',
|
||||
'type' => 'boolean',
|
||||
'afterHook' => 'disableCacheAfterHook',
|
||||
),
|
||||
'header' => array(
|
||||
'level' => 3,
|
||||
'description' => 'This setting is deprecated and can be safely removed.',
|
||||
|
@ -2173,6 +2183,11 @@ class Server extends AppModel {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function testDisableCache($value) {
|
||||
if (isset($value) && $value) return 'Export caches are disabled.';
|
||||
return true;
|
||||
}
|
||||
|
||||
public function testLive($value) {
|
||||
if ($this->testBool($value) !== true) return $this->testBool($value);
|
||||
if (!$value) return 'MISP disabled.';
|
||||
|
@ -2310,6 +2325,29 @@ class Server extends AppModel {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function disableCacheAfterHook($setting, $value) {
|
||||
if ($value) {
|
||||
$this->Event = ClassRegistry::init('Event');
|
||||
App::uses('Folder', 'Utility');
|
||||
App::uses('File', 'Utility');
|
||||
// delete all cache files
|
||||
foreach ($this->Event->export_types as $type => $settings) {
|
||||
$dir = new Folder(APP . 'tmp/cached_exports/' . $type);
|
||||
// No caches created for this type of export, move on
|
||||
if ($dir == null) {
|
||||
continue;
|
||||
}
|
||||
$files = $dir->find('.*' . $settings['extension']);
|
||||
foreach ($files as $file) {
|
||||
$file = new File($dir->pwd() . DS . $file);
|
||||
$file->delete();
|
||||
$file->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function correlationAfterHook($setting, $value) {
|
||||
if (!Configure::read('MISP.background_jobs')) {
|
||||
$this->Attribute = ClassRegistry::init('Attribute');
|
||||
|
|
Loading…
Reference in New Issue