rt 4.2.15
[freeside.git] / rt / devel / tools / rt-apache
index f9942ed..a0473a3 100644 (file)
@@ -4,7 +4,7 @@
 #
 # COPYRIGHT:
 #
-# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
 #                                          <sales@bestpractical.com>
 #
 # (Except where explicitly superseded by other copyright notices)
@@ -77,6 +77,7 @@ GetOptions(  \%opt,
     "port|p=i",
     "ssl:i",
     "single|X",
+    "auth|A:s",
 
     "modules=s",
 
@@ -125,6 +126,21 @@ unless ($opt{port}) {
 # Set ssl port if they want it but didn't provide a number
 $opt{ssl} = 4430 if defined $opt{ssl} and not $opt{ssl};
 
+# Default auth to on if they set $WebRemoteUserAuth
+$opt{auth} = '' if not exists $opt{auth} and parseconf( "WebRemoteUserAuth" );
+
+# Set an auth path if they want it but didn't pass a path
+if (defined $opt{auth} and not $opt{auth}) {
+    $opt{auth} = "$opt{root}/var/htpasswd";
+    unless (-f $opt{auth}) {
+        open(my $fh, ">", $opt{auth}) or die "Can't create default htpasswd: $!";
+        print $fh 'root:$apr1$TZA4Y0DL$DS5ZhDH8QrhB.uAtvNJmh.' . "\n";
+        close $fh or die "Can't create default htpasswd: $!";
+    }
+} elsif ($opt{auth} and not -f $opt{auth}) {
+    die "Can't read htpasswd file $opt{auth}!";
+}
+
 # Parse out the WebPath
 my $path = parseconf( "WebPath" ) || "";
 
@@ -133,6 +149,7 @@ $template =~ s/\$PORT/$opt{port}/g;
 $template =~ s!\$PATH/!$path/!g;
 $template =~ s!\$PATH!$path || "/"!ge;
 $template =~ s/\$SSL/$opt{ssl} || 0/ge;
+$template =~ s/\$AUTH/$opt{auth}/ge;
 $template =~ s/\$RTHOME/$opt{root}/g;
 $template =~ s/\$MODULES/$opt{modules}/g;
 $template =~ s/\$TOOLS/$FindBin::Bin/g;
@@ -227,7 +244,7 @@ environment variable, or C</opt/rt4>.
 Determines the Apache module which is used.  By default, the first one
 of that list which exists will be used.  See also L</--modules>.
 
-=item --port B<number>
+=item --port B<number>, -p
 
 Choses the port to listen on.  By default, this is parsed from the
 F<RT_SiteConfig.pm>, and falling back to 8888.
@@ -238,6 +255,13 @@ Also listens on the provided port with HTTPS, using a self-signed
 certificate for C<localhost>.  If the port number is not specified,
 defaults to port 4430.
 
+=item --auth [F</path/to/htpasswd>], -A
+
+Turns on HTTP Basic Authentication; this is done automatically if
+C<$WebRemoteUserAuth> is set in the F<RT_SiteConfig.pm>.  The provided
+path should be to a F<htpasswd> file; if not given, defaults to a file
+containing only user C<root> with password C<password>.
+
 =item --single, -X
 
 Run only one process or thread, for ease of debugging.
@@ -258,6 +282,29 @@ Defaults to F</usr/lib/apache2/modules>.
 =cut
 
 __DATA__
+Listen $PORT
+<IfDefine SSL>
+   Listen $SSL
+</IfDefine>
+
+ServerName localhost
+ServerRoot $RTHOME/var
+PidFile    $RTHOME/var/apache2.pid
+<IfVersion < 2.4>
+    LockFile   $RTHOME/var/apache2.lock
+</IfVersion>
+ServerAdmin root@localhost
+
+<IfVersion >= 2.4>
+    LoadModule mpm_prefork_module $MODULES/mod_mpm_prefork.so
+    LoadModule authz_core_module $MODULES/mod_authz_core.so
+</IfVersion>
+LoadModule authz_host_module  $MODULES/mod_authz_host.so
+LoadModule env_module         $MODULES/mod_env.so
+LoadModule alias_module       $MODULES/mod_alias.so
+LoadModule mime_module        $MODULES/mod_mime.so
+TypesConfig $TOOLS/mime.types
+
 <IfDefine SINGLE>
     <IfModule mpm_prefork_module>
         StartServers          1
@@ -278,23 +325,6 @@ __DATA__
     </IfModule>
 </IfDefine>
 
-Listen $PORT
-<IfDefine SSL>
-   Listen $SSL
-</IfDefine>
-
-ServerName localhost
-ServerRoot $RTHOME/var
-PidFile    $RTHOME/var/apache2.pid
-LockFile   $RTHOME/var/apache2.lock
-ServerAdmin root@localhost
-
-LoadModule authz_host_module  $MODULES/mod_authz_host.so
-LoadModule env_module         $MODULES/mod_env.so
-LoadModule alias_module       $MODULES/mod_alias.so
-LoadModule mime_module        $MODULES/mod_mime.so
-TypesConfig $TOOLS/mime.types
-
 <IfDefine PERL>
     LoadModule perl_module    $MODULES/mod_perl.so
 </IfDefine>
@@ -306,6 +336,9 @@ TypesConfig $TOOLS/mime.types
 </IfDefine>
 <IfDefine SSL>
     LoadModule ssl_module     $MODULES/mod_ssl.so
+    <IfVersion >= 2.4>
+        LoadModule socache_shmcb_module $MODULES/mod_socache_shmcb.so
+    </IfVersion>
 </IfDefine>
 
 <IfModule !log_config_module>
@@ -341,8 +374,6 @@ Alias $PATH/NoAuth/images/ $RTHOME/share/html/NoAuth/images/
 <IfDefine PERL>
     PerlSetEnv RT_SITE_CONFIG $RTHOME/etc/RT_SiteConfig.pm
     <Location $PATH>
-        Order allow,deny
-        Allow from all
         SetHandler modperl
         PerlResponseHandler Plack::Handler::Apache2
         PerlSetVar psgi_app $RTHOME/sbin/rt-server
@@ -359,8 +390,6 @@ Alias $PATH/NoAuth/images/ $RTHOME/share/html/NoAuth/images/
     FastCgiServer $RTHOME/sbin/rt-server.fcgi -processes $PROCESSES -idle-timeout 300
     ScriptAlias $PATH $RTHOME/sbin/rt-server.fcgi/
     <Location $PATH>
-        Order allow,deny
-        Allow from all
         Options +ExecCGI
         AddHandler fastcgi-script fcgi
     </Location>
@@ -373,8 +402,6 @@ Alias $PATH/NoAuth/images/ $RTHOME/share/html/NoAuth/images/
     FcgidMaxRequestLen 1073741824
     ScriptAlias $PATH $RTHOME/sbin/rt-server.fcgi/
     <Location $PATH>
-        Order allow,deny
-        Allow from all
         Options +ExecCGI
         AddHandler fcgid-script fcgi
     </Location>
@@ -402,10 +429,8 @@ Alias $PATH/NoAuth/images/ $RTHOME/share/html/NoAuth/images/
     FastCgiServer $RTHOME/bin/mason_handler.fcgi -processes $PROCESSES -idle-timeout 300
     ScriptAlias $PATH $RTHOME/bin/mason_handler.fcgi/
     <Location $PATH>
-       Order allow,deny
-       Allow from all
-       Options +ExecCGI
-       AddHandler fastcgi-script fcgi
+        Options +ExecCGI
+        AddHandler fastcgi-script fcgi
     </Location>
 </IfDefine>
 
@@ -416,10 +441,8 @@ Alias $PATH/NoAuth/images/ $RTHOME/share/html/NoAuth/images/
     FcgidMaxRequestLen 1073741824
     ScriptAlias $PATH $RTHOME/bin/mason_handler.fcgi/
     <Location $PATH>
-       Order allow,deny
-       Allow from all
-       Options +ExecCGI
-       AddHandler fcgid-script fcgi
+        Options +ExecCGI
+        AddHandler fcgid-script fcgi
     </Location>
 </IfDefine>
 </IfDefine>
@@ -430,10 +453,12 @@ Alias $PATH/NoAuth/images/ $RTHOME/share/html/NoAuth/images/
     SSLRandomSeed connect builtin
     SSLRandomSeed connect file:/dev/urandom 512
     SSLSessionCache shmcb:$RTHOME/var/ssl_scache(512000)
-    SSLMutex file:$RTHOME/var/ssl_mutex
+    <IfVersion < 2.4>
+        SSLMutex file:$RTHOME/var/ssl_mutex
+    </IfVersion>
     <VirtualHost *:$SSL>
         SSLEngine on
-       SSLCertificateFile    $TOOLS/localhost.crt
-       SSLCertificateKeyFile $TOOLS/localhost.key
+        SSLCertificateFile    $TOOLS/localhost.crt
+        SSLCertificateKeyFile $TOOLS/localhost.key
     </VirtualHost>
 </IfDefine>