getting_started_controller.rb 23 KB

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