forked from oneinstack/oneinstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pureftpd_vhost.sh
executable file
·164 lines (154 loc) · 5.15 KB
/
pureftpd_vhost.sh
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
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://blog.linuxeye.com
#
# Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
#
# Project home page:
# https://oneinstack.com
# https://github.com/lj2007331/oneinstack
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
clear
printf "
#######################################################################
# OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+ #
# FTP virtual user account management #
# For more information please visit https://oneinstack.com #
#######################################################################
"
. ./options.conf
. ./include/color.sh
# Check if user is root
[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
[ ! -d "$pureftpd_install_dir" ] && { echo "${CFAILURE}FTP server does not exist! ${CEND}"; exit 1; }
FTP_conf=$pureftpd_install_dir/etc/pure-ftpd.conf
FTP_tmp_passfile=$pureftpd_install_dir/etc/pureftpd_psss.tmp
Puredbfile=$pureftpd_install_dir/etc/pureftpd.pdb
Passwdfile=$pureftpd_install_dir/etc/pureftpd.passwd
FTP_bin=$pureftpd_install_dir/bin/pure-pw
[ -z "`grep ^PureDB $FTP_conf`" ] && { echo "${CFAILURE}pure-ftpd is not own password database${CEND}" ; exit 1; }
USER() {
while :; do echo
read -p "Please input a username: " User
if [ -z "$User" ]; then
echo "${CWARNING}username can't be NULL! ${CEND}"
else
break
fi
done
}
PASSWORD() {
while :; do echo
read -p "Please input the password: " Password
[ -n "`echo $Password | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and &${CEND}"; continue; }
if (( ${#Password} >= 5 ));then
echo -e "${Password}\n$Password" > $FTP_tmp_passfile
break
else
echo "${CWARNING}Ftp password least 5 characters! ${CEND}"
fi
done
}
DIRECTORY() {
while :; do echo
read -p "Please input the directory(Default directory: $wwwroot_dir): " Directory
if [ -z "$Directory" ]; then
Directory="$wwwroot_dir"
fi
if [ ! -d "$Directory" ]; then
echo "${CWARNING}The directory does not exist${CEND}"
else
break
fi
done
}
while :; do
printf "
What Are You Doing?
\t${CMSG}1${CEND}. UserAdd
\t${CMSG}2${CEND}. UserMod
\t${CMSG}3${CEND}. UserPasswd
\t${CMSG}4${CEND}. UserDel
\t${CMSG}5${CEND}. ListAllUser
\t${CMSG}6${CEND}. ShowUser
\t${CMSG}q${CEND}. Exit
"
read -p "Please input the correct option: " Number
if [[ ! $Number =~ ^[1-6,q]$ ]]; then
echo "${CFAILURE}input error! Please only input 1 ~ 6 and q${CEND}"
else
case "$Number" in
1)
USER
[ -e "$Passwdfile" ] && [ -n "`grep ^${User}: $Passwdfile`" ] && { echo "${CQUESTION}[$User] is already existed! ${CEND}"; continue; }
PASSWORD;DIRECTORY
$FTP_bin useradd $User -f $Passwdfile -u $run_user -g $run_user -d $Directory -m < $FTP_tmp_passfile
$FTP_bin mkdb $Puredbfile -f $Passwdfile > /dev/null 2>&1
echo "#####################################"
echo
echo "[$User] create successful! "
echo
echo "You user name is : ${CMSG}$User${CEND}"
echo "You Password is : ${CMSG}$Password${CEND}"
echo "You directory is : ${CMSG}$Directory${CEND}"
echo
;;
2)
USER
[ -e "$Passwdfile" ] && [ -z "`grep ^${User}: $Passwdfile`" ] && { echo "${CQUESTION}[$User] was not existed! ${CEND}"; continue; }
DIRECTORY
$FTP_bin usermod $User -f $Passwdfile -d $Directory -m
$FTP_bin mkdb $Puredbfile -f $Passwdfile > /dev/null 2>&1
echo "#####################################"
echo
echo "[$User] modify a successful! "
echo
echo "You user name is : ${CMSG}$User${CEND}"
echo "You new directory is : ${CMSG}$Directory${CEND}"
echo
;;
3)
USER
[ -e "$Passwdfile" ] && [ -z "`grep ^${User}: $Passwdfile`" ] && { echo "${CQUESTION}[$User] was not existed! ${CEND}"; continue; }
PASSWORD
$FTP_bin passwd $User -f $Passwdfile -m < $FTP_tmp_passfile
$FTP_bin mkdb $Puredbfile -f $Passwdfile > /dev/null 2>&1
echo "#####################################"
echo
echo "[$User] Password changed successfully! "
echo
echo "You user name is : ${CMSG}$User${CEND}"
echo "You new password is : ${CMSG}$Password${CEND}"
echo
;;
4)
if [ ! -e "$Passwdfile" ]; then
echo "${CQUESTION}User was not existed! ${CEND}"
else
$FTP_bin list
fi
USER
[ -e "$Passwdfile" ] && [ -z "`grep ^${User}: $Passwdfile`" ] && { echo "${CQUESTION}[$User] was not existed! ${CEND}"; continue; }
$FTP_bin userdel $User -f $Passwdfile -m
$FTP_bin mkdb $Puredbfile -f $Passwdfile > /dev/null 2>&1
echo
echo "[$User] have been deleted! "
;;
5)
if [ ! -e "$Passwdfile" ]; then
echo "${CQUESTION}User was not existed! ${CEND}"
else
$FTP_bin list
fi
;;
6)
USER
[ -e "$Passwdfile" ] && [ -z "`grep ^${User}: $Passwdfile`" ] && { echo "${CQUESTION}[$User] was not existed! ${CEND}"; continue; }
$FTP_bin show $User
;;
q)
exit
;;
esac
fi
done