13e9c102f86a43bf7beabe2a84d80fc0c886e494
[via-proxy] / add-provider.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use autodie;
5
6 my @domains = @ARGV;
7
8 open(my $fh, '>', "providers/$domains[0].conf");
9
10 print $fh qq{# $0 @domains\n\n};
11
12 foreach my $domain ( @domains ) {
13
14 print $fh qq{
15
16 <VirtualHost *:443>
17         Include /srv/via-proxy/ssl.conf
18
19         ServerName ${domain}.p.vbz.ffzg.hr
20
21         SSLProxyEngine on
22         ProxyAddHeaders Off
23         ProxyPass        / https://${domain}/
24         ProxyPassReverse / https://${domain}/
25
26         Header edit* Set-Cookie "(.*)(?i:; *domain=)([^;]+)(.*)" "\$1 ; domain=\$2.p.vbz.ffzg.hr \$3"
27         #Header edit* Set-Cookie "(.*)(?i:; *secure)" "\$1"
28 };
29
30 foreach ( @domains ) {
31         # for maximum compatibility, they should NOT end with /
32         print $fh qq{\tHeader edit* Location "https://$_" "https://$_.p.vbz.ffzg.hr"\n};
33 }
34
35 print $fh qq{
36         RequestHeader unset Accept-Encoding
37 };
38
39 foreach ( @domains ) {
40         print $fh qq{\tSubstitute "s|https://$_|https://$_.p.vbz.ffzg.hr|"\n};
41 }
42
43 print $fh qq{
44         FilterDeclare NEWPATHS
45         FilterProvider NEWPATHS SUBSTITUTE "%{Content_Type} =~ m|^text/html|"
46         FilterProvider NEWPATHS SUBSTITUTE "%{Content_Type} =~ m|^text/css|"
47         FilterProvider NEWPATHS SUBSTITUTE "%{Content_Type} =~ m|^text/javascript|"
48         FilterProvider NEWPATHS SUBSTITUTE "%{Content_Type} =~ m|^application/javascript|"
49         FilterChain NEWPATHS
50
51         CustomLog /var/log/apache2/access-p.vbz.ffzg.hr.log vhost_combined
52 </VirtualHost>
53 };
54
55 }
56
57 print $fh "\n\n## add domains to SSL certificate:\n";
58 print "## add domains to SSL certificate:\n";
59 foreach ( @domains ) {
60         print $fh qq{# $_.p.vbz.ffzg.hr\n};
61         print qq{$_.p.vbz.ffzg.hr\n};
62 }