postfix_admin 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ module PostfixAdmin
2
+ class Quota < ApplicationRecord
3
+ self.table_name = :quota2
4
+ self.primary_key = :username
5
+ end
6
+ end
@@ -1,105 +1,211 @@
1
1
  require 'thor'
2
2
  require 'postfix_admin'
3
3
  require 'postfix_admin/cli'
4
+ require 'postfix_admin/doveadm'
4
5
 
5
6
  module PostfixAdmin
6
7
  class Runner < Thor
8
+ def self.exit_on_failure?
9
+ true
10
+ end
11
+
7
12
  def initialize(*args)
8
13
  super
9
14
  @cli = CLI.new
10
15
  end
11
16
 
12
17
  desc "summary [example.com]", "Summarize the usage of PostfixAdmin"
13
- def summary(domain_name=nil)
14
- runner{ @cli.show_summary(domain_name) }
18
+ def summary(domain_name = nil)
19
+ runner { @cli.show_summary(domain_name) }
15
20
  end
16
21
 
17
- desc "show [example.com]", "List of domains"
18
- def show(domain_name=nil)
19
- runner{ @cli.show(domain_name) }
22
+ desc "schemes", "List all supported password schemes"
23
+ def schemes
24
+ runner { puts PostfixAdmin::Doveadm.schemes.join(' ') }
20
25
  end
21
26
 
22
- desc "setup example.com password", "Setup a domain"
23
- def setup(domain_name, password)
24
- runner{ @cli.setup_domain(domain_name, password) }
27
+ desc "show [example.com | admin@example.com | user@example.com]", "Show domains or admins or mailboxes"
28
+ def show(name = nil)
29
+ runner { @cli.show(name) }
25
30
  end
26
31
 
27
- desc "super_admin admin@example.com", "Enable super admin flag of an admin"
28
- method_option :disable, :type => :boolean, :aliases => "-d", :desc => "Disable super admin flag"
29
- def super_admin(user_name)
30
- runner{ @cli.super_admin(user_name, options[:disable]) }
32
+ desc "setup example.com password", "Setup a domain"
33
+ def setup(domain_name, password)
34
+ runner { @cli.setup_domain(domain_name, password) }
31
35
  end
32
36
 
33
37
  desc "admin_passwd admin@example.com new_password", "Change password of admin"
34
38
  def admin_passwd(user_name, password)
35
- runner{ @cli.change_admin_password(user_name, password) }
39
+ runner { @cli.change_admin_password(user_name, password) }
36
40
  end
37
41
 
38
42
  desc "account_passwd user@example.com new_password", "Change password of account"
39
43
  def account_passwd(user_name, password)
40
- runner{ @cli.change_account_password(user_name, password) }
44
+ runner { @cli.change_account_password(user_name, password) }
41
45
  end
42
46
 
43
47
  desc "add_domain example.com", "Add a domain"
44
48
  def add_domain(domain_name)
45
- runner{ @cli.add_domain(domain_name) }
49
+ runner { @cli.add_domain(domain_name) }
50
+ end
51
+
52
+ desc "edit_domain example.com", "Edit a domain limitation"
53
+ method_option :aliases, type: :numeric, aliases: "-a", desc: "Edit aliases limitation"
54
+ method_option :mailboxes, type: :numeric, aliases: "-m", desc: "Edit mailboxes limitation"
55
+ method_option :maxquota, type: :numeric, aliases: "-q", desc: "Edit max quota limitation"
56
+ method_option :active, type: :boolean, desc: "Update active status"
57
+ def edit_domain(domain_name)
58
+ runner do
59
+ if options.size == 0
60
+ warn "Use one or more options."
61
+ help('edit_domain')
62
+ else
63
+ @cli.edit_domain(domain_name, options)
64
+ end
65
+ end
46
66
  end
47
67
 
48
68
  desc "delete_domain example.com", "Delete a domain"
49
69
  def delete_domain(domain_name)
50
- runner{ @cli.delete_domain(domain_name) }
70
+ runner { @cli.delete_domain(domain_name) }
51
71
  end
52
72
 
