mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-19 21:04:06 -07:00
Refactoring stage IV (sys)
This commit is contained in:
parent
3dcc180087
commit
3ba10cdc6e
25 changed files with 141 additions and 351 deletions
|
@ -22,34 +22,22 @@ user="${4-admin}"
|
||||||
ip_status="${5-shared}"
|
ip_status="${5-shared}"
|
||||||
ip_name=$6
|
ip_name=$6
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/conf/vesta.conf
|
source $VESTA/conf/vesta.conf
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
source $VESTA/func/ip.sh
|
source $VESTA/func/ip.sh
|
||||||
source $VESTA/func/domain.sh # for namehosting
|
source $VESTA/func/domain.sh
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
# Verifications #
|
# Verifications #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Checking arg number
|
|
||||||
check_args '2' "$#" 'ip mask [interface] [user] [ip_status] [ip_name]'
|
check_args '2' "$#" 'ip mask [interface] [user] [ip_status] [ip_name]'
|
||||||
|
validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
|
||||||
# Checking argument format
|
is_ip_free
|
||||||
validate_format 'ip' 'mask' 'interface' 'user'
|
is_object_valid 'user' 'USER' "$user"
|
||||||
|
is_object_unsuspended 'user' 'USER' "$user"
|
||||||
# Checking system ip
|
|
||||||
is_sys_ip_free
|
|
||||||
|
|
||||||
# Checking user
|
|
||||||
is_object_valid 'user' 'USER' "$user" "$user"
|
|
||||||
|
|
||||||
# Checking ip_status
|
|
||||||
if [ ! -z "$ip_status" ]; then
|
|
||||||
validate_format 'ip_status'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Checking ip_name
|
|
||||||
if [ ! -z "$ip_name" ] ; then
|
if [ ! -z "$ip_name" ] ; then
|
||||||
validate_format 'ip_name'
|
validate_format 'ip_name'
|
||||||
fi
|
fi
|
||||||
|
@ -59,9 +47,8 @@ fi
|
||||||
# Action #
|
# Action #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Get interface number
|
# Get full interface name
|
||||||
i_number=$(get_next_interface_number)
|
get_ip_iface
|
||||||
iface="$interface$i_number"
|
|
||||||
|
|
||||||
# Defining config paths
|
# Defining config paths
|
||||||
conf='/etc/httpd/conf.d/vesta.conf'
|
conf='/etc/httpd/conf.d/vesta.conf'
|
||||||
|
@ -73,15 +60,12 @@ rconf='/etc/httpd/conf.d/rpaf.conf'
|
||||||
/sbin/ifconfig "$iface" "$ip" netmask "$mask"
|
/sbin/ifconfig "$iface" "$ip" netmask "$mask"
|
||||||
|
|
||||||
# Adding startup script
|
# Adding startup script
|
||||||
ip_add_startup
|
create_ip_startup
|
||||||
|
|
||||||
# Adding vesta ip
|
# Adding vesta ip
|
||||||
ip_add_vesta
|
create_vesta_ip
|
||||||
|
|
||||||
# Importing main config
|
# Namehosting support
|
||||||
source $VESTA/conf/vesta.conf
|
|
||||||
|
|
||||||
# Adding namehosting support
|
|
||||||
namehost_ip_support
|
namehost_ip_support
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,7 +77,7 @@ namehost_ip_support
|
||||||
increase_user_value "$user" '$IP_OWNED'
|
increase_user_value "$user" '$IP_OWNED'
|
||||||
if [ "$user" = 'admin' ]; then
|
if [ "$user" = 'admin' ]; then
|
||||||
if [ "$ip_status" = 'shared' ]; then
|
if [ "$ip_status" = 'shared' ]; then
|
||||||
for user in $(ls $V_USERS/); do
|
for user in $(ls $VESTA/data/users); do
|
||||||
increase_user_value "$user" '$IP_AVAIL'
|
increase_user_value "$user" '$IP_AVAIL'
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
@ -104,7 +88,7 @@ else
|
||||||
increase_user_value 'admin' '$IP_AVAIL'
|
increase_user_value 'admin' '$IP_AVAIL'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Adding task to the vesta pipe
|
# Restart web server
|
||||||
if [ "$web_restart" = 'yes' ]; then
|
if [ "$web_restart" = 'yes' ]; then
|
||||||
$BIN/v_restart_web "$EVENT"
|
$BIN/v_restart_web "$EVENT"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -40,7 +40,7 @@ is_object_unsuspended 'user' 'USER' "$user"
|
||||||
is_object_valid 'web' 'DOMAIN' "$domain"
|
is_object_valid 'web' 'DOMAIN' "$domain"
|
||||||
is_object_unsuspended 'web' 'DOMAIN' "$domain"
|
is_object_unsuspended 'web' 'DOMAIN' "$domain"
|
||||||
is_object_value_empty 'web' 'DOMAIN' "$domain" '$SSL'
|
is_object_value_empty 'web' 'DOMAIN' "$domain" '$SSL'
|
||||||
is_sys_ip_owner
|
is_ip_owner
|
||||||
is_web_domain_cert_valid
|
is_web_domain_cert_valid
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
key=$(echo "$1" | tr '[:lower:]' '[:upper:]' )
|
key=$(echo "$1" | tr '[:lower:]' '[:upper:]' )
|
||||||
value=$2
|
value=$2
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/conf/vesta.conf
|
source $VESTA/conf/vesta.conf
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
@ -23,17 +23,12 @@ source $VESTA/func/shared.sh
|
||||||
# Verifications #
|
# Verifications #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Checking args
|
|
||||||
check_args '2' "$#" 'key value'
|
check_args '2' "$#" 'key value'
|
||||||
|
|
||||||
# Checking argument format
|
|
||||||
validate_format 'key'
|
validate_format 'key'
|
||||||
|
|
||||||
# Checking key existance
|
|
||||||
check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf)
|
check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf)
|
||||||
if [ -z "$check_ckey" ]; then
|
if [ -z "$check_ckey" ]; then
|
||||||
echo "Error: key not found"
|
echo "Error: key $key not found"
|
||||||
log_event 'debug' "$E_INVALID $EVENT"
|
log_event "$E_INVALID" "$EVENT"
|
||||||
exit $E_INVALID
|
exit $E_INVALID
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
ip=$1
|
ip=$1
|
||||||
ip_name=$2
|
ip_name=$2
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/conf/vesta.conf
|
source $VESTA/conf/vesta.conf
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
source $VESTA/func/ip.sh
|
source $VESTA/func/ip.sh
|
||||||
|
@ -23,14 +23,9 @@ source $VESTA/func/ip.sh
|
||||||
# Verifications #
|
# Verifications #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Checking arg number
|
|
||||||
check_args '2' "$#" 'ip ip_name'
|
check_args '2' "$#" 'ip ip_name'
|
||||||
|
|
||||||
# Checking argument format
|
|
||||||
validate_format 'ip' 'ip_name'
|
validate_format 'ip' 'ip_name'
|
||||||
|
is_ip_valid
|
||||||
# Checking system ip
|
|
||||||
is_sys_ip_valid
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
@ -38,7 +33,7 @@ is_sys_ip_valid
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Changing ip name
|
# Changing ip name
|
||||||
update_sys_ip_value '$NAME' "$ip_name"
|
update_ip_value '$NAME' "$ip_name"
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -14,7 +14,6 @@ ip=$1
|
||||||
user=$2
|
user=$2
|
||||||
|
|
||||||
# Importing variables
|
# Importing variables
|
||||||
source $VESTA/conf/vesta.conf
|
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
source $VESTA/func/ip.sh
|
source $VESTA/func/ip.sh
|
||||||
|
|
||||||
|
@ -23,25 +22,12 @@ source $VESTA/func/ip.sh
|
||||||
# Verifications #
|
# Verifications #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Checking arg number
|
|
||||||
check_args '2' "$#" 'ip user'
|
check_args '2' "$#" 'ip user'
|
||||||
|
|
||||||
# Checking argument format
|
|
||||||
validate_format 'ip' 'user'
|
validate_format 'ip' 'user'
|
||||||
|
|
||||||
# Checking user
|
|
||||||
is_object_valid 'user' 'USER' "$user"
|
is_object_valid 'user' 'USER' "$user"
|
||||||
|
|
||||||
# Checking user is active
|
|
||||||
is_object_unsuspended 'user' 'USER' "$user"
|
is_object_unsuspended 'user' 'USER' "$user"
|
||||||
|
is_ip_valid
|
||||||
# Checking system ip
|
|
||||||
is_sys_ip_valid
|
|
||||||
|
|
||||||
# Checking webdomains on ip
|
|
||||||
is_ip_key_empty '$U_WEB_DOMAINS'
|
is_ip_key_empty '$U_WEB_DOMAINS'
|
||||||
|
|
||||||
# Checking users on ip
|
|
||||||
is_ip_key_empty '$U_SYS_USERS'
|
is_ip_key_empty '$U_SYS_USERS'
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,14 +36,14 @@ is_ip_key_empty '$U_SYS_USERS'
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Changing ip owner
|
# Changing ip owner
|
||||||
ip_owner=$(get_sys_ip_value '$OWNER')
|
ip_owner=$(get_ip_value '$OWNER')
|
||||||
if [ "$ip_owner" != "$user" ]; then
|
if [ "$ip_owner" != "$user" ]; then
|
||||||
ip_status="$(get_sys_ip_value '$STATUS')"
|
ip_status="$(get_ip_value '$STATUS')"
|
||||||
update_sys_ip_value '$OWNER' "$user"
|
update_ip_value '$OWNER' "$user"
|
||||||
decrease_user_value "$ip_owner" '$IP_OWNED'
|
decrease_user_value "$ip_owner" '$IP_OWNED'
|
||||||
if [ "$ip_owner" = 'admin' ]; then
|
if [ "$ip_owner" = 'admin' ]; then
|
||||||
if [ "$ip_status" = 'shared' ]; then
|
if [ "$ip_status" = 'shared' ]; then
|
||||||
for vesta_user in $(ls $V_USERS/); do
|
for vesta_user in $(ls $VESTA/data/users); do
|
||||||
decrease_user_value "$vesta_user" '$IP_AVAIL'
|
decrease_user_value "$vesta_user" '$IP_AVAIL'
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
@ -71,7 +57,7 @@ if [ "$ip_owner" != "$user" ]; then
|
||||||
increase_user_value "$user" '$IP_OWNED'
|
increase_user_value "$user" '$IP_OWNED'
|
||||||
if [ "$user" = 'admin' ]; then
|
if [ "$user" = 'admin' ]; then
|
||||||
if [ "$ip_status" = 'shared' ]; then
|
if [ "$ip_status" = 'shared' ]; then
|
||||||
for user in $(ls $V_USERS/); do
|
for user in $(ls $VESTA/data/users); do
|
||||||
increase_user_value "$user" '$IP_AVAIL'
|
increase_user_value "$user" '$IP_AVAIL'
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
ip=$1
|
ip=$1
|
||||||
ip_status=$2
|
ip_status=$2
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/conf/vesta.conf
|
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
source $VESTA/func/ip.sh
|
source $VESTA/func/ip.sh
|
||||||
|
|
||||||
|
@ -23,32 +22,21 @@ source $VESTA/func/ip.sh
|
||||||
# Verifications #
|
# Verifications #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Checking arg number
|
|
||||||
check_args '2' "$#" 'ip ip_status'
|
check_args '2' "$#" 'ip ip_status'
|
||||||
|
|
||||||
# Checking argument format
|
|
||||||
validate_format 'ip' 'ip_status'
|
validate_format 'ip' 'ip_status'
|
||||||
|
is_ip_valid
|
||||||
# Checking system ip
|
if [ "$ip_status" = "$(get_ip_value '$STATUS')" ]; then
|
||||||
is_sys_ip_valid
|
echo "Error: status $ip_status is already set"
|
||||||
|
log_event "$E_EXISTS" "$EVENT"
|
||||||
# Checking current status
|
|
||||||
current_status=$(get_sys_ip_value '$STATUS')
|
|
||||||
if [ "$ip_status" = "$current_status" ]; then
|
|
||||||
echo "Error: status is already set"
|
|
||||||
log_event 'debug' "$E_EXISTS $EVENT"
|
|
||||||
exit $E_EXISTS
|
exit $E_EXISTS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Parsing current ip usage
|
web_domains=$(get_ip_value '$U_WEB_DOMAINS')
|
||||||
web_domains=$(get_sys_ip_value '$U_WEB_DOMAINS')
|
sys_user=$(get_ip_value '$U_SYS_USERS')
|
||||||
sys_user=$(get_sys_ip_value '$U_SYS_USERS')
|
ip_owner=$(get_ip_value '$OWNER')
|
||||||
ip_owner=$(get_sys_ip_value '$OWNER')
|
|
||||||
|
|
||||||
# Checking condition
|
|
||||||
if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then
|
if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then
|
||||||
echo "Error: ip is used"
|
echo "Error: ip $ip is used"
|
||||||
log_event 'debug' "$E_INUSE $EVENT"
|
log_event "$E_INUSE" "$EVENT"
|
||||||
exit $E_INUSE
|
exit $E_INUSE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -58,7 +46,7 @@ fi
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Changing ip name
|
# Changing ip name
|
||||||
update_sys_ip_value '$STATUS' "$ip_status"
|
update_ip_value '$STATUS' "$ip_status"
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -24,24 +24,12 @@ source $VESTA/func/domain.sh
|
||||||
# Verifications #
|
# Verifications #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Checking arg number
|
|
||||||
check_args '1' "$#" 'ip'
|
check_args '1' "$#" 'ip'
|
||||||
|
|
||||||
# Checking argument format
|
|
||||||
validate_format 'ip'
|
validate_format 'ip'
|
||||||
|
is_ip_valid "$ip"
|
||||||
# Checking system ip
|
|
||||||
is_sys_ip_valid "$ip"
|
|
||||||
|
|
||||||
# Checking webdomains on ip
|
|
||||||
is_ip_key_empty '$U_WEB_DOMAINS'
|
is_ip_key_empty '$U_WEB_DOMAINS'
|
||||||
|
|
||||||
# Checking users on ip
|
|
||||||
is_ip_key_empty '$U_SYS_USERS'
|
is_ip_key_empty '$U_SYS_USERS'
|
||||||
|
|
||||||
# Checking interface
|
|
||||||
interface=$(get_current_interface)
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
# Action #
|
# Action #
|
||||||
|
@ -54,10 +42,11 @@ iconf='/etc/sysconfig/network-scripts/ifcfg'
|
||||||
rconf='/etc/httpd/conf.d/rpaf.conf'
|
rconf='/etc/httpd/conf.d/rpaf.conf'
|
||||||
|
|
||||||
# Get ip owner
|
# Get ip owner
|
||||||
user="$(get_sys_ip_value '$OWNER')"
|
user="$(get_ip_value '$OWNER')"
|
||||||
ip_status="$(get_sys_ip_value '$STATUS')"
|
ip_status="$(get_ip_value '$STATUS')"
|
||||||
|
|
||||||
# Deleting interface
|
# Deleting interface
|
||||||
|
get_current_interface
|
||||||
/sbin/ifconfig "$interface" down
|
/sbin/ifconfig "$interface" down
|
||||||
|
|
||||||
# Deleting startup script
|
# Deleting startup script
|
||||||
|
@ -66,9 +55,6 @@ rm -f $iconf-$interface
|
||||||
# Deleting vesta ip
|
# Deleting vesta ip
|
||||||
rm -f $VESTA/data/ips/$ip
|
rm -f $VESTA/data/ips/$ip
|
||||||
|
|
||||||
# Importing main config
|
|
||||||
source $VESTA/conf/vesta.conf
|
|
||||||
|
|
||||||
# Deleting namehosting support
|
# Deleting namehosting support
|
||||||
namehost_ip_disable
|
namehost_ip_disable
|
||||||
|
|
||||||
|
@ -84,7 +70,7 @@ fi
|
||||||
|
|
||||||
if [ "$user" = 'admin' ]; then
|
if [ "$user" = 'admin' ]; then
|
||||||
if [ "$ip_status" = 'shared' ]; then
|
if [ "$ip_status" = 'shared' ]; then
|
||||||
for user in $(ls $V_USERS/); do
|
for user in $(ls $VESTA/data/users/); do
|
||||||
decrease_user_value "$user" '$IP_AVAIL'
|
decrease_user_value "$user" '$IP_AVAIL'
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
# Argument defenition
|
# Argument defenition
|
||||||
format=${1-shell}
|
format=${1-shell}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
# Json function
|
# Json function
|
||||||
|
@ -21,8 +21,6 @@ json_list_iface() {
|
||||||
int_counter=$(echo "$interfaces" | wc -l)
|
int_counter=$(echo "$interfaces" | wc -l)
|
||||||
i=1
|
i=1
|
||||||
echo '['
|
echo '['
|
||||||
|
|
||||||
# Listing ifaces
|
|
||||||
for interface in $interfaces; do
|
for interface in $interfaces; do
|
||||||
if [ "$i" -lt "$int_counter" ]; then
|
if [ "$i" -lt "$int_counter" ]; then
|
||||||
echo -e "\t\"$interface\","
|
echo -e "\t\"$interface\","
|
||||||
|
@ -41,7 +39,6 @@ shell_list_iface() {
|
||||||
echo "INTERFACES"
|
echo "INTERFACES"
|
||||||
echo "----------"
|
echo "----------"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for interface in $interfaces; do
|
for interface in $interfaces; do
|
||||||
echo "$interface"
|
echo "$interface"
|
||||||
done
|
done
|
||||||
|
|
|
@ -14,7 +14,7 @@ ip=$1
|
||||||
IP=$ip
|
IP=$ip
|
||||||
format=${2-shell}
|
format=${2-shell}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
source $VESTA/func/ip.sh
|
source $VESTA/func/ip.sh
|
||||||
|
|
||||||
|
@ -23,17 +23,10 @@ json_list_ip() {
|
||||||
i=1
|
i=1
|
||||||
fileds_count=$(echo "$fields" | wc -w)
|
fileds_count=$(echo "$fields" | wc -w)
|
||||||
ip_data=$(cat $VESTA/data/ips/$IP)
|
ip_data=$(cat $VESTA/data/ips/$IP)
|
||||||
|
|
||||||
# Print top bracket
|
|
||||||
echo '{'
|
echo '{'
|
||||||
|
|
||||||
# Assign key=value
|
|
||||||
eval $ip_data
|
eval $ip_data
|
||||||
|
|
||||||
for field in $fields; do
|
for field in $fields; do
|
||||||
eval value=$field
|
eval value=$field
|
||||||
|
|
||||||
# Checking first field
|
|
||||||
if [ $i -eq 1 ]; then
|
if [ $i -eq 1 ]; then
|
||||||
echo -e "\t\"$value\": {"
|
echo -e "\t\"$value\": {"
|
||||||
else
|
else
|
||||||
|
@ -45,26 +38,21 @@ json_list_ip() {
|
||||||
fi
|
fi
|
||||||
(( ++i))
|
(( ++i))
|
||||||
done
|
done
|
||||||
|
|
||||||
# If there was any output
|
|
||||||
if [ -n "$value" ]; then
|
if [ -n "$value" ]; then
|
||||||
echo -e ' }'
|
echo -e ' }'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Printing bottom json bracket
|
|
||||||
echo -e '}'
|
echo -e '}'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Shell function
|
# Shell function
|
||||||
shell_list_ip() {
|
shell_list_ip() {
|
||||||
line=$(cat $VESTA/data/ips/$IP)
|
line=$(cat $VESTA/data/ips/$IP)
|
||||||
|
|
||||||
# Assing key=value
|
|
||||||
eval $line
|
eval $line
|
||||||
|
|
||||||
# Print result line
|
|
||||||
for field in $fields; do
|
for field in $fields; do
|
||||||
eval key="$field"
|
eval key="$field"
|
||||||
|
if [ -z "$key" ]; then
|
||||||
|
key='NULL'
|
||||||
|
fi
|
||||||
echo "${field//$/}: $key "
|
echo "${field//$/}: $key "
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -76,12 +64,8 @@ shell_list_ip() {
|
||||||
|
|
||||||
# Checking args
|
# Checking args
|
||||||
check_args '1' "$#" 'ip [format]'
|
check_args '1' "$#" 'ip [format]'
|
||||||
|
|
||||||
# Checking argument format
|
|
||||||
validate_format 'ip'
|
validate_format 'ip'
|
||||||
|
is_ip_valid
|
||||||
# Checking ip
|
|
||||||
is_sys_ip_valid
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
# Action #
|
# Action #
|
||||||
|
@ -89,8 +73,8 @@ is_sys_ip_valid
|
||||||
conf=$VESTA/data/ips/$IP
|
conf=$VESTA/data/ips/$IP
|
||||||
|
|
||||||
# Defining fileds to select
|
# Defining fileds to select
|
||||||
fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS
|
fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE
|
||||||
$INTERFACE $NETMASK $DATE'
|
$NETMASK $DATE'
|
||||||
|
|
||||||
# Listing ip
|
# Listing ip
|
||||||
case $format in
|
case $format in
|
||||||
|
|
|
@ -12,39 +12,27 @@
|
||||||
# Argument defenition
|
# Argument defenition
|
||||||
format=${1-shell}
|
format=${1-shell}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
# Json function
|
# Json function
|
||||||
json_list_ips() {
|
json_list_ips() {
|
||||||
# Print top bracket
|
|
||||||
echo '{'
|
echo '{'
|
||||||
|
|
||||||
# Definining ip list
|
|
||||||
ip_list=$(ls $VESTA/data/ips/)
|
ip_list=$(ls $VESTA/data/ips/)
|
||||||
|
|
||||||
fileds_count=$(echo "$fields" | wc -w)
|
fileds_count=$(echo "$fields" | wc -w)
|
||||||
|
|
||||||
# Starting main loop
|
|
||||||
for IP in $ip_list; do
|
for IP in $ip_list; do
|
||||||
# Assing key=value
|
|
||||||
ip_data=$(cat $VESTA/data/ips/$IP)
|
ip_data=$(cat $VESTA/data/ips/$IP)
|
||||||
eval $ip_data
|
eval $ip_data
|
||||||
|
|
||||||
# Closing bracket if there already was output
|
|
||||||
if [ -n "$data" ]; then
|
if [ -n "$data" ]; then
|
||||||
echo -e ' },'
|
echo -e ' },'
|
||||||
fi
|
fi
|
||||||
i=1
|
i=1
|
||||||
for field in $fields; do
|
for field in $fields; do
|
||||||
eval value=$field
|
eval value=$field
|
||||||
|
|
||||||
if [ $i -eq 1 ]; then
|
if [ $i -eq 1 ]; then
|
||||||
# Printing parrent
|
|
||||||
(( ++i))
|
(( ++i))
|
||||||
echo -e "\t\"$value\": {"
|
echo -e "\t\"$value\": {"
|
||||||
else
|
else
|
||||||
# Printing child
|
|
||||||
if [ $i -lt $fileds_count ]; then
|
if [ $i -lt $fileds_count ]; then
|
||||||
(( ++i))
|
(( ++i))
|
||||||
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
|
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
|
||||||
|
@ -55,22 +43,16 @@ json_list_ips() {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
# Closing bracket if there was output
|
|
||||||
if [ -n "$data" ]; then
|
if [ -n "$data" ]; then
|
||||||
echo -e ' }'
|
echo -e ' }'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Printing bottom bracket
|
|
||||||
echo -e '}'
|
echo -e '}'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Shell function
|
# Shell function
|
||||||
shell_list_ips() {
|
shell_list_ips() {
|
||||||
ip_list=$(ls $VESTA/data/ips/)
|
ip_list=$(ls $VESTA/data/ips/)
|
||||||
|
|
||||||
if [ -z "$nohead" ]; then
|
if [ -z "$nohead" ]; then
|
||||||
# Print brief info
|
|
||||||
echo "${fields//$/}"
|
echo "${fields//$/}"
|
||||||
for a in $fields; do
|
for a in $fields; do
|
||||||
echo -e "--------- \c"
|
echo -e "--------- \c"
|
||||||
|
@ -78,15 +60,9 @@ shell_list_ips() {
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Starting main loop
|
|
||||||
for IP in $ip_list; do
|
for IP in $ip_list; do
|
||||||
# Reading user data
|
|
||||||
ip_data=$(cat $VESTA/data/ips/$IP)
|
ip_data=$(cat $VESTA/data/ips/$IP)
|
||||||
|
|
||||||
# Assign key/value config
|
|
||||||
eval $ip_data
|
eval $ip_data
|
||||||
|
|
||||||
# Print result line
|
|
||||||
eval echo "$fields"
|
eval echo "$fields"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -95,9 +71,9 @@ shell_list_ips() {
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
# Action #
|
# Action #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
conf=$VESTA/data/ips/*
|
|
||||||
|
|
||||||
# Defining fileds to select
|
# Defining fileds to select
|
||||||
|
conf=$VESTA/data/ips/*
|
||||||
fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS"
|
fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS"
|
||||||
fields="$fields \$INTERFACE \$NETMASK \$DATE"
|
fields="$fields \$INTERFACE \$NETMASK \$DATE"
|
||||||
|
|
||||||
|
|
|
@ -22,32 +22,25 @@ json_list_rrd() {
|
||||||
if [ "$i" -ne 1 ]; then
|
if [ "$i" -ne 1 ]; then
|
||||||
echo -e "\t},"
|
echo -e "\t},"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define title
|
|
||||||
if [ "$type" = 'la' ]; then
|
if [ "$type" = 'la' ]; then
|
||||||
title="Load Average"
|
title="Load Average"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$type" = 'mem' ]; then
|
if [ "$type" = 'mem' ]; then
|
||||||
title="Memory Usage"
|
title="Memory Usage"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$type" = 'net' ]; then
|
if [ "$type" = 'net' ]; then
|
||||||
title="Bandwidth Usage $rrd"
|
title="Bandwidth Usage $rrd"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$type" = 'web' ] || [ "$type" = 'ftp' ] ||\
|
if [ "$type" = 'web' ] || [ "$type" = 'ftp' ] ||\
|
||||||
[ "$type" = 'ssh' ]; then
|
[ "$type" = 'ssh' ]; then
|
||||||
title="$(echo $rrd| tr '[:lower:]' '[:upper:]') Usage"
|
title="$(echo $rrd| tr '[:lower:]' '[:upper:]') Usage"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$type" = 'db' ]; then
|
if [ "$type" = 'db' ]; then
|
||||||
db_type=$(echo $rrd|cut -f 1 -d _ |sed -e 's/mysql/MySQL/g' \
|
db_type=$(echo $rrd|cut -f 1 -d _ |sed -e 's/mysql/MySQL/g' \
|
||||||
-e 's/pgsql/PostgreSQL/g' )
|
-e 's/pgsql/PostgreSQL/g' )
|
||||||
db_host=$(echo $rrd|cut -f 2 -d _ )
|
db_host=$(echo $rrd|cut -f 2 -d _ )
|
||||||
title="$db_type Usage on $db_host"
|
title="$db_type Usage on $db_host"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\t\"$i\": {"
|
echo -e "\t\"$i\": {"
|
||||||
echo -e "\t\t\"TYPE\": \"$type\"",
|
echo -e "\t\t\"TYPE\": \"$type\"",
|
||||||
echo -e "\t\t\"RRD\": \"$rrd\"",
|
echo -e "\t\t\"RRD\": \"$rrd\"",
|
||||||
|
@ -55,7 +48,6 @@ json_list_rrd() {
|
||||||
(( ++i))
|
(( ++i))
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$i" -gt 1 ]; then
|
if [ "$i" -gt 1 ]; then
|
||||||
echo -e "\t}"
|
echo -e "\t}"
|
||||||
fi
|
fi
|
||||||
|
@ -65,11 +57,9 @@ json_list_rrd() {
|
||||||
# Define jshell function
|
# Define jshell function
|
||||||
shell_list_rrd() {
|
shell_list_rrd() {
|
||||||
if [ -z "$nohead" ]; then
|
if [ -z "$nohead" ]; then
|
||||||
# Print brief info
|
|
||||||
echo "PATH"
|
echo "PATH"
|
||||||
echo "---------"
|
echo "---------"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for type in $rrd_types; do
|
for type in $rrd_types; do
|
||||||
for rrd in $(ls $RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do
|
for rrd in $(ls $RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do
|
||||||
echo "$RRD/$type/$rrd.rrd"
|
echo "$RRD/$type/$rrd.rrd"
|
||||||
|
@ -101,6 +91,7 @@ fi
|
||||||
if [ -n "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then
|
if [ -n "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then
|
||||||
rrd_types="$rrd_types ftp"
|
rrd_types="$rrd_types ftp"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rrd_types="$rrd_types ssh"
|
rrd_types="$rrd_types ssh"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
user=${1-admin}
|
user=${1-admin}
|
||||||
ip_status=${2-shared}
|
ip_status=${2-shared}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/conf/vesta.conf # include for internal func
|
source $VESTA/conf/vesta.conf # include for internal func
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
source $VESTA/func/ip.sh
|
source $VESTA/func/ip.sh
|
||||||
|
@ -26,19 +26,9 @@ source $VESTA/func/domain.sh
|
||||||
# Verifications #
|
# Verifications #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Checking arg number
|
|
||||||
check_args '0' "$#" '[user] [ip_status]'
|
check_args '0' "$#" '[user] [ip_status]'
|
||||||
|
validate_format 'user' 'ip_status'
|
||||||
# Checking user
|
is_object_valid 'user' 'USER' "$user" "$user"
|
||||||
if [ ! -z "$1" ]; then
|
|
||||||
validate_format 'user'
|
|
||||||
is_object_valid 'user' 'USER' "$user" "$user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Checking ip_status
|
|
||||||
if [ ! -z "$2" ]; then
|
|
||||||
validate_format 'ip_status'
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
@ -46,7 +36,7 @@ fi
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Get ip list
|
# Get ip list
|
||||||
ip_list=$(/sbin/ifconfig |grep 'inet addr:'|cut -f 2 -d :|\
|
ip_list=$(/sbin/ifconfig | grep 'inet addr:' | cut -f 2 -d : | \
|
||||||
cut -f 1 -d ' '| grep -v 127.0.0.1)
|
cut -f 1 -d ' '| grep -v 127.0.0.1)
|
||||||
|
|
||||||
# Get vesta registered ip list
|
# Get vesta registered ip list
|
||||||
|
@ -60,15 +50,14 @@ rconf='/etc/httpd/conf.d/rpaf.conf'
|
||||||
|
|
||||||
# Comparing each ip
|
# Comparing each ip
|
||||||
for ip in $ip_list; do
|
for ip in $ip_list; do
|
||||||
check_ip=$(echo $vesta_ip_list|grep -w "$ip")
|
check_ip=$(echo $vesta_ip_list | grep -w "$ip")
|
||||||
|
|
||||||
# Checking ip registered
|
# Checking ip registered
|
||||||
if [ -z "$check_ip" ]; then
|
if [ -z "$check_ip" ]; then
|
||||||
|
|
||||||
# Parsing additional params
|
# Parsing additional params
|
||||||
iface=$(/sbin/ifconfig|grep -B1 -w "$ip"|head -n 1|cut -f 1 -d ' ')
|
iface=$(/sbin/ifconfig |grep -B1 -w $ip |head -n 1 |cut -f 1 -d ' ')
|
||||||
interface=$(echo "$iface" | cut -f 1 -d :)
|
interface=$(echo "$iface" | cut -f 1 -d :)
|
||||||
mask=$(/sbin/ifconfig |grep -w "$ip"|awk -F "Mask:" '{print $2}')
|
mask=$(/sbin/ifconfig |grep -w $ip |awk -F "Mask:" '{print $2}')
|
||||||
|
|
||||||
# Adding vesta ip
|
# Adding vesta ip
|
||||||
ip_add_vesta
|
ip_add_vesta
|
||||||
|
@ -82,7 +71,7 @@ for ip in $ip_list; do
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# NOTE: later we'll make revers comparation
|
# TBD: revers comparation
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,7 +82,7 @@ done
|
||||||
# Updating user conf
|
# Updating user conf
|
||||||
increase_user_value "$user" '$IP_OWNED'
|
increase_user_value "$user" '$IP_OWNED'
|
||||||
|
|
||||||
# Adding task to the vesta pipe
|
# Restart web server
|
||||||
if [ "$web_restart" = 'yes' ]; then
|
if [ "$web_restart" = 'yes' ]; then
|
||||||
$BIN/v_restart_web "$EVENT"
|
$BIN/v_restart_web "$EVENT"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -19,43 +19,18 @@ queue=$1
|
||||||
# mostly by cron wich not read it by itself
|
# mostly by cron wich not read it by itself
|
||||||
source /etc/profile.d/vesta.sh
|
source /etc/profile.d/vesta.sh
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/conf/vesta.conf
|
source $VESTA/conf/vesta.conf
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
# Export PATH for cron
|
# Export PATH for cron
|
||||||
PATH=$PATH:$BIN
|
PATH=$PATH:$BIN
|
||||||
|
export $PATH
|
||||||
# Defining pipe functions
|
|
||||||
restart_pipe() {
|
|
||||||
bash $VESTA/data/queue/restart.pipe
|
|
||||||
rm $VESTA/data/queue/restart.pipe
|
|
||||||
touch $VESTA/data/queue/restart.pipe
|
|
||||||
}
|
|
||||||
|
|
||||||
stats_pipe() {
|
|
||||||
bash $VESTA/data/queue/stats.pipe
|
|
||||||
}
|
|
||||||
|
|
||||||
disk_pipe() {
|
|
||||||
bash $VESTA/data/queue/disk.pipe
|
|
||||||
}
|
|
||||||
|
|
||||||
traff_pipe() {
|
|
||||||
bash $VESTA/data/queue/traffic.pipe
|
|
||||||
}
|
|
||||||
|
|
||||||
backup_pipe() {
|
|
||||||
bash $VESTA/data/queue/backup.pip
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
# Verifications #
|
# Verifications #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Checking arg number
|
|
||||||
check_args '1' "$#" 'queue'
|
check_args '1' "$#" 'queue'
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,12 +38,15 @@ check_args '1' "$#" 'queue'
|
||||||
# Action #
|
# Action #
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
# Defining pipe functions
|
||||||
case $queue in
|
case $queue in
|
||||||
restart) restart_pipe ;;
|
restart) bash $VESTA/data/queue/restart.pipe;
|
||||||
stats) stats_pipe ;;
|
rm $VESTA/data/queue/restart.pipe;
|
||||||
backup) backup_pipe ;;
|
touch $VESTA/data/queue/restart.pipe;;
|
||||||
disk) disk_pipe ;;
|
stats) bash $VESTA/data/queue/stats.pipe;;
|
||||||
traffic) traff_pipe ;;
|
backup) bash $VESTA/data/queue/backup.pip;;
|
||||||
|
disk) bash $VESTA/data/queue/disk.pipe;;
|
||||||
|
traffic) bash $VESTA/data/queue/traffic.pipe;;
|
||||||
*) check_args '1' '0' 'queue'
|
*) check_args '1' '0' 'queue'
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,10 @@
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
# Importing system enviroment as we run this script
|
# Importing system enviroment as we run this script
|
||||||
# mostly by cron wich do not read it by itself
|
# mostly by cron wich do not read it by itself
|
||||||
source /etc/profile.d/vesta.sh
|
source /etc/profile.d/vesta.sh
|
||||||
|
|
||||||
|
# Includes
|
||||||
# Importing variables
|
|
||||||
source $VESTA/conf/vesta.conf
|
source $VESTA/conf/vesta.conf
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,9 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/conf/vesta.conf
|
source $VESTA/conf/vesta.conf
|
||||||
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@ for host in $hosts; do
|
||||||
if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $PORT ]
|
if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $PORT ]
|
||||||
then
|
then
|
||||||
echo "Error: config is broken"
|
echo "Error: config is broken"
|
||||||
log_event 'debug' "$E_PARSING $EVENT"
|
log_event "$E_PARSING" "$EVENT"
|
||||||
exit $E_PARSING
|
exit $E_PARSING
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,11 +82,10 @@ for host in $hosts; do
|
||||||
if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ]
|
if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ]
|
||||||
then
|
then
|
||||||
echo "Error: config is broken"
|
echo "Error: config is broken"
|
||||||
log_event 'debug' "$E_PARSING $EVENT"
|
log_event "$E_PARSING" "$EVENT"
|
||||||
exit $E_PARSING
|
exit $E_PARSING
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Parsing data
|
# Parsing data
|
||||||
q='SELECT SUM(xact_commit + xact_rollback), SUM(numbackends)
|
q='SELECT SUM(xact_commit + xact_rollback), SUM(numbackends)
|
||||||
FROM pg_stat_database;'
|
FROM pg_stat_database;'
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
update=$1
|
update=$1
|
||||||
period=${1-daily}
|
period=${1-daily}
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------#
|
#----------------------------------------------------------#
|
||||||
|
|
|
@ -17,7 +17,7 @@ updates=''
|
||||||
# Importing system enviroment
|
# Importing system enviroment
|
||||||
source /etc/profile.d/vesta.sh
|
source /etc/profile.d/vesta.sh
|
||||||
|
|
||||||
# Importing variables
|
# Includes
|
||||||
source $VESTA/conf/vesta.conf
|
source $VESTA/conf/vesta.conf
|
||||||
source $VESTA/func/shared.sh
|
source $VESTA/func/shared.sh
|
||||||
|
|
||||||
|
|
150
func/ip.sh
150
func/ip.sh
|
@ -25,7 +25,7 @@ is_ip_avalable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check ip ownership
|
# Check ip ownership
|
||||||
is_sys_ip_owner() {
|
is_ip_owner() {
|
||||||
# Parsing ip
|
# Parsing ip
|
||||||
owner=$(grep 'OWNER=' $VESTA/data/ips/$IP|cut -f 2 -d \')
|
owner=$(grep 'OWNER=' $VESTA/data/ips/$IP|cut -f 2 -d \')
|
||||||
if [ "$owner" != "$user" ]; then
|
if [ "$owner" != "$user" ]; then
|
||||||
|
@ -35,114 +35,77 @@ is_sys_ip_owner() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check if ip address is free
|
||||||
is_sys_ip_free() {
|
is_ip_free() {
|
||||||
# Parsing system ips
|
list=$(/sbin/ifconfig |grep 'inet addr:' |cut -f 2 -d : |cut -f 1 -d ' ')
|
||||||
ip_list=$(/sbin/ifconfig|grep 'inet addr:'|cut -f 2 -d ':'|cut -f 1 -d " ")
|
ip_check=$(echo "$list" |grep -w "$ip")
|
||||||
|
|
||||||
# Checking ip existance
|
|
||||||
ip_check=$(echo "$ip_list"|grep -w "$ip")
|
|
||||||
if [ -n "$ip_check" ] || [ -e "$VESTA/data/ips/$ip" ]; then
|
if [ -n "$ip_check" ] || [ -e "$VESTA/data/ips/$ip" ]; then
|
||||||
echo "Error: IP exist"
|
echo "Error: IP exist"
|
||||||
log_event 'debug' "$E_EXISTS $EVENT"
|
log_event "$E_EXISTS" "$EVENT"
|
||||||
exit $E_EXISTS
|
exit $E_EXISTS
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_next_interface_number() {
|
# Get full interface name
|
||||||
# Parsing ifconfig
|
get_ip_iface() {
|
||||||
i=$(/sbin/ifconfig -a |grep -w "$interface"|cut -f1 -d ' '|\
|
i=$(/sbin/ifconfig -a |grep -w "$interface"|cut -f1 -d ' '|\
|
||||||
tail -n 1|cut -f 2 -d :)
|
tail -n 1|cut -f 2 -d :)
|
||||||
|
|
||||||
# Checking result
|
|
||||||
if [ "$i" = "$interface" ]; then
|
if [ "$i" = "$interface" ]; then
|
||||||
n=0
|
n=0
|
||||||
else
|
else
|
||||||
n=$((i + 1))
|
n=$((i + 1))
|
||||||
fi
|
fi
|
||||||
echo ":$n"
|
iface="$interface:$n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Check ip address speciefic value
|
||||||
is_ip_key_empty() {
|
is_ip_key_empty() {
|
||||||
key="$1"
|
key="$1"
|
||||||
|
string=$(cat $VESTA/data/ips/$ip)
|
||||||
# Parsing ip
|
eval $string
|
||||||
string=$(cat $VESTA/data/ips/$ip )
|
|
||||||
|
|
||||||
# Parsing key=value
|
|
||||||
for keys in $string; do
|
|
||||||
eval ${keys%%=*}=${keys#*=}
|
|
||||||
done
|
|
||||||
|
|
||||||
# Self reference
|
|
||||||
eval value="$key"
|
eval value="$key"
|
||||||
|
|
||||||
# Checkng key
|
|
||||||
if [ ! -z "$value" ] && [ "$value" != '0' ]; then
|
if [ ! -z "$value" ] && [ "$value" != '0' ]; then
|
||||||
echo "Error: value is not empty = $value "
|
echo "Error: $key is not empty = $value"
|
||||||
log_event 'debug' "$E_EXISTS $EVENT"
|
log_event "$E_EXISTS" "$EVENT"
|
||||||
exit $E_EXISTS
|
exit $E_EXISTS
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_sys_ip_value() {
|
# Update ip address value
|
||||||
|
update_ip_value() {
|
||||||
key="$1"
|
key="$1"
|
||||||
value="$2"
|
value="$2"
|
||||||
|
|
||||||
# Defining conf
|
|
||||||
conf="$VESTA/data/ips/$ip"
|
conf="$VESTA/data/ips/$ip"
|
||||||
|
|
||||||
# Parsing conf
|
|
||||||
str=$(cat $conf)
|
str=$(cat $conf)
|
||||||
|
eval $str
|
||||||
# Reading key=values
|
|
||||||
for keys in $str; do
|
|
||||||
eval ${keys%%=*}=${keys#*=}
|
|
||||||
done
|
|
||||||
|
|
||||||
# Define clean key
|
|
||||||
c_key=$(echo "${key//$/}")
|
c_key=$(echo "${key//$/}")
|
||||||
|
|
||||||
eval old="${key}"
|
eval old="${key}"
|
||||||
|
|
||||||
# Escaping slashes
|
|
||||||
old=$(echo "$old" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
|
old=$(echo "$old" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
|
||||||
new=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
|
new=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
|
||||||
|
|
||||||
# Updating conf
|
|
||||||
sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\
|
sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\
|
||||||
$conf
|
$conf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get ip name
|
||||||
|
|
||||||
get_ip_name() {
|
get_ip_name() {
|
||||||
# Prinitng name
|
|
||||||
grep "NAME=" $VESTA/data/ips/$ip |cut -f 2 -d \'
|
grep "NAME=" $VESTA/data/ips/$ip |cut -f 2 -d \'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Increase ip value
|
||||||
increase_ip_value() {
|
increase_ip_value() {
|
||||||
sip=${1-ip}
|
sip=${1-ip}
|
||||||
USER=$user
|
USER=$user
|
||||||
web_key='U_WEB_DOMAINS'
|
web_key='U_WEB_DOMAINS'
|
||||||
usr_key='U_SYS_USERS'
|
usr_key='U_SYS_USERS'
|
||||||
|
|
||||||
# Parsing values
|
|
||||||
current_web=$(grep "$web_key=" $VESTA/data/ips/$sip |cut -f 2 -d \')
|
current_web=$(grep "$web_key=" $VESTA/data/ips/$sip |cut -f 2 -d \')
|
||||||
current_usr=$(grep "$usr_key=" $VESTA/data/ips/$sip |cut -f 2 -d \')
|
current_usr=$(grep "$usr_key=" $VESTA/data/ips/$sip |cut -f 2 -d \')
|
||||||
|
|
||||||
# Checking result
|
|
||||||
if [ -z "$current_web" ]; then
|
if [ -z "$current_web" ]; then
|
||||||
echo "Error: Parsing error"
|
echo "Error: Parsing error"
|
||||||
log_event 'debug' "$E_PARSING $EVENT"
|
log_event "$E_PARSING" "$EVENT"
|
||||||
exit $E_PARSING
|
exit $E_PARSING
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# +1 webdomain
|
|
||||||
new_web=$((current_web + 1))
|
new_web=$((current_web + 1))
|
||||||
|
|
||||||
# +1 user
|
|
||||||
if [ -z "$current_usr" ]; then
|
if [ -z "$current_usr" ]; then
|
||||||
new_usr="$USER"
|
new_usr="$USER"
|
||||||
else
|
else
|
||||||
|
@ -154,34 +117,29 @@ increase_ip_value() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Changing config
|
|
||||||
sed -i "s/$web_key='$current_web'/$web_key='$new_web'/g" \
|
sed -i "s/$web_key='$current_web'/$web_key='$new_web'/g" \
|
||||||
$VESTA/data/ips/$ip
|
$VESTA/data/ips/$ip
|
||||||
sed -i "s/$usr_key='$current_usr'/$usr_key='$new_usr'/g" \
|
sed -i "s/$usr_key='$current_usr'/$usr_key='$new_usr'/g" \
|
||||||
$VESTA/data/ips/$ip
|
$VESTA/data/ips/$ip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Decrease ip value
|
||||||
decrease_ip_value() {
|
decrease_ip_value() {
|
||||||
sip=${1-ip}
|
sip=${1-ip}
|
||||||
USER=$user
|
USER=$user
|
||||||
web_key='U_WEB_DOMAINS'
|
web_key='U_WEB_DOMAINS'
|
||||||
usr_key='U_SYS_USERS'
|
usr_key='U_SYS_USERS'
|
||||||
|
|
||||||
# Parsing values
|
|
||||||
current_web=$(grep "$web_key=" $VESTA/data/ips/$sip |cut -f 2 -d \')
|
current_web=$(grep "$web_key=" $VESTA/data/ips/$sip |cut -f 2 -d \')
|
||||||
current_usr=$(grep "$usr_key=" $VESTA/data/ips/$sip |cut -f 2 -d \')
|
current_usr=$(grep "$usr_key=" $VESTA/data/ips/$sip |cut -f 2 -d \')
|
||||||
|
|
||||||
# Checking result
|
|
||||||
if [ -z "$current_web" ]; then
|
if [ -z "$current_web" ]; then
|
||||||
echo "Error: Parsing error"
|
echo "Error: Parsing error"
|
||||||
log_event 'debug' "$E_PARSING $EVENT"
|
log_event "$E_PARSING" "$EVENT"
|
||||||
exit $E_PARSING
|
exit $E_PARSING
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# -1 webdomain
|
|
||||||
new_web=$((current_web - 1))
|
new_web=$((current_web - 1))
|
||||||
|
|
||||||
# -1 user
|
|
||||||
check_ip=$(grep $sip $USER_DATA/web.conf |wc -l)
|
check_ip=$(grep $sip $USER_DATA/web.conf |wc -l)
|
||||||
if [ "$check_ip" -lt 2 ]; then
|
if [ "$check_ip" -lt 2 ]; then
|
||||||
new_usr=$(echo "$current_usr" |\
|
new_usr=$(echo "$current_usr" |\
|
||||||
|
@ -193,54 +151,39 @@ decrease_ip_value() {
|
||||||
new_usr="$current_usr"
|
new_usr="$current_usr"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Changing config
|
|
||||||
sed -i "s/$web_key='$current_web'/$web_key='$new_web'/g" \
|
sed -i "s/$web_key='$current_web'/$web_key='$new_web'/g" \
|
||||||
$VESTA/data/ips/$sip
|
$VESTA/data/ips/$sip
|
||||||
sed -i "s/$usr_key='$current_usr'/$usr_key='$new_usr'/g" \
|
sed -i "s/$usr_key='$current_usr'/$usr_key='$new_usr'/g" \
|
||||||
$VESTA/data/ips/$sip
|
$VESTA/data/ips/$sip
|
||||||
}
|
}
|
||||||
|
|
||||||
get_sys_ip_value() {
|
# Get ip address value
|
||||||
|
get_ip_value() {
|
||||||
key="$1"
|
key="$1"
|
||||||
|
|
||||||
# Parsing domains
|
|
||||||
string=$( cat $VESTA/data/ips/$ip )
|
string=$( cat $VESTA/data/ips/$ip )
|
||||||
|
eval $string
|
||||||
# Parsing key=value
|
|
||||||
for keys in $string; do
|
|
||||||
eval ${keys%%=*}=${keys#*=}
|
|
||||||
done
|
|
||||||
|
|
||||||
# Self reference
|
|
||||||
eval value="$key"
|
eval value="$key"
|
||||||
|
|
||||||
# Print value
|
|
||||||
echo "$value"
|
echo "$value"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get current ip interface
|
||||||
get_current_interface() {
|
get_current_interface() {
|
||||||
# Parsing ifconfig
|
|
||||||
i=$(/sbin/ifconfig |grep -B1 "addr:$ip "|head -n 1 |cut -f 1 -d ' ')
|
i=$(/sbin/ifconfig |grep -B1 "addr:$ip "|head -n 1 |cut -f 1 -d ' ')
|
||||||
|
|
||||||
# Checking result
|
|
||||||
if [ -z "$i" ]; then
|
if [ -z "$i" ]; then
|
||||||
echo "Error: IP not exist"
|
echo "Error: interface for ip $ip not found"
|
||||||
log_event 'debug' "$E_NOTEXIST $EVENT"
|
log_event "$E_NOTEXIST" "$EVENT"
|
||||||
exit $E_NOTEXIST
|
exit $E_NOTEXIST
|
||||||
fi
|
fi
|
||||||
|
if [ -z "$(echo $i | cut -s -f 2 -d :)" ]; then
|
||||||
# Checking ip is alias
|
|
||||||
check_alias=$(echo $i| cut -s -f 2 -d :)
|
|
||||||
if [ -z "$check_alias" ]; then
|
|
||||||
echo "Error: Main IP on interface"
|
echo "Error: Main IP on interface"
|
||||||
log_event 'debug' "$E_FORBIDEN $EVENT"
|
log_event "$E_FORBIDEN" "$EVENT"
|
||||||
exit $E_FORBIDEN
|
exit $E_FORBIDEN
|
||||||
fi
|
fi
|
||||||
echo "$i"
|
interface="$i"
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_add_vesta() {
|
# Create ip vesta configuration
|
||||||
# Filling ip values
|
create_vesta_ip() {
|
||||||
ip_data="OWNER='$user'"
|
ip_data="OWNER='$user'"
|
||||||
ip_data="$ip_data\nSTATUS='$ip_status'"
|
ip_data="$ip_data\nSTATUS='$ip_status'"
|
||||||
ip_data="$ip_data\nNAME='$ip_name'"
|
ip_data="$ip_data\nNAME='$ip_name'"
|
||||||
|
@ -249,29 +192,14 @@ ip_add_vesta() {
|
||||||
ip_data="$ip_data\nINTERFACE='$interface'"
|
ip_data="$ip_data\nINTERFACE='$interface'"
|
||||||
ip_data="$ip_data\nNETMASK='$mask'"
|
ip_data="$ip_data\nNETMASK='$mask'"
|
||||||
ip_data="$ip_data\nDATE='$DATE'"
|
ip_data="$ip_data\nDATE='$DATE'"
|
||||||
|
|
||||||
# Adding ip
|
|
||||||
echo -e "$ip_data" >$VESTA/data/ips/$ip
|
echo -e "$ip_data" >$VESTA/data/ips/$ip
|
||||||
chmod 660 $VESTA/data/ips/$ip
|
chmod 660 $VESTA/data/ips/$ip
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_add_startup() {
|
# Create ip address startup configuration
|
||||||
# Filling ip values
|
create_ip_startup() {
|
||||||
ip_data="# Added by vesta $SCRIPT"
|
ip_data="# Added by vesta $SCRIPT\nDEVICE=$iface"
|
||||||
ip_data="$ip_data\nDEVICE=$iface"
|
ip_data="$ip_data\nBOOTPROTO=static\nONBOOT=yes\nIPADDR=$ip"
|
||||||
ip_data="$ip_data\nBOOTPROTO=static\nONBOOT=yes"
|
|
||||||
ip_data="$ip_data\nIPADDR=$ip"
|
|
||||||
ip_data="$ip_data\nNETMASK=$mask"
|
ip_data="$ip_data\nNETMASK=$mask"
|
||||||
|
echo -e "$ip_data" > $iconf-$iface
|
||||||
# Adding ip
|
|
||||||
echo -e "$ip_data" >$iconf-$iface
|
|
||||||
}
|
|
||||||
|
|
||||||
ip_owner_search(){
|
|
||||||
for ip in $(ls $VESTA/data/ips/); do
|
|
||||||
check_owner=$(grep "OWNER='$user'" $VESTA/data/ips/$ip)
|
|
||||||
if [ ! -z "$check_owner" ]; then
|
|
||||||
echo "$ip"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue