Skip to content

Commit c52ff93

Browse files
author
Kristan Kenney
committed
Merge branch 'fix/1063_https-enablement' into staging/fixes
2 parents d222812 + 048391e commit c52ff93

File tree

7 files changed

+102
-11
lines changed

7 files changed

+102
-11
lines changed

bin/v-add-web-domain-ssl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
9696
cp -f $USER_DATA/ssl/$domain.ca $HOMEDIR/$user/conf/web/$domain/ssl/$domain.ca
9797
fi
9898

99+
if [ "$SSL_FORCE" == "yes" ]; then
100+
# Enabling SSL redirection on demand
101+
$BIN/v-add-web-domain-ssl-force "$user" "$domain"
102+
fi
99103
# Parsing domain values
100104
get_domain_values 'web'
101105
local_ip=$(get_real_ip $IP)
@@ -123,9 +127,6 @@ increase_user_value "$user" '$U_WEB_SSL'
123127
update_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME' "$SSL_HOME"
124128
update_object_value 'web' 'DOMAIN' "$domain" '$SSL' "yes"
125129

126-
# Enabling automatic SSL redirection
127-
$BIN/v-add-web-domain-ssl-force "$user" "$domain"
128-
129130
# Restarting web server
130131
$BIN/v-restart-web $restart
131132
check_result $? "Web restart failed" >/dev/null

bin/v-add-web-domain-ssl-preset

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# info: Adding force SSL for a domain
3+
# options: USER DOMAIN [SSL]
4+
# labels: hestia web
5+
#
6+
# example: v-add-web-domain-ssl-preset
7+
#
8+
# Up on creating an web domain set the SSL Force values due to the delay of LE due to DNS propergation over DNS cluster
9+
# When LE has been activated it will set the actions
10+
11+
#----------------------------------------------------------#
12+
# Variable&Function #
13+
#----------------------------------------------------------#
14+
15+
# Argument definition
16+
user=$1
17+
domain=$2
18+
ssl=$3
19+
20+
# Includes
21+
source $HESTIA/func/main.sh
22+
source $HESTIA/conf/hestia.conf
23+
24+
#----------------------------------------------------------#
25+
# Verifications #
26+
#----------------------------------------------------------#
27+
28+
check_args '2' "$#" 'USER DOMAIN [SSL]'
29+
is_format_valid 'user' 'domain' 'ssl'
30+
is_object_valid 'user' 'USER' "$user"
31+
is_object_unsuspended 'user' 'USER' "$user"
32+
is_object_valid 'web' 'DOMAIN' "$domain"
33+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
34+
35+
# Perform verification if read-only mode is enabled
36+
check_hestia_demo_mode
37+
38+
#----------------------------------------------------------#
39+
# Action #
40+
#----------------------------------------------------------#
41+
42+
# Load domain data
43+
parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
44+
45+
if [ "$ssl" = "yes" ]; then
46+
if [ -z "$SSL_FORCE" ]; then
47+
add_object_key "web" 'DOMAIN' "$domain" 'SSL_FORCE' 'SSL_HOME'
48+
fi
49+
50+
# Set forcessl flag to enabled
51+
update_object_value 'web' 'DOMAIN' "$domain" '$SSL_FORCE' 'yes'
52+
fi
53+
54+
# Logging
55+
log_history "Set values SSL FORCE / HSTS for $domain"
56+
log_event "$OK" "$ARGUMENTS"
57+
58+
exit

