91 lines
2.7 KiB
PHP
91 lines
2.7 KiB
PHP
<?php
|
|
//
|
|
// OpenSMTPD Admin
|
|
// by Mischa Peters <mischa at high5 dot nl>
|
|
// Copyright (c) 2022 High5!
|
|
// License Info: LICENSE.TXT
|
|
//
|
|
// File: edit-mailbox.php
|
|
//
|
|
// Template File: edit-mailbox.tpl
|
|
//
|
|
// Template Variables:
|
|
//
|
|
// message
|
|
// name
|
|
//
|
|
// Form POST \ GET Variables:
|
|
//
|
|
// username
|
|
// domain
|
|
// password1
|
|
// password2
|
|
// name
|
|
//
|
|
require_once '../functions.inc.php';
|
|
include '../languages/' . check_language() . '.lang';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
|
$username = strtolower(filter_input(INPUT_GET, 'username', FILTER_DEFAULT));
|
|
$domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
|
|
|
|
try {
|
|
$dbh = connect_db();
|
|
$sth = $dbh->prepare("SELECT * FROM mailbox WHERE username=? AND domain=?");
|
|
$sth->bindParam(1, $username, PDO::PARAM_STR);
|
|
$sth->bindParam(2, $domain, PDO::PARAM_STR);
|
|
$sth->execute();
|
|
$mailbox_details = $sth->fetch();
|
|
$name = $mailbox_details['name'];
|
|
} catch(PDOException $e) {
|
|
$message = $LANG['Edit_mailbox_login_error'];
|
|
}
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|
$username = strtolower(filter_input(INPUT_GET, 'username', FILTER_DEFAULT));
|
|
$domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
|
|
$password1 = filter_input(INPUT_POST, 'password1', FILTER_DEFAULT);
|
|
$password2 = filter_input(INPUT_POST, 'password2', FILTER_DEFAULT);
|
|
$name = filter_input(INPUT_POST, 'name', FILTER_DEFAULT);
|
|
|
|
if ($password1 != $password2) {
|
|
$message = $LANG['Edit_mailbox_password_text_error'];
|
|
}
|
|
|
|
if (!empty($pqassword1) && empty($message)) {
|
|
$hashed = bcrypt($password1);
|
|
try {
|
|
$dbh = connect_db();
|
|
$sth = $dbh->prepare("UPDATE mailbox SET password=?,name=?,modified=NOW() WHERE username=? AND domain=?");
|
|
$sth->bindParam(1, $hashed, PDO::PARAM_STR);
|
|
$sth->bindParam(2, $name, PDO::PARAM_STR);
|
|
$sth->bindParam(3, $username, PDO::PARAM_STR);
|
|
$sth->bindParam(4, $domain, PDO::PARAM_STR);
|
|
$sth->execute();
|
|
} catch(PDOException $e) {
|
|
$message = $LANG['Edit_mailbox_result_error'];
|
|
}
|
|
}
|
|
|
|
if (empty($message)) {
|
|
try {
|
|
$dbh = connect_db();
|
|
$sth = $dbh->prepare("UPDATE mailbox SET name=?,modified=NOW() WHERE username=? AND domain=?");
|
|
$sth->bindParam(1, $name, PDO::PARAM_STR);
|
|
$sth->bindParam(2, $username, PDO::PARAM_STR);
|
|
$sth->bindParam(3, $domain, PDO::PARAM_STR);
|
|
$sth->execute();
|
|
logging(ADMIN_EMAIL, $domain, "edit mailbox", $username);
|
|
header("Location: list-virtual.php?domain=$domain");
|
|
} catch(PDOException $e) {
|
|
$message = $LANG['Edit_mailbox_result_error'];
|
|
}
|
|
}
|
|
}
|
|
include '../templates/header.tpl';
|
|
include '../templates/admin_menu.tpl';
|
|
include '../templates/edit-mailbox.tpl';
|
|
include '../templates/footer.tpl';
|
|
?>
|