Initial commit

This commit is contained in:
2020-06-26 10:41:13 +02:00
commit d16c28fe38
15 changed files with 1030 additions and 0 deletions

137
Tools/aclutil Executable file
View File

@@ -0,0 +1,137 @@
#!/bin/bash
#Funtions
Help()
{
# Display Help
echo
echo "#######################"
echo "# ACL_UTIL Help #"
echo "#######################"
echo
echo "Syntax: aclutil [-u <username> [-g <groupname>][-a|r] <target folder>"
echo "options:"
echo "-h, --help Print this Help."
echo
echo "Get info about set ALC's"
echo "-l, --list #get current ACL rules"
echo "-lg --listgui #get current ACL rules using the eiciel GUI"
echo
echo "Set user/group for ACL change"
echo "-u <username>, --user <username> #User for ACL change"
echo "-g <groupname>, --group <groupname> #group for ACL change "
echo
echo "Action for ACL rule"
echo "-a, --add #add ACL rule"
echo "-r, --remove #Remove ACL rule"
echo
}
#Input Handeler
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h | --help)
Help
exit
;;
-u | --user)
TARGET=user
USER=$2
shift
shift
;;
-g | --group)
TARGET=group
GROUP=$2
shift
shift
;;
-a | --add)
ACTION=add
shift
;;
-r | --remove)
ACTION=remove
shift
;;
-l | --list)
ACTION=list
shift
;;
-lg | --listgui)
ACTION=listgui
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
FOLDERPATH="$1"
#input Validation
##Action flag
if [ -z ${ACTION+x} ]; then echo "Incorrect or missing parameter(s)" && Help && exit; fi
##Target Flag
if [ "$ACTION" = "remove" ] || [ "$ACTION" = "add" ]; then
if [ -z ${TARGET+x} ]; then echo "Incorrect or missing parameter(s)" && Help && exit; fi
##User flag
if [ "$TARGET" = "user" ] && [ -z $USER ]; then
echo "User name not specified"
exit
fi
##Group flag
if [ "$TARGET" = "group" ] && [ -z $GROUP ]; then
echo "Group name not specified"
exit
fi
fi
##Path
if [ -z $FOLDERPATH ]; then echo "File or directory not specified" && exit; fi
if [ ! -d "$FOLDERPATH" ] && [ ! -f "$FOLDERPATH" ]; then
echo "'$FOLDERPATH': No such file or directory"
fi
#Script
if [ "$ACTION" = "list" ]; then
getfacl $FOLDERPATH
fi
if [ "$ACTION" = "listgui" ]; then
echo "If gui did not start make sure X11 forwarding is enabled"
echo "and eiciel it is installed"
eiciel $FOLDERPATH
fi
if [ "$ACTION" = "add" ] && [ "$TARGET" = "user" ]; then
setfacl -R -m u:"$USER":rx "$FOLDERPATH"
setfacl -R -d -m u:"$USER":rx "$FOLDERPATH"
fi
if [ "$ACTION" = "add" ] && [ "$TARGET" = "group" ]; then
setfacl -R -m g:"$GROUP":rx "$FOLDERPATH"
setfacl -R -d -m g:"$GROUP":rx "$FOLDERPATH"
fi
if [ "$ACTION" = "remove" ] && [ "$TARGET" = "user" ]; then
setfacl -R -x u:"$USER" "$FOLDERPATH"
setfacl -R -d -x u:"$USER" "$FOLDERPATH"
fi
if [ "$ACTION" = "remove" ] && [ "$TARGET" = "group" ]; then
setfacl -R -x g:"$GROUP" "$FOLDERPATH"
setfacl -R -d -x g:"$GROUP" "$FOLDERPATH"
fi

198
Tools/adduserutil Executable file
View File

