Changeset 247
Legend:
- Unmodified
- Added
- Removed
-
trunk/HACKING
r224 r247 1 1 NOTE: This guide is a rough reference, please take the time to read the code 2 line by line, as it is not that long. 2 line by line, as it is not that long. It is also outdated in some parts. 3 3 4 4 Abstract: -
trunk/server.py
r246 r247 172 172 return self.server.getHost() 173 173 174 174 175 class ScreenshotServer(BaseHTTPServer): 175 176 """ … … 197 198 # Also we create our unique authentication handler this keeps track if the user authenticated or not 198 199 self.authresource = AuthenticatedResource(self.gui) 199 self.root = RootResource(self.gui, self.authresource, self.itaka_globals.head_html + self.configuration['html']['html'] + self.itaka_globals.footer_html)200 self.root = DataResource(self.gui, self.authresource, self.itaka_globals.head_html + self.configuration['html']['html'] + self.itaka_globals.footer_html) 200 201 self.add_child_to_resource('root', '', self.root) 201 202 self.add_child_to_resource('root', 'screenshot', ScreenshotResource(self.gui, self.authresource)) … … 204 205 self.create_site(self.root) 205 206 207 206 208 class AuthenticatedResource: 207 209 """ 208 Helper object to handle authentication for resources. 210 Helper object to handle authentication for Resources. 211 Please read RFC 2617 to understand the HTTP Authentication process 209 212 """ 210 213 … … 282 285 283 286 if not self.username and not self.password: 284 self.gui.log.failure((' RootResource', 'render'), (_('Client provided empty username and password'), _('Client %s provided empty username and password') % (self.ip)), 'WARNING')287 self.gui.log.failure(('AuthenticatedResource', 'render'), (_('Client provided empty username and password'), _('Client %s provided empty username and password') % (self.ip)), 'WARNING') 285 288 self._prompt_auth() 286 289 else: 287 290 if self.username != self.configuration['server']['username'] or self.password != self.configuration['server']['password']: 288 self.gui.log.failure((' RootResource', 'render'), (_('Client provided incorrect username and password'), _('Client %s provided incorrect username and password: %s:%s') % (self.ip, self.username, self.password)), 'WARNING')291 self.gui.log.failure(('AuthenticatedResource', 'render'), (_('Client provided incorrect username and password'), _('Client %s provided incorrect username and password: %s:%s') % (self.ip, self.username, self.password)), 'WARNING') 289 292 self._prompt_auth() 290 293 elif self.username == self.configuration['server']['username'] and self.password == self.configuration['server']['password']: … … 314 317 return self.noauth 315 318 316 class RootResource(static.Data): 317 """ 318 Main resource with authentication support 319 320 Please read RFC 2617 to understand the HTTP Authentication process 319 class DataResource(static.Data): 320 """ 321 Generic Resource for data 321 322 """ 322 323 … … 371 372 return self.data 372 373 374 class FileResource(resource.Resource): 375 """ 376 Generic Resource for file objects 377 """ 378 379 def __init__(self, gui_instance, auth_instance, path, type): 380 """ 381 Constructor 382 383 @type gui_instance: Gui 384 @param gui_instance: An instance of our L{Gui} class 385 386 @type auth_instance: AuthenticatedResource 387 @param auth_instance: An instance of our L{AuthenticatedResource} class 388 389 @type path: string 390 @param path: The path to the file to be served 391 392 @type type: str 393 @param type: The MIME-type to bepassed to Content-Type 394 """ 395 396 self.gui = gui_instance 397 self.auth = auth_instance 398 self.itaka_globals = self.gui.itaka_globals 399 400 self.type = type 401 self.data = open(path, 'rb').read() 402 self.size = str(os.stat(path).st_size) 403 404 def render_GET(self, request): 405 """ 406 Handle GET requests 407 408 @type request: instance 409 @param request: twisted.web.server.Request instance 410 """ 411 412 self.configuration = self.gui.configuration 413 self.request = request 414 415 if self.configuration['server']['authentication']: 416 if self.auth.authenticated or self.auth.authenticate(self.request): 417 self.auth.set_request_data(self.data, self.size, self.type, True) 418 return self.auth.return_object_data() 419 else: 420 self.request.setHeader('Content-Type', self.type) 421 self.request.setHeader('Content-Length', self.size) 422 self.request.setHeader('Connection', 'close') 423 if self.itaka_globals.console_verbosity['normal']: 424 BaseMessage(_('Itaka shutting down')) 425 return self.data 373 426 374 427 class ScreenshotResource(resource.Resource): 375 428 """ 376 Handle server requestsand call for a screenshot429 Handle request and call for a screenshot 377 430 """ 378 431 … … 399 452 def get_screenshot(self): 400 453 """ 401 Takes a screenshot and notif ythe GUI.454 Takes a screenshot and notifies the GUI. 402 455 """ 403 456 … … 454 507 self.request.setHeader('Connection', 'close') 455 508 return self.data 456 457 class FileResource(resource.Resource):458 """459 Generic handler for file resources460 """461 462 def __init__(self, gui_instance, auth_instance, path, type):463 """464 Constructor465 466 @type gui_instance: Gui467 @param gui_instance: An instance of our L{Gui} class468 469 @type auth_instance: AuthenticatedResource470 @param auth_instance: An instance of our L{AuthenticatedResource} class471 472 @type path: string473 @param path: The path to the file to be served474 475 @type type: str476 @param type: The MIME-type to bepassed to Content-Type477 """478 479 self.gui = gui_instance480 self.auth = auth_instance481 self.itaka_globals = self.gui.itaka_globals482 483 self.type = type484 self.data = open(path, 'rb').read()485 self.size = str(os.stat(path).st_size)486 487 def render_GET(self, request):488 """489 Handle GET requests490 491 @type request: instance492 @param request: twisted.web.server.Request instance493 """494 495 self.configuration = self.gui.configuration496 self.request = request497 498 if self.configuration['server']['authentication']:499 if self.auth.authenticated or self.auth.authenticate(self.request):500 self.auth.set_request_data(self.data, self.size, self.type, True)501 return self.auth.return_object_data()502 else:503 self.request.setHeader('Content-Type', self.type)504 self.request.setHeader('Content-Length', self.size)505 self.request.setHeader('Connection', 'close')506 return self.data
Note: See TracChangeset
for help on using the changeset viewer.

