Skip to content

Commit 5b27dff

Browse files
committed
Sec: Fix input validation in v-change-sys-demo-mode and add logging
- active: Validate Bool, required
1 parent 9b94bbf commit 5b27dff

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

bin/v-change-sys-demo-mode

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: enable or disable demo mode
3-
#
3+
# options: ACTIVE
44
# This function will set the demo mode variable,
55
# which will prevent usage of certain v-scripts in the backend
66
# and prevent modification of objects in the control panel.
@@ -13,32 +13,29 @@
1313
# Variable&Function #
1414
#----------------------------------------------------------#
1515

16-
mode=$1
16+
active=$1
1717

1818
# Includes
1919
source $HESTIA/func/main.sh
2020
source $HESTIA/conf/hestia.conf
2121

22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
check_args '1' "$#" 'ACTIVE'
27+
is_format_valid 'active'
28+
2229
#----------------------------------------------------------#
2330
# Action #
2431
#----------------------------------------------------------#
2532

26-
if [ -z "$mode" ]; then
27-
echo "ERROR: No mode specified."
28-
echo "Usage: v-change-sys-demo-mode [no|yes]"
29-
exit 1
30-
elif [ "$mode" = "yes" ]; then
33+
if [ "$active" = "yes" ]; then
3134
#TO-DO: Instructions for disabling vhosts
32-
$BIN/v-change-sys-config-value 'DEMO_MODE' "$mode"
33-
elif [ "$mode" = "no" ]; then
35+
$BIN/v-change-sys-config-value 'DEMO_MODE' "$active"
36+
elif [ "$active" = "no" ]; then
3437
#TODO: Instructions for enabling vhosts
35-
$BIN/v-change-sys-config-value 'DEMO_MODE' "$mode"
36-
else
37-
echo "ERROR: Invalid mode specified."
38-
echo "Valid modes:"
39-
echo "no: Disables read only / demo mode."
40-
echo "yes: Enables read only / demo mode."
41-
exit 1
38+
$BIN/v-change-sys-config-value 'DEMO_MODE' "$active"
4239
fi
4340

4441
#----------------------------------------------------------#
@@ -52,4 +49,7 @@ check_result $? "restart" >/dev/null 2>&1
5249
$BIN/v-restart-proxy $restart
5350
check_result $? "restart" >/dev/null 2>&1
5451

52+
# Logging
53+
log_event "$OK" "$ARGUMENTS"
54+
5555
exit

func/main.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ is_format_valid() {
852852
case $arg_name in
853853
account) is_user_format_valid "$arg" "$arg_name";;
854854
action) is_fw_action_format_valid "$arg";;
855+
active) is_boolean_format_valid "$arg" 'active' ;;
855856
aliases) is_alias_format_valid "$arg" ;;
856857
antispam) is_boolean_format_valid "$arg" 'antispam' ;;
857858
antivirus) is_boolean_format_valid "$arg" 'antivirus' ;;

0 commit comments

Comments
 (0)