$error) { if ( $i == 0 ) { $error_msg = $error; } else { $error_msg = $error_msg.", ".$error; } } $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); } else { exec ('mktemp -d', $mktemp_output, $return_var); $tmpdir = $mktemp_output[0]; // Certificate if (!empty($_POST['v_ssl_crt'])) { $fp = fopen($tmpdir."/".$v_domain.".crt", 'w'); fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); fclose($fp); } // Key if (!empty($_POST['v_ssl_key'])) { $fp = fopen($tmpdir."/".$v_domain.".key", 'w'); fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); fclose($fp); } // CA if (!empty($_POST['v_ssl_ca'])) { $fp = fopen($tmpdir."/".$v_domain.".ca", 'w'); fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); fclose($fp); } exec (HESTIA_CMD."v-add-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." ".$tmpdir." 'no'", $output, $return_var); check_return_code($return_var,$output); unset($output); $v_ssl = 'yes'; $restart_web = 'yes'; $restart_proxy = 'yes'; exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." ".escapeshellarg($v_domain)." json", $output, $return_var); $ssl_str = json_decode(implode('', $output), true); unset($output); $v_ssl_crt = $ssl_str[$v_domain]['CRT']; $v_ssl_key = $ssl_str[$v_domain]['KEY']; $v_ssl_ca = $ssl_str[$v_domain]['CA']; $v_ssl_subject = $ssl_str[$v_domain]['SUBJECT']; $v_ssl_aliases = $ssl_str[$v_domain]['ALIASES']; $v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE']; $v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER']; $v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE']; $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY']; $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER']; // Cleanup certificate tempfiles if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$v_domain.".crt"); if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$v_domain.".key"); if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$v_domain.".ca"); rmdir($tmpdir); } } // Set success message if (empty($_SESSION['error_msg'])) { $_SESSION['ok_msg'] = __('Changes has been saved.'); } } // Check POST request for mail account if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['account']))) { // Check token if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) { header('location: /login/'); exit(); } // Validate email if ((!empty($_POST['v_send_email'])) && (empty($_SESSION['error_msg']))) { if (!filter_var($_POST['v_send_email'], FILTER_VALIDATE_EMAIL)) { $_SESSION['error_msg'] = __('Please enter valid email address.'); } } $v_domain = $_POST['v_domain']; if(!in_array($v_domain, $user_domains)) { check_return_code(3, ["Unknown domain"]); } $v_account = $_POST['v_account']; $v_send_email = $_POST['v_send_email']; $v_credentials = $_POST['v_credentials']; // Change password if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) { $v_password = tempnam("/tmp","vst"); $fp = fopen($v_password, "w"); fwrite($fp, $_POST['v_password']."\n"); fclose($fp); exec (HESTIA_CMD."v-change-mail-account-password ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_password, $output, $return_var); check_return_code($return_var,$output); unset($output); unlink($v_password); $v_password = escapeshellarg($_POST['v_password']);; } // Change quota if (($v_quota != $_POST['v_quota']) && (empty($_SESSION['error_msg']))) { if (empty($_POST['v_quota'])) { $v_quota = 0; } else { $v_quota = escapeshellarg($_POST['v_quota']); } exec (HESTIA_CMD."v-change-mail-account-quota ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_quota, $output, $return_var); check_return_code($return_var,$output); unset($output); } // Change account aliases if (empty($_SESSION['error_msg'])) { $waliases = preg_replace("/\n/", " ", $_POST['v_aliases']); $waliases = preg_replace("/,/", " ", $waliases); $waliases = preg_replace('/\s+/', ' ',$waliases); $waliases = trim($waliases); $aliases = explode(" ", $waliases); $v_aliases = str_replace(' ', "\n", $waliases); $result = array_diff($valiases, $aliases); foreach ($result as $alias) { if ((empty($_SESSION['error_msg'])) && (!empty($alias))) { exec (HESTIA_CMD."v-delete-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var); check_return_code($return_var,$output); unset($output); } } $result = array_diff($aliases, $valiases); foreach ($result as $alias) { if ((empty($_SESSION['error_msg'])) && (!empty($alias))) { exec (HESTIA_CMD."v-add-mail-account-alias ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($alias), $output, $return_var); check_return_code($return_var,$output); unset($output); } } } // Change forwarders if (empty($_SESSION['error_msg'])) { $wfwd = preg_replace("/\n/", " ", $_POST['v_fwd']); $wfwd = preg_replace("/,/", " ", $wfwd); $wfwd = preg_replace('/\s+/', ' ',$wfwd); $wfwd = trim($wfwd); $fwd = explode(" ", $wfwd); $v_fwd = str_replace(' ', "\n", $wfwd); $result = array_diff($vfwd, $fwd); foreach ($result as $forward) { if ((empty($_SESSION['error_msg'])) && (!empty($forward))) { exec (HESTIA_CMD."v-delete-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var); check_return_code($return_var,$output); unset($output); } } $result = array_diff($fwd, $vfwd); foreach ($result as $forward) { if ((empty($_SESSION['error_msg'])) && (!empty($forward))) { exec (HESTIA_CMD."v-add-mail-account-forward ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".escapeshellarg($forward), $output, $return_var); check_return_code($return_var,$output); unset($output); } } } // Delete FWD_ONLY flag if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) { exec (HESTIA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var); check_return_code($return_var,$output); unset($output); $v_fwd_only = ''; } // Add FWD_ONLY flag if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) { exec (HESTIA_CMD."v-add-mail-account-fwd-only ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var); check_return_code($return_var,$output); unset($output); $v_fwd_only = 'yes'; } // Delete autoreply if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) { exec (HESTIA_CMD."v-delete-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account), $output, $return_var); check_return_code($return_var,$output); unset($output); $v_autoreply = 'no'; $v_autoreply_message = ''; } // Add autoreply if ((!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) { if ( $v_autoreply_message != str_replace("\r\n", "\n", $_POST['v_autoreply_message'])) { $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']); $v_autoreply_message = escapeshellarg($v_autoreply_message); exec (HESTIA_CMD."v-add-mail-account-autoreply ".$v_username." ".escapeshellarg($v_domain)." ".escapeshellarg($v_account)." ".$v_autoreply_message, $output, $return_var); check_return_code($return_var,$output); unset($output); $v_autoreply = 'yes'; $v_autoreply_message = $_POST['v_autoreply_message']; } } // Email login credentials if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) { $to = $v_send_email; $subject = __("Email Credentials"); $hostname = exec('hostname'); $from = __('MAIL_FROM', $hostname); $mailtext = $v_credentials; send_email($to, $subject, $mailtext, $from); } // Set success message if (empty($_SESSION['error_msg'])) { $_SESSION['ok_msg'] = __('Changes has been saved.'); } } // Render page if (empty($_GET['account'])) { // Display body for mail domain render_page($user, $TAB, 'edit_mail'); } else { // Display body for mail account render_page($user, $TAB, 'edit_mail_acc'); } // Flush session messages unset($_SESSION['error_msg']); unset($_SESSION['ok_msg']);