web/add/web/index.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@
167167
exec (HESTIA_CMD."v-schedule-letsencrypt-domain ".$user." ".escapeshellarg($v_domain), $output, $return_var);
168168
check_return_code($return_var,$output);
169169
unset($output);
170+
171+
if(!empty($_POST['v_ssl_forcessl']) && $_POST['v_ssl_forcessl'] = 'yes'){
172+
exec (HESTIA_CMD."v-add-web-domain-ssl-preset ".$user." ".escapeshellarg($v_domain)." 'yes'", $output, $return_var);
173+
check_return_code($return_var,$output);
174+
unset ($output);
175+
}
176+
170177
} else {
171178
// Add SSL certificates only if Lets Encrypt is off
172179
if ((!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
@@ -202,6 +209,12 @@
202209
exec (HESTIA_CMD."v-add-web-domain-ssl ".$user." ".escapeshellarg($v_domain)." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var);
203210
check_return_code($return_var,$output);
204211
unset($output);
212+
213+
if(!empty($_POST['v_ssl_forcessl']) && $_POST['v_ssl_forcessl'] = 'yes'){
214+
exec (HESTIA_CMD."v-add-web-domain-ssl-force ".$user." ".escapeshellarg($v_domain), $output, $return_var);
215+
check_return_code($return_var,$output);
216+
unset ($output);
217+
}
205218

206219
// Cleanup certificate tempfiles
207220
if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$v_domain.".crt");
@@ -384,6 +397,12 @@
384397
$v_ftp_email = $panel[$user]['CONTACT'];
385398
$v_custom_doc_root_prepath = '/home/'.$user.'/web/';
386399

400+
if( $_POST['v_ssl_forcessl'] != 'no' ){
401+
$v_ssl_forcessl = 'yes';
402+
}else{
403+
$v_ssl_forcessl = 'no';
404+
}
405+
387406
// List IP addresses
388407
exec (HESTIA_CMD."v-list-user-ips ".$user." json", $output, $return_var);
389408
$ips = json_decode(implode('', $output), true);

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('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
6-
define('JS_LATEST_UPDATE', '1491697868');
6+
define('JS_LATEST_UPDATE', time());
77
define('DEFAULT_PHP_VERSION', "php-" . exec('php -r "echo (float)phpversion();"'));
88

99
$i = 0;

web/js/pages/edit_web.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ App.Actions.WEB.toggle_additional_ftp_accounts = function(elm) {
168168
}
169169
}
170170

171+
App.Actions.WEB.toggle_ssl = function (elm){
172+
elementHideShow('ssltable');
173+
if($('#ssl_crt').val().length > 0 || $('#ssl_hsts').prop('checked') || $('#letsencrypt').prop('checked')){
174+
return false;
175+
}
176+
$('#v_ssl_forcessl').prop('checked', true);
177+
}
178+
171179
App.Actions.WEB.toggle_letsencrypt = function(elm) {
172180
if ($(elm).attr('checked')) {
173181
$('#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]').attr('disabled', 'disabled');

web/templates/admin/add_web.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<a class="ui-button cancel" id="btn-back" href="/list/web/"><i class="fas fa-arrow-left status-icon blue"></i> <?=_('Back')?></a>
55
</div>
66
<div class="l-unit-toolbar__buttonstrip float-right">
7-
<a href="#" class="ui-button" data-action="submit" data-id="vstobjects"><i class="fas fa-save status-icon purple"></i> <?=_('Save')?></a>
7+
<a href="#" class="ui-button" title="<?=_('Save')?>" data-action="submit" data-id="vstobjects"><i class="fas fa-save status-icon purple"></i> <?=_('Save')?></a>
88
</div>
99
</div>
1010
</div>
@@ -264,12 +264,17 @@
264264
<td class="step-left input-label vst-text">
265265
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_letsencrypt" <?php if($v_letsencrypt == 'yes' || $v_letsencrypt == 'on') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_letsencrypt(this)"> <?php print _('Lets Encrypt Support');?></label>
266266
</td>
267-
</tr>
267+
</tr>
268268
<tr>
269269
<td class="vst-text input-label lets-encrypt-note step-left" >
270270
<?= _('Your certificate will be automatically issued in 5 minutes')?>
271271
</td>
272272
</tr>
273+
<tr>
274+
<td class="step-left input-label vst-text">
275+
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl_forcessl" <?php if($v_ssl_forcessl != 'no') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_forcessl(this)"> <?php print _('Force SSL/HTTPS');?></label>
276+
</td>
277+
</tr>
273278
<tr>
274279
<td class="vst-text input-label step-left">
275280
<?php print _('SSL Certificate');?>

web/templates/admin/edit_web.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,25 +292,25 @@
292292

293293
<tr>
294294
<td class="vst-text step-top">
295-
<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>
295+
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl" <?php if ($v_ssl == 'yes') echo "checked=yes" ?> onclick="javascript:App.Actions.WEB.toggle_ssl(this);"> <?php print _('SSL Support');?></label>
296296
</td>
297297
</tr>
298298
<tr>
299299
<td class="step-left">
300300
<table style="display:<?php if ($v_ssl == 'no' ) { echo 'none';} else {echo 'block';}?> ;" id="ssltable">
301301
<tr>
302302
<td class="input-label vst-text">
303-
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_letsencrypt" <?php if($v_letsencrypt == 'yes' || $v_letencrypt == 'on') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_letsencrypt(this)"> <?php print _('Lets Encrypt Support');?></label>
303+
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_letsencrypt" id="letsencrypt" <?php if($v_letsencrypt == 'yes' || $v_letencrypt == 'on') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_letsencrypt(this)"> <?php print _('Lets Encrypt Support');?></label>
304304
</td>
305305
</tr>
306306
<tr>
307307
<td class="input-label vst-text">
308-
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl_forcessl" <?php if($v_ssl_forcessl == 'yes') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_forcessl(this)"> <?php print _('Force SSL/HTTPS');?></label>
308+
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl_forcessl" id="v_ssl_forcessl" <?php if($v_ssl_forcessl == 'yes') echo "checked=yes" ?> onclick=""> <?php print _('Force SSL/HTTPS');?></label>
309309
</td>
310310
</tr>
311311
<tr>
312312
<td class="input-label vst-text">
313-
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl_hsts" <?php if($v_ssl_hsts == 'yes') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_hsts(this)"> <?php print _('Enable SSL HSTS');?></label>
313+
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl_hsts" id="ssl_hsts" <?php if($v_ssl_hsts == 'yes') echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_hsts(this)"> <?php print _('Enable SSL HSTS');?></label>
314314
</td>
315315
</tr>
316316
<tr style="display: none;">
@@ -335,7 +335,7 @@
335335
</tr>
336336
<tr>
337337
<td>
338-
<textarea size="20" class="vst-textinput short" name="v_ssl_crt"><?=htmlentities(trim($v_ssl_crt, "'"))?></textarea>
338+
<textarea size="20" class="vst-textinput short" name="v_ssl_crt" id="ssl_crt"><?=htmlentities(trim($v_ssl_crt, "'"))?></textarea>
339339
</td>
340340
</tr>
341341
<tr>

0 commit comments

Comments
 (0)