Skip to content

Commit 3ba10cd

Browse files
committed
Refactoring stage IV (sys)
1 parent 3dcc180 commit 3ba10cd

25 files changed

+141
-351
lines changed

bin/v_add_sys_ip

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,22 @@ user="${4-admin}"
2222
ip_status="${5-shared}"
2323
ip_name=$6
2424

25-
# Importing variables
25+
# Includes
2626
source $VESTA/conf/vesta.conf
2727
source $VESTA/func/shared.sh
2828
source $VESTA/func/ip.sh
29-
source $VESTA/func/domain.sh # for namehosting
29+
source $VESTA/func/domain.sh
30+
3031

3132
#----------------------------------------------------------#
3233
# Verifications #
3334
#----------------------------------------------------------#
3435

35-
# Checking arg number
3636
check_args '2' "$#" 'ip mask [interface] [user] [ip_status] [ip_name]'
37-
38-
# Checking argument format
39-
validate_format 'ip' 'mask' 'interface' 'user'
40-
41-
# Checking system ip
42-
is_sys_ip_free
43-
44-
# Checking user
45-
is_object_valid 'user' 'USER' "$user" "$user"
46-
47-
# Checking ip_status
48-
if [ ! -z "$ip_status" ]; then
49-
validate_format 'ip_status'
50-
fi
51-
52-
# Checking ip_name
37+
validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
38+
is_ip_free
39+
is_object_valid 'user' 'USER' "$user"
40+
is_object_unsuspended 'user' 'USER' "$user"
5341
if [ ! -z "$ip_name" ] ; then
5442
validate_format 'ip_name'
5543
fi
@@ -59,9 +47,8 @@ fi
5947
# Action #
6048
#----------------------------------------------------------#
6149

62-
# Get interface number
63-
i_number=$(get_next_interface_number)
64-
iface="$interface$i_number"
50+
# Get full interface name
51+
get_ip_iface
6552

6653
# Defining config paths
6754
conf='/etc/httpd/conf.d/vesta.conf'
@@ -73,15 +60,12 @@ rconf='/etc/httpd/conf.d/rpaf.conf'
7360
/sbin/ifconfig "$iface" "$ip" netmask "$mask"
7461

7562
# Adding startup script
76-
ip_add_startup
63+
create_ip_startup
7764

7865
# Adding vesta ip
79-
ip_add_vesta
80-
81-
# Importing main config
82-
source $VESTA/conf/vesta.conf
66+
create_vesta_ip
8367

84-
# Adding namehosting support
68+
# Namehosting support
8569
namehost_ip_support
8670

8771

@@ -93,7 +77,7 @@ namehost_ip_support
9377
increase_user_value "$user" '$IP_OWNED'
9478
if [ "$user" = 'admin' ]; then
9579
if [ "$ip_status" = 'shared' ]; then
96-
for user in $(ls $V_USERS/); do
80+
for user in $(ls $VESTA/data/users); do
9781
increase_user_value "$user" '$IP_AVAIL'
9882
done
9983
else
@@ -104,7 +88,7 @@ else
10488
increase_user_value 'admin' '$IP_AVAIL'
10589
fi
10690

107-
# Adding task to the vesta pipe
91+
# Restart web server
10892
if [ "$web_restart" = 'yes' ]; then
10993
$BIN/v_restart_web "$EVENT"
11094
fi

bin/v_add_web_domain_ssl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ is_object_unsuspended 'user' 'USER' "$user"
4040
is_object_valid 'web' 'DOMAIN' "$domain"
4141
is_object_unsuspended 'web' 'DOMAIN' "$domain"
4242
is_object_value_empty 'web' 'DOMAIN' "$domain" '$SSL'
43-
is_sys_ip_owner
43+
is_ip_owner
4444
is_web_domain_cert_valid
4545

4646

bin/v_change_sys_config_value

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
key=$(echo "$1" | tr '[:lower:]' '[:upper:]' )
1515
value=$2
1616

17-
# Importing variables
17+
# Includes
1818
source $VESTA/conf/vesta.conf
1919
source $VESTA/func/shared.sh
2020

@@ -23,17 +23,12 @@ source $VESTA/func/shared.sh
2323
# Verifications #
2424
#----------------------------------------------------------#
2525

26-
# Checking args
2726
check_args '2' "$#" 'key value'
28-
29-
# Checking argument format
3027
validate_format 'key'
31-
32-
# Checking key existance
3328
check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf)
3429
if [ -z "$check_ckey" ]; then
35-
echo "Error: key not found"
36-
log_event 'debug' "$E_INVALID $EVENT"
30+
echo "Error: key $key not found"
31+
log_event "$E_INVALID" "$EVENT"
3732
exit $E_INVALID
3833
fi
3934

