
##
## HTTP server setup
##

yum -y install httpd

rm -f /etc/httpd/conf.d/welcome.conf
rm -f /var/www/error/noindex.html
ln -s /usr/bin/perl /usr/local/bin/perl

if [ ! -f /etc/httpd/conf/httpd.conf.orig ]; then
	cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.orig
fi

sed -i 's%ServerTokens\ OS%ServerTokens\ Prod%' /etc/httpd/conf/httpd.conf
sed -i 's%KeepAlive Off%KeepAlive On%' /etc/httpd/conf/httpd.conf
sed -i 's%ServerAdmin\ root@localhost%ServerAdmin\ root@$full_hostname%' /etc/httpd/conf/httpd.conf
sed -i 's%#ServerName\ www.example.com:80%ServerName\ www.$full_hostname%' /etc/httpd/conf/httpd.conf
sed -i 's%Options\ Indexes\ FollowSymLinks%Options\ FollowSymLinks\ ExecCGI%' /etc/httpd/conf/httpd.conf
sed -i 's%AllowOverride\ None%AllowOverride\ All%' /etc/httpd/conf/httpd.conf
sed -i 's%DirectoryIndex\ index.html\ index.html.var%DirectoryIndex\ index.html\ index.cgi\ index.php%' /etc/httpd/conf/httpd.conf
sed -i 's%ServerSignature On%ServerSignature Off%' /etc/httpd/conf/httpd.conf
sed -i 's%AddDefaultCharset\ UTF-8%#AddDefaultCharset\ UTF-8%' /etc/httpd/conf/httpd.conf
sed -i 's%#AddHandler\ cgi-script\ .cgi%AddHandler\ cgi-script\ .cgi\ .pl%' /etc/httpd/conf/httpd.conf

# Allow www thru the firewall.
if [ ! `iptables-save | grep -- "--dport 80 -j ACCEPT" | awk '{print $1}'` ];then
iptables -I INPUT $INSRTLINE -m state --state NEW -p tcp --dport 80 -j ACCEPT 
fi 

if [ ! `iptables-save | grep -- "--dport 443 -j ACCEPT" |  awk '{print $1}'` ];then
    iptables -I INPUT $INSRTLINE -m state --state NEW -p tcp --dport 443 -j ACCEPT 
fi

/etc/rc.d/init.d/httpd restart
chkconfig httpd on

 ./auto-append-line  "Alias /centos6 /var/pxe/centos6" /etc/httpd/conf.d/pxeboot.conf nocomment
 ./auto-append-line  "<Directory /var/pxe/centos6>" /etc/httpd/conf.d/pxeboot.conf nocomment
 ./auto-append-line  "  Options Indexes FollowSymLinks" /etc/httpd/conf.d/pxeboot.conf nocomment
 ./auto-append-line  "  Order Deny,Allow" /etc/httpd/conf.d/pxeboot.conf nocomment
 ./auto-append-line  "  Deny from all" /etc/httpd/conf.d/pxeboot.conf nocomment
 ./auto-append-line  "  Allow from 127.0.0.1 $SUBNET/24" /etc/httpd/conf.d/pxeboot.conf nocomment
 ./auto-append-line  "</Directory>" /etc/httpd/conf.d/pxeboot.conf nocomment

if [ ! -f /etc/httpd/conf.d/pxeboot.conf.bak ]; then
	cp /etc/httpd/conf.d/pxeboot.conf /etc/httpd/conf.d/pxeboot.conf.bak
fi

/etc/rc.d/init.d/httpd restart



##
## Create Post-install of Kickstart 
##

# If the head node has several private_iface's, then there will be several "network" lines in $ksconfig  
# The sed substitutions will make them all identical and consecutive, so uniq the file. 
cat $ksconfig | uniq > $ksconfig.uniq
mv $ksconfig.uniq $ksconfig


