Browse Source

replace secret_key variable with code to automatically generate it and store it in .secret.txt.

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
2e2f34d292
  1. 2
      .hgignore
  2. 26
      pyweb/gen_secret_key.sh
  3. 21
      pyweb/settings.py

2
.hgignore

@ -4,4 +4,4 @@ syntax: glob
*.db3 *.db3
*~ *~
.directory .directory
.secret.txt

26
pyweb/gen_secret_key.sh

@ -1,26 +0,0 @@
#!/bin/bash
#
# Update settings.py with an automatically generated Secret Key.
#
# Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
#
# Mumble-Django is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
HASHSCRIPT='
from hashlib import sha1;
import sys;
print sha1( sys.stdin.read() ).hexdigest();'
KEY=` dd if=/dev/urandom bs=64 count=1 2>/dev/null | python -c "$HASHSCRIPT" `
SECKEY="SECRET_KEY = '$KEY'"
sed -i "s/^SECRET_KEY.*/${SECKEY}/" settings.py

21
pyweb/settings.py

@ -145,8 +145,25 @@ ADMIN_MEDIA_PREFIX = MUMBLE_DJANGO_URL+'media/'
LOGIN_URL = MUMBLE_DJANGO_URL + 'accounts/login'; LOGIN_URL = MUMBLE_DJANGO_URL + 'accounts/login';
LOGIN_REDIRECT_URL = MUMBLE_DJANGO_URL + 'accounts/profile'; LOGIN_REDIRECT_URL = MUMBLE_DJANGO_URL + 'accounts/profile';
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'u-mp185msk#z4%s(do2^5405)y5d!9adbn92)apu_p^qvqh10v'
# Automatically generate a .secret.txt file containing the SECRET_KEY.
# Shamelessly stolen from ByteFlow: <http://www.byteflow.su>
try:
SECRET_KEY
except NameError:
SECRET_FILE = join(MUMBLE_DJANGO_ROOT, '.secret.txt')
try:
SECRET_KEY = open(SECRET_FILE).read().strip()
except IOError:
try:
from random import choice
SECRET_KEY = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
secret = file(SECRET_FILE, 'w')
secret.write(SECRET_KEY)
secret.close()
except IOError:
Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)
# List of callables that know how to import templates from various sources. # List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (

Loading…
Cancel
Save