#!/bin/bash ############################################ ## ## ## FTP/sFTP Account Creation Script ## ## v0.2 ## ## Author: david@socialnerds.org ## ## ## ############################################ ## script configuration section ## accpath="/media/storage" acchost="some.domain.org" # 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="admin@somedomain.org admin@someotherdomain.org" jabberuser="jabber-account" jabberserver="jabber-server" jabberpass="jabber-account-password" ## 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 "" # just an empty line echo "Welcome to the FTP/sFTP Account Creation Script (v0.2)" ## choose ftp or sftp echo "" 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 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 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 accport="22" else accport="21" fi ## get timestamp acctimestamp=$(date '+%dr%B %Y %H:%M') ## 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 ## 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 $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 $accencpass $accname chown -R $accname\: $accpath/$acctype"_accounts"/$accname 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 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 your FTP/sFTP Server, a "$acctype" account was just created. Accountname:" $accname " Quota:" $accquota " Requester:" $accrequester | sendxmpp -r ftpcreation -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" exit 0