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.

setupchecks.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. * Runs setup checks on the server side
  46. *
  47. * @return $.Deferred object resolved with an array of error messages
  48. */
  49. checkSetup: function() {
  50. var deferred = $.Deferred();
  51. var afterCall = function(data, statusText, xhr) {
  52. var messages = [];
  53. if (xhr.status === 200 && data) {
  54. if (!data.serverHasInternetConnection) {
  55. messages.push({
  56. 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.'),
  57. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  58. });
  59. }
  60. if(!data.dataDirectoryProtected) {
  61. messages.push({
  62. 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.'),
  63. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  64. });
  65. }
  66. if(!data.isMemcacheConfigured) {
  67. messages.push({
  68. 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 href="{docLink}">documentation</a>.', {docLink: data.memcacheDocs}),
  69. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  70. });
  71. }
  72. if(!data.isUrandomAvailable) {
  73. messages.push({
  74. 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 href="{docLink}">documentation</a>.', {docLink: data.securityDocs}),
  75. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  76. });
  77. }
  78. if(data.isUsedTlsLibOutdated) {
  79. messages.push({
  80. msg: data.isUsedTlsLibOutdated,
  81. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  82. });
  83. }
  84. if(data.phpSupported && data.phpSupported.eol) {
  85. messages.push({
  86. msg: t('core', 'Your PHP version ({version}) is no longer <a 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'}),
  87. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  88. });
  89. }
  90. if(!data.forwardedForHeadersWorking) {
  91. messages.push({
  92. 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 href="{docLink}">documentation</a>.', {docLink: data.reverseProxyDocs}),
  93. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  94. });
  95. }
  96. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  97. messages.push({
  98. 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 href="{wikiLink}">memcached wiki about both modules</a>.', {wikiLink: 'https://code.google.com/p/memcached/wiki/PHPClientComparison'}),
  99. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  100. });
  101. }
  102. } else {
  103. messages.push({
  104. msg: t('core', 'Error occurred while checking server setup'),
  105. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  106. });
  107. }
  108. deferred.resolve(messages);
  109. };
  110. $.ajax({
  111. type: 'GET',
  112. url: OC.generateUrl('settings/ajax/checksetup')
  113. }).then(afterCall, afterCall);
  114. return deferred.promise();
  115. },
  116. /**
  117. * Runs generic checks on the server side, the difference to dedicated
  118. * methods is that we use the same XHR object for all checks to save
  119. * requests.
  120. *
  121. * @return $.Deferred object resolved with an array of error messages
  122. */
  123. checkGeneric: function() {
  124. var self = this;
  125. var deferred = $.Deferred();
  126. var afterCall = function(data, statusText, xhr) {
  127. var messages = [];
  128. messages = messages.concat(self._checkSecurityHeaders(xhr));
  129. messages = messages.concat(self._checkSSL(xhr));
  130. deferred.resolve(messages);
  131. };
  132. $.ajax({
  133. type: 'GET',
  134. url: OC.generateUrl('heartbeat')
  135. }).then(afterCall, afterCall);
  136. return deferred.promise();
  137. },
  138. /**
  139. * Runs check for some generic security headers on the server side
  140. *
  141. * @param {Object} xhr
  142. * @return {Array} Array with error messages
  143. */
  144. _checkSecurityHeaders: function(xhr) {
  145. var messages = [];
  146. if (xhr.status === 200) {
  147. var securityHeaders = {
  148. 'X-XSS-Protection': '1; mode=block',
  149. 'X-Content-Type-Options': 'nosniff',
  150. 'X-Robots-Tag': 'none',
  151. 'X-Frame-Options': 'SAMEORIGIN'
  152. };
  153. for (var header in securityHeaders) {
  154. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== securityHeaders[header].toLowerCase()) {
  155. messages.push({
  156. 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]}),
  157. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  158. });
  159. }
  160. }
  161. } else {
  162. messages.push({
  163. msg: t('core', 'Error occurred while checking server setup'),
  164. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  165. });
  166. }
  167. return messages;
  168. },
  169. /**
  170. * Runs check for some SSL configuration issues on the server side
  171. *
  172. * @param {Object} xhr
  173. * @return {Array} Array with error messages
  174. */
  175. _checkSSL: function(xhr) {
  176. var messages = [];
  177. if (xhr.status === 200) {
  178. if(OC.getProtocol() === 'https') {
  179. // Extract the value of 'Strict-Transport-Security'
  180. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  181. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  182. var firstComma = transportSecurityValidity.indexOf(";");
  183. if(firstComma !== -1) {
  184. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  185. } else {
  186. transportSecurityValidity = transportSecurityValidity.substring(8);
  187. }
  188. }
  189. var minimumSeconds = 15768000;
  190. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  191. messages.push({
  192. 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'}),
  193. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  194. });
  195. }
  196. } else {
  197. messages.push({
  198. 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'}),
  199. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  200. });
  201. }
  202. } else {
  203. messages.push({
  204. msg: t('core', 'Error occurred while checking server setup'),
  205. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  206. });
  207. }
  208. return messages;
  209. }
  210. };
  211. })();