1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: webservergluecgi.py 86974 2020-11-25 14:38:52Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | Test Manager Core - Web Server Abstraction Base Class.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2012-2020 Oracle Corporation
|
---|
11 |
|
---|
12 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | available from http://www.virtualbox.org. This file is free software;
|
---|
14 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | General Public License (GPL) as published by the Free Software
|
---|
16 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 |
|
---|
20 | The contents of this file may alternatively be used under the terms
|
---|
21 | of the Common Development and Distribution License Version 1.0
|
---|
22 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
23 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
24 | CDDL are applicable instead of those of the GPL.
|
---|
25 |
|
---|
26 | You may elect to license modified versions of this file under the
|
---|
27 | terms and conditions of either the GPL or the CDDL or both.
|
---|
28 | """
|
---|
29 | __version__ = "$Revision: 86974 $"
|
---|
30 |
|
---|
31 |
|
---|
32 | # Standard python imports.
|
---|
33 | import cgitb;
|
---|
34 | import os;
|
---|
35 | import sys;
|
---|
36 | import cgi;
|
---|
37 |
|
---|
38 | # Validation Kit imports.
|
---|
39 | from testmanager.core.webservergluebase import WebServerGlueBase;
|
---|
40 | from testmanager import config;
|
---|
41 |
|
---|
42 |
|
---|
43 | class WebServerGlueCgi(WebServerGlueBase):
|
---|
44 | """
|
---|
45 | CGI glue.
|
---|
46 | """
|
---|
47 | def __init__(self, sValidationKitDir, fHtmlOutput=True):
|
---|
48 | WebServerGlueBase.__init__(self, sValidationKitDir, fHtmlOutput);
|
---|
49 |
|
---|
50 | if config.g_kfSrvGlueCgiTb is True:
|
---|
51 | cgitb.enable(format=('html' if fHtmlOutput else 'text'));
|
---|
52 |
|
---|
53 | def getParameters(self):
|
---|
54 | return cgi.parse(keep_blank_values=True);
|
---|
55 |
|
---|
56 | def getClientAddr(self):
|
---|
57 | return os.environ.get('REMOTE_ADDR');
|
---|
58 |
|
---|
59 | def getMethod(self):
|
---|
60 | return os.environ.get('REQUEST_METHOD', 'POST');
|
---|
61 |
|
---|
62 | def getLoginName(self):
|
---|
63 | return os.environ.get('REMOTE_USER', WebServerGlueBase.ksUnknownUser);
|
---|
64 |
|
---|
65 | def getUrlScheme(self):
|
---|
66 | return 'https' if 'HTTPS' in os.environ else 'http';
|
---|
67 |
|
---|
68 | def getUrlNetLoc(self):
|
---|
69 | return os.environ['HTTP_HOST'];
|
---|
70 |
|
---|
71 | def getUrlPath(self):
|
---|
72 | return os.environ['REQUEST_URI'];
|
---|
73 |
|
---|
74 | def getUserAgent(self):
|
---|
75 | return os.getenv('HTTP_USER_AGENT', '');
|
---|
76 |
|
---|
77 | def getContentType(self):
|
---|
78 | return cgi.parse_header(os.environ.get('CONTENT_TYPE', 'text/html'));
|
---|
79 |
|
---|
80 | def getContentLength(self):
|
---|
81 | return int(os.environ.get('CONTENT_LENGTH', 0));
|
---|
82 |
|
---|
83 | def getBodyIoStream(self):
|
---|
84 | return sys.stdin;
|
---|
85 |
|
---|
86 | def getBodyIoStreamBinary(self):
|
---|
87 | # Python 3: sys.stdin.read() returns a string. To get untranslated
|
---|
88 | # binary data we use the sys.stdin.buffer object instead.
|
---|
89 | return getattr(sys.stdin, 'buffer', sys.stdin);
|
---|
90 |
|
---|