53
73
  desc "delete_admin admin@example.com", "Delete an admin"
54
74
  def delete_admin(user_name)
55
- runner{ @cli.delete_admin(user_name) }
75
+ runner { @cli.delete_admin(user_name) }
56
76
  end
57
77
 
58
78
  desc "delete_account user@example.com", "Delete an account"
59
79
  def delete_account(address)
60
- runner{ @cli.delete_account(address) }
80
+ runner { @cli.delete_account(address) }
61
81
  end
62
82
 
63
83
  desc "add_account user@example.com password", "Add an account"
84
+ method_option :scheme, type: :string, aliases: "-s", desc: "password scheme"
85
+ method_option :name, type: :string, aliases: "-n", desc: "full name"
64
86
  def add_account(address, password)
65
- runner{ @cli.add_account(address, password) }
87
+ runner do
88
+ if options[:scheme] == 'scheme'
89
+ warn "Specify password scheme"
90
+ help('add_account')
91
+ else
92
+ if options[:name] == 'name'
93
+ warn "Specify name"
94
+ help('add_account')
95
+ else
96
+ @cli.add_account(address, password, options[:scheme], options[:name])
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ desc "edit_account user@example.com", "Edit an account"
103
+ method_option :goto, type: :string, aliases: "-g", desc: "mailboxes, addresses e-mails are delivered to"
104
+ method_option :quota, type: :numeric, aliases: "-q", desc: "quota limitation (MB)"
105
+ method_option :name, type: :string, aliases: "-n", desc: "full name"
106
+ method_option :active, type: :boolean, desc: "Update active status"
107
+ def edit_account(address)
108
+ runner do
109
+ if options.size == 0
110
+ warn "Use one or more options."
111
+ help('edit_account')
112
+ else
113
+ if options[:name] == 'name'
114
+ warn "Specify name"
115
+ help('edit_account')
116
+ else
117
+ @cli.edit_account(address, options)
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ desc "edit_admin admin@example.com", "Edit an admin user"
124
+ method_option :active, type: :boolean, desc: "Update active status"
125
+ method_option :super, type: :boolean, desc: "Update super admin status"
126
+ def edit_admin(user_name)
127
+ runner do
128
+ if options.size == 0
129
+ warn "Use one or more options."
130
+ help('edit_admin')
131
+ else
132
+ @cli.edit_admin(user_name, options)
133
+ end
134
+ end
66
135
  end
67
136
 
68
137
  desc "add_admin admin@example.com password", "Add an admin user"
69
- method_option :super, :type => :boolean, :aliases => "-s", :desc => "register as a super admin"
138
+ method_option :super, type: :boolean, aliases: "-S", desc: "register as a super admin"
139
+ method_option :scheme, type: :string, aliases: "-s", desc: "password scheme"
70
140
  def add_admin(user_name, password)
71
- runner{ @cli.add_admin(user_name, password, options[:super]) }
141
+ runner do
142
+ if options[:scheme] == 'scheme'
143
+ warn "Specify password scheme"
144
+ help('add_admin')
145
+ else
146
+ @cli.add_admin(user_name, password, options[:super], options[:scheme])
147
+ end
148
+ end
72
149
  end
73
150
 
74
151
  desc "add_admin_domain admin@example.com example.com", "Add admin_domain"
75
152
  def add_admin_domain(user_name, domain_name)
76
- runner{ @cli.add_admin_domain(user_name, domain_name) }
153
+ runner { @cli.add_admin_domain(user_name, domain_name) }
154
+ end
155
+
156
+ desc "delete_admin_domain admin@example.com example.com", "Delete admin_domain"
157
+ def delete_admin_domain(user_name, domain_name)
158
+ runner { @cli.delete_admin_domain(user_name, domain_name) }
159
+ end
160
+
161
+ desc "edit_alias alias@example.com", "Edit an alias"
162
+ method_option :goto, type: :string, aliases: "-g",
163
+ desc: "mailboxes, addresses e-mails are delivered to"
164
+ method_option :active, type: :boolean, desc: "Update active status"
165
+ def edit_alias(address)
166
+ runner do
167
+ if options.size == 0
168
+ warn "Use one or more options."
169
+ help('edit_alias')
170
+ else
171
+ @cli.edit_alias(address, options)
172
+ end
173
+ end
77
174
  end
