2016-03-14 20:51:29 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-08-24 20:12:25 +00:00
|
|
|
|
2016-03-14 20:51:29 +00:00
|
|
|
##### osync / obackup ssh command filter
|
2013-08-24 20:12:25 +00:00
|
|
|
##### 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
|
|
|
|
|
2017-02-08 12:52:55 +00:00
|
|
|
##### 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"
|
2017-02-08 12:52:55 +00:00
|
|
|
##### For details, see ssh_filter.log
|
2013-08-24 20:12:25 +00:00
|
|
|
|
2017-02-08 14:28:41 +00:00
|
|
|
SCRIPT_BUILD=2017020802
|
2017-02-08 12:52:55 +00:00
|
|
|
|
|
|
|
## Allow sudo
|
2013-08-24 20:12:25 +00:00
|
|
|
SUDO_EXEC=yes
|
2017-02-08 12:52:55 +00:00
|
|
|
|
2017-02-08 14:28:41 +00:00
|
|
|
## Log all valid commands too
|
|
|
|
_DEBUG=no
|
2013-08-24 20:12:25 +00:00
|
|
|
|
2017-02-08 12:52:55 +00:00
|
|
|
## Set remote token in authorized_keys
|
|
|
|
if [ "$1" != "" ]; then
|
|
|
|
_REMOTE_TOKEN="${1}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
LOG_FILE="${HOME}/.ssh/ssh_filter.log"
|
2013-08-24 20:12:25 +00:00
|
|
|
|
2015-09-08 14:08:14 +00:00
|
|
|
function Log {
|
2013-08-24 20:12:25 +00:00
|
|
|
DATE=$(date)
|
2017-02-08 12:52:55 +00:00
|
|
|
echo "$DATE - $1" >> "$LOG_FILE"
|
2013-08-24 20:12:25 +00:00
|
|
|
}
|
|
|
|
|
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"
|
2013-08-24 20:12:25 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 12:52:55 +00:00
|
|
|
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"
|
2013-08-24 20:12:25 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-02-08 12:52:55 +00:00
|
|
|
Go
|
2013-08-24 20:12:25 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
|
2017-02-08 12:52:55 +00:00
|
|
|
echo "Syntax error near unexpected token"
|
2013-08-24 20:12:25 +00:00
|
|
|
exit 1
|
2017-02-08 12:52:55 +00:00
|
|
|
;;
|
2013-08-24 20:12:25 +00:00
|
|
|
esac
|