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.

install.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. * @author Julius Härtl <jus@bitgrid.net>
  6. * @author Richard Steinmetz <richard@steinmetz.cloud>
  7. *
  8. * @license AGPL-3.0-or-later
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. import $ from 'jquery'
  25. import { translate as t } from '@nextcloud/l10n'
  26. import { getToken } from './OC/requesttoken.js'
  27. import getURLParameter from './Util/get-url-parameter.js'
  28. import './jquery/showpassword.js'
  29. import 'jquery-ui/ui/widgets/button.js'
  30. import 'jquery-ui/themes/base/theme.css'
  31. import 'jquery-ui/themes/base/button.css'
  32. import './Polyfill/tooltip.js'
  33. import 'strengthify'
  34. import 'strengthify/strengthify.css'
  35. window.addEventListener('DOMContentLoaded', function() {
  36. const dbtypes = {
  37. sqlite: !!$('#hasSQLite').val(),
  38. mysql: !!$('#hasMySQL').val(),
  39. postgresql: !!$('#hasPostgreSQL').val(),
  40. oracle: !!$('#hasOracle').val(),
  41. }
  42. $('#selectDbType').buttonset()
  43. // change links inside an info box back to their default appearance
  44. $('#selectDbType p.info a').button('destroy')
  45. if ($('#hasSQLite').val()) {
  46. $('#use_other_db').hide()
  47. $('#use_oracle_db').hide()
  48. } else {
  49. $('#sqliteInformation').hide()
  50. }
  51. $('#adminlogin').change(function() {
  52. $('#adminlogin').val($.trim($('#adminlogin').val()))
  53. })
  54. $('#sqlite').click(function() {
  55. $('#use_other_db').slideUp(250)
  56. $('#use_oracle_db').slideUp(250)
  57. $('#sqliteInformation').show()
  58. $('#dbname').attr('pattern', '[0-9a-zA-Z$_-]+')
  59. })
  60. $('#mysql,#pgsql').click(function() {
  61. $('#use_other_db').slideDown(250)
  62. $('#use_oracle_db').slideUp(250)
  63. $('#sqliteInformation').hide()
  64. $('#dbname').attr('pattern', '[0-9a-zA-Z$_-]+')
  65. })
  66. $('#oci').click(function() {
  67. $('#use_other_db').slideDown(250)
  68. $('#use_oracle_db').show(250)
  69. $('#sqliteInformation').hide()
  70. $('#dbname').attr('pattern', '[0-9a-zA-Z$_-.]+')
  71. })
  72. $('#showAdvanced').click(function(e) {
  73. e.preventDefault()
  74. $('#datadirContent').slideToggle(250)
  75. $('#databaseBackend').slideToggle(250)
  76. $('#databaseField').slideToggle(250)
  77. })
  78. $('form').submit(function() {
  79. // Save form parameters
  80. const post = $(this).serializeArray()
  81. // Show spinner while finishing setup
  82. $('.float-spinner').show(250)
  83. // Disable inputs
  84. $('input[type="submit"]').attr('disabled', 'disabled').val($('input[type="submit"]').data('finishing'))
  85. $('input', this).addClass('ui-state-disabled').attr('disabled', 'disabled')
  86. // only disable buttons if they are present
  87. if ($('#selectDbType').find('.ui-button').length > 0) {
  88. $('#selectDbType').buttonset('disable')
  89. }
  90. $('.strengthify-wrapper, .tipsy')
  91. .css('filter', 'alpha(opacity=30)')
  92. .css('opacity', 0.3)
  93. // Create the form
  94. const form = $('<form>')
  95. form.attr('action', $(this).attr('action'))
  96. form.attr('method', 'POST')
  97. for (let i = 0; i < post.length; i++) {
  98. const input = $('<input type="hidden">')
  99. input.attr(post[i])
  100. form.append(input)
  101. }
  102. // Add redirect_url
  103. const redirectURL = getURLParameter('redirect_url')
  104. if (redirectURL) {
  105. const redirectURLInput = $('<input type="hidden">')
  106. redirectURLInput.attr({
  107. name: 'redirect_url',
  108. value: redirectURL,
  109. })
  110. form.append(redirectURLInput)
  111. }
  112. // Submit the form
  113. form.appendTo(document.body)
  114. form.submit()
  115. return false
  116. })
  117. // Expand latest db settings if page was reloaded on error
  118. const currentDbType = $('input[type="radio"]:checked').val()
  119. if (currentDbType === undefined) {
  120. $('input[type="radio"]').first().click()
  121. }
  122. if (
  123. currentDbType === 'sqlite'
  124. || (dbtypes.sqlite && currentDbType === undefined)
  125. ) {
  126. $('#datadirContent').hide(250)
  127. $('#databaseBackend').hide(250)
  128. $('#databaseField').hide(250)
  129. $('.float-spinner').hide(250)
  130. }
  131. $('#adminpass').strengthify({
  132. zxcvbn: OC.linkTo('core', 'vendor/zxcvbn/dist/zxcvbn.js'),
  133. titles: [
  134. t('core', 'Very weak password'),
  135. t('core', 'Weak password'),
  136. t('core', 'So-so password'),
  137. t('core', 'Good password'),
  138. t('core', 'Strong password'),
  139. ],
  140. drawTitles: true,
  141. nonce: btoa(getToken()),
  142. })
  143. $('#dbpass').showPassword().keyup()
  144. $('.toggle-password').click(function(event) {
  145. event.preventDefault()
  146. const currentValue = $(this).parent().children('input').attr('type')
  147. if (currentValue === 'password') {
  148. $(this).parent().children('input').attr('type', 'text')
  149. } else {
  150. $(this).parent().children('input').attr('type', 'password')
  151. }
  152. })
  153. })