From 1091cbb7786c0826b8e8aca65512347b199235ca Mon Sep 17 00:00:00 2001 From: Joas Schilling <coding@schilljs.com> Date: Thu, 28 Jul 2016 13:47:42 +0200 Subject: [PATCH] Add Request URL --- apps/workflowengine/js/requesturlplugin.js | Bin 0 -> 3441 bytes .../lib/AppInfo/Application.php | 1 + apps/workflowengine/lib/Check/RequestURL.php | 89 ++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 apps/workflowengine/js/requesturlplugin.js create mode 100644 apps/workflowengine/lib/Check/RequestURL.php diff --git a/apps/workflowengine/js/requesturlplugin.js b/apps/workflowengine/js/requesturlplugin.js new file mode 100644 index 0000000000000000000000000000000000000000..5f21d2a59fc410cfbe19986853fa9de6e86e136e GIT binary patch literal 3441 zcmcInZBN@s5dLg_#Z;=~1W~6iy8Dops<|AroG3&I6d^)Si#?9_aJ;_VbplHB-*0BK z4u*ynRXVA1<Mqt5&ph+8OJ{p~3%21ytjb$0Cz*x*`d2G%!|Ru?euux5FffWUndh>Y zz`Ix_^#2FrR{k+jtfub?#R26q#=;<cJUWHm$H5`YP#dWVcmqm<C~hGa7InSs-A*!T zpww!j#T4jgsu97c)Xs&*F5IdLVo`v`L>jB*Rb>&RCAg$Rs8iyT-tzXeRuu`s+YEuW znHo^3dvScy6t#knSfCa;45}+)3x}SuFpN<0qRB9Ut6S%|&s0X93hXPw7nTCr0hF}M zIuZ`hZN(@abBAMY3CjU!P$m1dzZW5TM1{Lx6Oe^tlc|yd%LtM}ol`>K3ZXKXR{0KZ zOv=F7!O5rN(-Y_&ox@pgIP4vroWCVwn<@H=Gh9K*X_-rklO)!nu(w2?5kBt?`=7|A z_s7BE!O1yCuzzrJv^N^T{_zlcFz5|W4*I8uy&()vhlAtMUIZ{Akw^^&__@-l%b7+< z&<dHGI{tG?vmugs0-2a0r8`DBBZ>mJKA)UQW+8G#rOH7Que;(Rss||)%I<(6%I`93 z%WkJLpU<O7QAJ8mI=+HU=e_6E+1hHQRS|RcT5VWtZ3V~uU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>Ycac`>Qv<>KYen`QfXXO$4`<RP;=p9pU-Zh270$kX$-eEt<xp7SSS tM<?pC-QsC?+^_Fl5uwo^8c37;`%7Ka=kwKH-)J6hu<#$hyPDB1{{g_76GQ+2 literal 0 HcmV?d00001 diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php index 82a07aa59e2..b024518c4c5 100644 --- a/apps/workflowengine/lib/AppInfo/Application.php +++ b/apps/workflowengine/lib/AppInfo/Application.php @@ -59,6 +59,7 @@ class Application extends \OCP\AppFramework\App { 'filesizeplugin', 'filesystemtagsplugin', 'requestuseragentplugin', + 'requesturlplugin', 'usergroupmembershipplugin', ]); }, diff --git a/apps/workflowengine/lib/Check/RequestURL.php b/apps/workflowengine/lib/Check/RequestURL.php new file mode 100644 index 00000000000..0cae3cf7e56 --- /dev/null +++ b/apps/workflowengine/lib/Check/RequestURL.php @@ -0,0 +1,89 @@ +<?php +/** + * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\WorkflowEngine\Check; + + +use OCP\IRequest; + +class RequestURL extends AbstractStringCheck { + + /** @var string */ + protected $url; + + /** @var IRequest */ + protected $request; + + /** + * @param IRequest $request + */ + public function __construct(IRequest $request) { + $this->request = $request; + } + + /** + * @param string $operator + * @param string $value + * @return bool + */ + public function executeCheck($operator, $value) { + $actualValue = $this->getActualValue(); + if (in_array($operator, ['is', '!is'])) { + switch ($value) { + case 'webdav': + if ($operator === 'is') { + return $this->isWebDAVRequest(); + } else { + return !$this->isWebDAVRequest(); + } + } + } + return $this->executeStringCheck($operator, $value, $actualValue); + } + + /** + * @return string + */ + protected function getActualValue() { + if ($this->url !== null) { + return $this->url; + } + + $this->url = $this->request->getServerProtocol() . '://';// E.g. http(s) + :// + $this->url .= $this->request->getServerHost();// E.g. localhost + $this->url .= $this->request->getScriptName();// E.g. /nextcloud/index.php + $this->url .= $this->request->getPathInfo();// E.g. /apps/files_texteditor/ajax/loadfile + + return $this->url; // E.g. https://localhost/nextcloud/index.php/apps/files_texteditor/ajax/loadfile + } + + /** + * @return bool + */ + protected function isWebDAVRequest() { + return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( + $this->request->getPathInfo() === '/webdav' || + strpos($this->request->getPathInfo(), '/webdav/') === 0 || + $this->request->getPathInfo() === '/dav/files' || + strpos($this->request->getPathInfo(), '/dav/files/') === 0 + ); + } +} -- GitLab