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.8KB

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