vesta/bin/v-change-sys-config-value
Anton Reutov d386c3598c
Fix for Sed Injection Vulnerability
Thanks to @hestiacp and @jaapmarcus for fix.
2022-07-18 13:08:50 +03:00

59 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# info: change sysconfig value
# options: KEY VALUE
#
# The function is for changing main config settings such as COMPANY_NAME or
# COMPANY_EMAIL and so on.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
key=$(echo "$1" | tr '[:lower:]' '[:upper:]' )
value=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'KEY VALUE'
is_format_valid 'key'
format_no_quotes "$value" 'value'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Updating conf
check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf)
if [ -z "$check_ckey" ]; then
echo "$key='$value'" >> $VESTA/conf/vesta.conf
else
sed -i "s|$key=.*|$key='$value'|g" $VESTA/conf/vesta.conf
fi
if [ "$key" = "BACKUP" ] && [ "$value" != '/backup' ]; then
rm /backup
ln -s $value /backup
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit