LogSettingsController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Kate Döen <kate.doeen@nextcloud.com>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  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, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OCA\Settings\Controller;
  29. use OC\Log;
  30. use OCP\AppFramework\Controller;
  31. use OCP\AppFramework\Http;
  32. use OCP\AppFramework\Http\StreamResponse;
  33. use OCP\IRequest;
  34. class LogSettingsController extends Controller {
  35. /** @var Log */
  36. private $log;
  37. public function __construct(string $appName, IRequest $request, Log $logger) {
  38. parent::__construct($appName, $request);
  39. $this->log = $logger;
  40. }
  41. /**
  42. * download logfile
  43. *
  44. * @NoCSRFRequired
  45. *
  46. * @psalm-suppress MoreSpecificReturnType The value of Content-Disposition is not relevant
  47. * @psalm-suppress LessSpecificReturnStatement The value of Content-Disposition is not relevant
  48. * @return StreamResponse<Http::STATUS_OK, array{Content-Type: 'application/octet-stream', 'Content-Disposition': string}>
  49. *
  50. * 200: Logfile returned
  51. */
  52. public function download() {
  53. if (!$this->log instanceof Log) {
  54. throw new \UnexpectedValueException('Log file not available');
  55. }
  56. $resp = new StreamResponse($this->log->getLogPath());
  57. $resp->setHeaders([
  58. 'Content-Type' => 'application/octet-stream',
  59. 'Content-Disposition' => 'attachment; filename="nextcloud.log"',
  60. ]);
  61. return $resp;
  62. }
  63. }