committed to v0.2
This commit is contained in:
parent
8c10beba82
commit
b369cdd0c1
108
addaccount.sh
108
addaccount.sh
|
@ -1,40 +1,46 @@
|
|||
#!/bin/bash
|
||||
|
||||
##########################################
|
||||
## aec ftp/sftp account creation script ##
|
||||
## written by david ##
|
||||
##########################################
|
||||
############################################
|
||||
## ##
|
||||
## AEC FTP/sFTP Account Creation Script ##
|
||||
## v0.2 ##
|
||||
## Author: David Starzengruber ##
|
||||
## ##
|
||||
############################################
|
||||
|
||||
## script configuration section
|
||||
# do not use an tailing slash here
|
||||
## script configuration section ##
|
||||
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"
|
||||
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"
|
||||
jabberserver="jabber.aec.at"
|
||||
jabberpass="somepassword"
|
||||
jabberpass="jabberLOG4711"
|
||||
|
||||
|
||||
## am i root?
|
||||
if [ "$(whoami)" != 'root' ]; then
|
||||
## am i root? ##
|
||||
if [ "$(whoami)" != "root" ]; then
|
||||
echo "only root can do this"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
## check for dependencys
|
||||
|
||||
## check for dependencys ##
|
||||
# not yet implemented (sendxmpp, ssh, vsftpd, ..)
|
||||
|
||||
clear
|
||||
echo "Welcome to the AEC FTP/sFTP Creation Script"
|
||||
echo ""
|
||||
|
||||
#clear
|
||||
echo "" # just an empty line
|
||||
echo "Welcome to the AEC FTP/sFTP Account Creation Script (v0.2)"
|
||||
## choose ftp or sftp
|
||||
echo "which type of account you want to create? [sftp|ftp]"
|
||||
echo ""
|
||||
echo "Which type of account you want to create? [sftp|ftp]"
|
||||
read acctype
|
||||
|
||||
if [ $acctype = "sftp" ]; then
|
||||
|
@ -50,16 +56,39 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
echo "Enter the Accountname:"
|
||||
read accname
|
||||
|
||||
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
|
||||
|
||||
|
||||
## quota
|
||||
accquota="quota not yet implemented"
|
||||
|
||||
|
||||
## requester
|
||||
echo ""
|
||||
echo "Who orderd this account? (I'm tracking this for greater good)"
|
||||
read accrequester
|
||||
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
|
||||
|
||||
## set $accport
|
||||
if [ $acctype = "sftp" ]; then
|
||||
|
@ -68,28 +97,33 @@ else
|
|||
accport="21"
|
||||
fi
|
||||
|
||||
|
||||
## get timestamp
|
||||
acctimestamp=$(date)
|
||||
acctimestamp=$(date '+%dr%B %Y %H:%M')
|
||||
|
||||
|
||||
## gen password (acpass)
|
||||
accpass=$(pwgen -sync 10 1)
|
||||
|
||||
accpass=$(pwgen -snc 10 1)
|
||||
echo $accpass > pass.txt
|
||||
accencpass=$(makepasswd --clearfrom=pass.txt --crypt-md5 |awk '{print $2}')
|
||||
rm pass.txt
|
||||
|
||||
## 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
|
||||
useradd -d /data -M -U -s /usr/lib/sftp-server -p $accencpass $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
|
||||
useradd -d $accpath/$acctype"_accounts"/$accname -M -U -s /bin/false -p $accencpass $accname
|
||||
chown -R $accname\: $accpath/$acctype"_accounts"/$accname
|
||||
adduser $accname $ftpgroup
|
||||
echo $accname >> /etc/vsftpd.user_list
|
||||
fi
|
||||
|
||||
|
||||
## logging (log type, name, pass, quota, requester and timestamp)
|
||||
if [ $logging = 1 ]; then
|
||||
if [ -e $logpath/$logfile ]; then
|
||||
|
@ -114,14 +148,14 @@ if [ $jabberlog = 1 ]; then
|
|||
a "$acctype" account was just created.
|
||||
Accountname:" $accname "
|
||||
Quota:" $accquota "
|
||||
Requester:" $accrequester | sendxmpp -u $jabberuser -j $jabberserver -p $jabberpass $jabberwatchdogs
|
||||
Requester:" $accrequester | sendxmpp -r ftpcreation -u $jabberuser -j $jabberserver -p $jabberpass $jabberwatchdogs
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
|
||||
|
||||
## account data output
|
||||
clear
|
||||
#clear
|
||||
echo ""
|
||||
echo "Account data"
|
||||
echo ""
|
||||
|
@ -135,3 +169,5 @@ echo "Requester:" $accrequester
|
|||
echo ""
|
||||
echo "Everything is done"
|
||||
|
||||
exit 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue