setupchecks.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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.isGetenvServerWorking) {
  167. messages.push({
  168. 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.') + ' ' +
  169. t('core', 'Please check the {linkstart}installation documentation ↗{linkend} for PHP configuration notes and the PHP configuration of your server, especially when using php-fpm.')
  170. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-php-fpm') + '">')
  171. .replace('{linkend}', '</a>'),
  172. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  173. });
  174. }
  175. if (data.isReadOnlyConfig) {
  176. messages.push({
  177. 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.'),
  178. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  179. });
  180. }
  181. if (!data.hasValidTransactionIsolationLevel) {
  182. messages.push({
  183. 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.'),
  184. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  185. });
  186. }
  187. if(!data.hasFileinfoInstalled) {
  188. messages.push({
  189. 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.'),
  190. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  191. });
  192. }
  193. if(!data.hasWorkingFileLocking) {
  194. messages.push({
  195. 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 {linkstart}documentation ↗{linkend} for more information.')
  196. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-transactional-locking') + '">')
  197. .replace('{linkend}', '</a>'),
  198. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  199. });
  200. }
  201. if (data.suggestedOverwriteCliURL !== '') {
  202. messages.push({
  203. 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}),
  204. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  205. });
  206. }
  207. if (!data.isDefaultPhoneRegionSet) {
  208. messages.push({
  209. msg: t('core', 'Your installation has no default phone region set. This is required to validate phone numbers in the profile settings without a country code. To allow numbers without a country code, please add "default_phone_region" with the respective {linkstart}ISO 3166-1 code ↗{linkend} of the region to your config file.')
  210. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements">')
  211. .replace('{linkend}', '</a>'),
  212. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  213. });
  214. }
  215. if (data.cronErrors.length > 0) {
  216. var listOfCronErrors = "";
  217. data.cronErrors.forEach(function(element){
  218. listOfCronErrors += "<li>";
  219. listOfCronErrors += element.error;
  220. listOfCronErrors += ' ';
  221. listOfCronErrors += element.hint;
  222. listOfCronErrors += "</li>";
  223. });
  224. messages.push({
  225. msg: t(
  226. 'core',
  227. 'It was not possible to execute the cron job via CLI. The following technical errors have appeared:'
  228. ) + "<ul>" + listOfCronErrors + "</ul>",
  229. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  230. })
  231. }
  232. if (data.cronInfo.diffInSeconds > 3600) {
  233. messages.push({
  234. msg: t('core', 'Last background job execution ran {relativeTime}. Something seems wrong. {linkstart}Check the background job settings ↗{linkend}.', {relativeTime: data.cronInfo.relativeTime})
  235. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.cronInfo.backgroundJobsUrl + '">')
  236. .replace('{linkend}', '</a>'),
  237. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  238. });
  239. }
  240. if (data.serverHasInternetConnectionProblems) {
  241. messages.push({
  242. 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.'),
  243. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  244. });
  245. }
  246. if(!data.isMemcacheConfigured) {
  247. messages.push({
  248. 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 {linkstart}documentation ↗{linkend}.')
  249. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.memcacheDocs + '">')
  250. .replace('{linkend}', '</a>'),
  251. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  252. });
  253. }
  254. if(!data.isRandomnessSecure) {
  255. messages.push({
  256. 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 {linkstart}documentation ↗{linkend}.')
  257. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.securityDocs + '">')
  258. .replace('{linkend}', '</a>'),
  259. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  260. });
  261. }
  262. if(data.isUsedTlsLibOutdated) {
  263. messages.push({
  264. msg: data.isUsedTlsLibOutdated,
  265. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  266. });
  267. }
  268. if (data.phpSupported && data.phpSupported.eol) {
  269. messages.push({
  270. msg: t('core', 'You are currently running PHP {version}. Upgrade your PHP version to take advantage of {linkstart}performance and security updates provided by the PHP Group ↗{linkend} as soon as your distribution supports it.', { version: data.phpSupported.version })
  271. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://secure.php.net/supported-versions.php">')
  272. .replace('{linkend}', '</a>'),
  273. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  274. })
  275. }
  276. if (data.phpSupported && data.phpSupported.version.substr(0, 3) === '7.2') {
  277. messages.push({
  278. msg: t('core', 'Nextcloud 20 is the last release supporting PHP 7.2. Nextcloud 21 requires at least PHP 7.3.'),
  279. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  280. })
  281. }
  282. if(!data.forwardedForHeadersWorking) {
  283. messages.push({
  284. 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 {linkstart}documentation ↗{linkend}.')
  285. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.reverseProxyDocs + '">')
  286. .replace('{linkend}', '</a>'),
  287. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  288. });
  289. }
  290. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  291. messages.push({
  292. 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}.')
  293. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://code.google.com/p/memcached/wiki/PHPClientComparison">')
  294. .replace('{linkend}', '</a>'),
  295. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  296. });
  297. }
  298. if(!data.hasPassedCodeIntegrityCheck) {
  299. messages.push({
  300. 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})')
  301. .replace('{linkstart1}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.codeIntegrityCheckerDocumentation + '">')
  302. .replace('{linkstart2}', '<a href="' + OC.generateUrl('/settings/integrity/failed') + '">')
  303. .replace('{linkstart3}', '<a href="' + OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken}) + '">')
  304. .replace(/{linkend}/g, '</a>'),
  305. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  306. });
  307. }
  308. if(!data.hasOpcacheLoaded) {
  309. messages.push({
  310. msg: t('core', 'The PHP OPcache module is not loaded. {linkstart}For better performance it is recommended ↗{linkend} to load it into your PHP installation.')
  311. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.phpOpcacheDocumentation + '">')
  312. .replace('{linkend}', '</a>'),
  313. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  314. });
  315. } else if(!data.isOpcacheProperlySetup) {
  316. messages.push({
  317. msg: t('core', 'The PHP OPcache module is not properly configured. {linkstart}For better performance it is recommended ↗{linkend} to use the following settings in the <code>php.ini</code>:')
  318. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.phpOpcacheDocumentation + '">')
  319. .replace('{linkend}', '</a>') + "<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>",
  320. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  321. });
  322. }
  323. if(!data.isSettimelimitAvailable) {
  324. messages.push({
  325. msg: t(
  326. 'core',
  327. '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.'),
  328. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  329. });
  330. }
  331. if (!data.hasFreeTypeSupport) {
  332. messages.push({
  333. msg: t(
  334. 'core',
  335. 'Your PHP does not have FreeType support, resulting in breakage of profile pictures and the settings interface.'
  336. ),
  337. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  338. })
  339. }
  340. if (data.missingIndexes.length > 0) {
  341. var listOfMissingIndexes = "";
  342. data.missingIndexes.forEach(function(element){
  343. listOfMissingIndexes += "<li>";
  344. listOfMissingIndexes += t('core', 'Missing index "{indexName}" in table "{tableName}".', element);
  345. listOfMissingIndexes += "</li>";
  346. });
  347. messages.push({
  348. msg: t(
  349. 'core',
  350. '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.'
  351. ) + "<ul>" + listOfMissingIndexes + "</ul>",
  352. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  353. })
  354. }
  355. if (data.missingPrimaryKeys.length > 0) {
  356. var listOfMissingPrimaryKeys = "";
  357. data.missingPrimaryKeys.forEach(function(element){
  358. listOfMissingPrimaryKeys += "<li>";
  359. listOfMissingPrimaryKeys += t('core', 'Missing primary key on table "{tableName}".', element);
  360. listOfMissingPrimaryKeys += "</li>";
  361. });
  362. messages.push({
  363. msg: t(
  364. 'core',
  365. '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.'
  366. ) + "<ul>" + listOfMissingPrimaryKeys + "</ul>",
  367. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  368. })
  369. }
  370. if (data.missingColumns.length > 0) {
  371. var listOfMissingColumns = "";
  372. data.missingColumns.forEach(function(element){
  373. listOfMissingColumns += "<li>";
  374. listOfMissingColumns += t('core', 'Missing optional column "{columnName}" in table "{tableName}".', element);
  375. listOfMissingColumns += "</li>";
  376. });
  377. messages.push({
  378. msg: t(
  379. 'core',
  380. '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.'
  381. ) + "<ul>" + listOfMissingColumns + "</ul>",
  382. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  383. })
  384. }
  385. if (data.recommendedPHPModules.length > 0) {
  386. var listOfRecommendedPHPModules = "";
  387. data.recommendedPHPModules.forEach(function(element){
  388. listOfRecommendedPHPModules += "<li>" + element + "</li>";
  389. });
  390. messages.push({
  391. msg: t(
  392. 'core',
  393. 'This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them.'
  394. ) + "<ul><code>" + listOfRecommendedPHPModules + "</code></ul>",
  395. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  396. })
  397. }
  398. if (data.imageMagickLacksSVGSupport) {
  399. messages.push({
  400. msg: t(
  401. 'core',
  402. 'Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it.'
  403. ),
  404. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  405. })
  406. }
  407. if (data.pendingBigIntConversionColumns.length > 0) {
  408. var listOfPendingBigIntConversionColumns = "";
  409. data.pendingBigIntConversionColumns.forEach(function(element){
  410. listOfPendingBigIntConversionColumns += "<li>" + element + "</li>";
  411. });
  412. messages.push({
  413. 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}.')
  414. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-bigint-conversion') + '">')
  415. .replace('{linkend}', '</a>') + "<ul>" + listOfPendingBigIntConversionColumns + "</ul>",
  416. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  417. })
  418. }
  419. if (data.isSqliteUsed) {
  420. messages.push({
  421. msg: t(
  422. 'core',
  423. 'SQLite is currently being used as the backend database. For larger installations we recommend that you switch to a different database backend.'
  424. ) + ' ' + t('core', 'This is particularly recommended when using the desktop client for file synchronisation.') + ' ' +
  425. t('core', 'To migrate to another database use the command line tool: \'occ db:convert-type\', or see the {linkstart}documentation ↗{linkend}.')
  426. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.databaseConversionDocumentation + '">')
  427. .replace('{linkend}', '</a>'),
  428. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  429. })
  430. }
  431. if (!data.isMemoryLimitSufficient) {
  432. messages.push({
  433. msg: t(
  434. 'core',
  435. 'The PHP memory limit is below the recommended value of 512MB.'
  436. ),
  437. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  438. })
  439. }
  440. if(data.appDirsWithDifferentOwner && data.appDirsWithDifferentOwner.length > 0) {
  441. var appDirsWithDifferentOwner = data.appDirsWithDifferentOwner.reduce(
  442. function(appDirsWithDifferentOwner, directory) {
  443. return appDirsWithDifferentOwner + '<li>' + directory + '</li>';
  444. },
  445. ''
  446. );
  447. messages.push({
  448. msg: t('core', 'Some app directories are owned by a different user than the web server one. ' +
  449. 'This may be the case if apps have been installed manually. ' +
  450. 'Check the permissions of the following app directories:')
  451. + '<ul>' + appDirsWithDifferentOwner + '</ul>',
  452. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  453. });
  454. }
  455. if (data.isMysqlUsedWithoutUTF8MB4) {
  456. messages.push({
  457. 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}.')
  458. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-mysql-utf8mb4') + '">')
  459. .replace('{linkend}', '</a>'),
  460. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  461. })
  462. }
  463. if (!data.isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed) {
  464. messages.push({
  465. msg: t(
  466. 'core',
  467. '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.'
  468. ),
  469. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  470. })
  471. }
  472. if (!data.temporaryDirectoryWritable) {
  473. messages.push({
  474. msg: t(
  475. 'core',
  476. 'The temporary directory of this instance points to an either non-existing or non-writable directory.'
  477. ),
  478. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  479. })
  480. }
  481. if (window.location.protocol === 'https:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
  482. messages.push({
  483. 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}.')
  484. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.reverseProxyDocs + '">')
  485. .replace('{linkend}', '</a>'),
  486. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  487. })
  488. }
  489. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\PhpDefaultCharset', messages)
  490. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\PhpOutputBuffering', messages)
  491. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat', messages)
  492. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\CheckUserCertificates', messages)
  493. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\SupportedDatabase', messages)
  494. } else {
  495. messages.push({
  496. msg: t('core', 'Error occurred while checking server setup'),
  497. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  498. });
  499. }
  500. deferred.resolve(messages);
  501. };
  502. $.ajax({
  503. type: 'GET',
  504. url: OC.generateUrl('settings/ajax/checksetup'),
  505. allowAuthErrors: true
  506. }).then(afterCall, afterCall);
  507. return deferred.promise();
  508. },
  509. addGenericSetupCheck: function(data, check, messages) {
  510. var setupCheck = data[check] || { pass: true, description: '', severity: 'info', linkToDocumentation: null}
  511. var type = OC.SetupChecks.MESSAGE_TYPE_INFO
  512. if (setupCheck.severity === 'warning') {
  513. type = OC.SetupChecks.MESSAGE_TYPE_WARNING
  514. } else if (setupCheck.severity === 'error') {
  515. type = OC.SetupChecks.MESSAGE_TYPE_ERROR
  516. }
  517. var message = setupCheck.description;
  518. if (setupCheck.linkToDocumentation) {
  519. message += ' ' + t('core', 'For more details see the {linkstart}documentation ↗{linkend}.')
  520. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + setupCheck.linkToDocumentation + '">')
  521. .replace('{linkend}', '</a>');
  522. }
  523. if (setupCheck.elements) {
  524. message += '<br><ul>'
  525. setupCheck.elements.forEach(function(element){
  526. message += '<li>';
  527. message += element
  528. message += '</li>';
  529. });
  530. message += '</ul>'
  531. }
  532. if (!setupCheck.pass) {
  533. messages.push({
  534. msg: message,
  535. type: type,
  536. })
  537. }
  538. },
  539. /**
  540. * Runs generic checks on the server side, the difference to dedicated
  541. * methods is that we use the same XHR object for all checks to save
  542. * requests.
  543. *
  544. * @return $.Deferred object resolved with an array of error messages
  545. */
  546. checkGeneric: function() {
  547. var self = this;
  548. var deferred = $.Deferred();
  549. var afterCall = function(data, statusText, xhr) {
  550. var messages = [];
  551. messages = messages.concat(self._checkSecurityHeaders(xhr));
  552. messages = messages.concat(self._checkSSL(xhr));
  553. deferred.resolve(messages);
  554. };
  555. $.ajax({
  556. type: 'GET',
  557. url: OC.generateUrl('heartbeat'),
  558. allowAuthErrors: true
  559. }).then(afterCall, afterCall);
  560. return deferred.promise();
  561. },
  562. checkDataProtected: function() {
  563. var deferred = $.Deferred();
  564. if(oc_dataURL === false){
  565. return deferred.resolve([]);
  566. }
  567. var afterCall = function(xhr) {
  568. var messages = [];
  569. // .ocdata is an empty file in the data directory - if this is readable then the data dir is not protected
  570. if (xhr.status === 200 && xhr.responseText === '') {
  571. messages.push({
  572. 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.'),
  573. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  574. });
  575. }
  576. deferred.resolve(messages);
  577. };
  578. $.ajax({
  579. type: 'GET',
  580. url: OC.linkTo('', oc_dataURL+'/.ocdata?t=' + (new Date()).getTime()),
  581. complete: afterCall,
  582. allowAuthErrors: true
  583. });
  584. return deferred.promise();
  585. },
  586. /**
  587. * Runs check for some generic security headers on the server side
  588. *
  589. * @param {Object} xhr
  590. * @return {Array} Array with error messages
  591. */
  592. _checkSecurityHeaders: function(xhr) {
  593. var messages = [];
  594. if (xhr.status === 200) {
  595. var securityHeaders = {
  596. 'X-Content-Type-Options': ['nosniff'],
  597. 'X-Robots-Tag': ['none'],
  598. 'X-Frame-Options': ['SAMEORIGIN', 'DENY'],
  599. 'X-Download-Options': ['noopen'],
  600. 'X-Permitted-Cross-Domain-Policies': ['none'],
  601. };
  602. for (var header in securityHeaders) {
  603. var option = securityHeaders[header][0];
  604. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== option.toLowerCase()) {
  605. 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});
  606. if(xhr.getResponseHeader(header) && securityHeaders[header].length > 1 && xhr.getResponseHeader(header).toLowerCase() === securityHeaders[header][1].toLowerCase()) {
  607. 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});
  608. }
  609. messages.push({
  610. msg: msg,
  611. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  612. });
  613. }
  614. }
  615. var xssfields = xhr.getResponseHeader('X-XSS-Protection') ? xhr.getResponseHeader('X-XSS-Protection').split(';').map(function(item) { return item.trim(); }) : [];
  616. if (xssfields.length === 0 || xssfields.indexOf('1') === -1 || xssfields.indexOf('mode=block') === -1) {
  617. messages.push({
  618. 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.',
  619. {
  620. header: 'X-XSS-Protection',
  621. expected: '1; mode=block'
  622. }),
  623. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  624. });
  625. }
  626. const referrerPolicy = xhr.getResponseHeader('Referrer-Policy')
  627. if (referrerPolicy === null || !/(no-referrer(-when-downgrade)?|strict-origin(-when-cross-origin)?|same-origin)(,|$)/.test(referrerPolicy)) {
  628. messages.push({
  629. 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}.',
  630. {
  631. header: 'Referrer-Policy',
  632. val1: 'no-referrer',
  633. val2: 'no-referrer-when-downgrade',
  634. val3: 'strict-origin',
  635. val4: 'strict-origin-when-cross-origin',
  636. val5: 'same-origin'
  637. })
  638. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">')
  639. .replace('{linkend}', '</a>'),
  640. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  641. })
  642. }
  643. } else {
  644. messages.push({
  645. msg: t('core', 'Error occurred while checking server setup'),
  646. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  647. });
  648. }
  649. return messages;
  650. },
  651. /**
  652. * Runs check for some SSL configuration issues on the server side
  653. *
  654. * @param {Object} xhr
  655. * @return {Array} Array with error messages
  656. */
  657. _checkSSL: function(xhr) {
  658. var messages = [];
  659. if (xhr.status === 200) {
  660. var tipsUrl = OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-security');
  661. if(OC.getProtocol() === 'https') {
  662. // Extract the value of 'Strict-Transport-Security'
  663. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  664. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  665. var firstComma = transportSecurityValidity.indexOf(";");
  666. if(firstComma !== -1) {
  667. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  668. } else {
  669. transportSecurityValidity = transportSecurityValidity.substring(8);
  670. }
  671. }
  672. var minimumSeconds = 15552000;
  673. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  674. messages.push({
  675. 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})
  676. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">')
  677. .replace('{linkend}', '</a>'),
  678. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  679. });
  680. }
  681. } else {
  682. messages.push({
  683. 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}.')
  684. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">')
  685. .replace('{linkend}', '</a>'),
  686. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  687. });
  688. }
  689. } else {
  690. messages.push({
  691. msg: t('core', 'Error occurred while checking server setup'),
  692. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  693. });
  694. }
  695. return messages;
  696. }
  697. };
  698. })();