my domain ARGV my new_dir ARGV my template VirtualHost 80 ServerName d

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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";