forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_add_user
More file actions
executable file
·173 lines (137 loc) · 4.41 KB
/
Copy pathv_add_user
File metadata and controls
executable file
·173 lines (137 loc) · 4.41 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
#!/bin/bash
# info: add system user
# options: user password email [package] [fname] [lname]
#
# The function creates new user account.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
password=$2
email=$3
package=${4-default}
fname=$5
lname=$6
# Importing variables
source $VESTA/conf/vars.conf
source $V_CONF/vesta.conf
source $V_FUNC/shared.func
is_user_free() {
# Parsing domain values
check_sysuser=$(cut -f 1 -d : /etc/passwd | grep -w "$user" )
# Checking result
if [ ! -z "$check_sysuser" ] || [ -e "$V_USERS/$user" ]; then
echo "Error: user $user exist"
log_event 'debug' "$E_EXISTS $V_EVENT"
exit $E_EXISTS
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '3' "$#" 'user password email [package] [fname] [lname]'
# Checking argument format
format_validation 'user' 'password' 'email' 'package' 'fname' 'lname'
# Checking user
is_user_free "$user"
# Checking package
is_package_valid "$package"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Parsing package data
package_data=$(cat $V_PKG/$package.pkg)
# Checking shell
shell_conf=$(echo "$package_data" | grep 'SHELL' | cut -f 2 -d \')
case $shell_conf in
nologin) shell='/sbin/nologin' ;;
bash) shell='/bin/bash' ;;
sh) shell='/bin/bash' ;;
*) shell='/sbin/nologin' ;;
esac
# Adding user
/usr/sbin/adduser "$user" -s "$shell" -c "$email" -m -d "$V_HOME/$user"
# Adding password
echo "$password" | /usr/bin/passwd "$user" --stdin >/dev/null 2>&1
# Building directory tree
if [ ! -z "$BACKUP_SYSTEM" ] && [ "$BACKUP_SYSTEM" != 'no' ]; then
mkdir $V_HOME/$user/backup
chmod 751 $V_HOME/$user/backup
fi
if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
mkdir $V_HOME/$user/conf
mkdir $V_HOME/$user/web
mkdir $V_HOME/$user/tmp
chmod 751 $V_HOME/$user/conf
chmod 751 $V_HOME/$user/web
chmod 777 $V_HOME/$user/tmp
chown $user:$user $V_HOME/$user/web
fi
if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
mkdir $V_HOME/$user/mail
chmod 751 $V_HOME/$user/mail
fi
# Set permissions
chmod -R a+x $V_HOME/$user
# Checking quota
if [ ! -z "$DISK_QUOTA" ] && [ "$DISK_QUOTA" != 'no' ]; then
DISK_QUOTA=$(echo "$package_data" | grep 'DISK_QUOTA' | cut -f 2 -d \')
#$V_BIN/v_add_user_quota "$user" "$DISK_QUOTA"
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Adding user dir
mkdir $V_USERS/$user
# Creating configuration files and pipes
touch $V_USERS/$user/user.conf
echo "v_update_user_disk $user" >> $V_QUEUE/disk.pipe
if [ ! -z "$WEB_SYSTEM" ] && [ "$WEB_SYSTEM" != 'no' ]; then
mkdir $V_USERS/$user/ssl
touch $V_USERS/$user/web.conf
echo "$V_BIN/v_update_web_domains_traff $user" >> $V_QUEUE/traffic.pipe
echo "v_update_web_domains_disk $user" >> $V_QUEUE/disk.pipe
fi
if [ ! -z "$DNS_SYSTEM" ] && [ "$DNS_SYSTEM" != 'no' ]; then
touch $V_USERS/$user/dns.conf
mkdir $V_USERS/$user/dns
fi
if [ ! -z "$MAIL_SYSTEM" ] && [ "$MAIL_SYSTEM" != 'no' ]; then
touch $V_USERS/$user/mail_domains.conf
touch $V_USERS/$user/mail_boxes.conf
echo "v_upd_mail_domains_disk $user" >> $V_QUEUE/disk.pipe
fi
if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ]; then
touch $V_USERS/$user/db.conf
echo "v_update_db_bases_disk $user" >> $V_QUEUE/disk.pipe
fi
if [ ! -z "$CRON_SYSTEM" ] && [ "$CRON_SYSTEM" != 'no' ]; then
touch $V_USERS/$user/cron.conf
fi
# Filling user config
echo "FNAME='$fname'
LNAME='$lname'
PACKAGE='$package'
$package_data
SUSPENDED='no'
CONTACT='$email'
REPORTS='yes'
RKEY='$(gen_password)'
IP_OWNED='0'
U_DIR_DISK='0'
U_DISK='0'
U_BANDWIDTH='0'
U_WEB_DOMAINS='0'
U_WEB_SSL='0'
U_DNS_DOMAINS='0'
U_DATABASES='0'
U_MAIL_DOMAINS='0'
U_CRON_JOBS='0'
DATE='$V_DATE'" > $V_USERS/$user/user.conf
# Hiding password
V_EVENT="$V_DATE $V_SCRIPT $user ***** $email $package $fname $lname"
# Logging
log_event 'system' "$V_EVENT"
exit