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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70bd18f454fd77684ab652949e36829f6d9e3e8e275e475819b60b025b3fea6e
4
- data.tar.gz: 477da494d685bcaeb45f090d92edbfb1abc6af811e04172a4e4f1865b51eac46
3
+ metadata.gz: a9877c43c00661c60c1fee5e200211c97cd4cdc8d53593985c3e49f8296d27b9
4
+ data.tar.gz: 9d9744f09e0a9e3ccdc72af138a4879824f3cd00bc3a1a111d0320a30007ee84
5
5
  SHA512:
6
- metadata.gz: a7b8c5f69e4f15589ca5c10250e88d9dfb76e623bed02548161e24c29fca02e74e97b154bf5f876936922e7b7d134f4fb6f46ab2e85765198fbaf5c7dddb1c32
7
- data.tar.gz: 777b1af93896c8df8a4eab31af493af872a694502cab871c0ea99bcf7e8a82ce014228e82b117c37a3c9953ec86bd54648a01954c2bcae72c373fca94d1c18dc
6
+ metadata.gz: 86dfd30f6793fd6c13d09e532d7499f2e040dbe654f1bf86299d79b518a96906b6e208fd87c9bbda631d577ccfe39fb08f910e9cc41617be00425c84860d03f2
7
+ data.tar.gz: f553b648aefc912877d3bcc149258a1d529caa457827f24b04bc4c5d4b45d7fc1397c4189c56ba0e800360320b6295b92abbde0ff344dc56d764995d8d88c448
@@ -0,0 +1,52 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on:
11
+ push:
12
+ branches:
13
+ - main
14
+ pull_request:
15
+ branches:
16
+ - main
17
+
18
+ permissions:
19
+ contents: read
20
+
21
+ jobs:
22
+ test:
23
+
24
+ runs-on: ubuntu-latest
25
+ strategy:
26
+ matrix:
27
+ ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3']
28
+
29
+ steps:
30
+ - uses: actions/checkout@v4
31
+ - name: Set up Ruby
32
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
33
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby-version }}
37
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
38
+ - name: Install dovecotpw
39
+ run: sudo apt-get install -y dovecot-core
40
+ - name: Copy configure file
41
+ run: cp ./spec/misc/postfix_admin.conf ~/.postfix_admin.conf
42
+ - name: Copy my.cnf (for `rake setup_test_db`)
43
+ run: cp ./spec/misc/ci.my.cnf ~/.my.cnf
44
+ - name: docker-compose up
45
+ run: docker-compose up -d db
46
+ - name: Sleep (work around)
47
+ # wait-for-it.sh doesn't work with docker compose port mapping
48
+ run: sleep 10
49
+ - name: Set up test database
50
+ run: bundle exec rake setup_test_db
51
+ - name: Run specs
52
+ run: bundle exec rake spec
data/.gitignore CHANGED
@@ -17,3 +17,5 @@ test/version_tmp
17
17
  tmp
18
18
  .idea
19
19
  .vagrant
20
+ .ruby-version
21
+ .rspec_status
data/.rubocop.yml CHANGED
@@ -1,2 +1,22 @@
1
+ AllCops:
2
+ NewCops: enable
1
3
  Style/StringLiterals:
2
4
  Enabled: false
5
+ Style/EmptyMethod:
6
+ Enabled: false
7
+ Style/IfUnlessModifier:
8
+ Enabled: false
9
+ Style/AsciiComments:
10
+ Enabled: false
11
+ Style/FrozenStringLiteralComment:
12
+ Enabled: false
13
+ Style/Documentation:
14
+ Enabled: false
15
+ Metrics/MethodLength:
16
+ Enabled: false
17
+ Metrics/AbcSize:
18
+ Enabled: false
19
+ Metrics/ClassLength:
20
+ Enabled: false
21
+ Style/EmptyElse:
22
+ EnforcedStyle: empty
data/CHANGELOG.md CHANGED
@@ -1,22 +1,36 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.3.1
4
+ + Added `admins`, `domains`, `accounts`, `aliases` and `forwards` subcommands
5
+ * Added `teardown` subcommand for the opposite operation of `setup`
6
+ * `delete_domain` subcommand removes logs associated with the domain
7
+ * Added `-s` (scheme) and `-r` (rounds) options for subcommands that require password arguments
8
+ + Encryption rounds are supported only for `BLF-CRYPT`, `SHA256-CRYPT`, and `SHA512-CRYPT` schemes
9
+
10
+ ## 0.3.0
11
+ * Added support for table display format
12
+ * No longer supports `dovecotpw` for password hash generation
13
+ + Only `doveadm pw` is supported
14
+
1
15
  ## 0.2.1
