ConfigLMM 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +70 -0
  3. data/CNAME +1 -0
  4. data/Examples/.lmm.state.yaml +159 -0
  5. data/Examples/ConfigLMM.mm.yaml +32 -0
  6. data/Examples/Implemented.mm.yaml +252 -4
  7. data/Examples/SmallBusiness.mm.yaml +492 -0
  8. data/Plugins/Apps/Answer/answer.lmm.rb +165 -0
  9. data/Plugins/Apps/Answer/answer@.service +40 -0
  10. data/Plugins/Apps/ArchiSteamFarm/ArchiSteamFarm.conf.erb +0 -3
  11. data/Plugins/Apps/ArchiSteamFarm/ArchiSteamFarm.lmm.rb +0 -1
  12. data/Plugins/Apps/Authentik/Authentik-ProxyOutpost.container +20 -0
  13. data/Plugins/Apps/Authentik/Authentik-Server.container +7 -1
  14. data/Plugins/Apps/Authentik/Authentik-Worker.container +7 -1
  15. data/Plugins/Apps/Authentik/Authentik.conf.erb +18 -6
  16. data/Plugins/Apps/Authentik/Authentik.lmm.rb +232 -45
  17. data/Plugins/Apps/BookStack/BookStack.conf.erb +38 -0
  18. data/Plugins/Apps/BookStack/BookStack.container +20 -0
  19. data/Plugins/Apps/BookStack/BookStack.lmm.rb +91 -0
  20. data/Plugins/Apps/Cassandra/Cassandra.lmm.rb +9 -19
  21. data/Plugins/Apps/ClickHouse/ClickHouse.container +28 -0
  22. data/Plugins/Apps/ClickHouse/ClickHouse.lmm.rb +113 -0
  23. data/Plugins/Apps/ClickHouse/Config/listen.yaml +2 -0
  24. data/Plugins/Apps/ClickHouse/Config/logger.yaml +8 -0
  25. data/Plugins/Apps/ClickHouse/Config/zookeepers.yaml +5 -0
  26. data/Plugins/Apps/ClickHouse/Connection.rb +96 -0
  27. data/Plugins/Apps/Discourse/Discourse-Sidekiq.container +22 -0
  28. data/Plugins/Apps/Discourse/Discourse.conf.erb +38 -0
  29. data/Plugins/Apps/Discourse/Discourse.container +21 -0
  30. data/Plugins/Apps/Discourse/Discourse.lmm.rb +156 -0
  31. data/Plugins/Apps/Dovecot/Dovecot.lmm.rb +87 -52
  32. data/Plugins/Apps/ERPNext/ERPNext-Frontend.container +24 -0
  33. data/Plugins/Apps/ERPNext/ERPNext-Queue.container +22 -0
  34. data/Plugins/Apps/ERPNext/ERPNext-Scheduler.container +22 -0
  35. data/Plugins/Apps/ERPNext/ERPNext-Websocket.container +24 -0
  36. data/Plugins/Apps/ERPNext/ERPNext.container +23 -0
  37. data/Plugins/Apps/ERPNext/ERPNext.lmm.rb +204 -0
  38. data/Plugins/Apps/ERPNext/ERPNext.network +12 -0
  39. data/Plugins/Apps/ERPNext/sites/apps.json +10 -0
  40. data/Plugins/Apps/ERPNext/sites/apps.txt +3 -0
  41. data/Plugins/Apps/ERPNext/sites/common_site_config.json +11 -0
  42. data/Plugins/Apps/GitLab/GitLab.container +9 -2
  43. data/Plugins/Apps/GitLab/GitLab.lmm.rb +52 -33
  44. data/Plugins/Apps/Homepage/Homepage.conf.erb +86 -0
  45. data/Plugins/Apps/Homepage/Homepage.container +19 -0
  46. data/Plugins/Apps/Homepage/Homepage.lmm.rb +54 -0
  47. data/Plugins/Apps/IPFS/IPFS.conf.erb +0 -3
  48. data/Plugins/Apps/IPFS/IPFS.lmm.rb +0 -1
  49. data/Plugins/Apps/InfluxDB/InfluxDB.conf.erb +0 -3
  50. data/Plugins/Apps/InfluxDB/InfluxDB.lmm.rb +0 -1
  51. data/Plugins/Apps/Jackett/Jackett.conf.erb +0 -3
  52. data/Plugins/Apps/Jackett/Jackett.lmm.rb +0 -1
  53. data/Plugins/Apps/Jellyfin/Jellyfin.conf.erb +0 -3
  54. data/Plugins/Apps/Jellyfin/Jellyfin.lmm.rb +0 -1
  55. data/Plugins/Apps/LetsEncrypt/LetsEncrypt.lmm.rb +78 -0
  56. data/Plugins/Apps/LetsEncrypt/hooks/dovecot.sh +2 -0
  57. data/Plugins/Apps/LetsEncrypt/hooks/nginx.sh +2 -0
  58. data/Plugins/Apps/LetsEncrypt/hooks/postfix.sh +2 -0
  59. data/Plugins/Apps/LetsEncrypt/renew-certificates.service +7 -0
  60. data/Plugins/Apps/LetsEncrypt/renew-certificates.timer +12 -0
  61. data/Plugins/Apps/LetsEncrypt/rfc2136.ini +11 -0
  62. data/Plugins/Apps/LibreTranslate/LibreTranslate.container +21 -0
  63. data/Plugins/Apps/LibreTranslate/LibreTranslate.lmm.rb +34 -0
  64. data/Plugins/Apps/Lobsters/Containerfile +81 -0
  65. data/Plugins/Apps/Lobsters/Lobsters-Tasks.container +26 -0
  66. data/Plugins/Apps/Lobsters/Lobsters.conf.erb +99 -0
  67. data/Plugins/Apps/Lobsters/Lobsters.container +27 -0
  68. data/Plugins/Apps/Lobsters/Lobsters.lmm.rb +196 -0
  69. data/Plugins/Apps/Lobsters/crontab +3 -0
  70. data/Plugins/Apps/Lobsters/database.yml +26 -0
  71. data/Plugins/Apps/Lobsters/entrypoint.sh +30 -0
  72. data/Plugins/Apps/Lobsters/generateCredentials.rb +19 -0
  73. data/Plugins/Apps/Lobsters/lobsters-cron.sh +25 -0
  74. data/Plugins/Apps/Lobsters/lobsters-daily.sh +23 -0
  75. data/Plugins/Apps/Lobsters/puma.rb +49 -0
  76. data/Plugins/Apps/MariaDB/Connection.rb +55 -0
  77. data/Plugins/Apps/MariaDB/MariaDB.lmm.rb +122 -0
  78. data/Plugins/Apps/Mastodon/Mastodon-Sidekiq.container +22 -0
  79. data/Plugins/Apps/Mastodon/Mastodon-Streaming.container +20 -0
  80. data/Plugins/Apps/Mastodon/Mastodon.conf.erb +34 -45
  81. data/Plugins/Apps/Mastodon/Mastodon.container +28 -0
  82. data/Plugins/Apps/Mastodon/Mastodon.lmm.rb +240 -5
  83. data/Plugins/Apps/Mastodon/configlmm.rake +30 -0
  84. data/Plugins/Apps/Mastodon/entrypoint.sh +16 -0
  85. data/Plugins/Apps/Matrix/Element.container +19 -0
  86. data/Plugins/Apps/Matrix/Matrix.conf.erb +47 -9
  87. data/Plugins/Apps/Matrix/Matrix.lmm.rb +119 -5
  88. data/Plugins/Apps/Matrix/Synapse.container +22 -0
  89. data/Plugins/Apps/Matrix/config.json +50 -0
  90. data/Plugins/Apps/Matrix/homeserver.yaml +70 -0
  91. data/Plugins/Apps/Matrix/log.config +30 -0
  92. data/Plugins/Apps/Netdata/Netdata.conf.erb +0 -3
  93. data/Plugins/Apps/Netdata/Netdata.lmm.rb +0 -1
  94. data/Plugins/Apps/Nextcloud/Nextcloud.conf.erb +3 -4
  95. data/Plugins/Apps/Nextcloud/Nextcloud.lmm.rb +155 -48
  96. data/Plugins/Apps/Nextcloud/autoconfig.php +13 -0
  97. data/Plugins/Apps/Nextcloud/config.php +10 -1
  98. data/Plugins/Apps/Nextcloud/nextcloudcron.service +8 -0
  99. data/Plugins/Apps/Nextcloud/nextcloudcron.timer +10 -0
  100. data/Plugins/Apps/Nginx/Connection.rb +93 -0
  101. data/Plugins/Apps/Nginx/conf.d/configlmm.conf +54 -4
  102. data/Plugins/Apps/Nginx/conf.d/languages.conf +21 -0
  103. data/Plugins/Apps/Nginx/config-lmm/errors.conf +33 -22
  104. data/Plugins/Apps/Nginx/config-lmm/gateway-errors.conf +20 -0
  105. data/Plugins/Apps/Nginx/config-lmm/proxy.conf +6 -2
  106. data/Plugins/Apps/Nginx/main.conf.erb +7 -3
  107. data/Plugins/Apps/Nginx/nginx.conf +2 -2
  108. data/Plugins/Apps/Nginx/nginx.lmm.rb +103 -81
  109. data/Plugins/Apps/Nginx/proxy.conf.erb +24 -6
  110. data/Plugins/Apps/Odoo/Odoo.conf.erb +0 -3
  111. data/Plugins/Apps/Odoo/Odoo.container +7 -1
  112. data/Plugins/Apps/Odoo/Odoo.lmm.rb +4 -5
  113. data/Plugins/Apps/Ollama/Ollama.container +26 -0
  114. data/Plugins/Apps/Ollama/Ollama.lmm.rb +73 -0
  115. data/Plugins/Apps/OpenTelemetry/Config/config.yaml +704 -0
  116. data/Plugins/Apps/OpenTelemetry/OpenTelemetry.lmm.rb +154 -0
  117. data/Plugins/Apps/OpenVidu/Ingress.container +23 -0
  118. data/Plugins/Apps/{GitLab/GitLab.conf.erb → OpenVidu/OpenVidu.conf.erb} +8 -3
  119. data/Plugins/Apps/OpenVidu/OpenVidu.container +21 -0
  120. data/Plugins/Apps/OpenVidu/OpenVidu.lmm.rb +94 -0
  121. data/Plugins/Apps/OpenVidu/OpenViduCall.conf.erb +32 -0
  122. data/Plugins/Apps/OpenVidu/OpenViduCall.container +20 -0
  123. data/Plugins/Apps/OpenVidu/ingress.yaml +10 -0
  124. data/Plugins/Apps/OpenVidu/livekit.yaml +13 -0
  125. data/Plugins/Apps/PHP-FPM/Connection.rb +91 -0
  126. data/Plugins/Apps/PHP-FPM/PHP-FPM.lmm.rb +31 -4
  127. data/Plugins/Apps/Peppermint/Peppermint.conf.erb +2 -9
  128. data/Plugins/Apps/Peppermint/Peppermint.container +7 -1
  129. data/Plugins/Apps/Peppermint/Peppermint.lmm.rb +29 -33
  130. data/Plugins/Apps/Perplexica/Perplexica.container +25 -0
  131. data/Plugins/Apps/Perplexica/Perplexica.lmm.rb +92 -0
  132. data/Plugins/Apps/Perplexica/config.toml +26 -0
  133. data/Plugins/Apps/Podman/Connection.rb +24 -0
  134. data/Plugins/Apps/Podman/Podman.lmm.rb +80 -0
  135. data/Plugins/Apps/Podman/storage.conf +6 -0
  136. data/Plugins/Apps/Postfix/Postfix.lmm.rb +249 -145
  137. data/Plugins/Apps/PostgreSQL/Connection.rb +97 -0
  138. data/Plugins/Apps/PostgreSQL/PostgreSQL.lmm.rb +204 -99
  139. data/Plugins/Apps/Pterodactyl/Pterodactyl.conf.erb +0 -3
  140. data/Plugins/Apps/Pterodactyl/Pterodactyl.lmm.rb +0 -2
  141. data/Plugins/Apps/Pterodactyl/Wings.conf.erb +0 -3
  142. data/Plugins/Apps/RVM/RVM.lmm.rb +57 -0
  143. data/Plugins/Apps/Roundcube/Roundcube.conf.erb +72 -0
  144. data/Plugins/Apps/Roundcube/Roundcube.lmm.rb +141 -0
  145. data/Plugins/Apps/SSH/SSH.lmm.rb +9 -15
  146. data/Plugins/Apps/SearXNG/SearXNG.container +22 -0
  147. data/Plugins/Apps/SearXNG/SearXNG.lmm.rb +79 -0
  148. data/Plugins/Apps/SearXNG/limiter.toml +40 -0
  149. data/Plugins/Apps/SearXNG/settings.yml +2 -0
  150. data/Plugins/Apps/SigNoz/Config/alerts.yml +11 -0
  151. data/Plugins/Apps/SigNoz/Config/otel-collector-config.yaml +110 -0
  152. data/Plugins/Apps/SigNoz/Config/otel-collector-opamp-config.yaml +1 -0
  153. data/Plugins/Apps/SigNoz/Config/prometheus.yml +18 -0
  154. data/Plugins/Apps/SigNoz/SigNoz-Collector.container +23 -0
  155. data/Plugins/Apps/SigNoz/SigNoz-Migrator.container +17 -0
  156. data/Plugins/Apps/SigNoz/SigNoz.conf.erb +61 -0
  157. data/Plugins/Apps/SigNoz/SigNoz.container +26 -0
  158. data/Plugins/Apps/SigNoz/SigNoz.lmm.rb +319 -0
  159. data/Plugins/Apps/Solr/log4j2.xml +89 -0
  160. data/Plugins/Apps/Solr/solr.lmm.rb +82 -0
  161. data/Plugins/Apps/Sunshine/Sunshine.conf.erb +0 -3
  162. data/Plugins/Apps/Sunshine/Sunshine.lmm.rb +0 -1
  163. data/Plugins/Apps/Tunnel/tunnel.lmm.rb +59 -0
  164. data/Plugins/Apps/Tunnel/tunnelTCP.service +9 -0
  165. data/Plugins/Apps/Tunnel/tunnelTCP.socket +9 -0
  166. data/Plugins/Apps/Tunnel/tunnelUDP.service +9 -0
  167. data/Plugins/Apps/Tunnel/tunnelUDP.socket +9 -0
  168. data/Plugins/Apps/UVdesk/UVdesk.conf.erb +0 -3
  169. data/Plugins/Apps/Umami/Umami.container +19 -0
  170. data/Plugins/Apps/Umami/Umami.lmm.rb +108 -0
  171. data/Plugins/Apps/Valkey/Valkey.lmm.rb +64 -20
  172. data/Plugins/Apps/Vaultwarden/Vaultwarden.conf.erb +9 -6
  173. data/Plugins/Apps/Vaultwarden/Vaultwarden.container +7 -1
  174. data/Plugins/Apps/Vaultwarden/Vaultwarden.lmm.rb +67 -28
  175. data/Plugins/Apps/Wiki.js/Wiki.js.conf.erb +39 -0
  176. data/Plugins/Apps/Wiki.js/Wiki.js.container +20 -0
  177. data/Plugins/Apps/Wiki.js/Wiki.js.lmm.rb +55 -0
  178. data/Plugins/Apps/YaCy/YaCy.conf.erb +93 -0
  179. data/Plugins/Apps/YaCy/YaCy.container +21 -0
  180. data/Plugins/Apps/YaCy/YaCy.lmm.rb +160 -0
  181. data/Plugins/Apps/ZooKeeper/ZooKeeper.container +24 -0
  182. data/Plugins/Apps/ZooKeeper/ZooKeeper.lmm.rb +68 -0
  183. data/Plugins/Apps/bitmagnet/bitmagnet.conf.erb +0 -3
  184. data/Plugins/Apps/bitmagnet/bitmagnet.lmm.rb +0 -1
  185. data/Plugins/Apps/gollum/gollum.conf.erb +40 -4
  186. data/Plugins/Apps/gollum/gollum.container +10 -1
  187. data/Plugins/Apps/gollum/gollum.lmm.rb +56 -47
  188. data/Plugins/Apps/llama.cpp/llama.cpp.container +28 -0
  189. data/Plugins/Apps/llama.cpp/llama.cpp.lmm.rb +90 -0
  190. data/Plugins/Apps/vLLM/vLLM.container +32 -0
  191. data/Plugins/Apps/vLLM/vLLM.lmm.rb +89 -0
  192. data/Plugins/OS/General/Utils.lmm.rb +26 -0
  193. data/Plugins/OS/Linux/Connection.rb +472 -0
  194. data/Plugins/OS/Linux/Debian/preseed.cfg.erb +81 -0
  195. data/Plugins/OS/Linux/Distributions.yaml +32 -0
  196. data/Plugins/OS/Linux/Flavours.yaml +24 -0
  197. data/Plugins/OS/Linux/Grub/grub.cfg +10 -0
  198. data/Plugins/OS/Linux/HTTP.rb +32 -0
  199. data/Plugins/OS/Linux/Linux.lmm.rb +708 -174
  200. data/Plugins/OS/Linux/Packages.yaml +67 -3
  201. data/Plugins/OS/Linux/Proxmox/answer.toml.erb +30 -0
  202. data/Plugins/OS/Linux/Services.yaml +8 -0
  203. data/Plugins/OS/Linux/Shell.rb +70 -0
  204. data/Plugins/OS/Linux/Syslinux/default +8 -0
  205. data/Plugins/OS/Linux/WireGuard/WireGuard.lmm.rb +93 -40
  206. data/Plugins/OS/Linux/WireGuard/wg0.conf.erb +3 -0
  207. data/Plugins/OS/Linux/openSUSE/autoinst.xml.erb +29 -3
  208. data/Plugins/OS/Linux/systemd/systemd.lmm.rb +13 -11
  209. data/Plugins/OS/Routers/Aruba/ArubaInstant.lmm.rb +6 -5
  210. data/Plugins/Platforms/GitHub.lmm.rb +73 -28
  211. data/Plugins/Platforms/GoDaddy/GoDaddy.lmm.rb +10 -7
  212. data/Plugins/Platforms/Proxmox/Proxmox.lmm.rb +402 -0
  213. data/Plugins/Platforms/Proxmox/XTerm.rb +321 -0
  214. data/Plugins/Platforms/libvirt/libvirt.lmm.rb +41 -15
  215. data/Plugins/Platforms/porkbun.lmm.rb +12 -2
  216. data/Plugins/Platforms/porkbun_spec.rb +2 -2
  217. data/Plugins/Services/DNS/AmberBit.lmm.rb +1 -1
  218. data/Plugins/Services/DNS/ArubaItDNS.lmm.rb +1 -1
  219. data/Plugins/Services/DNS/NICLV.lmm.rb +1 -1
  220. data/Plugins/Services/DNS/PowerDNS.lmm.rb +130 -41
  221. data/Plugins/Services/DNS/tonic.lmm.rb +22 -12
  222. data/bootstrap.sh +41 -3
  223. data/lib/ConfigLMM/Framework/plugins/dns.rb +4 -3
  224. data/lib/ConfigLMM/Framework/plugins/linuxApp.rb +187 -144
  225. data/lib/ConfigLMM/Framework/plugins/nginxApp.rb +54 -6
  226. data/lib/ConfigLMM/Framework/plugins/plugin.rb +68 -140
  227. data/lib/ConfigLMM/Framework/plugins/store.rb +4 -4
  228. data/lib/ConfigLMM/Framework/variables.rb +75 -0
  229. data/lib/ConfigLMM/Framework.rb +1 -0
  230. data/lib/ConfigLMM/cli.rb +13 -5
  231. data/lib/ConfigLMM/commands/cleanup.rb +1 -0
  232. data/lib/ConfigLMM/commands/configsCommand.rb +38 -5
  233. data/lib/ConfigLMM/commands/diff.rb +33 -9
  234. data/lib/ConfigLMM/context.rb +22 -3
  235. data/lib/ConfigLMM/io/configList.rb +85 -7
  236. data/lib/ConfigLMM/io/connection.rb +143 -0
  237. data/lib/ConfigLMM/io/dhcp.rb +330 -0
  238. data/lib/ConfigLMM/io/http.rb +78 -0
  239. data/lib/ConfigLMM/io/local.rb +207 -0
  240. data/lib/ConfigLMM/io/pxe.rb +92 -0
  241. data/lib/ConfigLMM/io/ssh.rb +156 -0
  242. data/lib/ConfigLMM/io/tftp.rb +105 -0
  243. data/lib/ConfigLMM/io.rb +2 -0
  244. data/lib/ConfigLMM/secrets/envStore.rb +39 -0
  245. data/lib/ConfigLMM/secrets/fileStore.rb +43 -0
  246. data/lib/ConfigLMM/state.rb +12 -3
  247. data/lib/ConfigLMM/version.rb +2 -1
  248. data/lib/ConfigLMM.rb +1 -0
  249. data/{Examples → scripts}/configlmmAuth.sh +7 -5
  250. metadata +257 -9
