2
0
mirror of https://github.com/deajan/osync synced 2024-11-15 12:12:56 +00:00
osync/ssh_filter.sh

54 lines
1.3 KiB
Bash
Raw Normal View History

2016-03-14 20:51:29 +00:00
#!/usr/bin/env bash
2016-03-14 20:51:29 +00:00
##### osync / obackup ssh command filter
##### This script should be located in /usr/local/bin in the remote system to sync / backup
##### It will filter the commands that can be run remotely via ssh.
##### Please chmod 755 and chown root:root this file
##### Any command that has env _REMOTE_TOKEN= with the corresponding token in it will be run
2017-02-08 14:28:41 +00:00
##### Any other command will return a "syntax error"
##### For details, see ssh_filter.log
2017-02-08 14:28:41 +00:00
SCRIPT_BUILD=2017020802
## Allow sudo
SUDO_EXEC=yes
2017-02-08 14:28:41 +00:00
## Log all valid commands too
_DEBUG=no
## Set remote token in authorized_keys
if [ "$1" != "" ]; then
_REMOTE_TOKEN="${1}"
fi
LOG_FILE="${HOME}/.ssh/ssh_filter.log"
2015-09-08 14:08:14 +00:00
function Log {
DATE=$(date)
echo "$DATE - $1" >> "$LOG_FILE"
}
2015-09-08 14:08:14 +00:00
function Go {
2017-02-08 14:28:41 +00:00
if [ "$_DEBUG" == "yes" ]; then
Log "Executing [$SSH_ORIGINAL_COMMAND]."
fi
2016-03-14 20:51:29 +00:00
eval "$SSH_ORIGINAL_COMMAND"
}
case "${SSH_ORIGINAL_COMMAND}" in
*"env _REMOTE_TOKEN=$_REMOTE_TOKEN"*)
if [ "$SUDO_EXEC" != "yes" ] && [[ $SSH_ORIGINAL_COMMAND == *"sudo "* ]]; then
Log "Command [$SSH_ORIGINAL_COMMAND] contains sudo which is not allowed."
echo "Syntax error unexpected end of file"
exit 1
fi
Go
;;
*)
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
echo "Syntax error near unexpected token"
exit 1
;;
esac