postfix_admin 0.1.0 → 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.
@@ -1,5 +0,0 @@
1
- ---
2
- database: 'sqlite::memory:'
3
- aliases: 30
4
- mailboxes: 30
5
- maxquota: 100
@@ -1,250 +0,0 @@
1
- -- phpMyAdmin SQL Dump
2
- -- version 3.4.7
3
- -- http://www.phpmyadmin.net
4
- --
5
- -- ホスト: localhost
6
- -- 生成時間: 2012 年 9 月 25 日 23:12
7
- -- サーバのバージョン: 5.5.15
8
- -- PHP のバージョン: 5.3.15
9
-
10
- SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
11
- SET time_zone = "+00:00";
12
-
13
-
14
- /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
15
- /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
16
- /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
17
- /*!40101 SET NAMES utf8 */;
18
-
19
- --
20
- -- データベース: `postfix_test`
21
- --
22
-
23
- -- --------------------------------------------------------
24
-
25
- --
26
- -- テーブルの構造 `admin`
27
- --
28
-
29
- CREATE TABLE IF NOT EXISTS `admin` (
30
- `username` varchar(255) NOT NULL DEFAULT '',
31
- `password` varchar(255) NOT NULL DEFAULT '',
32
- `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
33
- `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
34
- `active` tinyint(1) NOT NULL DEFAULT '1',
35
- PRIMARY KEY (`username`)
36
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Admins';
37
-
38
- --
39
- -- テーブルのデータをダンプしています `admin`
40
- --
41
-
42
- INSERT INTO `admin` (`username`, `password`, `created`, `modified`, `active`) VALUES
43
- ('all@example.com', 'password', '2012-08-31 15:39:02', '2012-08-31 15:39:19', 1),
44
- ('admin@example.com', 'password', '2012-08-31 10:27:58', '2012-08-31 10:28:16', 1);
45
-
46
- -- --------------------------------------------------------
47
-
48
- --
49
- -- テーブルの構造 `alias`
50
- --
51
-
52
- CREATE TABLE IF NOT EXISTS `alias` (
53
- `address` varchar(255) NOT NULL DEFAULT '',
54
- `goto` text NOT NULL,
55
- `domain` varchar(255) NOT NULL DEFAULT '',
56
- `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
57
- `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
58
- `active` tinyint(1) NOT NULL DEFAULT '1',
59
- PRIMARY KEY (`address`)
60
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Aliases';
61
-
62
- --
63
- -- テーブルのデータをダンプしています `alias`
64
- --
65
-
66
- INSERT INTO `alias` (`address`, `goto`, `domain`, `created`, `modified`, `active`) VALUES
67
- ('user@example.com', 'user@example.com', 'example.com', '2012-08-31 10:24:12', '2012-08-31 10:24:12', 1);
68
-
69
- -- --------------------------------------------------------
70
-
71
- --
72
- -- テーブルの構造 `config`
73
- --
74
-
75
- CREATE TABLE IF NOT EXISTS `config` (
76
- `id` int(11) NOT NULL AUTO_INCREMENT,
77
- `name` varchar(20) CHARACTER SET latin1 NOT NULL DEFAULT '',
78
- `value` varchar(20) CHARACTER SET latin1 NOT NULL DEFAULT '',
79
- PRIMARY KEY (`id`),
80
- UNIQUE KEY `name` (`name`)
81
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='PostfixAdmin settings' AUTO_INCREMENT=2 ;
82
-
83
- --
84
- -- テーブルのデータをダンプしています `config`
85
- --
86
-
87
- INSERT INTO `config` (`id`, `name`, `value`) VALUES
88
- (1, 'version', '352');
89
-
90
- -- --------------------------------------------------------
91
-
92
- --
93
- -- テーブルの構造 `domain`
94
- --
95
-
96
- CREATE TABLE IF NOT EXISTS `domain` (
97
- `domain` varchar(255) NOT NULL DEFAULT '',
98
- `description` varchar(255) NOT NULL DEFAULT '',
99
- `aliases` int(10) NOT NULL DEFAULT '0',
100
- `mailboxes` int(10) NOT NULL DEFAULT '0',
101
- `maxquota` bigint(20) NOT NULL DEFAULT '0',
102
- `quota` bigint(20) NOT NULL DEFAULT '0',
103
- `transport` varchar(255) DEFAULT NULL,
104
- `backupmx` tinyint(1) NOT NULL DEFAULT '0',
105
- `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
106
- `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
107
- `active` tinyint(1) NOT NULL DEFAULT '1',
108
- PRIMARY KEY (`domain`)
109
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Domains';
110
-
111
- --
112
- -- テーブルのデータをダンプしています `domain`
113
- --
114
-
115
- INSERT INTO `domain` (`domain`, `description`, `aliases`, `mailboxes`, `maxquota`, `quota`, `transport`, `backupmx`, `created`, `modified`, `active`) VALUES
116
- ('ALL', '', 0, 0, 0, 0, NULL, 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1),
117
- ('example.com', '', 100, 100, 100, 0, 'virtual', 0, '2012-08-31 10:21:49', '2012-08-31 10:21:49', 1);
118
-
119
- -- --------------------------------------------------------
120
-
121
- --
122
- -- テーブルの構造 `domain_admins`
123
- --
124
-
125
- CREATE TABLE IF NOT EXISTS `domain_admins` (
126
- `username` varchar(255) NOT NULL DEFAULT '',
127
- `domain` varchar(255) NOT NULL DEFAULT '',
128
- `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
129
- `active` tinyint(1) NOT NULL DEFAULT '1',
130
- KEY `username` (`username`)
131
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Domain Admins';
132
-
133
- --
134
- -- テーブルのデータをダンプしています `domain_admins`
135
- --
136
-
137
- INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`) VALUES
138
- ('all@example.com', 'ALL', '2012-08-31 15:39:19', 1),
139
- ('admin@example.com', 'example.com', '2012-08-31 10:28:16', 1);
140
-
141
- -- --------------------------------------------------------
142
-
143
- --
144
- -- テーブルの構造 `fetchmail`
145
- --
146
-
147
- CREATE TABLE IF NOT EXISTS `fetchmail` (
148
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
149
- `mailbox` varchar(255) NOT NULL DEFAULT '',
150
- `src_server` varchar(255) NOT NULL DEFAULT '',
151
- `src_auth` enum('password','kerberos_v5','kerberos','kerberos_v4','gssapi','cram-md5','otp','ntlm','msn','ssh','any') DEFAULT NULL,
152
- `src_user` varchar(255) NOT NULL DEFAULT '',
153
- `src_password` varchar(255) NOT NULL DEFAULT '',
154
- `src_folder` varchar(255) NOT NULL DEFAULT '',
155
- `poll_time` int(11) unsigned NOT NULL DEFAULT '10',
156
- `fetchall` tinyint(1) unsigned NOT NULL DEFAULT '0',
157
- `keep` tinyint(1) unsigned NOT NULL DEFAULT '0',
158
- `protocol` enum('POP3','IMAP','POP2','ETRN','AUTO') DEFAULT NULL,
159
- `extra_options` text,
160
- `returned_text` text,
161
- `mda` varchar(255) NOT NULL DEFAULT '',
162
- `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
163
- PRIMARY KEY (`id`)
164
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
165
-
166
- -- --------------------------------------------------------
167
-
168
- --
169
- -- テーブルの構造 `log`
170
- --
171
-
172
- CREATE TABLE IF NOT EXISTS `log` (
173
- `timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
174
- `username` varchar(255) NOT NULL DEFAULT '',
175
- `domain` varchar(255) NOT NULL DEFAULT '',
176
- `action` varchar(255) NOT NULL DEFAULT '',
177
- `data` varchar(255) NOT NULL DEFAULT '',
178
- KEY `timestamp` (`timestamp`)
179
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Log';
180
-
181
- -- --------------------------------------------------------
182
-
183
- --
184
- -- テーブルの構造 `mailbox`
185
- --
186
-
187
- CREATE TABLE IF NOT EXISTS `mailbox` (
188
- `username` varchar(255) NOT NULL DEFAULT '',
189
- `password` varchar(255) NOT NULL DEFAULT '',
190
- `name` varchar(255) NOT NULL DEFAULT '',
191
- `maildir` varchar(255) NOT NULL DEFAULT '',
192
- `quota` bigint(20) NOT NULL DEFAULT '0',
193
- `domain` varchar(255) NOT NULL DEFAULT '',
194
- `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
195
- `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
196
- `active` tinyint(1) NOT NULL DEFAULT '1',
197
- PRIMARY KEY (`username`)
198
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Mailboxes';
199
-
200
- --
201
- -- テーブルのデータをダンプしています `mailbox`
202
- --
203
-
204
- INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `domain`, `created`, `modified`, `active`) VALUES
205
- ('user@example.com', 'password', '', 'example.com/user@example.com/', 102400000, 'example.com', '2012-08-31 10:24:12', '2012-08-31 10:24:12', 1);
206
-
207
- -- --------------------------------------------------------
208
-
209
- --
210
- -- テーブルの構造 `vacation`
211
- --
212
-
213
- CREATE TABLE IF NOT EXISTS `vacation` (
214
- `email` varchar(255) NOT NULL,
215
- `subject` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
216
- `body` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
217
- `cache` text NOT NULL,
218
- `domain` varchar(255) NOT NULL,
219
- `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
220
- `active` tinyint(1) NOT NULL DEFAULT '1',
221
- PRIMARY KEY (`email`),
222
- KEY `email` (`email`)
223
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Vacation';
224
-
225
- -- --------------------------------------------------------
226
-
227
- --
228
- -- テーブルの構造 `vacation_notification`
229
- --
230
-
231
- CREATE TABLE IF NOT EXISTS `vacation_notification` (
232
- `on_vacation` varchar(255) NOT NULL,
233
- `notified` varchar(255) NOT NULL,
234
- `notified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
235
- PRIMARY KEY (`on_vacation`,`notified`)
236
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Vacation Notifications';
237
-
238
- --
239
- -- ダンプしたテーブルの制約
240
- --
241
-
242
- --
243
- -- テーブルの制約 `vacation_notification`
244
- --
245
- ALTER TABLE `vacation_notification`
246
- ADD CONSTRAINT `vacation_notification_pkey` FOREIGN KEY (`on_vacation`) REFERENCES `vacation` (`email`) ON DELETE CASCADE;
247
-
248
- /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
249
- /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
250
- /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
@@ -1,144 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
- require 'postfix_admin/runner'
3
-
4
- describe PostfixAdmin::Runner do
5
- before do
6
- db_initialize
7
- end
8
-
9
- it "version" do
10
- capture(:stdout){ Runner.start(["version"]) }.should =~ /postfix_admin \d+\.\d+\.\d/
11
- end
12
-
13
- it "summary" do
14
- capture(:stdout){ Runner.start(["summary"]) }.should =~ /\[Summary\]/
15
- capture(:stdout){ Runner.start(["summary", "example.com"]) }.should =~ /\[Summary of example.com\]/
16
- end
17
-
18
- describe "show" do
19
- it "shows information of example.com" do
20
- capture(:stdout){ Runner.start(["show"]) }.should =~ /example.com\s+1\s+\/\s+30\s+1\s+\/\s+30\s+100/
21
- end
22
-
23
- it "shows information of admin@example.com" do
24
- capture(:stdout){ Runner.start(["show"]) }.should =~ /admin@example.com\s+1\s+password/
25
- end
26
-
27
- it "show the detail of example.com" do
28
- capture(:stdout){ Runner.start(["show", "example.com"]) }.should =~ /user@example.com\s+100.0\s+password/
29
- end
30
-
31
- it "when no admins, no aliases and no addresses" do
32
- Admin.find('all@example.com').super_admin = false
33
- out = capture(:stdout){ Runner.start(["show", "example.org"]) }
34
- out.should =~ /No admins/
35
- out.should =~ /No addresses/
36
- out.should =~ /No aliases/
37
- end
38
-
39
- it "when no domains" do
40
- capture(:stdout){ Runner.start(['delete_domain', 'example.com']) }.should =~ EX_DELETED
41
- capture(:stdout){ Runner.start(['delete_domain', 'example.org']) }.should =~ EX_DELETED
42
- capture(:stdout){ Runner.start(["show"]) }.should =~ /No domains/
43
- end
44
- end
45
-
46
- it "setup" do
47
- capture(:stdout){ Runner.start(['setup', 'example.net', 'password']) }.should =~ EX_REGISTERED
48
- capture(:stdout){ Runner.start(['delete_domain', 'example.net']) }.should =~ EX_DELETED
49
- end
50
-
51
- describe "super_admin" do
52
- it "can enable super admin flag of an admin" do
53
- capture(:stdout){ Runner.start(['super', 'admin@example.com']) }.should =~ /Successfully enabled/
54
- end
55
-
56
- it "can disable super admin flag of an admin (--disable)" do
57
- capture(:stdout){ Runner.start(['super', 'admin@example.com', '--disable']) }.should =~ /Successfully disabled/
58
- end
59
-
60
- it "can use -d option as --disable" do
61
- capture(:stdout){ Runner.start(['super', 'admin@example.com', '-d']) }.should =~ /Successfully disabled/
62
- end
63
- end
64
-
65
- describe "admin_passwd" do
66
- it "can change password of an admin" do
67
- capture(:stdout){ Runner.start(['admin_passwd', 'admin@example.com', 'new_password']) }.should =~ /successfully changed/
68
- end
69
-
70
- it "can not use too short password (< 5)" do
71
- capture(:stderr){ Runner.start(['admin_passwd', 'admin@example.com', '124']) }.should =~ /too short/
72
- end
73
-
74
- it "can not use for unknown admin" do
75
- capture(:stderr){ Runner.start(['admin_passwd', 'unknown@example.com', 'new_password']) }.should =~ /Could not find/
76
- end
77
- end
78
-
79
- describe "account_passwd" do
80
- it "can change password of an account" do
81
- capture(:stdout){ Runner.start(['account_passwd', 'user@example.com', 'new_password']) }.should =~ /successfully changed/
82
- end
83
-
84
- it "can not use too short password (< 5)" do
85
- capture(:stderr){ Runner.start(['account_passwd', 'user@example.com', '1234']) }.should =~ /too short/
86
- end
87
-
88
- it "can not use for unknown account" do
89
- capture(:stderr){ Runner.start(['account_passwd', 'unknown@example.com', 'new_password']) }.should =~ /Could not find/
90
- end
91
- end
92
-
93
- describe "add_alias and delete_alias" do
94
- it "can add and delete an new alias." do
95
- capture(:stdout){ Runner.start(['add_alias', 'new_alias@example.com', 'goto@example.jp']) }.should =~ EX_REGISTERED
96
- capture(:stdout){ Runner.start(['delete_alias', 'new_alias@example.com']) }.should =~ EX_DELETED
97
- end
98
-
99
- it "can not delete mailbox alias." do
100
- capture(:stderr){ Runner.start(['delete_alias', 'user@example.com']) }.should =~ /Can not delete mailbox/
101
- end
102
-
103
- it "can not add an alias for existed mailbox" do
104
- capture(:stderr){ Runner.start(['add_alias', 'user@example.com', 'goto@example.jp']) }.should =~ /mailbox user@example.com is already registered!/
105
- end
106
- end
107
-
108
- describe "add_admin" do
109
- it "can add an new admin" do
110
- capture(:stdout){ Runner.start(['add_admin', 'admin@example.jp', 'password']) }.should =~ EX_REGISTERED
111
- end
112
-
113
- it "--super option" do
114
- capture(:stdout){ Runner.start(['add_admin', 'admin@example.jp', 'password', '--super']) }.should =~ /registered as a super admin/
115
- end
116
-
117
- it "-s (--super) option" do
118
- capture(:stdout){ Runner.start(['add_admin', 'admin@example.jp', 'password', '-s']) }.should =~ /registered as a super admin/
119
- end
120
- end
121
-
122
- it "add_admin_domain" do
123
- capture(:stdout){ Runner.start(['add_admin_domain', 'admin@example.com', 'example.org']) }.should =~ EX_REGISTERED
124
- end
125
-
126
- it "delete_admin" do
127
- capture(:stdout){ Runner.start(['delete_admin', 'admin@example.com']) }.should =~ EX_DELETED
128
- end
129
-
130
- it "add_account and delete_account" do
131
- capture(:stdout){ Runner.start(['add_account', 'user2@example.com', 'password']) }.should =~ EX_REGISTERED
132
- capture(:stdout){ Runner.start(['delete_account', 'user2@example.com']) }.should =~ EX_DELETED
133
- end
134
-
135
- it "add and delete methods" do
136
- lambda { Runner.start(['add_domain', 'example.net']) }.should_not raise_error
137
- Runner.start(['add_admin', 'admin@example.net', 'password'])
138
- Runner.start(['add_admin_domain', 'admin@example.net', 'example.net'])
139
-
140
- lambda { Runner.start(['add_account', 'user1@example.net', 'password']) }.should_not raise_error
141
- lambda { Runner.start(['add_account', 'user2@example.net', 'password']) }.should_not raise_error
142
- lambda { Runner.start(['delete_domain', 'example.net']) }.should_not raise_error
143
- end
144
- end
@@ -1,160 +0,0 @@
1
-
2
- $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- require 'postfix_admin'
5
-
6
- module PostfixAdmin
7
- class CLI
8
- def config_file
9
- File.join(File.dirname(__FILE__) , 'postfix_admin.conf')
10
- end
11
- end
12
- end
13
-
14
- include PostfixAdmin
15
-
16
- # [fixtures]
17
- # Domain:
18
- # ALL
19
- # example.com
20
- # example.org
21
- #
22
- # Admin:
23
- # all@example.com Super Admin
24
- # admin@example.com
25
- #
26
- # Mailbox, Alias:
27
- # user@example.com
28
- #
29
- # Alias:
30
- # alias@example.com
31
-
32
- def db_clear
33
- DomainAdmin.all.destroy
34
- Mailbox.all.destroy
35
- Alias.all.destroy
36
- Domain.all.destroy
37
- Admin.all.destroy
38
- end
39
-
40
- def create_domain(domain_name)
41
- domain = Domain.new
42
- domain.attributes = {
43
- :domain_name => domain_name,
44
- :description => domain_name,
45
- :maxaliases => 30,
46
- :maxmailboxes => 30,
47
- :maxquota => 100,
48
- }
49
- domain.save
50
- end
51
-
52
- def db_initialize
53
- db_clear
54
-
55
- create_domain('ALL')
56
- create_domain('example.com')
57
- create_domain('example.org')
58
-
59
- username = "admin@example.com"
60
- admin = Admin.new
61
- admin.attributes = {
62
- :username => username,
63
- :password => 'password',
64
- }
65
- admin.save
66
-
67
- domain = Domain.find('example.com')
68
- domain.admins << admin
69
- domain.save
70
-
71
- all_admin = Admin.new
72
- all_admin.attributes = {
73
- :username => 'all@example.com',
74
- :password => 'password',
75
- }
76
- all_admin.save
77
-
78
- all_domain = Domain.find('ALL')
79
- all_domain.admins << all_admin
80
- all_domain.save
81
-
82
- address = "user@example.com"
83
- mail_alias = Alias.new
84
- mail_alias.attributes = {
85
- :address => address,
86
- :goto => address,
87
- }
88
- domain.aliases << mail_alias
89
-
90
- forward = Alias.new
91
- forward.attributes = {
92
- :address => 'alias@example.com',
93
- :goto => 'example.jp',
94
- }
95
- domain.aliases << forward
96
-
97
- domain.save
98
-
99
- path = "example.com/user@example.com/"
100
- mailbox = Mailbox.new
101
- mailbox.attributes = {
102
- :username => address,
103
- :password => 'password',
104
- :name => '',
105
- :maildir => path,
106
- :quota => 100 * 1024 * 1000,
107
- # :local_part => user,
108
- }
109
- domain.mailboxes << mailbox
110
- domain.save
111
- end
112
-
113
- DataMapper.setup(:default, 'sqlite::memory:')
114
- DataMapper.finalize
115
- DataMapper.auto_migrate!
116
- db_initialize
117
-
118
- module PostfixAdmin
119
- class Base
120
-
121
- # without DataMapper setup
122
- def db_setup(database)
123
- unless database
124
- raise ArgumentError
125
- end
126
- end
127
- end
128
- end
129
-
130
- EX_DELETED = /successfully deleted/
131
- EX_REGISTERED = /successfully registered/
132
-
133
- RSpec.configure do |config|
134
- config.before do
135
- ARGV.replace []
136
- end
137
-
138
- def capture(stream)
139
- begin
140
- stream = stream.to_s
141
- eval "$#{stream} = StringIO.new"
142
- yield
143
- result = eval("$#{stream}").string
144
- ensure
145
- eval("$#{stream} = #{stream.upcase}")
146
- end
147
-
148
- result
149
- end
150
-
151
- def source_root
152
- File.join(File.dirname(__FILE__), 'fixtures')
153
- end
154
-
155
- def destination_root
156
- File.join(File.dirname(__FILE__), 'sandbox')
157
- end
158
-
159
- alias :silence :capture
160
- end