prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Manage user authentication and permissions
  Currently no authentication is implemented. Multiple issues will have to be tackled:
  - complete permission scheme or simple admin role plus admins per domain?
  - how to store user passwords (shared format between Flask-admin and dovecot)?
  - how should the initial use be created?
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `core/admin/start.py`
  Content:
  ```
  1 #!/usr/bin/python3
  2 
  3 import os
  4 import logging as log
  5 import sys
  6 
  7 log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "INFO"))
  8 
  9 os.system("flask mailu advertise")
  10 os.system("flask db upgrade")
  11 
  12 account = os.environ.get("INITIAL_ADMIN_ACCOUNT")
  13 domain = os.environ.get("INITIAL_ADMIN_DOMAIN")
  14 password = os.environ.get("INITIAL_ADMIN_PW")
  15 
  16 if account is not None and domain is not None and password is not None:
  17     mode = os.environ.get("INITIAL_ADMIN_MODE", default="ifmissing")
  18     log.info("Creating initial admin accout %s@%s with mode %s",account,domain,mode)
  19     os.system("flask mailu admin %s %s '%s' --mode %s" % (account, domain, password, mode))
  20 
  21 def test_DNS():
  22     import dns.resolver
  23     import dns.exception
  24     import dns.flags
  25     import dns.rdtypes
  26     import dns.rdatatype
  27     import dns.rdataclass
  28     import time
  29     # DNS stub configured to do DNSSEC enabled queries
  30     resolver = dns.resolver.Resolver()
  31     resolver.use_edns(0, 0, 1232)
  32     resolver.flags = dns.flags.AD | dns.flags.RD
  33     nameservers = resolver.nameservers
  34     for ns in nameservers:
  35         resolver.nameservers=[ns]
  36         while True:
  37             try:
  38                 result = resolver.query('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)
  39             except Exception as e:
  40                 log.critical("Your DNS resolver at %s is not working (%s). Please use another resolver or enable unbound via https://setup.mailu.io.", ns, e);
  41             else:
  42                 if result.response.flags & dns.flags.AD:
  43                     break
  44                 log.critical("Your DNS resolver at %s isn't doing DNSSEC validation; Please use another resolver or enable unbound via https://setup.mailu.io.", ns)
  45             time.sleep(5)
  46 
  47 test_DNS()
  48 
  49 start_command="".join([
  50     "gunicorn --threads ", str(os.cpu_count()),
  51     " -b :80 ",
  52     "--access-logfile - " if (log.root.level<=log.INFO) else "",
  53     "--error-logfile - ",
  54     "--preload ",
  55     "'mailu:create_app()'"])
  56 
  57 os.system(start_command)
  58
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/core/admin/start.py b/core/admin/start.py
  --- a/core/admin/start.py
  +++ b/core/admin/start.py
  @@ -35,7 +35,7 @@
           resolver.nameservers=[ns]
           while True:
               try:
  -                result = resolver.query('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)
  +                result = resolver.resolve('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)
               except Exception as e:
                   log.critical("Your DNS resolver at %s is not working (%s). Please use another resolver or enable unbound via https://setup.mailu.io.", ns, e);
               else:
  
verification_info: {"golden_diff": "diff --git a/core/admin/start.py b/core/admin/start.py\n--- a/core/admin/start.py\n+++ b/core/admin/start.py\n@@ -35,7 +35,7 @@\n         resolver.nameservers=[ns]\n         while True:\n             try:\n-                result = resolver.query('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)\n+                result = resolver.resolve('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)\n             except Exception as e:\n                 log.critical(\"Your DNS resolver at %s is not working (%s). Please use another resolver or enable unbound via https://setup.mailu.io.\", ns, e);\n             else:\n", "issue": "Manage user authentication and permissions\nCurrently no authentication is implemented. Multiple issues will have to be tackled:\n- complete permission scheme or simple admin role plus admins per domain?\n- how to store user passwords (shared format between Flask-admin and dovecot)?\n- how should the initial use be created?\n\n", "before_files": [{"content": "#!/usr/bin/python3\n\nimport os\nimport logging as log\nimport sys\n\nlog.basicConfig(stream=sys.stderr, level=os.environ.get(\"LOG_LEVEL\", \"INFO\"))\n\nos.system(\"flask mailu advertise\")\nos.system(\"flask db upgrade\")\n\naccount = os.environ.get(\"INITIAL_ADMIN_ACCOUNT\")\ndomain = os.environ.get(\"INITIAL_ADMIN_DOMAIN\")\npassword = os.environ.get(\"INITIAL_ADMIN_PW\")\n\nif account is not None and domain is not None and password is not None:\n    mode = os.environ.get(\"INITIAL_ADMIN_MODE\", default=\"ifmissing\")\n    log.info(\"Creating initial admin accout %s@%s with mode %s\",account,domain,mode)\n    os.system(\"flask mailu admin %s %s '%s' --mode %s\" % (account, domain, password, mode))\n\ndef test_DNS():\n    import dns.resolver\n    import dns.exception\n    import dns.flags\n    import dns.rdtypes\n    import dns.rdatatype\n    import dns.rdataclass\n    import time\n    # DNS stub configured to do DNSSEC enabled queries\n    resolver = dns.resolver.Resolver()\n    resolver.use_edns(0, 0, 1232)\n    resolver.flags = dns.flags.AD | dns.flags.RD\n    nameservers = resolver.nameservers\n    for ns in nameservers:\n        resolver.nameservers=[ns]\n        while True:\n            try:\n                result = resolver.query('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)\n            except Exception as e:\n                log.critical(\"Your DNS resolver at %s is not working (%s). Please use another resolver or enable unbound via https://setup.mailu.io.\", ns, e);\n            else:\n                if result.response.flags & dns.flags.AD:\n                    break\n                log.critical(\"Your DNS resolver at %s isn't doing DNSSEC validation; Please use another resolver or enable unbound via https://setup.mailu.io.\", ns)\n            time.sleep(5)\n\ntest_DNS()\n\nstart_command=\"\".join([\n    \"gunicorn --threads \", str(os.cpu_count()),\n    \" -b :80 \",\n    \"--access-logfile - \" if (log.root.level<=log.INFO) else \"\",\n    \"--error-logfile - \",\n    \"--preload \",\n    \"'mailu:create_app()'\"])\n\nos.system(start_command)\n", "path": "core/admin/start.py"}], "after_files": [{"content": "#!/usr/bin/python3\n\nimport os\nimport logging as log\nimport sys\n\nlog.basicConfig(stream=sys.stderr, level=os.environ.get(\"LOG_LEVEL\", \"INFO\"))\n\nos.system(\"flask mailu advertise\")\nos.system(\"flask db upgrade\")\n\naccount = os.environ.get(\"INITIAL_ADMIN_ACCOUNT\")\ndomain = os.environ.get(\"INITIAL_ADMIN_DOMAIN\")\npassword = os.environ.get(\"INITIAL_ADMIN_PW\")\n\nif account is not None and domain is not None and password is not None:\n    mode = os.environ.get(\"INITIAL_ADMIN_MODE\", default=\"ifmissing\")\n    log.info(\"Creating initial admin accout %s@%s with mode %s\",account,domain,mode)\n    os.system(\"flask mailu admin %s %s '%s' --mode %s\" % (account, domain, password, mode))\n\ndef test_DNS():\n    import dns.resolver\n    import dns.exception\n    import dns.flags\n    import dns.rdtypes\n    import dns.rdatatype\n    import dns.rdataclass\n    import time\n    # DNS stub configured to do DNSSEC enabled queries\n    resolver = dns.resolver.Resolver()\n    resolver.use_edns(0, 0, 1232)\n    resolver.flags = dns.flags.AD | dns.flags.RD\n    nameservers = resolver.nameservers\n    for ns in nameservers:\n        resolver.nameservers=[ns]\n        while True:\n            try:\n                result = resolver.resolve('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)\n            except Exception as e:\n                log.critical(\"Your DNS resolver at %s is not working (%s). Please use another resolver or enable unbound via https://setup.mailu.io.\", ns, e);\n            else:\n                if result.response.flags & dns.flags.AD:\n                    break\n                log.critical(\"Your DNS resolver at %s isn't doing DNSSEC validation; Please use another resolver or enable unbound via https://setup.mailu.io.\", ns)\n            time.sleep(5)\n\ntest_DNS()\n\nstart_command=\"\".join([\n    \"gunicorn --threads \", str(os.cpu_count()),\n    \" -b :80 \",\n    \"--access-logfile - \" if (log.root.level<=log.INFO) else \"\",\n    \"--error-logfile - \",\n    \"--preload \",\n    \"'mailu:create_app()'\"])\n\nos.system(start_command)\n", "path": "core/admin/start.py"}]}