Просмотр исходного кода

Update add domain

With new Doc root feature
Jaap Marcus 5 лет назад
Родитель
Сommit
2c1acbe56f
3 измененных файлов с 123 добавлено и 2 удалено
  1. 28 1
      web/add/web/index.php
  2. 38 0
      web/js/pages/add_web.js
  3. 57 1
      web/templates/admin/add_web.html

+ 28 - 1
web/add/web/index.php

@@ -94,6 +94,9 @@ if (!empty($_POST['ok'])) {
     $v_stats = escapeshellarg($_POST['v_stats']);
     $v_stats_user = $data[$v_domain]['STATS_USER'];
     $v_stats_password = $data[$v_domain]['STATS_PASSWORD'];
+    $v_custom_doc_domain = $_POST['v-custom-doc-domain'];
+    $v_custom_doc_folder = $_POST['v-custom-doc-folder'];
+    
     $v_ftp = $_POST['v_ftp'];
     $v_ftp_user = $_POST['v_ftp_user'];
     $v_ftp_password = $_POST['v_ftp_password'];
@@ -109,7 +112,8 @@ if (!empty($_POST['ok'])) {
     if ((!empty($_POST['v_ssl_crt'])) || (!empty($_POST['v_ssl_key']))) $v_adv = 'yes';
     if ((!empty($_POST['v_ssl_ca'])) || ($_POST['v_stats'] != 'none')) $v_adv = 'yes';
     if ((!empty($_POST['v_letsencrypt']))) $v_adv = 'yes';
-
+    if (!empty($_POST['v_custom_doc_root_check'])){$v_adv = 'yes'; $v_custom_doc_root = 1; }
+    
     // Check advanced features
     if (empty($_POST['v_dns'])) $v_dns = 'off';
     if (empty($_POST['v_mail'])) $v_mail = 'off';
@@ -227,6 +231,23 @@ if (!empty($_POST['ok'])) {
         unlink($v_stats_password);
         $v_stats_password = escapeshellarg($_POST['v_stats_password']);
     }
+     if ( !empty($_POST['v-custom-doc-domain']) && !empty($_POST['v_custom_doc_root_check']) && $v_custom_doc_root_prepath.$v_custom_doc_domain.'/public_html'.$v_custom_doc_folder != $v_custom_doc_root){
+        if($_POST['v-custom-doc-domain'] == $v_domain && empty($_POST['v-custom-doc-folder'])){
+
+        }else{
+            $v_custom_doc_domain = escapeshellarg($_POST['v-custom-doc-domain']);
+            $v_custom_doc_folder = escapeshellarg($_POST['v-custom-doc-folder']);
+            $v_domain = escapeshellarg(trim($_POST['v_domain']));
+            
+            exec(HESTIA_CMD."v-change-web-domain-docroot ".$user." ".$v_domain." ".$v_custom_doc_domain." ".$v_custom_doc_folder,  $output, $return_var);
+            check_return_code($return_var,$output);
+            unset($output);  
+            $v_custom_doc_root = 1; 
+        }
+    }else{
+        unset($v_custom_doc_root);
+    }   
+    
 
     // Restart DNS server
     if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) {
@@ -365,6 +386,12 @@ exec (HESTIA_CMD."v-list-web-stats json", $output, $return_var);
 $stats = json_decode(implode('', $output), true);
 unset($output);
 
+// Get all user domains 
+exec (HESTIA_CMD."v-list-web-domains ".escapeshellarg($user)." json", $output, $return_var);
+$user_domains = json_decode(implode('', $output), true);
+$user_domains = array_keys($user_domains);
+unset($output);
+
 // Render page
 render_page($user, $TAB, 'add_web');
 

+ 38 - 0
web/js/pages/add_web.js

@@ -1,3 +1,38 @@
+ App.Actions.WEB.update_custom_doc_root = function(elm, hint) {
+    var prepath = $('input[name="v-custom-doc-root_prepath"]').val();
+    var domain = $('select[name="v-custom-doc-domain"]').val();
+    var folder = $('input[name="v-custom-doc-folder"]').val();
+    console.log(domain, folder);
+    $('.custom_docroot_hint').html(prepath+domain+'/public_html/'+folder);
+}
+App.Listeners.DB.keypress_custom_folder = function() {
+    var ref = $('input[name="v-custom-doc-folder"]');
+    var current_rec = ref.val();
+    App.Actions.WEB.update_custom_doc_root(ref, current_rec);
+    
+    ref.bind('keypress input', function(evt) {
+        clearTimeout(window.frp_usr_tmt);
+        window.frp_usr_tmt = setTimeout(function() {
+            var elm = $(evt.target);
+            App.Actions.WEB.update_custom_doc_root(elm, $(elm).val());
+        });
+    });
+}
+
+App.Listeners.DB.change_custom_doc = function() {
+    var ref = $('select[name="v-custom-doc-domain"]');
+    var current_rec = ref.val();
+    ref.bind('change select', function(evt) {
+        clearTimeout(window.frp_usr_tmt);
+        window.frp_usr_tmt = setTimeout(function() {
+            var elm = $(evt.target);
+            App.Actions.WEB.update_custom_doc_root(elm, $(elm).val());
+            var domain = $('.ftp-path-prefix').text(GLOBAL.FTP_USER_PREPATH + '/' + $(evt.target));
+
+        });
+    });
+}
+
 App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
     if (hint.trim() == '') {
         $(elm).parent().find('.hint').html('');
@@ -38,6 +73,9 @@ App.Listeners.WEB.keypress_domain_name = function() {
             //var elm = $(evt.target);
             //App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
             var domain = $('.ftp-path-prefix').text(GLOBAL.FTP_USER_PREPATH + '/' + $('#v_domain').val());
+            $('#v-custom-doc-domain-main').text($('#v_domain').val());
+            $('#v-custom-doc-domain-main').val($('#v_domain').val());
+            
         }, 100);
     });
 }