@@ -0,0 +1,198 @@
#!/bin/bash
#Funtions
Help()
{
# Display Help
echo "Add user to backupserver"
echo
echo "Syntax: adduserutil [-a|v|s|ts] <NewUserName>"
echo "options:"
echo "-h, --help Print this Help."
echo
echo "Set user type for new user"
echo "-a, --admin #Backup Admin"
echo "-v, --viewer #Backup Viewer "
echo "-s, --source #Backup Source (ex:a webserver)"
echo
echo "Set backup source options for new user"
echo "-ts, --sftp #Backup source will use sftp/rsync to upload files"
echo "-tf, --ftp #Backup source will use ftp to upload files"
echo
}
Keyer()
{
echo 'Please paste in the public ssh key without ""'
read sshkey
echo
echo
echo "The following key was received"
echo "$sshkey"
echo
while true; do
read -p "Is this key correct? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
}
#Input Handeler
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h | --help)
Help
exit
;;
-v | --viewer)
USERTYPE=viewer
shift
;;
-a |--admin)
USERTYPE=admin
shift
;;
-s|--source)
USERTYPE=source
shift
;;
-tf|--ftp )
UPTYPE=FTP
shift
;;
-ts|--sftp )
UPTYPE=SFTP
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
username="$1"
#Input Check
if [ -z "$username" ]
then
echo "Please provide a username"
echo "For more information type adduserutil -h"
echo
exit
fi
if [ "$username" = "root" ]; then
echo "Root is not allowed"
exit
fi
getent passwd $username > /dev/null
if [ $? -eq 0 ]; then
echo "This username already exists"
exit
fi
if [ -z "$USERTYPE" ]
then
echo "Please provide user type"
echo "For more information type adduserutil -h"
echo
exit
fi
if [ "$USERTYPE" = "source" ]; then
if [ -z "$UPTYPE" ]
then
echo "Please provide upload methode"
echo "For more information type adduserutil -h"
echo
exit
fi
fi
#Confirmation before setting user
echo "Create user with the following information"
echo "Username: $username"
echo "User type: $USERTYPE"
if [ "$USERTYPE" = "source" ]; then
echo "Upload methode $UPTYPE"
fi
while true; do
read -p "Do you wish to add this user? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
#Add Admin user
if [ "$USERTYPE" = "admin" ]; then
Keyer
useradd -g BCKadmin -s /bin/bash -m -d /home/"$username" "$username"
passwd --expire -d "$username"
sudo -u "$username" mkdir /home/$username/.ssh
echo "$sshkey" | sudo -u "$username" tee /home/"$username"/.ssh/authorized_keys
fi
#Add Viewer user
if [ "$USERTYPE" = "viewer" ]; then
Keyer
useradd -g BCKviewer -s /usr/sbin/nologin -d / "$username"
mkdir -p /vhome/"$username"/.ssh
mkdir -p /vhome/"$username"/backups
chown root: /vhome/"$username"
chmod 755 /vhome/"$username"
chown root: /vhome/"$username"
chown -R $username: /vhome/"$username"/.ssh
chmod 750 -R /vhome/"$username"/.ssh
echo "$sshkey" | sudo -u "$username" tee /vhome/"$username"/.ssh/authorized_keys
echo "/backups /vhome/$username/backups none defaults,bind 0 0" >>/etc/fstab
mount -a
fi
#Add sftp source user
if [ "$USERTYPE" = "source" ] && [ "$UPTYPE" = "SFTP" ]; then
Keyer
mkdir -p /backups/sftp/"$username"
useradd -M -N -r "$username"
usermod -g sftpusers "$username"
python3 /opt/grequalizer/grequalizer.py /opt/grequalizer/conf/grequalizer-sftp.conf -O
mkdir -p /backups/sftp/"$username"/home/.ssh
echo "$sshkey" > /backups/sftp/"$username"/home/.ssh/authorized_keys
chown -R $username: /backups/sftp/"$username"/home
chmod -R 700 /backups/sftp/"$username"/home
setfacl -R -m g:BCKadmin:rwx /backups/sftp/"$username"/home
setfacl -R -d -m g:BCKadmin:rwx /backups/sftp/"$username"/home
fi
#Add ftp source user
if [ "$USERTYPE" = "source" ] && [ "$UPTYPE" = "FTP" ]; then
password=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 18 | head -n 1)
useradd -M -N -r "$username"
usermod -g ftpusers "$username"
echo "$username" | tee -a /etc/vsftpd.user_list
python3 /opt/grequalizer/grequalizer.py /opt/grequalizer/conf/grequalizer-ftp.conf -O
setfacl -R -m g:BCKadmin:rwx /backups/ftp/"$username"
setfacl -R -d -m g:BCKadmin:rwx /backups/ftp/"$username"
echo $username:$password | chpasswd
echo "The password for $username is: $password"
fi

