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 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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(url, placeholderUrl, runCheck, expectedStatus) {
  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. if (expectedStatus.indexOf(xhr.status) === -1) {
  70. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
  71. messages.push({
  72. 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 }),
  73. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  74. });
  75. }
  76. deferred.resolve(messages);
  77. };
  78. $.ajax({
  79. type: 'PROPFIND',
  80. url: url,
  81. complete: afterCall,
  82. allowAuthErrors: true
  83. });
  84. return deferred.promise();
  85. },
  86. /**
  87. * Check whether the .well-known URLs works.
  88. *
  89. * @param url the URL to test
  90. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  91. * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
  92. *
  93. * @return $.Deferred object resolved with an array of error messages
  94. */
  95. checkProviderUrl: function(url, placeholderUrl, runCheck) {
  96. var expectedStatus = [200];
  97. var deferred = $.Deferred();
  98. if(runCheck === false) {
  99. deferred.resolve([]);
  100. return deferred.promise();
  101. }
  102. var afterCall = function(xhr) {
  103. var messages = [];
  104. if (expectedStatus.indexOf(xhr.status) === -1) {
  105. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
  106. messages.push({
  107. 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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation page</a>. On Nginx those are typically the lines starting with "location ~" that need an update.', { docLink: docUrl, url: url }),
  108. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  109. });
  110. }
  111. deferred.resolve(messages);
  112. };
  113. $.ajax({
  114. type: 'GET',
  115. url: url,
  116. complete: afterCall,
  117. allowAuthErrors: true
  118. });
  119. return deferred.promise();
  120. },
  121. /**
  122. * Check whether the WOFF2 URLs works.
  123. *
  124. * @param url the URL to test
  125. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  126. * @return $.Deferred object resolved with an array of error messages
  127. */
  128. checkWOFF2Loading: function(url, placeholderUrl) {
  129. var deferred = $.Deferred();
  130. var afterCall = function(xhr) {
  131. var messages = [];
  132. if (xhr.status !== 200) {
  133. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
  134. messages.push({
  135. 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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }),
  136. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  137. });
  138. }
  139. deferred.resolve(messages);
  140. };
  141. $.ajax({
  142. type: 'GET',
  143. url: url,
  144. complete: afterCall,
  145. allowAuthErrors: true
  146. });
  147. return deferred.promise();
  148. },
  149. /**
  150. * Runs setup checks on the server side
  151. *
  152. * @return $.Deferred object resolved with an array of error messages
  153. */
  154. checkSetup: function() {
  155. var deferred = $.Deferred();
  156. var afterCall = function(data, statusText, xhr) {
  157. var messages = [];
  158. if (xhr.status === 200 && data) {
  159. if (!data.isGetenvServerWorking) {
  160. messages.push({
  161. msg: t('core', 'PHP does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.') + ' ' +
  162. t(
  163. 'core',
  164. 'Please check the <a target="_blank" rel="noreferrer noopener" href="{docLink}">installation documentation ↗</a> for PHP configuration notes and the PHP configuration of your server, especially when using php-fpm.',
  165. {
  166. docLink: OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-php-fpm')
  167. }
  168. ),
  169. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  170. });
  171. }
  172. if (data.isReadOnlyConfig) {
  173. messages.push({
  174. msg: t('core', 'The read-only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.'),
  175. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  176. });
  177. }
  178. if (!data.hasValidTransactionIsolationLevel) {
  179. messages.push({
  180. msg: t('core', 'Your database does not run with "READ COMMITTED" transaction isolation level. This can cause problems when multiple actions are executed in parallel.'),
  181. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  182. });
  183. }
  184. if(!data.hasFileinfoInstalled) {
  185. messages.push({
  186. msg: t('core', 'The PHP module "fileinfo" is missing. It is strongly recommended to enable this module to get the best results with MIME type detection.'),
  187. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  188. });
  189. }
  190. if(!data.hasWorkingFileLocking) {
  191. messages.push({
  192. msg: t('core', 'Transactional file locking is disabled, this might lead to issues with race conditions. Enable "filelocking.enabled" in config.php to avoid these problems. See the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation ↗</a> for more information.', {docLink: OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-transactional-locking')}),
  193. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  194. });
  195. }
  196. if (data.suggestedOverwriteCliURL !== '') {
  197. messages.push({
  198. msg: t('core', 'If your installation is not installed at the root of the domain and uses system cron, there can be issues with the URL generation. To avoid these problems, please set the "overwrite.cli.url" option in your config.php file to the webroot path of your installation (suggestion: "{suggestedOverwriteCliURL}")', {suggestedOverwriteCliURL: data.suggestedOverwriteCliURL}),
  199. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  200. });
  201. }
  202. if (data.cronErrors.length > 0) {
  203. var listOfCronErrors = "";
  204. data.cronErrors.forEach(function(element){
  205. listOfCronErrors += "<li>";
  206. listOfCronErrors += element.error;
  207. listOfCronErrors += ' ';
  208. listOfCronErrors += element.hint;
  209. listOfCronErrors += "</li>";
  210. });
  211. messages.push({
  212. msg: t(
  213. 'core',
  214. 'It was not possible to execute the cron job via CLI. The following technical errors have appeared:'
  215. ) + "<ul>" + listOfCronErrors + "</ul>",
  216. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  217. })
  218. }
  219. if (data.cronInfo.diffInSeconds > 3600) {
  220. messages.push({
  221. msg: t('core', 'Last background job execution ran {relativeTime}. Something seems wrong.', {relativeTime: data.cronInfo.relativeTime}) +
  222. ' <a href="' + data.cronInfo.backgroundJobsUrl + '">' + t('core', 'Check the background job settings') + '</a>',
  223. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  224. });
  225. }
  226. if (data.serverHasInternetConnectionProblems) {
  227. messages.push({
  228. 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.'),
  229. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  230. });
  231. }
  232. if(!data.isMemcacheConfigured) {
  233. messages.push({
  234. 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}),
  235. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  236. });
  237. }
  238. if(!data.isRandomnessSecure) {
  239. messages.push({
  240. msg: t('core', 'No suitable source for randomness found 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}),
  241. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  242. });
  243. }
  244. if(data.isUsedTlsLibOutdated) {
  245. messages.push({
  246. msg: data.isUsedTlsLibOutdated,
  247. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  248. });
  249. }
  250. if (data.phpSupported && data.phpSupported.eol) {
  251. messages.push({
  252. 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' }),
  253. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  254. })
  255. }
  256. if (data.phpSupported && data.phpSupported.version.substr(0, 3) === '7.2') {
  257. messages.push({
  258. msg: t('core', 'Nextcloud 19 is the last release supporting PHP 7.2. Nextcloud 20 requires at least PHP 7.3.'),
  259. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  260. })
  261. }
  262. if(!data.forwardedForHeadersWorking) {
  263. messages.push({
  264. 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}),
  265. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  266. });
  267. }
  268. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  269. messages.push({
  270. 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'}),
  271. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  272. });
  273. }
  274. if(!data.hasPassedCodeIntegrityCheck) {
  275. messages.push({
  276. msg: t(
  277. 'core',
  278. '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>)',
  279. {
  280. docLink: data.codeIntegrityCheckerDocumentation,
  281. codeIntegrityDownloadEndpoint: OC.generateUrl('/settings/integrity/failed'),
  282. rescanEndpoint: OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken})
  283. }
  284. ),
  285. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  286. });
  287. }
  288. if(!data.hasOpcacheLoaded) {
  289. messages.push({
  290. msg: t(
  291. 'core',
  292. 'The PHP OPcache module is not loaded. <a target="_blank" rel="noreferrer noopener" href="{docLink}">For better performance it is recommended</a> to load it into your PHP installation.',
  293. {
  294. docLink: data.phpOpcacheDocumentation,
  295. }
  296. ),
  297. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  298. });
  299. } else if(!data.isOpcacheProperlySetup) {
  300. messages.push({
  301. msg: t(
  302. 'core',
  303. '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>:',
  304. {
  305. docLink: data.phpOpcacheDocumentation,
  306. }
  307. ) + "<pre><code>opcache.enable=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>",
  308. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  309. });
  310. }
  311. if(!data.isSettimelimitAvailable) {
  312. messages.push({
  313. msg: t(
  314. 'core',
  315. '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.'),
  316. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  317. });
  318. }
  319. if (!data.hasFreeTypeSupport) {
  320. messages.push({
  321. msg: t(
  322. 'core',
  323. 'Your PHP does not have FreeType support, resulting in breakage of profile pictures and the settings interface.'
  324. ),
  325. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  326. })
  327. }
  328. if (data.missingIndexes.length > 0) {
  329. var listOfMissingIndexes = "";
  330. data.missingIndexes.forEach(function(element){
  331. listOfMissingIndexes += "<li>";
  332. listOfMissingIndexes += t('core', 'Missing index "{indexName}" in table "{tableName}".', element);
  333. listOfMissingIndexes += "</li>";
  334. });
  335. messages.push({
  336. msg: t(
  337. 'core',
  338. '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.'
  339. ) + "<ul>" + listOfMissingIndexes + "</ul>",
  340. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  341. })
  342. }
  343. if (data.missingColumns.length > 0) {
  344. var listOfMissingColumns = "";
  345. data.missingColumns.forEach(function(element){
  346. listOfMissingColumns += "<li>";
  347. listOfMissingColumns += t('core', 'Missing optional column "{columnName}" in table "{tableName}".', element);
  348. listOfMissingColumns += "</li>";
  349. });
  350. messages.push({
  351. msg: t(
  352. 'core',
  353. '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.'
  354. ) + "<ul>" + listOfMissingColumns + "</ul>",
  355. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  356. })
  357. }
  358. if (data.recommendedPHPModules.length > 0) {
  359. var listOfRecommendedPHPModules = "";
  360. data.recommendedPHPModules.forEach(function(element){
  361. listOfRecommendedPHPModules += "<li>" + element + "</li>";
  362. });
  363. messages.push({
  364. msg: t(
  365. 'core',
  366. 'This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them.'
  367. ) + "<ul><code>" + listOfRecommendedPHPModules + "</code></ul>",
  368. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  369. })
  370. }
  371. if (data.pendingBigIntConversionColumns.length > 0) {
  372. var listOfPendingBigIntConversionColumns = "";
  373. data.pendingBigIntConversionColumns.forEach(function(element){
  374. listOfPendingBigIntConversionColumns += "<li>" + element + "</li>";
  375. });
  376. messages.push({
  377. msg: t(
  378. 'core',
  379. '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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
  380. {
  381. docLink: OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-bigint-conversion'),
  382. }
  383. ) + "<ul>" + listOfPendingBigIntConversionColumns + "</ul>",
  384. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  385. })
  386. }
  387. if (data.isSqliteUsed) {
  388. messages.push({
  389. msg: t(
  390. 'core',
  391. 'SQLite is currently being used as the backend database. For larger installations we recommend that you switch to a different database backend.'
  392. ) + ' ' + t('core', 'This is particularly recommended when using the desktop client for file synchronisation.') + ' ' +
  393. t(
  394. 'core',
  395. 'To migrate to another database use the command line tool: \'occ db:convert-type\', or see the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation ↗</a>.',
  396. {
  397. docLink: data.databaseConversionDocumentation,
  398. }
  399. ),
  400. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  401. })
  402. }
  403. if (data.isPHPMailerUsed) {
  404. messages.push({
  405. msg: t(
  406. 'core',
  407. 'Use of the the built in php mailer is no longer supported. <a target="_blank" rel="noreferrer noopener" href="{docLink}">Please update your email server settings ↗<a/>.',
  408. {
  409. docLink: data.mailSettingsDocumentation,
  410. }
  411. ),
  412. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  413. });
  414. }
  415. if (!data.isMemoryLimitSufficient) {
  416. messages.push({
  417. msg: t(
  418. 'core',
  419. 'The PHP memory limit is below the recommended value of 512MB.'
  420. ),
  421. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  422. })
  423. }
  424. if(data.appDirsWithDifferentOwner && data.appDirsWithDifferentOwner.length > 0) {
  425. var appDirsWithDifferentOwner = data.appDirsWithDifferentOwner.reduce(
  426. function(appDirsWithDifferentOwner, directory) {
  427. return appDirsWithDifferentOwner + '<li>' + directory + '</li>';
  428. },
  429. ''
  430. );
  431. messages.push({
  432. msg: t('core', 'Some app directories are owned by a different user than the web server one. ' +
  433. 'This may be the case if apps have been installed manually. ' +
  434. 'Check the permissions of the following app directories:')
  435. + '<ul>' + appDirsWithDifferentOwner + '</ul>',
  436. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  437. });
  438. }
  439. if (data.isMysqlUsedWithoutUTF8MB4) {
  440. messages.push({
  441. msg: t(
  442. 'core',
  443. '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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
  444. {
  445. docLink: OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-mysql-utf8mb4'),
  446. }
  447. ),
  448. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  449. })
  450. }
  451. if (!data.isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed) {
  452. messages.push({
  453. msg: t(
  454. 'core',
  455. '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.'
  456. ),
  457. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  458. })
  459. }
  460. if (window.location.protocol === 'http:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
  461. messages.push({
  462. msg: t(
  463. 'core',
  464. '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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
  465. {
  466. docLink: data.reverseProxyDocs
  467. }
  468. ),
  469. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  470. })
  471. }
  472. } else {
  473. messages.push({
  474. msg: t('core', 'Error occurred while checking server setup'),
  475. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  476. });
  477. }
  478. deferred.resolve(messages);
  479. };
  480. $.ajax({
  481. type: 'GET',
  482. url: OC.generateUrl('settings/ajax/checksetup'),
  483. allowAuthErrors: true
  484. }).then(afterCall, afterCall);
  485. return deferred.promise();
  486. },
  487. /**
  488. * Runs generic checks on the server side, the difference to dedicated
  489. * methods is that we use the same XHR object for all checks to save
  490. * requests.
  491. *
  492. * @return $.Deferred object resolved with an array of error messages
  493. */
  494. checkGeneric: function() {
  495. var self = this;
  496. var deferred = $.Deferred();
  497. var afterCall = function(data, statusText, xhr) {
  498. var messages = [];
  499. messages = messages.concat(self._checkSecurityHeaders(xhr));
  500. messages = messages.concat(self._checkSSL(xhr));
  501. deferred.resolve(messages);
  502. };
  503. $.ajax({
  504. type: 'GET',
  505. url: OC.generateUrl('heartbeat'),
  506. allowAuthErrors: true
  507. }).then(afterCall, afterCall);
  508. return deferred.promise();
  509. },
  510. checkDataProtected: function() {
  511. var deferred = $.Deferred();
  512. if(oc_dataURL === false){
  513. return deferred.resolve([]);
  514. }
  515. var afterCall = function(xhr) {
  516. var messages = [];
  517. // .ocdata is an empty file in the data directory - if this is readable then the data dir is not protected
  518. if (xhr.status === 200 && xhr.responseText === '') {
  519. messages.push({
  520. 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.'),
  521. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  522. });
  523. }
  524. deferred.resolve(messages);
  525. };
  526. $.ajax({
  527. type: 'GET',
  528. url: OC.linkTo('', oc_dataURL+'/.ocdata?t=' + (new Date()).getTime()),
  529. complete: afterCall,
  530. allowAuthErrors: true
  531. });
  532. return deferred.promise();
  533. },
  534. /**
  535. * Runs check for some generic security headers on the server side
  536. *
  537. * @param {Object} xhr
  538. * @return {Array} Array with error messages
  539. */
  540. _checkSecurityHeaders: function(xhr) {
  541. var messages = [];
  542. if (xhr.status === 200) {
  543. var securityHeaders = {
  544. 'X-Content-Type-Options': ['nosniff'],
  545. 'X-Robots-Tag': ['none'],
  546. 'X-Frame-Options': ['SAMEORIGIN', 'DENY'],
  547. 'X-Download-Options': ['noopen'],
  548. 'X-Permitted-Cross-Domain-Policies': ['none'],
  549. };
  550. for (var header in securityHeaders) {
  551. var option = securityHeaders[header][0];
  552. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== option.toLowerCase()) {
  553. 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});
  554. if(xhr.getResponseHeader(header) && securityHeaders[header].length > 1 && xhr.getResponseHeader(header).toLowerCase() === securityHeaders[header][1].toLowerCase()) {
  555. 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});
  556. }
  557. messages.push({
  558. msg: msg,
  559. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  560. });
  561. }
  562. }
  563. var xssfields = xhr.getResponseHeader('X-XSS-Protection') ? xhr.getResponseHeader('X-XSS-Protection').split(';').map(function(item) { return item.trim(); }) : [];
  564. if (xssfields.length === 0 || xssfields.indexOf('1') === -1 || xssfields.indexOf('mode=block') === -1) {
  565. messages.push({
  566. msg: t('core', 'The "{header}" HTTP header doesn\'t contain "{expected}". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  567. {
  568. header: 'X-XSS-Protection',
  569. expected: '1; mode=block'
  570. }),
  571. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  572. });
  573. }
  574. const referrerPolicy = xhr.getResponseHeader('Referrer-Policy')
  575. if (referrerPolicy === null || !/(no-referrer(-when-downgrade)?|strict-origin(-when-cross-origin)?|same-origin)(,|$)/.test(referrerPolicy)) {
  576. messages.push({
  577. msg: t('core', 'The "{header}" HTTP header is not set to "{val1}", "{val2}", "{val3}", "{val4}" or "{val5}". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" href="{link}">W3C Recommendation ↗</a>.',
  578. {
  579. header: 'Referrer-Policy',
  580. val1: 'no-referrer',
  581. val2: 'no-referrer-when-downgrade',
  582. val3: 'strict-origin',
  583. val4: 'strict-origin-when-cross-origin',
  584. val5: 'same-origin',
  585. link: 'https://www.w3.org/TR/referrer-policy/'
  586. }),
  587. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  588. })
  589. }
  590. } else {
  591. messages.push({
  592. msg: t('core', 'Error occurred while checking server setup'),
  593. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  594. });
  595. }
  596. return messages;
  597. },
  598. /**
  599. * Runs check for some SSL configuration issues on the server side
  600. *
  601. * @param {Object} xhr
  602. * @return {Array} Array with error messages
  603. */
  604. _checkSSL: function(xhr) {
  605. var messages = [];
  606. if (xhr.status === 200) {
  607. var tipsUrl = OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-security');
  608. if(OC.getProtocol() === 'https') {
  609. // Extract the value of 'Strict-Transport-Security'
  610. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  611. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  612. var firstComma = transportSecurityValidity.indexOf(";");
  613. if(firstComma !== -1) {
  614. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  615. } else {
  616. transportSecurityValidity = transportSecurityValidity.substring(8);
  617. }
  618. }
  619. var minimumSeconds = 15552000;
  620. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  621. messages.push({
  622. 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}),
  623. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  624. });
  625. }
  626. } else {
  627. messages.push({
  628. 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 <a href="{docUrl}">security tips ↗</a>.', {docUrl: tipsUrl}),
  629. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  630. });
  631. }
  632. } else {
  633. messages.push({
  634. msg: t('core', 'Error occurred while checking server setup'),
  635. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  636. });
  637. }
  638. return messages;
  639. }
  640. };
  641. })();