diff --git a/.gitignore b/.gitignore index faeac35ce..daf7ef0f2 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ !/app/files/scripts/tmp/empty /app/tmp/files/* !/app/files/empty +!/app/files/terms +/app/files/terms/* +!/app/files/terms/empty /app/webroot/img/logo.png /app/Config/bootstrap.php /app/Config/database.php diff --git a/VERSION.json b/VERSION.json index 2c9763e50..840261a76 100644 --- a/VERSION.json +++ b/VERSION.json @@ -1 +1 @@ -{"major":2, "minor":3, "hotfix":16} \ No newline at end of file +{"major":2, "minor":3, "hotfix":17} \ No newline at end of file diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php index 79d32bcb9..0860e83b0 100755 --- a/app/Controller/UsersController.php +++ b/app/Controller/UsersController.php @@ -700,6 +700,16 @@ class UsersController extends AppController { } $this->set('termsaccepted', $this->Auth->user('termsaccepted')); } + + public function downloadTerms() { + if (!Configure::read('MISP.terms_file')) { + $termsFile = APP ."View/Users/terms"; + } else { + $termsFile = APP . 'files' . DS . 'terms' . DS . Configure::read('MISP.terms_file'); + } + $this->response->file($termsFile, array('download' => true, 'name' => Configure::read('MISP.terms_file'))); + return $this->response; + } public function news() { $this->User->id = $this->Auth->user('id'); diff --git a/app/Model/Server.php b/app/Model/Server.php index ab4bd95ab..d18b4f13f 100755 --- a/app/Model/Server.php +++ b/app/Model/Server.php @@ -357,6 +357,22 @@ class Server extends AppModel { 'test' => 'testBool', 'type' => 'boolean', ), + 'terms_download' => array( + 'level' => 2, + 'description' => 'Choose whether the terms and conditions should be displayed inline (false) or offered as a download (true)', + 'value' => '', + 'errorMessage' => '', + 'test' => 'testBool', + 'type' => 'boolean' + ), + 'terms_file' => array( + 'level' => 2, + 'description' => 'The filename of the terms and conditions file. Make sure that the file is located in your MISP/app/files/terms directory', + 'value' => '', + 'errorMessage' => '', + 'test' => 'testForTermsFile', + 'type' => 'string' + ), ), 'GnuPG' => array( 'branch' => 1, @@ -934,6 +950,21 @@ class Server extends AppModel { return true; } + public function testForTermsFile($value) { + return $this->__testForFile($value, APP . 'files' . DS . 'terms'); + } + + + // never come here directly, always go through a secondary check like testForTermsFile in order to also pass along the expected file path + private function __testForFile($value, $path) { + if ($this->testForEmpty($value) !== true) return $this->testForEmpty($value); + if (!preg_match('/^[\w,\s-]+(\.)?[A-Za-z0-9]+$/', $value)) return 'Invalid filename. Valid filenames can only include characters between a-z, A-Z or 0-9. They can also include - and _ and can optionally have an extension.'; + $file = $path . DS . $value; + if (!file_exists($file)) return 'Could not find the specified file. Make sure that it is uploaded into the following directory: ' . $path; + return true; + } + + public function serverSettingsSaveValue($setting, $value) { Configure::write($setting, $value); Configure::dump('config.php', 'default', array('MISP', 'GnuPG', 'SecureAuth', 'Security', 'debug')); diff --git a/app/View/Users/terms.ctp b/app/View/Users/terms.ctp index f1ff486dc..01d2dc598 100644 --- a/app/View/Users/terms.ctp +++ b/app/View/Users/terms.ctp @@ -1,24 +1,25 @@

MISP Terms and Conditions

- Please add your terms and conditions in file $termsFile.

"; -}else { - $terms = new File($termsFile, false); - echo $terms->read(true,'r'); - $terms->close(); -} -?> - -Form->create('User'); - echo $this->Form->hidden('termsaccepted', array('default' => '1')); - echo $this->Form->end(__('Accept Terms', true)); -} + $embedableExtensions = array('pdf'); + if (!Configure::read('MISP.terms_file')) { + $termsFile = APP ."View/Users/terms"; + } else { + $termsFile = APP . 'files' . DS . 'terms' . DS . Configure::read('MISP.terms_file'); + } + if (!(file_exists($termsFile))) { + echo "

Terms and Conditions file not found.

"; + } else { + if (!Configure::read('MISP.terms_download')) { + $terms = new File($termsFile, false); + echo $terms->read(true,'r'); + $terms->close(); + } else { + ?> + Download Terms and Conditions +