View Single Post
  #2   (View Single Post)  
Old 18th November 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,125
Default

To get you started
Code:
$ cat source1
accounttest.com. IN A 35.45.68.21

$ cat source2
gorilla.org.  IN A 11.22.33.44

$ cat zone2vhost                                             

#!/bin/sh

FILE="$1"

IP=$(awk '/^[^ ]+ +IN +A +/ { print $4 }' <${FILE} )
name=$(awk '/^[^ ]+ +IN +A +/ { print $1 }' <${FILE} )

NAME=$( echo ${name} | sed -e 's!\.$!!' )
#echo $IP
#echo $NAME

cat <<END
<VirtualHost ${IP} >
  ServerName ${NAME} 
  ServerAdmin webmaster@${NAME}
  DocumentRoot /www/docs/${NAME}
  ErrorLog logs/error_${NAME}.log
</VirtualHost>

END

$ for FILE in source1 source2 ; do zone2vhost ${FILE} ; done 

<VirtualHost 35.45.68.21 >
  ServerName accounttest.com 
  ServerAdmin webmaster@accounttest.com
  DocumentRoot /www/docs/accounttest.com
  ErrorLog logs/error_accounttest.com.log
</VirtualHost>

<VirtualHost 11.22.33.44 >
  ServerName gorilla.org 
  ServerAdmin webmaster@gorilla.org
  DocumentRoot /www/docs/gorilla.org
  ErrorLog logs/error_gorilla.org.log
</VirtualHost>
There is a slight problem if there are more IN A records in a file, or when the delimiters are not spaces but tabs

Actually it would be better to first extract all IN A records into a separate file. After the file has been checked for sanity, then process it.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump

Last edited by J65nko; 18th November 2008 at 09:30 PM. Reason: Hint at problems and possible solution
Reply With Quote