opensmtpdadmin/edit-mailbox.php

101 lines
3.1 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: edit-mailbox.php
//
// Template File: edit-mailbox.tpl
//
// Template Variables:
//
2022-09-04 14:49:44 +02:00
// message
// name
2022-08-18 14:01:52 +02:00
//
// Form POST \ GET Variables:
//
2022-09-04 14:49:44 +02:00
// username
// domain
// password1
// password2
// name
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
$username = strtolower(filter_input(INPUT_GET, 'username', FILTER_DEFAULT));
$domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
2022-09-04 16:04:56 +02:00
$domain_key = array_search($domain, array_column($list_domains, 'domain'));
$domain_exist = in_array($domain, array_column($list_domains, 'domain'));
2022-08-18 14:01:52 +02:00
2022-09-04 16:04:56 +02:00
if ($domain_exist) {
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'];
}
2022-08-18 14:01:52 +02:00
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
2022-09-04 14:49:44 +02:00
$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);
2022-09-04 16:04:56 +02:00
$domain_key = array_search($domain, array_column($list_domains, 'domain'));
$domain_exist = in_array($domain, array_column($list_domains, 'domain'));
2022-08-18 14:01:52 +02:00
2022-09-04 14:49:44 +02:00
if ($password1 != $password2) {
$message = $LANG['Edit_mailbox_password_text_error'];
2022-08-18 14:01:52 +02:00
}
2022-09-04 14:49:44 +02:00
if (empty($message) && isset($domain_key) && !empty($password1)) {
$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'];
}
2022-08-18 14:01:52 +02:00
}
2022-09-04 16:04:56 +02:00
if ($domain_exist && empty($message)) {
2022-09-04 14:49:44 +02:00
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, $domain, "edit mailbox", $username);
header("Location: list-virtual.php?domain=$domain");
} catch(PDOException $e) {
$message = $LANG['Edit_mailbox_result_error'];
}
2022-08-18 14:01:52 +02:00
}
}
2022-09-04 14:49:44 +02:00
include './templates/header.tpl';
2022-09-04 16:04:56 +02:00
include './templates/admin_menu.tpl';
2022-09-04 14:49:44 +02:00
include './templates/edit-mailbox.tpl';
include './templates/footer.tpl';
2022-08-18 14:01:52 +02:00
?>