setupchecks.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. allowAuthErrors: true
  42. });
  43. return deferred.promise();
  44. },
  45. /**
  46. * Check whether the .well-known URLs works.
  47. *
  48. * @param url the URL to test
  49. * @param placeholderUrl the placeholder URL - can be found at oc_defaults.docPlaceholderUrl
  50. * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
  51. * @return $.Deferred object resolved with an array of error messages
  52. */
  53. checkWellKnownUrl: function(url, placeholderUrl, runCheck) {
  54. var deferred = $.Deferred();
  55. if(runCheck === false) {
  56. deferred.resolve([]);
  57. return deferred.promise();
  58. }
  59. var afterCall = function(xhr) {
  60. var messages = [];
  61. if (xhr.status !== 207) {
  62. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
  63. messages.push({
  64. msg: t('core', 'Your web server is not set up properly to resolve "{url}". Further information can be found in our <a target="_blank" rel="noreferrer" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }),
  65. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  66. });
  67. }
  68. deferred.resolve(messages);
  69. };
  70. $.ajax({
  71. type: 'PROPFIND',
  72. url: url,
  73. complete: afterCall
  74. });
  75. return deferred.promise();
  76. },
  77. /**
  78. * Runs setup checks on the server side
  79. *
  80. * @return $.Deferred object resolved with an array of error messages
  81. */
  82. checkSetup: function() {
  83. var deferred = $.Deferred();
  84. var afterCall = function(data, statusText, xhr) {
  85. var messages = [];
  86. if (xhr.status === 200 && data) {
  87. if (!data.serverHasInternetConnection) {
  88. messages.push({
  89. 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.'),
  90. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  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" rel="noreferrer" 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" rel="noreferrer" 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', 'You are currently running PHP {version}. We encourage you to upgrade your PHP version to take advantage of <a target="_blank" rel="noreferrer" href="{phpLink}">performance and security updates provided by the PHP Group</a> as soon as your distribution supports it.', {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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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. allowAuthErrors: true
  155. }).then(afterCall, afterCall);
  156. return deferred.promise();
  157. },
  158. /**
  159. * Runs generic checks on the server side, the difference to dedicated
  160. * methods is that we use the same XHR object for all checks to save
  161. * requests.
  162. *
  163. * @return $.Deferred object resolved with an array of error messages
  164. */
  165. checkGeneric: function() {
  166. var self = this;
  167. var deferred = $.Deferred();
  168. var afterCall = function(data, statusText, xhr) {
  169. var messages = [];
  170. messages = messages.concat(self._checkSecurityHeaders(xhr));
  171. messages = messages.concat(self._checkSSL(xhr));
  172. deferred.resolve(messages);
  173. };
  174. $.ajax({
  175. type: 'GET',
  176. url: OC.generateUrl('heartbeat'),
  177. allowAuthErrors: true
  178. }).then(afterCall, afterCall);
  179. return deferred.promise();
  180. },
  181. checkDataProtected: function() {
  182. var deferred = $.Deferred();
  183. if(oc_dataURL === false){
  184. return deferred.resolve([]);
  185. }
  186. var afterCall = function(xhr) {
  187. var messages = [];
  188. if (xhr.status !== 403 && xhr.status !== 307 && xhr.status !== 301 && xhr.responseText !== '') {
  189. messages.push({
  190. 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.'),
  191. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  192. });
  193. }
  194. deferred.resolve(messages);
  195. };
  196. $.ajax({
  197. type: 'GET',
  198. url: OC.linkTo('', oc_dataURL+'/htaccesstest.txt?t=' + (new Date()).getTime()),
  199. complete: afterCall
  200. });
  201. return deferred.promise();
  202. },
  203. /**
  204. * Runs check for some generic security headers on the server side
  205. *
  206. * @param {Object} xhr
  207. * @return {Array} Array with error messages
  208. */
  209. _checkSecurityHeaders: function(xhr) {
  210. var messages = [];
  211. if (xhr.status === 200) {
  212. var securityHeaders = {
  213. 'X-XSS-Protection': '1; mode=block',
  214. 'X-Content-Type-Options': 'nosniff',
  215. 'X-Robots-Tag': 'none',
  216. 'X-Frame-Options': 'SAMEORIGIN',
  217. 'X-Download-Options': 'noopen',
  218. 'X-Permitted-Cross-Domain-Policies': 'none',
  219. };
  220. for (var header in securityHeaders) {
  221. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== securityHeaders[header].toLowerCase()) {
  222. messages.push({
  223. 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]}),
  224. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  225. });
  226. }
  227. }
  228. } else {
  229. messages.push({
  230. msg: t('core', 'Error occurred while checking server setup'),
  231. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  232. });
  233. }
  234. return messages;
  235. },
  236. /**
  237. * Runs check for some SSL configuration issues on the server side
  238. *
  239. * @param {Object} xhr
  240. * @return {Array} Array with error messages
  241. */
  242. _checkSSL: function(xhr) {
  243. var messages = [];
  244. if (xhr.status === 200) {
  245. if(OC.getProtocol() === 'https') {
  246. // Extract the value of 'Strict-Transport-Security'
  247. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  248. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  249. var firstComma = transportSecurityValidity.indexOf(";");
  250. if(firstComma !== -1) {
  251. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  252. } else {
  253. transportSecurityValidity = transportSecurityValidity.substring(8);
  254. }
  255. }
  256. var minimumSeconds = 15552000;
  257. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  258. messages.push({
  259. msg: t('core', 'The "Strict-Transport-Security" HTTP header is not configured to at least "{seconds}" seconds. For enhanced security we recommend enabling HSTS as described in our <a href="{docUrl}" rel="noreferrer">security tips</a>.', {'seconds': minimumSeconds, docUrl: '#admin-tips'}),
  260. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  261. });
  262. }
  263. } else {
  264. messages.push({
  265. 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'}),
  266. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  267. });
  268. }
  269. } else {
  270. messages.push({
  271. msg: t('core', 'Error occurred while checking server setup'),
  272. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  273. });
  274. }
  275. return messages;
  276. }
  277. };
  278. })();