setupchecks.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Copyright (c) 2014
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function() {
  11. OC.SetupChecks = {
  12. /* Message types */
  13. MESSAGE_TYPE_INFO:0,
  14. MESSAGE_TYPE_WARNING:1,
  15. MESSAGE_TYPE_ERROR:2,
  16. /**
  17. * Check whether the WebDAV connection works.
  18. *
  19. * @return $.Deferred object resolved with an array of error messages
  20. */
  21. checkWebDAV: function() {
  22. var deferred = $.Deferred();
  23. var afterCall = function(xhr) {
  24. var messages = [];
  25. if (xhr.status !== 207 && xhr.status !== 401) {
  26. messages.push({
  27. msg: t('core', 'Your web server is not yet set up properly to allow file synchronization because the WebDAV interface seems to be broken.'),
  28. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  29. });
  30. }
  31. deferred.resolve(messages);
  32. };
  33. $.ajax({
  34. type: 'PROPFIND',
  35. url: OC.linkToRemoteBase('webdav'),
  36. data: '<?xml version="1.0"?>' +
  37. '<d:propfind xmlns:d="DAV:">' +
  38. '<d:prop><d:resourcetype/></d:prop>' +
  39. '</d:propfind>',
  40. complete: afterCall
  41. });
  42. return deferred.promise();
  43. },
  44. /**
  45. * Check whether the .well-known URLs works.
  46. *
  47. * @param url the URL to test
  48. * @param placeholderUrl the placeholder URL - can be found at oc_defaults.docPlaceholderUrl
  49. * @return $.Deferred object resolved with an array of error messages
  50. */
  51. checkWellKnownUrl: function(url, placeholderUrl) {
  52. var deferred = $.Deferred();
  53. var afterCall = function(xhr) {
  54. var messages = [];
  55. if (xhr.status !== 207) {
  56. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
  57. messages.push({
  58. msg: t('core', 'Your web server is not set up properly to resolve "{url}". Further information can be found in our <a target="_blank" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }),
  59. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  60. });
  61. }
  62. deferred.resolve(messages);
  63. };
  64. $.ajax({
  65. type: 'PROPFIND',
  66. url: url,
  67. complete: afterCall
  68. });
  69. return deferred.promise();
  70. },
  71. /**
  72. * Runs setup checks on the server side
  73. *
  74. * @return $.Deferred object resolved with an array of error messages
  75. */
  76. checkSetup: function() {
  77. var deferred = $.Deferred();
  78. var afterCall = function(data, statusText, xhr) {
  79. var messages = [];
  80. if (xhr.status === 200 && data) {
  81. if (!data.serverHasInternetConnection) {
  82. messages.push({
  83. msg: t('core', 'This server has no working Internet connection. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. We suggest to enable Internet connection for this server if you want to have all features.'),
  84. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  85. });
  86. }
  87. if(!data.dataDirectoryProtected) {
  88. messages.push({
  89. msg: t('core', 'Your data directory and your files are probably accessible from the Internet. The .htaccess file is not working. We strongly suggest that you configure your web server in a way that the data directory is no longer accessible or you move the data directory outside the web server document root.'),
  90. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  91. });
  92. }
  93. if(!data.isMemcacheConfigured) {
  94. messages.push({
  95. msg: t('core', 'No memory cache has been configured. To enhance your performance please configure a memcache if available. Further information can be found in our <a target="_blank" href="{docLink}">documentation</a>.', {docLink: data.memcacheDocs}),
  96. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  97. });
  98. }
  99. if(!data.isUrandomAvailable) {
  100. messages.push({
  101. msg: t('core', '/dev/urandom is not readable by PHP which is highly discouraged for security reasons. Further information can be found in our <a target="_blank" href="{docLink}">documentation</a>.', {docLink: data.securityDocs}),
  102. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  103. });
  104. }
  105. if(data.isUsedTlsLibOutdated) {
  106. messages.push({
  107. msg: data.isUsedTlsLibOutdated,
  108. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  109. });
  110. }
  111. if(data.phpSupported && data.phpSupported.eol) {
  112. messages.push({
  113. msg: t('core', 'Your PHP version ({version}) is no longer <a target="_blank" href="{phpLink}">supported by PHP</a>. We encourage you to upgrade your PHP version to take advantage of performance and security updates provided by PHP.', {version: data.phpSupported.version, phpLink: 'https://secure.php.net/supported-versions.php'}),
  114. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  115. });
  116. }
  117. if(!data.forwardedForHeadersWorking) {
  118. messages.push({
  119. msg: t('core', 'The reverse proxy headers configuration is incorrect, or you are accessing ownCloud from a trusted proxy. If you are not accessing ownCloud from a trusted proxy, this is a security issue and can allow an attacker to spoof their IP address as visible to ownCloud. Further information can be found in our <a target="_blank" href="{docLink}">documentation</a>.', {docLink: data.reverseProxyDocs}),
  120. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  121. });
  122. }
  123. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  124. messages.push({
  125. msg: t('core', 'Memcached is configured as distributed cache, but the wrong PHP module "memcache" is installed. \\OC\\Memcache\\Memcached only supports "memcached" and not "memcache". See the <a target="_blank" href="{wikiLink}">memcached wiki about both modules</a>.', {wikiLink: 'https://code.google.com/p/memcached/wiki/PHPClientComparison'}),
  126. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  127. });
  128. }
  129. if(!data.hasPassedCodeIntegrityCheck) {
  130. messages.push({
  131. msg: t(
  132. 'core',
  133. 'Some files have not passed the integrity check. Further information on how to resolve this issue can be found in our <a target="_blank" href="{docLink}">documentation</a>. (<a href="{codeIntegrityDownloadEndpoint}">List of invalid files…</a> / <a href="{rescanEndpoint}">Rescan…</a>)',
  134. {
  135. docLink: data.codeIntegrityCheckerDocumentation,
  136. codeIntegrityDownloadEndpoint: OC.generateUrl('/settings/integrity/failed'),
  137. rescanEndpoint: OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken})
  138. }
  139. ),
  140. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  141. });
  142. }
  143. } else {
  144. messages.push({
  145. msg: t('core', 'Error occurred while checking server setup'),
  146. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  147. });
  148. }
  149. deferred.resolve(messages);
  150. };
  151. $.ajax({
  152. type: 'GET',
  153. url: OC.generateUrl('settings/ajax/checksetup')
  154. }).then(afterCall, afterCall);
  155. return deferred.promise();
  156. },
  157. /**
  158. * Runs generic checks on the server side, the difference to dedicated
  159. * methods is that we use the same XHR object for all checks to save
  160. * requests.
  161. *
  162. * @return $.Deferred object resolved with an array of error messages
  163. */
  164. checkGeneric: function() {
  165. var self = this;
  166. var deferred = $.Deferred();
  167. var afterCall = function(data, statusText, xhr) {
  168. var messages = [];
  169. messages = messages.concat(self._checkSecurityHeaders(xhr));
  170. messages = messages.concat(self._checkSSL(xhr));
  171. deferred.resolve(messages);
  172. };
  173. $.ajax({
  174. type: 'GET',
  175. url: OC.generateUrl('heartbeat')
  176. }).then(afterCall, afterCall);
  177. return deferred.promise();
  178. },
  179. /**
  180. * Runs check for some generic security headers on the server side
  181. *
  182. * @param {Object} xhr
  183. * @return {Array} Array with error messages
  184. */
  185. _checkSecurityHeaders: function(xhr) {
  186. var messages = [];
  187. if (xhr.status === 200) {
  188. var securityHeaders = {
  189. 'X-XSS-Protection': '1; mode=block',
  190. 'X-Content-Type-Options': 'nosniff',
  191. 'X-Robots-Tag': 'none',
  192. 'X-Frame-Options': 'SAMEORIGIN',
  193. 'X-Download-Options': 'noopen',
  194. 'X-Permitted-Cross-Domain-Policies': 'none',
  195. };
  196. for (var header in securityHeaders) {
  197. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== securityHeaders[header].toLowerCase()) {
  198. messages.push({
  199. msg: t('core', 'The "{header}" HTTP header is not configured to equal to "{expected}". This is a potential security or privacy risk and we recommend adjusting this setting.', {header: header, expected: securityHeaders[header]}),
  200. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  201. });
  202. }
  203. }
  204. } else {
  205. messages.push({
  206. msg: t('core', 'Error occurred while checking server setup'),
  207. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  208. });
  209. }
  210. return messages;
  211. },
  212. /**
  213. * Runs check for some SSL configuration issues on the server side
  214. *
  215. * @param {Object} xhr
  216. * @return {Array} Array with error messages
  217. */
  218. _checkSSL: function(xhr) {
  219. var messages = [];
  220. if (xhr.status === 200) {
  221. if(OC.getProtocol() === 'https') {
  222. // Extract the value of 'Strict-Transport-Security'
  223. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  224. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  225. var firstComma = transportSecurityValidity.indexOf(";");
  226. if(firstComma !== -1) {
  227. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  228. } else {
  229. transportSecurityValidity = transportSecurityValidity.substring(8);
  230. }
  231. }
  232. var minimumSeconds = 15768000;
  233. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  234. messages.push({
  235. msg: t('core', 'The "Strict-Transport-Security" HTTP header is not configured to least "{seconds}" seconds. For enhanced security we recommend enabling HSTS as described in our <a href="{docUrl}">security tips</a>.', {'seconds': minimumSeconds, docUrl: '#admin-tips'}),
  236. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  237. });
  238. }
  239. } else {
  240. messages.push({
  241. msg: t('core', 'You are accessing this site via HTTP. We strongly suggest you configure your server to require using HTTPS instead as described in our <a href="{docUrl}">security tips</a>.', {docUrl: '#admin-tips'}),
  242. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  243. });
  244. }
  245. } else {
  246. messages.push({
  247. msg: t('core', 'Error occurred while checking server setup'),
  248. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  249. });
  250. }
  251. return messages;
  252. }
  253. };
  254. })();