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.

RequestURL.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\WorkflowEngine\Check;
  25. use OCP\IL10N;
  26. use OCP\IRequest;
  27. class RequestURL extends AbstractStringCheck {
  28. /** @var string */
  29. protected $url;
  30. /** @var IRequest */
  31. protected $request;
  32. /**
  33. * @param IL10N $l
  34. * @param IRequest $request
  35. */
  36. public function __construct(IL10N $l, IRequest $request) {
  37. parent::__construct($l);
  38. $this->request = $request;
  39. }
  40. /**
  41. * @param string $operator
  42. * @param string $value
  43. * @return bool
  44. */
  45. public function executeCheck($operator, $value) {
  46. $actualValue = $this->getActualValue();
  47. if (in_array($operator, ['is', '!is'])) {
  48. switch ($value) {
  49. case 'webdav':
  50. if ($operator === 'is') {
  51. return $this->isWebDAVRequest();
  52. } else {
  53. return !$this->isWebDAVRequest();
  54. }
  55. }
  56. }
  57. return $this->executeStringCheck($operator, $value, $actualValue);
  58. }
  59. /**
  60. * @return string
  61. */
  62. protected function getActualValue() {
  63. if ($this->url !== null) {
  64. return $this->url;
  65. }
  66. $this->url = $this->request->getServerProtocol() . '://';// E.g. http(s) + ://
  67. $this->url .= $this->request->getServerHost();// E.g. localhost
  68. $this->url .= $this->request->getScriptName();// E.g. /nextcloud/index.php
  69. $this->url .= $this->request->getPathInfo();// E.g. /apps/files_texteditor/ajax/loadfile
  70. return $this->url; // E.g. https://localhost/nextcloud/index.php/apps/files_texteditor/ajax/loadfile
  71. }
  72. /**
  73. * @return bool
  74. */
  75. protected function isWebDAVRequest() {
  76. return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && (
  77. $this->request->getPathInfo() === '/webdav' ||
  78. strpos($this->request->getPathInfo(), '/webdav/') === 0 ||
  79. $this->request->getPathInfo() === '/dav/files' ||
  80. strpos($this->request->getPathInfo(), '/dav/files/') === 0
  81. );
  82. }
  83. }