1
0

Sharing.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
  160. $this->log(
  161. 'The %s "%s" with ID "%s" has been shared to the ScienceMesh user "%s" with permissions "%s" (Share ID: %s)',
  162. $params,
  163. [
  164. 'itemType',
  165. 'path',
  166. 'itemSource',
  167. 'shareWith',
  168. 'permissions',
  169. 'id',
  170. ]
  171. );
  172. }
  173. }
  174. /**
  175. * Logs unsharing of data
  176. *
  177. * @param array $params
  178. */
  179. public function unshare(array $params): void {
  180. if ($params['shareType'] === IShare::TYPE_LINK) {
  181. $this->log(
  182. 'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
  183. $params,
  184. [
  185. 'itemType',
  186. 'fileTarget',
  187. 'itemSource',
  188. 'id',
  189. ]
  190. );
  191. } elseif ($params['shareType'] === IShare::TYPE_USER) {
  192. $this->log(
  193. 'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
  194. $params,
  195. [
  196. 'itemType',
  197. 'fileTarget',
  198. 'itemSource',
  199. 'shareWith',
  200. 'id',
  201. ]
  202. );
  203. } elseif ($params['shareType'] === IShare::TYPE_GROUP) {
  204. $this->log(
  205. 'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
  206. $params,
  207. [
  208. 'itemType',
  209. 'fileTarget',
  210. 'itemSource',
  211. 'shareWith',
  212. 'id',
  213. ]
  214. );
  215. } elseif ($params['shareType'] === IShare::TYPE_ROOM) {
  216. $this->log(
  217. 'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
  218. $params,
  219. [
  220. 'itemType',
  221. 'fileTarget',
  222. 'itemSource',
  223. 'shareWith',
  224. 'id',
  225. ]
  226. );
  227. } elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
  228. $this->log(
  229. 'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
  230. $params,
  231. [
  232. 'itemType',
  233. 'fileTarget',
  234. 'itemSource',
  235. 'shareWith',
  236. 'id',
  237. ]
  238. );
  239. } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
  240. $this->log(
  241. 'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)',
  242. $params,
  243. [
  244. 'itemType',
  245. 'fileTarget',
  246. 'itemSource',
  247. 'shareWith',
  248. 'id',
  249. ]
  250. );
  251. } elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
  252. $this->log(
  253. 'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)',
  254. $params,
  255. [
  256. 'itemType',
  257. 'fileTarget',
  258. 'itemSource',
  259. 'shareWith',
  260. 'id',
  261. ]
  262. );
  263. } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
  264. $this->log(
  265. 'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)',
  266. $params,
  267. [
  268. 'itemType',
  269. 'fileTarget',
  270. 'itemSource',
  271. 'shareWith',
  272. 'id',
  273. ]
  274. );
  275. } elseif ($params['shareType'] === IShare::TYPE_DECK) {
  276. $this->log(
  277. 'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)',
  278. $params,
  279. [
  280. 'itemType',
  281. 'fileTarget',
  282. 'itemSource',
  283. 'shareWith',
  284. 'id',
  285. ]
  286. );
  287. } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
  288. $this->log(
  289. 'The %s "%s" with ID "%s" has been unshared from the ScienceMesh user "%s" (Share ID: %s)',
  290. $params,
  291. [
  292. 'itemType',
  293. 'fileTarget',
  294. 'itemSource',
  295. 'shareWith',
  296. 'id',
  297. ]
  298. );
  299. }
  300. }
  301. /**
  302. * Logs the updating of permission changes for shares
  303. *
  304. * @param array $params
  305. */
  306. public function updatePermissions(array $params): void {
  307. $this->log(
  308. 'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
  309. $params,
  310. [
  311. 'itemType',
  312. 'path',
  313. 'itemSource',
  314. 'permissions',
  315. ]
  316. );
  317. }
  318. /**
  319. * Logs the password changes for a share
  320. *
  321. * @param array $params
  322. */
  323. public function updatePassword(array $params): void {
  324. $this->log(
  325. 'The password of the publicly shared %s "%s" with ID "%s" has been changed',
  326. $params,
  327. [
  328. 'itemType',
  329. 'token',
  330. 'itemSource',
  331. ]
  332. );
  333. }
  334. /**
  335. * Logs the expiration date changes for a share
  336. *
  337. * @param array $params
  338. */
  339. public function updateExpirationDate(array $params): void {
  340. if ($params['date'] === null) {
  341. $this->log(
  342. 'The expiration date of the publicly shared %s with ID "%s" has been removed',
  343. $params,
  344. [
  345. 'itemType',
  346. 'itemSource',
  347. ]
  348. );
  349. } else {
  350. $this->log(
  351. 'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
  352. $params,
  353. [
  354. 'itemType',
  355. 'itemSource',
  356. 'date',
  357. ]
  358. );
  359. }
  360. }
  361. /**
  362. * Logs access of shared files
  363. *
  364. * @param array $params
  365. */
  366. public function shareAccessed(array $params): void {
  367. $this->log(
  368. 'The shared %s with the token "%s" by "%s" has been accessed.',
  369. $params,
  370. [
  371. 'itemType',
  372. 'token',
  373. 'uidOwner',
  374. ]
  375. );
  376. }
  377. }