|
1 | 1 | #!/usr/local/lib/mailinabox/env/bin/python3
|
| 2 | +# |
| 3 | +# During development, you can start the Mail-in-a-Box control panel |
| 4 | +# by running this script, e.g.: |
| 5 | +# |
| 6 | +# service mailinabox stop # stop the system process |
| 7 | +# DEBUG=1 management/daemon.py |
| 8 | +# service mailinabox start # when done debugging, start it up again |
2 | 9 |
|
3 | 10 | import os, os.path, re, json, time
|
4 | 11 | import multiprocessing.pool, subprocess
|
@@ -680,7 +687,22 @@ def log_failed_login(request):
|
680 | 687 | # APP
|
681 | 688 |
|
682 | 689 | if __name__ == '__main__':
|
683 |
| - if "DEBUG" in os.environ: app.debug = True |
| 690 | + if "DEBUG" in os.environ: |
| 691 | + # Turn on Flask debugging. |
| 692 | + app.debug = True |
| 693 | + |
| 694 | + # Use a stable-ish master API key so that login sessions don't restart on each run. |
| 695 | + # Use /etc/machine-id to seed the key with a stable secret, but add something |
| 696 | + # and hash it to prevent possibly exposing the machine id, using the time so that |
| 697 | + # the key is not valid indefinitely. |
| 698 | + import hashlib |
| 699 | + with open("/etc/machine-id") as f: |
| 700 | + api_key = f.read() |
| 701 | + api_key += "|" + str(int(time.time() / (60*60*2))) |
| 702 | + hasher = hashlib.sha1() |
| 703 | + hasher.update(api_key.encode("ascii")) |
| 704 | + auth_service.key = hasher.hexdigest() |
| 705 | + |
684 | 706 | if "APIKEY" in os.environ: auth_service.key = os.environ["APIKEY"]
|
685 | 707 |
|
686 | 708 | if not app.debug:
|
|
0 commit comments