Completed
Pull Request — master (#8565)
by Joas
105:07 queued 85:11
created
lib/public/IRequest.php 1 patch
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -65,237 +65,237 @@
 block discarded – undo
65 65
  * @since 6.0.0
66 66
  */
67 67
 interface IRequest {
68
-	/**
69
-	 * @since 9.1.0
70
-	 */
71
-	const USER_AGENT_CLIENT_ANDROID = '/^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/';
72
-
73
-	/**
74
-	 * @since 13.0.0
75
-	 */
76
-	const USER_AGENT_TALK_ANDROID = '/^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v.*$/';
77
-
78
-	/**
79
-	 * @since 9.1.0
80
-	 */
81
-	const USER_AGENT_CLIENT_DESKTOP = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/';
82
-
83
-	/**
84
-	 * @since 9.1.0
85
-	 */
86
-	const USER_AGENT_CLIENT_IOS = '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/';
87
-
88
-	/**
89
-	 * @since 13.0.0
90
-	 */
91
-	const USER_AGENT_TALK_IOS = '/^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v.*$/';
92
-
93
-	/**
94
-	 * @since 13.0.1
95
-	 */
96
-	const USER_AGENT_OUTLOOK_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v.*$/';
97
-
98
-	/**
99
-	 * @since 13.0.1
100
-	 */
101
-	const USER_AGENT_THUNDERBIRD_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v.*$/';
102
-
103
-	/**
104
-	 * @param string $name
105
-	 *
106
-	 * @return string
107
-	 * @since 6.0.0
108
-	 */
109
-	public function getHeader(string $name): string;
110
-
111
-	/**
112
-	 * Lets you access post and get parameters by the index
113
-	 * In case of json requests the encoded json body is accessed
114
-	 *
115
-	 * @param string $key the key which you want to access in the URL Parameter
116
-	 *                     placeholder, $_POST or $_GET array.
117
-	 *                     The priority how they're returned is the following:
118
-	 *                     1. URL parameters
119
-	 *                     2. POST parameters
120
-	 *                     3. GET parameters
121
-	 * @param mixed $default If the key is not found, this value will be returned
122
-	 * @return mixed the content of the array
123
-	 * @since 6.0.0
124
-	 */
125
-	public function getParam(string $key, $default = null);
126
-
127
-
128
-	/**
129
-	 * Returns all params that were received, be it from the request
130
-	 *
131
-	 * (as GET or POST) or through the URL by the route
132
-	 *
133
-	 * @return array the array with all parameters
134
-	 * @since 6.0.0
135
-	 */
136
-	public function getParams(): array;
137
-
138
-	/**
139
-	 * Returns the method of the request
140
-	 *
141
-	 * @return string the method of the request (POST, GET, etc)
142
-	 * @since 6.0.0
143
-	 */
144
-	public function getMethod(): string;
145
-
146
-	/**
147
-	 * Shortcut for accessing an uploaded file through the $_FILES array
148
-	 *
149
-	 * @param string $key the key that will be taken from the $_FILES array
150
-	 * @return array the file in the $_FILES element
151
-	 * @since 6.0.0
152
-	 */
153
-	public function getUploadedFile(string $key);
154
-
155
-
156
-	/**
157
-	 * Shortcut for getting env variables
158
-	 *
159
-	 * @param string $key the key that will be taken from the $_ENV array
160
-	 * @return array the value in the $_ENV element
161
-	 * @since 6.0.0
162
-	 */
163
-	public function getEnv(string $key);
164
-
165
-
166
-	/**
167
-	 * Shortcut for getting cookie variables
168
-	 *
169
-	 * @param string $key the key that will be taken from the $_COOKIE array
170
-	 * @return string|null the value in the $_COOKIE element
171
-	 * @since 6.0.0
172
-	 */
173
-	public function getCookie(string $key);
174
-
175
-
176
-	/**
177
-	 * Checks if the CSRF check was correct
178
-	 *
179
-	 * @return bool true if CSRF check passed
180
-	 * @since 6.0.0
181
-	 */
182
-	public function passesCSRFCheck(): bool;
183
-
184
-	/**
185
-	 * Checks if the strict cookie has been sent with the request if the request
186
-	 * is including any cookies.
187
-	 *
188
-	 * @return bool
189
-	 * @since 9.0.0
190
-	 */
191
-	public function passesStrictCookieCheck(): bool;
192
-
193
-	/**
194
-	 * Checks if the lax cookie has been sent with the request if the request
195
-	 * is including any cookies.
196
-	 *
197
-	 * @return bool
198
-	 * @since 9.0.0
199
-	 */
200
-	public function passesLaxCookieCheck(): bool;
201
-
202
-	/**
203
-	 * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
204
-	 * If `mod_unique_id` is installed this value will be taken.
205
-	 *
206
-	 * @return string
207
-	 * @since 8.1.0
208
-	 */
209
-	public function getId(): string;
210
-
211
-	/**
212
-	 * Returns the remote address, if the connection came from a trusted proxy
213
-	 * and `forwarded_for_headers` has been configured then the IP address
214
-	 * specified in this header will be returned instead.
215
-	 * Do always use this instead of $_SERVER['REMOTE_ADDR']
216
-	 *
217
-	 * @return string IP address
218
-	 * @since 8.1.0
219
-	 */
220
-	public function getRemoteAddress(): string;
221
-
222
-	/**
223
-	 * Returns the server protocol. It respects reverse proxy servers and load
224
-	 * balancers.
225
-	 *
226
-	 * @return string Server protocol (http or https)
227
-	 * @since 8.1.0
228
-	 */
229
-	public function getServerProtocol(): string;
230
-
231
-	/**
232
-	 * Returns the used HTTP protocol.
233
-	 *
234
-	 * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
235
-	 * @since 8.2.0
236
-	 */
237
-	public function getHttpProtocol(): string;
238
-
239
-	/**
240
-	 * Returns the request uri, even if the website uses one or more
241
-	 * reverse proxies
242
-	 *
243
-	 * @return string
244
-	 * @since 8.1.0
245
-	 */
246
-	public function getRequestUri(): string;
247
-
248
-	/**
249
-	 * Get raw PathInfo from request (not urldecoded)
250
-	 *
251
-	 * @throws \Exception
252
-	 * @return string Path info
253
-	 * @since 8.1.0
254
-	 */
255
-	public function getRawPathInfo(): string;
256
-
257
-	/**
258
-	 * Get PathInfo from request
259
-	 *
260
-	 * @throws \Exception
261
-	 * @return string|false Path info or false when not found
262
-	 * @since 8.1.0
263
-	 */
264
-	public function getPathInfo();
265
-
266
-	/**
267
-	 * Returns the script name, even if the website uses one or more
268
-	 * reverse proxies
269
-	 *
270
-	 * @return string the script name
271
-	 * @since 8.1.0
272
-	 */
273
-	public function getScriptName(): string;
274
-
275
-	/**
276
-	 * Checks whether the user agent matches a given regex
277
-	 *
278
-	 * @param array $agent array of agent names
279
-	 * @return bool true if at least one of the given agent matches, false otherwise
280
-	 * @since 8.1.0
281
-	 */
282
-	public function isUserAgent(array $agent): bool;
283
-
284
-	/**
285
-	 * Returns the unverified server host from the headers without checking
286
-	 * whether it is a trusted domain
287
-	 *
288
-	 * @return string Server host
289
-	 * @since 8.1.0
290
-	 */
291
-	public function getInsecureServerHost(): string;
292
-
293
-	/**
294
-	 * Returns the server host from the headers, or the first configured
295
-	 * trusted domain if the host isn't in the trusted list
296
-	 *
297
-	 * @return string Server host
298
-	 * @since 8.1.0
299
-	 */
300
-	public function getServerHost(): string;
68
+    /**
69
+     * @since 9.1.0
70
+     */
71
+    const USER_AGENT_CLIENT_ANDROID = '/^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/';
72
+
73
+    /**
74
+     * @since 13.0.0
75
+     */
76
+    const USER_AGENT_TALK_ANDROID = '/^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v.*$/';
77
+
78
+    /**
79
+     * @since 9.1.0
80
+     */
81
+    const USER_AGENT_CLIENT_DESKTOP = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/';
82
+
83
+    /**
84
+     * @since 9.1.0
85
+     */
86
+    const USER_AGENT_CLIENT_IOS = '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/';
87
+
88
+    /**
89
+     * @since 13.0.0
90
+     */
91
+    const USER_AGENT_TALK_IOS = '/^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v.*$/';
92
+
93
+    /**
94
+     * @since 13.0.1
95
+     */
96
+    const USER_AGENT_OUTLOOK_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v.*$/';
97
+
98
+    /**
99
+     * @since 13.0.1
100
+     */
101
+    const USER_AGENT_THUNDERBIRD_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v.*$/';
102
+
103
+    /**
104
+     * @param string $name
105
+     *
106
+     * @return string
107
+     * @since 6.0.0
108
+     */
109
+    public function getHeader(string $name): string;
110
+
111
+    /**
112
+     * Lets you access post and get parameters by the index
113
+     * In case of json requests the encoded json body is accessed
114
+     *
115
+     * @param string $key the key which you want to access in the URL Parameter
116
+     *                     placeholder, $_POST or $_GET array.
117
+     *                     The priority how they're returned is the following:
118
+     *                     1. URL parameters
119
+     *                     2. POST parameters
120
+     *                     3. GET parameters
121
+     * @param mixed $default If the key is not found, this value will be returned
122
+     * @return mixed the content of the array
123
+     * @since 6.0.0
124
+     */
125
+    public function getParam(string $key, $default = null);
126
+
127
+
128
+    /**
129
+     * Returns all params that were received, be it from the request
130
+     *
131
+     * (as GET or POST) or through the URL by the route
132
+     *
133
+     * @return array the array with all parameters
134
+     * @since 6.0.0
135
+     */
136
+    public function getParams(): array;
137
+
138
+    /**
139
+     * Returns the method of the request
140
+     *
141
+     * @return string the method of the request (POST, GET, etc)
142
+     * @since 6.0.0
143
+     */
144
+    public function getMethod(): string;
145
+
146
+    /**
147
+     * Shortcut for accessing an uploaded file through the $_FILES array
148
+     *
149
+     * @param string $key the key that will be taken from the $_FILES array
150
+     * @return array the file in the $_FILES element
151
+     * @since 6.0.0
152
+     */
153
+    public function getUploadedFile(string $key);
154
+
155
+
156
+    /**
157
+     * Shortcut for getting env variables
158
+     *
159
+     * @param string $key the key that will be taken from the $_ENV array
160
+     * @return array the value in the $_ENV element
161
+     * @since 6.0.0
162
+     */
163
+    public function getEnv(string $key);
164
+
165
+
166
+    /**
167
+     * Shortcut for getting cookie variables
168
+     *
169
+     * @param string $key the key that will be taken from the $_COOKIE array
170
+     * @return string|null the value in the $_COOKIE element
171
+     * @since 6.0.0
172
+     */
173
+    public function getCookie(string $key);
174
+
175
+
176
+    /**
177
+     * Checks if the CSRF check was correct
178
+     *
179
+     * @return bool true if CSRF check passed
180
+     * @since 6.0.0
181
+     */
182
+    public function passesCSRFCheck(): bool;
183
+
184
+    /**
185
+     * Checks if the strict cookie has been sent with the request if the request
186
+     * is including any cookies.
187
+     *
188
+     * @return bool
189
+     * @since 9.0.0
190
+     */
191
+    public function passesStrictCookieCheck(): bool;
192
+
193
+    /**
194
+     * Checks if the lax cookie has been sent with the request if the request
195
+     * is including any cookies.
196
+     *
197
+     * @return bool
198
+     * @since 9.0.0
199
+     */
200
+    public function passesLaxCookieCheck(): bool;
201
+
202
+    /**
203
+     * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
204
+     * If `mod_unique_id` is installed this value will be taken.
205
+     *
206
+     * @return string
207
+     * @since 8.1.0
208
+     */
209
+    public function getId(): string;
210
+
211
+    /**
212
+     * Returns the remote address, if the connection came from a trusted proxy
213
+     * and `forwarded_for_headers` has been configured then the IP address
214
+     * specified in this header will be returned instead.
215
+     * Do always use this instead of $_SERVER['REMOTE_ADDR']
216
+     *
217
+     * @return string IP address
218
+     * @since 8.1.0
219
+     */
220
+    public function getRemoteAddress(): string;
221
+
222
+    /**
223
+     * Returns the server protocol. It respects reverse proxy servers and load
224
+     * balancers.
225
+     *
226
+     * @return string Server protocol (http or https)
227
+     * @since 8.1.0
228
+     */
229
+    public function getServerProtocol(): string;
230
+
231
+    /**
232
+     * Returns the used HTTP protocol.
233
+     *
234
+     * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
235
+     * @since 8.2.0
236
+     */
237
+    public function getHttpProtocol(): string;
238
+
239
+    /**
240
+     * Returns the request uri, even if the website uses one or more
241
+     * reverse proxies
242
+     *
243
+     * @return string
244
+     * @since 8.1.0
245
+     */
246
+    public function getRequestUri(): string;
247
+
248
+    /**
249
+     * Get raw PathInfo from request (not urldecoded)
250
+     *
251
+     * @throws \Exception
252
+     * @return string Path info
253
+     * @since 8.1.0
254
+     */
255
+    public function getRawPathInfo(): string;
256
+
257
+    /**
258
+     * Get PathInfo from request
259
+     *
260
+     * @throws \Exception
261
+     * @return string|false Path info or false when not found
262
+     * @since 8.1.0
263
+     */
264
+    public function getPathInfo();
265
+
266
+    /**
267
+     * Returns the script name, even if the website uses one or more
268
+     * reverse proxies
269
+     *
270
+     * @return string the script name
271
+     * @since 8.1.0
272
+     */
273
+    public function getScriptName(): string;
274
+
275
+    /**
276
+     * Checks whether the user agent matches a given regex
277
+     *
278
+     * @param array $agent array of agent names
279
+     * @return bool true if at least one of the given agent matches, false otherwise
280
+     * @since 8.1.0
281
+     */
282
+    public function isUserAgent(array $agent): bool;
283
+
284
+    /**
285
+     * Returns the unverified server host from the headers without checking
286
+     * whether it is a trusted domain
287
+     *
288
+     * @return string Server host
289
+     * @since 8.1.0
290
+     */
291
+    public function getInsecureServerHost(): string;
292
+
293
+    /**
294
+     * Returns the server host from the headers, or the first configured
295
+     * trusted domain if the host isn't in the trusted list
296
+     *
297
+     * @return string Server host
298
+     * @since 8.1.0
299
+     */
300
+    public function getServerHost(): string;
301 301
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Check/RequestUserAgent.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -27,56 +27,56 @@
 block discarded – undo
27 27
 
28 28
 class RequestUserAgent extends AbstractStringCheck {
29 29
 
30
-	/** @var IRequest */
31
-	protected $request;
30
+    /** @var IRequest */
31
+    protected $request;
32 32
 
33
-	/**
34
-	 * @param IL10N $l
35
-	 * @param IRequest $request
36
-	 */
37
-	public function __construct(IL10N $l, IRequest $request) {
38
-		parent::__construct($l);
39
-		$this->request = $request;
40
-	}
33
+    /**
34
+     * @param IL10N $l
35
+     * @param IRequest $request
36
+     */
37
+    public function __construct(IL10N $l, IRequest $request) {
38
+        parent::__construct($l);
39
+        $this->request = $request;
40
+    }
41 41
 
42
-	/**
43
-	 * @param string $operator
44
-	 * @param string $value
45
-	 * @return bool
46
-	 */
47
-	public function executeCheck($operator, $value) {
48
-		$actualValue = $this->getActualValue();
49
-		if (in_array($operator, ['is', '!is'], true)) {
50
-			switch ($value) {
51
-				case 'android':
52
-					$operator = $operator === 'is' ? 'matches' : '!matches';
53
-					$value = IRequest::USER_AGENT_CLIENT_ANDROID;
54
-					break;
55
-				case 'ios':
56
-					$operator = $operator === 'is' ? 'matches' : '!matches';
57
-					$value = IRequest::USER_AGENT_CLIENT_IOS;
58
-					break;
59
-				case 'desktop':
60
-					$operator = $operator === 'is' ? 'matches' : '!matches';
61
-					$value = IRequest::USER_AGENT_CLIENT_DESKTOP;
62
-					break;
63
-				case 'mail':
64
-					if ($operator === 'is') {
65
-						return $this->executeStringCheck('matches', IRequest::USER_AGENT_OUTLOOK_ADDON, $actualValue)
66
-							|| $this->executeStringCheck('matches', IRequest::USER_AGENT_THUNDERBIRD_ADDON, $actualValue);
67
-					}
42
+    /**
43
+     * @param string $operator
44
+     * @param string $value
45
+     * @return bool
46
+     */
47
+    public function executeCheck($operator, $value) {
48
+        $actualValue = $this->getActualValue();
49
+        if (in_array($operator, ['is', '!is'], true)) {
50
+            switch ($value) {
51
+                case 'android':
52
+                    $operator = $operator === 'is' ? 'matches' : '!matches';
53
+                    $value = IRequest::USER_AGENT_CLIENT_ANDROID;
54
+                    break;
55
+                case 'ios':
56
+                    $operator = $operator === 'is' ? 'matches' : '!matches';
57
+                    $value = IRequest::USER_AGENT_CLIENT_IOS;
58
+                    break;
59
+                case 'desktop':
60
+                    $operator = $operator === 'is' ? 'matches' : '!matches';
61
+                    $value = IRequest::USER_AGENT_CLIENT_DESKTOP;
62
+                    break;
63
+                case 'mail':
64
+                    if ($operator === 'is') {
65
+                        return $this->executeStringCheck('matches', IRequest::USER_AGENT_OUTLOOK_ADDON, $actualValue)
66
+                            || $this->executeStringCheck('matches', IRequest::USER_AGENT_THUNDERBIRD_ADDON, $actualValue);
67
+                    }
68 68
 
69
-					return $this->executeStringCheck('!matches', IRequest::USER_AGENT_OUTLOOK_ADDON, $actualValue)
70
-						&& $this->executeStringCheck('!matches', IRequest::USER_AGENT_THUNDERBIRD_ADDON, $actualValue);
71
-			}
72
-		}
73
-		return $this->executeStringCheck($operator, $value, $actualValue);
74
-	}
69
+                    return $this->executeStringCheck('!matches', IRequest::USER_AGENT_OUTLOOK_ADDON, $actualValue)
70
+                        && $this->executeStringCheck('!matches', IRequest::USER_AGENT_THUNDERBIRD_ADDON, $actualValue);
71
+            }
72
+        }
73
+        return $this->executeStringCheck($operator, $value, $actualValue);
74
+    }
75 75
 
76
-	/**
77
-	 * @return string
78
-	 */
79
-	protected function getActualValue() {
80
-		return (string) $this->request->getHeader('User-Agent');
81
-	}
76
+    /**
77
+     * @return string
78
+     */
79
+    protected function getActualValue() {
80
+        return (string) $this->request->getHeader('User-Agent');
81
+    }
82 82
 }
Please login to merge, or discard this patch.