commit 21a35cb8e2a2ea80460dfa37f04a0d8abb2cefae Author: mifi Date: Wed Jul 23 21:33:16 2025 -0300 first commit diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..9f22e92 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,34 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: build-and-push + image: plugins/docker + settings: + repo: registry.your-gitea.com/your-org/mail-autoconfig + tags: latest + username: + from_secret: GITEA_USERNAME + password: + from_secret: GITEA_TOKEN + + - name: deploy-to-portainer + image: curlimages/curl:7.85.0 + environment: + PORTAINER_URL: https://portainer.mail.mifi.holdings + PORTAINER_API_KEY: + from_secret: PORTAINER_API_KEY + ENDPOINT_ID: + from_secret: PORTAINER_ENDPOINT_ID # e.g. "1" + STACK_ID: + from_secret: PORTAINER_STACK_ID # the ID of your mailconfig stack + commands: + - > + curl -s -X POST "$PORTAINER_URL/api/stacks/$STACK_ID/file?endpointId=$ENDPOINT_ID&method=string" + -H "Authorization: Bearer $PORTAINER_API_KEY" + -F "file=@docker-compose.yml" + +trigger: + branch: + - main diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..abc85a6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.11-slim + +WORKDIR /app +COPY app.py templates/ ./ + +RUN pip install --no-cache Flask Jinja2 gunicorn + +# expose port 80 +CMD ["gunicorn", "-b", "0.0.0.0:80", "app:app"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/app.py new file mode 100644 index 0000000..99ca668 --- /dev/null +++ b/app.py @@ -0,0 +1,20 @@ +from flask import Flask, request, Response +import jinja2 + +app = Flask(__name__) +env = jinja2.Environment( + loader=jinja2.FileSystemLoader('templates'), + autoescape=jinja2.select_autoescape(['xml']) +) + +@app.route('/mail/config-v1.1.xml') +def thunderbird_config(): + domain = request.host.split('.', 1)[1] + xml = env.get_template('config-v1.1.xml.j2').render(DOMAIN=domain) + return Response(xml, mimetype='application/xml') + +@app.route('/Autodiscover/Autodiscover.xml', methods=['POST','GET']) +def outlook_autodiscover(): + domain = request.host.split('.', 1)[1] + xml = env.get_template('Autodiscover.xml.j2').render(DOMAIN=domain) + return Response(xml, mimetype='text/xml') diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9bca358 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.7" + +services: + mail-autoconfig: + image: git.mifi.dev/mifi-holdings/mail-autoconfig:latest + networks: + - traefik + labels: + - "traefik.enable=true" + - "traefik.http.routers.mailconfig.rule=HostRegexp(`{sub:autoconfig|autodiscover}.{domain:.+}`)" + - "traefik.http.routers.mailconfig.entrypoints=websecure" + - "traefik.http.routers.mailconfig.tls.certresolver=letsencrypt" + - "traefik.http.services.mailconfig.loadbalancer.server.port=80" + +networks: + traefik: + external: true diff --git a/templates/Autodiscover.xml.j2 b/templates/Autodiscover.xml.j2 new file mode 100644 index 0000000..4deb475 --- /dev/null +++ b/templates/Autodiscover.xml.j2 @@ -0,0 +1,29 @@ + + + + + imap + settings + + IMAP + mail.mifi.holdings + 993 + off + on + off + on + %EMAILADDRESS% + + + SMTP + mail.mifi.holdings + 587 + off + on + off + on + %EMAILADDRESS% + + + + diff --git a/templates/config-v1.1.xml.j2 b/templates/config-v1.1.xml.j2 new file mode 100644 index 0000000..507661f --- /dev/null +++ b/templates/config-v1.1.xml.j2 @@ -0,0 +1,20 @@ + + + + {{ DOMAIN }} + + mail.mifi.holdings + 993 + SSL + password-cleartext + %EMAILLOCALPART% + + + mail.mifi.holdings + 587 + STARTTLS + password-cleartext + %EMAILLOCALPART% + + +