opensmtpdadmin/admin/edit-alias.php

94 lines
2.8 KiB
PHP
Raw Normal View History

2022-08-18 14:01:52 +02:00
<?php
//
// OpenSMTPD Admin
// by Mischa Peters <mischa at high5 dot nl>
// Copyright (c) 2022 High5!
// License Info: LICENSE.TXT
//
// File: edit-alias.php
//
// Template File: edit-alias.tpl
//
// Template Variables:
//
2022-09-04 11:38:47 +02:00
// message
// goto
2022-08-18 14:01:52 +02:00
//
// Form POST \ GET Variables:
//
2022-09-04 11:38:47 +02:00
// address
// domain
// goto
2022-08-18 14:01:52 +02:00
//
2022-09-04 11:38:47 +02:00
require_once '../functions.inc.php';
include '../languages/' . check_language() . '.lang';
2022-08-18 14:01:52 +02:00
2022-09-04 14:49:44 +02:00
$list_domains = list_domains();
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
2022-08-18 14:01:52 +02:00
if ($_SERVER['REQUEST_METHOD'] == "GET") {
2022-09-04 11:38:47 +02:00
$address = filter_input(INPUT_GET, 'address', FILTER_VALIDATE_EMAIL);
$domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
2022-09-04 14:49:44 +02:00
$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 11:38:47 +02:00
2022-09-04 16:04:56 +02:00
if ($domain_exist) {
try {
$dbh = connect_db();
$sth = $dbh->prepare("SELECT goto FROM alias WHERE address=? AND domain=?");
$sth->bindParam(1, $address, PDO::PARAM_STR);
$sth->bindParam(2, $domain, PDO::PARAM_STR);
$sth->execute();
$goto = $sth->fetch(PDO::FETCH_COLUMN);
$goto = explode(',', $goto);
} catch(PDOException $e) {
$message = $LANG['Edit_alias_address_error'];
}
2022-08-18 14:01:52 +02:00
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
2022-09-04 11:38:47 +02:00
$address = strtolower(filter_input(INPUT_GET, 'address', FILTER_VALIDATE_EMAIL));
$domain = strtolower(filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN));
$goto = strtolower(filter_input(INPUT_POST, 'goto', FILTER_DEFAULT));
2022-09-04 14:49:44 +02:00
$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-08-18 14:01:52 +02:00
2022-09-04 11:38:47 +02:00
if (empty($goto)) {
$goto = array();
$message = $LANG['Edit_alias_goto_text_error1'];
} else {
$goto = preg_replace('/\\\r\\\n/', ',', $goto);
$goto = preg_replace('/\r\n/', ',', $goto);
$goto = preg_replace('/[\s]+/i', '', $goto);
$goto = preg_replace('/\,*$/', '', $goto);
$validate_goto = explode(',', $goto);
foreach ($validate_goto as $row) {
if (!filter_var($row, FILTER_VALIDATE_EMAIL)) {
$goto = explode(',', $goto);
$message = $LANG['Edit_alias_goto_text_error2'] . "$row</div>";
}
2022-08-18 14:01:52 +02:00
}
}
2022-09-04 11:38:47 +02:00
2022-09-04 16:04:56 +02:00
if ($domain_exist && empty($message)) {
2022-09-04 11:38:47 +02:00
try {
$dbh = connect_db();
$sth = $dbh->prepare("UPDATE alias SET goto=?,modified=NOW() WHERE address=? AND domain=?");
$sth->bindParam(1, $goto, PDO::PARAM_STR);
$sth->bindParam(2, $address, PDO::PARAM_STR);
$sth->bindParam(3, $domain, PDO::PARAM_STR);
$sth->execute();
logging($admin, $domain, $LANG['Logging_alias_edit'], "$address -> $goto");
2022-09-04 11:38:47 +02:00
header("Location: list-virtual.php?domain=$domain");
} catch(PDOException $e) {
$message = $LANG['Edit_alias_result_error'];
2022-08-18 14:01:52 +02:00
}
}
}
2022-09-04 11:38:47 +02:00
include '../templates/header.tpl';
include '../templates/admin_menu.tpl';
include '../templates/edit-alias.tpl';
include '../templates/footer.tpl';
2022-08-18 14:01:52 +02:00
?>