opensmtpdadmin/create-alias.php

115 lines
3.2 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: create-alias.php
//
// Template File: create-alias.tpl
//
// Template Variables:
//
// tMessage
// tAddress
// tGoto
// tDomain
//
// Form POST \ GET Variables:
//
// fAddress
// fGoto
// fDomain
//
require("./variables.inc.php");
require("./config.inc.php");
require("./functions.inc.php");
include("./languages/" . check_language() . ".lang");
$SESSID_USERNAME = check_session();
$list_domains = list_domains_for_admin($SESSID_USERNAME);
if ($_SERVER['REQUEST_METHOD'] == "GET") {
2022-09-03 11:30:40 +02:00
$pCreate_alias_goto_text = $LANG['Create_alias_goto_text'];
2022-08-18 14:01:52 +02:00
if (isset($_GET['domain'])) $tDomain = escape_string($_GET['domain']);
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
2022-09-03 11:30:40 +02:00
$pCreate_alias_goto_text = $LANG['Create_alias_goto_text'];
2022-08-18 14:01:52 +02:00
$fAddress = escape_string($_POST['fAddress']) . "@" . escape_string($_POST['fDomain']);
$fAddress = strtolower($fAddress);
$fGoto = escape_string($_POST['fGoto']);
$fGoto = strtolower($fGoto);
$fDomain = escape_string($_POST['fDomain']);
if (!preg_match('/@/',$fGoto)) {
$fGoto = $fGoto . "@" . escape_string($_POST['fDomain']);
}
if (!check_owner($SESSID_USERNAME, $fDomain)) {
$error = 1;
$tAddress = escape_string($_POST['fAddress']);
$tGoto = $fGoto;
$tDomain = $fDomain;
2022-09-03 11:30:40 +02:00
$pCreate_alias_address_text = $LANG['Create_alias_address_text_error1'];
2022-08-18 14:01:52 +02:00
}
if (!check_alias($fDomain)) {
$error = 1;
$tAddress = escape_string($_POST['fAddress']);
$tGoto = $fGoto;
$tDomain = $fDomain;
2022-09-03 11:30:40 +02:00
$pCreate_alias_address_text = $LANG['Create_alias_address_text_error3'];
2022-08-18 14:01:52 +02:00
}
if (empty($fAddress) or !check_email($fAddress)) {
$error = 1;
$tAddress = escape_string($_POST['fAddress']);
$tGoto = $fGoto;
$tDomain = $fDomain;
2022-09-03 11:30:40 +02:00
$pCreate_alias_address_text = $LANG['Create_alias_address_text_error1'];
2022-08-18 14:01:52 +02:00
}
if (empty($fGoto) or !check_email($fGoto)) {
$error = 1;
$tAddress = escape_string($_POST['fAddress']);
$tGoto = $fGoto;
$tDomain = $fDomain;
2022-09-03 11:30:40 +02:00
$pCreate_alias_goto_text = $LANG['Create_alias_goto_text_error'];
2022-08-18 14:01:52 +02:00
}
if (escape_string($_POST['fAddress']) == "*") $fAddress = "@" . escape_string($_POST['fDomain']);
$result = db_query("SELECT * FROM alias WHERE address='$fAddress'");
if ($result['rows'] == 1) {
$error = 1;
$tAddress = escape_string($_POST['fAddress']);
$tGoto = $fGoto;
$tDomain = $fDomain;
2022-09-03 11:30:40 +02:00
$pCreate_alias_address_text = $LANG['Create_alias_address_text_error2'];
2022-08-18 14:01:52 +02:00
}
if ($error != 1) {
if (preg_match('/^\*@(.*)$/', $fGoto, $match)) $fGoto = "@" . $match[1];
$result = db_query("INSERT INTO alias (address,goto,domain,created,modified) VALUES ('$fAddress','$fGoto','$fDomain',NOW(),NOW())");
if ($result['rows'] != 1) {
$tDomain = $fDomain;
2022-09-03 11:30:40 +02:00
$tMessage = $LANG['Create_alias_result_error'] . "<br />($fAddress -> $fGoto)<br />\n";
2022-08-18 14:01:52 +02:00
} else {
db_log($SESSID_USERNAME, $fDomain, "create alias", "$fAddress -> $fGoto");
$tDomain = $fDomain;
2022-09-03 11:30:40 +02:00
$tMessage = $LANG['Create_alias_result_succes'] . "<br />($fAddress -> $fGoto)<br />\n";
2022-08-18 14:01:52 +02:00
}
}
}
include("./templates/header.tpl");
include("./templates/menu.tpl");
include("./templates/create-alias.tpl");
include("./templates/footer.tpl");
?>