78
175
 
79
176
  desc "add_alias alias@example.com goto@example.net", "Add an alias"
80
177
  def add_alias(address, goto)
81
- runner{ @cli.add_alias(address, goto) }
178
+ runner { @cli.add_alias(address, goto) }
82
179
  end
83
180
 
84
181
  desc "delete_alias alias@example.com", "Delete an alias"
85
182
  def delete_alias(address)
86
- runner{ @cli.delete_alias(address) }
183
+ runner { @cli.delete_alias(address) }
184
+ end
185
+
186
+ desc "log", "Show action logs"
187
+ def log
188
+ runner { @cli.log }
189
+ end
190
+
191
+ desc "dump", "Dump all data"
192
+ def dump
193
+ runner { @cli.dump }
87
194
  end
88
195
 
89
196
  desc "version", "Show postfix_admin version"
90
197
  def version
91
198
  require 'postfix_admin/version'
92
- say "postfix_admin #{VERSION}"
199
+ runner { say "postfix_admin #{VERSION}" }
93
200
  end
94
201
 
95
202
  private
96
203
 
97
204
  def runner
98
- begin
99
- yield
100
- rescue => e
101
- warn e.message
102
- end
205
+ @cli.db_setup
206
+ yield
207
+ rescue StandardError => e
208
+ abort "Error: #{e.message}"
103
209
  end
104
210
  end
105
211
  end
@@ -1,3 +1,3 @@
1
1
  module PostfixAdmin
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,22 +1,31 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require File.expand_path('../lib/postfix_admin/version', __FILE__)
3
2
 
4
3
  Gem::Specification.new do |gem|
5
- gem.add_dependency 'thor'
6
- gem.add_dependency 'data_mapper'
7
- gem.add_dependency 'dm-mysql-adapter'
8
- gem.add_development_dependency 'dm-sqlite-adapter'
9
-
4
+ gem.name = "postfix_admin"
5
+ gem.version = PostfixAdmin::VERSION
10
6
  gem.authors = ["Hitoshi Kurokawa"]
11
7
  gem.email = ["hitoshi@nextseed.jp"]
12
- gem.description = %q{Command Line Tools of PostfixAdmin}
8
+
13
9
  gem.summary = gem.description
10
+ gem.description = %q{Command Line Tools for Postfix Admin}
14
11
  gem.homepage = "https://github.com/krhitoshi/postfix_admin"
15
12
 
16
- gem.files = `git ls-files`.split($\)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.add_dependency 'thor', '~> 1.0.1'
14
+ gem.add_dependency 'activerecord', '~> 6.0.3'
15
+ gem.add_dependency 'mysql2', '>= 0.5.3'
16
+ gem.add_development_dependency 'pry'
17
+ gem.add_development_dependency 'rake', '~> 13.0.1'
18
+ gem.add_development_dependency 'rubocop'
19
+ gem.add_development_dependency 'rspec', '~> 3.9.0'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ gem.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ gem.bindir = "exe"
27
+ gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
28
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.name = "postfix_admin"
29
+
20
30
  gem.require_paths = ["lib"]
21
- gem.version = PostfixAdmin::VERSION
22
31
  end
metadata CHANGED
@@ -1,81 +1,114 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postfix_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Hitoshi Kurokawa
9
8
  autorequire:
10
- bindir: bin
9
+ bindir: exe
11
10
  cert_chain: []
12
- date: 2012-10-07 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: thor
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 1.0.1
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: 1.0.1
30
27
  - !ruby/object:Gem::Dependency
31
- name: data_mapper
28
+ name: activerecord
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: 6.0.3
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: 6.0.3
46
41
  - !ruby/object:Gem::Dependency
