logsettingscontroller.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @author Georg Ehrke <georg@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Thomas Müller <thomas.mueller@tmit.eu>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Settings\Controller;
  24. use OCP\AppFramework\Controller;
  25. use OCP\AppFramework\Http;
  26. use OCP\AppFramework\Http\JSONResponse;
  27. use OCP\AppFramework\Http\StreamResponse;
  28. use OCP\IL10N;
  29. use OCP\IRequest;
  30. use OCP\IConfig;
  31. /**
  32. * Class LogSettingsController
  33. *
  34. * @package OC\Settings\Controller
  35. */
  36. class LogSettingsController extends Controller {
  37. /**
  38. * @var \OCP\IConfig
  39. */
  40. private $config;
  41. /**
  42. * @var \OCP\IL10N
  43. */
  44. private $l10n;
  45. /**
  46. * @param string $appName
  47. * @param IRequest $request
  48. * @param IConfig $config
  49. */
  50. public function __construct($appName,
  51. IRequest $request,
  52. IConfig $config,
  53. IL10N $l10n) {
  54. parent::__construct($appName, $request);
  55. $this->config = $config;
  56. $this->l10n = $l10n;
  57. }
  58. /**
  59. * set log level for logger
  60. *
  61. * @param int $level
  62. * @return JSONResponse
  63. */
  64. public function setLogLevel($level) {
  65. if ($level < 0 || $level > 4) {
  66. return new JSONResponse([
  67. 'message' => (string) $this->l10n->t('log-level out of allowed range'),
  68. ], Http::STATUS_BAD_REQUEST);
  69. }
  70. $this->config->setSystemValue('loglevel', $level);
  71. return new JSONResponse([
  72. 'level' => $level,
  73. ]);
  74. }
  75. /**
  76. * get log entries from logfile
  77. *
  78. * @param int $count
  79. * @param int $offset
  80. * @return JSONResponse
  81. */
  82. public function getEntries($count=50, $offset=0) {
  83. return new JSONResponse([
  84. 'data' => \OC_Log_Owncloud::getEntries($count, $offset),
  85. 'remain' => count(\OC_Log_Owncloud::getEntries(1, $offset + $count)) !== 0,
  86. ]);
  87. }
  88. /**
  89. * download logfile
  90. *
  91. * @NoCSRFRequired
  92. *
  93. * @return StreamResponse
  94. */
  95. public function download() {
  96. $resp = new StreamResponse(\OC_Log_Owncloud::getLogFilePath());
  97. $resp->addHeader('Content-Disposition', 'attachment; filename="owncloud.log"');
  98. return $resp;
  99. }
  100. }