#
# 28nextcloud in Virtualhosts
#

{
   return "# nextcloud disabled\n" unless ((${'nextcloud'}{'status'} || 'disabled') eq 'enabled' );
   return "# nextcloud alias disabled\n" unless (($nextcloud{'AliasOnPrimary'} || 'enabled') eq 'enabled') ;

   my $CloudDomain = $nextcloud{'VirtualHost'} || 'none';#using CloudDomain, not to confuse for the template virtualHost variable
   $OUT = ''; 
   if (($port eq "80") && ($haveSSL eq 'yes'))
   {
      $OUT .= "    RewriteRule ^/nextcloud(/.*|\$)    https://%{HTTP_HOST}/nextcloud\$1 [L,R=301]\n";
   }
   else
   {
      $OUT .= " 
    Alias /nextcloud /usr/share/nextcloud
    RewriteEngine on
    RewriteRule ^/\\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
    RewriteRule ^/\\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
    #RewriteRule ^/\\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
    RewriteRule ^/\\.well-known/webfinger /nextcloud/index.php/.well-known/webfinger [R=301,L]
    RewriteRule ^/\\.well-known/nodeinfo /nextcloud/index.php/.well-known/nodeinfo [R=301,L]
    RewriteRule ^/\\.well-known/carddav /nextcloud/remote.php/dav [R=301,L]
    RewriteRule ^/\\.well-known/caldav /nextcloud/remote.php/dav [R=301,L]
    RewriteRule ^/remote.php/dav /nextcloud/remote.php/dav [R=301,L]
    RewriteRule ^ocm-provider/?\$ /nextcloud/index.php [QSA,L]
    RewriteRule ^ocs-provider/?\$ /nextcloud/index.php [QSA,L]
    # notify_push app
    ProxyPass /nextcloud/push/ws ws://127.0.0.1:7867/ws
    ProxyPass /nextcloud/push/ http://127.0.0.1:7867/
    ProxyPassReverse /nextcloud/push/ http://127.0.0.1:7867/\n";
   }
}

