postfix_admin 0.3.0 → 0.3.2
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 +2 -4
- data/CHANGELOG.md +24 -14
- data/README.md +14 -0
- data/Rakefile +29 -0
- data/db/reset.rb +7 -0
- data/db/seeds.rb +26 -0
- data/docker-admin/config.local.php +3 -1
- data/docker-compose.yml +3 -8
- data/lib/postfix_admin/base.rb +11 -22
- data/lib/postfix_admin/cli.rb +140 -56
- data/lib/postfix_admin/doveadm.rb +31 -15
- data/lib/postfix_admin/{admin.rb → models/admin.rb} +21 -2
- data/lib/postfix_admin/models/alias.rb +63 -0
- data/lib/postfix_admin/{application_record.rb → models/application_record.rb} +2 -2
- 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/{domain.rb → models/domain.rb} +66 -2
- data/lib/postfix_admin/models/domain_admin.rb +21 -0
- data/lib/postfix_admin/models/log.rb +22 -0
- data/lib/postfix_admin/models/mailbox.rb +143 -0
- data/lib/postfix_admin/models/quota2.rb +20 -0
- data/lib/postfix_admin/models.rb +8 -9
- data/lib/postfix_admin/runner.rb +68 -14
- data/lib/postfix_admin/version.rb +1 -1
- metadata +15 -14
- data/lib/postfix_admin/alias.rb +0 -46
- data/lib/postfix_admin/concerns/dovecot_cram_md5_password.rb +0 -29
- 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 -97
- data/lib/postfix_admin/quota.rb +0 -6
- /data/lib/postfix_admin/{concerns → models/concerns}/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79176db25ca525f4d2031a41bf66f35895ae7d96d944af8e607c75f7654a1916
|
4
|
+
data.tar.gz: 5d3f6f207505ff525e4e192d6d03747bb5c7cf08e90dad5d313d93893bbb8601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be19b8e778bf216deb66d9cc922d75022fb32425036def3a8b0642086a56b81b899bf3ec5070f667926b085354a3803da82f9d9b1e09075bae181876e67ac59f
|
7
|
+
data.tar.gz: 6af8ea674a934b5c522880a8c7f5a0c2d1a9c41959e626280f781ff6e6b62065b870830ee288582d49cafe91c83f8c42e535b61d9c62809c510fbdf396f72174
|
data/.github/workflows/ci.yml
CHANGED
@@ -38,9 +38,9 @@ jobs:
|
|
38
38
|
- name: Install dovecotpw
|
39
39
|
run: sudo apt-get install -y dovecot-core
|
40
40
|
- name: Copy configure file
|
41
|
-
run: cp ./
|
41
|
+
run: cp ./spec/misc/postfix_admin.conf ~/.postfix_admin.conf
|
42
42
|
- name: Copy my.cnf (for `rake setup_test_db`)
|
43
|
-
run: cp ./
|
43
|
+
run: cp ./spec/misc/ci.my.cnf ~/.my.cnf
|
44
44
|
- name: docker-compose up
|
45
45
|
run: docker-compose up -d db
|
46
46
|
- name: Sleep (work around)
|
@@ -48,7 +48,5 @@ jobs:
|
|
48
48
|
run: sleep 10
|
49
49
|
- name: Set up test database
|
50
50
|
run: bundle exec rake setup_test_db
|
51
|
-
- name: Run tests
|
52
|
-
run: bundle exec rake test
|
53
51
|
- name: Run specs
|
54
52
|
run: bundle exec rake spec
|
data/CHANGELOG.md
CHANGED
@@ -1,29 +1,39 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.3.2
|
4
|
+
* Added `-d` (description) option for the `setup` subcommand
|
5
|
+
|
6
|
+
## 0.3.1
|
7
|
+
* Added `admins`, `domains`, `accounts`, `aliases` and `forwards` subcommands
|
8
|
+
* Added `teardown` subcommand for the opposite operation of `setup`
|
9
|
+
* `delete_domain` subcommand removes logs associated with the domain
|
10
|
+
* Added `-s` (scheme) and `-r` (rounds) options for subcommands that require password arguments
|
11
|
+
+ Encryption rounds are supported only for `BLF-CRYPT`, `SHA256-CRYPT`, and `SHA512-CRYPT` schemes
|
12
|
+
|
3
13
|
## 0.3.0
|
4
|
-
|
5
|
-
|
6
|
-
|
14
|
+
* Added support for table display format
|
15
|
+
* No longer supports `dovecotpw` for password hash generation
|
16
|
+
+ Only `doveadm pw` is supported
|
7
17
|
|
8
18
|
## 0.2.1
|
9
|
-
|
10
|
-
|
19
|
+
* Added support for the `superadmin` column in the `admin` table
|
20
|
+
* Added `passwordhash_prefix` keyword in the configuration format for backward compatibility
|
11
21
|
|
12
22
|
## 0.2.0
|
13
|
-
|
14
|
-
|
23
|
+
* Switched the object-relational mapper from DataMapper to ActiveRecord
|
24
|
+
* Stored password hashes now include scheme prefixes, such as `{CRAM-MD5}` and `{PLAIN}`
|
15
25
|
|
16
26
|
## 0.1.4
|
17
|
-
|
27
|
+
* Added `log` subcommand
|
18
28
|
|
19
29
|
## 0.1.3
|
20
|
-
|
21
|
-
|
30
|
+
* Added support for activation and deactivation of domains, admins, and accounts
|
31
|
+
* Added `edit_admin` subcommand
|
22
32
|
|
23
33
|
## 0.1.2
|
24
|
-
|
25
|
-
|
26
|
-
|
34
|
+
* Added support for password hashing by doveadm (external subcommand)
|
35
|
+
* Display active status
|
36
|
+
* Hide passwords in list format
|
27
37
|
|
28
38
|
## 0.1.1, released 2013-05-10
|
29
|
-
|
39
|
+
* Fixed string length issue for passwords
|
data/README.md
CHANGED
@@ -35,6 +35,20 @@ Execute the `postfix_admin` command to generate your config file at `~/.postfix_
|
|
35
35
|
Edit the file for your environment:
|
36
36
|
|
37
37
|
$ vi ~/.postfix_admin.conf
|
38
|
+
---
|
39
|
+
database: mysql2://postfix:password@localhost/postfix
|
40
|
+
aliases: 30
|
41
|
+
mailboxes: 30
|
42
|
+
maxquota: 100
|
43
|
+
scheme: CRAM-MD5
|
44
|
+
|
45
|
+
The configuration file format is as follows:
|
46
|
+
|
47
|
+
database: mysql2://<username>:<password>@<host>/<database>
|
48
|
+
aliases: Default maximum number of aliases allowed per domain
|
49
|
+
mailboxes: Default maximum number of mailboxes allowed per domain
|
50
|
+
maxquota: Default maximum quota (in MB) allowed per mailbox for a domain
|
51
|
+
scheme: Default password scheme
|
38
52
|
|
39
53
|
You can see the domains on your host if the `database` parameter is set properly:
|
40
54
|
|
data/Rakefile
CHANGED
@@ -2,6 +2,11 @@ require "bundler/gem_tasks"
|
|
2
2
|
require "rake/testtask"
|
3
3
|
require "rspec/core/rake_task"
|
4
4
|
|
5
|
+
require "bundler/setup"
|
6
|
+
Bundler.require(:default, :development)
|
7
|
+
require "postfix_admin"
|
8
|
+
require "postfix_admin/cli"
|
9
|
+
|
5
10
|
Rake::TestTask.new(:test) do |t|
|
6
11
|
t.libs << "test"
|
7
12
|
t.libs << "lib"
|
@@ -22,3 +27,27 @@ task :setup_test_db do
|
|
22
27
|
puts import_db_cmd
|
23
28
|
puts `#{import_db_cmd}`
|
24
29
|
end
|
30
|
+
|
31
|
+
namespace :db do
|
32
|
+
desc "Loads the seed data from db/seeds.rb"
|
33
|
+
task :seed do
|
34
|
+
establish_db_connection
|
35
|
+
require_relative "db/seeds"
|
36
|
+
end
|
37
|
+
|
38
|
+
namespace :seed do
|
39
|
+
desc "Truncates tables of each database for current environment and loads the seeds"
|
40
|
+
task :replant do
|
41
|
+
establish_db_connection
|
42
|
+
|
43
|
+
require_relative "db/reset"
|
44
|
+
require_relative "db/seeds"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def establish_db_connection
|
49
|
+
FactoryBot.find_definitions
|
50
|
+
|
51
|
+
PostfixAdmin::CLI.new.db_setup
|
52
|
+
end
|
53
|
+
end
|
data/db/reset.rb
ADDED
data/db/seeds.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
include FactoryBot::Syntax::Methods
|
2
|
+
|
3
|
+
create(:domain, domain: "example.com", description: "example.com Description")
|
4
|
+
create(:domain, domain: "example.org", description: "example.org Description")
|
5
|
+
|
6
|
+
all_admin = create(:admin, username: "all@example.com")
|
7
|
+
all_admin.rel_domains << Domain.find('ALL')
|
8
|
+
all_admin.superadmin = true if all_admin.has_superadmin_column?
|
9
|
+
all_admin.save!
|
10
|
+
|
11
|
+
admin = create(:admin, username: "admin@example.com")
|
12
|
+
domain = Domain.find('example.com')
|
13
|
+
domain.admins << admin
|
14
|
+
domain.rel_aliases << build(:alias, address: "alias@example.com")
|
15
|
+
domain.rel_mailboxes << build(:mailbox, local_part: "user")
|
16
|
+
domain.rel_mailboxes << build(:mailbox, local_part: "user2")
|
17
|
+
domain.save!
|
18
|
+
|
19
|
+
# forward
|
20
|
+
user = Alias.find("user2@example.com").update(goto: "user2@example.com,forward@example.com")
|
21
|
+
|
22
|
+
create(:quota2, username: "user@example.com", bytes: 75 * PostfixAdmin::KB_TO_MB)
|
23
|
+
|
24
|
+
create(:log)
|
25
|
+
create(:log, action: "delete_domain", data: "user@example.com")
|
26
|
+
create(:log, domain: "example.org", data: "example.org")
|
@@ -16,9 +16,11 @@ $CONF['password_validation'] = array(
|
|
16
16
|
|
17
17
|
$CONF['encrypt'] = 'dovecot:CRAM-MD5';
|
18
18
|
|
19
|
+
$CONF['default_aliases'] = array();
|
19
20
|
$CONF['domain_quota'] = 'NO';
|
20
21
|
$CONF['quota'] = 'YES';
|
22
|
+
$CONF['emailcheck_resolve_domain']='NO';
|
21
23
|
|
22
24
|
// setup_password: 'password'
|
23
25
|
$CONF['setup_password'] = '87745eb0269b2f42813b23601be3231a:6e41880f73d97321f2f0b25a5ee30f57f5ab3be8';
|
24
|
-
?>
|
26
|
+
?>
|
data/docker-compose.yml
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# docker compose up -d
|
2
2
|
#
|
3
3
|
# Run tests on service app
|
4
|
-
# You may need to run tests on Docker because of its requirement of doveadm
|
4
|
+
# You may need to run tests on Docker because of its requirement of `doveadm` command.
|
5
5
|
# docker compose exec app bundle exec rake setup_test_db
|
6
|
-
# docker compose exec app bundle exec rake test
|
7
6
|
# docker compose exec app bundle exec rake spec
|
7
|
+
#
|
8
|
+
# rspec spec/runner_spec.rb
|
8
9
|
|
9
10
|
services:
|
10
11
|
app:
|
@@ -26,12 +27,6 @@ services:
|
|
26
27
|
- ./docker-admin/config.local.php:/var/www/html/config.local.php
|
27
28
|
depends_on:
|
28
29
|
- db
|
29
|
-
# environment:
|
30
|
-
# - POSTFIXADMIN_DB_TYPE=mysqli
|
31
|
-
# - POSTFIXADMIN_DB_HOST=db
|
32
|
-
# - POSTFIXADMIN_DB_USER=postfix
|
33
|
-
# - POSTFIXADMIN_DB_PASSWORD=password
|
34
|
-
# - POSTFIXADMIN_DB_NAME=postfix
|
35
30
|
db:
|
36
31
|
image: mariadb:10
|
37
32
|
ports:
|
data/lib/postfix_admin/base.rb
CHANGED
@@ -100,7 +100,7 @@ module PostfixAdmin
|
|
100
100
|
domain: domain_name,
|
101
101
|
password: password,
|
102
102
|
name: name,
|
103
|
-
|
103
|
+
quota: @config[:maxquota] * KB_TO_MB
|
104
104
|
}
|
105
105
|
|
106
106
|
# An Alias also will be added when a Mailbox is saved.
|
@@ -121,13 +121,14 @@ module PostfixAdmin
|
|
121
121
|
domain = find_domain(domain_name)
|
122
122
|
|
123
123
|
attributes = {
|
124
|
-
|
125
|
-
goto: goto
|
124
|
+
address: address,
|
125
|
+
goto: goto,
|
126
|
+
domain: domain_name
|
126
127
|
}
|
127
128
|
|
128
|
-
|
129
|
+
new_alias = Alias.new(attributes)
|
129
130
|
|
130
|
-
raise_save_error(
|
131
|
+
raise_save_error(new_alias) unless new_alias.save
|
131
132
|
end
|
132
133
|
|
133
134
|
def delete_alias(address)
|
@@ -153,7 +154,7 @@ module PostfixAdmin
|
|
153
154
|
raise_error "Domain has already been registered: #{domain_name}"
|
154
155
|
end
|
155
156
|
|
156
|
-
new_description = description ||
|
157
|
+
new_description = description || ""
|
157
158
|
|
158
159
|
domain = Domain.new
|
159
160
|
domain.attributes = {
|
@@ -174,18 +175,6 @@ module PostfixAdmin
|
|
174
175
|
admin_names = domain.admins.map(&:username)
|
175
176
|
|
176
177
|
domain.destroy!
|
177
|
-
|
178
|
-
# Remove admins who had the deleted domain only
|
179
|
-
admin_names.each do |name|
|
180
|
-
next unless Admin.exists?(name)
|
181
|
-
|
182
|
-
admin = Admin.find(name)
|
183
|
-
|
184
|
-
# check if the admin is needed or not
|
185
|
-
if admin.rel_domains.empty?
|
186
|
-
admin.destroy!
|
187
|
-
end
|
188
|
-
end
|
189
178
|
end
|
190
179
|
|
191
180
|
def delete_admin(user_name)
|
@@ -194,7 +183,6 @@ module PostfixAdmin
|
|
194
183
|
end
|
195
184
|
|
196
185
|
admin = Admin.find(user_name)
|
197
|
-
admin.rel_domains.delete_all
|
198
186
|
admin.destroy!
|
199
187
|
end
|
200
188
|
|
@@ -203,8 +191,8 @@ module PostfixAdmin
|
|
203
191
|
raise_error "Could not find account: #{address}"
|
204
192
|
end
|
205
193
|
|
206
|
-
Mailbox.
|
207
|
-
|
194
|
+
mailbox = Mailbox.find(address)
|
195
|
+
mailbox.destroy!
|
208
196
|
end
|
209
197
|
|
210
198
|
private
|
@@ -219,7 +207,8 @@ module PostfixAdmin
|
|
219
207
|
end
|
220
208
|
|
221
209
|
def raise_save_error(obj)
|
222
|
-
|
210
|
+
massage = obj.errors.full_messages.join(', ')
|
211
|
+
raise_error "Failed to save #{obj.class}: #{massage}"
|
223
212
|
end
|
224
213
|
|
225
214
|
def address_split(address)
|