Sending mail credentials to email [edit form]

This commit is contained in:
dpeca 2017-04-14 14:50:15 +02:00
commit 9347c2aa04
4 changed files with 57 additions and 1 deletions

View file

@ -179,8 +179,17 @@ if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['acco
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 = escapeshellarg($_POST['v_domain']);
$v_account = escapeshellarg($_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']))) {
@ -297,6 +306,16 @@ if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['acco
}
}
// 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.');

View file

@ -3,7 +3,7 @@
session_start();
define('VESTA_CMD', '/usr/bin/sudo /usr/local/vesta/bin/');
define('JS_LATEST_UPDATE', '1491697866');
define('JS_LATEST_UPDATE', '1491697867');
$i = 0;

View file

@ -91,14 +91,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(){
@ -106,6 +129,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(){
@ -113,6 +137,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){
@ -145,5 +170,6 @@ $(document).ready(function() {
$('#td_smtp_encryption').html(opt.attr('no_encryption'));
break;
}
generate_mail_credentials();
});
});

View file

@ -125,6 +125,17 @@
</table>
</td>
</tr>
<tr>
<td class="vst-text input-label">
<?php print __('Send login credentials to email address') ?>
</td>
</tr>
<tr>
<td>
<input type="text" class="vst-input" name="v_send_email" value="<?=htmlentities(trim($v_send_email, "'"))?>">
<input type="hidden" name="v_credentials" id="v_credentials">
</td>
</tr>
</table>
<table class="data-col2">
<tr>