EncryptedContentController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. namespace Kanboard\Plugin\EncryptedContent\Controller;
  3. use Kanboard\Controller\BaseController;
  4. use Kanboard\Plugin\EncryptedContent\Model\EncryptedContentModel;
  5. /**
  6. *
  7. * @author Valentino Pesce
  8. *
  9. */
  10. class EncryptedContentController extends BaseController
  11. {
  12. public function noHTTPS()
  13. {
  14. $project = $this->getProject();
  15. $task = $this->getTask();
  16. $this->response->html($this->helper->layout->task('EncryptedContent:task/nohttps',
  17. [ 'form_headline' => t('This feature requires the use of an SSL certificate on the server'),
  18. 'task' => $task,
  19. 'project' => $project,
  20. ]
  21. )
  22. );
  23. }
  24. public function task()
  25. {
  26. $project = $this->getProject();
  27. $task = $this->getTask();
  28. $metadata = $this->encryptedContentModel->getAll($task['id']);
  29. $this->response->html($this->helper->layout->task('EncryptedContent:task/metadata',
  30. ['title' => t('Encrypted Content'),
  31. 'task' => $task,
  32. 'add_form' => true,
  33. 'project' => $project,
  34. 'metadata' => $metadata,
  35. ]
  36. )
  37. );
  38. }
  39. public function saveTask()
  40. {
  41. $task = $this->getTask();
  42. $values = $this->request->getValues();
  43. $encrypt = $this->helper->EncryptedContentHelper->EncryptedValue($values['value']);
  44. $this->encryptedContentModel->save($task['id'], [$encrypt]);
  45. $this->flash->success(t('Content created successfully'));
  46. return $this->response->redirect($this->helper->url->to('EncryptedContentController', 'task', ['plugin' => 'encryptedContent', 'task_id' => $task['id'], 'project_id' => $task['project_id']]), true);
  47. }
  48. public function updateTask()
  49. {
  50. $task = $this->getTask();
  51. $values = $this->request->getValues();
  52. $encrypt = $this->helper->EncryptedContentHelper->EncryptedValue($values['value']);
  53. $this->encryptedContentModel->save($task['id'], [$values['name'] => $encrypt]);
  54. $this->flash->success(t('Content updated successfully'));
  55. return $this->response->redirect($this->helper->url->to('EncryptedContentController', 'task', ['plugin' => 'encryptedContent', 'task_id' => $task['id'], 'project_id' => $task['project_id']]), true);
  56. }
  57. public function unlockTask()
  58. {
  59. $project = $this->getProject();
  60. $task = $this->getTask();
  61. $name = $this->request->getStringParam('name');
  62. $key = $this->request->getStringParam('key');
  63. $metadata = $this->encryptedContentModel->get($task['id'], $name);
  64. $this->response->html($this->template->render('encryptedContent:task/formunlock',
  65. [
  66. 'project' => $project,
  67. 'task' => $task,
  68. 'form_headline' => t('Unlock Encrypted Content'),
  69. 'values' => ['name' => $name, 'key' => $key, 'value' => $metadata],
  70. ]
  71. )
  72. );
  73. }
  74. public function decryptTask()
  75. {
  76. $project = $this->getProject();
  77. $task = $this->getTask();
  78. $values = $this->request->getValues();
  79. $metadata = $this->encryptedContentModel->get($task['id'], $values['name']);
  80. $this->response->html($this->template->render('encryptedContent:task/decryptcontent',
  81. [
  82. 'project' => $project,
  83. 'task' => $task,
  84. 'form_headline' => t('Content decrypt'),
  85. 'values' => ['name' => $values['name'], 'key' => $values['key'], 'value' => $metadata],
  86. ]
  87. )
  88. );
  89. }
  90. public function unlockEditTask()
  91. {
  92. $project = $this->getProject();
  93. $task = $this->getTask();
  94. $name = $this->request->getStringParam('name');
  95. $key = $this->request->getStringParam('key');
  96. $metadata = $this->encryptedContentModel->get($task['id'], $name);
  97. $this->response->html($this->template->render('encryptedContent:task/formunlockedit',
  98. [
  99. 'project' => $project,
  100. 'task' => $task,
  101. 'form_headline' => t('Unlock Encrypted Content'),
  102. 'values' => ['name' => $name, 'key' => $key, 'value' => $metadata],
  103. ]
  104. )
  105. );
  106. }
  107. public function editTask()
  108. {
  109. $project = $this->getProject();
  110. $task = $this->getTask();
  111. $values = $this->request->getValues();
  112. $metadata = $this->encryptedContentModel->get($task['id'], $values['name']);
  113. $this->response->html($this->template->render('encryptedContent:task/form',
  114. [
  115. 'project' => $project,
  116. 'task' => $task,
  117. 'form_headline' => t('Edit Encrypted Content'),
  118. 'values' => ['name' => $values['name'], 'key' => $values['key'], 'value' => $metadata],
  119. ]
  120. )
  121. );
  122. }
  123. public function removeTask()
  124. {
  125. $task = $this->getTask();
  126. $name = $this->request->getStringParam('name');
  127. if ($this->encryptedContentModel->remove($task['id'], $name)) {
  128. $this->flash->success(t('Content removed successfully'));
  129. } else {
  130. $this->flash->failure(t('Unable to remove'));
  131. }
  132. return $this->response->redirect($this->helper->url->to('EncryptedContentController', 'task', ['plugin' => 'encryptedContent', 'task_id' => $task['id'], 'project_id' => $task['project_id']]), true);
  133. }
  134. public function confirmTask()
  135. {
  136. $project = $this->getProject();
  137. $task = $this->getTask();
  138. $name = $this->request->getStringParam('name');
  139. $this->response->html($this->template->render('encryptedContent:task/remove',
  140. [
  141. 'task' => $task,
  142. 'project' => $project,
  143. 'name' => $name,
  144. ]
  145. )
  146. );
  147. }
  148. public function removeAllTask()
  149. {
  150. $task = $this->getTask();
  151. if ($this->encryptedContentModel->removeAll($task['id'])) {
  152. $this->flash->success(t('Content removed successfully'));
  153. } else {
  154. $this->flash->failure(t('Unable to remove'));
  155. }
  156. return $this->response->redirect($this->helper->url->to('EncryptedContentController', 'task', ['plugin' => 'encryptedContent', 'task_id' => $task['id'], 'project_id' => $task['project_id']]), true);
  157. }
  158. public function confirmAllTask()
  159. {
  160. $project = $this->getProject();
  161. $task = $this->getTask();
  162. $this->response->html($this->template->render('encryptedContent:task/removeall',
  163. [
  164. 'task' => $task,
  165. 'project' => $project,
  166. ]
  167. )
  168. );
  169. }
  170. public function randomKey()
  171. {
  172. $project = $this->getProject();
  173. $task = $this->getTask();
  174. $this->response->html($this->template->render('encryptedContent:task/randomkey',
  175. [
  176. 'task' => $task,
  177. 'project' => $project,
  178. ]
  179. )
  180. );
  181. }
  182. }