Skip to content

Commit d858b1a

Browse files
authored
Fix hestiacp#1439 Allow template selection on creation. For “non” adminsitrative users default behavior has been coppied from edit web (hestiacp#1503)
1 parent 2be1a52 commit d858b1a

File tree

2 files changed

+136
-1
lines changed

2 files changed

+136
-1
lines changed

web/add/web/index.php

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,16 @@
104104
$v_ftp_email = $_POST['v_ftp_email'];
105105
if (!empty($v_domain)) $v_ftp_user_prepath .= $v_domain;
106106

107+
exec (HESTIA_CMD."v-list-user ".$user." json", $output, $return_var);
108+
$user_config = json_decode(implode('', $output), true);
109+
unset($output);
110+
111+
$v_template = $user_config[$user]['TEMPLATE'];
112+
$v_backend_template = $user_config[$user]['BACKEND_TEMPLATE'];
113+
$v_proxy_template = $user_config[$user]['PROXY_TEMPLATE'];
114+
107115
// Set advanced option checkmark
108-
if (!empty($_POST['v_proxy'])) $v_adv = 'yes';
116+
if (!empty($_POST['v_proxy'])) $v_adv = 'yes'; $v_proxy = "yes";
109117
if (!empty($_POST['v_ftp'])) $v_adv = 'yes';
110118
if ($_POST['v_proxy_ext'] != $v_proxy_ext) $v_adv = 'yes';
111119
if ((!empty($_POST['v_aliases'])) && ($_POST['v_aliases'] != 'www.'.$_POST['v_domain'])) $v_adv = 'yes';
@@ -161,6 +169,39 @@
161169
check_return_code($return_var,$output);
162170
unset($output);
163171
}
172+
173+
// Change template
174+
if (($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
175+
exec (HESTIA_CMD."v-change-web-domain-tpl ".$user." ".escapeshellarg($v_domain)." ".escapeshellarg($_POST['v_template'])." 'no'", $output, $return_var);
176+
check_return_code($return_var,$output);
177+
unset($output);
178+
$restart_web = 'yes';
179+
}
180+
// Change backend template
181+
if ((!empty($_SESSION['WEB_BACKEND'])) && ( $v_backend_template != $_POST['v_backend_template']) && ( $_SESSION['user'] == 'admin') && (empty($_SESSION['error_msg']))) {
182+
$v_backend_template = $_POST['v_backend_template'];
183+
exec (HESTIA_CMD."v-change-web-domain-backend-tpl ".$user." ".escapeshellarg($v_domain)." ".escapeshellarg($v_backend_template), $output, $return_var);
184+
check_return_code($return_var,$output);
185+
unset($output);
186+
}
187+
// Change proxy template / Update extension list
188+
if ((!empty($_SESSION['PROXY_SYSTEM'])) && (!empty($v_proxy)) && (!empty($_POST['v_proxy'])) && (empty($_SESSION['error_msg'])) ) {
189+
$ext = preg_replace("/\n/", " ", $_POST['v_proxy_ext']);
190+
$ext = preg_replace("/,/", " ", $ext);
191+
$ext = preg_replace('/\s+/', ' ',$ext);
192+
$ext = trim($ext);
193+
$ext = str_replace(' ', ", ", $ext);
194+
if (( $v_proxy_template != $_POST['v_proxy_template']) || ($v_proxy_ext != $ext)) {
195+
$ext = str_replace(', ', ",", $ext);
196+
if (!empty($_POST['v_proxy_template'])) $v_proxy_template = $_POST['v_proxy_template'];
197+
exec (HESTIA_CMD."v-change-web-domain-proxy-tpl ".$user." ".escapeshellarg($v_domain)." ".escapeshellarg($v_proxy_template)." ".escapeshellarg($ext)." 'no'", $output, $return_var);
198+
check_return_code($return_var,$output);
199+
$v_proxy_ext = str_replace(',', ', ', $ext);
200+
unset($output);
201+
$restart_proxy = 'yes';
202+
}
203+
}
204+
164205

165206
// Add Lets Encrypt support
166207
if ((!empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) {
@@ -403,6 +444,29 @@
403444
$v_ssl_forcessl = 'no';
404445
}
405446

447+
// List web templates and set default values
448+
exec (HESTIA_CMD."v-list-web-templates json", $output, $return_var);
449+
$templates = json_decode(implode('', $output), true);
450+
unset($output);
451+
$v_template = (!empty($_POST['v_template'])) ? $_POST['v_template'] : $user_config['WEB_TEMPLATE'];
452+
453+
// List backend templates
454+
if (!empty($_SESSION['WEB_BACKEND'])) {
455+
exec (HESTIA_CMD."v-list-web-templates-backend json", $output, $return_var);
456+
$backend_templates = json_decode(implode('', $output), true);
457+
unset($output);
458+
$v_backend_template = (!empty($_POST['v_backend_template'])) ? $_POST['v_backend_template'] : $user_config['BACKEND_TEMPLATE'];
459+
}
460+
461+
// List proxy templates
462+
if (!empty($_SESSION['PROXY_SYSTEM'])) {
463+
exec (HESTIA_CMD."v-list-web-templates-proxy json", $output, $return_var);
464+
$proxy_templates = json_decode(implode('', $output), true);
465+
unset($output);
466+
$v_proxy_template = (!empty($_POST['v_proxy_template'])) ? $_POST['v_proxy_template'] : $user_config['PROXY_TEMPLATE'];
467+
468+
}
469+
406470
// List IP addresses
407471
exec (HESTIA_CMD."v-list-user-ips ".$user." json", $output, $return_var);
408472
$ips = json_decode(implode('', $output), true);

web/templates/admin/add_web.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,83 @@
118118
<textarea size="20" class="vst-textinput short" name="v_aliases" id="v_aliases" ><?=htmlentities(trim($v_aliases, "'"))?></textarea>
119119
</td>
120120
</tr>
121+
<tr>
122+
<td class="vst-text input-label">
123+
<?php print _('Web Template') . "<span class='optional'>" .strtoupper($_SESSION['WEB_SYSTEM']) . "</span>";?>
124+
</td>
125+
</tr>
126+
<tr>
127+
<td>
128+
<select class="vst-list" name="v_template">
129+
<?php
130+
foreach ($templates as $key => $value) {
131+
echo "\t\t\t\t<option value=\"".htmlentities($value)."\"";
132+
$svalue = "'".$value."'";
133+
if ((!empty($v_template)) && ( $value == $v_template ) || ($svalue == $v_template)){
134+
echo ' selected' ;
135+
}
136+
echo ">".htmlentities($value)."</option>\n";
137+
}
138+
?>
139+
</select>
140+
</td>
141+
</tr>
142+
<?php if (!empty($_SESSION['WEB_BACKEND'])) { ?>
143+
<tr>
144+
<td class="vst-text input-label">
145+
<?php print _('Backend Template') . " <span class='optional'>" . strtoupper($_SESSION['WEB_BACKEND']) . "</span>";?>
146+
</td>
147+
</tr>
148+
<tr>
149+
<td>
150+
<select class="vst-list" name="v_backend_template">
151+
<?php
152+
foreach ($backend_templates as $key => $value) {
153+
echo "\t\t\t\t<option value=\"".$value."\"";
154+
$svalue = "'".$value."'";
155+
if ((!empty($v_backend_template)) && ( $value == $v_backend_template ) || ($svalue == $v_backend_template)){
156+
echo ' selected' ;
157+
}
158+
if ((empty($v_backend_template)) && ($value == 'default')){
159+
echo ' selected' ;
160+
}
161+
echo ">".htmlentities($value)."</option>\n";
162+
}
163+
?>
164+
</select>
165+
</td>
166+
</tr>
167+
<?php }?>
121168
<?php if (!empty($_SESSION['PROXY_SYSTEM'])) { echo ""; ?>
122169
<tr>
123170
<td class="vst-text step-top" >
124171
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_proxy" <?php if ($v_proxy !== 'off') echo "checked=yes" ?> onclick="javascript:elementHideShow('proxytable');"> <?php print _('Proxy Support');?></label>
125172
</td>
126173
</tr>
174+
<tr>
175+
<td class="vst-text input-label">
176+
<?php print _('Proxy Template');?>
177+
</td>
178+
</tr>
179+
<tr>
180+
<td>
181+
<select class="vst-list" name="v_proxy_template">
182+
<?php
183+
foreach ($proxy_templates as $key => $value) {
184+
echo "\t\t\t\t<option value=\"".htmlentities($value)."\"";
185+
$svalue = "'".$value."'";
186+
if ((!empty($v_proxy_template)) && ( $value == $v_proxy_template ) || ($svalue == $v_proxy_template)){
187+
echo ' selected' ;
188+
}
189+
if ((empty($v_proxy_template)) && ($value == 'default')){
190+
echo ' selected' ;
191+
}
192+
echo ">".htmlentities($value)."</option>\n";
193+
}
194+
?>
195+
</select>
196+
</td>
197+
</tr>
127198
<tr>
128199
<td>
129200
<table style="display:<?php if ($v_proxy == 'off') { echo 'none';} else {echo 'block';}?>;" id="proxytable" >

0 commit comments

Comments
 (0)