Skip to content

Commit acd140b

Browse files
hotfix for nuke accounts, email sending if available with creating domain and multi domain fix for webmail domain hostname
1 parent 9642234 commit acd140b

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

dockflare/app/core/email_manager.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ def enable_email_routing(zone_id):
6060
logging.error(f"Error enabling email routing: {e}")
6161
raise
6262

63+
def enable_email_sending(zone_id, zone_name):
64+
try:
65+
subdomain = f"mail.{zone_name}"
66+
res = cf_api_request('POST', f'/zones/{zone_id}/email/sending/subdomains', data={"name": subdomain})
67+
logging.info(f"Email sending enabled for {zone_name} (subdomain: {subdomain})")
68+
return res
69+
except Exception as e:
70+
err_str = str(e)
71+
if 'already exists' in err_str.lower() or '2004' in err_str or 'duplicate' in err_str.lower():
72+
logging.info(f"Email sending subdomain already exists for {zone_name}, continuing")
73+
return {}
74+
logging.warning(f"Could not enable email sending for {zone_name} (may require manual activation in CF Dashboard): {e}")
75+
return None
76+
6377
def get_email_routing_status(zone_id):
6478
try:
6579
res = cf_api_request('GET', f'/zones/{zone_id}/email/routing')
@@ -176,11 +190,13 @@ def create_r2_bucket(bucket_name):
176190
raise
177191

178192
def get_r2_s3_credentials():
193+
import hashlib
179194
token_verify = cf_api_request('GET', f'/accounts/{config.CF_ACCOUNT_ID}/tokens/verify')
180195
token_id = token_verify.get('result', {}).get('id', '')
196+
secret = hashlib.sha256(config.CF_API_TOKEN.encode()).hexdigest()
181197
return {
182198
'access_key_id': token_id,
183-
'secret_access_key': config.CF_API_TOKEN,
199+
'secret_access_key': secret,
184200
'endpoint_url': f"https://{config.CF_ACCOUNT_ID}.r2.cloudflarestorage.com"
185201
}
186202

dockflare/app/static/js/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,9 +2496,9 @@ async function emailVerifyDns(domain, event) {
24962496
}
24972497

24982498
async function emailUpdateR2(domain, event) {
2499-
const accessKeyId = prompt('R2 Access Key ID (from CF Dashboard → R2 → Manage R2 API Tokens):');
2499+
const accessKeyId = await dfPrompt('R2 Access Key ID (from CF Dashboard → R2 → Manage R2 API Tokens):', '', 'R2 Access Key ID');
25002500
if (!accessKeyId) return;
2501-
const secretAccessKey = prompt('R2 Secret Access Key:');
2501+
const secretAccessKey = await dfPrompt('R2 Secret Access Key:', '', 'R2 Secret Access Key');
25022502
if (!secretAccessKey) return;
25032503
const btn = event?.currentTarget;
25042504
const originalHTML = btn?.innerHTML;

dockflare/app/web/email_routes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def setup_email_domain():
137137
outbound_auth_secret = secrets.token_hex(32)
138138
inbound_worker_name = f"dockflare-mail-inbound-{zone_name.replace('.', '-')}"
139139
outbound_worker_name = f"dockflare-mail-outbound-{zone_name.replace('.', '-')}"
140-
webmail_hostname = f"mail.{zone_name}"
140+
webmail_hostname = _get_webmail_hostname() or f"mail.{zone_name}"
141141
webhook_url = f"https://{webmail_hostname}/api/v1/webhook/inbound"
142142

143143
quota_kv_ns_id = None
@@ -164,6 +164,11 @@ def setup_email_domain():
164164
email_manager.set_worker_cron(inbound_worker_name, ['*/5 * * * *'])
165165
email_manager.setup_catchall_routing_rule(zone_id, inbound_worker_name)
166166

167+
try:
168+
email_manager.enable_email_sending(zone_id, zone_name)
169+
except Exception as sending_err:
170+
logging.warning(f"Could not enable email sending for {zone_name} (may need manual enable in CF Dashboard): {sending_err}")
171+
167172
outbound_bindings = [
168173
{"type": "send_email", "name": "SEND_EMAIL"},
169174
{"type": "secret_text", "name": "AUTH_SECRET", "text": outbound_auth_secret}
@@ -389,7 +394,7 @@ def _redeploy_outbound_worker(email_cfg, domain):
389394
def _redeploy_inbound_worker(email_cfg, domain):
390395
d = email_cfg['domains'][domain]
391396
all_addresses = list(d['mailboxes'].keys())
392-
webmail_hostname = f"mail.{domain}"
397+
webmail_hostname = _get_webmail_hostname() or f"mail.{domain}"
393398
webhook_url = f"https://{webmail_hostname}/api/v1/webhook/inbound"
394399

395400
kv_ns_id = d.get('quota_kv_namespace_id')

mail-manager/app/api/system.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def wipe_domain():
104104
for row in rows:
105105
shutil.rmtree(os.path.join(config.ATTACHMENTS_PATH, str(row['id'])), ignore_errors=True)
106106
conn.execute("DELETE FROM mailboxes WHERE address LIKE ?", (f'%@{domain}',))
107+
conn.execute("DELETE FROM domain_configs WHERE domain_name=?", (domain,))
107108
conn.commit()
108109
conn.close()
109110
def _vacuum():
@@ -131,6 +132,7 @@ def wipe_all():
131132
conn = sqlite3.connect(db_path)
132133
conn.execute("PRAGMA foreign_keys=ON")
133134
conn.execute("DELETE FROM mailboxes")
135+
conn.execute("DELETE FROM domain_configs")
134136
conn.commit()
135137
conn.close()
136138
def _vacuum():

0 commit comments

Comments
 (0)