opensmtpdadmin/domain.php

97 lines
3.0 KiB
PHP
Raw Normal View History

2022-09-05 20:31:23 +02:00
<?php
//
// OpenSMTPD Admin
// by Mischa Peters <mischa at high5 dot nl>
// Copyright (c) 2022 High5!
// License Info: LICENSE.TXT
//
// File: domain.php
//
// Template File: domain.tpl
//
// Template Variables:
//
// action
// message
// domain
// description
// aliases
// mailboxes
//
// POST / GET Variables:
//
// domain
// description
// aliases
// mailboxes
//
require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
$SESSID_USERNAME = check_session();
2022-09-06 13:56:05 +02:00
$ROLE = check_role($SESSID_USERNAME);
2022-09-05 20:31:23 +02:00
if ($ROLE != ADMIN_ROLE) {
2022-09-05 20:31:23 +02:00
header("Location: list-domain.php");
die();
}
$list_domains = list_domains();
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT) ?? 'add';
if ($action == 'edit') {
$domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
$domain_key = array_search($domain, array_column($list_domains, 'domain'));
$description = $list_domains[$domain_key]['description'];
$aliases = $list_domains[$domain_key]['aliases'];
$mailboxes = $list_domains[$domain_key]['mailboxes'];
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT) ?? 'add';
$domain = strtolower(filter_input(INPUT_POST, 'domain', FILTER_VALIDATE_DOMAIN));
$description = filter_input(INPUT_POST, 'description', FILTER_CALLBACK, array('options' => 'htmlspecialchars'));
$aliases = filter_input(INPUT_POST, 'aliases', FILTER_VALIDATE_INT);
$mailboxes = filter_input(INPUT_POST, 'mailboxes', FILTER_VALIDATE_INT);
if (!in_array($domain, array_column($list_domains, 'domain'))) {
try {
$dbh = pdo_connect();
$sth = $dbh->prepare("INSERT INTO domain (domain,description,aliases,mailboxes,created,modified) VALUES (?,?,?,?,NOW(),NOW())");
$sth->bindParam(1, $domain, PDO::PARAM_STR);
$sth->bindParam(2, $description, PDO::PARAM_STR);
$sth->bindParam(3, $aliases, PDO::PARAM_INT);
$sth->bindParam(4, $mailboxes, PDO::PARAM_INT);
$sth->execute();
$message = $LANG['AdminAdd_domain_result_succes'] . "<br />($domain)</br />";
} catch(PDOException $e) {
$message = $LANG['AdminAdd_domain_result_error'] . "<br />($domain)<br />";
}
} else {
$message = $LANG['AdminAdd_domain_domain_text_error'];
}
if (in_array($domain, array_column($list_domains, 'domain')) && $action == 'edit') {
try {
$dbh = pdo_connect();
$sth = $dbh->prepare("UPDATE domain SET description=?,aliases=?,mailboxes=?,modified=NOW() WHERE domain=?");
$sth->bindParam(1, $description, PDO::PARAM_STR);
$sth->bindParam(2, $aliases, PDO::PARAM_INT);
$sth->bindParam(3, $mailboxes, PDO::PARAM_INT);
$sth->bindParam(4, $domain, PDO::PARAM_STR);
$sth->execute();
header("Location: list-domain.php");
} catch(PDOException $e) {
$message = $LANG['AdminEdit_domain_result_error'];
}
}
}
include './templates/header.tpl';
include './templates/menu.tpl';
include './templates/domain.tpl';
include './templates/footer.tpl';
?>