File:  [LON-CAPA] / doc / loncapafiles / webserver.piml
Revision 1.43.2.11: download - view: text, annotated - select for diffs
Sat Mar 13 00:51:08 2021 UTC (3 years, 1 month ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3
- For 2.11
  Backport 1.57

    1: <!DOCTYPE piml PUBLIC "-//TUX/DTD piml 1.0 Final//EN" 
    2: 	"http://lpml.sourceforge.net/DTD/piml.dtd">
    3: <!-- webserver.piml -->
    4: 
    5: <!-- $Id: webserver.piml,v 1.43.2.11 2021/03/13 00:51:08 raeburn Exp $ -->
    6: 
    7: <!--
    8: 
    9: Copyright Michigan State University Board of Trustees
   10: 
   11: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   12: 
   13: LON-CAPA is free software; you can redistribute it and/or modify
   14: it under the terms of the GNU General Public License as published by
   15: the Free Software Foundation; either version 2 of the License, or
   16: (at your option) any later version.
   17: 
   18: LON-CAPA is distributed in the hope that it will be useful,
   19: but WITHOUT ANY WARRANTY; without even the implied warranty of
   20: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21: GNU General Public License for more details.
   22: 
   23: You should have received a copy of the GNU General Public License
   24: along with LON-CAPA; if not, write to the Free Software
   25: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26: 
   27: /home/httpd/html/adm/gpl.txt
   28: 
   29: http://www.lon-capa.org/
   30: 
   31: -->
   32: 
   33: <!-- Default values must be defined before specific values. -->
   34: <!-- If no 'dist' attribute is specified, then it is always installed. -->
   35: <!-- If 'dist' attribute is set to  'default', then the specification. -->
   36: <!-- is accepted if an alternative distribution is not requested or not -->
   37: <!-- defined. -->
   38: 
   39: <piml>
   40: <targetroot>/</targetroot>
   41: <specialnotices>
   42: <specialnotice>
   43: </specialnotice>
   44: </specialnotices>
   45: <files>
   46: <file>
   47: <target dist='default'>/etc/httpd/conf/httpd.conf</target>
   48: <target dist='suse9.2 suse9.3 sles9'>/etc/httpd/httpd.conf</target>
   49: <target dist='sles10 sles11 sles12 sles15 suse10.1 suse10.2 suse10.3 suse11.1 suse11.2 suse11.3 suse11.4 suse12.1 suse12.2 suse12.3 suse13.1 suse13.2'>/etc/apache2/default-server.conf</target>
   50: <target dist='debian5 debian6 ubuntu6 ubuntu8 ubuntu10 ubuntu12'>/etc/apache2/sites-available/loncapa</target>
   51: <target dist='ubuntu14 ubuntu16 ubuntu18 ubuntu20'>/etc/apache2/conf-available/loncapa.conf</target>
   52: <note>This is for Apache 1.X for Red Hat 4ES, Fedora 2, 3 and 4, SusSE 9.2 and 9.3, and SLES 9 distributions. This is for Apache 2.X for Fedora 5, Red Hat 5, CentOS 5, Scientific Linux 5, Oracle Linux 5, SuSE 10.1, SLES 10, Debian 5, Ubuntu LTS 8 and later distributions</note>
   53: <dependencies dist='default'>
   54: /etc/httpd/conf/httpd.conf
   55: </dependencies>
   56: <dependencies dist='suse9.2 suse9.3 sles9'>
   57: /etc/httpd/httpd.conf
   58: </dependencies>
   59: <dependencies dist='debian5 debian6 ubuntu6 ubuntu8 ubuntu10 ubuntu12'>
   60: /etc/apache2/sites-available/loncapa
   61: </dependencies>
   62: <dependencies dist='ubuntu14 ubuntu16 ubuntu18 ubuntu20'>
   63: /etc/apache2/conf-available/loncapa.conf
   64: </dependencies>
   65: <dependencies dist='sles10 sles11 sles12 sles15 suse10.1 suse10.2 suse10.3 suse11.1 suse11.2 suse11.3 suse11.4 suse12.1 suse12.2 suse12.3 suse13.1 suse13.2'>
   66: /etc/apache2/default-server.conf
   67: </dependencies>
   68: <perlscript mode='fg' dist="default">
   69: # Generated from doc/loncapafiles/webserver.piml
   70: use Socket;
   71: use Sys::Hostname::FQDN();
   72: use File::Spec;
   73: use Cwd();
   74: 
   75: # For ubuntu 14 and later check for loncapa.conf in sites-available,
   76: # and conf-available, and for symlinks in sites-enabled, and conf-enabled
   77: if ('<DIST />' =~ /^ubuntu(\d+)$/) {
   78:     my $version = $1;
   79:     if ($version &gt; 12) {
   80:         if (-l '/etc/apache2/conf-enabled/loncapa.conf') {
   81:             my $linkfname = readlink('/etc/apache2/conf-enabled/loncapa.conf');
   82:             if ($linkfname ne '') {
   83:                 $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,'/etc/apache2/conf-enabled'));
   84:             }
   85:             unless ($linkfname eq '/etc/apache2/conf-available/loncapa.conf') {
   86:                 unlink('/etc/apache2/conf-enabled/loncapa.conf');
   87:             }
   88:         }
   89:         if (-e '/etc/apache2/conf-available/loncapa') {
   90:             system('mv /etc/apache2/conf-available/loncapa /etc/apache2/conf-available/loncapa.conf');
   91:         }
   92:         unless (-l '/etc/apache2/conf-enabled/loncapa.conf') {
   93:             if (-e '/etc/apache2/conf-available/loncapa.conf') {
   94:                 my $currdir = Cwd::getcwd();
   95:                 if ($currdir ne '') {
   96:                     chdir('/etc/apache2/conf-enabled');
   97:                     symlink('../conf-available/loncapa.conf','loncapa.conf');
   98:                     chdir($currdir);
   99:                 }
  100:             }
  101:         }
  102:         if (-l '/etc/apache2/sites-enabled/000-default.conf') {
  103:             my $linkfname = readlink('/etc/apache2/sites-enabled/000-default.conf');
  104:             if ($linkfname ne '') {
  105:                 $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,'/etc/apache2/sites-enabled'));
  106:             }
  107:             if (($linkfname eq '/etc/apache2/sites-available/loncapa') ||
  108:                 ($linkfname eq '/etc/apache2/sites-available/000-default.conf')) {
  109:                 unlink('/etc/apache2/sites-enabled/000-default.conf');
  110:             }
  111:         }
  112:         if (-e '/etc/apache2/sites-available/loncapa') {
  113:             system('mv /etc/apache2/sites-available/loncapa /etc/apache2/sites-available/loncapa.conf');
  114:         }
  115:         if (-l '/etc/apache2/sites-enabled/loncapa.conf') {
  116:             my $linkfname = readlink('/etc/apache2/sites-enabled/loncapa.conf');
  117:             if ($linkfname ne '') {
  118:                 $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,'/etc/apache2/sites-enabled'));
  119:             }
  120:             unless ($linkfname eq '/etc/apache2/sites-available/loncapa.conf') {
  121:                 unlink('/etc/apache2/sites-enabled/loncapa.conf');
  122:             }
  123:         }
  124:         unless (-l '/etc/apache2/sites-enabled/loncapa.conf') {
  125:             if (-e '/etc/apache2/sites-available/loncapa.conf') {
  126:                 my $currdir = Cwd::getcwd();
  127:                 if ($currdir ne '') {
  128:                     chdir('/etc/apache2/sites-enabled');
  129:                     symlink('../sites-available/loncapa.conf','loncapa.conf');
  130:                     chdir($currdir);
  131:                 }
  132:             }
  133:         }
  134:     }
  135: }
  136: 
  137: unless (-e "<TARGET />") {
  138:   print '**** ERROR! <TARGET /> should exist! Are you missing the Apache '.
  139:     'software package?';
  140:   exit(1);
  141: }
  142: else {
  143:   # Append loncapa_apache.conf inclusion to httpd.conf 
  144:   # (or sites-available/loncapa or conf-available/loncapa.conf) if not present.
  145:   $flag=0;
  146:   open(IN,'&lt;<TARGET />');
  147:   while (&lt;IN&gt;) { 
  148:     if (/^\s*Include\s+conf\/loncapa_apache.conf/) {
  149:       $flag=1; 
  150:     }
  151:   }
  152:   close(IN);
  153:   unless ($flag==1) {
  154:     open(OUT,'&gt;&gt;<TARGET />');
  155:     print(OUT 'Include conf/loncapa_apache.conf'."\n");
  156:     close(OUT);
  157:   }
  158:   # Remove loncapa.conf inclusion from httpd.conf 
  159:   # (or sites-available/loncapa or conf-available/loncapa.conf) if present.
  160:   $flag=0;
  161:   open(IN,'&lt;<TARGET />');
  162:   while (&lt;IN&gt;) {
  163:     if (/^\s*Include\s+conf\/loncapa.conf/) {
  164:       $flag=1;
  165:     }
  166:   }
  167:   close(IN);
  168:   $in='';
  169:   if ($flag==1) {
  170:     open(IN,'&lt;<TARGET />');
  171:     while(&lt;IN&gt;) {
  172:       $in.=$_ unless /^\s*Include\s+conf\/loncapa.conf/;
  173:     }
  174:     close(IN);
  175:     open(OUT,'&gt;<TARGET />');
  176:     print(OUT $in."\n");
  177:     close(OUT);
  178:   }
  179: 
  180: # Checking for overlapping ScriptAlias and DocumentRoot definitions.
  181:   $scriptalias_flag=0;
  182:   $documentroot_flag=0;
  183:   my $scriptalias;
  184:   my $documentroot;
  185:   open(IN,'&lt;<TARGET />');
  186:   while (&lt;IN&gt;) {
  187:     if (m!^\s*ScriptAlias\s+/cgi-bin/\s+(.*)$!) {
  188:       $scriptalias = $1;
  189:       if ($scriptalias !~ m!home/httpd/cgi-bin!) {
  190:         $scriptalias_flag = 1;
  191:       }
  192:     }
  193:     if (m!^\s*DocumentRoot\s+(.*)$!) {
  194:       $documentroot = $1;
  195:       if ($documentroot !~ m!home/httpd/html!) {
  196:         $documentroot_flag = 1;
  197:       }
  198:     }
  199:   }
  200:   close(IN);
  201:   if ($scriptalias_flag==1) {
  202:       my $conffile = '/etc/httpd/conf/httpd.conf';
  203:       if ('<DIST />' eq 'suse9.2' || '<DIST />' eq 'suse9.3' 
  204:           || '<DIST />' eq 'sles9') {
  205:           $conffile =  '/etc/httpd/httpd.conf';
  206:       } elsif ('<DIST />' =~ /^(suse|sles)/) {
  207:           $conffile = '/etc/apache2/default-server.conf';
  208:       } elsif ('<DIST />' =~ /^(debian|ubuntu)/) {
  209:           $conffile = '/etc/apache2/sites-available/loncapa';
  210:           if ('<DIST />' =~ /^ubuntu(\d+)$/) {
  211:               my $version = $1;
  212:               if ($version &gt; 12) {
  213:                   $conffile = '/etc/apache2/conf-available/loncapa.conf';
  214:               }
  215:           }
  216:       }
  217:       print('**** ERROR **** '.$conffile.' has an overlapping definition of '.
  218:             'ScriptAlias (it is incorrectly set to '.$scriptalias.').'."\n".
  219:             'This conflicts with loncapa_apache.conf.'."\n");
  220:   }
  221:   if ($documentroot_flag==1) {
  222:       print('**** ERROR **** '.$conffile.' has an overlapping definition of '.
  223:             'DocumentRoot (it is incorrectly set to '.$documentroot.').'."\n".
  224:             'This conflicts with loncapa_apache.conf.'."\n");
  225:   }
  226: 
  227: # Checking for rewrites of http:// to https://
  228:     my $rewrite_dir = '/etc/httpd/conf/rewrites';
  229:     my $curr_rewrite = '/etc/httpd/conf/loncapa_rewrite.conf';
  230:     if ('<DIST />' eq 'suse9.2' || '<DIST />' eq 'suse9.3'
  231:         || '<DIST />' eq 'sles9') {
  232:         $rewrite_dir = '/etc/httpd/rewrites/';
  233:         $curr_rewrite = '/etc/httpd/loncapa_rewrite.conf';
  234:     } elsif ('<DIST />' =~ /^(suse|sles|debian|ubuntu)/) {
  235:         $rewrite_dir = '/etc/apache2/rewrites';
  236:         $curr_rewrite = '/etc/apache2/loncapa_rewrite.conf';
  237:     }
  238:     my $rewrite_off = $rewrite_dir.'/loncapa_rewrite_off.conf';
  239:     my $rewrite_on = $rewrite_dir.'/loncapa_rewrite_on.conf';
  240:     if (!-e $curr_rewrite) { 
  241:         system("cp $rewrite_off $curr_rewrite");
  242:         chmod(0644, $curr_rewrite);
  243:     } else {
  244:         my ($not_rewrite_on,$not_rewrite_off,$rewrite_state);
  245:         if (open(PIPE, "diff --brief $rewrite_off $curr_rewrite |")) {
  246:             my $diffres = &lt;PIPE&gt; ;
  247:             close(PIPE);
  248:             chomp($diffres);
  249:             if ($diffres) {
  250:                 $not_rewrite_off = 1;
  251:             } else {
  252:                 $rewrite_state = 'off';
  253:             }
  254:         }
  255:         if (open(PIPE, "diff --brief $rewrite_on $curr_rewrite |")) {
  256:             my $diffres = &lt;PIPE&gt; ;
  257:             close(PIPE);
  258:             chomp($diffres);
  259:             if ($diffres) {
  260:                 $not_rewrite_on = 1;
  261:             } else {
  262:                 $rewrite_state = 'on';
  263:             }
  264:         }
  265:         if ($not_rewrite_off && $not_rewrite_on) {
  266:             print('**** WARNING **** '."\n".$curr_rewrite.' does not match '.
  267:             'either:'."\n".$rewrite_on.' - the file used to enable rewriting '.
  268:             'of requests for http:// to https:// '."\n".'or:'."\n".$rewrite_off.
  269:             ' - the file used to disable such rewriting'."\n\n".
  270:             'This may be because '. $curr_rewrite.' has been '. 
  271:             'previously customized,'."\n".'or it may be because of a change '.  
  272:             'to the files in '.$rewrite_dir."\n");
  273:             if (open(my $fh,'&lt;',$curr_rewrite)) {
  274:                 while(&lt;$fh&gt;) {
  275:                     if (/^\s*RewriteEngine\s+(on|off)\s*$/i) {
  276:                         if ($1 eq 'on') {
  277:                             $rewrite_state = 'on';
  278:                         } else {
  279:                             $rewrite_state = 'off';
  280:                         }
  281:                         last;
  282:                     }
  283:                 }
  284:             }
  285:         }
  286:         if ($rewrite_state eq 'on') {
  287:         # Checking for rewrites of https:// to http://
  288:             my ($gotrules,$rulestr,$ssldir);
  289:             if ('<DIST />' eq 'suse9.2' || '<DIST />' eq 'suse9.3'
  290:                 || '<DIST />' eq 'sles9') {
  291:                 $ssldir = '/etc/apache/vhosts.d';
  292:             } elsif ('<DIST />' =~ /^(suse|sles)/) {
  293:                 $ssldir = '/etc/apache2/vhosts.d';
  294:             } elsif ('<DIST />' =~ /^(debian|ubuntu)/) {
  295:                 $ssldir = '/etc/apache2/sites-available';
  296:             } else {
  297:                 $ssldir = '/etc/httpd/conf.d';
  298:             }
  299:             my $hostname = Sys::Hostname::FQDN::fqdn();
  300:             my $hostip = Socket::inet_ntoa(scalar(gethostbyname($hostname)) || 'localhost');
  301:             my @expected = ('RewriteEngine on',
  302:                             'RewriteCond %{HTTPS} =on',
  303:                             'RewriteCond %{REQUEST_URI} ^/adm/wrapper/ext/(?!https:)',
  304:                             'RewriteCond %{QUERY_STRING} (^|&(|amp;))usehttp=1($|&)',
  305:                             'RewriteRule ^/adm/wrapper/ext/(?!https:) http://%{HTTP_HOST}%{REQUEST_URI} [R,L,NE]',
  306:                             'RewriteCond %{REMOTE_ADDR} 127.0.0.1',
  307:                             'RewriteRule (.*) - [L]');
  308:             if (($hostip ne '') && ($hostip ne '127.0.0.1')) {
  309:                 push(@expected,('RewriteCond %{REMOTE_ADDR} '.$hostip,
  310:                                 'RewriteRule (.*) - [L]'));
  311:             }
  312:             push(@expected,('RewriteCond %{REQUEST_URI} ^/public/.*/syllabus$',
  313:                             'RewriteCond %{QUERY_STRING} (^|&(|amp;))usehttp=1($|&)',
  314:                             'RewriteRule ^/public/.*/syllabus$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L,NE]'));
  315:             if (-d $ssldir) {
  316:                 my @rewrites;
  317:                 if (opendir(my $dir,$ssldir)) {
  318:                     my @sslconf_files;
  319:                     foreach my $file (grep(!/^\./,readdir($dir))) {
  320:                         next if ($file =~ /\.rpmnew$/);
  321:                         if (open(my $fh,'&lt;',"$ssldir/$file")) {
  322:                             while (&lt;$fh&gt;) {
  323:                                 if (/^\s*&lt;VirtualHost\s+[^:]*\:443&gt;\s*$/) {
  324:                                     push(@sslconf_files,$file);
  325:                                     last;
  326:                                 }
  327:                             }
  328:                             close($fh);
  329:                         }
  330:                     }
  331:                     if (@sslconf_files) {
  332:                         foreach my $file (@sslconf_files) {
  333:                             if (open(my $fh,'&lt;',"$ssldir/$file")) {
  334:                                 my ($rewrite,$num) = (0,0);
  335:                                 while (&lt;$fh&gt;) {
  336:                                     if ($rewrite) {
  337:                                         if (/^\s*&lt;\/IfModule&gt;/) {
  338:                                             $rewrite = 0;
  339:                                             $num ++;
  340:                                         } else {
  341:                                             chomp();
  342:                                             s/^\s+|\s+$//g;
  343:                                             push(@{$rewrites[$num]},$_);
  344:                                         }
  345:                                     } elsif (/^\s*&lt;IfModule\s+mod_rewrite.c&gt;/) {
  346:                                         $rewrite = 1;
  347:                                     }
  348:                                 }
  349:                                 close($fh);
  350:                             }
  351:                         }
  352:                     }
  353:                     closedir($dir);
  354:                 }
  355:                 if (@rewrites) {
  356:                     foreach my $item (@rewrites) {
  357:                         if (ref($item) eq 'ARRAY') {
  358:                             my $found = 0;
  359:                             foreach my $line (@{$item}) {
  360:                                 foreach my $match (@expected) {
  361:                                     if ($match eq $line) {
  362:                                         $found ++;
  363:                                         last;
  364:                                     }
  365:                                 }
  366:                             }
  367:                             if ($found &gt;= scalar(@expected)) {
  368:                                 $gotrules = 1;
  369:                                 last;
  370:                             }
  371:                         }
  372:                     }
  373:                 }
  374:             }
  375:             unless ($gotrules) {
  376:                 print('**** WARNING **** '."\n".$curr_rewrite.' is currently set so rewrites '.
  377:                       'of http to https are enabled for most URLs.'."\n".
  378:                       'Unless your Apache configuration includes Strict-Transport-Security '.
  379:                       '(with max-age > 0), it is recommended to also set rewrites from https to http '.
  380:                       'for specific URLs in a file in '.$ssldir.' by including the following:'."\n".
  381:                       "&lt;IfModule mod_rewrite.c&gt;\n".'  '.
  382:                       join("\n  ",@expected)."\n".
  383:                       "&lt;/IfModule&gt;\n");
  384:             }
  385:         }
  386:     }
  387: }
  388: </perlscript>
  389: </file>
  390: </files>
  391: </piml>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>