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.

305 lines
8.1 KiB

3 years ago
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. * @author Thomas Tanghus <thomas@tanghus.net>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. /**
  32. * Public interface of ownCloud for apps to use.
  33. * Request interface
  34. *
  35. */
  36. // use OCP namespace for all classes that are considered public.
  37. // This means that they should be used by apps instead of the internal ownCloud classes
  38. namespace OCP;
  39. /**
  40. * This interface provides an immutable object with with accessors to
  41. * request variables and headers.
  42. *
  43. * Access request variables by method and name.
  44. *
  45. * Examples:
  46. *
  47. * $request->post['myvar']; // Only look for POST variables
  48. * $request->myvar; or $request->{'myvar'}; or $request->{$myvar}
  49. * Looks in the combined GET, POST and urlParams array.
  50. *
  51. * If you access e.g. ->post but the current HTTP request method
  52. * is GET a \LogicException will be thrown.
  53. *
  54. * NOTE:
  55. * - When accessing ->put a stream resource is returned and the accessor
  56. * will return false on subsequent access to ->put or ->patch.
  57. * - When accessing ->patch and the Content-Type is either application/json
  58. * or application/x-www-form-urlencoded (most cases) it will act like ->get
  59. * and ->post and return an array. Otherwise the raw data will be returned.
  60. *
  61. * @property-read string[] $server
  62. * @property-read string[] $urlParams
  63. * @since 6.0.0
  64. */
  65. interface IRequest {
  66. /**
  67. * @since 9.1.0
  68. */
  69. public const USER_AGENT_CLIENT_ANDROID = '/^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/';
  70. /**
  71. * @since 13.0.0
  72. */
  73. public const USER_AGENT_TALK_ANDROID = '/^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v.*$/';
  74. /**
  75. * @since 9.1.0
  76. */
  77. public const USER_AGENT_CLIENT_DESKTOP = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/';
  78. /**
  79. * @since 9.1.0
  80. */
  81. public const USER_AGENT_CLIENT_IOS = '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/';
  82. /**
  83. * @since 13.0.0
  84. */
  85. public const USER_AGENT_TALK_IOS = '/^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v.*$/';
  86. /**
  87. * @since 13.0.1
  88. */
  89. public const USER_AGENT_OUTLOOK_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v.*$/';
  90. /**
  91. * @since 13.0.1
  92. */
  93. public const USER_AGENT_THUNDERBIRD_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v.*$/';
  94. /**
  95. * @param string $name
  96. *
  97. * @return string
  98. * @since 6.0.0
  99. */
  100. public function getHeader(string $name): string;
  101. /**
  102. * Lets you access post and get parameters by the index
  103. * In case of json requests the encoded json body is accessed
  104. *
  105. * @param string $key the key which you want to access in the URL Parameter
  106. * placeholder, $_POST or $_GET array.
  107. * The priority how they're returned is the following:
  108. * 1. URL parameters
  109. * 2. POST parameters
  110. * 3. GET parameters
  111. * @param mixed $default If the key is not found, this value will be returned
  112. * @return mixed the content of the array
  113. * @since 6.0.0
  114. */
  115. public function getParam(string $key, $default = null);
  116. /**
  117. * Returns all params that were received, be it from the request
  118. *
  119. * (as GET or POST) or through the URL by the route
  120. *
  121. * @return array the array with all parameters
  122. * @since 6.0.0
  123. */
  124. public function getParams(): array;
  125. /**
  126. * Returns the method of the request
  127. *
  128. * @return string the method of the request (POST, GET, etc)
  129. * @since 6.0.0
  130. */
  131. public function getMethod(): string;
  132. /**
  133. * Shortcut for accessing an uploaded file through the $_FILES array
  134. *
  135. * @param string $key the key that will be taken from the $_FILES array
  136. * @return array the file in the $_FILES element
  137. * @since 6.0.0
  138. */
  139. public function getUploadedFile(string $key);
  140. /**
  141. * Shortcut for getting env variables
  142. *
  143. * @param string $key the key that will be taken from the $_ENV array
  144. * @return array the value in the $_ENV element
  145. * @since 6.0.0
  146. */
  147. public function getEnv(string $key);
  148. /**
  149. * Shortcut for getting cookie variables
  150. *
  151. * @param string $key the key that will be taken from the $_COOKIE array
  152. * @return string|null the value in the $_COOKIE element
  153. * @since 6.0.0
  154. */
  155. public function getCookie(string $key);
  156. /**
  157. * Checks if the CSRF check was correct
  158. *
  159. * @return bool true if CSRF check passed
  160. * @since 6.0.0
  161. */
  162. public function passesCSRFCheck(): bool;
  163. /**
  164. * Checks if the strict cookie has been sent with the request if the request
  165. * is including any cookies.
  166. *
  167. * @return bool
  168. * @since 9.0.0
  169. */
  170. public function passesStrictCookieCheck(): bool;
  171. /**
  172. * Checks if the lax cookie has been sent with the request if the request
  173. * is including any cookies.
  174. *
  175. * @return bool
  176. * @since 9.0.0
  177. */
  178. public function passesLaxCookieCheck(): bool;
  179. /**
  180. * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
  181. * If `mod_unique_id` is installed this value will be taken.
  182. *
  183. * @return string
  184. * @since 8.1.0
  185. */
  186. public function getId(): string;
  187. /**
  188. * Returns the remote address, if the connection came from a trusted proxy
  189. * and `forwarded_for_headers` has been configured then the IP address
  190. * specified in this header will be returned instead.
  191. * Do always use this instead of $_SERVER['REMOTE_ADDR']
  192. *
  193. * @return string IP address
  194. * @since 8.1.0
  195. */
  196. public function getRemoteAddress(): string;
  197. /**
  198. * Returns the server protocol. It respects reverse proxy servers and load
  199. * balancers.
  200. *
  201. * @return string Server protocol (http or https)
  202. * @since 8.1.0
  203. */
  204. public function getServerProtocol(): string;
  205. /**
  206. * Returns the used HTTP protocol.
  207. *
  208. * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
  209. * @since 8.2.0
  210. */
  211. public function getHttpProtocol(): string;
  212. /**
  213. * Returns the request uri, even if the website uses one or more
  214. * reverse proxies
  215. *
  216. * @return string
  217. * @since 8.1.0
  218. */
  219. public function getRequestUri(): string;
  220. /**
  221. * Get raw PathInfo from request (not urldecoded)
  222. *
  223. * @throws \Exception
  224. * @return string Path info
  225. * @since 8.1.0
  226. */
  227. public function getRawPathInfo(): string;
  228. /**
  229. * Get PathInfo from request
  230. *
  231. * @throws \Exception
  232. * @return string|false Path info or false when not found
  233. * @since 8.1.0
  234. */
  235. public function getPathInfo();
  236. /**
  237. * Returns the script name, even if the website uses one or more
  238. * reverse proxies
  239. *
  240. * @return string the script name
  241. * @since 8.1.0
  242. */
  243. public function getScriptName(): string;
  244. /**
  245. * Checks whether the user agent matches a given regex
  246. *
  247. * @param array $agent array of agent names
  248. * @return bool true if at least one of the given agent matches, false otherwise
  249. * @since 8.1.0
  250. */
  251. public function isUserAgent(array $agent): bool;
  252. /**
  253. * Returns the unverified server host from the headers without checking
  254. * whether it is a trusted domain
  255. *
  256. * @return string Server host
  257. * @since 8.1.0
  258. */
  259. public function getInsecureServerHost(): string;
  260. /**
  261. * Returns the server host from the headers, or the first configured
  262. * trusted domain if the host isn't in the trusted list
  263. *
  264. * @return string Server host
  265. * @since 8.1.0
  266. */
  267. public function getServerHost(): string;
  268. }