74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
//
|
|
// OpenSMTPD Admin
|
|
// by Mischa Peters <mischa at high5 dot nl>
|
|
// Copyright (c) 2022 High5!
|
|
// License Info: LICENSE.TXT
|
|
//
|
|
// File: create-alias.php
|
|
//
|
|
// Template File: create-alias.tpl
|
|
//
|
|
// Template Variables:
|
|
//
|
|
// tMessage
|
|
// tAddress
|
|
// tGoto
|
|
// domain
|
|
//
|
|
// Form POST \ GET Variables:
|
|
//
|
|
// address
|
|
// fGoto
|
|
// domain
|
|
//
|
|
require("../variables.inc.php");
|
|
require("../config.inc.php");
|
|
require("../functions.inc.php");
|
|
include("../languages/" . check_language() . ".lang");
|
|
|
|
$list_domains = list_domains();
|
|
|
|
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'));
|
|
|
|
$from = filter_var($address . '@' . $domain, FILTER_VALIDATE_EMAIL);
|
|
if (!str_contains($goto, '@')) {
|
|
$goto = $goto . "@" . $domain;
|
|
}
|
|
$goto = filter_var($goto, FILTER_VALIDATE_EMAIL);
|
|
|
|
if ($list_domains[$domain_key]['alias_count'] < 0 || $list_domains[$domain_key]['alias_count'] >= $list_domains[$domain_key]['aliases']) {
|
|
$message = $PALANG['pCreate_alias_address_text_error2'];
|
|
}
|
|
|
|
if (empty($address) || empty($goto)) {
|
|
$message = $PALANG['pCreate_alias_address_text_error1'];
|
|
}
|
|
|
|
if (empty($message)) {
|
|
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();
|
|
logging(ADMIN_EMAIL, $domain, "create alias", "$from -> $goto");
|
|
$message = $PALANG['pCreate_alias_result_succes'] . "<br />($from -> $goto)</br />";
|
|
$address = '';
|
|
$goto = '';
|
|
} catch(PDOException $e) {
|
|
$message = $PALANG['pCreate_alias_result_error'] . "<br />($from -> $goto) - $e<br />";
|
|
}
|
|
}
|
|
}
|
|
include("../templates/header.tpl");
|
|
include("../templates/admin_menu.tpl");
|
|
include("../templates/create-alias.tpl");
|
|
include("../templates/footer.tpl");
|
|
?>
|