@@ -1,4 +1,6 @@
1
1
 
2
+ require 'addressable/idna'
3
+
2
4
  module ConfigLMM
3
5
  module LMM
4
6
  class Postfix < Framework::Plugin
@@ -7,177 +9,279 @@ module ConfigLMM
7
9
  MASTER_FILE = 'master.cf'
8
10
  MAIN_FILE = 'main.cf'
9
11
  TRANSPORT_FILE = 'transport'
12
+ PASSWORD_FILE = 'sasl_passwd'
10
13
 
11
14
  def actionPostfixDeploy(id, target, activeState, context, options)
12
- plugins[:Linux].ensurePackages([PACKAGE_NAME, 'CyrusSASL'], target['Location'])
13
- plugins[:Linux].ensureServiceAutoStart(SERVICE_NAME, target['Location'])
15
+ self.withConnection(target['Location'], target) do |connection|
16
+ Linux.withConnection(connection) do |linuxConnection|
17
+ linuxConnection.ensurePackages([PACKAGE_NAME, 'CyrusSASL'], options)
18
+ linuxConnection.ensureServiceAutoStart(SERVICE_NAME, options)
14
19
 
15
- deploySettings(target, target['Location'], options)
20
+ deploySettings(target, linuxConnection, context, options)
21
+ deployAccounts(target, linuxConnection, context, options)
16
22
 
