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.

108 lines
2.5 KiB

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