+ 57 - 1
web/templates/admin/add_web.html

@@ -195,7 +195,63 @@
                                     </table>
                                 </td>
                             </tr>
-
+                             <tr>
+                                <td class="vst-text step-top">
+                                    <label><input type="checkbox" size="20" class="vst-checkbox" name="v_custom_doc_root_check" <?php if (!empty($v_custom_doc_root)) echo "checked=yes" ?> onclick="javascript:elementHideShow('v_custom_doc_root');"> <?php print __('Custom document root');?></label>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td class="step-left">
+                                    <table style="display:<?php if (empty($v_custom_doc_root)) { echo 'none';} else {echo 'block';}?> ;" id="v_custom_doc_root">
+                                        <tr>
+                                            <td class="vst-text input-label">
+                                                <?php print __('Point to');?>
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td>
+                                                <input type="hidden" name="v-custom-doc-root_prepath"" value="<?php echo $v_custom_doc_root_prepath;?>">
+                                                <select class="vst-list" name="v-custom-doc-domain">
+                                                    <option value="<?=htmlentities(trim($v_domain, "'"))?>" id="v-custom-doc-domain-main"><?=htmlentities(trim($v_domain, "'"))?></option>
+                                                    <?php
+                                                    foreach ($user_domains  as $domain) {
+                                                        if($domain != $v_domain ){
+                                                        if($v_custom_doc_domain == $domain){
+                                                    ?>
+                                                            <option value="<?php echo $domain;?>" selected="selected"><?php echo $domain;?></option> 
+                                                    <?php
+                                                        }else{
+                                                     ?>
+                                                            <option value="<?php echo $domain;?>"><?php echo $domain;?></option> 
+                                                    <?php                                                           
+                                                        }
+                                                        }
+                                                    }
+                                                    ?>
+                                                </select>
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td class="vst-text input-label">
+                                                <?php print( __('Folder'));?>
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td>
+                                                <input type="text" size="20" class="vst-input"
+                                                name="v-custom-doc-folder" value="<?=htmlentities(trim($v_custom_doc_folder, "'"))?>">
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td>
+                                                <small class="custom_docroot_hint"></small>
+                                            </td>
+                                        </tr>
+                                        
+                                    </table>
+                                </td>
+                            </tr>
+                                                    
                         <tr>
                             <td class="step-top vst-text">
                                 <label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl" <?php if($v_ssl == 'yes' || $v_ssl == 'on') echo "checked=yes" ?> onclick="javascript:elementHideShow('ssltable');"> <?php print __('SSL Support');?></label>