47
- name: dm-mysql-adapter
42
+ name: mysql2
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: '0'
47
+ version: 0.5.3
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  - !ruby/object:Gem::Dependency
63
- name: dm-sqlite-adapter
70
+ name: rake
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
- - - ! '>='
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 13.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 13.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
68
88
  - !ruby/object:Gem::Version
69
89
  version: '0'
70
90
  type: :development
71
91
  prerelease: false
72
92
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
93
  requirements:
75
- - - ! '>='
94
+ - - ">="
76
95
  - !ruby/object:Gem::Version
77
96
  version: '0'
78
- description: Command Line Tools of PostfixAdmin
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.9.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.9.0
111
+ description: Command Line Tools for Postfix Admin
79
112
  email:
80
113
  - hitoshi@nextseed.jp
81
114
  executables:
@@ -83,56 +116,60 @@ executables:
83
116
  extensions: []
84
117
  extra_rdoc_files: []
85
118
  files:
86
- - .gitignore
119
+ - ".gitignore"
120
+ - ".rubocop.yml"
121
+ - CHANGELOG.md
122
+ - Dockerfile
87
123
  - Gemfile
88
124
  - LICENSE
89
125
  - README.md
126
+ - Rakefile
90
127
  - Thorfile
91
- - bin/postfix_admin
128
+ - bin/console
129
+ - docker-compose.yml
130
+ - docker-entrypoint.sh
131
+ - exe/postfix_admin
92
132
  - lib/postfix_admin.rb
133
+ - lib/postfix_admin/admin.rb
134
+ - lib/postfix_admin/alias.rb
135
+ - lib/postfix_admin/application_record.rb
93
136
  - lib/postfix_admin/base.rb
94
137
  - lib/postfix_admin/cli.rb
138
+ - lib/postfix_admin/concerns/.keep
139
+ - lib/postfix_admin/concerns/dovecot_cram_md5_password.rb
140
+ - lib/postfix_admin/concerns/existing_timestamp.rb
141
+ - lib/postfix_admin/domain.rb
142
+ - lib/postfix_admin/domain_admin.rb
143
+ - lib/postfix_admin/doveadm.rb
95
144
  - lib/postfix_admin/error.rb
145
+ - lib/postfix_admin/log.rb
146
+ - lib/postfix_admin/mail_domain.rb
147
+ - lib/postfix_admin/mailbox.rb
96
148
  - lib/postfix_admin/models.rb
149
+ - lib/postfix_admin/quota.rb
97
150
  - lib/postfix_admin/runner.rb
98
151
  - lib/postfix_admin/version.rb
99
152
  - postfix_admin.gemspec
100
- - spec/base_spec.rb
101
- - spec/cli_spec.rb
102
- - spec/models_spec.rb
103
- - spec/postfix_admin.conf
104
- - spec/postfix_test.sql
105
- - spec/runner_spec.rb
106
- - spec/spec_helper.rb
107
153
  homepage: https://github.com/krhitoshi/postfix_admin
108
154
  licenses: []
155
+ metadata: {}
109
156
  post_install_message:
110
157
  rdoc_options: []
111
158
  require_paths:
112
159
  - lib
113
160
  required_ruby_version: !ruby/object:Gem::Requirement
114
- none: false
115
161
  requirements:
116
- - - ! '>='
162
+ - - ">="
117
163
  - !ruby/object:Gem::Version
118
164
  version: '0'
119
165
  required_rubygems_version: !ruby/object:Gem::Requirement
120
- none: false
121
166
  requirements:
122
- - - ! '>='
167
+ - - ">="
123
168
  - !ruby/object:Gem::Version
124
169
  version: '0'
125
170
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 1.8.24
171
+ rubygems_version: 3.0.3
128
172
  signing_key:
129
- specification_version: 3
130
- summary: Command Line Tools of PostfixAdmin
131
- test_files:
132
- - spec/base_spec.rb
133
- - spec/cli_spec.rb
134
- - spec/models_spec.rb
135
- - spec/postfix_admin.conf
136
- - spec/postfix_test.sql
137
- - spec/runner_spec.rb
138
- - spec/spec_helper.rb
173
+ specification_version: 4
174
+ summary: ''
175
+ test_files: []