|
18 | 18 | } |
19 | 19 | $v_username = $user; |
20 | 20 |
|
| 21 | +// Get all user domains |
| 22 | +exec (HESTIA_CMD."v-list-mail-domains ".escapeshellarg($user)." json", $output, $return_var); |
| 23 | +$user_domains = json_decode(implode('', $output), true); |
| 24 | +$user_domains = array_keys($user_domains); |
| 25 | +unset($output); |
| 26 | + |
21 | 27 | // List mail domain |
22 | | -if ((!empty($_GET['domain'])) && (empty($_GET['account']))) { |
23 | | - $v_domain = escapeshellarg($_GET['domain']); |
24 | | - exec (HESTIA_CMD."v-list-mail-domain ".$user." ".$v_domain." json", $output, $return_var); |
| 28 | +if ((!empty($_GET['domain'])) && (empty($_GET['account']))) { |
| 29 | + |
| 30 | + $v_domain = $_GET['domain']; |
| 31 | + if(!in_array($v_domain, $user_domains)) { |
| 32 | + header("Location: /list/mail/"); |
| 33 | + exit; |
| 34 | + } |
| 35 | + |
| 36 | + exec (HESTIA_CMD."v-list-mail-domain ".$user." ".escapeshellarg($v_domain)." json", $output, $return_var); |
25 | 37 | $data = json_decode(implode('', $output), true); |
26 | 38 | unset($output); |
27 | 39 |
|
28 | 40 | // Parse domain |
29 | | - $v_domain = escapeshellarg($_GET['domain']); |
30 | 41 | $v_antispam = $data[$v_domain]['ANTISPAM']; |
31 | 42 | $v_antivirus = $data[$v_domain]['ANTIVIRUS']; |
32 | 43 | $v_dkim = $data[$v_domain]['DKIM']; |
|
42 | 53 | } |
43 | 54 |
|
44 | 55 | // List mail account |
45 | | -if ((!empty($_GET['domain'])) && (!empty($_GET['account']))) { |
46 | | - $v_domain = escapeshellarg($_GET['domain']); |
47 | | - $v_account = escapeshellarg($_GET['account']); |
48 | | - exec (HESTIA_CMD."v-list-mail-account ".$user." ".$v_domain." ".$v_account." 'json'", $output, $return_var); |
| 56 | +if ((!empty($_GET['domain'])) && (!empty($_GET['account']))) { |
| 57 | + |
| 58 | + $v_domain = $_GET['domain']; |
| 59 | + if(!in_array($v_domain, $user_domains)) { |
| 60 | + header("Location: /list/mail/"); |
| 61 | + exit; |
| 62 | + } |
| 63 | + |
| 64 | + $v_account = $_GET['account']; |
| 65 | + exec (HESTIA_CMD."v-list-mail-account ".$user." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." 'json'", $output, $return_var); |
49 | 66 | $data = json_decode(implode('', $output), true); |
50 | 67 | unset($output); |
51 | 68 |
|
52 | 69 | // Parse mail account |
53 | 70 | $v_username = $user; |
54 | | - $v_domain = escapeshellarg($_GET['domain']); |
55 | | - $v_account = escapeshellarg($_GET['account']); |
56 | 71 | $v_password = ""; |
57 | 72 | $v_aliases = str_replace(',', "\n", $data[$v_account]['ALIAS']); |
58 | 73 | $valiases = explode(",", $data[$v_account]['ALIAS']); |
|
72 | 87 |
|
73 | 88 | // Parse autoreply |
74 | 89 | if ( $v_autoreply == 'yes' ) { |
75 | | - exec (HESTIA_CMD."v-list-mail-account-autoreply ".$user." '".$v_domain."' '".$v_account."' json", $output, $return_var); |
| 90 | + exec (HESTIA_CMD."v-list-mail-account-autoreply ".$user." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." json", $output, $return_var); |
76 | 91 | $autoreply_str = json_decode(implode('', $output), true); |
77 | 92 | unset($output); |
78 | 93 | $v_autoreply_message = $autoreply_str[$v_account]['MSG']; |
|
83 | 98 |
|
84 | 99 | // Check POST request for mail domain |
85 | 100 | if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (empty($_GET['account']))) { |
86 | | - $v_domain = escapeshellarg($_POST['v_domain']); |
| 101 | + $v_domain = $_POST['v_domain']; |
| 102 | + if(!in_array($v_domain, $user_domains)) { |
| 103 | + check_return_code(3, ["Unknown domain"]); |
| 104 | + } |
87 | 105 |
|
88 | 106 | // Check token |
89 | 107 | if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) { |
|
93 | 111 |
|
94 | 112 | // Delete antispam |
95 | 113 | if (($v_antispam == 'yes') && (empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) { |
96 | | - exec (HESTIA_CMD."v-delete-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var); |
| 114 | + exec (HESTIA_CMD."v-delete-mail-domain-antispam ".$v_username." ".escapeshellarg($v_domain), $output, $return_var); |
97 | 115 | check_return_code($return_var,$output); |
98 | 116 | $v_antispam = 'no'; |
99 | 117 | unset($output); |
100 | 118 | } |
101 | 119 |
|
102 | 120 | // Add antispam |
103 | 121 | if (($v_antispam == 'no') && (!empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) { |
104 | | - exec (HESTIA_CMD."v-add-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var); |
| 122 | + exec (HESTIA_CMD."v-add-mail-domain-antispam ".$v_username." ".escapeshellarg($v_domain), $output, $return_var); |
105 | 123 | check_return_code($return_var,$output); |
106 | 124 | $v_antispam = 'yes'; |
107 | 125 | unset($output); |
108 | 126 | } |
109 | 127 |
|
110 | 128 | // Delete antivirus |
111 | 129 | if (($v_antivirus == 'yes') && (empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) { |
112 | | - exec (HESTIA_CMD."v-delete-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var); |
| 130 | + exec (HESTIA_CMD."v-delete-mail-domain-antivirus ".$v_username." ".escapeshellarg($v_domain), $output, $return_var); |
113 | 131 | check_return_code($return_var,$output); |
114 | 132 | $v_antivirus = 'no'; |
115 | 133 | unset($output); |
116 | 134 | } |
117 | 135 |
|
118 | 136 | // Add antivirs |
119 | 137 | if (($v_antivirus == 'no') && (!empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) { |
120 | | - exec (HESTIA_CMD."v-add-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var); |
| 138 | + exec (HESTIA_CMD."v-add-mail-domain-antivirus ".$v_username." ".$escapeshellarg($v_domain), $output, $return_var); |
121 | 139 | check_return_code($return_var,$output); |
122 | 140 | $v_antivirus = 'yes'; |
123 | 141 | unset($output); |
124 | 142 | } |
125 | 143 |
|
126 | 144 | // Delete DKIM |
127 | 145 | if (($v_dkim == 'yes') && (empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) { |
128 | | - exec (HESTIA_CMD."v-delete-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var); |
| 146 | + exec (HESTIA_CMD."v-delete-mail-domain-dkim ".$v_username." ".$escapeshellarg($v_domain), $output, $return_var); |
129 | 147 | check_return_code($return_var,$output); |
130 | 148 | $v_dkim = 'no'; |
131 | 149 | unset($output); |
132 | 150 | } |
133 | 151 |
|
134 | 152 | // Add DKIM |
135 | 153 | if (($v_dkim == 'no') && (!empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) { |
136 | | - exec (HESTIA_CMD."v-add-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var); |
| 154 | + exec (HESTIA_CMD."v-add-mail-domain-dkim ".$v_username." ".$escapeshellarg($v_domain), $output, $return_var); |
137 | 155 | check_return_code($return_var,$output); |
138 | 156 | $v_dkim = 'yes'; |
139 | 157 | unset($output); |
140 | 158 | } |
141 | 159 |
|
142 | 160 | // Delete catchall |
143 | 161 | if ((!empty($v_catchall)) && (empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) { |
144 | | - exec (HESTIA_CMD."v-delete-mail-domain-catchall ".$v_username." ".$v_domain, $output, $return_var); |
| 162 | + exec (HESTIA_CMD."v-delete-mail-domain-catchall ".$v_username." ".escapeshellarg($v_domain), $output, $return_var); |
145 | 163 | check_return_code($return_var,$output); |
146 | 164 | $v_catchall = ''; |
147 | 165 | unset($output); |
|
151 | 169 | if ((!empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) { |
152 | 170 | if ($v_catchall != $_POST['v_catchall']) { |
153 | 171 | $v_catchall = escapeshellarg($_POST['v_catchall']); |
154 | | - exec (HESTIA_CMD."v-change-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var); |
| 172 | + exec (HESTIA_CMD."v-change-mail-domain-catchall ".$v_username." ".escapeshellarg($v_domain)." ".$v_catchall, $output, $return_var); |
155 | 173 | check_return_code($return_var,$output); |
156 | 174 | unset($output); |
157 | 175 | } |
|
160 | 178 | // Add catchall |
161 | 179 | if ((empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) { |
162 | 180 | $v_catchall = escapeshellarg($_POST['v_catchall']); |
163 | | - exec (HESTIA_CMD."v-add-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var); |
| 181 | + exec (HESTIA_CMD."v-add-mail-domain-catchall ".$v_username." ".escapeshellarg($v_domain)." ".$v_catchall, $output, $return_var); |
164 | 182 | check_return_code($return_var,$output); |
165 | 183 | unset($output); |
166 | 184 | } |
|
187 | 205 | } |
188 | 206 | } |
189 | 207 |
|
190 | | - $v_domain = escapeshellarg($_POST['v_domain']); |
191 | | - $v_account = escapeshellarg($_POST['v_account']); |
| 208 | + $v_domain = $_POST['v_domain']; |
| 209 | + if(!in_array($v_domain, $user_domains)) { |
| 210 | + check_return_code(3, ["Unknown domain"]); |
| 211 | + } |
| 212 | + |
| 213 | + $v_account = $_POST['v_account']; |
192 | 214 | $v_send_email = $_POST['v_send_email']; |
193 | 215 | $v_credentials = $_POST['v_credentials']; |
194 | 216 |
|
|
198 | 220 | $fp = fopen($v_password, "w"); |
199 | 221 | fwrite($fp, $_POST['v_password']."\n"); |
200 | 222 | fclose($fp); |
201 | | - exec (HESTIA_CMD."v-change-mail-account-password ".$v_username." ".$v_domain." ".$v_account." ".$v_password, $output, $return_var); |
| 223 | + exec (HESTIA_CMD."v-change-mail-account-password ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_password, $output, $return_var); |
202 | 224 | check_return_code($return_var,$output); |
203 | 225 | unset($output); |
204 | 226 | unlink($v_password); |
|
212 | 234 | } else { |
213 | 235 | $v_quota = escapeshellarg($_POST['v_quota']); |
214 | 236 | } |
215 | | - exec (HESTIA_CMD."v-change-mail-account-quota ".$v_username." ".$v_domain." ".$v_account." ".$v_quota, $output, $return_var); |
| 237 | + exec (HESTIA_CMD."v-change-mail-account-quota ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_quota, $output, $return_var); |
216 | 238 | check_return_code($return_var,$output); |
217 | 239 | unset($output); |
218 | 240 | } |
219 | 241 |
|
220 | 242 | // Change account aliases |
221 | 243 | if (empty($_SESSION['error_msg'])) { |
222 | | - $waliases = preg_replace("/\n/", " ", escapeshellarg($_POST['v_aliases'])); |
| 244 | + $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']); |
223 | 245 | $waliases = preg_replace("/,/", " ", $waliases); |
224 | 246 | $waliases = preg_replace('/\s+/', ' ',$waliases); |
225 | 247 | $waliases = trim($waliases); |
|
228 | 250 | $result = array_diff($valiases, $aliases); |
229 | 251 | foreach ($result as $alias) { |
230 | 252 | if ((empty($_SESSION['error_msg'])) && (!empty($alias))) { |
231 | | - exec (HESTIA_CMD."v-delete-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var); |
| 253 | + exec (HESTIA_CMD."v-delete-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var); |
232 | 254 | check_return_code($return_var,$output); |
233 | 255 | unset($output); |
234 | 256 | } |
235 | 257 | } |
236 | 258 | $result = array_diff($aliases, $valiases); |
237 | 259 | foreach ($result as $alias) { |
238 | 260 | if ((empty($_SESSION['error_msg'])) && (!empty($alias))) { |
239 | | - exec (HESTIA_CMD."v-add-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." ".escapeshellarg($alias), $output, $return_var); |
| 261 | + exec (HESTIA_CMD."v-add-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var); |
240 | 262 | check_return_code($return_var,$output); |
241 | 263 | unset($output); |
242 | 264 | } |
|
245 | 267 |
|
246 | 268 | // Change forwarders |
247 | 269 | if (empty($_SESSION['error_msg'])) { |
248 | | - $wfwd = preg_replace("/\n/", " ", escapeshellarg($_POST['v_fwd'])); |
| 270 | + $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']); |
249 | 271 | $wfwd = preg_replace("/,/", " ", $wfwd); |
250 | 272 | $wfwd = preg_replace('/\s+/', ' ',$wfwd); |
251 | 273 | $wfwd = trim($wfwd); |
|
254 | 276 | $result = array_diff($vfwd, $fwd); |
255 | 277 | foreach ($result as $forward) { |
256 | 278 | if ((empty($_SESSION['error_msg'])) && (!empty($forward))) { |
257 | | - exec (HESTIA_CMD."v-delete-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var); |
| 279 | + exec (HESTIA_CMD."v-delete-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var); |
258 | 280 | check_return_code($return_var,$output); |
259 | 281 | unset($output); |
260 | 282 | } |
261 | 283 | } |
262 | 284 | $result = array_diff($fwd, $vfwd); |
263 | 285 | foreach ($result as $forward) { |
264 | 286 | if ((empty($_SESSION['error_msg'])) && (!empty($forward))) { |
265 | | - exec (HESTIA_CMD."v-add-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." ".escapeshellarg($forward), $output, $return_var); |
| 287 | + exec (HESTIA_CMD."v-add-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var); |
266 | 288 | check_return_code($return_var,$output); |
267 | 289 | unset($output); |
268 | 290 | } |
|
271 | 293 |
|
272 | 294 | // Delete FWD_ONLY flag |
273 | 295 | if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) { |
274 | | - exec (HESTIA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var); |
| 296 | + exec (HESTIA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var); |
275 | 297 | check_return_code($return_var,$output); |
276 | 298 | unset($output); |
277 | 299 | $v_fwd_only = ''; |
278 | 300 | } |
279 | 301 |
|
280 | 302 | // Add FWD_ONLY flag |
281 | 303 | if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) { |
282 | | - exec (HESTIA_CMD."v-add-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var); |
| 304 | + exec (HESTIA_CMD."v-add-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var); |
283 | 305 | check_return_code($return_var,$output); |
284 | 306 | unset($output); |
285 | 307 | $v_fwd_only = 'yes'; |
286 | 308 | } |
287 | 309 |
|
288 | 310 | // Delete autoreply |
289 | 311 | if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) { |
290 | | - exec (HESTIA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var); |
| 312 | + exec (HESTIA_CMD."v-delete-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var); |
291 | 313 | check_return_code($return_var,$output); |
292 | 314 | unset($output); |
293 | 315 | $v_autoreply = 'no'; |
|
299 | 321 | if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) { |
300 | 322 | $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']); |
301 | 323 | $v_autoreply_message = escapeshellarg($v_autoreply_message); |
302 | | - exec (HESTIA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var); |
| 324 | + exec (HESTIA_CMD."v-add-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_autoreply_message, $output, $return_var); |
303 | 325 | check_return_code($return_var,$output); |
304 | 326 | unset($output); |
305 | 327 | $v_autoreply = 'yes'; |
|
0 commit comments