mirror of
https://github.com/myvesta/vesta
synced 2025-08-21 05:44:08 -07:00
API for user favourites
This commit is contained in:
parent
15a3d9486e
commit
cad14057cc
4 changed files with 326 additions and 1 deletions
111
bin/v-add-user-favourites
Executable file
111
bin/v-add-user-favourites
Executable file
|
@ -0,0 +1,111 @@
|
|||
#!/bin/bash
|
||||
# info: adding user favourites
|
||||
# options: USER SYSTEM OBJECT
|
||||
#
|
||||
# The function adds object to users favourites
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
user=$1
|
||||
system=$(echo "$2" |tr '[:lower:]' '[:upper:]')
|
||||
object=$3
|
||||
|
||||
# Includes
|
||||
source $VESTA/func/main.sh
|
||||
source $VESTA/conf/vesta.conf
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '3' "$#" 'USER SYSTEM OBJECT'
|
||||
validate_format 'user' 'system' 'object'
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
|
||||
# Checking system
|
||||
case $system in
|
||||
USER) check='ok' ;;
|
||||
WEB) check='ok' ;;
|
||||
DNS) check='ok' ;;
|
||||
MAIL) check='ok' ;;
|
||||
DB) check='ok' ;;
|
||||
CRON) check='ok' ;;
|
||||
BACKUP) check='ok' ;;
|
||||
IP) check='ok' ;;
|
||||
PACKAGE) check='ok' ;;
|
||||
FIREWALL) check='ok' ;;
|
||||
*) check_args '2' '0' 'USER SYSTEM OBJECT'
|
||||
esac
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Flushing vars
|
||||
USER=''
|
||||
WEB=''
|
||||
DNS=''
|
||||
MAIL=''
|
||||
DB=''
|
||||
CRON=''
|
||||
BACKUP=''
|
||||
IP=''
|
||||
PACKAGE=''
|
||||
FIREWALL=''
|
||||
|
||||
# Creating config just in case
|
||||
touch $USER_DATA/favourites.conf
|
||||
|
||||
# Reading current values
|
||||
source $USER_DATA/favourites.conf
|
||||
|
||||
# Assigning current system value
|
||||
eval value=\$$system
|
||||
|
||||
# Checking if object is new
|
||||
check_fav=$(echo "$value" |tr ',' '\n'| grep "^$object$")
|
||||
if [ ! -z "$check_fav" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Adding object to favorites
|
||||
if [ -z "$value" ]; then
|
||||
value="$object"
|
||||
else
|
||||
value="$value,$object"
|
||||
fi
|
||||
|
||||
# Updating sytem
|
||||
eval $system=$value
|
||||
|
||||
# Updating user favorites
|
||||
echo "USER='$USER'
|
||||
WEB='$WEB'
|
||||
DNS='$DNS'
|
||||
MAIL='$MAIL'
|
||||
DB='$DB'
|
||||
CRON='$CRON'
|
||||
BACKUP='$BACKUP'
|
||||
IP='$IP'
|
||||
PACKAGE='$PACKAGE'
|
||||
FIREWALL='$FIREWALL'" > $USER_DATA/favourites.conf
|
||||
|
||||
# Changing file permission
|
||||
chmod 640 $USER_DATA/favourites.conf
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Logging
|
||||
log_history "added starred $object in $system listing"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
Loading…
Add table
Add a link
Reference in a new issue