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