17
- plugins[:Linux].startService(SERVICE_NAME, target['Location'])
23
+ linuxConnection.restartService(SERVICE_NAME, options)
24
+ end
25
+ end
18
26
  end
19
27
 
20
- def deploySettings(target, location, options)
28
+ def deploySettings(target, linuxConnection, context, options)
21
29
  postfixDirName = 'postfix'
22
30
  postfixDirName = 'postfix-' + target['Instance'] if target['Instance']
23
31
  postfixDir = '/etc/' + postfixDirName + '/'
24
- if location && location != '@me'
25
- self.class.sshStart(location) do |ssh|
26
- if target['Instance']
27
- self.class.sshExec!(ssh, "postmulti -e init")
28
- self.class.sshExec!(ssh, "postmulti -I #{postfixDirName} -e create", true)
29
- self.class.sshExec!(ssh, "sed -i 's|^master_service_disable|#master_service_disable|' #{postfixDir + MAIN_FILE}")
30
- end
31
- self.class.sshExec!(ssh, "sed -i 's|^tlsmgr|#tlsmgr|' #{postfixDir + MASTER_FILE}")
32
- if target.key?('SMTP')
33
- if !target['SMTP'] || target['SMTP'] == 'unix'
34
- self.class.sshExec!(ssh, "sed -i 's|^smtp|#smtp|' #{postfixDir + MASTER_FILE}")
35
- end
36
- end
37
- updateRemoteFile(ssh, postfixDir + MASTER_FILE, options, true) do |fileLines|
38
- if target['AlternativePort']
39
- fileLines << "#{target['AlternativePort']} inet n - n - - smtpd\n"
40
- fileLines << "tlsmgr unix - - n 1000? 1 tlsmgr\n"
41
- else
42
- if !target.key?('Submission') || (target.key?('Submission') && target['Submission'])
43
- fileLines << "submissions inet n - n - - smtpd\n"
44
- fileLines << " -o syslog_name=postfix/submissions\n"
45
- fileLines << " -o smtpd_tls_wrappermode=yes\n"
46
- fileLines << " -o smtpd_tls_security_level=encrypt\n"
47
- fileLines << " -o smtpd_sasl_auth_enable=yes\n"
48
- fileLines << " -o cleanup_service_name=header_cleanup\n"
49
- fileLines << "header_cleanup unix n - - - 0 cleanup\n"
50
- fileLines << " -o header_checks=regexp:/etc/postfix/header_cleanup\n"
51
-
52
- self.class.sshExec!(ssh, "echo '/^Received:/ IGNORE' > /etc/postfix/header_cleanup")
53
- self.class.sshExec!(ssh, "echo '/^User-Agent:/ IGNORE' >> /etc/postfix/header_cleanup")
54
- end
55
- fileLines << "tlsmgr unix - - n 1000? 1 tlsmgr\n"
56
- if target['SMTP'] == 'unix'
57
- fileLines << "smtp unix - - n - - smtp\n"
58
- end
59
- end
60
- fileLines
61
- end
62
32
 
