forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_add_web_domain
More file actions
executable file
·187 lines (147 loc) · 5.33 KB
/
Copy pathv_add_web_domain
File metadata and controls
executable file
·187 lines (147 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# info: adding web domain
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user="$1"
domain=$(idn -t --quiet -u "$2" )
domain_idn=$(idn -t --quiet -a "$domain")
ip="$3"
template=${4-default}
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
source $V_FUNC/domain_func.sh
source $V_FUNC/ip_func.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '3' "$#" 'user domain ip [template]'
# Checking argument format
format_validation 'user' 'domain' 'ip' 'template'
# Checking web system is enabled
is_system_enabled 'web'
# Checking user
is_user_valid
# Checking user is active
is_user_suspended
# Checking domain
is_domain_new 'quiet'
if [ $? -ne $OK ]; then
# Checking domain owner
is_domain_owner
# Checking domain service
is_web_domain_free
fi
# Checking ip
is_ip_avalable
# Checking package
is_package_full 'web_domain'
# Checking template
templates=$(get_user_value '$TEMPLATES')
is_template_valid "web"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining domain aliases
ip_name=$(get_ip_name)
ip_name_idn=$(idn -t --quiet -a "$ip_name")
domain_alias="www.$domain"
domain_alias_idn="www.$domain_idn"
if [ ! -z "$ip_name" ]; then
domain_alias_dash="${domain//./-}.$ip_name"
domain_alias_dash_idn="${domain_idn//./-}.$ip_name_idn"
aliases="$domain_alias,$domain_alias_dash"
aliases_idn="$domain_alias_idn,$domain_alias_dash_idn"
else
aliases="$domain_alias"
aliases_idn="$domain_alias_idn"
fi
# Defining vars for httpd_add_config function
port=$(get_web_port)
group="$user"
email="$user@$domain"
docroot="$V_HOME/$user/domains/$domain/public_html"
conf="$V_HOME/$user/conf/httpd.conf"
tpl_file="$V_WEBTPL/apache_$template.tpl"
# Adding domain to the httpd.conf
httpd_add_config
# Building directory tree
mkdir $V_HOME/$user/domains/$domain \
$V_HOME/$user/domains/$domain/public_html \
$V_HOME/$user/domains/$domain/public_shtml \
$V_HOME/$user/domains/$domain/document_errors \
$V_HOME/$user/domains/$domain/cgi-bin \
$V_HOME/$user/domains/$domain/private \
$V_HOME/$user/domains/$domain/stats \
$V_HOME/$user/domains/$domain/logs
# Adding domain logs
touch /var/log/httpd/domains/$domain.bytes \
/var/log/httpd/domains/$domain.log \
/var/log/httpd/domains/$domain.error_log
# Adding symlink for logs
ln -s /var/log/httpd/domains/$domain.*log $V_HOME/$user/domains/$domain/logs/
# Adding domain skeleton
cp -r $V_WEBTPL/skel/public_html/ $V_HOME/$user/domains/$domain/
cp -r $V_WEBTPL/skel/public_shtml/ $V_HOME/$user/domains/$domain/
cp -r $V_WEBTPL/skel/document_errors/ $V_HOME/$user/domains/$domain/
cp -r $V_WEBTPL/skel/cgi-bin/ $V_HOME/$user/domains/$domain/
# Changing tpl values
for file in $(find "$V_HOME/$user/domains/$domain/" -type f); do
sed -i "s/%domain%/$domain/g" $file
done
# Changing file owner
chown -R $user:$user $V_HOME/$user/domains/$domain
chown root:$user /var/log/httpd/domains/$domain.*
# Changing file permissions
chmod 551 $V_HOME/$user/domains/$domain
chmod 751 $V_HOME/$user/domains/$domain/private
chmod 751 $V_HOME/$user/domains/$domain/cgi-bin
chmod 751 $V_HOME/$user/domains/$domain/public_html
chmod 751 $V_HOME/$user/domains/$domain/public_shtml
chmod 751 $V_HOME/$user/domains/$domain/document_errors
chmod -f -R 775 $V_HOME/$user/domains/$domain/cgi-bin/*
chmod -f -R 775 $V_HOME/$user/domains/$domain/public_html/*
chmod -f -R 775 $V_HOME/$user/domains/$domain/document_errors/*
chmod 551 $V_HOME/$user/domains/$domain/stats
chmod 551 $V_HOME/$user/domains/$domain/logs
chmod 640 /var/log/httpd/domains/$domain.*
# Running template post setup file
if [ -e $V_WEBTPL/apache_$template.sh ]; then
$V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot $port
fi
# Checking main vesta httpd config
main_conf='/etc/httpd/conf.d/vesta.conf'
main_conf_check=$(grep "$conf" $main_conf )
if [ -z "$main_conf_check" ]; then
echo "Include $conf" >>$main_conf
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Increasing ip value
increase_ip_value
# Increasing domain value
increase_user_value "$user" '$U_WEB_DOMAINS'
# Defining domain variables
template_data=$(cat $V_WEBTPL/apache_$template.descr|grep -v '#')
v_str="DOMAIN='$domain'"
v_str="$v_str IP='$ip'"
v_str="$v_str U_DISK='0'"
v_str="$v_str U_BANDWIDTH='0'"
v_str="$v_str TPL='$template'"
v_str="$v_str ALIAS='$aliases'"
v_str="$v_str $template_data" # Inserting PHP,CGI and ELOG keys
v_str="$v_str STATS='' STATS_AUTH=''"
v_str="$v_str SSL='no' SSL_HOME='' SSL_CERT=''"
v_str="$v_str NGINX='' NGINX_EXT='' SUSPEND='no' DATE='$V_DATE'"
# Registering domain
echo "$v_str" >>$V_USERS/$user/web_domains.conf
# Adding task to the vesta pipe
restart_schedule 'web'
# Logging
log_history "$V_EVENT" "v_del_web_domain $user $domain"
log_event 'system' "$V_EVENT"
exit $OK