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

Merge branch 'feature/867_addon-domain-support-ui' into origin/feature/867_addon-domain-support

Kristan Kenney 5 лет назад
Родитель
Сommit
220a8009c9

+ 3 - 3
bin/v-add-web-domain-backend

@@ -44,9 +44,9 @@ prepare_web_backend
 get_domain_values 'web'
 
 # Checking backend configuration
-if [ -e "$pool/$backend_type.conf" ]; then
-    exit
-fi
+#if [ -e "$pool/$backend_type.conf" ]; then
+#    exit
+#fi
 
 # Allocating backend port
 backend_port=9000

+ 1 - 0
bin/v-list-web-domain

@@ -41,6 +41,7 @@ json_list() {
         "BACKEND": "'$BACKEND'",
         "PROXY": "'$PROXY'",
         "PROXY_EXT": "'$PROXY_EXT'",
+        "CUSTOM_DOCROOT": "'$CUSTOM_DOCROOT'",
         "SUSPENDED": "'$SUSPENDED'",
         "TIME": "'$TIME'",
         "DATE": "'$DATE'"

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

@@ -94,6 +94,10 @@ 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_custom_doc_root_prepath = '/home/'.$user.'/web/';
+    
     $v_ftp = $_POST['v_ftp'];
     $v_ftp_user = $_POST['v_ftp_user'];
     $v_ftp_password = $_POST['v_ftp_password'];
@@ -109,7 +113,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 +232,24 @@ 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']))) {
@@ -354,6 +377,7 @@ if (!empty($_POST['ok'])) {
 // Define user variables
 $v_ftp_user_prepath = $panel[$user]['HOME'] . "/web";
 $v_ftp_email = $panel[$user]['CONTACT'];
+$v_custom_doc_root_prepath = '/home/'.$user.'/web/';
 
 // List IP addresses
 exec (HESTIA_CMD."v-list-user-ips ".$user." json", $output, $return_var);
@@ -365,6 +389,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');
 

+ 40 - 2
web/edit/web/index.php

@@ -73,11 +73,24 @@ $v_proxy_ext = str_replace(',', ', ', $data[$v_domain]['PROXY_EXT']);
 $v_stats = $data[$v_domain]['STATS'];
 $v_stats_user = $data[$v_domain]['STATS_USER'];
 if (!empty($v_stats_user)) $v_stats_password = "";
+$v_custom_doc_root_prepath = '/home/'.$v_username.'/web/';
+$v_custom_doc_root = $data[$v_domain]['CUSTOM_DOCROOT'];
+
+$m = preg_match('/\/home\/'.$v_username.'\/web\/([A-Za-z0-9.-].*)\/([A-Za-z0-9.-\/].*)/', $v_custom_doc_root, $matches);
+$v_custom_doc_domain = $matches[1];
+$v_custom_doc_folder = str_replace('public_html/','',$matches[2]);
+
 $v_ftp_user = $data[$v_domain]['FTP_USER'];
 $v_ftp_path = $data[$v_domain]['FTP_PATH'];
 if (!empty($v_ftp_user)) $v_ftp_password = "";
-$v_ftp_user_prepath = $data[$v_domain]['DOCUMENT_ROOT'];
-$v_ftp_user_prepath = str_replace('/public_html', '', $v_ftp_user_prepath, $occurance = 1);
+
+if($v_custom_doc_domain != ''){
+    $v_ftp_user_prepath = '/home/'.$v_username.'/web/'.$v_custom_doc_domain;
+}else{
+    $v_ftp_user_prepath = '/home/'.$v_username.'/web/'.$v_domain;
+}
+
+
 $v_ftp_email = $panel[$user]['CONTACT'];
 $v_suspended = $data[$v_domain]['SUSPENDED'];
 if ( $v_suspended == 'yes' ) {
@@ -736,6 +749,31 @@ if (!empty($_POST['save'])) {
             }
         }
     }
+    //custom docoot with check box disabled      
+    if( !empty($v_custom_doc_root) && empty($_POST['v_custom_doc_root_check']) ){
+        exec(HESTIA_CMD."v-change-web-domain-docroot ".$v_username." ".escapeshellarg($v_domain)." default",  $output, $return_var);
+        check_return_code($return_var,$output);
+        unset($output);    
+        unset($_POST['v-custom-doc-domain'], $_POST['v-custom-doc-folder']);    
+    }
+
+    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'])){
+            exec(HESTIA_CMD."v-change-web-domain-docroot ".$v_username." ".escapeshellarg($v_domain)." default",  $output, $return_var);
+            check_return_code($return_var,$output);
+            unset($output);     
+        }else{
+            $v_custom_doc_domain = escapeshellarg($_POST['v-custom-doc-domain']);
+            $v_custom_doc_folder = escapeshellarg($_POST['v-custom-doc-folder']);
+        
+            exec(HESTIA_CMD."v-change-web-domain-docroot ".$v_username." ".escapeshellarg($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 web server
     if (!empty($restart_web) && (empty($_SESSION['error_msg']))) {

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

@@ -1,3 +1,43 @@
+ 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));
+
+        });
+    });
+}
+
+// Page entry point
+// Trigger listeners
+App.Listeners.DB.keypress_custom_folder();
+App.Listeners.DB.change_custom_doc();
+
 App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
     if (hint.trim() == '') {
         $(elm).parent().find('.hint').html('');
@@ -38,6 +78,10 @@ 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());
+            App.Actions.WEB.update_custom_doc_root(13, 12);
+            
         }, 100);
     });
 }

+ 39 - 0
web/js/pages/edit_web.js

@@ -1,3 +1,42 @@
+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());
+        });
+    });
+}
+
+// Page entry point
+// Trigger listeners
+App.Listeners.DB.keypress_custom_folder();
+App.Listeners.DB.change_custom_doc();
+
 App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
     if (hint.trim() == '') {
         $(elm).parent().find('.hint').html('');

+ 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'));?> <span class="optional">(<?php print __('optional');?>)</span>
+                                            </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>

+ 57 - 0
web/templates/admin/edit_web.html

@@ -243,6 +243,63 @@
                                 </td>
                             </tr>
                             <?php } ?>
+                            <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="<?php echo $v_domain;?>"><?php echo $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'));?> <span class="optional">(<?php print __('optional');?>)</span>
+                                            </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="vst-text step-top">
                                     <label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl" <?php if ($v_ssl == 'yes') echo "checked=yes" ?> onclick="javascript:elementHideShow('ssltable');"> <?php print __('SSL Support');?></label>

+ 57 - 0
web/templates/user/edit_web.html

@@ -256,6 +256,63 @@
                                 </td>
                             </tr>
                             <?php } ?>
+                            <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="<?php echo $v_domain;?>"><?php echo $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'));?> <span class="optional">(<?php print __('optional');?>)</span>
+                                            </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="vst-text step-top">
                                     <label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl" <?php if ($v_ssl == 'yes') echo "checked=yes" ?> onclick="javascript:elementHideShow('ssltable');"> <?php print __('SSL Support');?></label>