import frappe
import sys

try:
    frappe.init(site="almanara.serveirc.com")
    frappe.connect()
except Exception as e:
    print("Could not connect to site:", e)
    sys.exit(1)

try:
    domains = frappe.get_all('Domain', pluck='name')
    print("Found domains:", domains)
    if domains:
        doc = frappe.get_single('Domain Settings')
        doc.set('active_domains', [])
        for d in domains:
            doc.append('active_domains', {'domain': d})
        doc.save()
        frappe.db.commit()
        print("Successfully enabled all domains.")
except Exception as e:
    print("Error enabling domains:", e)
finally:
    frappe.destroy()
