138 lines
3.2 KiB
Bash
138 lines
3.2 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
##########################################
|
||
|
## aec ftp/sftp account creation script ##
|
||
|
## written by david ##
|
||
|
##########################################
|
||
|
|
||
|
## script configuration section
|
||
|
# do not use an tailing slash here
|
||
|
accpath="/media/storage"
|
||
|
acchost="newftp.aec.at"
|
||
|
sftpgroup="sftpusers" # must exist
|
||
|
ftpgroup="ftpusers" # must exist
|
||
|
logging=1
|
||
|
logpath="/media/storage/logs"
|
||
|
logfile="accounts.log"
|
||
|
jabberlog=1
|
||
|
jabberwatchdogs="david@aec.at david@socialnerds.org"
|
||
|
jabberuser="david"
|
||
|
jabberserver="jabber.aec.at"
|
||
|
jabberpass="somepassword"
|
||
|
|
||
|
|
||
|
## am i root?
|
||
|
if [ "$(whoami)" != 'root' ]; then
|
||
|
echo "only root can do this"
|
||
|
exit 1;
|
||
|
fi
|
||
|
|
||
|
## check for dependencys
|
||
|
# not yet implemented (sendxmpp, ssh, vsftpd, ..)
|
||
|
|
||
|
clear
|
||
|
echo "Welcome to the AEC FTP/sFTP Creation Script"
|
||
|
echo ""
|
||
|
## choose ftp or sftp
|
||
|
echo "which type of account you want to create? [sftp|ftp]"
|
||
|
read acctype
|
||
|
|
||
|
if [ $acctype = "sftp" ]; then
|
||
|
echo ""
|
||
|
else
|
||
|
if [ $acctype = "ftp" ]; then
|
||
|
echo ""
|
||
|
else
|
||
|
#clear
|
||
|
echo "I'm sorry, i need to break this up right now."
|
||
|
echo "It seams you can't understand some simple instructions.."
|
||
|
exit 1;
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
echo "Enter the Accountname:"
|
||
|
read accname
|
||
|
|
||
|
## quota
|
||
|
accquota="quota not yet implemented"
|
||
|
|
||
|
## requester
|
||
|
echo ""
|
||
|
echo "Who orderd this account? (I'm tracking this for greater good)"
|
||
|
read accrequester
|
||
|
|
||
|
## set $accport
|
||
|
if [ $acctype = "sftp" ]; then
|
||
|
accport="22"
|
||
|
else
|
||
|
accport="21"
|
||
|
fi
|
||
|
|
||
|
## get timestamp
|
||
|
acctimestamp=$(date)
|
||
|
|
||
|
## gen password (acpass)
|
||
|
accpass=$(pwgen -sync 10 1)
|
||
|
|
||
|
|
||
|
## create home, set its permissions and add the user to sftp/ftpgroup
|
||
|
if [ $acctype = "sftp" ]; then
|
||
|
mkdir -p $accpath/$acctype"_accounts"/$accname/data
|
||
|
# create the actual user (sftp)
|
||
|
useradd -d /data -M -U -s /usr/lib/sftp-server -p $accpass $accname
|
||
|
chown -R $accname\: $accpath/$acctype"_accounts"/$accname/data
|
||
|
adduser $accname $sftpgroup
|
||
|
else
|
||
|
mkdir -p $accpath/$acctype"_accounts"/$accname
|
||
|
# create the actual user (ftp)
|
||
|
useradd -d $accpath/$acctype"_accounts"/$accname -M -U -s /bin/false -p $accpass $accname
|
||
|
chown -R $accname\: $accpath/$acctype"_accounts"/$accname
|
||
|
adduser $accname $ftpgroup
|
||
|
fi
|
||
|
|
||
|
## logging (log type, name, pass, quota, requester and timestamp)
|
||
|
if [ $logging = 1 ]; then
|
||
|
if [ -e $logpath/$logfile ]; then
|
||
|
cd $logpath
|
||
|
echo $acctype $accname $accpass $accquota $accrequester $acctimestamp >> $logfile
|
||
|
else
|
||
|
mkdir -p $logpath
|
||
|
cd $logpath
|
||
|
touch $logfile
|
||
|
echo "type name pass quota reguester timestamp" >> $logfile
|
||
|
echo $acctype $accname $accpass $accquota $accrequester $acctimestamp >> $logfile
|
||
|
fi
|
||
|
else
|
||
|
echo ""
|
||
|
fi
|
||
|
|
||
|
|
||
|
## jabber notification
|
||
|
if [ $jabberlog = 1 ]; then
|
||
|
echo "
|
||
|
This is Lieutenant Sulu,
|
||
|
a "$acctype" account was just created.
|
||
|
Accountname:" $accname "
|
||
|
Quota:" $accquota "
|
||
|
Requester:" $accrequester | sendxmpp -u $jabberuser -j $jabberserver -p $jabberpass $jabberwatchdogs
|
||
|
else
|
||
|
echo ""
|
||
|
fi
|
||
|
|
||
|
|
||
|
## account data output
|
||
|
clear
|
||
|
echo ""
|
||
|
echo "Account data"
|
||
|
echo ""
|
||
|
echo "Host:" $acchost
|
||
|
echo "Port:" $accport
|
||
|
echo "Username:" $accname
|
||
|
echo "Password:" $accpass
|
||
|
echo "Quota:" $accquota
|
||
|
echo "Directory:" $accpath/$acctype"_accounts"/$accname
|
||
|
echo "Requester:" $accrequester
|
||
|
echo ""
|
||
|
echo "Everything is done"
|
||
|
|