1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import sys
17 import os
18 import time
19 import string
20
21 from spacewalk.common import apache, rhnApache, rhnTB, rhnFlags
22 from spacewalk.common.rhnException import rhnException, rhnFault
23 from spacewalk.common.rhnConfig import CFG, initCFG
24 from spacewalk.common.rhnLog import log_debug, log_error, initLOG, log_setreq
25
26
27 import rhnSQL
28
29 from apacheRequest import apacheGET, apachePOST, HandlerNotFoundError
30 import rhnCapability
31
32
33
34
36 if not last:
37 return 0
38 log_debug(2, "%.2f sec" % (time.time() - last,))
39 return 0
40
41
43
44 """ a class that extends rhnApache with several support functions used
45 by the main handler class. This class deals with the processing of
46 the request and setup for the real action handled in the
47 apacheHandler class below. """
48 _lang_catalog = "server"
49
50
52
53 """ main Apache XMLRPC point of entry for the server """
54
59
60
61
62
63
64
66
67 log_setreq(req)
68
69 options = req.get_options()
70
71
72 if "RHNComponentType" not in options:
73
74 return apache.OK
75 initCFG(options["RHNComponentType"])
76 initLOG(CFG.LOG_FILE, CFG.DEBUG)
77
78 """ parse the request, init database and figure out what can we call """
79 log_debug(2, req.the_request)
80
81 ret = apacheSession.headerParserHandler(self, req)
82 if ret != apache.OK:
83 return ret
84
85 if not CFG.SEND_MESSAGE_TO_ALL:
86 try:
87 rhnSQL.initDB()
88 except rhnSQL.SQLConnectError:
89 rhnTB.Traceback(mail=1, req=req, severity="schema")
90 return apache.HTTP_INTERNAL_SERVER_ERROR
91 else:
92
93 rhnSQL.closeDB()
94
95
96 client_cap_header = 'X-RHN-Client-Capability'
97 if client_cap_header in req.headers_in:
98 client_caps = req.headers_in[client_cap_header]
99 client_caps = [_f for _f in list(map(string.strip, string.split(client_caps, ","))) if _f]
100 rhnCapability.set_client_capabilities(client_caps)
101
102
103 redirect_support_flags = ['X-RHN-Redirect', 'X-RHN-Transport-Capability']
104 for flag in redirect_support_flags:
105 if flag in req.headers_in:
106 rhnFlags.set(flag, str(req.headers_in[flag]))
107
108 return apache.OK
109
132
134 """ Clean up the request processor """
135 self._req_processor = None
136 return apache.OK
137
139 """ main Apache handler """
140 log_debug(2)
141 ret = apacheSession.handler(self, req)
142 if ret != apache.OK:
143 return ret
144
145 if not CFG.SEND_MESSAGE_TO_ALL:
146
147
148
149
150 h = rhnSQL.prepare("select label, value from rhnTemplateString")
151 h.execute()
152
153 templateStrings = {}
154 while 1:
155 row = h.fetchone_dict()
156 if not row:
157 break
158
159 templateStrings[row['label']] = row['value']
160
161 if templateStrings:
162 rhnFlags.set('templateOverrides', templateStrings)
163
164 log_debug(4, "template strings: %s" % templateStrings)
165
166 if not CFG.SECRET_KEY:
167
168 try:
169 raise rhnException("Secret key not found!")
170 except:
171 rhnTB.Traceback(mail=1, req=req, severity="schema")
172 req.status = 500
173 req.send_http_header()
174 return apache.OK
175
176
177
178 if self.proxyVersion:
179 try:
180 ret = self._req_processor.auth_proxy()
181 except rhnFault:
182 f = sys.exc_info()[1]
183 return self._req_processor.response(f.getxml())
184
185
186
187
188
189 if req.method == "GET":
190 try:
191 ret = self._req_processor.auth_client()
192 except rhnFault:
193 f = sys.exc_info()[1]
194 return self._req_processor.response(f.getxml())
195
196 if not ret:
197 log_error("Got a GET call, but auth_client declined",
198 req.path_info)
199 return apache.HTTP_METHOD_NOT_ALLOWED
200
201
202 try:
203 ret = self._req_processor.process()
204 rhnSQL.rollback()
205 except:
206 if not CFG.SEND_MESSAGE_TO_ALL:
207 rhnSQL.rollback()
208 raise
209 log_debug(4, "Leave with return value", ret)
210 return ret
211
213 """ Clean up stuff before we close down the session when we are called
214 from apacheServer.Cleanup() """
215 log_debug(2)
216
217 while 1:
218 pid = status = -1
219 try:
220 (pid, status) = os.waitpid(-1, 0)
221 except OSError:
222 break
223 else:
224 log_error("Reaped child process %d with status %d" % (
225 pid, status))
226 ret = apacheSession.cleanupHandler(self, req)
227 return ret
228