Skip to content

Commit ed0965b

Browse files
jaapmarcusScIT-Raphael
authored andcommitted
Allow Force SSL on creation
1 parent a1e3933 commit ed0965b

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

bin/v-add-web-domain-ssl

Lines changed: 4 additions & 0 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)

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'] == 'yes' ){
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/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');?>

0 commit comments

Comments
 (0)