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
|
|
|
//
|
2022-09-05 20:29:41 +02:00
|
|
|
// POST / GET Variables:
|
2022-08-18 14:01:52 +02:00
|
|
|
//
|
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-06 13:56:05 +02:00
|
|
|
$ROLE = check_role($SESSID_USERNAME);
|
2022-08-18 14:01:52 +02:00
|
|
|
|
2022-09-05 22:24:35 +02:00
|
|
|
if ($ROLE == ADMIN_ROLE) {
|
2022-09-05 20:29:41 +02:00
|
|
|
$list_domains = list_domains();
|
|
|
|
$list_admins = list_admins();
|
|
|
|
} else {
|
|
|
|
$list_domains = list_domains($SESSID_USERNAME);
|
|
|
|
}
|
|
|
|
|
2022-08-18 14:01:52 +02:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
2022-09-06 13:56:05 +02:00
|
|
|
$username = filter_input(INPUT_GET, 'username', FILTER_DEFAULT);
|
2022-09-04 14:49:44 +02:00
|
|
|
$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'));
|
2022-08-18 14:01:52 +02:00
|
|
|
|
2022-09-06 14:29:52 +02:00
|
|
|
if (in_array($domain, array_column($list_domains, 'domain'))) {
|
2022-09-04 16:04:56 +02:00
|
|
|
try {
|
2022-09-04 20:50:21 +02:00
|
|
|
$dbh = pdo_connect();
|
2022-09-04 16:04:56 +02:00
|
|
|
$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'));
|
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 {
|
2022-09-04 20:50:21 +02:00
|
|
|
$dbh = pdo_connect();
|
2022-09-04 14:49:44 +02:00
|
|
|
$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-06 14:29:52 +02:00
|
|
|
if (empty($message) && in_array($domain, array_column($list_domains, 'domain'))) {
|
2022-09-04 14:49:44 +02:00
|
|
|
try {
|
2022-09-04 20:50:21 +02:00
|
|
|
$dbh = pdo_connect();
|
2022-09-04 14:49:44 +02:00
|
|
|
$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();
|
2022-09-05 22:24:35 +02:00
|
|
|
logging($SESSID_USERNAME, $domain, $LANG['Logging_mailbox_edit'], $username);
|
2022-09-04 14:49:44 +02:00
|
|
|
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-05 20:29:41 +02:00
|
|
|
include './templates/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
|
|
|
?>
|