161
Tools/deluserutil Executable file
View File

@@ -0,0 +1,161 @@
#!/bin/bash
#Funtions
Help()
{
# Display Help
echo "Remove user from backupserver"
echo
echo "Syntax: deluserutil [-a|v|s|ts] <UserName>"
echo "options:"
echo "-h, --help Print this Help."
echo
echo "Define user type for user that shoud be removed"
echo "-a, --admin #Backup Admin"
echo "-v, --viewer #Backup Viewer "
echo "-s, --source #Backup Source (ex:a webserver)"
echo
echo "Set backup source options for new user"
echo "-ts, --sftp #Backup source uses sftp/rsync to upload files"
echo "-tf, --ftp #Backup source uses ftp to upload files"
echo
}
#Input Handeler
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h | --help)
Help
exit
;;
-v | --viewer)
USERTYPE=viewer
shift
shift
;;
-a |--admin)
USERTYPE=admin
shift
;;
-s|--source)
USERTYPE=source
shift
;;
-tf|--ftp )
UPTYPE=FTP
shift
;;
-ts|--sftp )
UPTYPE=SFTP
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
username="$1"
#Input Check
if [ -z "$username" ]
then
echo "Please provide a username"
echo "For more information type deluserutil -h"
echo
exit
fi
if [ "$username" = "root" ]; then
echo "Root is not allowed"
fi
getent passwd $username > /dev/null
if [ $? -eq 2 ]; then
echo "This username does not exists"
exit
fi
if [ -z "$USERTYPE" ]
then
echo "Please provide user type"
echo "For more information type deluserutil -h"
echo
exit
fi
if [ "$USERTYPE" = "source" ]; then
if [ -z "$UPTYPE" ]
then
echo "Please provide upload methode"
echo "For more information type deluserutil -h"
echo
exit
fi
fi
#Confirmation before setting user
echo "Removing the user with the following information"
echo "Username: $username"
echo "User type: $USERTYPE"
if [ "$USERTYPE" = "source" ]; then
echo "Upload methode $UPTYPE"
fi
while true; do
read -p "Do you wish to REMOVE $username? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
#Remove Admin user
if [ "$USERTYPE" = "admin" ]; then
userdel -rf $username
fi
#Remove Viewer user
if [ "$USERTYPE" = "viewer" ]; then
umount /vhome/$username/backup
sed -i "/\/$username\//d" /etc/fstab
userdel -f $username
rm -rf /vhome/$username
fi
#Remove sftp source user
if [ "$USERTYPE" = "source" ] && [ "$UPTYPE" = "SFTP" ]; then
while true; do
read -p "Do you wish to REMOVE the backups connected to this user? " yn
case $yn in
[Yy]* ) rm -rf /backups/sftp/"$username" && break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
userdel -f $username
fi
#Remove ftp source user
if [ "$USERTYPE" = "source" ] && [ "$UPTYPE" = "FTP" ]; then
while true; do
read -p "Do you wish to REMOVE the backups connected to this user? " yn
case $yn in
[Yy]* ) rm -rf /backups/ftp/"$username" && break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
sed -i "/\<$username\>/d" /etc/ftpusers
userdel -f $username
fi

156
Tools/ez-aclutil Executable file
View File