2
- * Supported `superadmin` column of `admin` table
3
- * Added `passwordhash_prefix` keyword in the configuration format for backward compatibility
16
+ * Added support for the `superadmin` column in the `admin` table
17
+ * Added `passwordhash_prefix` keyword in the configuration format for backward compatibility
4
18
 
5
19
  ## 0.2.0
6
- * Switched its object-relational mapper from DataMapper to ActiveRecord
7
- * Stored password hash includes scheme prefix: like `{CRAM-MD5}`, `{PLAIN}`
20
+ * Switched the object-relational mapper from DataMapper to ActiveRecord
21
+ * Stored password hashes now include scheme prefixes, such as `{CRAM-MD5}` and `{PLAIN}`
8
22
 
9
23
  ## 0.1.4
10
- * Added "log" subcommand
24
+ * Added `log` subcommand
11
25
 
12
26
  ## 0.1.3
13
- * Support for activation and deactivation of domain, admin and account
14
- * Added "edit_admin" subcommand
27
+ * Added support for activation and deactivation of domains, admins, and accounts
28
+ * Added `edit_admin` subcommand
15
29
 
16
30
  ## 0.1.2
17
- * Support password hash by doveadm (external subcommand)
18
- * Show active status
19
- * Don't show passwords using list format
31
+ * Added support for password hashing by doveadm (external subcommand)
32
+ * Display active status
33
+ * Hide passwords in list format
20
34
 
21
- ## 0.1.1, release 2013-05-10
22
- * Fixed string length of password
35
+ ## 0.1.1, released 2013-05-10
36
+ * Fixed string length issue for passwords
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in postfix_admin.gemspec
4
4
  gemspec
data/LICENSE CHANGED
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -10,19 +10,25 @@ Command Line Tools for Postfix Admin
10
10
  + Web Site http://postfixadmin.sourceforge.net/
11
11
  + GitHub https://github.com/postfixadmin/postfixadmin
12
12
 
13
- * Postfix Admin 3.2 is supported.
13
+ * Supports Postfix Admin 3.2
14
14
 
15
- * MySQL/MariaDB is supported.
15
+ * Supports MySQL/MariaDB
16
16
 
17
- * Other database engines are not supported.
17
+ * Other database engines are not supported
18
+
19
+ ## Requirements
20
+
21
+ * Ruby 2.6 or higher
22
+ * MySQL/MariaDB
23
+ * Dovecot (required for setting passwords using the `doveadm pw` subcommand)
18
24
 
19
25
  ## Installation
20
26
 
21
- Install postfix_admin as:
27
+ Install `postfix_admin` using:
22
28
 
23
29
  $ gem install postfix_admin
24
30
 
25
- Just execute `postfix_admin` command to generate your config file: `~/.postfix_admin.conf`
31
+ Execute the `postfix_admin` command to generate your config file at `~/.postfix_admin.conf`:
26
32
 
27
33
  $ postfix_admin
28
34
 
@@ -30,40 +36,40 @@ Edit the file for your environment:
30
36
 
31
37
  $ vi ~/.postfix_admin.conf
32
38
 
33
- You can see domains on your host if the `database` parameter is set properly:
39
+ You can see the domains on your host if the `database` parameter is set properly:
34
40
 
35
41
  $ postfix_admin show
36
42
 
37
43
  ## Usage
38
44
 
39
- List the postfix_admin subcommands as:
45
+ List the `postfix_admin` subcommands with:
40
46
 
41
47
  $ postfix_admin
42
48
 