63
- domain = target['Domain']
64
- domain = self.class.sshExec!(ssh, "hostname --fqdn").strip unless domain
65
- command = "sed -i 's|^myhostname = .*|myhostname = #{domain}|' #{postfixDir + MAIN_FILE}"
66
- self.class.sshExec!(ssh, command)
67
- command = "sed -i 's|^#myhostname = virtual.domain.tld|myhostname = #{domain}|' #{postfixDir + MAIN_FILE}"
68
- self.class.sshExec!(ssh, command)
69
-
70
- # Fix config bug
71
- command = "sed -i 's|^alias_maps = :/etc/aliases|alias_maps = lmdb:/etc/aliases|' #{postfixDir + MAIN_FILE}"
72
- self.class.sshExec!(ssh, command)
73
- command = "sed -i 's|^canonical_maps = :/etc/postfix/canonical|canonical_maps = lmdb:/etc/postfix/canonical|' #{postfixDir + MAIN_FILE}"
74
- self.class.sshExec!(ssh, command)
75
- command = "sed -i 's|^relocated_maps = :/etc/postfix/relocated|relocated_maps = lmdb:/etc/postfix/relocated|' #{postfixDir + MAIN_FILE}"
76
- self.class.sshExec!(ssh, command)
77
- command = "sed -i 's|^sender_canonical_maps = :/etc/postfix/sender_canonical|sender_canonical_maps = lmdb:/etc/postfix/sender_canonical|' #{postfixDir + MAIN_FILE}"
78
- self.class.sshExec!(ssh, command)
79
- command = "sed -i 's|^transport_maps = :/etc/postfix/transport|transport_maps = lmdb:/etc/postfix/transport|' #{postfixDir + MAIN_FILE}"
80
- self.class.sshExec!(ssh, command)
81
- command = "sed -i 's|^smtpd_sender_restrictions = :/etc/postfix/access|smtpd_sender_restrictions = lmdb:/etc/postfix/access|' #{postfixDir + MAIN_FILE}"
82
- self.class.sshExec!(ssh, command)
83
- command = "sed -i 's|^virtual_alias_maps = :/etc/postfix/virtual|virtual_alias_maps = lmdb:/etc/postfix/virtual|' #{postfixDir + MAIN_FILE}"
84
- self.class.sshExec!(ssh, command)
85
- command = "sed -i 's|^relay_domains = $mydestination :/etc/postfix/relay|relay_domains = $mydestination lmdb:/etc/postfix/relay|' #{postfixDir + MAIN_FILE}"
86
- self.class.sshExec!(ssh, command)
87
- command = "sed -i 's|^relay_recipient_maps = :/etc/postfix/relay_recipients|relay_recipient_maps = lmdb:/etc/postfix/relay_recipients|' #{postfixDir + MAIN_FILE}"
88
- self.class.sshExec!(ssh, command)
89
- command = "sed -i 's|^virtual_mailbox_maps =.*|virtual_mailbox_maps = lmdb:/etc/postfix/mailboxes|' #{postfixDir + MAIN_FILE}"
90
- self.class.sshExec!(ssh, command)
91
-
92
-
93
- if target['AlternativePort']
94
- self.class.sshExec!(ssh, "firewall-cmd -q --add-port='#{target['AlternativePort']}/tcp'")
95
- self.class.sshExec!(ssh, "firewall-cmd -q --permanent --add-port='#{target['AlternativePort']}/tcp'")
96
- else
97
- self.class.sshExec!(ssh, "firewall-cmd -q --add-service='smtp'")
98
- self.class.sshExec!(ssh, "firewall-cmd -q --permanent --add-service='smtp'")
99
- end
100
- self.class.sshExec!(ssh, "firewall-cmd -q --add-service='smtps'")
101
- self.class.sshExec!(ssh, "firewall-cmd -q --permanent --add-service='smtps'")
102
-
103
- ssh.scp.upload!(__dir__ + '/smtpd.conf', '/etc/sasl2/smtpd.conf')
104
- self.class.sshExec!(ssh, "touch /etc/sasldb2")
105
- self.class.sshExec!(ssh, "chown postfix:postfix /etc/sasldb2")
106
- self.class.sshExec!(ssh, "touch #{postfixDir}access")
107
- self.class.sshExec!(ssh, "postmap #{postfixDir}access")
108
- self.class.sshExec!(ssh, "touch #{postfixDir}sender_login")
109
- self.class.sshExec!(ssh, "postmap #{postfixDir}sender_login")
110
-
111
- certDir = Framework::LinuxApp.createCertificateOverSSH(ssh)
112
- target['Settings'] ||= []
113
- target['Settings']['smtpd_sender_login_maps'] = "lmdb:#{postfixDir}sender_login" unless target['Settings']['smtpd_sender_login_maps']
114
- target['Settings']['smtpd_sender_restrictions'] = "reject_sender_login_mismatch, lmdb:#{postfixDir}access" unless target['Settings']['smtpd_sender_restrictions']
115
- target['Settings']['smtp_tls_security_level'] = 'may' unless target['Settings']['smtp_tls_security_level']
116
- target['Settings']['smtpd_tls_mandatory_protocols'] = '>=TLSv1.2' unless target['Settings']['smtpd_tls_mandatory_protocols']
117
- target['Settings']['smtpd_tls_auth_only'] = 'yes' unless target['Settings']['smtpd_tls_auth_only']
118
- target['Settings']['smtpd_tls_security_level'] = 'may' unless target['Settings']['smtpd_tls_security_level']
119
- target['Settings']['smtpd_tls_cert_file'] = certDir + 'fullchain.pem' unless target['Settings']['smtpd_tls_cert_file']
120
- target['Settings']['smtpd_tls_key_file'] = certDir + 'privkey.pem' unless target['Settings']['smtpd_tls_key_file']
121
- target['Settings']['tls_preempt_cipherlist'] = 'yes' unless target['Settings']['tls_preempt_cipherlist']
122
- target['Settings']['tls_ssl_options'] = 'NO_RENEGOTIATION' unless target['Settings']['tls_ssl_options']
123
-
124
-
125
- target['Settings'].each do |name, value|
126
- command = "sed -i 's|^#{name} =.*|##{name} = #{value}|' #{postfixDir + MAIN_FILE}"
127
- self.class.sshExec!(ssh, command)
128
- end
129
- updateRemoteFile(ssh, postfixDir + MAIN_FILE, options) do |fileLines|
130
- target['Settings'].each do |name, value|
131
- value = 'yes' if value == true
132
- value = 'no' if value == false
133
- fileLines << "#{name} = #{value}\n"
134
- end
135
- fileLines
136
- end
33
+ if target['Instance']
34
+ linuxConnection.exec("postmulti -e init", false, options)
35
+ linuxConnection.exec("postmulti -I #{postfixDirName} -e create", true, options)
36
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^master_service_disable', '#master_service_disable', options)
37
+ end
38
+
39
+ linuxConnection.fileReplace("#{postfixDir + MASTER_FILE}", '^tlsmgr', '#tlsmgr', options)
40
+ if target.key?('SMTP')
41
+ if !target['SMTP'] || target['SMTP'] == 'unix'
42
+ linuxConnection.fileReplace("#{postfixDir + MASTER_FILE}", '^smtp', '#smtp', options)
43
+ end
44
+ end
137
45
 
