1 |
#!/usr/bin/perl -w |
2 |
|
3 |
# perl script to add users to Document Manager's .htusers file |
4 |
|
5 |
use Digest::MD5 qw(md5_hex); |
6 |
|
7 |
my $htpasswd = shift @ARGV || ".htusers"; |
8 |
|
9 |
my $login = shift @ARGV; |
10 |
if (! $login) { |
11 |
print "login: "; |
12 |
$login=<STDIN>; chomp $login; |
13 |
} |
14 |
|
15 |
my $fullname = shift @ARGV; |
16 |
if (! $fullname) { |
17 |
print "full name: "; |
18 |
$fullname=<STDIN>; chomp $fullname; |
19 |
} |
20 |
|
21 |
my $passswd = shift @ARGV; |
22 |
if (! $passswd) { |
23 |
print "password [auth_pop3]: "; |
24 |
$passwd=<STDIN>; chomp $passwd; |
25 |
if ($passwd eq "") { |
26 |
$passwd="auth_pop3"; |
27 |
} elsif (substr($passwd,0,5) ne "auth_") { |
28 |
$passwd=md5_hex($login.$passwd); |
29 |
} |
30 |
} |
31 |
|
32 |
my $email = shift @ARGV; |
33 |
while (! $email || $email !~ /@/) { |
34 |
print "e-mail: "; |
35 |
$email=<STDIN>; chomp $email; |
36 |
print "e-mail address needs to have @ for auth_pop3 to work!\n" if ($email !~ /@/); |
37 |
} |
38 |
|
39 |
if (! -e "$htpasswd") { |
40 |
print "creating $htpasswd\n"; |
41 |
open(HTPASSWD,"> $htpasswd") || die "open $htpasswd: $!"; |
42 |
} else { |
43 |
open(HTPASSWD,">> $htpasswd") || die "append $htpasswd: $!"; |
44 |
} |
45 |
print HTPASSWD "$login:$fullname:$passwd:$email\n"; |
46 |
close(HTPASSWD); |