setupchecks.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. /**
  13. * Check whether the WebDAV connection works.
  14. *
  15. * @return $.Deferred object resolved with an array of error messages
  16. */
  17. checkWebDAV: function() {
  18. var deferred = $.Deferred();
  19. var afterCall = function(xhr) {
  20. var messages = [];
  21. if (xhr.status !== 207 && xhr.status !== 401) {
  22. messages.push(
  23. t('core', 'Your web server is not yet set up properly to allow file synchronization because the WebDAV interface seems to be broken.')
  24. );
  25. }
  26. deferred.resolve(messages);
  27. };
  28. $.ajax({
  29. type: 'PROPFIND',
  30. url: OC.linkToRemoteBase('webdav'),
  31. data: '<?xml version="1.0"?>' +
  32. '<d:propfind xmlns:d="DAV:">' +
  33. '<d:prop><d:resourcetype/></d:prop>' +
  34. '</d:propfind>',
  35. complete: afterCall
  36. });
  37. return deferred.promise();
  38. },
  39. /**
  40. * Runs setup checks on the server side
  41. *
  42. * @return $.Deferred object resolved with an array of error messages
  43. */
  44. checkSetup: function() {
  45. var deferred = $.Deferred();
  46. var afterCall = function(data, statusText, xhr) {
  47. var messages = [];
  48. if (xhr.status === 200 && data) {
  49. if (!data.serverHasInternetConnection) {
  50. messages.push(
  51. 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.')
  52. );
  53. }
  54. if(!data.dataDirectoryProtected) {
  55. messages.push(
  56. 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.')
  57. );
  58. }
  59. if(!data.isMemcacheConfigured) {
  60. messages.push(
  61. 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})
  62. );
  63. }
  64. } else {
  65. messages.push(t('core', 'Error occurred while checking server setup'));
  66. }
  67. deferred.resolve(messages);
  68. };
  69. $.ajax({
  70. type: 'GET',
  71. url: OC.generateUrl('settings/ajax/checksetup')
  72. }).then(afterCall, afterCall);
  73. return deferred.promise();
  74. },
  75. /**
  76. * Runs generic checks on the server side, the difference to dedicated
  77. * methods is that we use the same XHR object for all checks to save
  78. * requests.
  79. *
  80. * @return $.Deferred object resolved with an array of error messages
  81. */
  82. checkGeneric: function() {
  83. var self = this;
  84. var deferred = $.Deferred();
  85. var afterCall = function(data, statusText, xhr) {
  86. var messages = [];
  87. messages = messages.concat(self._checkSecurityHeaders(xhr));
  88. messages = messages.concat(self._checkSSL(xhr));
  89. deferred.resolve(messages);
  90. };
  91. $.ajax({
  92. type: 'GET',
  93. url: OC.generateUrl('heartbeat')
  94. }).then(afterCall, afterCall);
  95. return deferred.promise();
  96. },
  97. /**
  98. * Runs check for some generic security headers on the server side
  99. *
  100. * @param {Object} xhr
  101. * @return {Array} Array with error messages
  102. */
  103. _checkSecurityHeaders: function(xhr) {
  104. var messages = [];
  105. if (xhr.status === 200) {
  106. var securityHeaders = {
  107. 'X-XSS-Protection': '1; mode=block',
  108. 'X-Content-Type-Options': 'nosniff',
  109. 'X-Robots-Tag': 'none',
  110. 'X-Frame-Options': 'SAMEORIGIN'
  111. };
  112. for (var header in securityHeaders) {
  113. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== securityHeaders[header].toLowerCase()) {
  114. messages.push(
  115. 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]})
  116. );
  117. }
  118. }
  119. } else {
  120. messages.push(t('core', 'Error occurred while checking server setup'));
  121. }
  122. return messages;
  123. },
  124. /**
  125. * Runs check for some SSL configuration issues on the server side
  126. *
  127. * @param {Object} xhr
  128. * @return {Array} Array with error messages
  129. */
  130. _checkSSL: function(xhr) {
  131. var messages = [];
  132. if (xhr.status === 200) {
  133. if(OC.getProtocol() === 'https') {
  134. // Extract the value of 'Strict-Transport-Security'
  135. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  136. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  137. var firstComma = transportSecurityValidity.indexOf(";");
  138. if(firstComma !== -1) {
  139. transportSecurityValidity = transportSecurityValidity.substring(0, firstComma);
  140. } else {
  141. transportSecurityValidity = transportSecurityValidity.substring(8);
  142. }
  143. }
  144. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= 2678399) {
  145. messages.push(
  146. t('core', 'The "Strict-Transport-Security" HTTP header is not configured to least "2,678,400" seconds. This is a potential security risk and we recommend adjusting this setting.')
  147. );
  148. }
  149. } else {
  150. messages.push(
  151. t('core', 'You are accessing this site via HTTP. We strongly suggest you configure your server to require using HTTPS instead.')
  152. );
  153. }
  154. } else {
  155. messages.push(t('core', 'Error occurred while checking server setup'));
  156. }
  157. return messages;
  158. }
  159. };
  160. })();