Skip to content

Commit 82229ce

Browse files
committed
Document how to start the control panel from the command line and in debugging use a stable API key
1 parent f66e609 commit 82229ce

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

management/daemon.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#!/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
29

310
import os, os.path, re, json, time
411
import multiprocessing.pool, subprocess
@@ -680,7 +687,22 @@ def log_failed_login(request):
680687
# APP
681688

682689
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+
684706
if "APIKEY" in os.environ: auth_service.key = os.environ["APIKEY"]
685707

686708
if not app.debug:

0 commit comments

Comments
 (0)