mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-14 10:37:39 -07:00
API for user favourites
This commit is contained in:
parent
15a3d9486e
commit
cad14057cc
4 changed files with 326 additions and 1 deletions
102
bin/v-list-user-favourites
Executable file
102
bin/v-list-user-favourites
Executable file
|
@ -0,0 +1,102 @@
|
|||
#!/bin/bash
|
||||
# info: list user favourites
|
||||
# options: USER [FORMAT]
|
||||
#
|
||||
# The function for getting the list of favourite user objects
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
user=$1
|
||||
format=${2-shell}
|
||||
|
||||
# Includes
|
||||
source $VESTA/func/main.sh
|
||||
|
||||
# Json function
|
||||
json_list_favourites() {
|
||||
i=1
|
||||
fileds_count=$(echo "$fields" | wc -w)
|
||||
fvrt_data=$(cat $USER_DATA/favourites.conf >/dev/null)
|
||||
echo '{'
|
||||
eval $fvrt_data
|
||||
for field in $fields; do
|
||||
eval value=$field
|
||||
if [ $i -eq 1 ]; then
|
||||
echo -e "\t\"$value\": {"
|
||||
else
|
||||
if [ $fileds_count -eq $i ]; then
|
||||
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
|
||||
else
|
||||
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
|
||||
fi
|
||||
fi
|
||||
(( ++i))
|
||||
done
|
||||
if [ -n "$value" ]; then
|
||||
echo -e ' }'
|
||||
fi
|
||||
echo -e '}'
|
||||
}
|
||||
|
||||
# Shell function
|
||||
shell_list_favourites() {
|
||||
line=$(cat $USER_DATA/favourites.conf 2>/dev/null)
|
||||
eval $line
|
||||
for field in $fields; do
|
||||
eval key="$field"
|
||||
if [ -z "$key" ]; then
|
||||
key='NULL'
|
||||
fi
|
||||
echo "${field//$/}: $key "
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Checking args
|
||||
check_args '1' "$#" 'USER [FORMAT]'
|
||||
validate_format 'user'
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Flushing vars
|
||||
USER=''
|
||||
WEB=''
|
||||
DNS=''
|
||||
MAIL=''
|
||||
DB=''
|
||||
CRON=''
|
||||
BACKUP=''
|
||||
IP=''
|
||||
PACKAGE=''
|
||||
FIREWALL=''
|
||||
|
||||
# Defining fileds to select
|
||||
OBJ='Favourites'
|
||||
fields='$OBJ $USER $WEB $DNS $MAIL $DB $CRON $BACKUP $IP $PACKAGE $FIREWALL'
|
||||
|
||||
# Listing favourites
|
||||
case $format in
|
||||
json) json_list_favourites ;;
|
||||
plain) shell_list_favourites ;;
|
||||
shell) shell_list_favourites | column -t ;;
|
||||
*) check_args '1' '0' 'USER [FORMAT]'
|
||||
esac
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
exit
|
Loading…
Add table
Add a link
Reference in a new issue