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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -4
  3. data/CHANGELOG.md +24 -14
  4. data/README.md +14 -0
  5. data/Rakefile +29 -0
  6. data/db/reset.rb +7 -0
  7. data/db/seeds.rb +26 -0
  8. data/docker-admin/config.local.php +3 -1
  9. data/docker-compose.yml +3 -8
  10. data/lib/postfix_admin/base.rb +11 -22
  11. data/lib/postfix_admin/cli.rb +140 -56
  12. data/lib/postfix_admin/doveadm.rb +31 -15
  13. data/lib/postfix_admin/{admin.rb → models/admin.rb} +21 -2
  14. data/lib/postfix_admin/models/alias.rb +63 -0
  15. data/lib/postfix_admin/{application_record.rb → models/application_record.rb} +2 -2
  16. data/lib/postfix_admin/{concerns → models/concerns}/existing_timestamp.rb +1 -2
  17. data/lib/postfix_admin/models/concerns/has_password.rb +16 -0
  18. data/lib/postfix_admin/{domain.rb → models/domain.rb} +66 -2
  19. data/lib/postfix_admin/models/domain_admin.rb +21 -0
  20. data/lib/postfix_admin/models/log.rb +22 -0
  21. data/lib/postfix_admin/models/mailbox.rb +143 -0
  22. data/lib/postfix_admin/models/quota2.rb +20 -0
  23. data/lib/postfix_admin/models.rb +8 -9
  24. data/lib/postfix_admin/runner.rb +68 -14
  25. data/lib/postfix_admin/version.rb +1 -1
  26. metadata +15 -14
  27. data/lib/postfix_admin/alias.rb +0 -46
  28. data/lib/postfix_admin/concerns/dovecot_cram_md5_password.rb +0 -29
  29. data/lib/postfix_admin/domain_admin.rb +0 -8
  30. data/lib/postfix_admin/log.rb +0 -5
  31. data/lib/postfix_admin/mail_domain.rb +0 -9
  32. data/lib/postfix_admin/mailbox.rb +0 -97
  33. data/lib/postfix_admin/quota.rb +0 -6
  34. /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: 8a15e49758d586d12c05d2e0f15f04b123345942d9de889a3617d9cb13ca25bb
4
- data.tar.gz: 9b0a5e9d4741ad9dc8562347c4ca63616bddf97b5e20e6669ae7088bbb04bb29
3
+ metadata.gz: 79176db25ca525f4d2031a41bf66f35895ae7d96d944af8e607c75f7654a1916
4
+ data.tar.gz: 5d3f6f207505ff525e4e192d6d03747bb5c7cf08e90dad5d313d93893bbb8601
5
5
  SHA512:
6
- metadata.gz: eeee12bb7ba7e2d3530878a431f82bfd0c239f64b96225577d46a20e90d60f870a6df73fe96a3dbc02cc69363b380f63976074d8d0e4debd465ae0c014d337a4
7
- data.tar.gz: 257ad43dfbb601927501abab85a6ecf8c0c1bc2d353f2bf7f6be93db81a50c6f27eaf685cc9c6386c5c734a0989e3909346e8aa66247dbabb77c1fb66562b40e
6
+ metadata.gz: be19b8e778bf216deb66d9cc922d75022fb32425036def3a8b0642086a56b81b899bf3ec5070f667926b085354a3803da82f9d9b1e09075bae181876e67ac59f
7
+ data.tar.gz: 6af8ea674a934b5c522880a8c7f5a0c2d1a9c41959e626280f781ff6e6b62065b870830ee288582d49cafe91c83f8c42e535b61d9c62809c510fbdf396f72174
@@ -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 ./test/misc/postfix_admin.conf ~/.postfix_admin.conf
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 ./test/misc/ci.my.cnf ~/.my.cnf
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
- * Added support for table display format
5
- * No longer supports `dovecotpw` for password hash generation
6
- + Only `doveadm pw` is supported
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
- * Added support for the `superadmin` column in the `admin` table
10
- * Added `passwordhash_prefix` keyword in the configuration format for backward compatibility
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
- * Switched the object-relational mapper from DataMapper to ActiveRecord
14
- * Stored password hashes now include scheme prefixes, such as `{CRAM-MD5}` and `{PLAIN}`
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
- * Added "log" subcommand
27
+ * Added `log` subcommand
18
28
 
19
29
  ## 0.1.3
20
- * Added support for activation and deactivation of domains, admins, and accounts
21
- * Added "edit_admin" subcommand
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
- * Added support for password hashing by doveadm (external subcommand)
25
- * Display active status
26
- * Hide passwords in list format
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
- * Fixed string length issue for passwords
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
@@ -0,0 +1,7 @@
1
+ DomainAdmin.delete_all
2
+ Mailbox.delete_all
3
+ Alias.delete_all
4
+ Domain.without_all.delete_all
5
+ Admin.delete_all
6
+ Quota2.delete_all
7
+ Log.delete_all
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:
@@ -100,7 +100,7 @@ module PostfixAdmin
100
100
  domain: domain_name,
101
101
  password: password,
102
102
  name: name,
103
- quota_mb: @config[:maxquota]
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
- local_part: local_part,
125
- goto: goto
124
+ address: address,
125
+ goto: goto,
126
+ domain: domain_name
126
127
  }
127
128
 
128
- domain.rel_aliases << Alias.new(attributes)
129
+ new_alias = Alias.new(attributes)
129
130
 
130
- raise_save_error(domain) unless domain.save
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 || domain_name
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.where(username: address).delete_all
207
- Alias.where(address: address).delete_all
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
- raise_error "Failed to save #{obj.class}: #{obj.errors.full_messages.join(', ')}"
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)