setupchecks.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 properly set up 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 properly set up to resolve "{url}". Further information can be found in the <a target="_blank" rel="noreferrer noopener" 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. allowAuthErrors: true
  75. });
  76. return deferred.promise();
  77. },
  78. /**
  79. * Runs setup checks on the server side
  80. *
  81. * @return $.Deferred object resolved with an array of error messages
  82. */
  83. checkSetup: function() {
  84. var deferred = $.Deferred();
  85. var afterCall = function(data, statusText, xhr) {
  86. var messages = [];
  87. if (xhr.status === 200 && data) {
  88. if (!data.serverHasInternetConnection) {
  89. messages.push({
  90. msg: t('core', 'This server has no working Internet connection: Multiple endpoints could not be reached. 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. Establish a connection from this server to the Internet to enjoy all features.'),
  91. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  92. });
  93. }
  94. if(!data.isMemcacheConfigured) {
  95. messages.push({
  96. msg: t('core', 'No memory cache has been configured. To enhance performance, please configure a memcache, if available. Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', {docLink: data.memcacheDocs}),
  97. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  98. });
  99. }
  100. if(!data.isUrandomAvailable) {
  101. messages.push({
  102. msg: t('core', '/dev/urandom is not readable by PHP which is highly discouraged for security reasons. Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', {docLink: data.securityDocs}),
  103. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  104. });
  105. }
  106. if(data.isUsedTlsLibOutdated) {
  107. messages.push({
  108. msg: data.isUsedTlsLibOutdated,
  109. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  110. });
  111. }
  112. if(data.phpSupported && data.phpSupported.eol) {
  113. messages.push({
  114. msg: t('core', 'You are currently running PHP {version}. Upgrade your PHP version to take advantage of <a target="_blank" rel="noreferrer noopener" 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'}),
  115. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  116. });
  117. }
  118. if(data.phpSupported && data.phpSupported.version.substr(0, 3) === '5.6') {
  119. messages.push({
  120. msg: t('core', 'You are currently running PHP 5.6. The current major version of Nextcloud is the last that is supported on PHP 5.6. It is recommended to upgrade the PHP version to 7.0+ to be able to upgrade to Nextcloud 14.'),
  121. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  122. });
  123. }
  124. if(!data.forwardedForHeadersWorking) {
  125. messages.push({
  126. msg: t('core', 'The reverse proxy header configuration is incorrect, or you are accessing Nextcloud from a trusted proxy. If not, this is a security issue and can allow an attacker to spoof their IP address as visible to the Nextcloud. Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', {docLink: data.reverseProxyDocs}),
  127. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  128. });
  129. }
  130. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  131. messages.push({
  132. 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 noopener" href="{wikiLink}">memcached wiki about both modules</a>.', {wikiLink: 'https://code.google.com/p/memcached/wiki/PHPClientComparison'}),
  133. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  134. });
  135. }
  136. if(!data.hasPassedCodeIntegrityCheck) {
  137. messages.push({
  138. msg: t(
  139. 'core',
  140. 'Some files have not passed the integrity check. Further information on how to resolve this issue can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>. (<a href="{codeIntegrityDownloadEndpoint}">List of invalid files…</a> / <a href="{rescanEndpoint}">Rescan…</a>)',
  141. {
  142. docLink: data.codeIntegrityCheckerDocumentation,
  143. codeIntegrityDownloadEndpoint: OC.generateUrl('/settings/integrity/failed'),
  144. rescanEndpoint: OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken})
  145. }
  146. ),
  147. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  148. });
  149. }
  150. if(!data.isOpcacheProperlySetup) {
  151. messages.push({
  152. msg: t(
  153. 'core',
  154. 'The PHP OPcache is not properly configured. <a target="_blank" rel="noreferrer noopener" href="{docLink}">For better performance it is recommended</a> to use the following settings in the <code>php.ini</code>:',
  155. {
  156. docLink: data.phpOpcacheDocumentation,
  157. }
  158. ) + "<pre><code>opcache.enable=1\nopcache.enable_cli=1\nopcache.interned_strings_buffer=8\nopcache.max_accelerated_files=10000\nopcache.memory_consumption=128\nopcache.save_comments=1\nopcache.revalidate_freq=1</code></pre>",
  159. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  160. });
  161. }
  162. if(!data.isSettimelimitAvailable) {
  163. messages.push({
  164. msg: t(
  165. 'core',
  166. 'The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.'),
  167. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  168. });
  169. }
  170. if (!data.hasFreeTypeSupport) {
  171. messages.push({
  172. msg: t(
  173. 'core',
  174. 'Your PHP does not have FreeType support, resulting in breakage of profile pictures and the settings interface.'
  175. ),
  176. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  177. })
  178. }
  179. } else {
  180. messages.push({
  181. msg: t('core', 'Error occurred while checking server setup'),
  182. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  183. });
  184. }
  185. deferred.resolve(messages);
  186. };
  187. $.ajax({
  188. type: 'GET',
  189. url: OC.generateUrl('settings/ajax/checksetup'),
  190. allowAuthErrors: true
  191. }).then(afterCall, afterCall);
  192. return deferred.promise();
  193. },
  194. /**
  195. * Runs generic checks on the server side, the difference to dedicated
  196. * methods is that we use the same XHR object for all checks to save
  197. * requests.
  198. *
  199. * @return $.Deferred object resolved with an array of error messages
  200. */
  201. checkGeneric: function() {
  202. var self = this;
  203. var deferred = $.Deferred();
  204. var afterCall = function(data, statusText, xhr) {
  205. var messages = [];
  206. messages = messages.concat(self._checkSecurityHeaders(xhr));
  207. messages = messages.concat(self._checkSSL(xhr));
  208. deferred.resolve(messages);
  209. };
  210. $.ajax({
  211. type: 'GET',
  212. url: OC.generateUrl('heartbeat'),
  213. allowAuthErrors: true
  214. }).then(afterCall, afterCall);
  215. return deferred.promise();
  216. },
  217. checkDataProtected: function() {
  218. var deferred = $.Deferred();
  219. if(oc_dataURL === false){
  220. return deferred.resolve([]);
  221. }
  222. var afterCall = function(xhr) {
  223. var messages = [];
  224. // .ocdata is an empty file in the data directory - if this is readable then the data dir is not protected
  225. if (xhr.status === 200 && xhr.responseText === '') {
  226. messages.push({
  227. msg: t('core', 'Your data directory and files are probably accessible from the Internet. The .htaccess file is not working. It is strongly recommended that you configure your web server so that the data directory is no longer accessible, or move the data directory outside the web server document root.'),
  228. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  229. });
  230. }
  231. deferred.resolve(messages);
  232. };
  233. $.ajax({
  234. type: 'GET',
  235. url: OC.linkTo('', oc_dataURL+'/.ocdata?t=' + (new Date()).getTime()),
  236. complete: afterCall,
  237. allowAuthErrors: true
  238. });
  239. return deferred.promise();
  240. },
  241. /**
  242. * Runs check for some generic security headers on the server side
  243. *
  244. * @param {Object} xhr
  245. * @return {Array} Array with error messages
  246. */
  247. _checkSecurityHeaders: function(xhr) {
  248. var messages = [];
  249. if (xhr.status === 200) {
  250. var securityHeaders = {
  251. 'X-XSS-Protection': ['1; mode=block'],
  252. 'X-Content-Type-Options': ['nosniff'],
  253. 'X-Robots-Tag': ['none'],
  254. 'X-Frame-Options': ['SAMEORIGIN', 'DENY'],
  255. 'X-Download-Options': ['noopen'],
  256. 'X-Permitted-Cross-Domain-Policies': ['none'],
  257. };
  258. for (var header in securityHeaders) {
  259. var option = securityHeaders[header][0];
  260. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== option.toLowerCase()) {
  261. var msg = t('core', 'The "{header}" HTTP header is not set to "{expected}". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', {header: header, expected: option});
  262. if(xhr.getResponseHeader(header) && securityHeaders[header].length > 1 && xhr.getResponseHeader(header).toLowerCase() === securityHeaders[header][1].toLowerCase()) {
  263. msg = t('core', 'The "{header}" HTTP header is not set to "{expected}". Some features might not work correctly, as it is recommended to adjust this setting accordingly.', {header: header, expected: option});
  264. }
  265. messages.push({
  266. msg: msg,
  267. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  268. });
  269. }
  270. }
  271. } else {
  272. messages.push({
  273. msg: t('core', 'Error occurred while checking server setup'),
  274. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  275. });
  276. }
  277. return messages;
  278. },
  279. /**
  280. * Runs check for some SSL configuration issues on the server side
  281. *
  282. * @param {Object} xhr
  283. * @return {Array} Array with error messages
  284. */
  285. _checkSSL: function(xhr) {
  286. var messages = [];
  287. if (xhr.status === 200) {
  288. var tipsUrl = OC.generateUrl('settings/admin/tips-tricks');
  289. if(OC.getProtocol() === 'https') {
  290. // Extract the value of 'Strict-Transport-Security'
  291. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  292. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  293. var firstComma = transportSecurityValidity.indexOf(";");
  294. if(firstComma !== -1) {
  295. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  296. } else {
  297. transportSecurityValidity = transportSecurityValidity.substring(8);
  298. }
  299. }
  300. var minimumSeconds = 15552000;
  301. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  302. messages.push({
  303. msg: t('core', 'The "Strict-Transport-Security" HTTP header is not set to at least "{seconds}" seconds. For enhanced security, it is recommended to enable HSTS as described in the <a href="{docUrl}" rel="noreferrer noopener">security tips</a>.', {'seconds': minimumSeconds, docUrl: tipsUrl}),
  304. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  305. });
  306. }
  307. } else {
  308. messages.push({
  309. msg: t('core', 'Accessing site insecurely via HTTP. You are strongly adviced to set up your server to require HTTPS instead, as described in the <a href="{docUrl}">security tips</a>.', {docUrl: tipsUrl}),
  310. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  311. });
  312. }
  313. } else {
  314. messages.push({
  315. msg: t('core', 'Error occurred while checking server setup'),
  316. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  317. });
  318. }
  319. return messages;
  320. }
  321. };
  322. })();