my $domain = $ARGV[0];
my $new_dir = $ARGV[1];
my $template = "<VirtualHost *:80>
ServerName ".$domain."
ServerAdmin webmaster@localhost
DocumentRoot /home/anon/".$domain."
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/anon/".$domain.">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
";
#sysopen(FH, "/etc/apache2/sites-available/".$domain, O_CREAT|O_O_RDWR) or die "error: $!";
open(FH, "> /etc/apache2/sites-available/".$domain);
print FH $template;
close(FH);
system("ln /etc/apache2/sites-available/".$domain." /etc/apache2/sites-enabled/".$domain);
if (defined $new_dir && $new_dir == 1) {
system("mkdir ~/".$domain);
}
open(FHOSTS, ">> /etc/hosts");
print FHOSTS "127.0.0.1 ".$domain."\n";
close(FHOSTS);
system("sudo service apache2 restart");
print "Success!\n";