config-manager.component.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. upgUserGroups: false
  54. },
  55. considerations: {
  56. https: false,
  57. port: false,
  58. localhost: false
  59. }
  60. }
  61. },
  62. computed: {
  63. currentProgress: function () {
  64. let perc = '0%'
  65. switch (this.state) {
  66. case 'welcome':
  67. perc = '0%'
  68. break
  69. case 'syscheck':
  70. perc = (this.syscheck.ok) ? '15%' : '5%'
  71. break
  72. case 'general':
  73. perc = '25%'
  74. break
  75. case 'considerations':
  76. perc = '30%'
  77. break
  78. case 'git':
  79. perc = '50%'
  80. break
  81. case 'gitcheck':
  82. perc = (this.gitcheck.ok) ? '70%' : '55%'
  83. break
  84. case 'admin':
  85. perc = '75%'
  86. break
  87. case 'upgrade':
  88. perc = '85%'
  89. break
  90. }
  91. return perc
  92. }
  93. },
  94. mounted: function () {
  95. /* if (appconfig.paths) {
  96. this.conf.pathData = appconfig.paths.data || './data'
  97. this.conf.pathRepo = appconfig.paths.repo || './repo'
  98. }
  99. if (appconfig.git !== false && _.isPlainObject(appconfig.git)) {
  100. this.conf.gitUrl = appconfig.git.url || ''
  101. this.conf.gitBranch = appconfig.git.branch || 'master'
  102. this.conf.gitShowUserEmail = (appconfig.git.showUserEmail !== false)
  103. this.conf.gitServerEmail = appconfig.git.serverEmail || ''
  104. if (_.isPlainObject(appconfig.git.auth)) {
  105. this.conf.gitAuthType = appconfig.git.auth.type || 'ssh'
  106. this.conf.gitAuthSSHKey = appconfig.git.auth.privateKey || ''
  107. this.conf.gitAuthUser = appconfig.git.auth.username || ''
  108. this.conf.gitAuthPass = appconfig.git.auth.password || ''
  109. this.conf.gitAuthSSL = (appconfig.git.auth.sslVerify !== false)
  110. }
  111. } */
  112. },
  113. methods: {
  114. proceedToWelcome: function (ev) {
  115. this.state = 'welcome'
  116. this.loading = false
  117. },
  118. proceedToSyscheck: function (ev) {
  119. let self = this
  120. this.state = 'syscheck'
  121. this.loading = true
  122. self.syscheck = {
  123. ok: false,
  124. error: '',
  125. results: []
  126. }
  127. this.$helpers._.delay(() => {
  128. axios.post('/syscheck', self.conf).then(resp => {
  129. if (resp.data.ok === true) {
  130. self.syscheck.ok = true
  131. self.syscheck.results = resp.data.results
  132. } else {
  133. self.syscheck.ok = false
  134. self.syscheck.error = resp.data.error
  135. }
  136. self.loading = false
  137. self.$nextTick()
  138. }).catch(err => {
  139. window.alert(err.message)
  140. })
  141. }, 1000)
  142. },
  143. proceedToGeneral: function (ev) {
  144. let self = this
  145. self.state = 'general'
  146. self.loading = false
  147. self.$nextTick(() => {
  148. self.$validator.validateAll('general')
  149. })
  150. },
  151. proceedToConsiderations: function (ev) {
  152. this.considerations = {
  153. https: !this.$helpers._.startsWith(this.conf.host, 'https'),
  154. port: false, // TODO
  155. localhost: this.$helpers._.includes(this.conf.host, 'localhost')
  156. }
  157. this.state = 'considerations'
  158. this.loading = false
  159. },
  160. proceedToGit: function (ev) {
  161. let self = this
  162. self.state = 'git'
  163. self.loading = false
  164. self.$nextTick(() => {
  165. self.$validator.validateAll('git')
  166. })
  167. },
  168. proceedToGitCheck: function (ev) {
  169. let self = this
  170. this.state = 'gitcheck'
  171. this.loading = true
  172. self.gitcheck = {
  173. ok: false,
  174. results: [],
  175. error: ''
  176. }
  177. this.$helpers._.delay(() => {
  178. axios.post('/gitcheck', self.conf).then(resp => {
  179. if (resp.data.ok === true) {
  180. self.gitcheck.ok = true
  181. self.gitcheck.results = resp.data.results
  182. } else {
  183. self.gitcheck.ok = false
  184. self.gitcheck.error = resp.data.error
  185. }
  186. self.loading = false
  187. self.$nextTick()
  188. }).catch(err => {
  189. window.alert(err.message)
  190. })
  191. }, 1000)
  192. },
  193. proceedToAdmin: function (ev) {
  194. let self = this
  195. self.state = 'admin'
  196. self.loading = false
  197. self.$nextTick(() => {
  198. self.$validator.validateAll('admin')
  199. })
  200. },
  201. proceedToUpgrade: function (ev) {
  202. if (this.conf.upgrade) {
  203. this.state = 'upgrade'
  204. this.loading = false
  205. this.$nextTick(() => {
  206. this.$validator.validateAll('upgrade')
  207. })
  208. } else {
  209. this.proceedToFinal()
  210. }
  211. },
  212. proceedToFinal: function (ev) {
  213. let self = this
  214. self.state = 'final'
  215. self.loading = true
  216. self.final = {
  217. ok: false,
  218. error: '',
  219. results: []
  220. }
  221. this.$helpers._.delay(() => {
  222. axios.post('/finalize', self.conf).then(resp => {
  223. if (resp.data.ok === true) {
  224. self.final.ok = true
  225. self.final.results = resp.data.results
  226. } else {
  227. self.final.ok = false
  228. self.final.error = resp.data.error
  229. }
  230. self.loading = false
  231. self.$nextTick()
  232. }).catch(err => {
  233. window.alert(err.message)
  234. })
  235. }, 1000)
  236. },
  237. finish: function (ev) {
  238. let self = this
  239. self.state = 'restart'
  240. this.$helpers._.delay(() => {
  241. axios.post('/restart', {}).then(resp => {
  242. this.$helpers._.delay(() => {
  243. window.location.assign(self.conf.host)
  244. }, 30000)
  245. }).catch(err => {
  246. window.alert(err.message)
  247. })
  248. }, 1000)
  249. }
  250. }
  251. }