@@ -0,0 +1,156 @@
#!/bin/bash
#Funtions
Help()
{
# Display Help
echo
echo "#########################"
echo "# ez ACL_UTIL Help #"
echo "#########################"
echo
echo "Syntax: ezaclutil [-u <username> | -g <groupname> | -av][-a|r] [-f <ftpusername>] [-s <sftpusername>]"
echo "options:"
echo "-h, --help Print this Help."
echo
echo "Get info about set ALC's"
echo "-l, --list #get current ACL rules"
echo
echo "Set user/group for ACL change"
echo "-u <username>, --user <username> #User for ACL change"
echo "-g <groupname>, --group <groupname> #group for ACL change "
echo "-av, --allviewers #Set group to backup viewers (-g not needed)"
echo
echo "Action for ACL rule"
echo "-a, --add #add ACL rule"
echo "-r, --remove #Remove ACL rule"
echo
echo "Set target for ACL change"
echo "-f <ftpusername>, --ftp <ftpusername> #User for ACL change"
echo "-s <sftpusername>, --sftp <sftpusername> #group for ACL change "
echo
}
#Input Handeler
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h | --help)
Help
exit
;;
-u | --user)
TARGET=user
USER=$2
shift
shift
;;
-g | --group)
TARGET=group
GROUP=$2
shift
shift
;;
-a | --add)
ACTION=add
shift
;;
-r | --remove)
ACTION=remove
shift
;;
-l | --list)
ACTION=list
shift
;;
-lg | --listgui)
ACTION=listgui
shift
;;
-av | --allviewers)
TARGET=group
GROUP=BCKviewer
shift
;;
-f | --ftp)
FOLDERPATH="/backups/ftp/$2"
shift
shift
;;
-s | --sftp)
FOLDERPATH="/backups/sftp/$2/home"
shift
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
#input Validation
##Action flag
if [ -z ${ACTION+x} ]; then echo "Incorrect or missing parameter(s)" && Help && exit; fi
##Target Flag
if [ "$ACTION" = "remove" ] || [ "$ACTION" = "add" ]; then
if [ -z ${TARGET+x} ]; then echo "Incorrect or missing parameter(s)" && Help && exit; fi
##User flag
if [ "$TARGET" = "user" ] && [ -z $USER ]; then
echo "User name not specified"
exit
fi
##Group flag
if [ "$TARGET" = "group" ] && [ -z $GROUP ]; then
echo "Group name not specified"
exit
fi
fi
##Path
if [ -z $FOLDERPATH ]; then echo "Target backup not specified" && exit; fi
if [ ! -d "$FOLDERPATH" ] && [ ! -f "$FOLDERPATH" ]; then
echo "Target backup not found"
fi
#Script
if [ "$ACTION" = "list" ]; then
getfacl $FOLDERPATH
fi
if [ "$ACTION" = "listgui" ]; then
echo "If gui did not start make sure X11 forwarding is enabled"
echo "and eiciel it is installed"
eiciel $FOLDERPATH
fi
if [ "$ACTION" = "add" ] && [ "$TARGET" = "user" ]; then
setfacl -R -m u:"$USER":rx "$FOLDERPATH"
setfacl -R -d -m u:"$USER":rx "$FOLDERPATH"
fi
if [ "$ACTION" = "add" ] && [ "$TARGET" = "group" ]; then
setfacl -R -m g:"$GROUP":rx "$FOLDERPATH"
setfacl -R -d -m g:"$GROUP":rx "$FOLDERPATH"
fi
if [ "$ACTION" = "remove" ] && [ "$TARGET" = "user" ]; then
setfacl -R -x u:"$USER" "$FOLDERPATH"
setfacl -R -d -x u:"$USER" "$FOLDERPATH"
fi
if [ "$ACTION" = "remove" ] && [ "$TARGET" = "group" ]; then
setfacl -R -x g:"$GROUP" "$FOLDERPATH"
setfacl -R -d -x g:"$GROUP" "$FOLDERPATH"
fi