2021-04-25 03:32:02 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# The command rvtysh can be run as root priviledge by any user without password, only allow to execute readonly commands.
|
|
|
|
|
|
|
|
# The options in the show command cannot contains any charactors to run multiple sub-commands potentially, such as "\n", "\r", "|", "&", "$" and ";".
|
|
|
|
if printf -- "$*" | grep -qPz '[\n\r|&$;]'; then
|
|
|
|
echo "Not allow to run the command, please use the comand 'sudo vtysh' instead." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# The sub commands must start with "show"
|
2021-05-20 08:35:23 -05:00
|
|
|
LAST_PARAM=
|
|
|
|
for param in "$@"
|
2021-04-25 03:32:02 -05:00
|
|
|
do
|
2021-05-20 08:35:23 -05:00
|
|
|
if [ "$LAST_PARAM" == "-c" ] && [[ "$param" != show* ]]; then
|
|
|
|
echo "Not allow to run the command '$param', please use the comand 'sudo vtysh' instead." 1>&2
|
2021-04-25 03:32:02 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-20 08:35:23 -05:00
|
|
|
LAST_PARAM=$param
|
2021-04-25 03:32:02 -05:00
|
|
|
done
|
|
|
|
|
|
|
|
vtysh "$@"
|