Improve name validation for create and rename, add error_notify function

This commit is contained in:
Jose
2020-05-09 15:31:15 -04:00
parent e07f6cb0ed
commit f84fd4ad85
2 changed files with 40 additions and 24 deletions

View File

@@ -42,6 +42,14 @@ error_notify() {
exit 1
}
validate_name() {
local NAME_VERIFY=${NAME}
local NAME_SANITY=$(echo "${NAME_VERIFY}" | tr -c -d 'a-zA-Z0-9-_')
if [ "${NAME_VERIFY}" != "${NAME_SANITY}" ]; then
error_notify "${COLOR_RED}Container names may not contain special characters!${COLOR_RESET}"
fi
}
# Handle special-case commands first
case "$1" in
help|-h|--help)
@@ -132,4 +140,9 @@ elif [ -d "${bastille_jailsdir}/${NEWNAME}" ]; then
error_notify "${COLOR_RED}Jail: ${NEWNAME} already exist.${COLOR_RESET}"
fi
## validate jail name
if [ -n "${NAME}" ]; then
validate_name
fi
change_name