Преглед изворни кода

Sending mail credentials to email

dpeca пре 8 година
родитељ
комит
8c1deb80f7
4 измењених фајлова са 64 додато и 7 уклоњено
  1. 20 0
      web/add/mail/index.php
  2. 1 1
      web/inc/main.php
  3. 26 0
      web/js/pages/add_mail_acc.js
  4. 17 6
      web/templates/admin/add_mail_acc.html

+ 20 - 0
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]));

+ 1 - 1
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;
 

+ 26 - 0
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();
     });
 });

+ 17 - 6
web/templates/admin/add_mail_acc.html

@@ -118,6 +118,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>
@@ -185,15 +196,15 @@
                             <td><?=__('SMTP auth method')?>:</td>
                             <td><div><?=__('Normal password')?></div></td>
                         </tr>
-			<?
-			  list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
-			  $webmail = "http://".$http_host."/webmail/";
-			  if (!empty($_SESSION['MAIL_URL'])) $webmail = $_SESSION['MAIL_URL'];
-			  ?>
+            <?
+              list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
+              $webmail = "http://".$http_host."/webmail/";
+              if (!empty($_SESSION['MAIL_URL'])) $webmail = $_SESSION['MAIL_URL'];
+              ?>
                         <tr>
                             <td><?=__('Webmail URL')?>:</td>
                             <td><div><a class="vst" href="<?=$webmail?>" target="_blank"><?=$webmail?> <i></i></a></div></td>
-			</tr>
+            </tr>
                     </table>
                 </div>
             </td>