43
49
  ```
44
50
  Commands:
45
- postfix_admin account_passwd user@example.com new_password # Change password of account
46
- postfix_admin add_account user@example.com password # Add an account
47
- postfix_admin add_admin admin@example.com password # Add an admin user
48
- postfix_admin add_admin_domain admin@example.com example.com # Add admin_domain
49
- postfix_admin add_alias alias@example.com goto@example.net # Add an alias
50
- postfix_admin add_domain example.com # Add a domain
51
- postfix_admin admin_passwd admin@example.com new_password # Change password of admin
51
+ postfix_admin account_passwd user@example.com new_password # Change the password of an account
52
+ postfix_admin add_account user@example.com password # Add a new account
53
+ postfix_admin add_admin admin@example.com password # Add a new admin user
54
+ postfix_admin add_admin_domain admin@example.com example.com # Grant an admin user access to a specific domain
55
+ postfix_admin add_alias alias@example.com goto@example.net # Add a new alias
56
+ postfix_admin add_domain example.com # Add a new domain
57
+ postfix_admin admin_passwd admin@example.com new_password # Change the password of an admin user
52
58
  postfix_admin delete_account user@example.com # Delete an account
53
- postfix_admin delete_admin admin@example.com # Delete an admin
54
- postfix_admin delete_admin_domain admin@example.com example.com # Delete admin_domain
59
+ postfix_admin delete_admin admin@example.com # Delete an admin user
60
+ postfix_admin delete_admin_domain admin@example.com example.com # Revoke an admin user's access to a specific domain
55
61
  postfix_admin delete_alias alias@example.com # Delete an alias
56
62
  postfix_admin delete_domain example.com # Delete a domain
57
63
  postfix_admin dump # Dump all data
58
64
  postfix_admin edit_account user@example.com # Edit an account
59
65
  postfix_admin edit_admin admin@example.com # Edit an admin user
60
66
  postfix_admin edit_alias alias@example.com # Edit an alias
61
- postfix_admin edit_domain example.com # Edit a domain limitation
67
+ postfix_admin edit_domain example.com # Edit a domain
62
68
  postfix_admin help [COMMAND] # Describe available commands or one specific command
63
- postfix_admin log # Show action logs
69
+ postfix_admin log # Display action logs
64
70
  postfix_admin schemes # List all supported password schemes
65
- postfix_admin setup example.com password # Setup a domain
66
- postfix_admin show [example.com | admin@example.com | user@example.com] # Show domains or admins or mailboxes
71
+ postfix_admin setup example.com password # Set up a domain
72
+ postfix_admin show [example.com | admin@example.com | user@example.com] # Display details about domains, admins, or accounts
67
73
  postfix_admin summary [example.com] # Summarize the usage of PostfixAdmin
68
74
  postfix_admin version # Show postfix_admin version
69
75
  ```
data/Rakefile CHANGED
@@ -1,6 +1,53 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
2
3
  require "rspec/core/rake_task"
3
4
 
5
+ require "bundler/setup"
6
+ Bundler.require(:default, :development)
7
+ require "postfix_admin"
8
+ require "postfix_admin/cli"
9
+
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << "test"
12
+ t.libs << "lib"
13
+ t.test_files = FileList["test/**/*_test.rb"]
14
+ end
15
+
4
16
  RSpec::Core::RakeTask.new(:spec)
5
17
 
6
- task default: :spec
18
+ task default: :test
19
+
20
+ desc "Set up test database"
21
+ task :setup_test_db do
22
+ create_db_cmd = "mysql -e 'CREATE DATABASE `postfix_test`;'"
23
+ puts create_db_cmd
24
+ puts `#{create_db_cmd}`
25
+
26
+ import_db_cmd = "mysql postfix_test < docker-db/postfix.v1841.sql"
27
+ puts import_db_cmd
28
+ puts `#{import_db_cmd}`
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/bin/console CHANGED
@@ -1,16 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
+ Bundler.require(:default, :development)
4
5
  require "postfix_admin"
5
6
  require "postfix_admin/cli"
6
7
 
7
8
  # You can add fixtures and/or initialization code here to make experimenting
8
9
  # with your gem easier. You can also use a different console, if you like.
9
10
 
10
- cli = PostfixAdmin::CLI.new
11
- cli.db_setup
11
+ @cli = PostfixAdmin::CLI.new
12
+ @cli.db_setup
12
13
  include PostfixAdmin
13
14
 
15
+ include FactoryBot::Syntax::Methods
16
+ FactoryBot.find_definitions
17
+
14
18
  require "pry"
15
19
  Pry.start
