setup.component.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* global siteConfig */
  2. import axios from 'axios'
  3. export default {
  4. name: 'configManager',
  5. data() {
  6. return {
  7. loading: false,
  8. state: 'welcome',
  9. syscheck: {
  10. ok: false,
  11. error: '',
  12. results: []
  13. },
  14. dbcheck: {
  15. ok: false,
  16. error: ''
  17. },
  18. gitcheck: {
  19. ok: false,
  20. error: ''
  21. },
  22. final: {
  23. ok: false,
  24. error: '',
  25. results: []
  26. },
  27. conf: {
  28. adminEmail: '',
  29. adminPassword: '',
  30. adminPasswordConfirm: '',
  31. gitAuthPass: '',
  32. gitAuthSSHKey: '',
  33. gitAuthSSHKeyEnv: '',
  34. gitAuthSSHKeyDB: '',
  35. gitAuthSSL: true,
  36. gitAuthType: 'ssh',
  37. gitAuthUser: '',
  38. gitBranch: 'master',
  39. gitServerEmail: '',
  40. gitShowUserEmail: true,
  41. gitUrl: '',
  42. gitUseRemote: (siteConfig.git !== false),
  43. lang: siteConfig.lang || 'en',
  44. path: siteConfig.path || '/',
  45. pathRepo: './repo',
  46. port: siteConfig.port || 80,
  47. public: (siteConfig.public === true),
  48. selfRegister: (siteConfig.selfRegister === true),
  49. telemetry: true,
  50. title: siteConfig.title || 'Wiki',
  51. upgrade: false,
  52. upgMongo: 'mongodb://'
  53. },
  54. considerations: {
  55. https: false,
  56. port: false,
  57. localhost: false
  58. }
  59. }
  60. },
  61. computed: {
  62. currentProgress: function () {
  63. let perc = '0%'
  64. switch (this.state) {
  65. case 'welcome':
  66. perc = '0%'
  67. break
  68. case 'syscheck':
  69. perc = (this.syscheck.ok) ? '15%' : '5%'
  70. break
  71. case 'general':
  72. perc = '25%'
  73. break
  74. case 'considerations':
  75. perc = '30%'
  76. break
  77. case 'git':
  78. perc = '50%'
  79. break
  80. case 'gitcheck':
  81. perc = (this.gitcheck.ok) ? '70%' : '55%'
  82. break
  83. case 'admin':
  84. perc = '75%'
  85. break
  86. case 'upgrade':
  87. perc = '85%'
  88. break
  89. }
  90. return perc
  91. }
  92. },
  93. mounted: function () {
  94. /* if (appconfig.paths) {
  95. this.conf.pathData = appconfig.paths.data || './data'
  96. this.conf.pathRepo = appconfig.paths.repo || './repo'
  97. }
  98. if (appconfig.git !== false && _.isPlainObject(appconfig.git)) {
  99. this.conf.gitUrl = appconfig.git.url || ''
  100. this.conf.gitBranch = appconfig.git.branch || 'master'
  101. this.conf.gitShowUserEmail = (appconfig.git.showUserEmail !== false)
  102. this.conf.gitServerEmail = appconfig.git.serverEmail || ''
  103. if (_.isPlainObject(appconfig.git.auth)) {
  104. this.conf.gitAuthType = appconfig.git.auth.type || 'ssh'
  105. this.conf.gitAuthSSHKey = appconfig.git.auth.privateKey || ''
  106. this.conf.gitAuthUser = appconfig.git.auth.username || ''
  107. this.conf.gitAuthPass = appconfig.git.auth.password || ''
  108. this.conf.gitAuthSSL = (appconfig.git.auth.sslVerify !== false)
  109. }
  110. } */
  111. },
  112. methods: {
  113. proceedToWelcome: function (ev) {
  114. this.state = 'welcome'
  115. this.loading = false
  116. },
  117. proceedToSyscheck: function (ev) {
  118. let self = this
  119. this.state = 'syscheck'
  120. this.loading = true
  121. self.syscheck = {
  122. ok: false,
  123. error: '',
  124. results: []
  125. }
  126. this.$helpers._.delay(() => {
  127. axios.post('/syscheck', self.conf).then(resp => {
  128. if (resp.data.ok === true) {
  129. self.syscheck.ok = true
  130. self.syscheck.results = resp.data.results
  131. } else {
  132. self.syscheck.ok = false
  133. self.syscheck.error = resp.data.error
  134. }
  135. self.loading = false
  136. self.$nextTick()
  137. }).catch(err => {
  138. window.alert(err.message)
  139. })
  140. }, 1000)
  141. },
  142. proceedToGeneral: function (ev) {
  143. let self = this
  144. self.state = 'general'
  145. self.loading = false
  146. self.$nextTick(() => {
  147. self.$validator.validateAll('general')
  148. })
  149. },
  150. proceedToConsiderations: function (ev) {
  151. this.considerations = {
  152. https: !this.$helpers._.startsWith(this.conf.host, 'https'),
  153. port: false, // TODO
  154. localhost: this.$helpers._.includes(this.conf.host, 'localhost')
  155. }
  156. this.state = 'considerations'
  157. this.loading = false
  158. },
  159. proceedToGit: function (ev) {
  160. let self = this
  161. self.state = 'git'
  162. self.loading = false
  163. self.$nextTick(() => {
  164. self.$validator.validateAll('git')
  165. })
  166. },
  167. proceedToGitCheck: function (ev) {
  168. let self = this
  169. this.state = 'gitcheck'
  170. this.loading = true
  171. self.gitcheck = {
  172. ok: false,
  173. results: [],
  174. error: ''
  175. }
  176. this.$helpers._.delay(() => {
  177. axios.post('/gitcheck', self.conf).then(resp => {
  178. if (resp.data.ok === true) {
  179. self.gitcheck.ok = true
  180. self.gitcheck.results = resp.data.results
  181. } else {
  182. self.gitcheck.ok = false
  183. self.gitcheck.error = resp.data.error
  184. }
  185. self.loading = false
  186. self.$nextTick()
  187. }).catch(err => {
  188. window.alert(err.message)
  189. })
  190. }, 1000)
  191. },
  192. proceedToAdmin: function (ev) {
  193. let self = this
  194. self.state = 'admin'
  195. self.loading = false
  196. self.$nextTick(() => {
  197. self.$validator.validateAll('admin')
  198. })
  199. },
  200. proceedToUpgrade: function (ev) {
  201. if (this.conf.upgrade) {
  202. this.state = 'upgrade'
  203. this.loading = false
  204. this.$nextTick(() => {
  205. this.$validator.validateAll('upgrade')
  206. })
  207. } else {
  208. this.proceedToFinal()
  209. }
  210. },
  211. proceedToFinal: function (ev) {
  212. let self = this
  213. self.state = 'final'
  214. self.loading = true
  215. self.final = {
  216. ok: false,
  217. error: '',
  218. results: []
  219. }
  220. this.$helpers._.delay(() => {
  221. axios.post('/finalize', self.conf).then(resp => {
  222. if (resp.data.ok === true) {
  223. self.final.ok = true
  224. self.final.results = resp.data.results
  225. } else {
  226. self.final.ok = false
  227. self.final.error = resp.data.error
  228. }
  229. self.loading = false
  230. self.$nextTick()
  231. }).catch(err => {
  232. window.alert(err.message)
  233. })
  234. }, 1000)
  235. },
  236. finish: function (ev) {
  237. let self = this
  238. self.state = 'restart'
  239. this.$helpers._.delay(() => {
  240. axios.post('/restart', {}).then(resp => {
  241. this.$helpers._.delay(() => {
  242. window.location.assign(self.conf.host)
  243. }, 30000)
  244. }).catch(err => {
  245. window.alert(err.message)
  246. })
  247. }, 1000)
  248. }
  249. }
  250. }