Added user history log

This commit is contained in:
Serghey Rodin 2012-05-02 13:27:57 +03:00
commit d2685e8b49
11 changed files with 136 additions and 38 deletions

View file

@ -17,13 +17,16 @@ hour=$3
day=$4
month=$5
wday=$6
command=$7
command=$(echo $7 | sed -e "s/'/%quote%/g")
job=$8
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
# Assing new value
A7="$command"
#----------------------------------------------------------#
# Verifications #
@ -45,7 +48,6 @@ is_object_free 'cron' 'JOB' "$job"
#----------------------------------------------------------#
# Concatenating cron string
command=$(echo $command | sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"

View file

@ -30,6 +30,9 @@ source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/db.sh
# Hiding password
A4='******'
#----------------------------------------------------------#
# Verifications #
@ -74,10 +77,6 @@ str="$str DATE='$DATE'"
echo "$str" >> $USER_DATA/db.conf
chmod 660 $USER_DATA/db.conf
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$user $database $dbuser ***** $type $host $charset'"
# Logging
log_history "$EVENT"
log_event "$OK" "$EVENT"

View file

@ -19,7 +19,7 @@ host=$2
port=$3
dbuser=$4
dbpass=$5
max_db=${6-300}
A5='******'
charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
template=${8-template1}
@ -28,6 +28,9 @@ source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/db.sh
# Hiding password
max_db=${6-500}
#----------------------------------------------------------#
# Verifications #
@ -69,11 +72,6 @@ chmod 660 $VESTA/conf/$type.conf
# Vesta #
#----------------------------------------------------------#
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$type $host $port $dbuser ****** $max_db $charsets"
EVENT="$EVENT $tpl'"
# Logging
log_event "$OK" "$EVENT"

View file

@ -23,6 +23,9 @@ source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
# Hiding password
A4='******'
#----------------------------------------------------------#
# Verifications #
@ -61,10 +64,6 @@ accounts=$(wc -l $USER_DATA/mail/$domain.conf | cut -f 1 -d ' ')
increase_user_value "$user" '$U_MAIL_ACCOUNTS'
update_object_value 'mail' 'DOMAIN' "$domain" '$ACCOUNTS' "$accounts"
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$user $domain ***** $quota'"
# Logging
log_history "$EVENT"
log_event "$OK" "$EVENT"

View file

@ -21,6 +21,9 @@ lname=$6
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
# Hiding password
A2='******'
is_user_free() {
check_sysuser=$(cut -f 1 -d : /etc/passwd | grep -w "$user" )
if [ ! -z "$check_sysuser" ] || [ -e "$USER_DATA" ]; then
@ -205,10 +208,6 @@ if [ "$user" != 'admin' ]; then
increase_user_value 'admin' '$U_USERS'
fi
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$user ***** $email $package $fname $lname'"
# Logging
log_event "$OK" "$EVENT"

View file

@ -20,6 +20,9 @@ source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
# Hiding password
A4='******'
#----------------------------------------------------------#
# Verifications #
@ -61,10 +64,6 @@ stats_crypt=$(grep $stats_user: $stats_dir/.htpasswd |cut -f 2 -d :)
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user"
update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_crypt"
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$user $domain $stats_user *****'"
# Logging
log_history "$EVENT"
log_event "$OK" "$EVENT"

View file

@ -20,6 +20,9 @@ source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/db.sh
# Hiding password
A3='******'
#----------------------------------------------------------#
# Verifications #
@ -53,10 +56,6 @@ esac
# Update config value
update_object_value 'db' 'DB' "$database" '$MD5' "$md5"
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$user $database *****'"
# Logging
log_event "$OK" "$EVENT"

View file

@ -22,6 +22,9 @@ source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
# Hiding password
A4='******'
#----------------------------------------------------------#
# Verifications #
@ -54,10 +57,6 @@ echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
# Update md5
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5' "$md5"
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$user $domain *****'"
# Logging
log_history "$EVENT"
log_event "$OK" "$EVENT"

View file

@ -17,6 +17,9 @@ password=$2
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
# Hiding password
A2='******'
#----------------------------------------------------------#
# Verifications #
@ -45,9 +48,6 @@ md5=$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)
update_user_value "$user" '$RKEY' "$(gen_password)"
update_user_value "$user" '$MD5' "$md5"
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT' ARGUMENTS='$user *****'"
# Logging
log_event "$OK" "$EVENT"

88
bin/v_list_user_log Executable file
View file

@ -0,0 +1,88 @@
#!/bin/bash
# info: list user log
# options: user [format]
#
# The function of obtaining the list of 100 last users commands.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
format=${2-shell}
# Includes
source $VESTA/func/main.sh
# Json func
json_list_history() {
echo '{'
fileds_count=$(echo $fields| wc -w )
while read line; do
IFS=$'\n'
eval $line
if [ -n "$data" ]; then
echo -e ' },'
fi
i=1
IFS=' '
for field in $fields; do
eval value=\"$field\"
value=$(echo "$value" | sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
if [ $i -eq 1 ]; then
(( ++i))
echo -e "\t\"$value\": {"
else
if [ $i -lt $fileds_count ]; then
(( ++i))
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
else
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
data=1
fi
fi
done
done < $conf
if [ -n "$data" ]; then
echo -e ' }'
fi
echo -e '}'
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'user [format]'
validate_format 'user'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining config
conf=$USER_DATA/history.log
# Defining fileds to select
fields="\$CMD \$A1 \$A2 \$A3 \$A4 \$A5 \$A6 \$A7 \$A8 \$A9 \$TIME \$DATE"
# Listing domains
case $format in
json) json_list_history ;;
plain) nohead=1; shell_list ;;
shell) fields="\$DATE \$TIME \$CMD \$A1 \$A2 \$A3 \$A4 \$A5 \$A6 \$A7"
shell_list ;;
*) check_args '1' '0' 'user [format]'
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

View file

@ -2,7 +2,17 @@
DATE=$(date +%F)
TIME=$(date +%T)
SCRIPT=$(basename $0)
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT' ARGUMENTS='$*'"
A1=$1
A2=$2
A3=$3
A4=$4
A5=$5
A6=$6
A7=$7
A8=$8
A9=$9
EVENT="DATE='$DATE' TIME='$TIME' CMD='$SCRIPT' A1='$A1' A2='$A2' A3='$A3'"
EVENT="$EVENT A4='$A4' A5='$A5' A6='$A6' A7='$A7' A8='$A8' A9='$A9'"
BACKUP_GZIP=5
BACKUP_DISK_LIMIT=95
BACKUP_LA_LIMIT=5
@ -40,12 +50,18 @@ E_RESTART=20
# Log event function
log_event() {
echo "$1 $2" >> $VESTA/log/system.log
echo "RC='$1' $2" >> $VESTA/log/system.log
}
# Log user history
log_history() {
echo "$1" >> $USER_DATA/history.log
touch $USER_DATA/history.log
if [ '99' -lt "$(wc -l $USER_DATA/history.log |cut -f 1 -d ' ')" ]; then
tail -n 99 $USER_DATA/history.log > $USER_DATA/history.log.mv
mv -f $USER_DATA/history.log.mv $USER_DATA/history.log
chmod 660 $USER_DATA/history.log
fi
echo "$1 UNDO='$2'" >> $USER_DATA/history.log
}
# Argument list checker