# AnvilTermOffice Document Server — ONLYOFFICE Docs with baked-in branding.
#
# Build:  docker build -t anviltermoffice/documentserver docker/
# Run:    docker run -d --name onlyoffice --net=host -e JWT_ENABLED=false \
#           anviltermoffice/documentserver
#
# After upgrading the base image tag, bump OO_BRAND_REV in doceditor/server.py
# so browsers refetch the rebranded assets.
FROM onlyoffice/documentserver:latest

ENV WEBAPPS=/var/www/onlyoffice/documentserver/web-apps/apps

# The engine is a local companion (JWT off): the DS must be allowed to fetch
# documents from host-local addresses. On mac/win Docker Desktop that is
# host.docker.internal, which resolves to a "meta" IP that the bundled
# request-filtering-agent rejects by default (SSRF guard — irrelevant here).
RUN python3 -c "import json; p='/etc/onlyoffice/documentserver/local.json'; c=json.load(open(p)); co=c.setdefault('services',{}).setdefault('CoAuthoring',{}); co['request-filtering-agent']={'allowPrivateIPAddress':True,'allowMetaIPAddress':True}; json.dump(c,open(p,'w'),indent=2)"

COPY header-logo_s.svg dark-logo_s.svg $WEBAPPS/common/main/resources/img/header/

RUN set -e; \
    cd $WEBAPPS/common/main/resources/img/header && \
    gzip -kf9 header-logo_s.svg dark-logo_s.svg && \
    RULE='#header-logo{pointer-events:none}#header-logo i{width:140px!important;min-width:140px}.box-tabs .extra.left{flex-shrink:0}'; \
    for ed in presentationeditor documenteditor spreadsheeteditor pdfeditor visioeditor; do \
      CSS=$WEBAPPS/$ed/main/resources/css/app.css; \
      [ -f "$CSS" ] || continue; \
      printf '\n/*AnvilTermOffice-brand*/%s\n' "$RULE" >> "$CSS"; \
      gzip -kf9 "$CSS"; \
    done
