// Copyright (c) 2022 High5! // License Info: LICENSE.TXT // // File: edit-mailbox.php // // Template File: edit-mailbox.tpl // // Template Variables: // // message // name // // POST / GET Variables: // // username // domain // password1 // password2 // name // require_once './functions.inc.php'; include './languages/' . check_language() . '.lang'; $SESSID_USERNAME = check_session(); $ROLE = check_role($SESSID_USERNAME); if ($ROLE == ADMIN_ROLE) { $list_domains = list_domains(); $list_admins = list_admins(); } else { $list_domains = list_domains($SESSID_USERNAME); } if ($_SERVER['REQUEST_METHOD'] == "GET") { $username = filter_input(INPUT_GET, 'username', FILTER_DEFAULT); $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN); $domain_key = array_search($domain, array_column($list_domains, 'domain')); $domain_exist = in_array($domain, array_column($list_domains, 'domain')); if ($domain_exist) { try { $dbh = pdo_connect(); $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); $domain_key = array_search($domain, array_column($list_domains, 'domain')); $domain_exist = in_array($domain, array_column($list_domains, 'domain')); if ($password1 != $password2) { $message = $LANG['Edit_mailbox_password_text_error']; } if (empty($message) && isset($domain_key) && !empty($password1)) { $hashed = bcrypt($password1); try { $dbh = pdo_connect(); $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 ($domain_exist && empty($message)) { try { $dbh = pdo_connect(); $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($SESSID_USERNAME, $domain, $LANG['Logging_mailbox_edit'], $username); header("Location: list-virtual.php?domain=$domain"); } catch(PDOException $e) { $message = $LANG['Edit_mailbox_result_error']; } } } include './templates/header.tpl'; include './templates/menu.tpl'; include './templates/edit-mailbox.tpl'; include './templates/footer.tpl'; ?>