bin/v_change_sys_ip_name

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ip=$1
1414
ip_name=$2
1515

16-
# Importing variables
16+
# Includes
1717
source $VESTA/conf/vesta.conf
1818
source $VESTA/func/shared.sh
1919
source $VESTA/func/ip.sh
@@ -23,22 +23,17 @@ source $VESTA/func/ip.sh
2323
# Verifications #
2424
#----------------------------------------------------------#
2525

26-
# Checking arg number
2726
check_args '2' "$#" 'ip ip_name'
28-
29-
# Checking argument format
3027
validate_format 'ip' 'ip_name'
31-
32-
# Checking system ip
33-
is_sys_ip_valid
28+
is_ip_valid
3429

3530

3631
#----------------------------------------------------------#
3732
# Action #
3833
#----------------------------------------------------------#
3934

4035
# Changing ip name
41-
update_sys_ip_value '$NAME' "$ip_name"
36+
update_ip_value '$NAME' "$ip_name"
4237

4338

4439
#----------------------------------------------------------#

bin/v_change_sys_ip_owner

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ ip=$1
1414
user=$2
1515

1616
# Importing variables
17-
source $VESTA/conf/vesta.conf
1817
source $VESTA/func/shared.sh
1918
source $VESTA/func/ip.sh
2019

@@ -23,25 +22,12 @@ source $VESTA/func/ip.sh
2322
# Verifications #
2423
#----------------------------------------------------------#
2524

26-
# Checking arg number
2725
check_args '2' "$#" 'ip user'
28-
29-
# Checking argument format
3026
validate_format 'ip' 'user'
31-
32-
# Checking user
3327
is_object_valid 'user' 'USER' "$user"
34-
35-
# Checking user is active
3628
is_object_unsuspended 'user' 'USER' "$user"
37-
38-
# Checking system ip
39-
is_sys_ip_valid
40-
41-
# Checking webdomains on ip
29+
is_ip_valid
4230
is_ip_key_empty '$U_WEB_DOMAINS'
43-
44-
# Checking users on ip
4531
is_ip_key_empty '$U_SYS_USERS'
4632

4733

@@ -50,14 +36,14 @@ is_ip_key_empty '$U_SYS_USERS'
5036
#----------------------------------------------------------#
5137

5238
# Changing ip owner
53-
ip_owner=$(get_sys_ip_value '$OWNER')
39+
ip_owner=$(get_ip_value '$OWNER')
5440
if [ "$ip_owner" != "$user" ]; then
55-
ip_status="$(get_sys_ip_value '$STATUS')"
56-
update_sys_ip_value '$OWNER' "$user"
41+
ip_status="$(get_ip_value '$STATUS')"
42+
update_ip_value '$OWNER' "$user"
5743
decrease_user_value "$ip_owner" '$IP_OWNED'
5844
if [ "$ip_owner" = 'admin' ]; then
5945
if [ "$ip_status" = 'shared' ]; then
60-
for vesta_user in $(ls $V_USERS/); do
46+
for vesta_user in $(ls $VESTA/data/users); do
6147
decrease_user_value "$vesta_user" '$IP_AVAIL'
6248
done
6349
else
@@ -71,7 +57,7 @@ if [ "$ip_owner" != "$user" ]; then
7157
increase_user_value "$user" '$IP_OWNED'
7258
if [ "$user" = 'admin' ]; then
7359
if [ "$ip_status" = 'shared' ]; then
74-
for user in $(ls $V_USERS/); do
60+
for user in $(ls $VESTA/data/users); do
7561
increase_user_value "$user" '$IP_AVAIL'
7662
done
7763
else

bin/v_change_sys_ip_status

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
ip=$1
1414
ip_status=$2
1515

16-
# Importing variables
17-
source $VESTA/conf/vesta.conf
16+
# Includes
1817
source $VESTA/func/shared.sh
1918
source $VESTA/func/ip.sh
2019

@@ -23,32 +22,21 @@ source $VESTA/func/ip.sh
2322
# Verifications #
2423
#----------------------------------------------------------#
2524