138
- if target['ForwardDovecot']
139
- command = "sed -i 's|^#virtual_transport =.*|virtual_transport = lmtp:unix:/run/dovecot/lmtp|' #{postfixDir + MAIN_FILE}"
140
- self.class.sshExec!(ssh, command)
46
+ linuxConnection.updateFile(postfixDir + MASTER_FILE, options, true) do |fileLines|
47
+ if target['AlternativePort']
48
+ fileLines << "#{target['AlternativePort']} inet n - n - - smtpd\n"
49
+ fileLines << "tlsmgr unix - - n 1000? 1 tlsmgr\n"
50
+ else
51
+ fileLines << "tlsmgr unix - - n 1000? 1 tlsmgr\n"
52
+ if target['SMTP'] == 'unix'
53
+ fileLines << "smtp unix - - n - - smtp\n"
141
54
  end
55
+ end
56
+ if target['Submission']
57
+ fileLines << "submissions inet n - n - - smtpd\n"
58
+ fileLines << " -o syslog_name=postfix/submissions\n"
59
+ fileLines << " -o smtpd_tls_wrappermode=yes\n"
60
+ fileLines << " -o smtpd_tls_security_level=encrypt\n"
61
+ fileLines << " -o smtpd_sasl_auth_enable=yes\n"
62
+ fileLines << " -o smtpd_client_restrictions=permit_sasl_authenticated,reject\n"
63
+ fileLines << " -o smtpd_sender_restrictions=reject_sender_login_mismatch,lmdb:#{postfixDir}access\n"
64
+ fileLines << " -o cleanup_service_name=header_cleanup\n"
65
+ fileLines << "header_cleanup unix n - - - 0 cleanup\n"
66
+ fileLines << " -o header_checks=regexp:/etc/postfix/header_cleanup\n"
142
67
 
