Skip to content

Commit 530fc3b

Browse files
committed
add dns zones when editing webaliases
1 parent fda044b commit 530fc3b

File tree

6 files changed

+142
-44
lines changed

6 files changed

+142
-44
lines changed

bin/v_add_dns_on_web_alias

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# info: add dns domain or dns record based on web domain alias
2+
# info: add dns domain or dns record based on web domain alias restart
33
# options: user domain
44
#
55
# The function adds dns domain or dns record based on web domain alias.
@@ -11,8 +11,13 @@
1111

1212
# Argument defenition
1313
user=$1
14-
domain=$(echo $domain | sed -e 's/\.*$//g' -e 's/^\.*//g')
14+
domain=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
1515
domain_idn=$(idn -t --quiet -a "$domain")
16+
dom_alias=$(idn -t --quiet -u "$3" )
17+
dom_alias=$(echo $dom_alias | sed -e 's/\.*$//g' -e 's/^\.*//g')
18+
dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]')
19+
dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
20+
restart="$4"
1621

1722
# Includes
1823
source $VESTA/conf/vesta.conf
@@ -24,7 +29,7 @@ source $VESTA/func/domain.sh
2429
# Verifications #
2530
#----------------------------------------------------------#
2631

27-
check_args '2' "$#" 'user domain'
32+
check_args '3' "$#" 'user domain alias'
2833
validate_format 'user' 'domain'
2934
is_system_enabled "$WEB_SYSTEM"
3035
is_system_enabled "$DNS_SYSTEM"
@@ -41,34 +46,35 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain"
4146
# Parsing domain values
4247
get_domain_values 'web'
4348

44-
OLD_IFS=$IFS
45-
IFS=','
46-
for web_alias in $ALIAS; do
47-
# Check if parent dns domain exist
48-
sub_domain=$(echo $web_alias | cut -f1 -d .)
49-
pr_domain=$(echo $web_alias | sed -e "s/^$sub_domain.//" )
50-
check_parent=$(grep "DOMAIN='$pr_domain'" $USER_DATA/dns.conf)
51-
if [ -z "$check_parent" ]; then
52-
check_dom=$(grep "DOMAIN='$web_alias'" $USER_DATA/dns.conf)
53-
if [ -z "$check_dom" ]; then
54-
$BIN/v_add_dns_domain $user $web_alias $IP
55-
fi
49+
# Check if it a simple domain
50+
if [ $(echo -e "${dom_alias//\./\n}" | wc -l) -le 2 ]; then
51+
if [ ! -e "$USER_DATA/dns/$dom_alias.conf" ]; then
52+
$BIN/v_add_dns_domain $user $dom_alias $IP '' '' '' '' '' $restart
53+
fi
54+
else
55+
# Check subdomain
56+
sub=$(echo "$dom_alias" | cut -f1 -d . -s)
57+
dom=$(echo "$dom_alias" | sed -e "s/^$sub.//" )
58+
if [ ! -e "$USER_DATA/dns/$dom.conf" ]; then
59+
$BIN/v_add_dns_domain $user $dom $IP '' '' '' '' '' $restart
60+
$BIN/v_add_dns_domain_record $user $dom "$sub" A $IP '' '' $restart
5661
else
57-
check_rec=$(grep "RECORD='$sub_domain'" $USER_DATA/dns/$pr_domain.conf)
58-
if [ -z "$check_rec" ]; then
59-
$BIN/v_add_dns_domain_record $user $pr_domain $sub_domain A $IP
62+
if [ "$sub" == '*' ]; then
63+
rec=$(grep -w "RECORD='\*'" $USER_DATA/dns/$dom.conf)
64+
else
65+
rec=$(grep -w "RECORD='$sub'" $USER_DATA/dns/$dom.conf)
66+
fi
67+
if [ -z "$rec" ]; then
68+
$BIN/v_add_dns_domain_record $user $dom "$sub" A $IP '' '' $restart
6069
fi
6170
fi
62-
done
71+
fi
6372

6473

6574
#----------------------------------------------------------#
6675
# Vesta #
6776
#----------------------------------------------------------#
6877

69-
# Restart web server
70-
$BIN/v_restart_dns "$EVENT"
71-
7278
# Logging
7379
log_history "$EVENT"
7480
log_event "$OK" "$EVENT"

