1
Files
2024-02-14 16:04:31 +01:00

121 lines
2.9 KiB
Bash

#!/bin/bash
create_user() {
username=$1
password=$2
directory="${3//[^[:alnum:]_-]}"
if [[ -z "$directory" ]]; then
echo "Error: Directory name does not contain any alphanumeric character."
return 1
fi
mkdir -p /srv/ftp/$directory
chown ftpuser:ftpgroup /srv/ftp/$directory
pure-pw useradd $username -u ftpuser -d /srv/ftp/$directory -m <<EOF 2>&1 >/dev/null
$password
$password
EOF
if [ $? -eq 0 ]; then
pure-pw mkdb
echo "User $username created successfully."
echo "A directory have been created: /srv/ftp/$directory"
fi
}
remove_user() {
username=$1
pure-pw userdel $username -m
if [ $? -eq 0 ]; then
pure-pw mkdb
echo "User $username removed successfully."
fi
}
change_password() {
username=$1
new_password=$2
pure-pw passwd $username -m <<EOF 2>&1 >/dev/null
$new_password
$new_password
EOF
if [ $? -eq 0 ]; then
pure-pw mkdb
echo "Password for user $username changed successfully."
fi
}
list_users() {
echo "Users:"
echo
pure-pw list
}
while true; do
read -p "Command (h for help): " choice
echo
case $choice in
c)
read -p "Enter username: " username
read -sp "Enter password: " password
echo
read -p "Enter directory name: " directory
create_user $username $password $directory
echo
;;
r)
read -p "Enter username: " username
remove_user $username
echo
;;
p)
read -p "Enter username: " username
read -sp "Enter new password: " new_password
echo
change_password $username $new_password
echo
;;
l)
list_users
echo
;;
i)
echo "Connection:"
echo
host=$(curl -s iplookup.fr/hostname)
ip=$(curl -s iplookup.fr)
echo " host $host ($ip)"
echo " port 21"
echo
echo "Server:"
echo
users_amount=$(pure-pw list | wc -l)
echo " users $users_amount"
tls_expiration=$(openssl x509 -enddate -noout -in /etc/ssl/private/pure-ftpd.pem | awk -F '=' '{ print $2 }')
echo " certificate valid until $tls_expiration"
echo
;;
q)
break
;;
h)
echo "Help:"
echo
echo " c create a new user"
echo " r remove a user"
echo " p modify a password"
echo " l list users"
echo " i get server information"
echo " q leave this script"
echo
;;
*)
echo "Unknown command (type help the show available commands)."
;;
esac
done