1
0
mirror of https://github.com/deajan/obackup.git synced 2024-11-14 11:43:41 +01:00
obackup/ssh_filter.sh

107 lines
2.3 KiB
Bash
Raw Normal View History

2015-11-12 01:26:38 +01:00
#!/usr/bin/env bash
2013-06-23 13:44:48 +02:00
2016-03-14 21:50:40 +01:00
##### osync / obackup ssh command filter
2015-08-25 15:26:36 +02: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
2013-06-23 13:44:48 +02:00
2015-08-25 15:26:36 +02:00
##### Obackup needed commands: rsync find du mysql mysqldump (sudo)
##### Osync needed commands: rsync find du echo mkdir rm if df (sudo)
2016-03-14 21:50:40 +01:00
SCRIPT_BUILD=2016031401
2015-08-25 15:26:36 +02:00
2013-06-23 13:53:22 +02:00
## If enabled, execution of "sudo" command will be allowed.
SUDO_EXEC=yes
## Paranoia option. Don't change this unless you read the documentation and still feel concerned about security issues.
2013-06-23 13:44:48 +02:00
RSYNC_EXECUTABLE=rsync
## Enable other commands, useful for remote execution hooks like remotely creating snapshots.
2016-03-14 21:50:40 +01:00
CMD1=""
CMD2=""
CMD3=""
2013-08-25 12:39:13 +02:00
LOG_FILE=~/.ssh/ssh_filter.log
2015-11-12 01:26:38 +01:00
function Log {
DATE=$(date)
echo "$DATE - $1" >> $LOG_FILE
}
2013-06-23 13:44:48 +02:00
2015-11-12 01:26:38 +01:00
function Go {
2016-03-14 21:50:40 +01:00
eval "$SSH_ORIGINAL_COMMAND"
2013-06-23 13:44:48 +02:00
}
case ${SSH_ORIGINAL_COMMAND%% *} in
"$RSYNC_EXECUTABLE")
Go ;;
2015-11-12 01:26:38 +01:00
"echo")
Go ;;
2013-06-23 13:44:48 +02:00
"find")
Go ;;
"du")
Go ;;
2015-11-12 01:26:38 +01:00
"mkdir")
Go ;;
"rm")
Go ;;
"df")
Go ;;
2015-11-12 01:26:38 +01:00
"mv")
2015-08-25 15:26:36 +02:00
Go ;;
"$CMD1")
2015-11-12 01:26:38 +01:00
if [ "$CMD1" != "" ]; then
2016-03-14 21:50:40 +01:00
Go
2015-08-25 15:26:36 +02:00
fi
2016-03-14 21:50:40 +01:00
;;
2015-08-25 15:26:36 +02:00
"$CMD2")
2015-11-12 01:26:38 +01:00
if [ "$CMD2" != "" ]; then
2016-03-14 21:50:40 +01:00
Go
2015-08-25 15:26:36 +02:00
fi
2016-03-14 21:50:40 +01:00
;;
2015-08-25 15:26:36 +02:00
"$CMD3")
2015-11-12 01:26:38 +01:00
if [ "$CMD3" != "" ]; then
2016-03-14 21:50:40 +01:00
Go
2015-08-25 15:26:36 +02:00
fi
2016-03-14 21:50:40 +01:00
;;
2013-06-23 13:44:48 +02:00
"sudo")
2015-11-12 01:26:38 +01:00
if [ "$SUDO_EXEC" == "yes" ]; then
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo du"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then
Go
2016-03-14 21:50:40 +01:00
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]; then
2013-06-23 13:53:22 +02:00
Go
2016-03-14 21:50:40 +01:00
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]]; then
2013-06-23 13:53:22 +02:00
Go
2016-03-14 21:50:40 +01:00
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]]; then
Go
2016-03-14 21:50:40 +01:00
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]]; then
Go
2016-03-14 21:50:40 +01:00
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]]; then
2015-11-12 01:26:38 +01:00
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then
if [ "$CMD1" != "" ]; then
Go
2015-08-25 15:26:36 +02:00
fi
2015-11-12 01:26:38 +01:00
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]; then
if [ "$CMD2" != "" ]; then
Go
fi
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]; then
if [ "$CMD3" != "" ]; then
2013-06-23 13:53:22 +02:00
Go
2015-08-25 15:26:36 +02:00
fi
2013-06-23 13:53:22 +02:00
else
2013-06-23 23:11:35 +02:00
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
2015-08-25 15:26:36 +02:00
exit 1
2013-06-23 13:53:22 +02:00
fi
2013-06-23 13:44:48 +02:00
else
2013-06-23 23:11:35 +02:00
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed. sudo not enabled."
2015-08-25 15:26:36 +02:00
exit 1
2013-06-23 13:44:48 +02:00
fi
;;
*)
2013-06-23 23:11:35 +02:00
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
2015-08-25 15:26:36 +02:00
exit 1
2013-06-23 13:44:48 +02:00
esac