<commit_before>#!/usr/bin/env bash

############################################################
#                                                          #
#  EvoAdmin : gestion des comptes FTP virtuels de ProFTPd  #
#                                                          #
#  Copyright (c) 2009 Evolix - Tous droits reserves        #
#                                                          #
#  @author <NAME> <<EMAIL>>              #
#  @version 1.0                                            #
#                                                          #
############################################################

# 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"
FTPLOG_PATH="/var/log/evolix-ftp.log"

usage() {

cat <<EOT >&2

Usage: $0 [ACTION UID [PARAMS]]

    Manage ProFTPd virtual accounts.

    -a ACTION
       l (list), a (add), m (modify), d (delete) ProFTPd virtual account(s)

    -u UID
       UID of the real account the virtual FTP accounts will be related to

    Available PARAMS are :

    -n ACCOUNTNAME
       Name of the ProFTPd virtual account you want to add/edit/delete.
       Mandatory in all actions.

    -f FOLDER
       Directory that the virtual account will have as home directory.
       Mandatory for add and modify action.

    -p PASSWD
       Password for the virtual account.
       Mandatory for add and modify action.

EOT
}

log_msg() {
    curdate="$(date +"%Y/%m/%d %H:%M:%S")"
    echo "$curdate $1" >> "$FTPLOG_PATH"
}

get_user_login_by_UID() {
    uid=$1
    grep "$uid" /etc/passwd | awk -F : "{if (\$3==$uid) print \$1}"
}

list_accounts_by_UID() {
  uid=$1

  while IFS=$'\n' read -r line;
  do
     line_uid="$(echo "$line" | cut -d":" -f3)"

     if [[ ! "$uid" ]] ||  [[ "$line_uid" == "$uid" ]]; then
       username="$(get_user_login_by_UID "$line_uid")"
       account="$(echo "$line" | cut -d":" -f1)"
       path="$(echo "$line" | cut -d":" -f6)"
       size="$(du -s "$path" | cut -f 1)"
       #modif="$(cat $path/.lastmodified)"
       # Passage en minuscule ?
       #account="$(echo $account | tr '[A-Z]' '[a-z]')"
       #path="$(echo $path | tr '[A-Z]' '[a-z]')"

       echo "$username:$account:$path:$size${modif:+:$modif}"
       
     fi
  done < "$VPASSWD_PATH"
}
<commit_msg>#62716 : Corrections et améliorations ftpadmin.sh<commit_after>#!/usr/bin/env bash

############################################################
#                                                          #
#  EvoAdmin : gestion des comptes FTP virtuels de ProFTPd  #
#                                                          #
#  Copyright (c) 2009 Evolix - Tous droits reserves        #
#                                                          #
#  @author <NAME> <<EMAIL>>              #
#  @version 1.0                                            #
#                                                          #
############################################################

# 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"
FTPLOG_PATH="/var/log/evolix-ftp.log"

usage() {

cat <<EOT >&2

Usage: $0 [ACTION UID [PARAMS]]

    Manage ProFTPd virtual accounts.

    -a ACTION
       l (list), a (add), m (modify), d (delete) ProFTPd virtual account(s)

    -u UID
       UID of the real account the virtual FTP accounts will be related to

    Available PARAMS are :

    -n ACCOUNTNAME
       Name of the ProFTPd virtual account you want to add/edit/delete.
       Mandatory in all actions.

    -f FOLDER
       Directory that the virtual account will have as home directory.
       Mandatory for add and modify action.

    -p <PASSWORD>WD
       Password for the virtual account.
       Mandatory for add and modify action.

EOT
}

log_msg() {
    curdate="$(date +"%Y/%m/%d %H:%M:%S")"
    echo "$curdate $1" >> "$FTPLOG_PATH"
}

get_user_login_by_UID() {
    uid=$1
    grep "$uid" /etc/passwd | awk -F : '{if ($3==$uid) print $1}'
}

list_accounts_by_UID() {
    uid=$1
  
    # Remove # and empty lines
    ftp_users=$(grep -v -E '^[[:blank:]]*(#.*)*$' "$VPASSWD_PATH")

    for line in $ftp_users; do
        line_uid="$(echo "$line" | cut -d":" -f3)"
    
        if [[ ! "$uid" ]] || [[ "$line_uid" == "$uid" ]]; then
            username=$(get_user_login_by_UID "$line_uid")
            account=$(echo "$line" | cut -d":" -f1)
            path=$(echo "$line" | cut -d":" -f6)
            size="inconnue"
            # Check output of daily "du" cron job
            # (set by ansible-roles/packweb-apache/tasks/main.yml)
            if [ -r "$path/.size" ]; then
                size=$(cat "$path/.size")
            fi
            #modif="$(cat $path/.lastmodified)"
            echo "$username:$account:$path:$size${modif:+:$modif}"
        fi
    done
}

{'fraction_non_alphanumeric': 0.18312134060165555, 'fraction_numerical': 0.009287300625883304, 'mean_word_length': 1.8244013683010263, 'pattern_counts': {'":': 6, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4184396', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1529, 'n_words': 426}