From 8c1deb80f72d244bf98c581ecceaf696976efb0a Mon Sep 17 00:00:00 2001 From: dpeca Date: Sun, 9 Apr 2017 02:35:13 +0200 Subject: [PATCH] Sending mail credentials to email --- web/add/mail/index.php | 20 ++++++++++++++++++++ web/inc/main.php | 2 +- web/js/pages/add_mail_acc.js | 26 ++++++++++++++++++++++++++ web/templates/admin/add_mail_acc.html | 23 +++++++++++++++++------ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/web/add/mail/index.php b/web/add/mail/index.php index 02f765de1..8769c4638 100644 --- a/web/add/mail/index.php +++ b/web/add/mail/index.php @@ -94,15 +94,25 @@ if (!empty($_POST['ok_acc'])) { $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); } + // 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.'); + } + } + // Protect input $v_domain = escapeshellarg($_POST['v_domain']); $v_domain = strtolower($v_domain); $v_account = escapeshellarg($_POST['v_account']); $v_quota = escapeshellarg($_POST['v_quota']); + $v_send_email = $_POST['v_send_email']; + $v_credentials = $_POST['v_credentials']; $v_aliases = $_POST['v_aliases']; $v_fwd = $_POST['v_fwd']; if (empty($_POST['v_quota'])) $v_quota = 0; if ((!empty($_POST['v_quota'])) || (!empty($_POST['v_aliases'])) || (!empty($_POST['v_fwd'])) ) $v_adv = 'yes'; + $v_quota = escapeshellarg($_POST['v_quota']); // Add Mail Account if (empty($_SESSION['error_msg'])) { @@ -165,6 +175,16 @@ if (!empty($_POST['ok_acc'])) { if (!empty($_SESSION['MAIL_URL'])) $webmail = $_SESSION['MAIL_URL']; } + // 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); + } + // Flush field values on success if (empty($_SESSION['error_msg'])) { $_SESSION['ok_msg'] = __('MAIL_ACCOUNT_CREATED_OK',htmlentities(strtolower($_POST['v_account'])),htmlentities($_POST[v_domain]),htmlentities(strtolower($_POST['v_account'])),htmlentities($_POST[v_domain])); diff --git a/web/inc/main.php b/web/inc/main.php index 75482cd1b..2ec8b5fdb 100644 --- a/web/inc/main.php +++ b/web/inc/main.php @@ -3,7 +3,7 @@ session_start(); define('VESTA_CMD', '/usr/bin/sudo /usr/local/vesta/bin/'); -define('JS_LATEST_UPDATE', '1476144160'); +define('JS_LATEST_UPDATE', '1491697866'); $i = 0; diff --git a/web/js/pages/add_mail_acc.js b/web/js/pages/add_mail_acc.js index 35afca2fc..fa19a3b49 100644 --- a/web/js/pages/add_mail_acc.js +++ b/web/js/pages/add_mail_acc.js @@ -90,14 +90,37 @@ randomString = function() { $('#v_password').text(randomstring); else $('#v_password').text(Array(randomstring.length+1).join('*')); + generate_mail_credentials(); +} + +generate_mail_credentials = function() { + var div = $('.mail-infoblock').clone(); + div.find('#mail_configuration').remove(); + var pass=div.find('#v_password').text(); + if (pass=="") div.find('#v_password').html(' '); + var output = div.text(); + output=output.replace(/(?:\r\n|\r|\n|\t)/g, "|"); + output=output.replace(/ /g, ""); + output=output.replace(/\|\|/g, "|"); + output=output.replace(/\|\|/g, "|"); + output=output.replace(/\|\|/g, "|"); + output=output.replace(/^\|+/g, ""); + output=output.replace(/\|$/, ""); + output=output.replace(/ $/, ""); + output=output.replace(/:\|/g, ": "); + output=output.replace(/\|/g, "\n"); + //console.log(output); + $('#v_credentials').val(output); } $(document).ready(function() { $('#v_account').text($('input[name=v_account]').val()); $('#v_password').text($('input[name=v_password]').val()); + generate_mail_credentials(); $('input[name=v_account]').change(function(){ $('#v_account').text($(this).val()); + generate_mail_credentials(); }); $('input[name=v_password]').change(function(){ @@ -105,6 +128,7 @@ $(document).ready(function() { $('#v_password').text($(this).val()); else $('#v_password').text(Array($(this).val().length+1).join('*')); + generate_mail_credentials(); }); $('.toggle-psw-visibility-icon').click(function(){ @@ -112,6 +136,7 @@ $(document).ready(function() { $('#v_password').text($('input[name=v_password]').val()); else $('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*')); + generate_mail_credentials(); }); $('#mail_configuration').change(function(evt){ @@ -144,5 +169,6 @@ $(document).ready(function() { $('#td_smtp_encryption').html(opt.attr('no_encryption')); break; } + generate_mail_credentials(); }); }); diff --git a/web/templates/admin/add_mail_acc.html b/web/templates/admin/add_mail_acc.html index 5d3fbae8b..110a7ed98 100644 --- a/web/templates/admin/add_mail_acc.html +++ b/web/templates/admin/add_mail_acc.html @@ -118,6 +118,17 @@ + + + + + + + + "> + + + @@ -185,15 +196,15 @@ - + - +
:
: