| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100 |
- <?php
- use function Hestiacp\quoteshellarg\quoteshellarg;
- ob_start();
- $TAB = "MAIL";
- // Main include
- include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
- // Check domain argument
- if (empty($_GET["domain"])) {
- header("Location: /list/mail/");
- exit();
- }
- // Edit as someone else?
- if ($_SESSION["userContext"] === "admin" && !empty($_GET["user"])) {
- $user = quoteshellarg($_GET["user"]);
- $user_plain = htmlentities($_GET["user"]);
- }
- $v_username = $user;
- // List mail domain
- if (!empty($_GET["domain"]) && empty($_GET["account"])) {
- $v_domain = $_GET["domain"];
- exec(HESTIA_CMD . "v-list-sys-webmail json", $output, $return_var);
- $webmail_clients = json_decode(implode("", $output), true);
- unset($output);
- exec(
- HESTIA_CMD . "v-list-mail-domain " . $user . " " . quoteshellarg($v_domain) . " json",
- $output,
- $return_var,
- );
- $data = json_decode(implode("", $output), true);
- check_return_code_redirect($return_var, $output, "/list/mail/");
- unset($output);
- // Parse domain
- $v_antispam = $data[$v_domain]["ANTISPAM"];
- $v_reject = $data[$v_domain]["REJECT"];
- $v_antivirus = $data[$v_domain]["ANTIVIRUS"];
- $v_dkim = $data[$v_domain]["DKIM"];
- $v_catchall = $data[$v_domain]["CATCHALL"];
- $v_rate = $data[$v_domain]["RATE_LIMIT"];
- $v_date = $data[$v_domain]["DATE"];
- $v_time = $data[$v_domain]["TIME"];
- $v_suspended = $data[$v_domain]["SUSPENDED"];
- $v_webmail_alias = $data[$v_domain]["WEBMAIL_ALIAS"];
- $v_webmail = $data[$v_domain]["WEBMAIL"];
- $v_smtp_relay = $data[$v_domain]["U_SMTP_RELAY"];
- $v_smtp_relay_host = $data[$v_domain]["U_SMTP_RELAY_HOST"];
- $v_smtp_relay_port = $data[$v_domain]["U_SMTP_RELAY_PORT"];
- $v_smtp_relay_user = $data[$v_domain]["U_SMTP_RELAY_USERNAME"];
- if ($v_suspended == "yes") {
- $v_status = "suspended";
- } else {
- $v_status = "active";
- }
- $v_ssl = $data[$v_domain]["SSL"];
- if (!empty($v_ssl)) {
- exec(
- HESTIA_CMD .
- "v-list-mail-domain-ssl " .
- $user .
- " " .
- quoteshellarg($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"];
- }
- $v_letsencrypt = $data[$v_domain]["LETSENCRYPT"];
- if (empty($v_letsencrypt)) {
- $v_letsencrypt = "no";
- }
- }
- // List mail account
- if (!empty($_GET["domain"]) && !empty($_GET["account"])) {
- $v_domain = $_GET["domain"];
- $v_account = $_GET["account"];
- exec(
- HESTIA_CMD .
- "v-list-mail-account " .
- $user .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " 'json'",
- $output,
- $return_var,
- );
- $data = json_decode(implode("", $output), true);
- check_return_code_redirect($return_var, $output, "/list/mail/");
- unset($output);
- // Parse mail account
- $v_username = $user;
- $v_password = "";
- $v_aliases = str_replace(",", "\n", $data[$v_account]["ALIAS"]);
- $valiases = explode(",", $data[$v_account]["ALIAS"]);
- $v_fwd = str_replace(",", "\n", $data[$v_account]["FWD"]);
- if ($v_fwd == ":blackhole:") {
- $v_fwd = "";
- $v_blackhole = "yes";
- } else {
- $v_blackhole = "no";
- }
- $vfwd = explode(",", $data[$v_account]["FWD"]);
- $v_fwd_only = $data[$v_account]["FWD_ONLY"];
- $v_rate = $data[$v_account]["RATE_LIMIT"];
- $v_quota = $data[$v_account]["QUOTA"];
- $v_autoreply = $data[$v_account]["AUTOREPLY"];
- $v_suspended = $data[$v_account]["SUSPENDED"];
- $v_webmail_alias = $data[$v_account]["WEBMAIL_ALIAS"];
- if (empty($v_send_email)) {
- $v_send_email = "";
- }
- if ($v_suspended == "yes") {
- $v_status = "suspended";
- } else {
- $v_status = "active";
- }
- $v_date = $data[$v_account]["DATE"];
- $v_time = $data[$v_account]["TIME"];
- // Parse autoreply
- if ($v_autoreply == "yes") {
- exec(
- HESTIA_CMD .
- "v-list-mail-account-autoreply " .
- $user .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " json",
- $output,
- $return_var,
- );
- $autoreply_str = json_decode(implode("", $output), true);
- unset($output);
- $v_autoreply_message = $autoreply_str[$v_account]["MSG"];
- $v_autoreply_message = str_replace("\\n", "\n", $v_autoreply_message);
- } else {
- $v_autoreply_message = "";
- }
- }
- // Check POST request for mail domain
- if (!empty($_POST["save"]) && !empty($_GET["domain"]) && empty($_GET["account"])) {
- // Check token
- verify_csrf($_POST);
- exec(
- HESTIA_CMD . "v-list-mail-domain " . $user . " " . quoteshellarg($v_domain) . " json",
- $output,
- $return_var,
- );
- $data = json_decode(implode("", $output), true);
- check_return_code_redirect($return_var, $output, "/list/mail/");
- unset($output);
- // Delete antispam
- if ($v_antispam == "yes" && empty($_POST["v_antispam"]) && empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD .
- "v-delete-mail-domain-antispam " .
- $v_username .
- " " .
- quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_antispam = "no";
- unset($output);
- }
- // Add antispam
- if ($v_antispam == "no" && !empty($_POST["v_antispam"]) && empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD .
- "v-add-mail-domain-antispam " .
- $v_username .
- " " .
- quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_antispam = "yes";
- unset($output);
- }
- // Delete antivirus
- if ($v_antivirus == "yes" && empty($_POST["v_antivirus"]) && empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD .
- "v-delete-mail-domain-antivirus " .
- $v_username .
- " " .
- quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_antivirus = "no";
- unset($output);
- }
- // Add antivirus
- if ($v_antivirus == "no" && !empty($_POST["v_antivirus"]) && empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD .
- "v-add-mail-domain-antivirus " .
- $v_username .
- " " .
- quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_antivirus = "yes";
- unset($output);
- }
- // Delete DKIM
- if ($v_dkim == "yes" && empty($_POST["v_dkim"]) && empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD .
- "v-delete-mail-domain-dkim " .
- $v_username .
- " " .
- quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_dkim = "no";
- unset($output);
- }
- // Add DKIM
- if ($v_dkim == "no" && !empty($_POST["v_dkim"]) && empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD . "v-add-mail-domain-dkim " . $v_username . " " . quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_dkim = "yes";
- unset($output);
- }
- // Delete catchall
- if (!empty($v_catchall) && empty($_POST["v_catchall"]) && empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD .
- "v-delete-mail-domain-catchall " .
- $v_username .
- " " .
- quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_catchall = "";
- unset($output);
- }
- // Change rate limit
- if (
- $v_rate != $_POST["v_rate"] &&
- empty($_SESSION["error_msg"]) &&
- $_SESSION["userContext"] == "admin"
- ) {
- if (empty($_POST["v_rate"])) {
- $v_rate = "system";
- } else {
- $v_rate = quoteshellarg($_POST["v_rate"]);
- }
- exec(
- HESTIA_CMD .
- "v-change-mail-domain-rate-limit " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- $v_rate,
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- if ($v_rate == "system") {
- $v_rate = "";
- }
- unset($output);
- }
- if (!empty($_POST["v_reject"]) && $v_antispam == "yes" && $v_reject != "yes") {
- exec(
- HESTIA_CMD . "v-add-mail-domain-reject " . $user . " " . $v_domain . " yes",
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_reject = "yes";
- unset($output);
- }
- if (empty($_POST["v_reject"]) && $v_reject == "yes") {
- exec(
- HESTIA_CMD . "v-delete-mail-domain-reject " . $user . " " . $v_domain . " yes",
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_reject = "";
- unset($output);
- }
- // Change catchall address
- if (!empty($v_catchall) && !empty($_POST["v_catchall"]) && empty($_SESSION["error_msg"])) {
- if ($v_catchall != $_POST["v_catchall"]) {
- $v_catchall = quoteshellarg($_POST["v_catchall"]);
- exec(
- HESTIA_CMD .
- "v-change-mail-domain-catchall " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- $v_catchall,
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- }
- // Add catchall
- if (empty($v_catchall) && !empty($_POST["v_catchall"]) && empty($_SESSION["error_msg"])) {
- $v_catchall = quoteshellarg($_POST["v_catchall"]);
- exec(
- HESTIA_CMD .
- "v-add-mail-domain-catchall " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- $v_catchall,
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- if (!empty($_SESSION["IMAP_SYSTEM"]) && !empty($_SESSION["WEBMAIL_SYSTEM"])) {
- if (empty($_SESSION["error_msg"])) {
- if (!empty($_POST["v_webmail"])) {
- $v_webmail = quoteshellarg($_POST["v_webmail"]);
- exec(
- HESTIA_CMD .
- "v-add-mail-domain-webmail " .
- $user .
- " " .
- $v_domain .
- " " .
- $v_webmail .
- " yes",
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- }
- }
- if (!empty($_SESSION["IMAP_SYSTEM"]) && !empty($_SESSION["WEBMAIL_SYSTEM"])) {
- if (empty($_POST["v_webmail"])) {
- if (empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD . "v-delete-mail-domain-webmail " . $user . " " . $v_domain . " yes",
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- $v_webmail = "";
- unset($output);
- }
- }
- }
- // Change SSL certificate
- if (
- $v_letsencrypt == "no" &&
- empty($_POST["v_letsencrypt"]) &&
- $v_ssl == "yes" &&
- !empty($_POST["v_ssl"]) &&
- empty($_SESSION["error_msg"])
- ) {
- if (
- $v_ssl_crt != str_replace("\r\n", "\n", $_POST["v_ssl_crt"]) ||
- $v_ssl_key != str_replace("\r\n", "\n", $_POST["v_ssl_key"]) ||
- $v_ssl_ca != str_replace("\r\n", "\n", $_POST["v_ssl_ca"])
- ) {
- 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"]));
- fwrite($fp, "\n");
- 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"]));
- fwrite($fp, "\n");
- 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"]));
- fwrite($fp, "\n");
- fclose($fp);
- }
- exec(
- HESTIA_CMD .
- "v-change-mail-domain-sslcert " .
- $user .
- " " .
- quoteshellarg($v_domain) .
- " " .
- $tmpdir .
- " 'no'",
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- $restart_web = "yes";
- $restart_proxy = "yes";
- exec(
- HESTIA_CMD .
- "v-list-mail-domain-ssl " .
- $user .
- " " .
- quoteshellarg($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);
- }
- }
- // Delete Lets Encrypt support
- if (
- $v_letsencrypt == "yes" &&
- (empty($_POST["v_letsencrypt"]) || empty($_POST["v_ssl"])) &&
- empty($_SESSION["error_msg"])
- ) {
- exec(
- HESTIA_CMD .
- "v-delete-letsencrypt-domain " .
- $user .
- " " .
- quoteshellarg($v_domain) .
- " '' 'yes'",
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- $v_ssl_crt = "";
- $v_ssl_key = "";
- $v_ssl_ca = "";
- $v_letsencrypt = "no";
- $v_letsencrypt_deleted = "yes";
- $v_ssl = "no";
- $restart_mail = "yes";
- }
- // Delete SSL certificate
- if ($v_ssl == "yes" && empty($_POST["v_ssl"]) && empty($_SESSION["error_msg"])) {
- exec(
- HESTIA_CMD . "v-delete-mail-domain-ssl " . $v_username . " " . quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- $v_ssl_crt = "";
- $v_ssl_key = "";
- $v_ssl_ca = "";
- $v_ssl = "no";
- $restart_mail = "yes";
- }
- // Add Lets Encrypt support
- if (
- !empty($_POST["v_ssl"]) &&
- $v_letsencrypt == "no" &&
- !empty($_POST["v_letsencrypt"]) &&
- empty($_SESSION["error_msg"])
- ) {
- exec(
- HESTIA_CMD .
- "v-add-letsencrypt-domain " .
- $user .
- " " .
- quoteshellarg($v_domain) .
- " ' ' 'yes'",
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- $v_letsencrypt = "yes";
- $v_ssl = "yes";
- $restart_mail = "yes";
- }
- // Add SSL certificate
- if (
- $v_ssl == "no" &&
- !empty($_POST["v_ssl"]) &&
- empty($v_letsencrypt_deleted) &&
- empty($_SESSION["error_msg"])
- ) {
- if (empty($_POST["v_ssl_crt"])) {
- $errors[] = "ssl certificate";
- }
- if (empty($_POST["v_ssl_key"])) {
- $errors[] = "ssl key";
- }
- if (!empty($errors[0])) {
- foreach ($errors as $i => $error) {
- if ($i == 0) {
- $error_msg = $error;
- } else {
- $error_msg = $error_msg . ", " . $error;
- }
- }
- $_SESSION["error_msg"] = sprintf(_('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 .
- " " .
- quoteshellarg($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 .
- " " .
- quoteshellarg($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);
- }
- }
- // Add SMTP Relay Support
- if (empty($_SESSION["error_msg"])) {
- if (isset($_POST["v_smtp_relay"]) && !empty($_POST["v_smtp_relay_host"])) {
- if (
- $_POST["v_smtp_relay_host"] != $v_smtp_relay_host ||
- $_POST["v_smtp_relay_user"] != $v_smtp_relay_user ||
- $_POST["v_smtp_relay_port"] != $v_smtp_relay_port
- ) {
- $v_smtp_relay = true;
- $v_smtp_relay_host = quoteshellarg($_POST["v_smtp_relay_host"]);
- $v_smtp_relay_user = quoteshellarg($_POST["v_smtp_relay_user"]);
- $v_smtp_relay_pass = quoteshellarg($_POST["v_smtp_relay_pass"]);
- if (!empty($_POST["v_smtp_relay_port"])) {
- $v_smtp_relay_port = quoteshellarg($_POST["v_smtp_relay_port"]);
- } else {
- $v_smtp_relay_port = "587";
- }
- exec(
- HESTIA_CMD .
- "v-add-mail-domain-smtp-relay " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- $v_smtp_relay_host .
- " " .
- $v_smtp_relay_user .
- " " .
- $v_smtp_relay_pass .
- " " .
- $v_smtp_relay_port,
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- }
- if (!isset($_POST["v_smtp_relay"]) && $v_smtp_relay == true) {
- $v_smtp_relay = false;
- $v_smtp_relay_host = $v_smtp_relay_user = $v_smtp_relay_pass = $v_smtp_relay_port = "";
- exec(
- HESTIA_CMD .
- "v-delete-mail-domain-smtp-relay " .
- $v_username .
- " " .
- quoteshellarg($v_domain),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- }
- // Set success message
- if (empty($_SESSION["error_msg"])) {
- $_SESSION["ok_msg"] = _("Changes have been saved.");
- }
- }
- // Check POST request for mail account
- if (!empty($_POST["save"]) && !empty($_GET["domain"]) && !empty($_GET["account"])) {
- // Check token
- verify_csrf($_POST);
- // 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_account = $_POST["v_account"];
- $v_send_email = $_POST["v_send_email"];
- $v_credentials = $_POST["v_credentials"];
- exec(
- HESTIA_CMD .
- "v-list-mail-account " .
- $user .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " json",
- $output,
- $return_var,
- );
- $data = json_decode(implode("", $output), true);
- check_return_code_redirect($return_var, $output, "/list/mail/");
- unset($output);
- // Change password
- if (!empty($_POST["v_password"]) && empty($_SESSION["error_msg"])) {
- if (!validate_password($_POST["v_password"])) {
- $_SESSION["error_msg"] = _("Password does not match the minimum requirements");
- } else {
- $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 .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " " .
- $v_password,
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- unlink($v_password);
- $v_password = quoteshellarg($_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 = quoteshellarg($_POST["v_quota"]);
- }
- exec(
- HESTIA_CMD .
- "v-change-mail-account-quota " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " " .
- $v_quota,
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- // Change rate limit
- if (
- $v_rate != $_POST["v_rate"] &&
- empty($_SESSION["error_msg"]) &&
- $_SESSION["userContext"] == "admin"
- ) {
- if (empty($_POST["v_rate"])) {
- $v_rate = "system";
- } else {
- $v_rate = quoteshellarg($_POST["v_rate"]);
- }
- exec(
- HESTIA_CMD .
- "v-change-mail-account-rate-limit " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " " .
- $v_rate,
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- if ($v_rate == "system") {
- $v_rate = "";
- }
- 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 .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " " .
- quoteshellarg($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 .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " " .
- quoteshellarg($alias),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- }
- }
- // Change forwarders to :blackhole:
- if (empty($_SESSION["error_msg"]) && !empty($_POST["v_blackhole"])) {
- foreach ($vfwd as $forward) {
- if (empty($_SESSION["error_msg"]) && !empty($forward)) {
- exec(
- HESTIA_CMD .
- "v-delete-mail-account-forward " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " " .
- quoteshellarg($forward),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- exec(
- HESTIA_CMD .
- "v-add-mail-account-forward " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " :blackhole:",
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- $v_fwd = "";
- $v_blackhole = "yes";
- }
- }
- // Change forwarders
- if (empty($_SESSION["error_msg"]) && empty($_POST["v_blackhole"])) {
- $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 .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " " .
- quoteshellarg($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 .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($v_account) .
- " " .
- quoteshellarg($forward),
- $output,
- $return_var,
- );
- check_return_code($return_var, $output);
- unset($output);
- }
- }
- $v_blackhole = "no";
- }
- // 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 .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($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 .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($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 .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($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 = quoteshellarg($v_autoreply_message);
- exec(
- HESTIA_CMD .
- "v-add-mail-account-autoreply " .
- $v_username .
- " " .
- quoteshellarg($v_domain) .
- " " .
- quoteshellarg($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 = get_hostname();
- $from = "noreply@" . $hostname;
- $from_name = _("Hestia Control Panel");
- $mailtext = $v_credentials;
- send_email($to, $subject, $mailtext, $from, $from_name);
- }
- // Set success message
- if (empty($_SESSION["error_msg"])) {
- $_SESSION["ok_msg"] = _("Changes have 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"]);
|