opensmtpdadmin/admin/domain.php

89 lines
2.9 KiB
PHP
Raw Normal View History

2022-09-02 23:06:08 +02:00
<?php
//
// OpenSMTPD Admin
// by Mischa Peters <mischa at high5 dot nl>
// Copyright (c) 2022 High5!
// License Info: LICENSE.TXT
//
// File: domain.php
2022-09-02 23:06:08 +02:00
//
// Template File: admin_domain.tpl
2022-09-02 23:06:08 +02:00
//
// Template Variables:
//
// action
// message
// domain
// description
// aliases
// mailboxes
2022-09-02 23:06:08 +02:00
//
// Form POST \ GET Variables:
//
// domain
// description
// aliases
// mailboxes
2022-09-02 23:06:08 +02:00
//
require_once '../functions.inc.php';
include '../languages/' . check_language() . '.lang';
$list_domains = list_domains();
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT) ?? 'add';
2022-09-02 23:06:08 +02:00
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';
2022-09-02 23:06:08 +02:00
$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 = connect_db();
$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();
2022-09-03 11:30:40 +02:00
$message = $LANG['AdminAdd_domain_result_succes'] . "<br />($domain)</br />";
2022-09-02 23:06:08 +02:00
} catch(PDOException $e) {
2022-09-03 11:30:40 +02:00
$message = $LANG['AdminAdd_domain_result_error'] . "<br />($domain)<br />";
2022-09-02 23:06:08 +02:00
}
} else {
2022-09-03 11:30:40 +02:00
$message = $LANG['AdminAdd_domain_domain_text_error'];
2022-09-02 23:06:08 +02:00
}
if (in_array($domain, array_column($list_domains, 'domain')) && $action == 'edit') {
try {
$dbh = connect_db();
$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) {
2022-09-03 11:30:40 +02:00
$message = $LANG['AdminEdit_domain_result_error'];
2022-09-02 23:06:08 +02:00
}
}
}
include '../templates/header.tpl';
include '../templates/admin_menu.tpl';
include '../templates/admin_domain.tpl';
include '../templates/footer.tpl';
?>