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

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