Merge branch 'shellcheck-ftpadmin' of evolix/evoadmin-web into master
This commit is contained in:
commit
a06f31e80a
|
@ -155,7 +155,7 @@ if ($action=="add") {
|
||||||
|
|
||||||
} elseif ($action=="delete") {
|
} elseif ($action=="delete") {
|
||||||
|
|
||||||
sudoexec("ftpadmin.sh -a d -u $user_id -n $account -f /dev/null -p azertyuiop", $standard_output, $function_output);
|
sudoexec("ftpadmin.sh -a d -n $account -f /dev/null -p azertyuiop", $standard_output, $function_output);
|
||||||
|
|
||||||
|
|
||||||
$_SESSION['error'] = null;
|
$_SESSION['error'] = null;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# #
|
# #
|
||||||
|
@ -13,6 +13,11 @@
|
||||||
|
|
||||||
# vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
|
# vim: expandtab softtabstop=4 tabstop=4 shiftwidth=4 showtabline=2
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
#set -x
|
||||||
|
|
||||||
VPASSWD_PATH="/etc/proftpd/vpasswd"
|
VPASSWD_PATH="/etc/proftpd/vpasswd"
|
||||||
FTPLOG_PATH="/var/log/evolix-ftp.log"
|
FTPLOG_PATH="/var/log/evolix-ftp.log"
|
||||||
|
|
||||||
|
@ -48,48 +53,36 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
log_msg() {
|
log_msg() {
|
||||||
curdate=`date +"%Y/%m/%d %H:%M:%S"`
|
curdate="$(date +"%Y/%m/%d %H:%M:%S")"
|
||||||
echo "$curdate $1" >>$FTPLOG_PATH
|
echo "$curdate $1" >> "$FTPLOG_PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_user_login_by_UID() {
|
get_user_login_by_UID() {
|
||||||
uid=$1
|
uid=$1
|
||||||
grep $uid /etc/passwd | awk -F : "{if (\$3==$uid) print \$1}"
|
grep "$uid" /etc/passwd | awk -F : "{if (\$3==$uid) print \$1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
list_accounts_by_UID() {
|
list_accounts_by_UID() {
|
||||||
uid=$1
|
uid=$1
|
||||||
|
|
||||||
account_list=''
|
while IFS=$'\n' read -r line;
|
||||||
oldIFS=IFS
|
|
||||||
IFS=$'\n'
|
|
||||||
|
|
||||||
for line in `cat $VPASSWD_PATH`
|
|
||||||
do
|
do
|
||||||
line_uid=`echo $line | cut -d":" -f3`
|
line_uid="$(echo "$line" | cut -d":" -f3)"
|
||||||
|
|
||||||
if [ ! "$uid" ] || [ "$line_uid" == "$uid" ]; then
|
if [[ ! "$uid" ]] || [[ "$line_uid" == "$uid" ]]; then
|
||||||
username=`get_user_login_by_UID $line_uid`
|
username="$(get_user_login_by_UID "$line_uid")"
|
||||||
account=`echo $line | cut -d":" -f1`
|
account="$(echo "$line" | cut -d":" -f1)"
|
||||||
path=`echo $line | cut -d":" -f6`
|
path="$(echo "$line" | cut -d":" -f6)"
|
||||||
if [ -r $path/.size ]; then
|
size="$(du -s "$path" | cut -f 1)"
|
||||||
size=`cat $path/.size`
|
#modif="$(cat $path/.lastmodified)"
|
||||||
else
|
|
||||||
size=0
|
|
||||||
fi
|
|
||||||
#modif=`cat $path/.lastmodified`
|
|
||||||
# Passage en minuscule ?
|
# Passage en minuscule ?
|
||||||
#account=`echo $account | tr '[A-Z]' '[a-z]'`
|
#account="$(echo $account | tr '[A-Z]' '[a-z]')"
|
||||||
#path=`echo $path | tr '[A-Z]' '[a-z]'`
|
#path="$(echo $path | tr '[A-Z]' '[a-z]')"
|
||||||
|
|
||||||
account_list="${account_list}$username:$account:$path:$size:$modif\n"
|
echo "$username:$account:$path:$size${modif:+:$modif}"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
done
|
done < "$VPASSWD_PATH"
|
||||||
|
|
||||||
echo "$account_list"
|
|
||||||
|
|
||||||
IFS=$oldIFS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_account() {
|
add_account() {
|
||||||
|
@ -99,18 +92,17 @@ add_account() {
|
||||||
passwd=$4
|
passwd=$4
|
||||||
|
|
||||||
cmd="{if (\$3==$user_id) print \$4}"
|
cmd="{if (\$3==$user_id) print \$4}"
|
||||||
user_gid=`awk -F : "$cmd" /etc/passwd`
|
user_gid="$(awk -F : "$cmd" /etc/passwd)"
|
||||||
|
|
||||||
# Si le répoertoire de travail du compte FTP n'existe pas, on le crée
|
# Si le répertoire de travail du compte FTP n'existe pas, on le crée
|
||||||
if [ ! -d "$path" ]; then
|
if [[ ! -d "$path" ]]; then
|
||||||
mkdir -p $path
|
mkdir -p "$path"
|
||||||
chown $user_id:$user_gid $path
|
chown "$user_id":"$user_gid" "$path"
|
||||||
# fix by tmartin : s/655/755/
|
# fix by tmartin : s/655/755/
|
||||||
chmod 755 $path
|
chmod 755 "$path"
|
||||||
setfacl -R -d -m 'o:rX' $path
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo `echo $passwd | ftpasswd --passwd --file=$VPASSWD_PATH --name=$account_name --uid=$user_id --gid=$user_gid --home=$path --shell=/bin/false --stdin`
|
echo "$passwd" | ftpasswd --passwd --file=$VPASSWD_PATH --name="$account_name" --uid="$user_id" --gid="$user_gid" --home="$path" --shell=/bin/false --stdin
|
||||||
log_msg "Creation du compte $account_name (uid=$user_id, gid=$user_gid, home=$path)"
|
log_msg "Creation du compte $account_name (uid=$user_id, gid=$user_gid, home=$path)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +110,7 @@ edit_password() {
|
||||||
account_name=$1
|
account_name=$1
|
||||||
passwd=$2
|
passwd=$2
|
||||||
|
|
||||||
echo `echo $passwd | ftpasswd --passwd --file=$VPASSWD_PATH --name=$account_name --uid=9999 --gid=9999 --home=/dev/null --shell=/dev/null --change-password --stdin`
|
echo "$passwd" | ftpasswd --passwd --file="$VPASSWD_PATH" --name="$account_name" --uid=9999 --gid=9999 --home=/dev/null --shell=/dev/null --change-password --stdin
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,12 +119,11 @@ delete_account() {
|
||||||
|
|
||||||
account_name=$1
|
account_name=$1
|
||||||
|
|
||||||
echo `ftpasswd --passwd --file=$VPASSWD_PATH --name=$account_name --uid=9999 --gid=9999 --home=/dev/null --shell=/dev/null --delete-user`
|
ftpasswd --passwd --file=$VPASSWD_PATH --name="$account_name" --uid=9999 --gid=9999 --home=/dev/null --shell=/dev/null --delete-user
|
||||||
log_msg "Suppression du compte $account_name"
|
log_msg "Suppression du compte $account_name"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while getopts ha:u:n:f:p: opt; do
|
||||||
while getopts a:u:n:f:p: opt; do
|
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
a)
|
a)
|
||||||
in_action=$OPTARG
|
in_action=$OPTARG
|
||||||
|
@ -149,26 +140,67 @@ while getopts a:u:n:f:p: opt; do
|
||||||
p)
|
p)
|
||||||
in_password=$OPTARG
|
in_password=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
case "$in_action" in
|
case "${in_action-}" in
|
||||||
l)
|
l)
|
||||||
account_list=`list_accounts_by_UID $in_userid`
|
echo -e "$(list_accounts_by_UID "${in_userid-}")"
|
||||||
echo -e -n $account_list
|
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
a)
|
a)
|
||||||
echo -e -n `add_account $in_userid $in_accountname $in_workpath $in_password`
|
if [[ -z "${in_userid-}" ]]; then
|
||||||
|
echo "User ID not specified"
|
||||||
|
elif [[ $in_userid = *[!0-9]* ]]; then
|
||||||
|
echo "User ID must be a non negative integer"
|
||||||
|
elif [[ -z "${in_accountname-}" ]]; then
|
||||||
|
echo "Account name not specified"
|
||||||
|
elif [[ -z "${in_workpath-}" ]]; then
|
||||||
|
echo "A directory was not specified"
|
||||||
|
elif [[ -z "${in_password-}" ]]; then
|
||||||
|
echo "A password was not specified"
|
||||||
|
else
|
||||||
|
echo -e -n \
|
||||||
|
"$(add_account \
|
||||||
|
"$in_userid" \
|
||||||
|
"$in_accountname" \
|
||||||
|
"$in_workpath" \
|
||||||
|
"$in_password")"
|
||||||
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
m)
|
m)
|
||||||
echo -e -n `edit_password $in_accountname $in_password`
|
if [[ -z "${in_accountname-}" ]]; then
|
||||||
|
echo "Account name not specified"
|
||||||
|
elif [[ -z "${in_password-}" ]]; then
|
||||||
|
echo "A password was not specified"
|
||||||
|
else
|
||||||
|
echo -e -n \
|
||||||
|
"$(edit_password \
|
||||||
|
"$in_accountname" \
|
||||||
|
"$in_password")"
|
||||||
|
fi
|
||||||
exit 1;
|
exit 1;
|
||||||
;;
|
;;
|
||||||
d)
|
d)
|
||||||
echo -e -n `delete_account $in_accountname`
|
if [[ -z "${in_accountname-}" ]]; then
|
||||||
|
echo "Account name not specified"
|
||||||
|
else
|
||||||
|
echo -e -n \
|
||||||
|
"$(delete_account "$in_accountname")"
|
||||||
|
fi
|
||||||
exit 1;
|
exit 1;
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue