Added digest authentication for cookbook editing
authorW. Trevor King <wking@drexel.edu>
Thu, 22 Jul 2010 16:42:58 +0000 (12:42 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 22 Jul 2010 16:43:04 +0000 (12:43 -0400)
The example .htaccess file sets up the user
  user: guest
  pass: guest
or, if you're running CherryPy < 3.2
  user: guest
  pass: 8eb3d4841608f011af3dd4bdc4c8b340

.htaccess [new file with mode: 0644]
bin/cook.py

diff --git a/.htaccess b/.htaccess
new file mode 100644 (file)
index 0000000..50c2d6b
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1 @@
+guest:cookbook:8eb3d4841608f011af3dd4bdc4c8b340
index 5f006b4e3bcfd763f9b5d8d409f34ef40623ce91..42fc032b40c9e4431fff2649d73f3840f6352cbc 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with Cookbook.  If not, see <http://www.gnu.org/licenses/>.
 
+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