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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +52 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +26 -12
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +26 -20
- data/Rakefile +48 -1
- data/bin/console +6 -2
- data/db/reset.rb +7 -0
- data/db/seeds.rb +26 -0
- data/docker-admin/config.local.php +6 -1
- data/docker-app/Dockerfile +2 -6
- data/docker-app/my.cnf +2 -2
- data/docker-compose.yml +20 -20
- data/lib/postfix_admin/base.rb +119 -112
- data/lib/postfix_admin/cli.rb +267 -158
- data/lib/postfix_admin/doveadm.rb +32 -20
- data/lib/postfix_admin/{admin.rb → models/admin.rb} +25 -2
- data/lib/postfix_admin/{alias.rb → models/alias.rb} +16 -26
- data/lib/postfix_admin/{application_record.rb → models/application_record.rb} +1 -1
- data/lib/postfix_admin/{concerns → models/concerns}/existing_timestamp.rb +1 -2
- data/lib/postfix_admin/models/concerns/has_password.rb +16 -0
- data/lib/postfix_admin/models/domain.rb +112 -0
- data/lib/postfix_admin/models/domain_admin.rb +19 -0
- data/lib/postfix_admin/models/log.rb +20 -0
- data/lib/postfix_admin/models/mailbox.rb +126 -0
- data/lib/postfix_admin/models/quota2.rb +18 -0
- data/lib/postfix_admin/models.rb +8 -9
- data/lib/postfix_admin/runner.rb +91 -28
- data/lib/postfix_admin/version.rb +1 -1
- data/postfix_admin.gemspec +12 -10
- metadata +61 -34
- data/.github/workflows/ruby.yml +0 -37
- data/docker-app/docker-entrypoint.sh +0 -5
- data/docker-app-2.5/Dockerfile +0 -15
- data/lib/postfix_admin/concerns/dovecot_cram_md5_password.rb +0 -30
- data/lib/postfix_admin/domain.rb +0 -98
- data/lib/postfix_admin/domain_admin.rb +0 -8
- data/lib/postfix_admin/log.rb +0 -5
- data/lib/postfix_admin/mail_domain.rb +0 -9
- data/lib/postfix_admin/mailbox.rb +0 -89
- data/lib/postfix_admin/quota.rb +0 -6
- /data/lib/postfix_admin/{concerns → models/concerns}/.keep +0 -0
data/lib/postfix_admin/log.rb
DELETED
@@ -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
|
data/lib/postfix_admin/quota.rb
DELETED
File without changes
|