postfix_admin 0.1.4 → 0.2.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +7 -5
- data/Dockerfile +24 -0
- data/README.md +22 -15
- data/Rakefile +5 -0
- data/bin/console +18 -0
- data/docker-compose.yml +24 -0
- data/docker-entrypoint.sh +5 -0
- data/{bin → exe}/postfix_admin +1 -0
- data/lib/postfix_admin.rb +1 -1
- data/lib/postfix_admin/admin.rb +52 -0
- data/lib/postfix_admin/alias.rb +65 -0
- data/lib/postfix_admin/application_record.rb +44 -0
- data/lib/postfix_admin/base.rb +98 -88
- data/lib/postfix_admin/cli.rb +50 -46
- data/lib/postfix_admin/concerns/.keep +0 -0
- data/lib/postfix_admin/concerns/dovecot_cram_md5_password.rb +30 -0
- data/lib/postfix_admin/concerns/existing_timestamp.rb +18 -0
- data/lib/postfix_admin/domain.rb +98 -0
- data/lib/postfix_admin/domain_admin.rb +8 -0
- data/lib/postfix_admin/doveadm.rb +1 -1
- data/lib/postfix_admin/log.rb +5 -0
- data/lib/postfix_admin/mail_domain.rb +9 -0
- data/lib/postfix_admin/mailbox.rb +89 -0
- data/lib/postfix_admin/models.rb +10 -213
- data/lib/postfix_admin/quota.rb +6 -0
- data/lib/postfix_admin/runner.rb +39 -36
- data/lib/postfix_admin/version.rb +1 -1
- data/postfix_admin.gemspec +20 -13
- metadata +49 -50
- data/spec/base_spec.rb +0 -253
- data/spec/cli_spec.rb +0 -300
- data/spec/doveadm_spec.rb +0 -35
- data/spec/models_spec.rb +0 -195
- data/spec/postfix_admin.conf +0 -5
- data/spec/postfix_test.sql +0 -250
- data/spec/runner_spec.rb +0 -370
- data/spec/spec_helper.rb +0 -201
data/spec/spec_helper.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
|
2
|
-
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
-
|
4
|
-
require 'postfix_admin'
|
5
|
-
require 'postfix_admin/cli'
|
6
|
-
|
7
|
-
include PostfixAdmin
|
8
|
-
|
9
|
-
# CRAM-MD5
|
10
|
-
SAMPLE_PASSWORD = "9186d855e11eba527a7a52ca82b313e180d62234f0acc9051b527243d41e2740"
|
11
|
-
|
12
|
-
# [fixtures]
|
13
|
-
# Domain:
|
14
|
-
# ALL
|
15
|
-
# example.com
|
16
|
-
# example.org
|
17
|
-
#
|
18
|
-
# Admin:
|
19
|
-
# all@example.com Super Admin
|
20
|
-
# admin@example.com
|
21
|
-
#
|
22
|
-
# Mailbox, Alias:
|
23
|
-
# user@example.com
|
24
|
-
#
|
25
|
-
# Alias:
|
26
|
-
# alias@example.com -> goto@example.jp
|
27
|
-
|
28
|
-
def config_initialize
|
29
|
-
CLI.config_file = File.join(File.dirname(__FILE__) , 'postfix_admin.conf')
|
30
|
-
end
|
31
|
-
|
32
|
-
def db_clear
|
33
|
-
::PostfixAdmin::Config.all.destroy
|
34
|
-
DomainAdmin.all.destroy
|
35
|
-
Mailbox.all.destroy
|
36
|
-
Alias.all.destroy
|
37
|
-
Domain.all.destroy
|
38
|
-
Admin.all.destroy
|
39
|
-
end
|
40
|
-
|
41
|
-
def create_domain(domain_name, active=true)
|
42
|
-
domain = Domain.new
|
43
|
-
domain.attributes = {
|
44
|
-
:domain_name => domain_name,
|
45
|
-
:description => domain_name,
|
46
|
-
:maxaliases => 30,
|
47
|
-
:maxmailboxes => 30,
|
48
|
-
:maxquota => 100,
|
49
|
-
:active => active
|
50
|
-
}
|
51
|
-
domain.save
|
52
|
-
end
|
53
|
-
|
54
|
-
def create_alias_base(address, goto, active)
|
55
|
-
Alias.new.attributes = {
|
56
|
-
:address => address,
|
57
|
-
:goto => goto,
|
58
|
-
:active => active
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
|
-
def create_alias(address, active=true)
|
63
|
-
create_alias_base(address, 'goto@example.jp', active)
|
64
|
-
end
|
65
|
-
|
66
|
-
def create_mailbox_alias(address, active=true)
|
67
|
-
create_alias_base(address, address, active)
|
68
|
-
end
|
69
|
-
|
70
|
-
def create_mailbox(address, in_path=nil, active=true)
|
71
|
-
path = in_path || "#{address.split('@').last}/#{address}/"
|
72
|
-
Mailbox.new.attributes = {
|
73
|
-
:username => address,
|
74
|
-
:password => SAMPLE_PASSWORD,
|
75
|
-
:name => '',
|
76
|
-
:maildir => path,
|
77
|
-
:quota => 100 * KB_TO_MB,
|
78
|
-
# :local_part => user,
|
79
|
-
:active => active
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
def create_admin(username, active=true)
|
84
|
-
admin = Admin.new
|
85
|
-
admin.attributes = {
|
86
|
-
:username => username,
|
87
|
-
:password => SAMPLE_PASSWORD,
|
88
|
-
:active => active
|
89
|
-
}
|
90
|
-
admin.save
|
91
|
-
admin
|
92
|
-
end
|
93
|
-
|
94
|
-
class ::PostfixAdmin::Mailbox
|
95
|
-
property :local_part, String
|
96
|
-
end
|
97
|
-
|
98
|
-
def db_initialize
|
99
|
-
db_clear
|
100
|
-
|
101
|
-
config = ::PostfixAdmin::Config.new
|
102
|
-
config.attributes = {
|
103
|
-
:id => 1,
|
104
|
-
:name => "version",
|
105
|
-
:value => "740"
|
106
|
-
}
|
107
|
-
config.save
|
108
|
-
|
109
|
-
create_domain('ALL')
|
110
|
-
create_domain('example.com')
|
111
|
-
create_domain('example.org')
|
112
|
-
|
113
|
-
all_admin = create_admin('all@example.com')
|
114
|
-
all_domain = Domain.find('ALL')
|
115
|
-
all_domain.admins << all_admin
|
116
|
-
|
117
|
-
unless all_domain.save
|
118
|
-
raise "Could not save all_domain"
|
119
|
-
end
|
120
|
-
|
121
|
-
admin = create_admin('admin@example.com')
|
122
|
-
domain = Domain.find('example.com')
|
123
|
-
domain.admins << admin
|
124
|
-
domain.aliases << create_alias('alias@example.com')
|
125
|
-
domain.aliases << create_alias('user@example.com')
|
126
|
-
domain.mailboxes << create_mailbox('user@example.com')
|
127
|
-
|
128
|
-
unless domain.save
|
129
|
-
raise "Could not save domain"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
DataMapper.setup(:default, 'sqlite::memory:')
|
134
|
-
DataMapper.finalize
|
135
|
-
DataMapper.auto_migrate!
|
136
|
-
db_initialize
|
137
|
-
config_initialize
|
138
|
-
|
139
|
-
module PostfixAdmin
|
140
|
-
class Base
|
141
|
-
|
142
|
-
# without DataMapper setup
|
143
|
-
def db_setup(database)
|
144
|
-
unless database
|
145
|
-
raise ArgumentError
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
CRAM_MD5_PASS = '9186d855e11eba527a7a52ca82b313e180d62234f0acc9051b527243d41e2740'
|
152
|
-
CRAM_MD5_NEW_PASS = '820de4c70957274d41111c5fbcae4c87240c9f047fc56f3e720f103571be6cbc'
|
153
|
-
EX_DELETED = /successfully deleted/
|
154
|
-
EX_REGISTERED = /successfully registered/
|
155
|
-
EX_UPDATED = /Successfully updated/
|
156
|
-
EX_MD5_CRYPT = /^\$1\$[\.\/0-9A-Za-z]{8}\$[\.\/0-9A-Za-z]{22}$/
|
157
|
-
|
158
|
-
RSpec.configure do |config|
|
159
|
-
config.before do
|
160
|
-
ARGV.replace []
|
161
|
-
end
|
162
|
-
|
163
|
-
def capture(stream)
|
164
|
-
begin
|
165
|
-
stream = stream.to_s
|
166
|
-
eval "$#{stream} = StringIO.new"
|
167
|
-
$stderr = StringIO.new if stream != "stderr"
|
168
|
-
yield
|
169
|
-
result = eval("$#{stream}").string
|
170
|
-
rescue SystemExit => e
|
171
|
-
message = $stderr.string
|
172
|
-
message += e.message
|
173
|
-
raise message
|
174
|
-
ensure
|
175
|
-
eval("$#{stream} = #{stream.upcase}")
|
176
|
-
end
|
177
|
-
|
178
|
-
result
|
179
|
-
end
|
180
|
-
|
181
|
-
def exit_capture
|
182
|
-
begin
|
183
|
-
$stderr = StringIO.new
|
184
|
-
yield
|
185
|
-
rescue SystemExit => e
|
186
|
-
ensure
|
187
|
-
result = $stderr.string
|
188
|
-
end
|
189
|
-
result
|
190
|
-
end
|
191
|
-
|
192
|
-
def source_root
|
193
|
-
File.join(File.dirname(__FILE__), 'fixtures')
|
194
|
-
end
|
195
|
-
|
196
|
-
def destination_root
|
197
|
-
File.join(File.dirname(__FILE__), 'sandbox')
|
198
|
-
end
|
199
|
-
|
200
|
-
alias :silence :capture
|
201
|
-
end
|