line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::OpenMbox; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
71939
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
702
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
App::OpenMbox - The methods for email management used in OpenMbox.net |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.12 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Here are several methods used by Open Mbox, a free email provider. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use App::OpenMbox; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $om = App::OpenMbox->new(); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# test purpose by providing temp files |
29
|
|
|
|
|
|
|
$om->register('/tmp/dove.db','/tmp/user.temp'); |
30
|
|
|
|
|
|
|
$om->password('/tmp/dove.db','/tmp/pass.temp'); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Sample input from user.temp: |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
henry SomePassword111 |
35
|
|
|
|
|
|
|
hello SomePassword222 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Sample input from pass.temp: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
henry OldPassword111 NewPassword111 |
40
|
|
|
|
|
|
|
hello OldPassword222 NewPassword222 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
You may know that we don't have RDB in the system for email and user management. We do not record any information about users, nor track user's behavior. For registration, user submits his/her username and password to our system, these username/password are stored in a temp file. A perl program reads data from the file, and updates its content to Dovecot's user database, which is pure text DB for email users and encrypted passwords. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
To make this program work, you should have Postfix and Dovecot deployed at first. There are many documentation for how to deploy that a system. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 new() |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
New the instance. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
57
|
0
|
|
|
|
|
|
bless {},$class; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 register('/path/to/dove_userdb','/path/to/temp_userfile') |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Register users with username and password. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Web CGI writes username and password to a temp file, another perl script reads this file periodically, and updates its content to Dovecot user DB. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub register { |
70
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
my $dove_userdb = shift; |
72
|
0
|
|
|
|
|
|
my $temp_userfile = shift; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if (-f $temp_userfile) { |
75
|
0
|
|
|
|
|
|
my %hash; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
open my $fd,$temp_userfile or die $!; |
78
|
0
|
|
|
|
|
|
while(<$fd>) { |
79
|
0
|
|
|
|
|
|
chomp; |
80
|
0
|
|
|
|
|
|
my ($user,$pass) = split; |
81
|
0
|
|
|
|
|
|
$hash{$user} = $pass; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
close $fd; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
open my $fdw,">>",$dove_userdb or die $!; |
86
|
0
|
|
|
|
|
|
for my $key (keys %hash) { |
87
|
0
|
|
|
|
|
|
my $usr = $key . '@openmbox.net'; |
88
|
0
|
|
|
|
|
|
my $pwd = $hash{$key}; |
89
|
0
|
|
|
|
|
|
my $crypt = `/usr/bin/doveadm pw -p '$pwd'`; |
90
|
0
|
|
|
|
|
|
chomp $crypt; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
print $fdw $usr . ':' . $crypt, "\n"; |
93
|
|
|
|
|
|
|
} |
94
|
0
|
|
|
|
|
|
close $fdw; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
unlink $temp_userfile; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 password('/path/to/dove_userdb','/path/to/temp_passfile') |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Update passwords by providing username, old password and new password. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Web CGI writes username and old_password and new_password to a temp file, another perl script reads this file periodically, and updates its content to Dovecot user DB. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub password { |
110
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
111
|
0
|
|
|
|
|
|
my $dove_userdb = shift; |
112
|
0
|
|
|
|
|
|
my $temp_passfile = shift; |
113
|
0
|
|
|
|
|
|
my %hash; |
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
if (-f $temp_passfile) { |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
open my $fd,$temp_passfile or die $!; |
118
|
0
|
|
|
|
|
|
while(<$fd>) { |
119
|
0
|
|
|
|
|
|
chomp; |
120
|
0
|
|
|
|
|
|
my ($user,$oldpass,$newpass) = split; |
121
|
0
|
|
|
|
|
|
my $mbox = $user . '@openmbox.net'; |
122
|
0
|
|
|
|
|
|
my @res = `/usr/bin/doveadm auth test '$mbox' '$oldpass'`; |
123
|
0
|
0
|
|
|
|
|
if ($? == 0) { |
124
|
0
|
|
|
|
|
|
$hash{$mbox} = $newpass; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
close $fd; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
unlink $temp_passfile; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
if (%hash) { |
133
|
0
|
|
|
|
|
|
my @arr; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
open my $fd,$dove_userdb or die $!; |
136
|
0
|
|
|
|
|
|
while( my $line = <$fd>) { |
137
|
0
|
|
|
|
|
|
my ($u,$p) = split/\:/,$line; |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
if (exists $hash{$u}) { |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $pass = $hash{$u}; |
142
|
0
|
|
|
|
|
|
my $crypt = `/usr/bin/doveadm pw -p '$pass'`; |
143
|
0
|
|
|
|
|
|
chomp $crypt; |
144
|
0
|
|
|
|
|
|
push @arr, $u . ':' . $crypt, "\n"; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
} else { |
147
|
0
|
|
|
|
|
|
push @arr, $line; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
0
|
|
|
|
|
|
close $fd; |
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
|
open my $fdw,">",$dove_userdb or die $!; |
153
|
0
|
|
|
|
|
|
for (@arr) { |
154
|
0
|
|
|
|
|
|
print $fdw $_; |
155
|
|
|
|
|
|
|
} |
156
|
0
|
|
|
|
|
|
close $fdw; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 AUTHOR |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Henry R, C<< >> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 BUGS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
168
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
169
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SUPPORT |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
perldoc App::OpenMbox |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
You can also look for information at: |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=over 4 |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * CPAN Ratings |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
L |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * Search CPAN |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Henry R. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This is free software, licensed under: |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=cut |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
1; # End of App::OpenMbox |