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

80 lines
1.6 KiB
Bash
Raw Normal View History

2013-06-23 13:44:48 +02:00
#!/bin/bash
##### Obackup ssh command filter build 2306201301
##### This script should be located in /usr/local/bin in the remote system that will be backed up
##### 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
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.
CMD1=
CMD2=
CMD3=
2013-06-23 23:11:35 +02:00
LOG_FILE=~/.ssh/obackup_ssh_filter.log
function Log
{
DATE=$(date)
echo "$DATE - $1" >> $LOG_FILE
}
2013-06-23 13:44:48 +02:00
function Go
{
2013-06-23 23:37:16 +02:00
eval $SSH_ORIGINAL_COMMAND
2013-06-23 13:44:48 +02:00
}
case ${SSH_ORIGINAL_COMMAND%% *} in
"$RSYNC_EXECUTABLE")
Go ;;
"mysqldump")
Go ;;
2013-06-23 23:37:16 +02:00
"mysql")
Go ;;
"echo")
Go ;;
2013-06-23 13:44:48 +02:00
"find")
Go ;;
"du")
Go ;;
"$CMD1")
Go ;;
"$CMD2")
Go ;;
"$CMD3")
Go ;;
2013-06-23 13:44:48 +02:00
"sudo")
2013-06-23 13:53:22 +02:00
if [ "$SUDO_EXEC" == "yes" ]
2013-06-23 13:44:48 +02:00
then
2013-06-23 13:53:22 +02:00
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
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]
then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]
then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]
2013-06-23 13:53:22 +02:00
then
Go
else
2013-06-23 23:11:35 +02:00
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
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."
2013-06-23 13:44:48 +02:00
fi
;;
*)
2013-06-23 23:11:35 +02:00
Log "Command [$SSH_ORIGINAL_COMMAND] not allowed."
2013-06-23 13:44:48 +02:00
esac