143
- if target['ForwardAll']
144
- command = "sed -i 's|^transport_maps =.*|transport_maps = lmdb:#{postfixDir}transport|' #{postfixDir + MAIN_FILE}"
145
- self.class.sshExec!(ssh, command)
146
- updateRemoteFile(ssh, postfixDir + TRANSPORT_FILE, options, true) do |fileLines|
147
- hostname, port = target['ForwardAll'].split(':')
148
- hostname = '[' + hostname + ']'
149
- line = '* smtp:' + hostname
150
- line += ':' + port if port
151
- fileLines << line + "\n"
152
- end
153
- self.class.sshExec!(ssh, "postmap #{postfixDir + TRANSPORT_FILE}")
68
+ linuxConnection.fileWrite("/etc/postfix/header_cleanup", '/^Received:/ IGNORE', options)
69
+ linuxConnection.fileAppend("/etc/postfix/header_cleanup", '/^User-Agent:/ IGNORE', options)
70
+ end
71
+ fileLines
72
+ end
73
+
74
+ domain = target['Domain']
75
+ domain = linuxConnection.exec("hostname --fqdn", false, { **options, 'dry' => false }).strip unless domain
76
+
77
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^myhostname = .*', "myhostname = #{domain}", options)
78
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^#myhostname = virtual.domain.tld', "myhostname = #{domain}", options)
79
+
80
+ # Fix config bug
81
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^alias_maps = :/etc/aliases', 'alias_maps = lmdb:/etc/aliases', options)
82
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^canonical_maps = :/etc/postfix/canonical', 'canonical_maps = lmdb:/etc/postfix/canonical', options)
83
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^relocated_maps = :/etc/postfix/relocated', 'relocated_maps = lmdb:/etc/postfix/relocated', options)
84
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^sender_canonical_maps = :/etc/postfix/sender_canonical', 'sender_canonical_maps = lmdb:/etc/postfix/sender_canonical', options)
85
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^transport_maps = :/etc/postfix/transport', 'transport_maps = lmdb:/etc/postfix/transport', options)
86
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^smtpd_sender_restrictions = :/etc/postfix/access', 'smtpd_sender_restrictions = lmdb:/etc/postfix/access', options)
87
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^virtual_alias_maps = :/etc/postfix/virtual', 'virtual_alias_maps = lmdb:/etc/postfix/virtual', options)
88
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^relay_domains = $mydestination :/etc/postfix/relay', 'relay_domains = $mydestination lmdb:/etc/postfix/relay', options)
89
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^relay_recipient_maps = :/etc/postfix/relay_recipients', 'relay_recipient_maps = lmdb:/etc/postfix/relay_recipients', options)
90
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^virtual_mailbox_maps =.*', 'virtual_mailbox_maps = lmdb:/etc/postfix/mailboxes', options)
91
+
92
+ if target['AlternativePort']
93
+ linuxConnection.firewallAddPort("#{target['AlternativePort']}/tcp", options)
94
+ else
95
+ linuxConnection.firewallAddService('smtp', options)
96
+ end
97
+ linuxConnection.firewallAddService('smtps', options)
98
+
99
+ linuxConnection.createDirs(options, '/etc/sasl2')
100
+ linuxConnection.upload(__dir__ + '/smtpd.conf', '/etc/sasl2/smtpd.conf', options)
101
+ linuxConnection.ensureFile('/etc/sasldb2', options)
102
+ linuxConnection.setUserGroup('/etc/sasldb2', 'postfix', 'postfix', options)
103
+ linuxConnection.ensureFile("#{postfixDir}access", options)
104
+ linuxConnection.exec("postmap lmdb:#{postfixDir}access", false, options)
105
+ linuxConnection.ensureFile("#{postfixDir}sender_login", options)
106
+ linuxConnection.exec("postmap lmdb:#{postfixDir}sender_login", false, options)
107
+ linuxConnection.ensureFile("/etc/postfix/#{PASSWORD_FILE}", options)
108
+
109
+ if !target['Aliases'].to_h.empty?
110
+ if !linuxConnection.filePresent?('/etc/aliases', options)
111
+ linuxConnection.exec('cp /etc/postfix/aliases /etc/', false, options)
112
+ linuxConnection.rm("/etc/postfix/aliases", false, options[:dry])
113
+ end
114
+ target['Aliases'].each do |name, destination|
115
+ linuxConnection.fileReplace('/etc/aliases', '^'+name + ':', '#' + name + ':', options)
116
+ end
117
+ linuxConnection.updateFile('/etc/aliases', options, true) do |fileLines|
118
+ target['Aliases'].each do |name, destination|
119
+ fileLines << "#{(name.to_s + ':').ljust(16)}#{self.class.punnycodeEMail(destination)}\n"
154
120
  end
