Sharing.php 7.7 KB

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