# 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
'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