diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 2ac68ec8e..df2b884a9 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -2770,8 +2770,7 @@ class EventsController extends AppController // write $attachments_dir = Configure::read('MISP.attachments_dir'); if (empty($attachments_dir)) { - $this->loadModel('Server'); - $attachments_dir = $this->Server->getDefaultAttachments_dir(); + $attachments_dir = $this->Event->getDefaultAttachments_dir(); } $rootDir = $attachments_dir . DS . $id . DS; App::uses('Folder', 'Utility'); diff --git a/app/Controller/ShadowAttributesController.php b/app/Controller/ShadowAttributesController.php index 773087d8f..176424599 100644 --- a/app/Controller/ShadowAttributesController.php +++ b/app/Controller/ShadowAttributesController.php @@ -201,8 +201,7 @@ class ShadowAttributesController extends AppController { $attachments_dir = Configure::read('MISP.attachments_dir'); if (empty($attachments_dir)) { - $my_server = ClassRegistry::init('Server'); - $attachments_dir = $my_server->getDefaultAttachments_dir(); + $attachments_dir = $this->ShadowAttribute->getDefaultAttachments_dir(); } $pathOld = $attachments_dir . DS . 'shadow' . DS . $shadowId; $pathNew = $attachments_dir . DS . $newId; @@ -506,8 +505,7 @@ class ShadowAttributesController extends AppController { $attachments_dir = Configure::read('MISP.attachments_dir'); if (empty($attachments_dir)) { - $my_server = ClassRegistry::init('Server'); - $attachments_dir = $my_server->getDefaultAttachments_dir(); + $attachments_dir = $this->ShadowAttribute->getDefaultAttachments_dir(); } $path = $attachments_dir . DS . 'shadow' . DS . $shadowAttribute['event_id'] . DS; $file = $shadowAttribute['id']; diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index 009245a5f..198e12e5d 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -1793,4 +1793,14 @@ class AppModel extends Model } return $val / (1024 * 1024); } + + public function getDefaultAttachments_dir() + { + return APP . 'files'; + } + + public function getDefaultTmp_dir() + { + return sys_get_temp_dir(); + } } diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index b37444a48..50185771a 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -675,8 +675,7 @@ class Attribute extends AppModel // only delete the file if it exists $attachments_dir = Configure::read('MISP.attachments_dir'); if (empty($attachments_dir)) { - $my_server = ClassRegistry::init('Server'); - $attachments_dir = $my_server->getDefaultAttachments_dir(); + $attachments_dir = $this->getDefaultAttachments_dir(); } // Special case - If using S3, we have to delete from there @@ -1531,8 +1530,7 @@ class Attribute extends AppModel { $attachments_dir = Configure::read('MISP.attachments_dir'); if (empty($attachments_dir)) { - $my_server = ClassRegistry::init('Server'); - $attachments_dir = $my_server->getDefaultAttachments_dir(); + $attachments_dir = $this->getDefaultAttachments_dir(); } if ($this->attachmentDirIsS3()) { @@ -1557,8 +1555,7 @@ class Attribute extends AppModel { $attachments_dir = Configure::read('MISP.attachments_dir'); if (empty($attachments_dir)) { - $my_server = ClassRegistry::init('Server'); - $attachments_dir = $my_server->getDefaultAttachments_dir(); + $attachments_dir = $this->getDefaultAttachments_dir(); } if ($this->attachmentDirIsS3()) { @@ -2993,8 +2990,7 @@ class Attribute extends AppModel } $attachments_dir = Configure::read('MISP.attachments_dir'); if (empty($attachments_dir)) { - $my_server = ClassRegistry::init('Server'); - $attachments_dir = $my_server->getDefaultAttachments_dir(); + $attachments_dir = $this->getDefaultAttachments_dir(); } // If we've set attachments to S3, we can't write there @@ -3003,8 +2999,7 @@ class Attribute extends AppModel // Sometimes it's not set? if (empty($attachments_dir)) { // Get a default tmpdir - $my_server = ClassRegistry::init('Server'); - $attachments_dir = $my_server->getDefaultTmp_dir(); + $attachments_dir = $this->getDefaultTmp_dir(); } } diff --git a/app/Model/Server.php b/app/Model/Server.php index 2c822d0cb..ae96380bf 100644 --- a/app/Model/Server.php +++ b/app/Model/Server.php @@ -2051,7 +2051,7 @@ class Server extends AppModel 'action' => 'pull', 'user_id' => $user['id'], 'title' => 'Failed to pull event #' . $eventid . '.', - 'change' => 'Reason:' . $message + 'change' => 'Reason:' . $message )); } } @@ -4142,16 +4142,6 @@ class Server extends AppModel return $final; } - public function getDefaultAttachments_dir() - { - return APP . 'files'; - } - - public function getDefaultTmp_dir() - { - return sys_get_temp_dir(); - } - public function fetchServer($id) { if (empty($id)) {