setupchecks.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. contentType: 'application/xml; charset=utf-8',
  41. complete: afterCall,
  42. allowAuthErrors: true
  43. });
  44. return deferred.promise();
  45. },
  46. /**
  47. * Check whether the .well-known URLs works.
  48. *
  49. * @param url the URL to test
  50. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  51. * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
  52. * @param {int|int[]} expectedStatus the expected HTTP status to be returned by the URL, 207 by default
  53. * @return $.Deferred object resolved with an array of error messages
  54. */
  55. checkWellKnownUrl: function(verb, url, placeholderUrl, runCheck, expectedStatus, checkCustomHeader) {
  56. if (expectedStatus === undefined) {
  57. expectedStatus = [207];
  58. }
  59. if (!Array.isArray(expectedStatus)) {
  60. expectedStatus = [expectedStatus];
  61. }
  62. var deferred = $.Deferred();
  63. if(runCheck === false) {
  64. deferred.resolve([]);
  65. return deferred.promise();
  66. }
  67. var afterCall = function(xhr) {
  68. var messages = [];
  69. var customWellKnown = xhr.getResponseHeader('X-NEXTCLOUD-WELL-KNOWN')
  70. if (expectedStatus.indexOf(xhr.status) === -1 || (checkCustomHeader && !customWellKnown)) {
  71. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
  72. messages.push({
  73. msg: t('core', 'Your web server is not properly set up to resolve "{url}". Further information can be found in the {linkstart}documentation ↗{linkend}.', { url: url })
  74. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">')
  75. .replace('{linkend}', '</a>'),
  76. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  77. });
  78. }
  79. deferred.resolve(messages);
  80. };
  81. $.ajax({
  82. type: verb,
  83. url: url,
  84. complete: afterCall,
  85. allowAuthErrors: true
  86. });
  87. return deferred.promise();
  88. },
  89. /**
  90. * Check whether the .well-known URLs works.
  91. *
  92. * @param url the URL to test
  93. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  94. * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
  95. *
  96. * @return $.Deferred object resolved with an array of error messages
  97. */
  98. checkProviderUrl: function(url, placeholderUrl, runCheck) {
  99. var expectedStatus = [200];
  100. var deferred = $.Deferred();
  101. if(runCheck === false) {
  102. deferred.resolve([]);
  103. return deferred.promise();
  104. }
  105. var afterCall = function(xhr) {
  106. var messages = [];
  107. if (expectedStatus.indexOf(xhr.status) === -1) {
  108. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
  109. messages.push({
  110. msg: t('core', 'Your web server is not properly set up to resolve "{url}". This is most likely related to a web server configuration that was not updated to deliver this folder directly. Please compare your configuration against the shipped rewrite rules in ".htaccess" for Apache or the provided one in the documentation for Nginx at it\'s {linkstart}documentation page ↗{linkend}. On Nginx those are typically the lines starting with "location ~" that need an update.', { docLink: docUrl, url: url })
  111. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">')
  112. .replace('{linkend}', '</a>'),
  113. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  114. });
  115. }
  116. deferred.resolve(messages);
  117. };
  118. $.ajax({
  119. type: 'GET',
  120. url: url,
  121. complete: afterCall,
  122. allowAuthErrors: true
  123. });
  124. return deferred.promise();
  125. },
  126. /**
  127. * Check whether the WOFF2 URLs works.
  128. *
  129. * @param url the URL to test
  130. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  131. * @return $.Deferred object resolved with an array of error messages
  132. */
  133. checkWOFF2Loading: function(url, placeholderUrl) {
  134. var deferred = $.Deferred();
  135. var afterCall = function(xhr) {
  136. var messages = [];
  137. if (xhr.status !== 200) {
  138. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
  139. messages.push({
  140. msg: t('core', 'Your web server is not properly set up to deliver .woff2 files. This is typically an issue with the Nginx configuration. For Nextcloud 15 it needs an adjustement to also deliver .woff2 files. Compare your Nginx configuration to the recommended configuration in our {linkstart}documentation ↗{linkend}.', { docLink: docUrl, url: url })
  141. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">')
  142. .replace('{linkend}', '</a>'),
  143. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  144. });
  145. }
  146. deferred.resolve(messages);
  147. };
  148. $.ajax({
  149. type: 'GET',
  150. url: url,
  151. complete: afterCall,
  152. allowAuthErrors: true
  153. });
  154. return deferred.promise();
  155. },
  156. /**
  157. * Runs setup checks on the server side
  158. *
  159. * @return $.Deferred object resolved with an array of error messages
  160. */
  161. checkSetup: function() {
  162. var deferred = $.Deferred();
  163. var afterCall = function(data, statusText, xhr) {
  164. var messages = [];
  165. if (xhr.status === 200 && data) {
  166. if (data.suggestedOverwriteCliURL !== '') {
  167. messages.push({
  168. msg: t('core', 'Please make sure to set the "overwrite.cli.url" option in your config.php file to the URL that your users mainly use to access this Nextcloud. Suggestion: "{suggestedOverwriteCliURL}". Otherwise there might be problems with the URL generation via cron. (It is possible though that the suggested URL is not the URL that your users mainly use to access this Nextcloud. Best is to double check this in any case.)', {suggestedOverwriteCliURL: data.suggestedOverwriteCliURL}),
  169. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  170. });
  171. }
  172. if (data.cronErrors.length > 0) {
  173. var listOfCronErrors = "";
  174. data.cronErrors.forEach(function(element){
  175. listOfCronErrors += '<li>';
  176. listOfCronErrors += element.error;
  177. listOfCronErrors += ' ';
  178. listOfCronErrors += element.hint;
  179. listOfCronErrors += '</li>';
  180. });
  181. messages.push({
  182. msg: t('core', 'It was not possible to execute the cron job via CLI. The following technical errors have appeared:') + '<ul>' + listOfCronErrors + '</ul>',
  183. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  184. })
  185. }
  186. if (data.cronInfo.diffInSeconds > 3600) {
  187. messages.push({
  188. msg: t('core', 'Last background job execution ran {relativeTime}. Something seems wrong. {linkstart}Check the background job settings ↗{linkend}.', {relativeTime: data.cronInfo.relativeTime})
  189. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.cronInfo.backgroundJobsUrl + '">')
  190. .replace('{linkend}', '</a>'),
  191. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  192. });
  193. }
  194. if (!data.isFairUseOfFreePushService) {
  195. messages.push({
  196. msg: t('core', 'This is the unsupported community build of Nextcloud. Given the size of this instance, performance, reliability and scalability cannot be guaranteed. Push notifications are limited to avoid overloading our free service. Learn more about the benefits of Nextcloud Enterprise at {linkstart}https://nextcloud.com/enterprise{linkend}.')
  197. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://nextcloud.com/enterprise">')
  198. .replace('{linkend}', '</a>'),
  199. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  200. });
  201. }
  202. if(data.isUsedTlsLibOutdated) {
  203. messages.push({
  204. msg: data.isUsedTlsLibOutdated,
  205. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  206. });
  207. }
  208. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  209. messages.push({
  210. 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 {linkstart}memcached wiki about both modules ↗{linkend}.')
  211. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://code.google.com/p/memcached/wiki/PHPClientComparison">')
  212. .replace('{linkend}', '</a>'),
  213. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  214. });
  215. }
  216. if(!data.hasPassedCodeIntegrityCheck) {
  217. messages.push({
  218. msg: t('core', 'Some files have not passed the integrity check. Further information on how to resolve this issue can be found in the {linkstart1}documentation ↗{linkend}. ({linkstart2}List of invalid files…{linkend} / {linkstart3}Rescan…{linkend})')
  219. .replace('{linkstart1}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.codeIntegrityCheckerDocumentation + '">')
  220. .replace('{linkstart2}', '<a href="' + OC.generateUrl('/settings/integrity/failed') + '">')
  221. .replace('{linkstart3}', '<a href="' + OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken}) + '">')
  222. .replace(/{linkend}/g, '</a>'),
  223. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  224. });
  225. }
  226. if(data.OpcacheSetupRecommendations.length > 0) {
  227. var listOfOPcacheRecommendations = "";
  228. data.OpcacheSetupRecommendations.forEach(function(element){
  229. listOfOPcacheRecommendations += '<li>' + element + '</li>';
  230. });
  231. messages.push({
  232. msg: t('core', 'The PHP OPcache module is not properly configured. See the {linkstart}documentation ↗{linkend} for more information.')
  233. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-php-opcache') + '">')
  234. .replace('{linkend}', '</a>') + '<ul>' + listOfOPcacheRecommendations + '</ul>',
  235. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  236. });
  237. }
  238. if(!data.isSettimelimitAvailable) {
  239. messages.push({
  240. msg: t('core', '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.'),
  241. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  242. });
  243. }
  244. if (data.missingIndexes.length > 0) {
  245. var listOfMissingIndexes = "";
  246. data.missingIndexes.forEach(function(element){
  247. listOfMissingIndexes += '<li>';
  248. listOfMissingIndexes += t('core', 'Missing index "{indexName}" in table "{tableName}".', element);
  249. listOfMissingIndexes += '</li>';
  250. });
  251. messages.push({
  252. msg: t('core', 'The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running "occ db:add-missing-indices" those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.') + '<ul>' + listOfMissingIndexes + '</ul>',
  253. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  254. })
  255. }
  256. if (data.missingPrimaryKeys.length > 0) {
  257. var listOfMissingPrimaryKeys = "";
  258. data.missingPrimaryKeys.forEach(function(element){
  259. listOfMissingPrimaryKeys += '<li>';
  260. listOfMissingPrimaryKeys += t('core', 'Missing primary key on table "{tableName}".', element);
  261. listOfMissingPrimaryKeys += '</li>';
  262. });
  263. messages.push({
  264. msg: t('core', 'The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running "occ db:add-missing-primary-keys" those missing primary keys could be added manually while the instance keeps running.') + '<ul>' + listOfMissingPrimaryKeys + '</ul>',
  265. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  266. })
  267. }
  268. if (data.missingColumns.length > 0) {
  269. var listOfMissingColumns = "";
  270. data.missingColumns.forEach(function(element){
  271. listOfMissingColumns += '<li>';
  272. listOfMissingColumns += t('core', 'Missing optional column "{columnName}" in table "{tableName}".', element);
  273. listOfMissingColumns += '</li>';
  274. });
  275. messages.push({
  276. msg: t('core', 'The database is missing some optional columns. Due to the fact that adding columns on big tables could take some time they were not added automatically when they can be optional. By running "occ db:add-missing-columns" those missing columns could be added manually while the instance keeps running. Once the columns are added some features might improve responsiveness or usability.') + '<ul>' + listOfMissingColumns + '</ul>',
  277. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  278. })
  279. }
  280. if (!data.isImagickEnabled) {
  281. messages.push({
  282. msg: t(
  283. 'core',
  284. 'The PHP module "imagick" is not enabled although the theming app is. For favicon generation to work correctly, you need to install and enable this module.'
  285. ),
  286. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  287. })
  288. }
  289. if (!data.areWebauthnExtensionsEnabled) {
  290. messages.push({
  291. msg: t(
  292. 'core',
  293. 'The PHP modules "gmp" and/or "bcmath" are not enabled. If you use WebAuthn passwordless authentication, these modules are required.'
  294. ),
  295. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  296. })
  297. }
  298. if (data.imageMagickLacksSVGSupport) {
  299. messages.push({
  300. msg: t('core', 'Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it.'),
  301. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  302. })
  303. }
  304. if (data.pendingBigIntConversionColumns.length > 0) {
  305. var listOfPendingBigIntConversionColumns = "";
  306. data.pendingBigIntConversionColumns.forEach(function(element){
  307. listOfPendingBigIntConversionColumns += '<li>' + element + '</li>';
  308. });
  309. messages.push({
  310. msg: t('core', 'Some columns in the database are missing a conversion to big int. Due to the fact that changing column types on big tables could take some time they were not changed automatically. By running "occ db:convert-filecache-bigint" those pending changes could be applied manually. This operation needs to be made while the instance is offline. For further details read {linkstart}the documentation page about this ↗{linkend}.')
  311. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-bigint-conversion') + '">')
  312. .replace('{linkend}', '</a>') + '<ul>' + listOfPendingBigIntConversionColumns + '</ul>',
  313. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  314. })
  315. }
  316. if (data.isSqliteUsed) {
  317. messages.push({
  318. msg: t('core', 'SQLite is currently being used as the backend database. For larger installations we recommend that you switch to a different database backend.') + ' ' + t('core', 'This is particularly recommended when using the desktop client for file synchronisation.') + ' ' +
  319. t('core', 'To migrate to another database use the command line tool: "occ db:convert-type", or see the {linkstart}documentation ↗{linkend}.')
  320. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.databaseConversionDocumentation + '">')
  321. .replace('{linkend}', '</a>'),
  322. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  323. })
  324. }
  325. if(data.appDirsWithDifferentOwner && data.appDirsWithDifferentOwner.length > 0) {
  326. var appDirsWithDifferentOwner = data.appDirsWithDifferentOwner.reduce(
  327. function(appDirsWithDifferentOwner, directory) {
  328. return appDirsWithDifferentOwner + '<li>' + directory + '</li>';
  329. },
  330. ''
  331. );
  332. messages.push({
  333. msg: t('core', 'Some app directories are owned by a different user than the web server one. ' +
  334. 'This may be the case if apps have been installed manually. ' +
  335. 'Check the permissions of the following app directories:')
  336. + '<ul>' + appDirsWithDifferentOwner + '</ul>',
  337. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  338. });
  339. }
  340. if (data.isMysqlUsedWithoutUTF8MB4) {
  341. messages.push({
  342. msg: t('core', 'MySQL is used as database but does not support 4-byte characters. To be able to handle 4-byte characters (like emojis) without issues in filenames or comments for example it is recommended to enable the 4-byte support in MySQL. For further details read {linkstart}the documentation page about this ↗{linkend}.')
  343. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-mysql-utf8mb4') + '">')
  344. .replace('{linkend}', '</a>'),
  345. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  346. })
  347. }
  348. if (!data.isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed) {
  349. messages.push({
  350. msg: t('core', 'This instance uses an S3 based object store as primary storage. The uploaded files are stored temporarily on the server and thus it is recommended to have 50 GB of free space available in the temp directory of PHP. Check the logs for full details about the path and the available space. To improve this please change the temporary directory in the php.ini or make more space available in that path.'),
  351. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  352. })
  353. }
  354. if (!data.temporaryDirectoryWritable) {
  355. messages.push({
  356. msg: t('core', 'The temporary directory of this instance points to an either non-existing or non-writable directory.'),
  357. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  358. })
  359. }
  360. if (window.location.protocol === 'https:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
  361. messages.push({
  362. msg: t('core', 'You are accessing your instance over a secure connection, however your instance is generating insecure URLs. This most likely means that you are behind a reverse proxy and the overwrite config variables are not set correctly. Please read {linkstart}the documentation page about this ↗{linkend}.')
  363. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.reverseProxyDocs + '">')
  364. .replace('{linkend}', '</a>'),
  365. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  366. })
  367. }
  368. if (window.oc_debug) {
  369. messages.push({
  370. msg: t('core', 'This instance is running in debug mode. Only enable this for local development and not in production environments.'),
  371. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  372. })
  373. }
  374. if (Object.keys(data.generic).length > 0) {
  375. Object.keys(data.generic).forEach(function(key){
  376. Object.keys(data.generic[key]).forEach(function(title){
  377. if (data.generic[key][title].severity != 'success') {
  378. data.generic[key][title].pass = false;
  379. OC.SetupChecks.addGenericSetupCheck(data.generic[key], title, messages);
  380. }
  381. });
  382. });
  383. }
  384. } else {
  385. messages.push({
  386. msg: t('core', 'Error occurred while checking server setup'),
  387. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  388. });
  389. }
  390. deferred.resolve(messages);
  391. };
  392. $.ajax({
  393. type: 'GET',
  394. url: OC.generateUrl('settings/ajax/checksetup'),
  395. allowAuthErrors: true
  396. }).then(afterCall, afterCall);
  397. return deferred.promise();
  398. },
  399. addGenericSetupCheck: function(data, check, messages) {
  400. var setupCheck = data[check] || { pass: true, description: '', severity: 'info', linkToDoc: null}
  401. var type = OC.SetupChecks.MESSAGE_TYPE_INFO
  402. if (setupCheck.severity === 'warning') {
  403. type = OC.SetupChecks.MESSAGE_TYPE_WARNING
  404. } else if (setupCheck.severity === 'error') {
  405. type = OC.SetupChecks.MESSAGE_TYPE_ERROR
  406. }
  407. var message = setupCheck.description;
  408. if (setupCheck.linkToDoc) {
  409. message += ' ' + t('core', 'For more details see the {linkstart}documentation ↗{linkend}.')
  410. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + setupCheck.linkToDoc + '">')
  411. .replace('{linkend}', '</a>');
  412. }
  413. if (setupCheck.elements) {
  414. message += '<br><ul>'
  415. setupCheck.elements.forEach(function(element){
  416. message += '<li>';
  417. message += element
  418. message += '</li>';
  419. });
  420. message += '</ul>'
  421. }
  422. if (!setupCheck.pass) {
  423. messages.push({
  424. msg: message,
  425. type: type,
  426. })
  427. }
  428. },
  429. /**
  430. * Runs generic checks on the server side, the difference to dedicated
  431. * methods is that we use the same XHR object for all checks to save
  432. * requests.
  433. *
  434. * @return $.Deferred object resolved with an array of error messages
  435. */
  436. checkGeneric: function() {
  437. var self = this;
  438. var deferred = $.Deferred();
  439. var afterCall = function(data, statusText, xhr) {
  440. var messages = [];
  441. messages = messages.concat(self._checkSecurityHeaders(xhr));
  442. messages = messages.concat(self._checkSSL(xhr));
  443. deferred.resolve(messages);
  444. };
  445. $.ajax({
  446. type: 'GET',
  447. url: OC.generateUrl('heartbeat'),
  448. allowAuthErrors: true
  449. }).then(afterCall, afterCall);
  450. return deferred.promise();
  451. },
  452. checkDataProtected: function() {
  453. var deferred = $.Deferred();
  454. if(oc_dataURL === false){
  455. return deferred.resolve([]);
  456. }
  457. var afterCall = function(xhr) {
  458. var messages = [];
  459. // .ocdata is an empty file in the data directory - if this is readable then the data dir is not protected
  460. if (xhr.status === 200 && xhr.responseText === '') {
  461. messages.push({
  462. 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.'),
  463. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  464. });
  465. }
  466. deferred.resolve(messages);
  467. };
  468. $.ajax({
  469. type: 'GET',
  470. url: OC.linkTo('', oc_dataURL+'/.ocdata?t=' + (new Date()).getTime()),
  471. complete: afterCall,
  472. allowAuthErrors: true
  473. });
  474. return deferred.promise();
  475. },
  476. /**
  477. * Runs check for some generic security headers on the server side
  478. *
  479. * @param {Object} xhr
  480. * @return {Array} Array with error messages
  481. */
  482. _checkSecurityHeaders: function(xhr) {
  483. var messages = [];
  484. if (xhr.status === 200) {
  485. var securityHeaders = {
  486. 'X-Content-Type-Options': ['nosniff'],
  487. 'X-Robots-Tag': ['noindex, nofollow'],
  488. 'X-Frame-Options': ['SAMEORIGIN', 'DENY'],
  489. 'X-Permitted-Cross-Domain-Policies': ['none'],
  490. };
  491. for (var header in securityHeaders) {
  492. var option = securityHeaders[header][0];
  493. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).replace(/, /, ',').toLowerCase() !== option.replace(/, /, ',').toLowerCase()) {
  494. 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});
  495. if(xhr.getResponseHeader(header) && securityHeaders[header].length > 1 && xhr.getResponseHeader(header).toLowerCase() === securityHeaders[header][1].toLowerCase()) {
  496. 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});
  497. }
  498. messages.push({
  499. msg: msg,
  500. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  501. });
  502. }
  503. }
  504. var xssfields = xhr.getResponseHeader('X-XSS-Protection') ? xhr.getResponseHeader('X-XSS-Protection').split(';').map(function(item) { return item.trim(); }) : [];
  505. if (xssfields.length === 0 || xssfields.indexOf('1') === -1 || xssfields.indexOf('mode=block') === -1) {
  506. messages.push({
  507. msg: t('core', 'The "{header}" HTTP header does not contain "{expected}". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  508. {
  509. header: 'X-XSS-Protection',
  510. expected: '1; mode=block'
  511. }),
  512. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  513. });
  514. }
  515. const referrerPolicy = xhr.getResponseHeader('Referrer-Policy')
  516. if (referrerPolicy === null || !/(no-referrer(-when-downgrade)?|strict-origin(-when-cross-origin)?|same-origin)(,|$)/.test(referrerPolicy)) {
  517. messages.push({
  518. msg: t('core', 'The "{header}" HTTP header is not set to "{val1}", "{val2}", "{val3}", "{val4}" or "{val5}". This can leak referer information. See the {linkstart}W3C Recommendation ↗{linkend}.',
  519. {
  520. header: 'Referrer-Policy',
  521. val1: 'no-referrer',
  522. val2: 'no-referrer-when-downgrade',
  523. val3: 'strict-origin',
  524. val4: 'strict-origin-when-cross-origin',
  525. val5: 'same-origin'
  526. })
  527. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">')
  528. .replace('{linkend}', '</a>'),
  529. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  530. })
  531. }
  532. } else {
  533. messages.push({
  534. msg: t('core', 'Error occurred while checking server setup'),
  535. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  536. });
  537. }
  538. return messages;
  539. },
  540. /**
  541. * Runs check for some SSL configuration issues on the server side
  542. *
  543. * @param {Object} xhr
  544. * @return {Array} Array with error messages
  545. */
  546. _checkSSL: function(xhr) {
  547. var messages = [];
  548. if (xhr.status === 200) {
  549. var tipsUrl = OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-security');
  550. if(OC.getProtocol() === 'https') {
  551. // Extract the value of 'Strict-Transport-Security'
  552. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  553. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  554. var firstComma = transportSecurityValidity.indexOf(";");
  555. if(firstComma !== -1) {
  556. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  557. } else {
  558. transportSecurityValidity = transportSecurityValidity.substring(8);
  559. }
  560. }
  561. var minimumSeconds = 15552000;
  562. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  563. messages.push({
  564. 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 {linkstart}security tips ↗{linkend}.', {'seconds': minimumSeconds})
  565. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">')
  566. .replace('{linkend}', '</a>'),
  567. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  568. });
  569. }
  570. } else if (!/(?:^(?:localhost|127\.0\.0\.1|::1)|\.onion)$/.exec(window.location.hostname)) {
  571. messages.push({
  572. msg: t('core', 'Accessing site insecurely via HTTP. You are strongly advised to set up your server to require HTTPS instead, as described in the {linkstart}security tips ↗{linkend}. Without it some important web functionality like "copy to clipboard" or "service workers" will not work!')
  573. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">')
  574. .replace('{linkend}', '</a>'),
  575. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  576. });
  577. }
  578. } else {
  579. messages.push({
  580. msg: t('core', 'Error occurred while checking server setup'),
  581. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  582. });
  583. }
  584. return messages;
  585. }
  586. };
  587. })();