/[glsr]/trunk/harmonious/_pathfilter.py
Gentoo

Contents of /trunk/harmonious/_pathfilter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91 - (show annotations) (download) (as text)
Fri Jul 29 14:41:11 2005 UTC (13 years, 4 months ago) by port001
File MIME type: text/x-python
File size: 2754 byte(s)
Persistent connections and threaded requests
1 _id__ = '$Id$'
2 __modulename__ = 'PathFilter'
3
4 import os
5 import md5
6 import base64
7
8 from harmonious import server
9
10 class PathFilter:
11
12 def __init__(self, harm):
13
14 self.__harm = harm
15
16 def perform(self):
17
18 self.__normalise()
19 self.__harm.request.status = self.__get_status()
20
21 return self.__harm
22
23 def __normalise(self):
24
25 self.__harm.request.path = os.path.normcase(os.path.normpath(self.__harm.request.path))
26 self.__harm.request.abs_path = os.path.normcase(os.path.normpath(self.__harm.request.abs_path))
27
28 if len(self.__harm.request.path) > 1:
29
30 if self.__harm.request.path[-1] != '/':
31
32 self.__harm.request.path = "%s/" % self.__harm.request.path
33
34 def __get_status(self):
35
36 # Does the path and file exist?
37 if not os.path.exists(self.__harm.request.abs_path):
38
39 return 404
40
41 if not os.path.exists(os.path.join(self.__harm.request.abs_path, self.__harm.request.file)):
42
43 return 404
44
45 # Do we have access?
46 if not os.access(self.__harm.request.abs_path, os.R_OK):
47
48 return 403
49
50 # Is it protected?
51 if server.config.hosts[self.__harm.request.host].has_key('protected'):
52
53 if self.__harm.request.path in server.config.hosts[self.__harm.request.host]['protected'].keys():
54
55 # Has the user supplied a username and password?
56 if self.__harm.request.headers.has_key('Authorization'):
57
58 try:
59
60 (basic, user_pass) = self.__harm.request.headers['Authorization'].split(' ', 1)
61
62 except ValueError:
63
64 return 400
65
66 if basic.lower() != 'basic':
67
68 return 400
69
70 user_pass = base64.standard_b64decode(user_pass)
71
72 try:
73
74 (user, passwd) = user_pass.split(':', 1)
75
76 except ValueError:
77
78 return 400
79
80 matched = False
81
82 for auth in server.config.hosts[self.__harm.request.host]['protected'][self.__harm.request.path]:
83
84 print auth
85
86 if auth['user'] == user and auth['passwd'] == md5.new(passwd).hexdigest():
87
88 matched = True
89
90 if not matched:
91
92 return 401
93
94 else:
95
96 return 401
97
98 if self.__harm.request.file != '':
99
100 if not os.access(os.path.join(self.__harm.request.abs_path, self.__harm.request.file), os.R_OK):
101
102 return 403
103
104 else:
105
106 return 200
107
108 else:
109
110 return 501
111

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20