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: add-alias.php
9 //
10 // Template File: add-alias.tpl
11 //
12 // Template Variables:
13 //
14 // message
15 // address
16 // domain
17 // goto
18 //
19 // POST / GET Variables:
20 //
21 // address
22 // domain
23 // goto
24 //
25 require_once './functions.inc.php';
26 include './languages/' . check_language() . '.lang';
28 $SESSID_USERNAME = check_session();
29 $ROLE = check_role($SESSID_USERNAME);
31 if ($ROLE == ADMIN_ROLE) {
32 $list_domains = list_domains();
33 } else {
34 $list_domains = list_domains($SESSID_USERNAME);
35 }
37 if ($_SERVER['REQUEST_METHOD'] == "GET") {
38 $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
39 $domain_key = array_search($domain, array_column($list_domains, 'domain'));
40 }
42 if ($_SERVER['REQUEST_METHOD'] == "POST") {
43 $address = strtolower(filter_input(INPUT_POST, 'address', FILTER_DEFAULT));
44 $domain = filter_input(INPUT_POST, 'domain', FILTER_VALIDATE_DOMAIN);
45 $goto = strtolower(filter_input(INPUT_POST, 'goto', FILTER_DEFAULT));
46 $domain_key = array_search($domain, array_column($list_domains, 'domain'));
47 $from = filter_var($address . '@' . $domain, FILTER_VALIDATE_EMAIL);
49 if (!str_contains($goto, '@')) {
50 $goto = $goto . "@" . $domain;
51 }
52 $goto = filter_var($goto, FILTER_VALIDATE_EMAIL);
54 if ($list_domains[$domain_key]['aliases'] != 0 && $list_domains[$domain_key]['alias_count'] >= $list_domains[$domain_key]['aliases']) {
55 $message = $LANG['Add_alias_address_text_error2'];
56 }
58 if (empty($address) || empty($goto)) {
59 $message = $LANG['Add_alias_address_text_error1'];
60 }
62 if (empty($message) && in_array($domain, array_column($list_domains, 'domain'))) {
63 try {
64 $dbh = pdo_connect();
65 $sth = $dbh->prepare("INSERT INTO alias (address,goto,domain,created,modified) VALUES (?,?,?,NOW(),NOW())");
66 $sth->bindParam(1, $from, PDO::PARAM_STR);
67 $sth->bindParam(2, $goto, PDO::PARAM_STR);
68 $sth->bindParam(3, $domain, PDO::PARAM_STR);
69 $sth->execute();
70 logging($SESSID_USERNAME, $domain, $LANG['Logging_alias_add'], "$from -> $goto");
71 $message = $LANG['Add_alias_result_succes'] . "<br />($from -> $goto)</br />";
72 $address = '';
73 $goto = '';
74 } catch(PDOException $e) {
75 $message = $LANG['Add_alias_result_error'] . "<br />($from -> $goto)<br />";
76 }
77 }
78 }
79 include './templates/header.tpl';
80 include './templates/menu.tpl';
81 include './templates/add-alias.tpl';
82 include './templates/footer.tpl';
83 ?>