postfix_admin 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +52 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +20 -0
  5. data/CHANGELOG.md +26 -12
  6. data/Gemfile +1 -1
  7. data/LICENSE +1 -1
  8. data/README.md +26 -20
  9. data/Rakefile +48 -1
  10. data/bin/console +6 -2
  11. data/db/reset.rb +7 -0
  12. data/db/seeds.rb +26 -0
  13. data/docker-admin/config.local.php +6 -1
  14. data/docker-app/Dockerfile +2 -6
  15. data/docker-app/my.cnf +2 -2
  16. data/docker-compose.yml +20 -20
  17. data/lib/postfix_admin/base.rb +119 -112
  18. data/lib/postfix_admin/cli.rb +267 -158
  19. data/lib/postfix_admin/doveadm.rb +32 -20
  20. data/lib/postfix_admin/{admin.rb → models/admin.rb} +25 -2
  21. data/lib/postfix_admin/{alias.rb → models/alias.rb} +16 -26
  22. data/lib/postfix_admin/{application_record.rb → models/application_record.rb} +1 -1
  23. data/lib/postfix_admin/{concerns → models/concerns}/existing_timestamp.rb +1 -2
  24. data/lib/postfix_admin/models/concerns/has_password.rb +16 -0
  25. data/lib/postfix_admin/models/domain.rb +112 -0
  26. data/lib/postfix_admin/models/domain_admin.rb +19 -0
  27. data/lib/postfix_admin/models/log.rb +20 -0
  28. data/lib/postfix_admin/models/mailbox.rb +126 -0
  29. data/lib/postfix_admin/models/quota2.rb +18 -0
  30. data/lib/postfix_admin/models.rb +8 -9
  31. data/lib/postfix_admin/runner.rb +91 -28
  32. data/lib/postfix_admin/version.rb +1 -1
  33. data/postfix_admin.gemspec +12 -10
  34. metadata +61 -34
  35. data/.github/workflows/ruby.yml +0 -37
  36. data/docker-app/docker-entrypoint.sh +0 -5
  37. data/docker-app-2.5/Dockerfile +0 -15
  38. data/lib/postfix_admin/concerns/dovecot_cram_md5_password.rb +0 -30
  39. data/lib/postfix_admin/domain.rb +0 -98
  40. data/lib/postfix_admin/domain_admin.rb +0 -8
  41. data/lib/postfix_admin/log.rb +0 -5
  42. data/lib/postfix_admin/mail_domain.rb +0 -9
  43. data/lib/postfix_admin/mailbox.rb +0 -89
  44. data/lib/postfix_admin/quota.rb +0 -6
  45. /data/lib/postfix_admin/{concerns → models/concerns}/.keep +0 -0
@@ -1,8 +0,0 @@
1
- module PostfixAdmin
2
- class DomainAdmin < ApplicationRecord
3
- self.table_name = :domain_admins
4
-
5
- belongs_to :admin, primary_key: :username, foreign_key: :username
6
- belongs_to :rel_domain, class_name: "Domain", foreign_key: :domain
7
- end
8
- end
@@ -1,5 +0,0 @@
1
- module PostfixAdmin
2
- class Log < ApplicationRecord
3
- self.table_name = :log
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- module PostfixAdmin
2
- class MailDomain < ApplicationRecord
3
- self.table_name = :domain
4
- self.primary_key = :domain
5
-
6
- has_many :addresses, class_name: "Mailbox", foreign_key: :domain,
7
- dependent: :destroy
8
- end
9
- end
@@ -1,89 +0,0 @@
1
- module PostfixAdmin
2
- class Mailbox < ApplicationRecord
3
- self.table_name = :mailbox
4
- self.primary_key = :username
5
-
6
- include DovecotCramMD5Password
7
-
8
- attribute :quota_mb, :integer
9
-
10
- validates :username, presence: true, uniqueness: { case_sensitive: false },
11
- format: { with: RE_EMAIL_LIKE_WITH_ANCHORS,
12
- message: "must be a valid email address" }
13
- validates :maildir, presence: true, uniqueness: { case_sensitive: false }
14
- validates :local_part, presence: true
15
- validates :quota, presence: true,
16
- numericality: { only_integer: true,
17
- greater_than_or_equal_to: 0 }
18
- validates :quota_mb, presence: true,
19
- numericality: { only_integer: true,
20
- greater_than_or_equal_to: 0 }
21
-
22
- belongs_to :rel_domain, class_name: "Domain", foreign_key: :domain
23
- has_one :alias, foreign_key: :address, dependent: :destroy
24
- has_one :quota_usage, class_name: "Quota", foreign_key: :username,
25
- dependent: :destroy
26
-
27
- validate on: :create do |mailbox|
28
- domain = mailbox.rel_domain
29
- if !domain.mailboxes.zero? && domain.rel_mailboxes.count >= domain.mailboxes
30
- message = "already has the maximum number of mailboxes " \
31
- "(maximum is #{domain.mailboxes} mailboxes)"
32
- mailbox.errors.add(:domain, message)
33
- end
34
- end
35
-
36
- # just in case
37
- validate on: :update do |mailbox|
38
- mailbox.errors.add(:username, 'cannot be changed') if mailbox.username_changed?
39
- mailbox.errors.add(:local_part, 'cannot be changed') if mailbox.local_part_changed?
40
- end
41
-
42
- validate do |mailbox|
43
- domain = mailbox.rel_domain
44
-
45
- unless domain.maxquota.zero?
46
- if mailbox.quota_mb.zero?
47
- mailbox.errors.add(:quota_mb, "cannot be 0")
48
- elsif mailbox.quota_mb > domain.maxquota
49
- message = "must be less than or equal to #{domain.maxquota} (MB)"
50
- mailbox.errors.add(:quota_mb, message)
51
- end
52
- end
53
- end
54
-
55
- before_validation do |mailbox|
56
- mailbox.name = "" if mailbox.name.nil?
57
- if mailbox.quota_mb
58
- mailbox.quota = mailbox.quota_mb * KB_TO_MB
59
- elsif mailbox.quota
60
- mailbox.quota_mb = mailbox.quota / KB_TO_MB
61
- else
62
- mailbox.quota_mb = 0
63
- mailbox.quota = 0
64
- end
65
- mailbox.username = "#{mailbox.local_part}@#{mailbox.domain}"
66
- mailbox.maildir = "#{mailbox.domain}/#{mailbox.username}/"
67
- mailbox.build_alias(local_part: mailbox.local_part, goto: mailbox.username,
68
- domain: mailbox.domain)
69
- end
70
-
71
- def quota_usage_str
72
- if quota_usage
73
- usage_mb = quota_usage.bytes / KB_TO_MB
74
- usage_mb.to_s
75
- else
76
- "0"
77
- end
78
- end
79
-
80
- def quota_str
81
- if quota.zero?
82
- "--"
83
- else
84
- quota_mb = quota / KB_TO_MB
85
- "#{quota_mb} MB"
86
- end
87
- end
88
- end
89
- end
@@ -1,6 +0,0 @@
1
- module PostfixAdmin
2
- class Quota < ApplicationRecord
3
- self.table_name = :quota2
4
- self.primary_key = :username
5
- end
6
- end