26-
# Checking arg number
2725
check_args '2' "$#" 'ip ip_status'
28-
29-
# Checking argument format
3026
validate_format 'ip' 'ip_status'
31-
32-
# Checking system ip
33-
is_sys_ip_valid
34-
35-
# Checking current status
36-
current_status=$(get_sys_ip_value '$STATUS')
37-
if [ "$ip_status" = "$current_status" ]; then
38-
echo "Error: status is already set"
39-
log_event 'debug' "$E_EXISTS $EVENT"
27+
is_ip_valid
28+
if [ "$ip_status" = "$(get_ip_value '$STATUS')" ]; then
29+
echo "Error: status $ip_status is already set"
30+
log_event "$E_EXISTS" "$EVENT"
4031
exit $E_EXISTS
4132
fi
4233

43-
# Parsing current ip usage
44-
web_domains=$(get_sys_ip_value '$U_WEB_DOMAINS')
45-
sys_user=$(get_sys_ip_value '$U_SYS_USERS')
46-
ip_owner=$(get_sys_ip_value '$OWNER')
47-
48-
# Checking condition
34+
web_domains=$(get_ip_value '$U_WEB_DOMAINS')
35+
sys_user=$(get_ip_value '$U_SYS_USERS')
36+
ip_owner=$(get_ip_value '$OWNER')
4937
if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then
50-
echo "Error: ip is used"
51-
log_event 'debug' "$E_INUSE $EVENT"
38+
echo "Error: ip $ip is used"
39+
log_event "$E_INUSE" "$EVENT"
5240
exit $E_INUSE
5341
fi
5442

@@ -58,7 +46,7 @@ fi
5846
#----------------------------------------------------------#
5947

6048
# Changing ip name
61-
update_sys_ip_value '$STATUS' "$ip_status"
49+
update_ip_value '$STATUS' "$ip_status"
6250

6351

6452
#----------------------------------------------------------#

bin/v_delete_sys_ip

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,12 @@ source $VESTA/func/domain.sh
2424
# Verifications #
2525
#----------------------------------------------------------#
2626

27-
# Checking arg number
2827
check_args '1' "$#" 'ip'
29-
30-
# Checking argument format
3128
validate_format 'ip'
32-
33-
# Checking system ip
34-
is_sys_ip_valid "$ip"
35-
36-
# Checking webdomains on ip
29+
is_ip_valid "$ip"
3730
is_ip_key_empty '$U_WEB_DOMAINS'
38-
39-
# Checking users on ip
4031
is_ip_key_empty '$U_SYS_USERS'
4132

42-
# Checking interface
43-
interface=$(get_current_interface)
44-
4533

4634
#----------------------------------------------------------#
4735
# Action #
@@ -54,10 +42,11 @@ iconf='/etc/sysconfig/network-scripts/ifcfg'
5442
rconf='/etc/httpd/conf.d/rpaf.conf'
5543

5644
# Get ip owner
57-
user="$(get_sys_ip_value '$OWNER')"
58-
ip_status="$(get_sys_ip_value '$STATUS')"
45+
user="$(get_ip_value '$OWNER')"
46+
ip_status="$(get_ip_value '$STATUS')"
5947

6048
# Deleting interface
49+
get_current_interface
6150
/sbin/ifconfig "$interface" down
6251

6352
# Deleting startup script
@@ -66,9 +55,6 @@ rm -f $iconf-$interface
6655
# Deleting vesta ip
6756
rm -f $VESTA/data/ips/$ip
6857

69-
# Importing main config
70-
source $VESTA/conf/vesta.conf
71-
7258
# Deleting namehosting support
7359
namehost_ip_disable
7460

@@ -84,7 +70,7 @@ fi
8470

8571
if [ "$user" = 'admin' ]; then
8672
if [ "$ip_status" = 'shared' ]; then
87-
for user in $(ls $V_USERS/); do
73+
for user in $(ls $VESTA/data/users/); do
8874
decrease_user_value "$user" '$IP_AVAIL'
8975
done
9076
else

bin/v_list_sys_interfaces

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Argument defenition
1313
format=${1-shell}
1414

15-
# Importing variables
15+
# Includes
1616
source $VESTA/func/shared.sh
1717

1818
# Json function
@@ -21,8 +21,6 @@ json_list_iface() {
2121
int_counter=$(echo "$interfaces" | wc -l)
2222
i=1
2323
echo '['
24-
25-
# Listing ifaces
2624
for interface in $interfaces; do
2725
if [ "$i" -lt "$int_counter" ]; then
2826
echo -e "\t\"$interface\","
@@ -41,7 +39,6 @@ shell_list_iface() {
4139
echo "INTERFACES"
4240
echo "----------"
4341
fi
44-
4542
for interface in $interfaces; do
4643
echo "$interface"
4744
done

0 commit comments

Comments
 (0)