# Apache config file for use in <VirtualHost> section to share the standard https port on one server and proxy surgemail 
# end user functionality to a nonstandard surgemail port
# Alternative ways to achieve this include: 
#  - Add second IP address and have apache on IP1:443 and surgemail on IP2:443
#  - Add subdomain (eg webmail.yourdomain.com) and only have single ProxyPass / ProxyPassReverse rule for all urls

  # Use default g_webmail_secure_port port if not explicitly defined 
  <IfDefine  !surgemail_port>
    Define surgemail_port 7443
  </IfDefine>

  <IfDefine !surgemail_protocol>
    <If "'${isurgemail_port}' == '7443'">
      Define surgemail_protocol https
    </If>
    <If "'${isurgemail_port}' == '7080'">
      Define surgemail_protocol http
    </If>
    <IfDefine !surgemail_protocol>
      Define surgemail_protocol https
    </IfDefine>
  </IfDefine>

  Define surgemail_url ${surgemail_protocol}://${surgemail_host}:${surgemail_port}
  
  # Allow all surgeweb functionality
  ProxyPass /surgeweb ${surgemail_url}/surgeweb
  ProxyPassReverse /surgeweb ${surgemail_url}/surgeweb

  # Allow all user.cgi functionality (included in parts of surgeweb ui)
  ProxyPass /cgi/user.cgi ${surgemail_url}/cgi/user.cgi
  ProxyPassReverse /cgi/user.cgi ${surgemail_url}/cgi/user.cgi

  ProxyPass /web ${surgemail_url}/web
  ProxyPassReverse /web ${surgemail_url}/web

  ProxyPass /cgi/viewmsg.cgi ${surgemail_url}/cgi/viewmsg.cgi
  ProxyPassReverse /cgi/viewmsg.cgi ${surgemail_url}/cgi/viewmsg.cgi

  ProxyPass /cgi/report.cgi ${surgemail_url}/cgi/report.cgi
  ProxyPassReverse /cgi/report.cgi ${surgemail_url}/cgi/report.cgi

  # Allow other random URLs
  #ProxyPass /.well-known ${surgemail_url}/.well-known
  #ProxyPassReverse /.well-known ${surgemail_url}/.well-known