121
+ fileLines
122
+ end
123
+ linuxConnection.exec('postalias lmdb:/etc/aliases', false, options)
124
+ end
125
+
126
+ certDir = linuxConnection.createWildecardCertificate(options)
127
+ target['Settings'] ||= {}
128
+ target['Settings']['alias_maps'] = 'lmdb:/etc/aliases'
129
+ target['Settings']['default_database_type'] = 'lmdb'
130
+ target['Settings']['smtp_tls_security_level'] = 'may' unless target['Settings']['smtp_tls_security_level']
131
+ target['Settings']['smtp_sasl_password_maps'] = 'lmdb:/etc/postfix/' + PASSWORD_FILE
132
+ target['Settings']['smtp_sasl_security_options'] = 'noanonymous'
133
+ target['Settings']['smtpd_sender_login_maps'] = "lmdb:#{postfixDir}sender_login" unless target['Settings']['smtpd_sender_login_maps']
134
+ target['Settings']['smtpd_sender_restrictions'] = "lmdb:#{postfixDir}access" unless target['Settings']['smtpd_sender_restrictions']
135
+ target['Settings']['smtpd_tls_mandatory_protocols'] = '>=TLSv1.2' unless target['Settings']['smtpd_tls_mandatory_protocols']
136
+ target['Settings']['smtpd_tls_auth_only'] = 'yes' unless target['Settings']['smtpd_tls_auth_only']
137
+ target['Settings']['smtpd_tls_security_level'] = 'may' unless target['Settings']['smtpd_tls_security_level']
138
+ target['Settings']['smtpd_tls_cert_file'] = certDir + 'fullchain.pem' unless target['Settings']['smtpd_tls_cert_file']
139
+ target['Settings']['smtpd_tls_key_file'] = certDir + 'privkey.pem' unless target['Settings']['smtpd_tls_key_file']
140
+ target['Settings']['tls_preempt_cipherlist'] = 'yes' unless target['Settings']['tls_preempt_cipherlist']
141
+ target['Settings']['tls_ssl_options'] = 'NO_RENEGOTIATION' unless target['Settings']['tls_ssl_options']
155
142
 
156
- if target['Instance']
157
- self.class.sshExec!(ssh, "postmulti -i #{postfixDirName} -e enable")
158
- self.class.sshExec!(ssh, "postmulti -i #{postfixDirName} -p start", true)
143
+ if target['Relay']
144
+ port = target['Relay']['Port'].to_s
145
+ port = '587' if port.empty?
146
+ target['Settings']['relayhost'] = "#{target['Relay']['Host']}:#{port}" unless target['Settings']['relayhost']
147
+ target['Settings']['smtp_sasl_auth_enable'] = 'yes'
148
+ if port == '465'
149
+ target['Settings']['smtp_tls_security_level'] = 'encrypt'
150
+ target['Settings']['smtp_tls_wrappermode'] = 'yes'
151
+ end
152
+ if target['Relay']['SecretId']
153
+ username = target['Relay']['Username'].to_s
154
+ password = context.secrets.load(target['Relay']['SecretId'], username.upcase + '_PASSWORD')
155
+ linuxConnection.updateFile('/etc/postfix/' + PASSWORD_FILE, options) do |fileLines|
156
+ fileLines << "#{target['Settings']['relayhost']} #{username}:#{password}\n"
159
157
  end
160
158
  end
161
- else
162
- if target['AlternativePort']
163
- updateLocalFile(postfixDir + MASTER_FILE, options, true) do |fileLines|
164
- fileLines << "#{target['AlternativePort']} inet n - n - - smtpd\n"
159
+ end
160
+ linuxConnection.exec("postmap lmdb:/etc/postfix/#{PASSWORD_FILE}", false, options)
161
+
162
+ target['Settings'].each do |name, value|
163
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, "^#{name}[[:blank:]]*=[[:blank:]]*", "##{name} = ", options)
164
+ end
165
+ linuxConnection.updateFile(postfixDir + MAIN_FILE, options) do |fileLines|
166
+ target['Settings'].each do |name, value|
167
+ value = 'yes' if value == true
168
+ value = 'no' if value == false
169
+ fileLines << "#{name} = #{value}\n"
170
+ end
171
+ fileLines
172
+ end
173
+
174
+ if target['ForwardDovecot']
175
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^#virtual_transport =.*', 'virtual_transport = lmtp:unix:/run/dovecot/lmtp', options)
176
+ end
177
+
178
+ if target['ForwardAll']
179
+ linuxConnection.fileReplace(postfixDir + MAIN_FILE, '^transport_maps =.*', "transport_maps = lmdb:#{postfixDir}transport", options)
180
+
181
+ linuxConnection.updateFile(postfixDir + TRANSPORT_FILE, options, true) do |fileLines|
182
+ hostname, port = target['ForwardAll'].split(':')
183
+ hostname = '[' + hostname + ']'
184
+ line = '* smtp:' + hostname
185
+ line += ':' + port if port
186
+ fileLines << line + "\n"
187
+ end
188
+ linuxConnection.exec("postmap lmdb:#{postfixDir + TRANSPORT_FILE}", false, options)
189
+ end
190
+
191
+ if target['Instance']
192
+ linuxConnection.exec("postmulti -i #{postfixDirName} -e enable", false, options)
193
+ linuxConnection.exec("postmulti -i #{postfixDirName} -p start", true, options)
194
+ end
195
+ end
196
+
197
+ def deployAccounts(target, linuxConnection, context, options)
198
+ if target['Accounts']
199
+ postfixDirName = 'postfix'
200
+ postfixDirName = 'postfix-' + target['Instance'] if target['Instance']
201
+ postfixDir = '/etc/' + postfixDirName + '/'
202
+
203
+ linuxConnection.ensureFile("#{postfixDir}sender_login", { **options, 'dry' => false })
204
+ linuxConnection.download("#{postfixDir}sender_login", options['output'], { **options, 'dry' => false })
205
+ senderLoginFile = options['output'] + '/sender_login'
206
+ accountData = File.read(senderLoginFile)
207
+ addAccounts = []
208
+ accountPasswords = linuxConnection.exec('sasldblistusers2', false, { **options, 'dry' => false })
209
+ target['Accounts'].each do |account, emails|
210
+ accountLine = "#{account} #{account}"
211
+ if !accountData.include?(accountLine)
212
+ addAccounts << accountLine
213
+ end
214
+ if !accountPasswords.include?(account + ':')
215
+ passwordName = account.upcase + '_PASSWORD'
216
+ password = context.secrets.load(target['SecretId'], passwordName)
217
+ if password.nil?
218
+ password = SecureRandom.urlsafe_base64(20)
219
+ context.secrets.store(target['SecretId'], passwordName, password) unless options['dry']
220
+ end
221
+ linuxConnection.exec("echo '#{password}' | saslpasswd2 -p #{account}", false, { **options, hide: true })
222
+ end
223
+ if emails.is_a?(String)
224
+ accountLine = "#{emails} #{account}"
225
+ if !accountData.include?(accountLine)
226
+ addAccounts << accountLine
227
+ end
228
+ elsif emails.is_a?(Array)
229
+ emails.each do |email|
230
+ accountLine = "#{email} #{account}"
231
+ if !accountData.include?(accountLine)
232
+ addAccounts << accountLine
233
+ end
234
+ end
165
235
  end
166
236
  end
167
- if target['Settings']
168
- target['Settings'].each do |name, value|
169
- `sed -i 's|^#{name} =.*|#{name} = #{value}|' #{postfixDir + MAIN_FILE}`
237
+ if !addAccounts.empty?
238
+ addAccounts.each do |accountLine|
239
+ accountData << "\n" + accountLine
170
240
  end
