setupchecks.js 28 KB

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