bin/v_delete_dns_on_web_alias

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
# info: delete dns domain or dns record based on web domain alias
3+
# options: user domain
4+
#
5+
# The function deletes dns domain or dns record based on web domain alias.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
15+
domain_idn=$(idn -t --quiet -a "$domain")
16+
dom_alias=$(idn -t --quiet -u "$3" )
17+
dom_alias=$(echo $dom_alias | sed -e 's/\.*$//g' -e 's/^\.*//g')
18+
dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]')
19+
dom_alias_idn=$(idn -t --quiet -a "$dom_alias" )
20+
restart="$4"
21+
22+
# Includes
23+
source $VESTA/conf/vesta.conf
24+
source $VESTA/func/main.sh
25+
source $VESTA/func/domain.sh
26+
27+
28+
#----------------------------------------------------------#
29+
# Verifications #
30+
#----------------------------------------------------------#
31+
32+
check_args '3' "$#" 'user domain alias'
33+
validate_format 'user' 'domain'
34+
is_system_enabled "$WEB_SYSTEM"
35+
is_system_enabled "$DNS_SYSTEM"
36+
is_object_valid 'user' 'USER' "$user"
37+
is_object_unsuspended 'user' 'USER' "$user"
38+
is_object_valid 'web' 'DOMAIN' "$domain"
39+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
40+
41+
42+
#----------------------------------------------------------#
43+
# Action #
44+
#----------------------------------------------------------#
45+
46+
# Parsing domain values
47+
get_domain_values 'web'
48+
49+
# Check if it a simple domain
50+
if [ $(echo -e "${dom_alias//\./\n}" | wc -l) -le 2 ]; then
51+
if [ -e "$USER_DATA/dns/$dom_alias.conf" ]; then
52+
$BIN/v_delete_dns_domain $user $dom_alias $IP $restart
53+
fi
54+
else
55+
# Check subdomain
56+
sub=$(echo "$dom_alias" | cut -f1 -d . -s)
57+
root=$(echo "$dom_alias" | sed -e "s/^$sub.//" )
58+
if [ -e "$USER_DATA/dns/$root.conf" ]; then
59+
if [ "$sub" == '*' ]; then
60+
rec=$(grep -w "RECORD='\*'" $USER_DATA/dns/$root.conf)
61+
else
62+
rec=$(grep -w "RECORD='$sub'" $USER_DATA/dns/$root.conf)
63+
fi
64+
if [ ! -z "$rec" ]; then
65+
eval "$rec"
66+
$BIN/v_delete_dns_domain_record $user "$root" "$ID"
67+
fi
68+
fi
69+
fi
70+
71+
72+
#----------------------------------------------------------#
73+
# Vesta #
74+
#----------------------------------------------------------#
75+
76+
# Logging
77+
log_history "$EVENT"
78+
log_event "$OK" "$EVENT"
79+
80+
exit

bin/v_update_mail_domains_disk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ done
5858
recalc_user_disk_usage
5959

6060
# Logging
61-
log_history "$EVENT"
6261
log_event "$OK" "$EVENT"
6362

6463
exit

web/add/web/index.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@
100100
}
101101
}
102102
unset($output);
103-
}
104-
if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) {
105-
exec (VESTA_CMD."v_add_dns_on_web_alias ".$user." ".$v_domain." 'no'", $output, $return_var);
106-
if ($return_var != 0) {
107-
$error = implode('<br>', $output);
108-
if (empty($error)) $error = 'Error: vesta did not return any output.';
109-
$_SESSION['error_msg'] = $error;
103+
if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) {
104+
exec (VESTA_CMD."v_add_dns_on_web_alias ".$user." ".$v_domain." ".$alias." 'no'", $output, $return_var);
105+
if ($return_var != 0) {
106+
$error = implode('<br>', $output);
107+
if (empty($error)) $error = 'Error: vesta did not return any output.';
108+
$_SESSION['error_msg'] = $error;
109+
}
110+
unset($output);
110111
}
111-
unset($output);
112112
}
113113
}
114114

@@ -182,6 +182,16 @@
182182
unset($output);
183183
}
184184

