From: W. Trevor King Date: Thu, 22 Jul 2010 16:42:58 +0000 (-0400) Subject: Added digest authentication for cookbook editing X-Git-Tag: v0.1~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=668f81ee37bafa65fe89ec90734f0c876ffa4a3d;p=cookbook.git Added digest authentication for cookbook editing The example .htaccess file sets up the user user: guest pass: guest or, if you're running CherryPy < 3.2 user: guest pass: 8eb3d4841608f011af3dd4bdc4c8b340 --- diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..50c2d6b --- /dev/null +++ b/.htaccess @@ -0,0 +1 @@ +guest:cookbook:8eb3d4841608f011af3dd4bdc4c8b340 diff --git a/bin/cook.py b/bin/cook.py index 5f006b4..42fc032 100755 --- a/bin/cook.py +++ b/bin/cook.py @@ -17,7 +17,10 @@ # You should have received a copy of the GNU General Public License # along with Cookbook. If not, see . +from __future__ import with_statement + import os.path +import uuid import cookbook from cookbook import Cookbook @@ -93,8 +96,37 @@ if __name__ == '__main__': 'tools.encode.encoding': 'utf8', 'tools.staticdir.root': static_dir, }) - app_config = { '/static': { 'tools.staticdir.on': True, - 'tools.staticdir.dir': '', } } + if cherrypy.__version__.startswith('3.2'): + get_ha1 = cherrypy.lib.auth_digest.get_ha1_file_htdigest( + '.htaccess') + digest_auth = { + 'tools.auth_digest.on': True, + 'tools.auth_digest.realm': 'cookbook', + 'tools.auth_digest.get_ha1': get_ha1, + 'tools.auth_digest.key': str(uuid.uuid4()), + } + else: + passwds = {} + with open('.htaccess', 'r') as f: + for line in f: + user,realm,ha1 = line.strip().split(':') + passwds[user] = ha1 # use the ha1 as the password + digest_auth = { + 'tools.digest_auth.on': True, + 'tools.digest_auth.realm': 'cookbook', + 'tools.digest_auth.users': passwds, + } + print passwds + del(passwds) + app_config = { + '/static': { + 'tools.staticdir.on': True, + 'tools.staticdir.dir': '', + }, + '/edit': digest_auth, + '/add_tag': digest_auth, + '/remove_tag': digest_auth, + } cherrypy.quickstart(root=s, config=app_config) elif cherrypy.__version__.startswith('2.'): cherrypy.root = s