241
+ accountData << "\n"
242
+ File.write(senderLoginFile, accountData)
243
+ linuxConnection.upload(senderLoginFile, "#{postfixDir}sender_login", options)
244
+ linuxConnection.exec("postmap lmdb:#{postfixDir}sender_login", false, options)
171
245
  end
172
- if target['ForwardAll']
173
- updateLocalFile(postfixDir + TRANSPORT_FILE, options, true) do |fileLines|
174
- fileLines << '* smtp:[' + target['ForwardAll'] + "]\n"
246
+ end
247
+ end
248
+
249
+ def cleanup(configs, state, context, options)
250
+ cleanupType(:Postfix, configs, state, context, options) do |item, id, state, context, options, connection|
251
+ Linux.withConnection(connection) do |linuxConnection|
252
+ instances = linuxConnection.exec('postmulti -l | wc -l', true).strip.to_i
253
+ if instances <= 1
254
+ linuxConnection.stopService(SERVICE_NAME, options)
255
+ linuxConnection.firewallRemoveService('smtps', options)
256
+ if item['AlternativePort']
257
+ linuxConnection.firewallRemovePort("#{item['AlternativePort']}/tcp", options)
258
+ else
259
+ linuxConnection.firewallRemoveService('smtp', options)
260
+ end
261
+ linuxConnection.removePackage(PACKAGE_NAME, options)
262
+
263
+ state.item(id)['Status'] = State::STATUS_DELETED unless options[:dry]
264
+
265
+ if options[:destroy]
266
+ linuxConnection.rm('/etc/postfix', options[:dry])
267
+
268
+ state.item(id)['Status'] = State::STATUS_DESTROYED unless options[:dry]
269
+ end
270
+ else
271
+ prompt.say('Postfix multiple instance cleanup not implemented!', :color => :red)
175
272
  end
176
- `postmap #{postfixDir + TRANSPORT_FILE}`
177
273
  end
178
274
  end
179
275
  end
180
276
 
277
+ def self.punnycodeEMail(email)
278
+ emailLocal, emailDomain = email.to_s.split('@')
279
+ if emailLocal && emailDomain && emailLocal.ascii_only? && !emailDomain.ascii_only?
280
+ email = emailLocal + '@' + Addressable::IDNA.to_ascii(emailDomain)
281
+ end
282
+ email
283
+ end
284
+
181
285
  end
182
286
 
183
287
  end
@@ -0,0 +1,97 @@
1
+
2
+ module ConfigLMM
3
+ module LMM
4
+ class PostgreSQLConnection
5
+
6
+ attr_reader :connection
7
+
8
+ def initialize(connection, settings)
9
+ @connection = connection
10
+ @settings = settings
11
+ @pgsqlDir = nil
12
+ end
13
+
14
+ def exec(sql, db, allowFailure = false, queryOptions = [], options = {})
15
+ db = 'postgres' unless db
16
+ cmd = "psql #{queryOptions.join(' ')} --dbname=#{db} --command=#{sql.shellescape}"
17
+ if options[:hide]
18
+ cmd = ' ' + cmd
19
+ end
20
+ connection.exec(cmd, allowFailure, options)
21
+ end
22
+
23
+ def createUser(user, password = nil, options = {})
24
+ connection.exec("createuser #{user.shellescape}", true)
25
+ if !password.nil?
26
+ sql = " ALTER USER #{user} WITH PASSWORD '#{LinuxShell.escapeSingleQuotes(password)}'"
27
+ exec(sql, nil, false, [], { **options, hide: true })
28
+ end
29
+ end
30
+
31
+ def createDB(db, owner = nil, options = {})
32
+ ownerSQL = owner ? "--owner=#{owner.shellescape}" : ''
33
+ connection.exec("createdb --locale=C --template=template0 #{ownerSQL} #{db.shellescape}", true, options)
34
+ end
35
+
36
+ def createUserAndDB(user, password, options = {})
37
+ createUser(user, password, options)
38
+ createDB(user, user, options)
39
+ end
40
+
41
+ def dropUserAndDB(user, options = {})
42
+ connection.exec("dropdb #{user.shellescape}", true, options)
43
+ connection.exec("dropuser #{user.shellescape}", true, options)
44
+ end
45
+
46
+ def grantReplication(user, options = {})
47
+ exec("ALTER USER #{user} REPLICATION", nil, false, [], options)
48
+ exec("GRANT pg_read_all_data TO #{user}", nil, false, [], options)
49
+ end
50
+
51
+ def createExtensions(db, extensions, options)
52
+ extensions.each do |extension|
53
+ exec("CREATE EXTENSION #{extension}", db, true, [], options)
54
+ end
55
+ end
56
+
57
+ def importSQL(owner, db, sqlFile, options = {})
58
+ cmd = "psql #{db} < #{sqlFile}"
59
+ output = connection.exec(cmd, false, options)
60
+ raise output if output.include?('ERROR:') && !output.include?('already exists')
61
+ end
62
+
63
+ def updateOwner(db, owner, options = {})
64
+ sql = "SELECT tablename FROM pg_tables WHERE NOT schemaname IN ('pg_catalog', 'information_schema')"
65
+ tables = self.exec(sql, db, false, ['--csv', '--tuples-only']).strip.lines
66
+ tables.each do |table|
67
+ self.exec("ALTER TABLE public.#{table} OWNER TO #{owner};", db, false, [], options)
68
+ end
69
+
70
+ sql = "SELECT sequence_name FROM information_schema.sequences WHERE NOT sequence_schema IN ('pg_catalog', 'information_schema')"
71
+ sequences = self.exec(sql, db, false, ['--csv', '--tuples-only']).strip.lines
72
+ sequences.each do |sequence|
73
+ self.exec("ALTER SEQUENCE public.#{sequence} OWNER TO #{owner};", db, false, [], options)
74
+ end
75
+
76
+ sql = "SELECT table_name FROM information_schema.views WHERE NOT table_schema IN ('pg_catalog', 'information_schema')"
77
+ views = self.exec(sql, db, false, ['--csv', '--tuples-only']).strip.lines
78
+ views.each do |view|
79
+ self.exec("ALTER VIEW public.#{view} OWNER TO #{owner};", db, false, [], options)
80
+ end
81
+ end
82
+
83
+ def pgsqlDir
84
+ return @pgsqlDir if @pgsqlDir
85
+ distroID = connection.distroID
86
+ if distroID == 'opensuse-leap'
87
+ @pgsqlDir = '/var/lib/pgsql/'
88
+ elsif distroID == 'arch'
89
+ @pgsqlDir = '/var/lib/postgres/'
90
+ else
91
+ raise Framework::PluginProcessError.new("Unsupported Linux Distro: #{distroID}!")
92
+ end
93
+ @pgsqlDir
94
+ end
95
+ end
96
+ end
97
+ end