Skip to content

Commit 8c1deb8

Browse files
committed
Sending mail credentials to email
1 parent a68dce9 commit 8c1deb8

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

web/add/mail/index.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,25 @@
9494
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
9595
}
9696

97+
// Validate email
98+
if ((!empty($_POST['v_send_email'])) && (empty($_SESSION['error_msg']))) {
99+
if (!filter_var($_POST['v_send_email'], FILTER_VALIDATE_EMAIL)) {
100+
$_SESSION['error_msg'] = __('Please enter valid email address.');
101+
}
102+
}
103+
97104
// Protect input
98105
$v_domain = escapeshellarg($_POST['v_domain']);
99106
$v_domain = strtolower($v_domain);
100107
$v_account = escapeshellarg($_POST['v_account']);
101108
$v_quota = escapeshellarg($_POST['v_quota']);
109+
$v_send_email = $_POST['v_send_email'];
110+
$v_credentials = $_POST['v_credentials'];
102111
$v_aliases = $_POST['v_aliases'];
103112
$v_fwd = $_POST['v_fwd'];
104113
if (empty($_POST['v_quota'])) $v_quota = 0;
105114
if ((!empty($_POST['v_quota'])) || (!empty($_POST['v_aliases'])) || (!empty($_POST['v_fwd'])) ) $v_adv = 'yes';
115+
$v_quota = escapeshellarg($_POST['v_quota']);
106116

107117
// Add Mail Account
108118
if (empty($_SESSION['error_msg'])) {
@@ -165,6 +175,16 @@
165175
if (!empty($_SESSION['MAIL_URL'])) $webmail = $_SESSION['MAIL_URL'];
166176
}
167177

178+
// Email login credentials
179+
if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
180+
$to = $v_send_email;
181+
$subject = __("Email Credentials");
182+
$hostname = exec('hostname');
183+
$from = __('MAIL_FROM', $hostname);
184+
$mailtext = $v_credentials;
185+
send_email($to, $subject, $mailtext, $from);
186+
}
187+
168188
// Flush field values on success
169189
if (empty($_SESSION['error_msg'])) {
170190
$_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]));

web/inc/main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
session_start();
44

55
define('VESTA_CMD', '/usr/bin/sudo /usr/local/vesta/bin/');
6-
define('JS_LATEST_UPDATE', '1476144160');
6+
define('JS_LATEST_UPDATE', '1491697866');
77

88
$i = 0;
99

web/js/pages/add_mail_acc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,53 @@ randomString = function() {
9090
$('#v_password').text(randomstring);
9191
else
9292
$('#v_password').text(Array(randomstring.length+1).join('*'));
93+
generate_mail_credentials();
94+
}
95+
96+
generate_mail_credentials = function() {
97+
var div = $('.mail-infoblock').clone();
98+
div.find('#mail_configuration').remove();
99+
var pass=div.find('#v_password').text();
100+
if (pass=="") div.find('#v_password').html(' ');
101+
var output = div.text();
102+
output=output.replace(/(?:\r\n|\r|\n|\t)/g, "|");
103+
output=output.replace(/ /g, "");
104+
output=output.replace(/\|\|/g, "|");
105+
output=output.replace(/\|\|/g, "|");
106+
output=output.replace(/\|\|/g, "|");
107+
output=output.replace(/^\|+/g, "");
108+
output=output.replace(/\|$/, "");
109+
output=output.replace(/ $/, "");
110+
output=output.replace(/:\|/g, ": ");
111+
output=output.replace(/\|/g, "\n");
112+
//console.log(output);
113+
$('#v_credentials').val(output);
93114
}
94115

95116
$(document).ready(function() {
96117
$('#v_account').text($('input[name=v_account]').val());
97118
$('#v_password').text($('input[name=v_password]').val());
119+
generate_mail_credentials();
98120

99121
$('input[name=v_account]').change(function(){
100122
$('#v_account').text($(this).val());
123+
generate_mail_credentials();
101124
});
102125

103126
$('input[name=v_password]').change(function(){
104127
if($('input[name=v_password]').attr('type') == 'text')
105128
$('#v_password').text($(this).val());
106129
else
107130
$('#v_password').text(Array($(this).val().length+1).join('*'));
131+
generate_mail_credentials();
108132
});
109133

110134
$('.toggle-psw-visibility-icon').click(function(){
111135
if($('input[name=v_password]').attr('type') == 'text')
112136
$('#v_password').text($('input[name=v_password]').val());
113137
else
114138
$('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*'));
139+
generate_mail_credentials();
115140
});
116141

117142
$('#mail_configuration').change(function(evt){
@@ -144,5 +169,6 @@ $(document).ready(function() {
144169
$('#td_smtp_encryption').html(opt.attr('no_encryption'));
145170
break;
146171
}
172+
generate_mail_credentials();
147173
});
148174
});

web/templates/admin/add_mail_acc.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@
118118
</table>
119119
</td>
120120
</tr>
121+
<tr>
122+
<td class="vst-text input-label">
123+
<?php print __('Send login credentials to email address') ?>
124+
</td>
125+
</tr>
126+
<tr>
127+
<td>
128+
<input type="text" class="vst-input" name="v_send_email" value="<?=htmlentities(trim($v_send_email, "'"))?>">
129+
<input type="hidden" name="v_credentials" id="v_credentials">
130+
</td>
131+
</tr>
121132
</table>
122133
<table class="data-col2">
123134
<tr>
@@ -185,15 +196,15 @@
185196
<td><?=__('SMTP auth method')?>:</td>
186197
<td><div><?=__('Normal password')?></div></td>
187198
</tr>
188-
<?
189-
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
190-
$webmail = "http://".$http_host."/webmail/";
191-
if (!empty($_SESSION['MAIL_URL'])) $webmail = $_SESSION['MAIL_URL'];
192-
?>
199+
<?
200+
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
201+
$webmail = "http://".$http_host."/webmail/";
202+
if (!empty($_SESSION['MAIL_URL'])) $webmail = $_SESSION['MAIL_URL'];
203+
?>
193204
<tr>
194205
<td><?=__('Webmail URL')?>:</td>
195206
<td><div><a class="vst" href="<?=$webmail?>" target="_blank"><?=$webmail?> <i></i></a></div></td>
196-
</tr>
207+
</tr>
197208
</table>
198209
</div>
199210
</td>

0 commit comments

Comments
 (0)