opensmtpdadmin/admin/add-alias.php

80 lines
2.4 KiB
PHP
Raw Normal View History

2022-09-02 23:08:29 +02:00
<?php
//
// OpenSMTPD Admin
// by Mischa Peters <mischa at high5 dot nl>
// Copyright (c) 2022 High5!
// License Info: LICENSE.TXT
//
// File: add-alias.php
2022-09-02 23:08:29 +02:00
//
// Template File: add-alias.tpl
2022-09-02 23:08:29 +02:00
//
// Template Variables:
//
// message
// address
2022-09-02 23:08:29 +02:00
// domain
// goto
2022-09-02 23:08:29 +02:00
//
// Form POST \ GET Variables:
//
// address
// domain
// goto
2022-09-02 23:08:29 +02:00
//
require_once '../functions.inc.php';
2022-09-04 11:38:47 +02:00
include '../languages/' . check_language() . '.lang';
2022-09-02 23:08:29 +02:00
$list_domains = list_domains();
2022-09-04 14:49:44 +02:00
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
2022-09-02 23:08:29 +02:00
2022-09-04 13:10:23 +02:00
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
$domain_key = array_search($domain, array_column($list_domains, 'domain'));
2022-09-04 16:04:56 +02:00
$domain_exist = in_array($domain, array_column($list_domains, 'domain'));
2022-09-04 13:10:23 +02:00
}
2022-09-02 23:08:29 +02:00
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$address = strtolower(filter_input(INPUT_POST, 'address', FILTER_DEFAULT));
$domain = filter_input(INPUT_POST, 'domain', FILTER_VALIDATE_DOMAIN);
$goto = strtolower(filter_input(INPUT_POST, 'goto', FILTER_DEFAULT));
$domain_key = array_search($domain, array_column($list_domains, 'domain'));
2022-09-04 16:04:56 +02:00
$domain_exist = in_array($domain, array_column($list_domains, 'domain'));
2022-09-02 23:08:29 +02:00
$from = filter_var($address . '@' . $domain, FILTER_VALIDATE_EMAIL);
2022-09-04 14:49:44 +02:00
2022-09-02 23:08:29 +02:00
if (!str_contains($goto, '@')) {
$goto = $goto . "@" . $domain;
}
$goto = filter_var($goto, FILTER_VALIDATE_EMAIL);
2022-09-04 14:49:44 +02:00
if ($list_domains[$domain_key]['aliases'] != 0 && $list_domains[$domain_key]['alias_count'] >= $list_domains[$domain_key]['aliases']) {
2022-09-03 11:30:40 +02:00
$message = $LANG['Create_alias_address_text_error2'];
2022-09-02 23:08:29 +02:00
}
if (empty($address) || empty($goto)) {
2022-09-03 11:30:40 +02:00
$message = $LANG['Create_alias_address_text_error1'];
2022-09-02 23:08:29 +02:00
}
2022-09-04 16:04:56 +02:00
if ($domain_exist && empty($message)) {
2022-09-02 23:08:29 +02:00
try {
$dbh = connect_db();
$sth = $dbh->prepare("INSERT INTO alias (address,goto,domain,created,modified) VALUES (?,?,?,NOW(),NOW())");
$sth->bindParam(1, $from, PDO::PARAM_STR);
$sth->bindParam(2, $goto, PDO::PARAM_STR);
$sth->bindParam(3, $domain, PDO::PARAM_STR);
$sth->execute();
2022-09-04 14:49:44 +02:00
logging($admin, $domain, "create alias", "$from -> $goto");
2022-09-03 11:30:40 +02:00
$message = $LANG['Create_alias_result_succes'] . "<br />($from -> $goto)</br />";
2022-09-02 23:08:29 +02:00
$address = '';
$goto = '';
} catch(PDOException $e) {
2022-09-04 14:49:44 +02:00
$message = $LANG['Create_alias_result_error'] . "<br />($from -> $goto)<br />";
2022-09-02 23:08:29 +02:00
}
}
}
include '../templates/header.tpl';
include '../templates/admin_menu.tpl';
include '../templates/add-alias.tpl';
include '../templates/footer.tpl';
2022-09-02 23:08:29 +02:00
?>