You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Sharing.php 7.3KB

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