opensmtpdadmin/delete.php

86 lines
2.6 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: delete.php
//
// Template File: message.tpl
//
// Template Variables:
//
2022-09-04 14:49:44 +02:00
// message
2022-08-18 14:01:52 +02:00
//
// Form POST \ GET Variables:
//
2022-09-04 14:49:44 +02:00
// table
// where
// delete
// domain
2022-08-18 14:01:52 +02:00
//
2022-09-04 14:49:44 +02:00
require_once './functions.inc.php';
include './languages/' . check_language() . '.lang';
2022-08-18 14:01:52 +02:00
$SESSID_USERNAME = check_session();
2022-09-04 14:49:44 +02:00
$list_domains = list_domains($SESSID_USERNAME);
$admin = $SESSID_USERNAME ?? ADMIN_EMAIL;
2022-08-18 14:01:52 +02:00
if ($_SERVER['REQUEST_METHOD'] == "GET") {
2022-09-04 14:49:44 +02:00
$table = strtolower(filter_input(INPUT_GET, 'table', FILTER_DEFAULT));
$delete = filter_input(INPUT_GET, 'delete', FILTER_DEFAULT);
$domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
$domain_key = array_search($domain, array_column($list_domains, 'domain'));
2022-08-18 14:01:52 +02:00
2022-09-04 14:49:44 +02:00
if (($table == 'alias' || $table == 'mailbox') && in_array($domain, array_column($list_domains, 'domain'))) {
try {
$dbh = connect_db();
$sth = $dbh->prepare("DELETE FROM alias WHERE address=? AND domain=?");
$sth->bindParam(1, $delete, PDO::PARAM_STR);
$sth->bindParam(2, $domain, PDO::PARAM_STR);
$sth->execute();
if ($sth->rowCount() != 1) {
throw new RuntimeException('alias');
}
logging($admin, $domain, "delete alias", $delete);
2022-08-18 14:01:52 +02:00
2022-09-04 14:49:44 +02:00
header("Location: list-virtual.php?domain=$domain");
exit;
} catch (RuntimeException $e) {
$message = $LANG['Delete_delete_error'] . "<b>$delete</b> (" . $e->getMessage() . ")!</span>";
} catch (PDOException $e) {
$message = $LANG['Delete_delete_error'] . "<b>$delete</b> (alias)!</span> " . $e-getMessage();
2022-08-18 14:01:52 +02:00
}
2022-09-04 14:49:44 +02:00
try {
$dbh = connect_db();
$sth = $dbh->prepare("DELETE FROM mailbox WHERE username=? AND domain=?");
$sth->bindParam(1, $delete, PDO::PARAM_STR);
$sth->bindParam(2, $domain, PDO::PARAM_STR);
$sth->execute();
if ($sth->rowCount() != 1) {
throw new RuntimeException('mailbox');
2022-08-18 14:01:52 +02:00
}
2022-09-04 14:49:44 +02:00
logging($admin, $domain, "delete mailbox", $delete);
2022-08-18 14:01:52 +02:00
2022-09-04 14:49:44 +02:00
$sth = $dbh->prepare("DELETE FROM vacation WHERE email=? AND domain=?");
$sth->bindParam(1, $delete, PDO::PARAM_STR);
$sth->bindParam(2, $domain, PDO::PARAM_STR);
$sth->execute();
2022-08-18 14:01:52 +02:00
2022-09-04 14:49:44 +02:00
header("Location: list-virtual.php?domain=$domain");
exit;
} catch (RuntimeException $e) {
$message = $LANG['Delete_delete_error'] . "<b>$delete</b> (" . $e->getMessage() . ")!</span>";
} catch (PDOException $e) {
$message = $LANG['Delete_delete_error'] . "<b>$delete</b> (mailbox)!</span>";
}
}
2022-08-18 14:01:52 +02:00
}
2022-09-04 14:49:44 +02:00
include './templates/header.tpl';
include './templates/menu.tpl';
include './templates/message.tpl';
include './templates/footer.tpl';
2022-08-18 14:01:52 +02:00
?>