185+
if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) {
186+
exec (VESTA_CMD."v_restart_dns", $output, $return_var);
187+
if ($return_var != 0) {
188+
$error = implode('<br>', $output);
189+
if (empty($error)) $error = 'Error: vesta did not return any output.';
190+
$_SESSION['error_msg'] = $error;
191+
}
192+
unset($output);
193+
}
194+
185195
if (empty($_SESSION['error_msg'])) {
186196
exec (VESTA_CMD."v_restart_web", $output, $return_var);
187197
if ($return_var != 0) {
@@ -205,6 +215,10 @@
205215
$ips = json_decode(implode('', $output), true);
206216
unset($output);
207217

218+
exec (VESTA_CMD."v_get_user_value ".$user." 'TEMPLATE'", $output, $return_var);
219+
$template = $output[0] ;
220+
unset($output);
221+
208222
exec (VESTA_CMD."v_list_web_templates json", $output, $return_var);
209223
$templates = json_decode(implode('', $output), true);
210224
unset($output);

web/edit/web/index.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
$v_aliases = str_replace(' ', "\n", $waliases);
143143
$result = array_diff($valiases, $aliases);
144144
foreach ($result as $alias) {
145-
if (empty($_SESSION['error_msg'])) {
145+
if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
146146
$restart_web = 'yes';
147147
$v_template = escapeshellarg($_POST['v_template']);
148148
exec (VESTA_CMD."v_delete_web_domain_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var);
@@ -152,9 +152,9 @@
152152
$_SESSION['error_msg'] = $error;
153153
}
154154
unset($output);
155-
exec (VESTA_CMD."v_list_dns_domain ".$v_username." '".$alias."' json", $output, $return_var);
156-
if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) {
157-
exec (VESTA_CMD."v_delete_dns_domain ".$v_username." '".$alias."'", $output, $return_var);
155+
156+
if (empty($_SESSION['error_msg'])) {
157+
exec (VESTA_CMD."v_delete_dns_on_web_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var);
158158
if ($return_var != 0) {
159159
$error = implode('<br>', $output);
160160
if (empty($error)) $error = 'Error: vesta did not return any output.';
@@ -168,7 +168,7 @@
168168

169169
$result = array_diff($aliases, $valiases);
170170
foreach ($result as $alias) {
171-
if (empty($_SESSION['error_msg'])) {
171+
if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
172172
$restart_web = 'yes';
173173
$v_template = escapeshellarg($_POST['v_template']);
174174
exec (VESTA_CMD."v_add_web_domain_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var);
@@ -178,9 +178,8 @@
178178
$_SESSION['error_msg'] = $error;
179179
}
180180
unset($output);
181-
exec (VESTA_CMD."v_list_dns_domain ".$v_username." '".$alias."' json", $output, $return_var);
182-
if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) {
183-
exec (VESTA_CMD."v_add_dns_domain ".$v_username." '".$alias."' ".$v_ip, $output, $return_var);
181+
if (empty($_SESSION['error_msg'])) {
182+
exec (VESTA_CMD."v_add_dns_on_web_alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var);
184183
if ($return_var != 0) {
185184
$error = implode('<br>', $output);
186185
if (empty($error)) $error = 'Error: vesta did not return any output.';

web/templates/admin/add_web.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242
<tr><td class="add-text" style="padding: 10px 0 0 2px;">DNS support</td></tr>
4343
<tr><td><input type="checkbox" size="20" class="add-checkbox" name="v_dns" <?php if (empty($v_dns)) echo "checked=yes"; ?>></tr>
44-
4544
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Mail support</td></tr>
4645
<tr><td><input type="checkbox" size="20" class="add-checkbox" name="v_mail" <?php if (empty($v_mail)) echo "checked=yes"; ?>></tr>
4746
<tr><td class="add-text" style="padding: 10px 0 0 2px;"><a href="javascript:elementHideShow('advtable');" class="add-advanced">Advanced Options ⇢</a></td></tr>
@@ -52,14 +51,15 @@
5251
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Apache Template</td></tr>
5352
<tr><td><select class="add-list" name="v_template">
5453
<?php
55-
echo "<option value=''></option>";
5654
foreach ($templates as $key => $value) {
57-
5855
echo "\t\t\t\t<option value=\"".$value."\"";
59-
if ((!empty($v_template)) && ( $key == $_POST['v_template'])){
56+
if ((!empty($v_template)) && ( $value == $_POST['v_template'])){
6057
echo ' selected' ;
6158
}
62-
echo ">".$value."</option>\n";
59+
if ((empty($v_template)) && ( $value == $template)){
60+
echo ' selected' ;
61+
}
62+
echo "> ".$value." </option>\n";
6363
}
6464
?>
6565
</select></td></tr>

0 commit comments

Comments
 (0)