forked from mkay/Exim4UI_mk1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsiteaddsubmit.php
More file actions
191 lines (182 loc) · 7.24 KB
/
siteaddsubmit.php
File metadata and controls
191 lines (182 loc) · 7.24 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
include_once dirname(__FILE__) . "/config/variables.php";
include_once dirname(__FILE__) . "/config/authsite.php";
include_once dirname(__FILE__) . "/config/functions.php";
include_once dirname(__FILE__) . "/config/httpheaders.php";
if (isset($_POST['spamassassin'])) {
$_POST['spamassassin'] = 1;
} else {
$_POST['spamassassin'] = 0;
}
if (isset($_POST['enabled'])) {
$_POST['enabled'] = 1;
} else {
$_POST['enabled'] = 0;
}
if (isset($_POST['pipe'])) {
$_POST['pipe'] = 1;
} else {
$_POST['pipe'] = 0;
}
if ($_POST['type'] == "relay") {
$_POST['clear'] = $_POST['vclear'] = "BLANK";
}
if ($_POST['type'] == "alias") {
$_POST['clear'] = $_POST['vclear'] = "BLANK";
}
if ($_POST['max_accounts'] == '') {
$_POST['max_accounts'] = '0';
}
// User can specify either UID, or username, the former being preferred.
// Using posix_getpwuid/posix_getgrgid even when we have an UID is so we
// are sure the UID exists.
if (isset ($_POST['uid'])) {
$uid = $_POST['uid'];
}
if (isset ($_POST['gid'])) {
$gid = $_POST['gid'];
}
if ($userinfo = @posix_getpwuid ($uid)) {
$uid = $userinfo['uid'];
} elseif ($userinfo = @posix_getpwnam ($uid)) {
$uid = $userinfo['uid'];
} else {
header ("Location: site.php?failuidguid={$_POST['domain']}");
die;
}
if ($groupinfo = @posix_getgrgid ($gid)) {
$gid = $groupinfo['gid'];
} elseif ($groupinfo = @posix_getgrnam ($gid)) {
$gid = $groupinfo['gid'];
} else {
header ("Location: site.php?failuidguid={$_POST['domain']}");
die;
}
$smtphomepath = realpath($_POST['maildir'] . "/") .
"/" . $_POST['domain'] . "/" . $_POST['localpart'] . "/Maildir";
$pophomepath = realpath($_POST['maildir'] . "/") .
"/" . $_POST['domain'] . "/" . $_POST['localpart'];
//Gah. Transactions!! -- GCBirzan
if ((validate_password($_POST['clear'], $_POST['vclear'])) &&
($_POST['type'] != "alias")) {
if ($multi_ip == "yes") {
$query = "INSERT INTO domains
(domain, spamassassin, sa_tag, sa_refuse,
max_accounts, quotas, maildir, pipe, enabled, uid, gid,
type, relay_address, outgoing_ip, maxmsgsize)
VALUES ('" . $_POST['domain'] . "'," .
"'{$_POST['spamassassin']}','".
((isset($_POST['sa_tag'])) ? $_POST['sa_tag'] : 0) . "','" .
((isset($_POST['sa_refuse'])) ? $_POST['sa_refuse'] : 0) . "','" .
"{$_POST['max_accounts']}','".
((isset($_POST['quotas'])) ? $_POST['quotas'] : 0) . "','" .
realpath ($_POST['maildir'] . "/") . "/" . $_POST['domain'] ."','" .
"{$_POST['pipe']}','" .
"{$_POST['enabled']}'," .
"'$uid'," .
"'$gid'," .
"'{$_POST['type']}',".
"'{$_POST['relaydest']}',".
"'{$_POST['outgoingip']}','".
((isset($_POST['maxmsgsize'])) ? $_POST['maxmsgsize'] : 0) . "')";
} else {
$query = "INSERT INTO domains
(domain, spamassassin, sa_tag, sa_refuse,
max_accounts, quotas, maildir, pipe, enabled, uid, gid,
type, relay_address, outgoing_ip, maxmsgsize)
VALUES ('" . $_POST['domain'] . "'," .
"'{$_POST['spamassassin']}','".
((isset($_POST['sa_tag'])) ? $_POST['sa_tag'] : 0) . "','" .
((isset($_POST['sa_refuse'])) ? $_POST['sa_refuse'] : 0) . "','" .
"{$_POST['max_accounts']}','".
((isset($_POST['quotas'])) ? $_POST['quotas'] : 0) . "','" .
realpath ($_POST['maildir'] . "/") . "/" . $_POST['domain'] ."','" .
"{$_POST['pipe']}','" .
"{$_POST['enabled']}'," .
"'$uid'," .
"'$gid'," .
"'{$_POST['type']}',".
"'{$_POST['relaydest']}',".
"'$outgoing_IP','".
((isset($_POST['maxmsgsize'])) ? $_POST['maxmsgsize'] : 0) . "')";
}
$domresult = $db->query($query);
if (!DB::isError($domresult)) {
if ($_POST['type'] == "local") {
$query = "INSERT INTO users
(domain_id, localpart, username, clear, crypt, uid, gid,
smtp, pop, on_spamassassin, sa_tag, sa_refuse, maxmsgsize, quota, realname, type, admin)
SELECT domain_id, '" . $_POST['localpart'] . "'," .
"'{$_POST['localpart']}@{$_POST['domain']}'," .
"'{$_POST['clear']}'," .
"'". crypt_password($_POST['clear'],$salt) . "','" .
$uid . "','" .
$gid . "'," .
"'{$smtphomepath}', '{$pophomepath}'," .
"'{$_POST['spamassassin']}','".
((isset($_POST['sa_tag'])) ? $_POST['sa_tag'] : 0) . "','" .
((isset($_POST['sa_refuse'])) ? $_POST['sa_refuse'] : 0) . "','" .
((isset($_POST['maxmsgsize'])) ? $_POST['maxmsgsize'] : 0) . "','" .
((isset($_POST['quotas'])) ? $_POST['quotas'] : 0) . "'," .
"'Domain Admin', 'local', 1 FROM domains
WHERE domains.domain = '{$_POST['domain']}'";
// Is using indexes worth setting the domain_id by hand? -- GCBirzan
$usrresult = $db->query($query);
if (DB::isError($usrresult)) {
header ("Location: site.php?failaddedusrerr={$_POST['domain']}");
die;
} else {
header ("Location: site.php?added={$_POST['domain']}" .
"&type={$_POST['type']}");
mail("{$_POST['localpart']}@{$_POST['domain']}",
"Welcome Domain Admin!",
"$welcome_newdomain",
"From: {$_POST['localpart']}@{$_POST['domain']}\r\n");
die;
}
} else {
header ("Location: site.php?added={$_POST['domain']}" .
"&type={$_POST['type']}");
/* GLD fix for bug in relay welcome message to blank local part. email to: postmaster@<relay-to-domain> */
/* mail("{$_POST['localpart']}@{$_POST['domain']}", GLD removed this */
mail("postmaster@{$_POST['domain']}",
"Welcome Domain Admin!",
"$welcome_newdomain");
/* "From: {$_POST['localpart']}@{$_POST['domain']}\r\n"); GLD removed this */
/* GLD fix: email from: apache@<relay from domain> */
die;
}
} else {
header ("Location: site.php?failaddeddomerr={$_POST['domain']}");
die;
}
} else if ($_POST['type'] == "alias") {
$idquery = "SELECT domain_id FROM domains
WHERE domain = '{$_POST['aliasdest']}'
AND domain_id > 1";
$idresult = $db->query($idquery);
if (DB::isError($idresult)) {
header ("Location: site.php?baddestdom={$_POST['domain']}");
die;
} else {
$idrow = $idresult->fetchRow();
if (!isset($idrow['domain_id'])) {
header ("Location: site.php?baddestdom={$_POST['domain']}");
die;
}
}
$query = "INSERT INTO domainalias (domain_id, alias)
VALUES ('{$idrow['domain_id']}', '{$_POST['domain']}')";
$result = $db->query($query);
if (DB::isError($result)) {
header ("Location: site.php?failaddeddomerr={$_POST['domain']}");
die;
} else {
header ("Location: site.php?added={$_POST['domain']}" .
"&type={$_POST['type']}");
die;
}
} else {
header ("Location: site.php?failaddedpassmismatch={$_POST['domain']}");
}
?>