forked from virtualmin/virtualmin-gpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoconfig.cgi
executable file
·104 lines (97 loc) · 2.31 KB
/
autoconfig.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl
# This script gets copied to each domain's CGI directory to output the
# correct SMTP and IMAP server details.
# For internal version checking
$AUTOCONFIG_VERSION = 1.0;
# These variables get replaced when the script is copied
$OWNER = ''; # Bob's website
$USER = ''; # bob
$SMTP_HOST = ''; # mail.bob.com
$SMTP_PORT = ''; # 25
$SMTP_TYPE = ''; # plain or SSL
$SMTP_SSL = ''; # yes or no
$SMTP_SSL2 = ''; # on or off
$SMTP_ENC = ''; # password-cleartext
$IMAP_HOST = ''; # mail.bob.com
$IMAP_PORT = ''; # 143
$IMAP_TYPE = ''; # plain or SSL
$IMAP_SSL = ''; # yes or no
$IMAP_ENC = ''; # password-cleartext or password-encrypted
$PREFIX = ''; # bob
$STYLE = ''; # 1
sub error_exit
{
print "Content-type: text/plain\n\n";
print @_,"\n";
exit(0);
}
# Get email address parameter
my $mode;
if ($ENV{'QUERY_STRING'} =~ /emailaddress=([^&]+)/i) {
# Thunderbird style
$email = $1;
$email =~ s/%(..)/pack("c",hex($1))/ge;
($mailbox, $SMTP_DOMAIN) = split(/\@/, $email);
$mailbox && $SMTP_DOMAIN ||
&error_exit("emailaddress parameter is not in user@domain format");
$mode = "thunderbird";
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Outlook style
read(STDIN, $buf, $ENV{'CONTENT_LENGTH'});
$buf =~ /<EMailAddress>([^@<>]+)@([^<>]+)<\/EMailAddress>/i ||
&error_exit("EMailAddress missing from input XML");
($mailbox, $SMTP_DOMAIN) = ($1, $2);
$email = $1."\@".$2;
$mode = "outlook";
}
else {
&error_exit("Missing emailaddress parameter");
}
# Work out the full username
if ($mailbox eq $USER) {
# Domain owner, so no need for prefix
$SMTP_LOGIN = $USER;
}
elsif ($STYLE == 0) {
$SMTP_LOGIN = $mailbox.".".$PREFIX;
}
elsif ($STYLE == 1) {
$SMTP_LOGIN = $mailbox."-".$PREFIX;
}
elsif ($STYLE == 2) {
$SMTP_LOGIN = $PREFIX.".".$mailbox;
}
elsif ($STYLE == 3) {
$SMTP_LOGIN = $PREFIX."-".$mailbox;
}
elsif ($STYLE == 4) {
$SMTP_LOGIN = $mailbox."_".$PREFIX;
}
elsif ($STYLE == 5) {
$SMTP_LOGIN = $PREFIX."_".$mailbox;
}
elsif ($STYLE == 6) {
$SMTP_LOGIN = $email;
}
elsif ($STYLE == 7) {
$SMTP_LOGIN = $mailbox."\%".$PREFIX;
}
else {
&error_exit("Unknown style $STYLE");
}
$MAILBOX = $mailbox;
# Output the XML
print "Content-type: text/xml\n\n";
if ($mode eq "outlook") {
# Outlook
print <<EOF;
_OUTLOOK_XML_GOES_HERE_
EOF
}
else {
# Thunderbird
print <<EOF;
_THUNDERBIRD_XML_GOES_HERE_
EOF
}