Kaynağa Gözat

Added user history log

Serghey Rodin 13 yıl önce
ebeveyn
işleme
d2685e8b49

+ 4 - 2
bin/v_add_cron_job

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

+ 3 - 4
bin/v_add_database

@@ -30,6 +30,9 @@ source $VESTA/conf/vesta.conf
 source $VESTA/func/main.sh
 source $VESTA/func/main.sh
 source $VESTA/func/db.sh
 source $VESTA/func/db.sh
 
 
+# Hiding password
+A4='******'
+
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                    Verifications                         #
 #                    Verifications                         #
@@ -74,10 +77,6 @@ str="$str DATE='$DATE'"
 echo "$str" >> $USER_DATA/db.conf
 echo "$str" >> $USER_DATA/db.conf
 chmod 660 $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
 # Logging
 log_history "$EVENT"
 log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"

+ 4 - 6
bin/v_add_database_server

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

+ 3 - 4
bin/v_add_mail_account

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

+ 3 - 4
bin/v_add_user

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

+ 3 - 4
bin/v_add_web_domain_stats_user

@@ -20,6 +20,9 @@ source $VESTA/conf/vesta.conf
 source $VESTA/func/main.sh
 source $VESTA/func/main.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
 
 
+# Hiding password
+A4='******'
+
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                    Verifications                         #
 #                    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_USER' "$stats_user"
 update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_crypt"
 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
 # Logging
 log_history "$EVENT"
 log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"

+ 3 - 4
bin/v_change_database_password

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

+ 3 - 4
bin/v_change_mail_account_password

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

+ 3 - 3
bin/v_change_user_password

@@ -17,6 +17,9 @@ password=$2
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/main.sh
 source $VESTA/func/main.sh
 
 
+# Hiding password
+A2='******'
+
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                    Verifications                         #
 #                    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" '$RKEY' "$(gen_password)"
 update_user_value "$user" '$MD5' "$md5"
 update_user_value "$user" '$MD5' "$md5"
 
 
-# Hiding password
-EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT' ARGUMENTS='$user *****'"
-
 # Logging
 # Logging
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 

+ 88 - 0
bin/v_list_user_log

@@ -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

+ 19 - 3
func/main.sh

@@ -2,7 +2,17 @@
 DATE=$(date +%F)
 DATE=$(date +%F)
 TIME=$(date +%T)
 TIME=$(date +%T)
 SCRIPT=$(basename $0)
 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_GZIP=5
 BACKUP_DISK_LIMIT=95
 BACKUP_DISK_LIMIT=95
 BACKUP_LA_LIMIT=5
 BACKUP_LA_LIMIT=5
@@ -40,12 +50,18 @@ E_RESTART=20
 
 
 # Log event function
 # Log event function
 log_event() {
 log_event() {
-    echo "$1 $2" >> $VESTA/log/system.log
+    echo "RC='$1' $2" >> $VESTA/log/system.log
 }
 }
 
 
 # Log user history
 # Log user history
 log_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
 # Argument list checker