Add two points tolerance in config files and simplify the params you have to send to the function
This commit is contained in:
parent
b6f0d82f6b
commit
912d374d6d
|
@ -23,15 +23,15 @@ check_value_in_conf_file () {
|
||||||
# Get parameters
|
# Get parameters
|
||||||
local name=${1}
|
local name=${1}
|
||||||
local conf_file=${2}
|
local conf_file=${2}
|
||||||
local search_ok=${3}
|
local param_key=${3}
|
||||||
local param_key=${4}
|
local search_ok=${4}
|
||||||
|
|
||||||
# Print message to explain this check
|
# Print message to explain this check
|
||||||
echo -e "Check ${BLUE}${name} ${param_key}${NC} config file ${conf_file} ..."
|
echo -e "Check ${BLUE}${name} ${param_key}${NC} config file ${conf_file} ..."
|
||||||
|
|
||||||
# If multiple expected values
|
# If multiple expected values
|
||||||
local list_search_ok=(${search_ok})
|
local list_search_ok=(${search_ok})
|
||||||
local search_ok_to_grep="^[[:space:]]*"${search_ok}"[[:space:]]*$"
|
local search_ok_to_grep="^[[:space:]]*"${param_key}"[[:space:]]*:\?[[:space:]]*"${search_ok}"[[:space:]]*$"
|
||||||
|
|
||||||
# If there is more than one unexpected values
|
# If there is more than one unexpected values
|
||||||
if [ ${#list_search_ok[@]} -gt 1 ]
|
if [ ${#list_search_ok[@]} -gt 1 ]
|
||||||
|
@ -39,10 +39,10 @@ check_value_in_conf_file () {
|
||||||
search_ok_to_grep=""
|
search_ok_to_grep=""
|
||||||
for var_search_ok in ${list_search_ok[@]}
|
for var_search_ok in ${list_search_ok[@]}
|
||||||
do
|
do
|
||||||
search_ok_to_grep=${search_ok_to_grep}'-e '"^[[:space:]]*${var_search_ok}[[:space:]]*$"' '
|
search_ok_to_grep=${search_ok_to_grep}'-e '"^[[:space:]]*${param_key}[[:space:]]*:\?[[:space:]]*${var_search_ok}[[:space:]]*$"' '
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
echo 1
|
||||||
# Check if unexpected value is set (grep -v) (success if return code = 1)
|
# Check if unexpected value is set (grep -v) (success if return code = 1)
|
||||||
grep "^[[:space:]]*"${param_key} ${conf_file} | grep -q -v ${search_ok_to_grep}
|
grep "^[[:space:]]*"${param_key} ${conf_file} | grep -q -v ${search_ok_to_grep}
|
||||||
|
|
||||||
|
@ -57,7 +57,8 @@ check_value_in_conf_file () {
|
||||||
# Unexpected value is not set
|
# Unexpected value is not set
|
||||||
else
|
else
|
||||||
|
|
||||||
search_ok_to_grep="^[[:space:]]*"${search_ok}"[[:space:]]*$"
|
echo 2
|
||||||
|
search_ok_to_grep="^[[:space:]]*"${param_key}"[[:space:]]*:\?[[:space:]]*"${search_ok}"[[:space:]]*$"
|
||||||
|
|
||||||
# Boolean for final Return Code, if one return code in the loop -ne 0 -> set finalRC=1
|
# Boolean for final Return Code, if one return code in the loop -ne 0 -> set finalRC=1
|
||||||
local finalRC=0
|
local finalRC=0
|
||||||
|
@ -67,7 +68,7 @@ check_value_in_conf_file () {
|
||||||
then
|
then
|
||||||
for var_search_ok in ${list_search_ok[@]}
|
for var_search_ok in ${list_search_ok[@]}
|
||||||
do
|
do
|
||||||
grep -q "^[[:space:]]*"${var_search_ok}"[[:space:]]*$" ${conf_file}
|
grep -q "^[[:space:]]*"${param_key}"[[:space:]]*:\?[[:space:]]*"${var_search_ok}"[[:space:]]*$" ${conf_file}
|
||||||
|
|
||||||
RC=${?}
|
RC=${?}
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ check_value_in_conf_file () {
|
||||||
# Else : do classical check
|
# Else : do classical check
|
||||||
else
|
else
|
||||||
# Check if OK value is set (success if return code = 0)
|
# Check if OK value is set (success if return code = 0)
|
||||||
grep -q "^[[:space:]]*"${search_ok}"[[:space:]]*$" ${conf_file}
|
grep -q "^[[:space:]]*"${param_key}"[[:space:]]*:\?[[:space:]]*"${search_ok}"[[:space:]]*$" ${conf_file}
|
||||||
|
|
||||||
# Return Code
|
# Return Code
|
||||||
finalRC=${?}
|
finalRC=${?}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
print_config_title 'CHECK SSH CONFIG'
|
print_config_title 'CHECK SSH CONFIG'
|
||||||
|
|
||||||
check_value_in_conf_file "SSH" "/etc/ssh/sshd_config" "PasswordAuthentication[[:space:]]*no" "PasswordAuthentication"
|
check_value_in_conf_file "SSH" "/etc/ssh/sshd_config" "PasswordAuthentication" "no"
|
||||||
|
|
||||||
case ${?} in
|
case ${?} in
|
||||||
0) # OK, nothing to do
|
0) # OK, nothing to do
|
||||||
|
@ -19,7 +19,7 @@ case ${?} in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
check_value_in_conf_file "SSH" "/etc/ssh/sshd_config" "PermitRootLogin[[:space:]]*no" "PermitRootLogin"
|
check_value_in_conf_file "SSH" "/etc/ssh/sshd_config" "PermitRootLogin" "no"
|
||||||
|
|
||||||
case ${?} in
|
case ${?} in
|
||||||
0) # OK, nothing to do
|
0) # OK, nothing to do
|
||||||
|
@ -38,7 +38,7 @@ case ${?} in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
check_value_in_conf_file "SSH" "/etc/ssh/sshd_config" "ListenAddress[[:space:]]*${IPV4_ADMIN_LAN_IP} ListenAddress[[:space:]]*${IPV6_ADMIN_LAN_IP}" "ListenAddress"
|
check_value_in_conf_file "SSH" "/etc/ssh/sshd_config" "ListenAddress" "${IPV4_ADMIN_LAN_IP} ${IPV6_ADMIN_LAN_IP}"
|
||||||
|
|
||||||
case ${?} in
|
case ${?} in
|
||||||
0) # OK, nothing to do
|
0) # OK, nothing to do
|
||||||
|
|
Loading…
Reference in a new issue