diff --git a/bin/v_add_sys_ip b/bin/v_add_sys_ip index d46e04fb..d17d0316 100755 --- a/bin/v_add_sys_ip +++ b/bin/v_add_sys_ip @@ -22,34 +22,22 @@ user="${4-admin}" ip_status="${5-shared}" ip_name=$6 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/ip.sh -source $VESTA/func/domain.sh # for namehosting +source $VESTA/func/domain.sh + #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'ip mask [interface] [user] [ip_status] [ip_name]' - -# Checking argument format -validate_format 'ip' 'mask' 'interface' '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 +validate_format 'ip' 'mask' 'interface' 'user' 'ip_status' +is_ip_free +is_object_valid 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" if [ ! -z "$ip_name" ] ; then validate_format 'ip_name' fi @@ -59,9 +47,8 @@ fi # Action # #----------------------------------------------------------# -# Get interface number -i_number=$(get_next_interface_number) -iface="$interface$i_number" +# Get full interface name +get_ip_iface # Defining config paths conf='/etc/httpd/conf.d/vesta.conf' @@ -73,15 +60,12 @@ rconf='/etc/httpd/conf.d/rpaf.conf' /sbin/ifconfig "$iface" "$ip" netmask "$mask" # Adding startup script -ip_add_startup +create_ip_startup # Adding vesta ip -ip_add_vesta +create_vesta_ip -# Importing main config -source $VESTA/conf/vesta.conf - -# Adding namehosting support +# Namehosting support namehost_ip_support @@ -93,7 +77,7 @@ namehost_ip_support increase_user_value "$user" '$IP_OWNED' if [ "$user" = 'admin' ]; 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' done else @@ -104,7 +88,7 @@ else increase_user_value 'admin' '$IP_AVAIL' fi -# Adding task to the vesta pipe +# Restart web server if [ "$web_restart" = 'yes' ]; then $BIN/v_restart_web "$EVENT" fi diff --git a/bin/v_add_web_domain_ssl b/bin/v_add_web_domain_ssl index d3eb91df..d386b4db 100755 --- a/bin/v_add_web_domain_ssl +++ b/bin/v_add_web_domain_ssl @@ -40,7 +40,7 @@ is_object_unsuspended 'user' 'USER' "$user" is_object_valid 'web' 'DOMAIN' "$domain" is_object_unsuspended 'web' 'DOMAIN' "$domain" is_object_value_empty 'web' 'DOMAIN' "$domain" '$SSL' -is_sys_ip_owner +is_ip_owner is_web_domain_cert_valid diff --git a/bin/v_change_sys_config_value b/bin/v_change_sys_config_value index a7e91440..fbad6db4 100755 --- a/bin/v_change_sys_config_value +++ b/bin/v_change_sys_config_value @@ -14,7 +14,7 @@ key=$(echo "$1" | tr '[:lower:]' '[:upper:]' ) value=$2 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh @@ -23,17 +23,12 @@ source $VESTA/func/shared.sh # Verifications # #----------------------------------------------------------# -# Checking args check_args '2' "$#" 'key value' - -# Checking argument format validate_format 'key' - -# Checking key existance check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf) if [ -z "$check_ckey" ]; then - echo "Error: key not found" - log_event 'debug' "$E_INVALID $EVENT" + echo "Error: key $key not found" + log_event "$E_INVALID" "$EVENT" exit $E_INVALID fi diff --git a/bin/v_change_sys_ip_name b/bin/v_change_sys_ip_name index ccee08e1..7fd72895 100755 --- a/bin/v_change_sys_ip_name +++ b/bin/v_change_sys_ip_name @@ -13,7 +13,7 @@ ip=$1 ip_name=$2 -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/ip.sh @@ -23,14 +23,9 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'ip ip_name' - -# Checking argument format validate_format 'ip' 'ip_name' - -# Checking system ip -is_sys_ip_valid +is_ip_valid #----------------------------------------------------------# @@ -38,7 +33,7 @@ is_sys_ip_valid #----------------------------------------------------------# # Changing ip name -update_sys_ip_value '$NAME' "$ip_name" +update_ip_value '$NAME' "$ip_name" #----------------------------------------------------------# diff --git a/bin/v_change_sys_ip_owner b/bin/v_change_sys_ip_owner index f8eb6269..c23728f2 100755 --- a/bin/v_change_sys_ip_owner +++ b/bin/v_change_sys_ip_owner @@ -14,7 +14,6 @@ ip=$1 user=$2 # Importing variables -source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh source $VESTA/func/ip.sh @@ -23,25 +22,12 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'ip user' - -# Checking argument format validate_format 'ip' 'user' - -# Checking user is_object_valid 'user' 'USER' "$user" - -# Checking user is active is_object_unsuspended 'user' 'USER' "$user" - -# Checking system ip -is_sys_ip_valid - -# Checking webdomains on ip +is_ip_valid is_ip_key_empty '$U_WEB_DOMAINS' - -# Checking users on ip is_ip_key_empty '$U_SYS_USERS' @@ -50,14 +36,14 @@ is_ip_key_empty '$U_SYS_USERS' #----------------------------------------------------------# # Changing ip owner -ip_owner=$(get_sys_ip_value '$OWNER') +ip_owner=$(get_ip_value '$OWNER') if [ "$ip_owner" != "$user" ]; then - ip_status="$(get_sys_ip_value '$STATUS')" - update_sys_ip_value '$OWNER' "$user" + ip_status="$(get_ip_value '$STATUS')" + update_ip_value '$OWNER' "$user" decrease_user_value "$ip_owner" '$IP_OWNED' if [ "$ip_owner" = 'admin' ]; 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' done else @@ -71,7 +57,7 @@ if [ "$ip_owner" != "$user" ]; then increase_user_value "$user" '$IP_OWNED' if [ "$user" = 'admin' ]; 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' done else diff --git a/bin/v_change_sys_ip_status b/bin/v_change_sys_ip_status index d15a4fa6..7af485a9 100755 --- a/bin/v_change_sys_ip_status +++ b/bin/v_change_sys_ip_status @@ -13,8 +13,7 @@ ip=$1 ip_status=$2 -# Importing variables -source $VESTA/conf/vesta.conf +# Includes source $VESTA/func/shared.sh source $VESTA/func/ip.sh @@ -23,32 +22,21 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '2' "$#" 'ip ip_status' - -# Checking argument format validate_format 'ip' 'ip_status' - -# Checking system ip -is_sys_ip_valid - -# 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" +is_ip_valid +if [ "$ip_status" = "$(get_ip_value '$STATUS')" ]; then + echo "Error: status $ip_status is already set" + log_event "$E_EXISTS" "$EVENT" exit $E_EXISTS fi -# Parsing current ip usage -web_domains=$(get_sys_ip_value '$U_WEB_DOMAINS') -sys_user=$(get_sys_ip_value '$U_SYS_USERS') -ip_owner=$(get_sys_ip_value '$OWNER') - -# Checking condition +web_domains=$(get_ip_value '$U_WEB_DOMAINS') +sys_user=$(get_ip_value '$U_SYS_USERS') +ip_owner=$(get_ip_value '$OWNER') if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then - echo "Error: ip is used" - log_event 'debug' "$E_INUSE $EVENT" + echo "Error: ip $ip is used" + log_event "$E_INUSE" "$EVENT" exit $E_INUSE fi @@ -58,7 +46,7 @@ fi #----------------------------------------------------------# # Changing ip name -update_sys_ip_value '$STATUS' "$ip_status" +update_ip_value '$STATUS' "$ip_status" #----------------------------------------------------------# diff --git a/bin/v_delete_sys_ip b/bin/v_delete_sys_ip index 243b6889..b8df35f6 100755 --- a/bin/v_delete_sys_ip +++ b/bin/v_delete_sys_ip @@ -24,24 +24,12 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '1' "$#" 'ip' - -# Checking argument format validate_format 'ip' - -# Checking system ip -is_sys_ip_valid "$ip" - -# Checking webdomains on ip +is_ip_valid "$ip" is_ip_key_empty '$U_WEB_DOMAINS' - -# Checking users on ip is_ip_key_empty '$U_SYS_USERS' -# Checking interface -interface=$(get_current_interface) - #----------------------------------------------------------# # Action # @@ -54,10 +42,11 @@ iconf='/etc/sysconfig/network-scripts/ifcfg' rconf='/etc/httpd/conf.d/rpaf.conf' # Get ip owner -user="$(get_sys_ip_value '$OWNER')" -ip_status="$(get_sys_ip_value '$STATUS')" +user="$(get_ip_value '$OWNER')" +ip_status="$(get_ip_value '$STATUS')" # Deleting interface +get_current_interface /sbin/ifconfig "$interface" down # Deleting startup script @@ -66,9 +55,6 @@ rm -f $iconf-$interface # Deleting vesta ip rm -f $VESTA/data/ips/$ip -# Importing main config -source $VESTA/conf/vesta.conf - # Deleting namehosting support namehost_ip_disable @@ -84,7 +70,7 @@ fi if [ "$user" = 'admin' ]; 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' done else diff --git a/bin/v_list_sys_interfaces b/bin/v_list_sys_interfaces index c2ec908e..84e11d37 100755 --- a/bin/v_list_sys_interfaces +++ b/bin/v_list_sys_interfaces @@ -12,7 +12,7 @@ # Argument defenition format=${1-shell} -# Importing variables +# Includes source $VESTA/func/shared.sh # Json function @@ -21,8 +21,6 @@ json_list_iface() { int_counter=$(echo "$interfaces" | wc -l) i=1 echo '[' - - # Listing ifaces for interface in $interfaces; do if [ "$i" -lt "$int_counter" ]; then echo -e "\t\"$interface\"," @@ -41,7 +39,6 @@ shell_list_iface() { echo "INTERFACES" echo "----------" fi - for interface in $interfaces; do echo "$interface" done diff --git a/bin/v_list_sys_ip b/bin/v_list_sys_ip index e9c27404..0a20a188 100755 --- a/bin/v_list_sys_ip +++ b/bin/v_list_sys_ip @@ -14,7 +14,7 @@ ip=$1 IP=$ip format=${2-shell} -# Importing variables +# Includes source $VESTA/func/shared.sh source $VESTA/func/ip.sh @@ -23,17 +23,10 @@ json_list_ip() { i=1 fileds_count=$(echo "$fields" | wc -w) ip_data=$(cat $VESTA/data/ips/$IP) - - # Print top bracket echo '{' - - # Assign key=value eval $ip_data - for field in $fields; do eval value=$field - - # Checking first field if [ $i -eq 1 ]; then echo -e "\t\"$value\": {" else @@ -45,26 +38,21 @@ json_list_ip() { fi (( ++i)) done - - # If there was any output if [ -n "$value" ]; then echo -e ' }' fi - - # Printing bottom json bracket echo -e '}' } # Shell function shell_list_ip() { line=$(cat $VESTA/data/ips/$IP) - - # Assing key=value eval $line - - # Print result line for field in $fields; do eval key="$field" + if [ -z "$key" ]; then + key='NULL' + fi echo "${field//$/}: $key " done } @@ -76,12 +64,8 @@ shell_list_ip() { # Checking args check_args '1' "$#" 'ip [format]' - -# Checking argument format validate_format 'ip' - -# Checking ip -is_sys_ip_valid +is_ip_valid #----------------------------------------------------------# # Action # @@ -89,8 +73,8 @@ is_sys_ip_valid conf=$VESTA/data/ips/$IP # Defining fileds to select -fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS - $INTERFACE $NETMASK $DATE' +fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE + $NETMASK $DATE' # Listing ip case $format in diff --git a/bin/v_list_sys_ips b/bin/v_list_sys_ips index 2d78b8d1..57c14061 100755 --- a/bin/v_list_sys_ips +++ b/bin/v_list_sys_ips @@ -12,39 +12,27 @@ # Argument defenition format=${1-shell} -# Importing variables +# Includes source $VESTA/func/shared.sh # Json function json_list_ips() { - # Print top bracket echo '{' - - # Definining ip list ip_list=$(ls $VESTA/data/ips/) - fileds_count=$(echo "$fields" | wc -w) - - # Starting main loop for IP in $ip_list; do - # Assing key=value ip_data=$(cat $VESTA/data/ips/$IP) eval $ip_data - - # Closing bracket if there already was output if [ -n "$data" ]; then echo -e ' },' fi i=1 for field in $fields; do eval value=$field - if [ $i -eq 1 ]; then - # Printing parrent (( ++i)) echo -e "\t\"$value\": {" else - # Printing child if [ $i -lt $fileds_count ]; then (( ++i)) echo -e "\t\t\"${field//$/}\": \"${value//,/, }\"," @@ -55,22 +43,16 @@ json_list_ips() { fi done done - - # Closing bracket if there was output if [ -n "$data" ]; then echo -e ' }' fi - - # Printing bottom bracket echo -e '}' } # Shell function shell_list_ips() { ip_list=$(ls $VESTA/data/ips/) - if [ -z "$nohead" ]; then - # Print brief info echo "${fields//$/}" for a in $fields; do echo -e "--------- \c" @@ -78,15 +60,9 @@ shell_list_ips() { echo fi - # Starting main loop for IP in $ip_list; do - # Reading user data ip_data=$(cat $VESTA/data/ips/$IP) - - # Assign key/value config eval $ip_data - - # Print result line eval echo "$fields" done } @@ -95,9 +71,9 @@ shell_list_ips() { #----------------------------------------------------------# # Action # #----------------------------------------------------------# -conf=$VESTA/data/ips/* # Defining fileds to select +conf=$VESTA/data/ips/* fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS" fields="$fields \$INTERFACE \$NETMASK \$DATE" diff --git a/bin/v_list_sys_rrd b/bin/v_list_sys_rrd index 91486141..0e80b2f2 100755 --- a/bin/v_list_sys_rrd +++ b/bin/v_list_sys_rrd @@ -22,32 +22,25 @@ json_list_rrd() { if [ "$i" -ne 1 ]; then echo -e "\t}," fi - - # Define title if [ "$type" = 'la' ]; then title="Load Average" fi - if [ "$type" = 'mem' ]; then title="Memory Usage" fi - if [ "$type" = 'net' ]; then title="Bandwidth Usage $rrd" fi - if [ "$type" = 'web' ] || [ "$type" = 'ftp' ] ||\ [ "$type" = 'ssh' ]; then title="$(echo $rrd| tr '[:lower:]' '[:upper:]') Usage" fi - if [ "$type" = 'db' ]; then db_type=$(echo $rrd|cut -f 1 -d _ |sed -e 's/mysql/MySQL/g' \ -e 's/pgsql/PostgreSQL/g' ) db_host=$(echo $rrd|cut -f 2 -d _ ) title="$db_type Usage on $db_host" fi - echo -e "\t\"$i\": {" echo -e "\t\t\"TYPE\": \"$type\"", echo -e "\t\t\"RRD\": \"$rrd\"", @@ -55,7 +48,6 @@ json_list_rrd() { (( ++i)) done done - if [ "$i" -gt 1 ]; then echo -e "\t}" fi @@ -65,11 +57,9 @@ json_list_rrd() { # Define jshell function shell_list_rrd() { if [ -z "$nohead" ]; then - # Print brief info echo "PATH" echo "---------" fi - for type in $rrd_types; do for rrd in $(ls $RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do echo "$RRD/$type/$rrd.rrd" @@ -101,6 +91,7 @@ fi if [ -n "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then rrd_types="$rrd_types ftp" fi + rrd_types="$rrd_types ssh" diff --git a/bin/v_update_sys_ip b/bin/v_update_sys_ip index 397069bd..81958e50 100755 --- a/bin/v_update_sys_ip +++ b/bin/v_update_sys_ip @@ -15,7 +15,7 @@ user=${1-admin} ip_status=${2-shared} -# Importing variables +# Includes source $VESTA/conf/vesta.conf # include for internal func source $VESTA/func/shared.sh source $VESTA/func/ip.sh @@ -26,19 +26,9 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '0' "$#" '[user] [ip_status]' - -# Checking 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 +validate_format 'user' 'ip_status' +is_object_valid 'user' 'USER' "$user" "$user" #----------------------------------------------------------# @@ -46,7 +36,7 @@ fi #----------------------------------------------------------# # 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) # Get vesta registered ip list @@ -60,15 +50,14 @@ rconf='/etc/httpd/conf.d/rpaf.conf' # Comparing each ip 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 if [ -z "$check_ip" ]; then - # 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 :) - 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 ip_add_vesta @@ -82,7 +71,7 @@ for ip in $ip_list; do fi fi - # NOTE: later we'll make revers comparation + # TBD: revers comparation done @@ -93,7 +82,7 @@ done # Updating user conf increase_user_value "$user" '$IP_OWNED' -# Adding task to the vesta pipe +# Restart web server if [ "$web_restart" = 'yes' ]; then $BIN/v_restart_web "$EVENT" fi diff --git a/bin/v_update_sys_queue b/bin/v_update_sys_queue index addebcd2..9b877ee3 100755 --- a/bin/v_update_sys_queue +++ b/bin/v_update_sys_queue @@ -19,43 +19,18 @@ queue=$1 # mostly by cron wich not read it by itself source /etc/profile.d/vesta.sh -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh # Export PATH for cron PATH=$PATH:$BIN - -# 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 -} - - +export $PATH #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# -# Checking arg number check_args '1' "$#" 'queue' @@ -63,12 +38,15 @@ check_args '1' "$#" 'queue' # Action # #----------------------------------------------------------# +# Defining pipe functions case $queue in - restart) restart_pipe ;; - stats) stats_pipe ;; - backup) backup_pipe ;; - disk) disk_pipe ;; - traffic) traff_pipe ;; + restart) bash $VESTA/data/queue/restart.pipe; + rm $VESTA/data/queue/restart.pipe; + touch $VESTA/data/queue/restart.pipe;; + stats) bash $VESTA/data/queue/stats.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' esac diff --git a/bin/v_update_sys_rrd b/bin/v_update_sys_rrd index ddf26ea0..0a63b255 100755 --- a/bin/v_update_sys_rrd +++ b/bin/v_update_sys_rrd @@ -11,11 +11,10 @@ #----------------------------------------------------------# # 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 - -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh diff --git a/bin/v_update_sys_rrd_ftp b/bin/v_update_sys_rrd_ftp index 5efe5178..5d7b0e54 100755 --- a/bin/v_update_sys_rrd_ftp +++ b/bin/v_update_sys_rrd_ftp @@ -13,8 +13,9 @@ update=$1 period=${1-daily} -# Importing variables +# Includes source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh #----------------------------------------------------------# diff --git a/bin/v_update_sys_rrd_httpd b/bin/v_update_sys_rrd_httpd index e64b4d5c..dfa8e649 100755 --- a/bin/v_update_sys_rrd_httpd +++ b/bin/v_update_sys_rrd_httpd @@ -13,7 +13,9 @@ update=$1 period=${1-daily} -# Importing variables +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh #----------------------------------------------------------# diff --git a/bin/v_update_sys_rrd_la b/bin/v_update_sys_rrd_la index 68760473..187003b9 100755 --- a/bin/v_update_sys_rrd_la +++ b/bin/v_update_sys_rrd_la @@ -13,7 +13,9 @@ update=$1 period=${1-daily} -# Importing variables +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh #----------------------------------------------------------# diff --git a/bin/v_update_sys_rrd_mem b/bin/v_update_sys_rrd_mem index 4c901938..5c6cfd02 100755 --- a/bin/v_update_sys_rrd_mem +++ b/bin/v_update_sys_rrd_mem @@ -13,7 +13,9 @@ update=$1 period=${1-daily} -# Importing variables +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh #----------------------------------------------------------# diff --git a/bin/v_update_sys_rrd_mysql b/bin/v_update_sys_rrd_mysql index b5d269f9..025bea99 100755 --- a/bin/v_update_sys_rrd_mysql +++ b/bin/v_update_sys_rrd_mysql @@ -13,7 +13,8 @@ update=$1 period=${1-daily} -# Importing variables +# Includes +source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh @@ -79,7 +80,7 @@ for host in $hosts; do if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $PORT ] then echo "Error: config is broken" - log_event 'debug' "$E_PARSING $EVENT" + log_event "$E_PARSING" "$EVENT" exit $E_PARSING fi diff --git a/bin/v_update_sys_rrd_net b/bin/v_update_sys_rrd_net index 35b6d688..ba1e0c5c 100755 --- a/bin/v_update_sys_rrd_net +++ b/bin/v_update_sys_rrd_net @@ -13,7 +13,9 @@ update=$1 period=${1-daily} -# Importing variables +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh #----------------------------------------------------------# diff --git a/bin/v_update_sys_rrd_nginx b/bin/v_update_sys_rrd_nginx index a75d6f23..33ac7a3c 100755 --- a/bin/v_update_sys_rrd_nginx +++ b/bin/v_update_sys_rrd_nginx @@ -13,7 +13,9 @@ update=$1 period=${1-daily} -# Importing variables +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh #----------------------------------------------------------# diff --git a/bin/v_update_sys_rrd_pgsql b/bin/v_update_sys_rrd_pgsql index 0da1f6d9..cfd54b32 100755 --- a/bin/v_update_sys_rrd_pgsql +++ b/bin/v_update_sys_rrd_pgsql @@ -13,7 +13,8 @@ update=$1 period=${1-daily} -# Importing variables +# Includes +source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh @@ -81,11 +82,10 @@ for host in $hosts; do if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ] then echo "Error: config is broken" - log_event 'debug' "$E_PARSING $EVENT" + log_event "$E_PARSING" "$EVENT" exit $E_PARSING fi - # Parsing data q='SELECT SUM(xact_commit + xact_rollback), SUM(numbackends) FROM pg_stat_database;' diff --git a/bin/v_update_sys_rrd_ssh b/bin/v_update_sys_rrd_ssh index b99d431a..6e822fba 100755 --- a/bin/v_update_sys_rrd_ssh +++ b/bin/v_update_sys_rrd_ssh @@ -13,7 +13,9 @@ update=$1 period=${1-daily} -# Importing variables +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/shared.sh #----------------------------------------------------------# diff --git a/bin/v_update_sys_vesta b/bin/v_update_sys_vesta index 90d1626e..4f3caf7f 100755 --- a/bin/v_update_sys_vesta +++ b/bin/v_update_sys_vesta @@ -17,7 +17,7 @@ updates='' # Importing system enviroment source /etc/profile.d/vesta.sh -# Importing variables +# Includes source $VESTA/conf/vesta.conf source $VESTA/func/shared.sh diff --git a/func/ip.sh b/func/ip.sh index d70fad68..fc8c8d21 100644 --- a/func/ip.sh +++ b/func/ip.sh @@ -25,7 +25,7 @@ is_ip_avalable() { } # Check ip ownership -is_sys_ip_owner() { +is_ip_owner() { # Parsing ip owner=$(grep 'OWNER=' $VESTA/data/ips/$IP|cut -f 2 -d \') if [ "$owner" != "$user" ]; then @@ -35,114 +35,77 @@ is_sys_ip_owner() { fi } - -is_sys_ip_free() { - # Parsing system ips - ip_list=$(/sbin/ifconfig|grep 'inet addr:'|cut -f 2 -d ':'|cut -f 1 -d " ") - - # Checking ip existance - ip_check=$(echo "$ip_list"|grep -w "$ip") +# Check if ip address is free +is_ip_free() { + list=$(/sbin/ifconfig |grep 'inet addr:' |cut -f 2 -d : |cut -f 1 -d ' ') + ip_check=$(echo "$list" |grep -w "$ip") if [ -n "$ip_check" ] || [ -e "$VESTA/data/ips/$ip" ]; then echo "Error: IP exist" - log_event 'debug' "$E_EXISTS $EVENT" + log_event "$E_EXISTS" "$EVENT" exit $E_EXISTS fi } -get_next_interface_number() { - # Parsing ifconfig +# Get full interface name +get_ip_iface() { i=$(/sbin/ifconfig -a |grep -w "$interface"|cut -f1 -d ' '|\ tail -n 1|cut -f 2 -d :) - - # Checking result if [ "$i" = "$interface" ]; then n=0 else n=$((i + 1)) fi - echo ":$n" + iface="$interface:$n" } +# Check ip address speciefic value is_ip_key_empty() { key="$1" - - # Parsing ip - string=$(cat $VESTA/data/ips/$ip ) - - # Parsing key=value - for keys in $string; do - eval ${keys%%=*}=${keys#*=} - done - - # Self reference + string=$(cat $VESTA/data/ips/$ip) + eval $string eval value="$key" - - # Checkng key if [ ! -z "$value" ] && [ "$value" != '0' ]; then - echo "Error: value is not empty = $value " - log_event 'debug' "$E_EXISTS $EVENT" + echo "Error: $key is not empty = $value" + log_event "$E_EXISTS" "$EVENT" exit $E_EXISTS fi } -update_sys_ip_value() { +# Update ip address value +update_ip_value() { key="$1" value="$2" - - # Defining conf conf="$VESTA/data/ips/$ip" - - # Parsing conf str=$(cat $conf) - - # Reading key=values - for keys in $str; do - eval ${keys%%=*}=${keys#*=} - done - - # Define clean key + eval $str c_key=$(echo "${key//$/}") - eval old="${key}" - - # Escaping slashes 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') - - # Updating conf sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\ - $conf + $conf } - - +# Get ip name get_ip_name() { - # Prinitng name grep "NAME=" $VESTA/data/ips/$ip |cut -f 2 -d \' } +# Increase ip value increase_ip_value() { sip=${1-ip} USER=$user web_key='U_WEB_DOMAINS' usr_key='U_SYS_USERS' - - # Parsing values 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 \') - - # Checking result if [ -z "$current_web" ]; then echo "Error: Parsing error" - log_event 'debug' "$E_PARSING $EVENT" + log_event "$E_PARSING" "$EVENT" exit $E_PARSING fi - - # +1 webdomain new_web=$((current_web + 1)) - - # +1 user if [ -z "$current_usr" ]; then new_usr="$USER" else @@ -154,34 +117,29 @@ increase_ip_value() { fi fi - # Changing config sed -i "s/$web_key='$current_web'/$web_key='$new_web'/g" \ $VESTA/data/ips/$ip sed -i "s/$usr_key='$current_usr'/$usr_key='$new_usr'/g" \ $VESTA/data/ips/$ip } +# Decrease ip value decrease_ip_value() { sip=${1-ip} USER=$user web_key='U_WEB_DOMAINS' usr_key='U_SYS_USERS' - # Parsing values 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 \') - # Checking result if [ -z "$current_web" ]; then echo "Error: Parsing error" - log_event 'debug' "$E_PARSING $EVENT" + log_event "$E_PARSING" "$EVENT" exit $E_PARSING fi - # -1 webdomain new_web=$((current_web - 1)) - - # -1 user check_ip=$(grep $sip $USER_DATA/web.conf |wc -l) if [ "$check_ip" -lt 2 ]; then new_usr=$(echo "$current_usr" |\ @@ -193,54 +151,39 @@ decrease_ip_value() { new_usr="$current_usr" fi - # Changing config sed -i "s/$web_key='$current_web'/$web_key='$new_web'/g" \ $VESTA/data/ips/$sip sed -i "s/$usr_key='$current_usr'/$usr_key='$new_usr'/g" \ $VESTA/data/ips/$sip } -get_sys_ip_value() { +# Get ip address value +get_ip_value() { key="$1" - - # Parsing domains string=$( cat $VESTA/data/ips/$ip ) - - # Parsing key=value - for keys in $string; do - eval ${keys%%=*}=${keys#*=} - done - - # Self reference + eval $string eval value="$key" - - # Print value echo "$value" } +# Get current ip interface get_current_interface() { - # Parsing ifconfig i=$(/sbin/ifconfig |grep -B1 "addr:$ip "|head -n 1 |cut -f 1 -d ' ') - - # Checking result if [ -z "$i" ]; then - echo "Error: IP not exist" - log_event 'debug' "$E_NOTEXIST $EVENT" + echo "Error: interface for ip $ip not found" + log_event "$E_NOTEXIST" "$EVENT" exit $E_NOTEXIST fi - - # Checking ip is alias - check_alias=$(echo $i| cut -s -f 2 -d :) - if [ -z "$check_alias" ]; then + if [ -z "$(echo $i | cut -s -f 2 -d :)" ]; then echo "Error: Main IP on interface" - log_event 'debug' "$E_FORBIDEN $EVENT" + log_event "$E_FORBIDEN" "$EVENT" exit $E_FORBIDEN fi - echo "$i" + interface="$i" } -ip_add_vesta() { - # Filling ip values +# Create ip vesta configuration +create_vesta_ip() { ip_data="OWNER='$user'" ip_data="$ip_data\nSTATUS='$ip_status'" ip_data="$ip_data\nNAME='$ip_name'" @@ -249,29 +192,14 @@ ip_add_vesta() { ip_data="$ip_data\nINTERFACE='$interface'" ip_data="$ip_data\nNETMASK='$mask'" ip_data="$ip_data\nDATE='$DATE'" - - # Adding ip echo -e "$ip_data" >$VESTA/data/ips/$ip chmod 660 $VESTA/data/ips/$ip } -ip_add_startup() { - # Filling ip values - ip_data="# Added by vesta $SCRIPT" - ip_data="$ip_data\nDEVICE=$iface" - ip_data="$ip_data\nBOOTPROTO=static\nONBOOT=yes" - ip_data="$ip_data\nIPADDR=$ip" +# Create ip address startup configuration +create_ip_startup() { + ip_data="# Added by vesta $SCRIPT\nDEVICE=$iface" + ip_data="$ip_data\nBOOTPROTO=static\nONBOOT=yes\nIPADDR=$ip" ip_data="$ip_data\nNETMASK=$mask" - - # 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 + echo -e "$ip_data" > $iconf-$iface }