Sharing.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Sascha Wiswedel <sascha.wiswedel@nextcloud.com>
  12. *
  13. * @license GNU AGPL version 3 or any later version
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License as
  17. * published by the Free Software Foundation, either version 3 of the
  18. * License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. */
  29. namespace OCA\AdminAudit\Actions;
  30. use OCP\Share\IShare;
  31. /**
  32. * Class Sharing logs the sharing actions
  33. *
  34. * @package OCA\AdminAudit\Actions
  35. */
  36. class Sharing extends Action {
  37. /**
  38. * Logs sharing of data
  39. *
  40. * @param array $params
  41. */
  42. public function shared(array $params): void {
  43. if ($params['shareType'] === IShare::TYPE_LINK) {
  44. $this->log(
  45. 'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)',
  46. $params,
  47. [
  48. 'itemType',
  49. 'path',
  50. 'itemSource',
  51. 'permissions',
  52. 'id',
  53. ]
  54. );
  55. } elseif ($params['shareType'] === IShare::TYPE_USER) {
  56. $this->log(
  57. 'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s" (Share ID: %s)',
  58. $params,
  59. [
  60. 'itemType',
  61. 'path',
  62. 'itemSource',
  63. 'shareWith',
  64. 'permissions',
  65. 'id',
  66. ]
  67. );
  68. } elseif ($params['shareType'] === IShare::TYPE_GROUP) {
  69. $this->log(
  70. 'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s" (Share ID: %s)',
  71. $params,
  72. [
  73. 'itemType',
  74. 'path',
  75. 'itemSource',
  76. 'shareWith',
  77. 'permissions',
  78. 'id',
  79. ]
  80. );
  81. } elseif ($params['shareType'] === IShare::TYPE_ROOM) {
  82. $this->log(
  83. 'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)',
  84. $params,
  85. [
  86. 'itemType',
  87. 'path',
  88. 'itemSource',
  89. 'shareWith',
  90. 'permissions',
  91. 'id',
  92. ]
  93. );
  94. } elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
  95. $this->log(
  96. 'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)',
  97. $params,
  98. [
  99. 'itemType',
  100. 'path',
  101. 'itemSource',
  102. 'shareWith',
  103. 'permissions',
  104. 'id',
  105. ]
  106. );
  107. } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
  108. $this->log(
  109. 'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)',
  110. $params,
  111. [
  112. 'itemType',
  113. 'path',
  114. 'itemSource',
  115. 'shareWith',
  116. 'permissions',
  117. 'id',
  118. ]
  119. );
  120. } elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
  121. $this->log(
  122. 'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)',
  123. $params,
  124. [
  125. 'itemType',
  126. 'path',
  127. 'itemSource',
  128. 'shareWith',
  129. 'permissions',
  130. 'id',
  131. ]
  132. );
  133. } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
  134. $this->log(
  135. 'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)',
  136. $params,
  137. [
  138. 'itemType',
  139. 'path',
  140. 'itemSource',
  141. 'shareWith',
  142. 'permissions',
  143. 'id',
  144. ]
  145. );
  146. } elseif ($params['shareType'] === IShare::TYPE_DECK) {
  147. $this->log(
  148. 'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)',
  149. $params,
  150. [
  151. 'itemType',
  152. 'path',
  153. 'itemSource',
  154. 'shareWith',
  155. 'permissions',
  156. 'id',
  157. ]
  158. );
  159. }
  160. }
  161. /**
  162. * Logs unsharing of data
  163. *
  164. * @param array $params
  165. */
  166. public function unshare(array $params): void {
  167. if ($params['shareType'] === IShare::TYPE_LINK) {
  168. $this->log(
  169. 'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
  170. $params,
  171. [
  172. 'itemType',
  173. 'fileTarget',
  174. 'itemSource',
  175. 'id',
  176. ]
  177. );
  178. } elseif ($params['shareType'] === IShare::TYPE_USER) {
  179. $this->log(
  180. 'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
  181. $params,
  182. [
  183. 'itemType',
  184. 'fileTarget',
  185. 'itemSource',
  186. 'shareWith',
  187. 'id',
  188. ]
  189. );
  190. } elseif ($params['shareType'] === IShare::TYPE_GROUP) {
  191. $this->log(
  192. 'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
  193. $params,
  194. [
  195. 'itemType',
  196. 'fileTarget',
  197. 'itemSource',
  198. 'shareWith',
  199. 'id',
  200. ]
  201. );
  202. } elseif ($params['shareType'] === IShare::TYPE_ROOM) {
  203. $this->log(
  204. 'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
  205. $params,
  206. [
  207. 'itemType',
  208. 'fileTarget',
  209. 'itemSource',
  210. 'shareWith',
  211. 'id',
  212. ]
  213. );
  214. } elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
  215. $this->log(
  216. 'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
  217. $params,
  218. [
  219. 'itemType',
  220. 'fileTarget',
  221. 'itemSource',
  222. 'shareWith',
  223. 'id',
  224. ]
  225. );
  226. } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
  227. $this->log(
  228. 'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)',
  229. $params,
  230. [
  231. 'itemType',
  232. 'fileTarget',
  233. 'itemSource',
  234. 'shareWith',
  235. 'id',
  236. ]
  237. );
  238. } elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
  239. $this->log(
  240. 'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)',
  241. $params,
  242. [
  243. 'itemType',
  244. 'fileTarget',
  245. 'itemSource',
  246. 'shareWith',
  247. 'id',
  248. ]
  249. );
  250. } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
  251. $this->log(
  252. 'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)',
  253. $params,
  254. [
  255. 'itemType',
  256. 'fileTarget',
  257. 'itemSource',
  258. 'shareWith',
  259. 'id',
  260. ]
  261. );
  262. } elseif ($params['shareType'] === IShare::TYPE_DECK) {
  263. $this->log(
  264. 'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)',
  265. $params,
  266. [
  267. 'itemType',
  268. 'fileTarget',
  269. 'itemSource',
  270. 'shareWith',
  271. 'id',
  272. ]
  273. );
  274. }
  275. }
  276. /**
  277. * Logs the updating of permission changes for shares
  278. *
  279. * @param array $params
  280. */
  281. public function updatePermissions(array $params): void {
  282. $this->log(
  283. 'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
  284. $params,
  285. [
  286. 'itemType',
  287. 'path',
  288. 'itemSource',
  289. 'permissions',
  290. ]
  291. );
  292. }
  293. /**
  294. * Logs the password changes for a share
  295. *
  296. * @param array $params
  297. */
  298. public function updatePassword(array $params): void {
  299. $this->log(
  300. 'The password of the publicly shared %s "%s" with ID "%s" has been changed',
  301. $params,
  302. [
  303. 'itemType',
  304. 'token',
  305. 'itemSource',
  306. ]
  307. );
  308. }
  309. /**
  310. * Logs the expiration date changes for a share
  311. *
  312. * @param array $params
  313. */
  314. public function updateExpirationDate(array $params): void {
  315. if ($params['date'] === null) {
  316. $this->log(
  317. 'The expiration date of the publicly shared %s with ID "%s" has been removed',
  318. $params,
  319. [
  320. 'itemType',
  321. 'itemSource',
  322. ]
  323. );
  324. } else {
  325. $this->log(
  326. 'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
  327. $params,
  328. [
  329. 'itemType',
  330. 'itemSource',
  331. 'date',
  332. ]
  333. );
  334. }
  335. }
  336. /**
  337. * Logs access of shared files
  338. *
  339. * @param array $params
  340. */
  341. public function shareAccessed(array $params): void {
  342. $this->log(
  343. 'The shared %s with the token "%s" by "%s" has been accessed.',
  344. $params,
  345. [
  346. 'itemType',
  347. 'token',
  348. 'uidOwner',
  349. ]
  350. );
  351. }
  352. }