-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathftpcredz.sh
executable file
·63 lines (57 loc) · 1.95 KB
/
ftpcredz.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
# +----+----+----+----+
# | | | | |
# Author: Mark David Scott Cunningham | M | D | S | C |
# +----+----+----+----+
# Created: 2014-07-31
# Updated: 2014-07-31
#
#
#!/bin/bash
ftpcredz(){
# Parse input parameters (Check for help option, or empty run)
if [[ -z $@ || $1 =~ -h ]]; then
echo "
Usage: ftpcredz [-u <ftpuser>] [-d <domain>] [ -m | -x | -p <password> ]
-u ... Specify username of ftp user w/o domain (assumes primary domain)
-d ... Specify domain for secondry ftp users
-m ... Generate password using mkpasswd
-p ... Specify new password directly
-x ... Generate password using xkcd (default if no method specified)
"
return 0;
fi
# if -u option is given then next parameter is username
# otherwise assume that the user if [email protected]
if [[ $1 = '-u' ]]; then
ftpUser=$2; shift; shift;
else
ftpUser='ftp';
fi
if [[ $1 == '-d' ]]; then
primaryDomain=$2; shift; shift
else
#Lookup primary domain given unix user
primaryDomain=$(~iworx/bin/listaccounts.pex | grep $(getusr) | awk '{print $2}')
fi
# if password option is given use prefered password method
# ^^^ defaults to xkcd method if no method is specified
if [[ $1 == '-m' ]]; then
newPass=$(mkpasswd -l 15);
elif [[ $1 == '-x' ]]; then
newPass=$(xkcd);
elif [[ $1 == '-p' ]]; then
newPass="$2";
else
newPass=$(xkcd);
fi
# Log into Siteworx using unix user for account
# ^^^ Can't run a ftp reset from Nodeworx, to log into Siteworx without credz, sudo to the unix user.
sudo -u $(getusr) -- siteworx -u --login_domain $primaryDomain -n -c Ftp -a edit --password $newPass --confirm_password $newPass --user $ftpUser
# Print new credentials as block for copy pasta
echo "
Hostname: $(hostname)
Username: ${ftpUser}@${primaryDomain}
Password: $newPass
"
}
ftpcredz "$@"