16
20
 
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,6 +16,11 @@ $CONF['password_validation'] = array(
16
16
 
17
17
  $CONF['encrypt'] = 'dovecot:CRAM-MD5';
18
18
 
19
+ $CONF['default_aliases'] = array();
20
+ $CONF['domain_quota'] = 'NO';
21
+ $CONF['quota'] = 'YES';
22
+ $CONF['emailcheck_resolve_domain']='NO';
23
+
19
24
  // setup_password: 'password'
20
25
  $CONF['setup_password'] = '87745eb0269b2f42813b23601be3231a:6e41880f73d97321f2f0b25a5ee30f57f5ab3be8';
21
- ?>
26
+ ?>
@@ -9,7 +9,7 @@ WORKDIR /app
9
9
  COPY Gemfile postfix_admin.gemspec ./
10
10
  COPY ./lib/postfix_admin/version.rb ./lib/postfix_admin/version.rb
11
11
 
12
- RUN gem install bundler && bundle install
12
+ RUN gem install bundler -v 2.4.22 && bundle install
13
13
 
14
14
  COPY spec/postfix_admin.conf /root/.postfix_admin.conf
15
15
  COPY docker-app/my.cnf /root/.my.cnf
@@ -18,8 +18,4 @@ COPY docker-app/my.cnf /root/.my.cnf
18
18
  RUN curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -so /wait-for-it.sh && \
19
19
  chmod 755 /wait-for-it.sh
20
20
 
21
- COPY docker-app/docker-entrypoint.sh /docker-entrypoint.sh
22
- RUN chmod +x /docker-entrypoint.sh
23
- ENTRYPOINT ["/docker-entrypoint.sh"]
24
-
25
- CMD ["irb"]
21
+ CMD ["irb"]
data/docker-app/my.cnf CHANGED
@@ -1,5 +1,5 @@
1
1
  [client]
2
- user = postfix
3
- password = password
2
+ user = root
3
+ password = ScRgkaMz4YwHN5dyxfQj
4
4
  host = db
5
5
  database = postfix
data/docker-compose.yml CHANGED
@@ -1,4 +1,12 @@
1
- version: '3.8'
1
+ # docker compose up -d
2
+ #
3
+ # Run tests on service app
4
+ # You may need to run tests on Docker because of its requirement of `doveadm` command.
5
+ # docker compose exec app bundle exec rake setup_test_db
6
+ # docker compose exec app bundle exec rake test
7
+ # docker compose exec app bundle exec rake spec
8
+ #
9
+ # rspec spec/runner_spec.rb
2
10
 
3
11
  services:
4
12
  app:
@@ -6,17 +14,10 @@ services:
6
14
  context: .
7
15
  dockerfile: docker-app/Dockerfile
8
16
  tty: true
9
- volumes:
10
- - .:/app
11
- depends_on:
12
- - db
13
- app2.5:
14
- tty: true
15
- build:
16
- context: .
17
- dockerfile: docker-app-2.5/Dockerfile
18
17
  volumes:
19
18
  - .:/app
19
+ environment:
20
+ - DATABASE_URL=mysql2://postfix:password@db/postfix
20
21
  depends_on:
21
22
  - db
22
23
  admin:
@@ -27,20 +28,19 @@ services:
27
28
  - ./docker-admin/config.local.php:/var/www/html/config.local.php
28
29
  depends_on:
29
30
  - db
30
- # environment:
31
- # - POSTFIXADMIN_DB_TYPE=mysqli
32
- # - POSTFIXADMIN_DB_HOST=db
33
- # - POSTFIXADMIN_DB_USER=postfix
34
- # - POSTFIXADMIN_DB_PASSWORD=password
35
- # - POSTFIXADMIN_DB_NAME=postfix
36
31
  db:
37
32
  image: mariadb:10
33
+ ports:
34
+ - "13306:3306"
38
35
  volumes:
39
- - ./docker-db/postfix.v1841.sql:/docker-entrypoint-initdb.d/postfix.sql
40
- # - ./docker-db/postfix.v740.sql:/docker-entrypoint-initdb.d/postfix.sql
41
- # - ./docker-db/postfix.v352.sql:/docker-entrypoint-initdb.d/postfix.sql
36
+ - db-data:/var/lib/mysql
37
+ - ./docker-db/postfix.v1841.sql:/docker-entrypoint-initdb.d/postfix.sql
38
+ # - ./docker-db/postfix.v740.sql:/docker-entrypoint-initdb.d/postfix.sql
39
+ # - ./docker-db/postfix.v352.sql:/docker-entrypoint-initdb.d/postfix.sql
42
40
  environment:
43
- - MYSQL_RANDOM_ROOT_PASSWORD=yes
41
+ - MYSQL_ROOT_PASSWORD=ScRgkaMz4YwHN5dyxfQj
44
42
  - MYSQL_USER=postfix
45
43
  - MYSQL_PASSWORD=password
46
44
  - MYSQL_DATABASE=postfix
45
+ volumes:
46
+ db-data: