<IfModule mod_ssl.c>
<VirtualHost *:443>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com

ServerName openmodelica.org
ServerAlias hugo.openmodelica.org
ServerAlias www.openmodelica.org

	ServerAdmin webmaster@openmodelica.org
	DocumentRoot /var/www/hugo.openmodelica.org

<Directory /var/www/hugo.openmodelica.org>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/openmodelica.org/

<Directory "/usr/lib/cgi-bin/openmodelica.org/">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    AddHandler cgi-script .cgi .pl .py
    Order allow,deny
    Allow from all
    SSLOptions +StdEnvVars
    AuthType basic
    <Files git-mirror.pl>
      Require all granted
    </Files>
</Directory>

Alias /doc /var/www/openmodelica.org-documentation
Alias /images/docs /var/www/2022-openmodelica.org-archived-files/docs
Alias /images/documents /var/www/2022-openmodelica.org-archived-files/documents
Alias /images/M_images /var/www/2022-openmodelica.org-archived-files/M_images
Alias /images/videos /var/www/2022-openmodelica.org-archived-files/videos
Alias /forum /var/www/2022-openmodelica.org-archived-files/forum
Alias /eoolt /var/www/2022-openmodelica.org-archived-files/eoolt

<Directory /var/www/2022-openmodelica.org-archived-files>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
ScriptAlias /git-readonly/ /usr/lib/git-core/git-http-backend/

<Directory "/usr/lib/git-core*">
    Options +ExecCgi +Indexes +SymLinksIfOwnerMatch
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/git>
  Options -Indexes +FollowSymLinks +MultiViews +ExecCGI
  AllowOverride None
  Require all granted
  #Order allow,deny
  #allow from all
  Dav on
</Directory>

<Directory /var/www/git-readonly>
  Options -Indexes +FollowSymLinks +MultiViews +ExecCGI
  AllowOverride None
  Require all granted
  Dav on
</Directory>

<Location "/git">
  SSLRequireSSL
  SetEnv GIT_PROJECT_ROOT /var/www/git
  SetEnv GIT_HTTP_EXPORT_ALL
  SetEnv REMOTE_USER $REDIRECT_REMOTE_USER
</Location>

<Location "/git-readonly">
  SSLRequireSSL
  SetEnv GIT_PROJECT_ROOT /var/www/git-readonly
  SetEnv GIT_HTTP_EXPORT_ALL
  SetEnv REMOTE_USER $REDIRECT_REMOTE_USER
</Location>

<LocationMatch "^/git/">
  #  Write access
  Order Deny,Allow
  Deny from env=AUTHREQUIRED
  Options +FollowSymLinks +ExecCGI
  SSLRequireSSL
  AuthType Basic
  AuthName "OpenModelica git repository"
  Require valid-user
  AddHandler cgi-script # .cgi
  Satisfy any
</LocationMatch>

<LocationMatch "^/git-readonly/">
  # No write access
  Allow from all
  Options +FollowSymLinks +ExecCGI
  SSLRequireSSL
  AddHandler cgi-script # .cgi
  Satisfy any
</LocationMatch>

RewriteEngine On

RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]

RewriteCond %{REQUEST_URI} ^/index.php [NC]
RewriteCond %{QUERY_STRING} ^option=com_content&view=category&id=23.*
RewriteRule (.*)  /tags/news/index.xml? [PT]

RewriteCond %{SERVER_NAME} =hugo.openmodelica.org [OR]
RewriteCond %{SERVER_NAME} =www.openmodelica.org

RewriteRule (.*)  https://openmodelica.org%{REQUEST_URI}


	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/openmodelica.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/openmodelica.org/privkey.pem
</VirtualHost>
</IfModule>
