#!/usr/local/bin/bash # # add-mrtg-user # # scripts adds a user to the mrtg scripts, updates their particular page # with the proper bandwidth quota, and sets their quota and adds them to /etc/ftpchroot # # WHAT IS IT FOR? # --------------- # this script is for running immediately after you add a user. # it takes the hassle out of setting up all these things. # right after you add a user, say "someuser" you run this: # # bash# ./add-mrtg-user someuser 2 silver # # this will: # - add 'someuser' to the mrtg scripts to be run every ten minutes # - add ipfw rules for 'someuser' so that mrtg can get data from somewhere # - add traffic pages for user 'someuser' with their specific bandwidth quota # - create their quotas based on prototype users (bronze, silver, etc.) # - add the user to /etc/ftpchroot # # # Zoidial Incorporated # Eric Thern eric(at)zoidial.com # # v0.1 February, 2003 -- initial # v0.2 May, 2003 -- added updated traffic pages, added prototype user quota support # v0.3 July, 2003 -- added /etc/ftpchroot # # # if [ -d /home/$1/traffic ] then echo "user already set up for mrtg accounting" else if test "$1" = '' then echo "Please enter a username to add." else if test "$2" = '' then echo "Please enter a bandwidth (in gigabytes). For example: 2" else if test "$3" = '' then echo "Please enter an account type. (bronze,silver,gold,platinum)" else ### # chmod their home dir # chmod 711 /home/$1 ### # make the directory # mkdir /home/$1/public_html chown $1:$1 /home/$1/public_html mkdir /home/$1/public_html/traffic ### # copy the billing script over # cp /root/mrtg/index2.php /home/$1/public_html/traffic/ # add the right bandwidth amount to the billing script # sed -e "s/BANDWIDTHGOESHERE/$2/" /root/mrtg/index.php > //home/$1/public_html/traffic/index.php ### # add the user to the template, add template to mrtg-users.cfg # sed -e "s/USER/$1/" template-users > /root/mrtg/mrtg-users/$1.cfg ### # add firewall rules for user # /sbin/ipfw add 00002 count ip from any to any uid $1 in /sbin/ipfw add 00002 count ip from any to any uid $1 out ### # # #echo "AuthType Basic #AuthName user_bandwidth_accounting #require user $1" > /home/$1/public_html/traffic/.htaccess ### # set up userquota # edquota -p $3 $1 ### # add user to /etc/ftpchroot in order to chroot them when they use ftp # echo $1 >> /etc/ftpchroot fi fi fi fi