getting_started_controller.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. require 'resolv'
  3. class GettingStartedController < ApplicationController
  4. =begin
  5. Resource:
  6. GET /api/v1/getting_started
  7. Response:
  8. {
  9. "master_user": 1,
  10. "groups": [
  11. {
  12. "name": "group1",
  13. "active":true
  14. },
  15. {
  16. "name": "group2",
  17. "active":true
  18. }
  19. ]
  20. }
  21. Test:
  22. curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
  23. =end
  24. def index
  25. # check if first user already exists
  26. return if setup_done_response
  27. # check it auto wizard is already done
  28. auto_wizard_admin = AutoWizard.setup
  29. if auto_wizard_admin
  30. # set current session user
  31. current_user_set(auto_wizard_admin)
  32. # set system init to done
  33. Setting.set( 'system_init_done', true )
  34. render json: {
  35. auto_wizard: true,
  36. setup_done: setup_done,
  37. import_mode: Setting.get('import_mode'),
  38. import_backend: Setting.get('import_backend'),
  39. system_online_service: Setting.get('system_online_service'),
  40. }
  41. return
  42. end
  43. # if master user already exists, we need to be authenticated
  44. if setup_done
  45. return if !authentication_check
  46. end
  47. # return result
  48. render json: {
  49. setup_done: setup_done,
  50. import_mode: Setting.get('import_mode'),
  51. import_backend: Setting.get('import_backend'),
  52. system_online_service: Setting.get('system_online_service'),
  53. }
  54. end
  55. def base
  56. # check admin permissions
  57. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  58. # validate url
  59. messages = {}
  60. if !Setting.get('system_online_service')
  61. if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$}
  62. messages[:url] = 'A URL looks like http://zammad.example.com'
  63. end
  64. end
  65. # validate organization
  66. if !params[:organization] || params[:organization].empty?
  67. messages[:organization] = 'Invalid!'
  68. end
  69. # validate image
  70. if params[:logo] && params[:logo] =~ /^data:image/i
  71. file = StaticAssets.data_url_attributes( params[:logo] )
  72. if !file[:content] || !file[:mime_type]
  73. messages[:logo] = 'Unable to process image upload.'
  74. end
  75. end
  76. if !messages.empty?
  77. render json: {
  78. result: 'invalid',
  79. messages: messages,
  80. }
  81. return
  82. end
  83. # split url in http_type and fqdn
  84. settings = {}
  85. if !Setting.get('system_online_service')
  86. if params[:url] =~ %r{/^(http|https)://(.+?)$}
  87. Setting.set('http_type', $1)
  88. settings[:http_type] = $1
  89. Setting.set('fqdn', $2)
  90. settings[:fqdn] = $2
  91. end
  92. end
  93. # save organization
  94. Setting.set('organization', params[:organization])
  95. settings[:organization] = params[:organization]
  96. # save image
  97. if params[:logo] && params[:logo] =~ /^data:image/i
  98. # data:image/png;base64
  99. file = StaticAssets.data_url_attributes( params[:logo] )
  100. # store image 1:1
  101. StaticAssets.store_raw( file[:content], file[:mime_type] )
  102. end
  103. if params[:logo_resize] && params[:logo_resize] =~ /^data:image/i
  104. # data:image/png;base64
  105. file = StaticAssets.data_url_attributes( params[:logo_resize] )
  106. # store image 1:1
  107. settings[:product_logo] = StaticAssets.store( file[:content], file[:mime_type] )
  108. end
  109. # set changed settings
  110. settings.each {|key, value|
  111. Setting.set(key, value)
  112. }
  113. render json: {
  114. result: 'ok',
  115. settings: settings,
  116. }
  117. end
  118. def email_probe
  119. # check admin permissions
  120. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  121. # validation
  122. user = nil
  123. domain = nil
  124. if params[:email] =~ /^(.+?)@(.+?)$/
  125. user = $1
  126. domain = $2
  127. end
  128. if !user || !domain
  129. render json: {
  130. result: 'invalid',
  131. messages: {
  132. email: 'Invalid email.'
  133. },
  134. }
  135. return
  136. end
  137. # check domain based attributes
  138. provider_map = {
  139. google: {
  140. domain: 'gmail.com|googlemail.com|gmail.de',
  141. inbound: {
  142. adapter: 'imap',
  143. options: {
  144. host: 'imap.gmail.com',
  145. port: '993',
  146. ssl: true,
  147. user: params[:email],
  148. password: params[:password],
  149. },
  150. },
  151. outbound: {
  152. adapter: 'smtp',
  153. options: {
  154. host: 'smtp.gmail.com',
  155. port: '25',
  156. start_tls: true,
  157. user: params[:email],
  158. password: params[:password],
  159. }
  160. },
  161. },
  162. microsoft: {
  163. domain: 'outlook.com|hotmail.com',
  164. inbound: {
  165. adapter: 'imap',
  166. options: {
  167. host: 'imap-mail.outlook.com',
  168. port: '993',
  169. ssl: true,
  170. user: params[:email],
  171. password: params[:password],
  172. },
  173. },
  174. outbound: {
  175. adapter: 'smtp',
  176. options: {
  177. host: 'smtp-mail.outlook.com',
  178. port: 25,
  179. start_tls: true,
  180. user: params[:email],
  181. password: params[:password],
  182. }
  183. },
  184. },
  185. }
  186. # probe based on email domain and mx
  187. domains = [domain]
  188. mail_exchangers = mxers(domain)
  189. if mail_exchangers && mail_exchangers[0]
  190. logger.info "MX for #{domain}: #{mail_exchangers} - #{mail_exchangers[0][0]}"
  191. end
  192. if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
  193. domains.push mail_exchangers[0][0]
  194. end
  195. provider_map.each {|_provider, settings|
  196. domains.each {|domain_to_check|
  197. next if domain_to_check !~ /#{settings[:domain]}/i
  198. # probe inbound
  199. result = email_probe_inbound( settings[:inbound] )
  200. if result[:result] != 'ok'
  201. render json: result
  202. return # rubocop:disable Lint/NonLocalExitFromIterator
  203. end
  204. # probe outbound
  205. result = email_probe_outbound( settings[:outbound], params[:email] )
  206. if result[:result] != 'ok'
  207. render json: result
  208. return # rubocop:disable Lint/NonLocalExitFromIterator
  209. end
  210. render json: {
  211. result: 'ok',
  212. setting: settings,
  213. }
  214. return # rubocop:disable Lint/NonLocalExitFromIterator
  215. }
  216. }
  217. # probe inbound
  218. inbound_map = []
  219. if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
  220. inbound_mx = [
  221. {
  222. adapter: 'imap',
  223. options: {
  224. host: mail_exchangers[0][0],
  225. port: 993,
  226. ssl: true,
  227. user: user,
  228. password: params[:password],
  229. },
  230. },
  231. {
  232. adapter: 'imap',
  233. options: {
  234. host: mail_exchangers[0][0],
  235. port: 993,
  236. ssl: true,
  237. user: params[:email],
  238. password: params[:password],
  239. },
  240. },
  241. ]
  242. inbound_map = inbound_map + inbound_mx
  243. end
  244. inbound_auto = [
  245. {
  246. adapter: 'imap',
  247. options: {
  248. host: "mail.#{domain}",
  249. port: 993,
  250. ssl: true,
  251. user: user,
  252. password: params[:password],
  253. },
  254. },
  255. {
  256. adapter: 'imap',
  257. options: {
  258. host: "mail.#{domain}",
  259. port: 993,
  260. ssl: true,
  261. user: params[:email],
  262. password: params[:password],
  263. },
  264. },
  265. {
  266. adapter: 'imap',
  267. options: {
  268. host: "imap.#{domain}",
  269. port: 993,
  270. ssl: true,
  271. user: user,
  272. password: params[:password],
  273. },
  274. },
  275. {
  276. adapter: 'imap',
  277. options: {
  278. host: "imap.#{domain}",
  279. port: 993,
  280. ssl: true,
  281. user: params[:email],
  282. password: params[:password],
  283. },
  284. },
  285. {
  286. adapter: 'pop3',
  287. options: {
  288. host: "mail.#{domain}",
  289. port: 995,
  290. ssl: true,
  291. user: user,
  292. password: params[:password],
  293. },
  294. },
  295. {
  296. adapter: 'pop3',
  297. options: {
  298. host: "mail.#{domain}",
  299. port: 995,
  300. ssl: true,
  301. user: params[:email],
  302. password: params[:password],
  303. },
  304. },
  305. {
  306. adapter: 'pop3',
  307. options: {
  308. host: "pop.#{domain}",
  309. port: 995,
  310. ssl: true,
  311. user: user,
  312. password: params[:password],
  313. },
  314. },
  315. {
  316. adapter: 'pop3',
  317. options: {
  318. host: "pop.#{domain}",
  319. port: 995,
  320. ssl: true,
  321. user: params[:email],
  322. password: params[:password],
  323. },
  324. },
  325. {
  326. adapter: 'pop3',
  327. options: {
  328. host: "pop3.#{domain}",
  329. port: 995,
  330. ssl: true,
  331. user: user,
  332. password: params[:password],
  333. },
  334. },
  335. {
  336. adapter: 'pop3',
  337. options: {
  338. host: "pop3.#{domain}",
  339. port: 995,
  340. ssl: true,
  341. user: params[:email],
  342. password: params[:password],
  343. },
  344. },
  345. ]
  346. inbound_map = inbound_map + inbound_auto
  347. settings = {}
  348. success = false
  349. inbound_map.each {|config|
  350. logger.info "INBOUND PROBE: #{config.inspect}"
  351. result = email_probe_inbound( config )
  352. logger.info "INBOUND RESULT: #{result.inspect}"
  353. next if result[:result] != 'ok'
  354. success = true
  355. settings[:inbound] = config
  356. break
  357. }
  358. if !success
  359. render json: {
  360. result: 'failed',
  361. }
  362. return
  363. end
  364. # probe outbound
  365. outbound_map = []
  366. if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
  367. outbound_mx = [
  368. {
  369. adapter: 'smtp',
  370. options: {
  371. host: mail_exchangers[0][0],
  372. port: 25,
  373. start_tls: true,
  374. user: user,
  375. password: params[:password],
  376. },
  377. },
  378. {
  379. adapter: 'smtp',
  380. options: {
  381. host: mail_exchangers[0][0],
  382. port: 25,
  383. start_tls: true,
  384. user: params[:email],
  385. password: params[:password],
  386. },
  387. },
  388. {
  389. adapter: 'smtp',
  390. options: {
  391. host: mail_exchangers[0][0],
  392. port: 465,
  393. start_tls: true,
  394. user: user,
  395. password: params[:password],
  396. },
  397. },
  398. {
  399. adapter: 'smtp',
  400. options: {
  401. host: mail_exchangers[0][0],
  402. port: 465,
  403. start_tls: true,
  404. user: params[:email],
  405. password: params[:password],
  406. },
  407. },
  408. ]
  409. outbound_map = outbound_map + outbound_mx
  410. end
  411. outbound_auto = [
  412. {
  413. adapter: 'smtp',
  414. options: {
  415. host: "mail.#{domain}",
  416. port: 25,
  417. start_tls: true,
  418. user: user,
  419. password: params[:password],
  420. },
  421. },
  422. {
  423. adapter: 'smtp',
  424. options: {
  425. host: "mail.#{domain}",
  426. port: 25,
  427. start_tls: true,
  428. user: params[:email],
  429. password: params[:password],
  430. },
  431. },
  432. {
  433. adapter: 'smtp',
  434. options: {
  435. host: "mail.#{domain}",
  436. port: 465,
  437. start_tls: true,
  438. user: user,
  439. password: params[:password],
  440. },
  441. },
  442. {
  443. adapter: 'smtp',
  444. options: {
  445. host: "mail.#{domain}",
  446. port: 465,
  447. start_tls: true,
  448. user: params[:email],
  449. password: params[:password],
  450. },
  451. },
  452. {
  453. adapter: 'smtp',
  454. options: {
  455. host: "smtp.#{domain}",
  456. port: 25,
  457. start_tls: true,
  458. user: user,
  459. password: params[:password],
  460. },
  461. },
  462. {
  463. adapter: 'smtp',
  464. options: {
  465. host: "smtp.#{domain}",
  466. port: 25,
  467. start_tls: true,
  468. user: params[:email],
  469. password: params[:password],
  470. },
  471. },
  472. {
  473. adapter: 'smtp',
  474. options: {
  475. host: "smtp.#{domain}",
  476. port: 465,
  477. start_tls: true,
  478. user: user,
  479. password: params[:password],
  480. },
  481. },
  482. {
  483. adapter: 'smtp',
  484. options: {
  485. host: "smtp.#{domain}",
  486. port: 465,
  487. start_tls: true,
  488. user: params[:email],
  489. password: params[:password],
  490. },
  491. },
  492. ]
  493. success = false
  494. outbound_map.each {|config|
  495. logger.info "OUTBOUND PROBE: #{config.inspect}"
  496. result = email_probe_outbound( config, params[:email] )
  497. logger.info "OUTBOUND RESULT: #{result.inspect}"
  498. next if result[:result] != 'ok'
  499. success = true
  500. settings[:outbound] = config
  501. break
  502. }
  503. if !success
  504. render json: {
  505. result: 'failed',
  506. }
  507. return
  508. end
  509. render json: {
  510. result: 'ok',
  511. setting: settings,
  512. }
  513. end
  514. def email_outbound
  515. # check admin permissions
  516. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  517. # validate params
  518. if !params[:adapter]
  519. render json: {
  520. result: 'invalid',
  521. }
  522. return
  523. end
  524. # connection test
  525. result = email_probe_outbound( params, params[:email] )
  526. render json: result
  527. end
  528. def email_inbound
  529. # check admin permissions
  530. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  531. # validate params
  532. if !params[:adapter]
  533. render json: {
  534. result: 'invalid',
  535. }
  536. return
  537. end
  538. # connection test
  539. result = email_probe_inbound( params )
  540. render json: result
  541. end
  542. def email_verify
  543. # check admin permissions
  544. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  545. # send verify email to inbox
  546. if !params[:subject]
  547. subject = '#' + rand(99_999_999_999).to_s
  548. else
  549. subject = params[:subject]
  550. end
  551. result = email_probe_outbound( params[:outbound], params[:meta][:email], subject )
  552. (1..5).each {
  553. sleep 10
  554. # fetch mailbox
  555. found = nil
  556. begin
  557. if params[:inbound][:adapter] =~ /^imap$/i
  558. found = Channel::IMAP.new.fetch( { options: params[:inbound][:options] }, 'verify', subject )
  559. else
  560. found = Channel::POP3.new.fetch( { options: params[:inbound][:options] }, 'verify', subject )
  561. end
  562. rescue Exception => e
  563. render json: {
  564. result: 'invalid',
  565. message: e.to_s,
  566. subject: subject,
  567. }
  568. return # rubocop:disable Lint/NonLocalExitFromIterator
  569. end
  570. next if !found
  571. next if found != 'verify ok'
  572. # remember address
  573. address = EmailAddress.where( email: params[:meta][:email] ).first
  574. if !address
  575. address = EmailAddress.first
  576. end
  577. if address
  578. address.update_attributes(
  579. realname: params[:meta][:realname],
  580. email: params[:meta][:email],
  581. active: 1,
  582. updated_by_id: 1,
  583. created_by_id: 1,
  584. )
  585. else
  586. EmailAddress.create(
  587. realname: params[:meta][:realname],
  588. email: params[:meta][:email],
  589. active: 1,
  590. updated_by_id: 1,
  591. created_by_id: 1,
  592. )
  593. end
  594. # store mailbox
  595. Channel.create(
  596. area: 'Email::Inbound',
  597. adapter: params[:inbound][:adapter],
  598. options: params[:inbound][:options],
  599. group_id: 1,
  600. active: 1,
  601. updated_by_id: 1,
  602. created_by_id: 1,
  603. )
  604. # save settings
  605. if params[:outbound][:adapter] =~ /^smtp$/i
  606. smtp = Channel.where( adapter: 'SMTP', area: 'Email::Outbound' ).first
  607. smtp.options = params[:outbound][:options]
  608. smtp.active = true
  609. smtp.save!
  610. sendmail = Channel.where( adapter: 'Sendmail' ).first
  611. sendmail.active = false
  612. sendmail.save!
  613. else
  614. sendmail = Channel.where( adapter: 'Sendmail', area: 'Email::Outbound' ).first
  615. sendmail.options = {}
  616. sendmail.active = true
  617. sendmail.save!
  618. smtp = Channel.where( adapter: 'SMTP' ).first
  619. smtp.active = false
  620. smtp.save
  621. end
  622. render json: {
  623. result: 'ok',
  624. }
  625. return # rubocop:disable Lint/NonLocalExitFromIterator
  626. }
  627. # check delivery for 30 sek.
  628. render json: {
  629. result: 'invalid',
  630. message: 'Verification Email not found in mailbox.',
  631. subject: subject,
  632. }
  633. end
  634. private
  635. def email_probe_outbound(params, email, subject = nil)
  636. # validate params
  637. if !params[:adapter]
  638. result = {
  639. result: 'invalid',
  640. message: 'Invalid, need adapter!',
  641. }
  642. return result
  643. end
  644. if subject
  645. mail = {
  646. :from => email,
  647. :to => email,
  648. :subject => "Zammad Getting started Test Email #{subject}",
  649. :body => "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.",
  650. 'x-zammad-ignore' => 'true',
  651. }
  652. else
  653. mail = {
  654. from: email,
  655. to: 'emailtrytest@znuny.com',
  656. subject: 'test',
  657. body: 'test',
  658. }
  659. end
  660. # test connection
  661. translation_map = {
  662. 'authentication failed' => 'Authentication failed!',
  663. 'Incorrect username' => 'Authentication failed!',
  664. 'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!',
  665. 'No route to host' => 'No route to host!',
  666. 'Connection refused' => 'Connection refused!',
  667. }
  668. if params[:adapter] =~ /^smtp$/i
  669. # in case, fill missing params
  670. if !params[:options].key?(:port)
  671. params[:options][:port] = 25
  672. end
  673. if !params[:options].key?(:ssl)
  674. params[:options][:ssl] = true
  675. end
  676. begin
  677. Channel::SMTP.new.send(
  678. mail,
  679. {
  680. options: params[:options]
  681. }
  682. )
  683. rescue Exception => e
  684. # check if sending email was ok, but mailserver rejected
  685. if !subject
  686. white_map = {
  687. 'Recipient address rejected' => true,
  688. }
  689. white_map.each {|key, _message|
  690. next if e.message !~ /#{Regexp.escape(key)}/i
  691. result = {
  692. result: 'ok',
  693. settings: params,
  694. notice: e.message,
  695. }
  696. return result
  697. }
  698. end
  699. message_human = ''
  700. translation_map.each {|key, message|
  701. if e.message =~ /#{Regexp.escape(key)}/i
  702. message_human = message
  703. end
  704. }
  705. result = {
  706. result: 'invalid',
  707. settings: params,
  708. message: e.message,
  709. message_human: message_human,
  710. }
  711. return result
  712. end
  713. result = {
  714. result: 'ok',
  715. }
  716. return result
  717. end
  718. begin
  719. Channel::Sendmail.new.send(
  720. mail,
  721. nil
  722. )
  723. rescue Exception => e
  724. message_human = ''
  725. translation_map.each {|key, message|
  726. if e.message =~ /#{Regexp.escape(key)}/i
  727. message_human = message
  728. end
  729. }
  730. result = {
  731. result: 'invalid',
  732. settings: params,
  733. message: e.message,
  734. message_human: message_human,
  735. }
  736. return result
  737. end
  738. result = {
  739. result: 'ok',
  740. }
  741. result
  742. end
  743. def email_probe_inbound(params)
  744. # validate params
  745. if !params[:adapter]
  746. fail 'need :adapter param'
  747. end
  748. # connection test
  749. translation_map = {
  750. 'authentication failed' => 'Authentication failed!',
  751. 'Incorrect username' => 'Authentication failed!',
  752. 'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!',
  753. 'No route to host' => 'No route to host!',
  754. 'Connection refused' => 'Connection refused!',
  755. }
  756. if params[:adapter] =~ /^imap$/i
  757. begin
  758. Channel::IMAP.new.fetch( { options: params[:options] }, 'check' )
  759. rescue Exception => e
  760. message_human = ''
  761. translation_map.each {|key, message|
  762. if e.message =~ /#{Regexp.escape(key)}/i
  763. message_human = message
  764. end
  765. }
  766. result = {
  767. result: 'invalid',
  768. settings: params,
  769. message: e.message,
  770. message_human: message_human,
  771. }
  772. return result
  773. end
  774. result = {
  775. result: 'ok',
  776. }
  777. return result
  778. end
  779. begin
  780. Channel::POP3.new.fetch( { options: params[:options] }, 'check' )
  781. rescue Exception => e
  782. message_human = ''
  783. translation_map.each {|key, message|
  784. if e.message =~ /#{Regexp.escape(key)}/i
  785. message_human = message
  786. end
  787. }
  788. result = {
  789. result: 'invalid',
  790. settings: params,
  791. message: e.message,
  792. message_human: message_human,
  793. }
  794. return result
  795. end
  796. result = {
  797. result: 'ok',
  798. }
  799. result
  800. end
  801. def mxers(domain)
  802. begin
  803. mxs = Resolv::DNS.open do |dns|
  804. ress = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
  805. ress.map { |r| [r.exchange.to_s, IPSocket.getaddress(r.exchange.to_s), r.preference] }
  806. end
  807. rescue Exception => e
  808. logger.error e.message
  809. logger.error e.backtrace.inspect
  810. end
  811. mxs
  812. end
  813. def setup_done
  814. #return false
  815. count = User.all.count()
  816. done = true
  817. if count <= 2
  818. done = false
  819. end
  820. done
  821. end
  822. def setup_done_response
  823. if !setup_done
  824. return false
  825. end
  826. # get all groups
  827. groups = Group.where( active: true )
  828. # get email addresses
  829. addresses = EmailAddress.where( active: true )
  830. render json: {
  831. setup_done: true,
  832. import_mode: Setting.get('import_mode'),
  833. import_backend: Setting.get('import_backend'),
  834. system_online_service: Setting.get('system_online_service'),
  835. addresses: addresses,
  836. groups: groups,
  837. }
  838. true
  839. end
  840. end