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('/')
def index():
subdomain = request.host.split('.', 1)[0]
domain = request.host.split('.', 1)[1] if '.' in request.host else request.host
base_html = """
{title}
"""
if subdomain == 'autoconfig':
return base_html.format(
title="Mail Autoconfig Service",
service_type="Mozilla Thunderbird",
icon="🔧",
domain=domain,
content=f'''
'''
)
elif subdomain == 'autodiscover':
return base_html.format(
title="Mail Autodiscover Service",
service_type="Microsoft Outlook",
icon="🔍",
domain=domain,
content=f'''
'''
)
else:
return base_html.format(
title="Mail Configuration Service",
service_type="Error",
icon="❌",
domain="Invalid",
content='''
Invalid subdomain!
Please use autoconfig.domain.com or autodiscover.domain.com
'''
), 400
@app.route('/ping')
def ping():
return "✅ Mail Autoconfig Service is running."
@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')