1
1
scripts/addaccount.sh

174 lines
4.4 KiB
Bash
Raw Normal View History

2010-06-26 02:43:02 +02:00
#!/bin/bash
2010-06-26 03:01:46 +02:00
############################################
## ##
## AEC FTP/sFTP Account Creation Script ##
## v0.2 ##
## Author: David Starzengruber ##
## ##
############################################
## script configuration section ##
2010-06-26 02:43:02 +02:00
accpath="/media/storage"
2010-06-26 03:01:46 +02:00
acchost="betterftp.aec.at" # the dns name where your sever is reachable
sftpgroup="sftpusers" # this group must exist
trackrequester="yes" # switch to "no" if you do not want to track the requester
logging=1 # set this to 0 if you don't want any logging
logpath="/media/storage/logs" # there you want to create your logfile
logfile="accounts.log" # choose the logfile name here
jabberlog=1 # set this to 0 if you don't want jabber notifications
## following ist not necessary if jabberlog=0
jabberwatchdogs="david@aec.at biancasc@aec.at geraldho@aec.at danielwe@aec.at"
jabberuser="logging"
2010-06-26 02:43:02 +02:00
jabberserver="jabber.aec.at"
2010-06-26 03:01:46 +02:00
jabberpass="jabberLOG4711"
2010-06-26 02:43:02 +02:00
2010-06-26 03:01:46 +02:00
## am i root? ##
if [ "$(whoami)" != "root" ]; then
2010-06-26 02:43:02 +02:00
echo "only root can do this"
exit 1;
fi
2010-06-26 03:01:46 +02:00
## check for dependencys ##
2010-06-26 02:43:02 +02:00
# not yet implemented (sendxmpp, ssh, vsftpd, ..)
2010-06-26 03:01:46 +02:00
#clear
echo "" # just an empty line
echo "Welcome to the AEC FTP/sFTP Account Creation Script (v0.2)"
2010-06-26 02:43:02 +02:00
## choose ftp or sftp
2010-06-26 03:01:46 +02:00
echo ""
echo "Which type of account you want to create? [sftp|ftp]"
2010-06-26 02:43:02 +02:00
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
2010-06-26 03:01:46 +02:00
if [ -z $1 ]; then
needaccname="yes"
while [ $needaccname = "yes" ]; do
echo ""
echo "Enter Accountname:"
read accname
if [ -z $accname ]; then
echo "This field is mandatory."
else
needaccname="notanymore"
fi
done
else
accname=$1
fi
2010-06-26 02:43:02 +02:00
## quota
accquota="quota not yet implemented"
2010-06-26 03:01:46 +02:00
2010-06-26 02:43:02 +02:00
## requester
2010-06-26 03:01:46 +02:00
while [ $trackrequester = "yes" ]; do
echo ""
echo "Who orderd this account? (I'm tracking this for a greater good.)"
read accrequester
if [ -z "$accrequester" ]; then
echo "This field is mandatory."
else
trackrequester="notanymore"
fi
done
2010-06-26 02:43:02 +02:00
## set $accport
if [ $acctype = "sftp" ]; then
accport="22"
else
accport="21"
fi
2010-06-26 03:01:46 +02:00
2010-06-26 02:43:02 +02:00
## get timestamp
2010-06-26 03:01:46 +02:00
acctimestamp=$(date '+%dr%B %Y %H:%M')
2010-06-26 02:43:02 +02:00
2010-06-26 03:01:46 +02:00
## gen password (acpass)
accpass=$(pwgen -snc 10 1)
echo $accpass > pass.txt
accencpass=$(makepasswd --clearfrom=pass.txt --crypt-md5 |awk '{print $2}')
rm pass.txt
2010-06-26 02:43:02 +02:00
## 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)
2010-06-26 03:01:46 +02:00
useradd -d /data -M -U -s /usr/lib/sftp-server -p $accencpass $accname
2010-06-26 02:43:02 +02:00
chown -R $accname\: $accpath/$acctype"_accounts"/$accname/data
adduser $accname $sftpgroup
else
mkdir -p $accpath/$acctype"_accounts"/$accname
# create the actual user (ftp)
2010-06-26 03:01:46 +02:00
useradd -d $accpath/$acctype"_accounts"/$accname -M -U -s /bin/false -p $accencpass $accname
2010-06-26 02:43:02 +02:00
chown -R $accname\: $accpath/$acctype"_accounts"/$accname
2010-06-26 03:01:46 +02:00
echo $accname >> /etc/vsftpd.user_list
2010-06-26 02:43:02 +02:00
fi
2010-06-26 03:01:46 +02:00
2010-06-26 02:43:02 +02:00
## 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 "
2010-06-26 03:01:46 +02:00
Requester:" $accrequester | sendxmpp -r ftpcreation -u $jabberuser -j $jabberserver -p $jabberpass $jabberwatchdogs
2010-06-26 02:43:02 +02:00
else
echo ""
fi
## account data output
2010-06-26 03:01:46 +02:00
#clear
2010-06-26 02:43:02 +02:00
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"
2010-06-26 03:01:46 +02:00
exit 0