Blob


1 <?php
2 //
3 // OpenSMTPD Admin
4 // by Mischa Peters <mischa at high5 dot nl>
5 // Copyright (c) 2022 High5!
6 // License Info: LICENSE.TXT
7 //
8 // File: edit-alias.php
9 //
10 // Template File: edit-alias.tpl
11 //
12 // Template Variables:
13 //
14 // message
15 // goto
16 //
17 // POST / GET Variables:
18 //
19 // address
20 // domain
21 // goto
22 //
23 require_once './functions.inc.php';
24 include './languages/' . check_language() . '.lang';
26 $SESSID_USERNAME = check_session();
27 $ROLE = check_role($SESSID_USERNAME);
29 if ($ROLE == ADMIN_ROLE) {
30 $list_domains = list_domains();
31 $list_admins = list_admins();
32 } else {
33 $list_domains = list_domains($SESSID_USERNAME);
34 }
36 if ($_SERVER['REQUEST_METHOD'] == "GET") {
37 $address = filter_input(INPUT_GET, 'address', FILTER_VALIDATE_EMAIL);
38 $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
39 $domain_key = array_search($domain, array_column($list_domains, 'domain'));
41 if (in_array($domain, array_column($list_domains, 'domain'))) {
42 try {
43 $dbh = pdo_connect();
44 $sth = $dbh->prepare("SELECT goto FROM alias WHERE address=? AND domain=?");
45 $sth->bindParam(1, $address, PDO::PARAM_STR);
46 $sth->bindParam(2, $domain, PDO::PARAM_STR);
47 $sth->execute();
48 $goto = $sth->fetch(PDO::FETCH_COLUMN);
49 $goto = explode(',', $goto);
50 } catch(PDOException $e) {
51 $message = $LANG['Edit_alias_address_error'];
52 }
53 }
54 }
56 if ($_SERVER['REQUEST_METHOD'] == "POST") {
57 $address = strtolower(filter_input(INPUT_GET, 'address', FILTER_VALIDATE_EMAIL));
58 $domain = strtolower(filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN));
59 $goto = strtolower(filter_input(INPUT_POST, 'goto', FILTER_DEFAULT));
60 $domain_key = array_search($domain, array_column($list_domains, 'domain'));
62 if (empty($goto)) {
63 $goto = array();
64 $message = $LANG['Edit_alias_goto_text_error1'];
65 } else {
66 $goto = preg_replace('/\\\r\\\n/', ',', $goto);
67 $goto = preg_replace('/\r\n/', ',', $goto);
68 $goto = preg_replace('/[\s]+/i', '', $goto);
69 $goto = preg_replace('/\,*$/', '', $goto);
70 $validate_goto = explode(',', $goto);
71 foreach ($validate_goto as $row) {
72 if (!filter_var($row, FILTER_VALIDATE_EMAIL)) {
73 $goto = explode(',', $goto);
74 $message = $LANG['Edit_alias_goto_text_error2'] . "$row</div>";
75 }
76 }
77 }
79 if (empty($message) && in_array($domain, array_column($list_domains, 'domain'))) {
80 try {
81 $dbh = pdo_connect();
82 $sth = $dbh->prepare("UPDATE alias SET goto=?,modified=NOW() WHERE address=? AND domain=?");
83 $sth->bindParam(1, $goto, PDO::PARAM_STR);
84 $sth->bindParam(2, $address, PDO::PARAM_STR);
85 $sth->bindParam(3, $domain, PDO::PARAM_STR);
86 $sth->execute();
87 logging($SESSID_USERNAME, $domain, $LANG['Logging_alias_edit'], "$address -> $goto");
88 header("Location: list-virtual.php?domain=$domain");
89 } catch(PDOException $e) {
90 $message = $LANG['Edit_alias_result_error'];
91 }
92 }
93 }
94 include './templates/header.tpl';
95 include './templates/menu.tpl';
96 include './templates/edit-alias.tpl';
97 include './templates/footer.tpl';
98 ?>