#!/bin/bash
#########################################################
#####웹호스팅사용자 셋팅스크립트: AutoMaster V 1.0
######################################################
# 1. 제작자 #
# - 이름 : 박성수 #
# - Email : master at superuser.co.kr #
# 2. 저작권 #
# ; 이 프로그램의 저작권은 위의 제작자(박성수)에게 #
# 있으며, 어떠한 경우라도 이 프로그램의 일부분 #
# 또는 전부를 제작자의 서면허락없이 사용하는 것을 #
# 금합니다. 제작자의 허락없이 이 프로그램을 사용할 #
# 시에는 허락을 득하지아니한채 사용한 자에게 #
# 법적인 책임이 있음을 알려드립니다. #
# #
# Date : 2000년 8월 31일 #
# #
# 업그레이드할 것.. #
# 1. 홈페이지 초기파일 (index.html) 사용자별 복사기능 #
#########################################################
# from V0.1 to V0.3 upgrade
# - DNS zone파일 자동생성기능
# - accesswatch 환경파일 자동생성기능
# from V0.30 to V0.31 upgrade (2000.10.22)
# - User Counter datafile 자동생성기능
# from V0.31 to V0.32 upgrade (2000.10.31)
# - /usr/local/aw/cfg/에 생성되는 사용자환경설정파일 버거수정
# from V0.32 to V0.4 upgrade (2000.11.1)
# - /etc/mail/virtusertable에 가상메일등록
# - /etc/mail/relay-domains에 relay허용설정
# from V0.4 to V0.7 upgrade (2000.11.1)
# - 게시판자동생성기능 입력(niceboard)
# from V0.7 to V0.9 upgrade (2000.11.1)
# - 방명록 자동생성기능 입력(nicebook)
# from V0.9 to V1.0 upgrade (2000.11.2)
# - 웹로그접속제한기능 (관리자기능)
#######################################################
# 변수선언
export hostip_address="211.174.58.43"
export name_server="ns.superuser.co.kr"
#임시파일 삭제
rm -f /tmp/httpd.conf_tempfile
rm -f /tmp/named.conf_tempfile
rm -f /tmp/zone_tempfile
rm -f /tmp/logfile_tempfile
rm -f /tmp/aw.cfg_tempfile
#임시파일 생성
touch /tmp/httpd.conf_tempfile
touch /tmp/named.conf_tempfile
touch /tmp/zone_tempfile
touch /tmp/logfile_tempfile
touch /tmp/aw.cfg_tempfile
#사용자생성및 패스워드 설정
/usr/sbin/useradd -m -s /bin/bash -d /home/$1 -g webhost $1
echo " Please input mysql Administrator's passwd"
passwd $1
#용량설정
edquota -u $1
#홈페이지디렉토리생성및 설정
chmod 701 /home/$1
# 홈디렉토리(/home/user)를 701로 설정하는 것이 좋다.
# 다른 일반사용자들은 cd 명령어로 들어올 수 없으며
# Apache(httpd)로 홈페이지는 보여줄수 있다.
# 디렉토리에서 rwx 의 x는 cd 가능을 의미하며,
# r은 들어와서 ls가능을 의미한다.
mkdir /home/$1/www
chmod 705 /home/$1/www
chown $1:webhost /home/$1/www
mkdir /home/$1/www/weblog
chmod 705 /home/$1/www/weblog
chown $1:webhost /home/$1/www/weblog
#고객의 접속통계를고객의 관리자만이 볼수 있도록 접근제한을 설정한다.
touch /home/$1/www/weblog/.htaccess
echo "AuthName "$2 Administrator"" >> /home/$1/www/weblog/.htaccess
echo "AuthType Basic" >> /home/$1/www/weblog/.htaccess
echo "AuthUserFile /home/$1/www/weblog/.htpasswd" >> /home/$1/www/weblog/.htaccess
echo "AuthGroupFile /dev/null" >> /home/$1/www/weblog/.htaccess
echo "<Limit GET POST>" >> /home/$1/www/weblog/.htaccess
echo "require valid-user" >> /home/$1/www/weblog/.htaccess
echo "</Limit>" >> /home/$1/www/weblog/.htaccess
echo " Please input Administrator's passwd"
htpasswd -c /home/$1/www/weblog/.htpasswd $1
cp /sbin/index.html /home/$1/www/index.html
chmod 755 /home/$1/www/index.html
chown $1:webhost /home/$1/www/index.html
mkdir /home/$1/www/cgi-bin
chmod 755 /home/$1/www/cgi-bin
chown $1:webhost /home/$1/www/cgi-bin
mkdir /home/$1/www_log
chmod 705 /home/$1/www_log
chown $1:webhost /home/$1/www_log
#가상호스트설정
#vi /usr/local/apache/conf/httpd.conf
echo "<VirtualHost $hostip_address>" >> /tmp/httpd.conf_tempfile
echo " ServerAdmin $1@$2" >> /tmp/httpd.conf_tempfile
echo " DocumentRoot /home/$1/www" >> /tmp/httpd.conf_tempfile
echo " ServerName www.$2" >> /tmp/httpd.conf_tempfile
echo " ErrorLog /home/$1/www_log/error_log" >> /tmp/httpd.conf_tempfile
echo " CustomLog /home/$1/www_log/access_log common" >> /tmp/httpd.conf_tempfile
echo "</VirtualHost>" >> /tmp/httpd.conf_tempfile
cat /tmp/httpd.conf_tempfile >> /usr/local/apache/conf/httpd.conf
#도메인설정
#vi /etc/named.conf
echo "zone "$2" {" >> /tmp/named.conf_tempfile
echo " type master;" >> /tmp/named.conf_tempfile
echo " file "$2.zone";" >> /tmp/named.conf_tempfile
echo "};" >> /tmp/named.conf_tempfile
cat /tmp/named.conf_tempfile >> /etc/named.conf
#cp /var/named/default.zone /var/named/$2.zone
#vi /var/named/$2.zone
#/var/named/domain.zone파일 생성
#echo "@ IN SOA www.$2. $1.$2. (" >> /tmp/zone_tempfile
#SOA 바로위의 도메인을 ns.superuser.co.kr로 수정함.
echo "@ IN SOA ns.superuser.co.kr. $1.$2. (" >> /tmp/zone_tempfile
echo " 20000402 ; Serial" >> /tmp/zone_tempfile
echo " 21600 ; Refresh(6h)" >> /tmp/zone_tempfile
echo " 900 ; Retry(15min)" >> /tmp/zone_tempfile
echo " 604800 ; Expire(7d)" >> /tmp/zone_tempfile
echo " 43200) ; Minimum(12h);" >> /tmp/zone_tempfile
echo " IN NS $name_server." >> /tmp/zone_tempfile
echo ";" >> /tmp/zone_tempfile
echo " IN A $hostip_address" >> /tmp/zone_tempfile
echo " IN MX 0 $2." >> /tmp/zone_tempfile
echo "www IN A $hostip_address" >> /tmp/zone_tempfile
echo " IN MX 0 $2." >> /tmp/zone_tempfile
cp /tmp/zone_tempfile /var/named/$2.zone
#메일설정(SMTP)
#vi /etc/sendmail.cw
echo $2 >> /etc/sendmail.cw
echo $2 >> /etc/mail/relay-domains
echo "webmaster@$2 $1" >> /etc/mail/virtusertable
#로그분석설정
#vi /usr/local/aw/accesswatch-start
#accesswatch-start파일에 사용자의 로그분석 시작스크립트 입력
echo "$2로그분석중입니다." >> /tmp/logfile_tempfile
echo "/usr/local/aw/aw-parser.pl -c /usr/local/aw/cfg/$2.cfg" >> /tmp/logfile_tempfile
echo "/usr/local/aw/aw-report.pl -c /usr/local/aw/cfg/$2.cfg" >> /tmp/logfile_tempfile
cat /tmp/logfile_tempfile >> /usr/local/aw/accesswatch-start
#/usr/local/aw/cfg디렉토리에 사용자의 로그분석환경설정파일 작성
#cp /usr/local/aw/cfg/default.cfg /usr/local/aw/cfg/$2.cfg
#vi /usr/local/aw/cfg/$2.cfg
echo "###############################################################################" >> /tmp/aw.cfg_tempfile
echo "##### Accesswatch Config File Setup #####" >> /tmp/aw.cfg_tempfile
echo "###############################################################################" >> /tmp/aw.cfg_tempfile
echo "$accessLog = "/home/$1/www_log/access_log";" >> /tmp/aw.cfg_tempfile
echo "$DNSlookups = 0;" >> /tmp/aw.cfg_tempfile
echo "$defaultPage = "index.html";" >> /tmp/aw.cfg_tempfile
echo "$includeURL = ".*";" >> /tmp/aw.cfg_tempfile
echo "$compressdata = 1;" >> /tmp/aw.cfg_tempfile
echo "$compresscommand = "gzip -9fc";" >> /tmp/aw.cfg_tempfile
echo "$catcompresscommand = "gunzip -c";" >> /tmp/aw.cfg_tempfile
echo "$compresssuffix = "gz";" >> /tmp/aw.cfg_tempfile
echo "$excludeURL = ".gif|.jpg|.jpeg|.xbm";" >> /tmp/aw.cfg_tempfile
echo "$reportBase = "/home/$1/www/weblog";" >> /tmp/aw.cfg_tempfile
echo "$siteName = "www.$2";" >> /tmp/aw.cfg_tempfile
echo "$siteBaseURL = "http://www.$2";" >> /tmp/aw.cfg_tempfile
echo "$orgname = "www.$2";" >> /tmp/aw.cfg_tempfile
echo "$orgdomain = "$2";" >> /tmp/aw.cfg_tempfile
echo "$excludeHosts = "";" >> /tmp/aw.cfg_tempfile
echo "###############################################################################" >> /tmp/aw.cfg_tempfile
echo "##### Program Options #####" >> /tmp/aw.cfg_tempfile
echo "###############################################################################" >> /tmp/aw.cfg_tempfile
echo "$maxPagesToList = -1;" >> /tmp/aw.cfg_tempfile
echo "$maxDomainsToList = -1;" >> /tmp/aw.cfg_tempfile
echo "$maxHostsToList = 15;" >> /tmp/aw.cfg_tempfile
echo "$maxRefsToList = 10;" >> /tmp/aw.cfg_tempfile
echo "$maxAgentsToList = 15;" >> /tmp/aw.cfg_tempfile
echo "$customFooter = <<EOM;" >> /tmp/aw.cfg_tempfile
echo "<!-- START custom footer -->" >> /tmp/aw.cfg_tempfile
echo "$2" >> /tmp/aw.cfg_tempfile
echo "<!-- END custom footer -->" >> /tmp/aw.cfg_tempfile
echo "EOM" >> /tmp/aw.cfg_tempfile
echo "1;" >> /tmp/aw.cfg_tempfile
echo "###############################################################################" >> /tmp/aw.cfg_tempfile
echo "########### End - AccessWatch Custom Configuration ############################" >> /tmp/aw.cfg_tempfile
echo "###############################################################################" >> /tmp/aw.cfg_tempfile
cp /tmp/aw.cfg_tempfile /usr/local/aw/cfg/$2.cfg
#User Counter datafile Setting (Version 0.31 upgrade)
touch /usr/local/apache/Counter/data/$1.dat
chmod 644 /usr/local/apache/Counter/data/$1.dat
chown nobody:webhost /usr/local/apache/Counter/data/$1.dat
cat /usr/local/apache/Counter/data/counter_default_digit.dat >> $1.dat
#고객의 게시판을 생성한다.
#게시판 작업1 게시판파일을 복사하고 권한및 파일수정을 한다.
cd /home/nice/www/
cp -r niceboard /home/$1/www/niceboard/
cd /home/$1/www/
chown -R $1:webhost niceboard
cd /home/$1/www/niceboard/
mv nice.gif $1.gif
mv nice_icon $1_icon
mv nice.cfg $1.cfg
vi auth.inc
vi dbconn.inc
vi $1.cfg
#게시판 작업2 mysql데이터베이스에 사용자에게 필요한 DB작업을 실행한다.
cd /usr/local/mysql/bin/
vi niceboard-create.sql
vi niceboard-create2.sql
mysql -u root -p niceboard < niceboard-create.sql
mysql -u root -p mysql < niceboard-create2.sql
#고객의 방명록을 생성한다.
#방명록작업1 방명록파일을 복사하고 권한및 파일을 수정한다.
cd /home/nice/www/
cp -r nicebook /home/$1/www/
cd /home/$1/www/
chown -R $1:webhost nicebook
mv nice.cfg $1.cfg
mv nice.gif $1.gif
mv nice_icon $1_icon
cd /home/$1/www/nicebook/
vi auth.inc
vi dbconn.inc
vi $1.cfg
#방명록작업2 mysql데이터베이스에 사용자에게 필요한 DB작업을 실행한다.
cd /usr/local/mysql/bin/
vi nicebook-create.sql
mysql -u root -p GUESTBOOK < nicebook-create.sql
#게시판 방명록 적용작업mysql reload
echo " Please input mysql Administrator's passwd"
./mysqladmin -u root -p reload
#변수 선언 해제(메모리에서 할당해제)
unset hostip_address
unset name_server
# 관련서버 restart
/etc/rc.d/init.d/named restart
/usr/local/apache/bin/apachectl restart
#메일설정 적용을위한 메일관련DB작업
makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable