backend/Makefile.backend | 2
backend/apache-conf/zz-spacewalk-server-wsgi.conf | 20 +-
backend/server/Makefile | 2
backend/server/wsgi/Makefile | 10 -
backend/server/wsgi/__init__.py | 16 --
backend/server/wsgi/app.py | 20 --
backend/server/wsgi/applet.py | 20 --
backend/server/wsgi/config.py | 20 --
backend/server/wsgi/config_tool.py | 20 --
backend/server/wsgi/package_push.py | 20 --
backend/server/wsgi/package_upload.py | 20 --
backend/server/wsgi/sat.py | 21 ---
backend/server/wsgi/sat_dump.py | 20 --
backend/server/wsgi/wsgiHandler.py | 78 -----------
backend/server/wsgi/wsgiRequest.py | 150 ----------------------
backend/server/wsgi/xmlrpc.py | 22 ---
backend/server/wsgi/xp.py | 21 ---
backend/spacewalk-backend.spec | 33 ++--
backend/wsgi/Makefile | 10 +
backend/wsgi/__init__.py | 16 ++
backend/wsgi/app.py | 20 ++
backend/wsgi/applet.py | 20 ++
backend/wsgi/config.py | 20 ++
backend/wsgi/config_tool.py | 20 ++
backend/wsgi/package_push.py | 20 ++
backend/wsgi/package_upload.py | 20 ++
backend/wsgi/sat.py | 21 +++
backend/wsgi/sat_dump.py | 20 ++
backend/wsgi/wsgiHandler.py | 78 +++++++++++
backend/wsgi/wsgiRequest.py | 150 ++++++++++++++++++++++
backend/wsgi/xmlrpc.py | 22 +++
backend/wsgi/xp.py | 21 +++
32 files changed, 488 insertions(+), 485 deletions(-)
New commits:
commit 7e6b23d882efc18bd3b7d2914cd0d5dbdeacbd61
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Thu Mar 25 16:54:59 2010 +0100
moved mod_wsgi stuff from spacewalk-backend-server to spacewalk-backend
in order to be able to reuse it in proxy
diff --git a/backend/Makefile.backend b/backend/Makefile.backend
index 378723e..e2393fa 100644
--- a/backend/Makefile.backend
+++ b/backend/Makefile.backend
@@ -2,7 +2,7 @@
#
# $Id$
-CODE_DIRS = common server upload_server satellite_tools satellite_exporter po
+CODE_DIRS = common server upload_server satellite_tools satellite_exporter po wsgi
CONF_DIRS = apache-conf httpd-conf rhn-conf logrotate
# We look for config files in "well known" locations (rhn-conf,
diff --git a/backend/apache-conf/zz-spacewalk-server-wsgi.conf
b/backend/apache-conf/zz-spacewalk-server-wsgi.conf
index 5119cf9..233af0f 100644
--- a/backend/apache-conf/zz-spacewalk-server-wsgi.conf
+++ b/backend/apache-conf/zz-spacewalk-server-wsgi.conf
@@ -4,14 +4,14 @@
WSGIPythonPath "/usr/share/rhn"
-WSGIScriptAlias /APP /usr/share/rhn/server/wsgi/app.py
-WSGIScriptAlias /APPLET /usr/share/rhn/server/wsgi/applet.py
-WSGIScriptAlias /CONFIG-MANAGEMENT /usr/share/rhn/server/wsgi/config.py
-WSGIScriptAlias /CONFIG-MANAGEMENT-TOOL /usr/share/rhn/server/wsgi/config_tool.py
-WSGIScriptAlias /PACKAGE-PUSH /usr/share/rhn/server/wsgi/package_push.py
-WSGIScriptAlias /PKG-UPLOAD /usr/share/rhn/server/wsgi/package_upload.py
-WSGIScriptAlias /SAT /usr/share/rhn/server/wsgi/sat.py
-WSGIScriptAlias /SAT-DUMP-INTERNAL /usr/share/rhn/server/wsgi/sat_dump.py
-WSGIScriptAlias /XMLRPC /usr/share/rhn/server/wsgi/xmlrpc.py
-WSGIScriptAlias /XP /usr/share/rhn/server/wsgi/xp.py
+WSGIScriptAlias /APP /usr/share/rhn/wsgi/app.py
+WSGIScriptAlias /APPLET /usr/share/rhn/wsgi/applet.py
+WSGIScriptAlias /CONFIG-MANAGEMENT /usr/share/rhn/wsgi/config.py
+WSGIScriptAlias /CONFIG-MANAGEMENT-TOOL /usr/share/rhn/wsgi/config_tool.py
+WSGIScriptAlias /PACKAGE-PUSH /usr/share/rhn/wsgi/package_push.py
+WSGIScriptAlias /PKG-UPLOAD /usr/share/rhn/wsgi/package_upload.py
+WSGIScriptAlias /SAT /usr/share/rhn/wsgi/sat.py
+WSGIScriptAlias /SAT-DUMP-INTERNAL /usr/share/rhn/wsgi/sat_dump.py
+WSGIScriptAlias /XMLRPC /usr/share/rhn/wsgi/xmlrpc.py
+WSGIScriptAlias /XP /usr/share/rhn/wsgi/xp.py
diff --git a/backend/server/Makefile b/backend/server/Makefile
index 75166dd..1f91e5f 100644
--- a/backend/server/Makefile
+++ b/backend/server/Makefile
@@ -21,6 +21,6 @@ FILES = __init__ \
rhnSession rhnUser rhnVirtualization taskomatic
SUBDIRS = rhnSQL rhnServer action \
handlers importlib action_extra_data \
- config_common repomd wsgi
+ config_common repomd
include $(TOP)/Makefile.defs
diff --git a/backend/server/wsgi/Makefile b/backend/server/wsgi/Makefile
deleted file mode 100644
index b458c7c..0000000
--- a/backend/server/wsgi/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-# Makefile for the wsgi module
-
-TOP = ../..
-
-SUBDIR = server/wsgi
-
-FILES = __init__ app applet config config_tool package_push package_upload \
- sat sat_dump wsgiHandler wsgiRequest xmlrpc xp
-
-include $(TOP)/Makefile.defs
diff --git a/backend/server/wsgi/__init__.py b/backend/server/wsgi/__init__.py
deleted file mode 100644
index d7305c3..0000000
--- a/backend/server/wsgi/__init__.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
diff --git a/backend/server/wsgi/app.py b/backend/server/wsgi/app.py
deleted file mode 100644
index b66c5cf..0000000
--- a/backend/server/wsgi/app.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response,
"app","server.app")
diff --git a/backend/server/wsgi/applet.py b/backend/server/wsgi/applet.py
deleted file mode 100644
index 2f31885..0000000
--- a/backend/server/wsgi/applet.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response,
"applet","server.applet")
diff --git a/backend/server/wsgi/config.py b/backend/server/wsgi/config.py
deleted file mode 100644
index 3049ac2..0000000
--- a/backend/server/wsgi/config.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response,
"config","server.config-management")
diff --git a/backend/server/wsgi/config_tool.py b/backend/server/wsgi/config_tool.py
deleted file mode 100644
index 4089cc8..0000000
--- a/backend/server/wsgi/config_tool.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response,
"config_mgmt","server.config-management-tool")
diff --git a/backend/server/wsgi/package_push.py b/backend/server/wsgi/package_push.py
deleted file mode 100644
index afc029b..0000000
--- a/backend/server/wsgi/package_push.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response,
"package_push","server.upload.package-push", type="upload")
diff --git a/backend/server/wsgi/package_upload.py
b/backend/server/wsgi/package_upload.py
deleted file mode 100644
index f8cbd51..0000000
--- a/backend/server/wsgi/package_upload.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response,
"package","server.upload.package", type="upload")
diff --git a/backend/server/wsgi/sat.py b/backend/server/wsgi/sat.py
deleted file mode 100644
index 82a48c4..0000000
--- a/backend/server/wsgi/sat.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response,
"sat","server.iss")
diff --git a/backend/server/wsgi/sat_dump.py b/backend/server/wsgi/sat_dump.py
deleted file mode 100644
index fb4b601..0000000
--- a/backend/server/wsgi/sat_dump.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response, "non_auth_dumper",
"server.satexport.internal", type='exporter')
diff --git a/backend/server/wsgi/wsgiHandler.py b/backend/server/wsgi/wsgiHandler.py
deleted file mode 100644
index 0c5bda2..0000000
--- a/backend/server/wsgi/wsgiHandler.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-
-from server.wsgi import wsgiRequest
-from server import apacheServer
-from server import apacheUploadServer
-from satellite_exporter import satexport
-
-from common import log_debug
-
-def handle(environ, start_response, server, component_type, type="normal"):
- #wsgi seems to capitalize incoming headers and add HTTP- to the front :/
- # so we strip out the first 5 letters, and transform it into what we want.
- replacements = {'_':'-', 'Rhn':'RHN',
'Md5Sum':'MD5sum', 'Xml':'XML'}
- for key in environ.keys():
- if key[:5] == "HTTP_":
- new_key = key[5:].title()
- for k,v in replacements.iteritems():
- new_key = new_key.replace(k,v)
- environ[new_key] = environ[key]
-
-
-
- req = wsgiRequest.WsgiRequest(environ, start_response)
- req.set_option("SERVER", server)
- req.set_option("RHNComponentType", component_type)
- req.set_option("RootDir", "/usr/share/rhn")
-
- parseServ = get_handle(type, "headerParserHandler", init=1)
- ret = parseServ(req)
-
- if len(req.output) > 0:
- if not req.sent_header:
- req.send_http_header(status=ret)
- return req.output
-
- appServ = get_handle(type, "handler")
- ret = appServ(req)
-
- if not ret:
- ret = None
-
- if not req.sent_header:
- req.send_http_header(status=ret)
-
- #exporter doesn't have a logHandler
- if type != 'exporter':
- logServ = get_handle(type, "logHandler")
- logServ(req)
- cleanServ = get_handle(type, "cleanupHandler")
- cleanServ(req)
-
- return req.output
-
-def get_handle(type, name, init=0):
- if type == 'upload':
- return apacheUploadServer.UploadHandlerWrap(name)
- #the sat export module doesn't provide a nice server module
- elif type == 'exporter':
- return getattr(satexport, name)
- else:
- return apacheServer.HandlerWrap(name, init=init)
-
-
diff --git a/backend/server/wsgi/wsgiRequest.py b/backend/server/wsgi/wsgiRequest.py
deleted file mode 100644
index e0106f9..0000000
--- a/backend/server/wsgi/wsgiRequest.py
+++ /dev/null
@@ -1,150 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-
-
-import socket
-from common import log_debug
-import httplib
-
-
-class WsgiRequest:
-
- def __init__(self, env, start_response):
- self.method = env['REQUEST_METHOD']
- self.headers_in = env
- self.path_info = env['PATH_INFO']
- self.start_response = start_response
- self.unparsed_uri = env['REQUEST_URI']
- self.server = WsgiServer(env['SERVER_NAME'], env['SERVER_PORT'])
- self.connection = WsgiConnection(env['REMOTE_ADDR'])
- self.options = {}
- self.main = 0
- self.proto_num = float(env['SERVER_PROTOCOL'].split('/')[1])
- self.headers_out = WsgiMPtable()
- self.sent_header = 0
- self.content_type = ""
- self.the_request = env['REQUEST_METHOD'] + " " +
env['SCRIPT_NAME'] + " " + env['SERVER_PROTOCOL']
- self.output = []
- self.err_headers_out = WsgiMPtable()
- self.status = ""
- self.sent_bodyct = 0
- self.sent_header = 0
-
- def set_option(self, key, value):
- self.options[key] = value
-
- def get_options(self):
- return self.options
-
- def get_config(self):
- return "" #FIXME
-
- def write(self, str):
- self.output.append(str)
-
- def send_http_header(self, status=None):
- self.sent_header = 1
-
- if status is not None:
- self.status = str(status)
- if len(self.status) == 0 or self.status == None:
- self.status = "200"
- elif self.status.startswith("500"):
- for i in self.err_headers_out.items():
- self.headers_out.add(i[0], i[1])
-
- self.status = self.status + " " + httplib.responses[int(self.status)]
-
- if len(self.content_type) > 0:
- self.headers_out['Content-Type'] = self.content_type
- #default to text/xml
- if not self.headers_out.has_key('Content-Type'):
- self.headers_out['Content-Type'] = 'text/xml'
-
- self.start_response(self.status, self.headers_out.items())
- return
-
- def get_remote_host(self, rev=""):
- host = self.headers_in['REMOTE_ADDR']
- try:
- host = socket.gethostbyaddr(host)[0]
- except:
- pass
- return host
-
- def read(self, buffer=-1):
- return self.headers_in['wsgi.input'].read(buffer)
-
-
-class WsgiServer:
- def __init__(self, hostname, port):
- self.server_hostname = hostname
- self.port = int(port)
-
-class WsgiConnection:
- def __init__(self, remote_ip):
- self.remote_ip = remote_ip
-
-class WsgiMPtable:
- """ This class emulates mod_python's mp_table. See
-
http://www.modpython.org/live/current/doc-html/pyapi-mptable.html
-
- The table object is a wrapper around the Apache APR table. The table
- object behaves very much like a dictionary (including the Python 2.2
- features such as support of the in operator, etc.), with the following
- differences:
-
- ...
- - Duplicate keys are allowed (see add() below). When there is more
- than one value for a key, a subscript operation returns a list.
-
- Much of the information that Apache uses is stored in tables.
- For example, req.headers_in and req.headers_out.
- """
- def __init__(self):
- self.dict = {}
-
- def add(self, key, value):
- if self.dict.has_key(key):
- self.dict[key].append(str(value))
- else:
- self.dict[key] = [str(value)]
-
- def __getitem__(self, key):
- if len(self.dict[key]) == 1:
- return self.dict[key][0]
- return self.dict[key]
-
- def __setitem__(self, key, value):
- self.dict[key] = [str(value)]
-
- def items(self):
- list = []
- for k,v in self.dict.items():
- for vi in v:
- list.append((k,vi))
- return list
-
- def has_key(self, key):
- return self.dict.has_key(key)
-
- def keys(self):
- return self.dict.keys()
-
- def __str__(self):
- return str(self.items())
-
diff --git a/backend/server/wsgi/xmlrpc.py b/backend/server/wsgi/xmlrpc.py
deleted file mode 100644
index de4fadd..0000000
--- a/backend/server/wsgi/xmlrpc.py
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response, "xmlrpc",
"server.xmlrpc")
diff --git a/backend/server/wsgi/xp.py b/backend/server/wsgi/xp.py
deleted file mode 100644
index f127690..0000000
--- a/backend/server/wsgi/xp.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Copyright (c) 2010 Red Hat, Inc.
-#
-# This software is licensed to you under the GNU General Public License,
-# version 2 (GPLv2). There is NO WARRANTY for this software, express or
-# implied, including the implied warranties of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
-# along with this software; if not, see
-#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
-#
-# Red Hat trademarks are not licensed under GPLv2. No permission is
-# granted to use or replicate Red Hat trademarks that are incorporated
-# in this software or its documentation.
-#
-#
-
-
-from server.wsgi import wsgiHandler
-
-def application(environ, start_response):
- return wsgiHandler.handle(environ, start_response,
"xp","server.xp")
diff --git a/backend/spacewalk-backend.spec b/backend/spacewalk-backend.spec
index 454a3d4..44b1de2 100644
--- a/backend/spacewalk-backend.spec
+++ b/backend/spacewalk-backend.spec
@@ -259,7 +259,7 @@ export PYTHON_MODULE_VERSION=%{version}
%if 0%{?rhel} && 0%{?rhel} < 6
rm -v $RPM_BUILD_ROOT/%{apacheconfd}/zz-spacewalk-server-wsgi.conf
-rm -rfv $RPM_BUILD_ROOT/%{rhnroot}/server/wsgi
+rm -rfv $RPM_BUILD_ROOT/%{rhnroot}/wsgi
%else
rm -v $RPM_BUILD_ROOT/%{apacheconfd}/zz-spacewalk-server-python.conf
%endif
@@ -324,6 +324,12 @@ rm -f %{rhnconf}/rhnSecret.py*
%attr(640,root,apache) %{rhnconf}/default/rhn.conf
%attr(755,root,root) %{_bindir}/spacewalk-cfg-get
%{_mandir}/man8/spacewalk-cfg-get.8.gz
+# wsgi stuff
+%if !( 0%{?rhel} && 0%{?rhel} < 6)
+%dir %{rhnroot}/wsgi
+%{rhnroot}/wsgi/wsgiHandler.py*
+%{rhnroot}/wsgi/wsgiRequest.py*
+%endif
%files sql
%defattr(-,root,root)
@@ -403,20 +409,17 @@ rm -f %{rhnconf}/rhnSecret.py*
%else
# wsgi stuff
%attr(640,root,apache) %config %{apacheconfd}/zz-spacewalk-server-wsgi.conf
-%dir %{rhnroot}/server/wsgi
-%{rhnroot}/server/wsgi/__init__.py*
-%{rhnroot}/server/wsgi/app.py*
-%{rhnroot}/server/wsgi/applet.py*
-%{rhnroot}/server/wsgi/config.py*
-%{rhnroot}/server/wsgi/config_tool.py*
-%{rhnroot}/server/wsgi/package_push.py*
-%{rhnroot}/server/wsgi/package_upload.py*
-%{rhnroot}/server/wsgi/sat.py*
-%{rhnroot}/server/wsgi/sat_dump.py*
-%{rhnroot}/server/wsgi/wsgiHandler.py*
-%{rhnroot}/server/wsgi/wsgiRequest.py*
-%{rhnroot}/server/wsgi/xmlrpc.py*
-%{rhnroot}/server/wsgi/xp.py*
+%{rhnroot}/wsgi/__init__.py*
+%{rhnroot}/wsgi/app.py*
+%{rhnroot}/wsgi/applet.py*
+%{rhnroot}/wsgi/config.py*
+%{rhnroot}/wsgi/config_tool.py*
+%{rhnroot}/wsgi/package_push.py*
+%{rhnroot}/wsgi/package_upload.py*
+%{rhnroot}/wsgi/sat.py*
+%{rhnroot}/wsgi/sat_dump.py*
+%{rhnroot}/wsgi/xmlrpc.py*
+%{rhnroot}/wsgi/xp.py*
%endif
# logs and other stuff
diff --git a/backend/wsgi/Makefile b/backend/wsgi/Makefile
new file mode 100644
index 0000000..40152a9
--- /dev/null
+++ b/backend/wsgi/Makefile
@@ -0,0 +1,10 @@
+# Makefile for the wsgi module
+
+TOP = ../..
+
+SUBDIR = wsgi
+
+FILES = __init__ app applet config config_tool package_push package_upload \
+ sat sat_dump wsgiHandler wsgiRequest xmlrpc xp
+
+include $(TOP)/Makefile.defs
diff --git a/backend/wsgi/__init__.py b/backend/wsgi/__init__.py
new file mode 100644
index 0000000..d7305c3
--- /dev/null
+++ b/backend/wsgi/__init__.py
@@ -0,0 +1,16 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
diff --git a/backend/wsgi/app.py b/backend/wsgi/app.py
new file mode 100644
index 0000000..fe81647
--- /dev/null
+++ b/backend/wsgi/app.py
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response,
"app","server.app")
diff --git a/backend/wsgi/applet.py b/backend/wsgi/applet.py
new file mode 100644
index 0000000..4a834fa
--- /dev/null
+++ b/backend/wsgi/applet.py
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response,
"applet","server.applet")
diff --git a/backend/wsgi/config.py b/backend/wsgi/config.py
new file mode 100644
index 0000000..9ccd965
--- /dev/null
+++ b/backend/wsgi/config.py
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response,
"config","server.config-management")
diff --git a/backend/wsgi/config_tool.py b/backend/wsgi/config_tool.py
new file mode 100644
index 0000000..2e9bc72
--- /dev/null
+++ b/backend/wsgi/config_tool.py
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response,
"config_mgmt","server.config-management-tool")
diff --git a/backend/wsgi/package_push.py b/backend/wsgi/package_push.py
new file mode 100644
index 0000000..ea8b435
--- /dev/null
+++ b/backend/wsgi/package_push.py
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response,
"package_push","server.upload.package-push", type="upload")
diff --git a/backend/wsgi/package_upload.py b/backend/wsgi/package_upload.py
new file mode 100644
index 0000000..22c03c9
--- /dev/null
+++ b/backend/wsgi/package_upload.py
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response,
"package","server.upload.package", type="upload")
diff --git a/backend/wsgi/sat.py b/backend/wsgi/sat.py
new file mode 100644
index 0000000..8a053b2
--- /dev/null
+++ b/backend/wsgi/sat.py
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response,
"sat","server.iss")
diff --git a/backend/wsgi/sat_dump.py b/backend/wsgi/sat_dump.py
new file mode 100644
index 0000000..d2104aa
--- /dev/null
+++ b/backend/wsgi/sat_dump.py
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response, "non_auth_dumper",
"server.satexport.internal", type='exporter')
diff --git a/backend/wsgi/wsgiHandler.py b/backend/wsgi/wsgiHandler.py
new file mode 100644
index 0000000..a3cd73a
--- /dev/null
+++ b/backend/wsgi/wsgiHandler.py
@@ -0,0 +1,78 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+
+from wsgi import wsgiRequest
+from server import apacheServer
+from server import apacheUploadServer
+from satellite_exporter import satexport
+
+from common import log_debug
+
+def handle(environ, start_response, server, component_type, type="normal"):
+ #wsgi seems to capitalize incoming headers and add HTTP- to the front :/
+ # so we strip out the first 5 letters, and transform it into what we want.
+ replacements = {'_':'-', 'Rhn':'RHN',
'Md5Sum':'MD5sum', 'Xml':'XML'}
+ for key in environ.keys():
+ if key[:5] == "HTTP_":
+ new_key = key[5:].title()
+ for k,v in replacements.iteritems():
+ new_key = new_key.replace(k,v)
+ environ[new_key] = environ[key]
+
+
+
+ req = wsgiRequest.WsgiRequest(environ, start_response)
+ req.set_option("SERVER", server)
+ req.set_option("RHNComponentType", component_type)
+ req.set_option("RootDir", "/usr/share/rhn")
+
+ parseServ = get_handle(type, "headerParserHandler", init=1)
+ ret = parseServ(req)
+
+ if len(req.output) > 0:
+ if not req.sent_header:
+ req.send_http_header(status=ret)
+ return req.output
+
+ appServ = get_handle(type, "handler")
+ ret = appServ(req)
+
+ if not ret:
+ ret = None
+
+ if not req.sent_header:
+ req.send_http_header(status=ret)
+
+ #exporter doesn't have a logHandler
+ if type != 'exporter':
+ logServ = get_handle(type, "logHandler")
+ logServ(req)
+ cleanServ = get_handle(type, "cleanupHandler")
+ cleanServ(req)
+
+ return req.output
+
+def get_handle(type, name, init=0):
+ if type == 'upload':
+ return apacheUploadServer.UploadHandlerWrap(name)
+ #the sat export module doesn't provide a nice server module
+ elif type == 'exporter':
+ return getattr(satexport, name)
+ else:
+ return apacheServer.HandlerWrap(name, init=init)
+
+
diff --git a/backend/wsgi/wsgiRequest.py b/backend/wsgi/wsgiRequest.py
new file mode 100644
index 0000000..e0106f9
--- /dev/null
+++ b/backend/wsgi/wsgiRequest.py
@@ -0,0 +1,150 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+
+
+import socket
+from common import log_debug
+import httplib
+
+
+class WsgiRequest:
+
+ def __init__(self, env, start_response):
+ self.method = env['REQUEST_METHOD']
+ self.headers_in = env
+ self.path_info = env['PATH_INFO']
+ self.start_response = start_response
+ self.unparsed_uri = env['REQUEST_URI']
+ self.server = WsgiServer(env['SERVER_NAME'], env['SERVER_PORT'])
+ self.connection = WsgiConnection(env['REMOTE_ADDR'])
+ self.options = {}
+ self.main = 0
+ self.proto_num = float(env['SERVER_PROTOCOL'].split('/')[1])
+ self.headers_out = WsgiMPtable()
+ self.sent_header = 0
+ self.content_type = ""
+ self.the_request = env['REQUEST_METHOD'] + " " +
env['SCRIPT_NAME'] + " " + env['SERVER_PROTOCOL']
+ self.output = []
+ self.err_headers_out = WsgiMPtable()
+ self.status = ""
+ self.sent_bodyct = 0
+ self.sent_header = 0
+
+ def set_option(self, key, value):
+ self.options[key] = value
+
+ def get_options(self):
+ return self.options
+
+ def get_config(self):
+ return "" #FIXME
+
+ def write(self, str):
+ self.output.append(str)
+
+ def send_http_header(self, status=None):
+ self.sent_header = 1
+
+ if status is not None:
+ self.status = str(status)
+ if len(self.status) == 0 or self.status == None:
+ self.status = "200"
+ elif self.status.startswith("500"):
+ for i in self.err_headers_out.items():
+ self.headers_out.add(i[0], i[1])
+
+ self.status = self.status + " " + httplib.responses[int(self.status)]
+
+ if len(self.content_type) > 0:
+ self.headers_out['Content-Type'] = self.content_type
+ #default to text/xml
+ if not self.headers_out.has_key('Content-Type'):
+ self.headers_out['Content-Type'] = 'text/xml'
+
+ self.start_response(self.status, self.headers_out.items())
+ return
+
+ def get_remote_host(self, rev=""):
+ host = self.headers_in['REMOTE_ADDR']
+ try:
+ host = socket.gethostbyaddr(host)[0]
+ except:
+ pass
+ return host
+
+ def read(self, buffer=-1):
+ return self.headers_in['wsgi.input'].read(buffer)
+
+
+class WsgiServer:
+ def __init__(self, hostname, port):
+ self.server_hostname = hostname
+ self.port = int(port)
+
+class WsgiConnection:
+ def __init__(self, remote_ip):
+ self.remote_ip = remote_ip
+
+class WsgiMPtable:
+ """ This class emulates mod_python's mp_table. See
+
http://www.modpython.org/live/current/doc-html/pyapi-mptable.html
+
+ The table object is a wrapper around the Apache APR table. The table
+ object behaves very much like a dictionary (including the Python 2.2
+ features such as support of the in operator, etc.), with the following
+ differences:
+
+ ...
+ - Duplicate keys are allowed (see add() below). When there is more
+ than one value for a key, a subscript operation returns a list.
+
+ Much of the information that Apache uses is stored in tables.
+ For example, req.headers_in and req.headers_out.
+ """
+ def __init__(self):
+ self.dict = {}
+
+ def add(self, key, value):
+ if self.dict.has_key(key):
+ self.dict[key].append(str(value))
+ else:
+ self.dict[key] = [str(value)]
+
+ def __getitem__(self, key):
+ if len(self.dict[key]) == 1:
+ return self.dict[key][0]
+ return self.dict[key]
+
+ def __setitem__(self, key, value):
+ self.dict[key] = [str(value)]
+
+ def items(self):
+ list = []
+ for k,v in self.dict.items():
+ for vi in v:
+ list.append((k,vi))
+ return list
+
+ def has_key(self, key):
+ return self.dict.has_key(key)
+
+ def keys(self):
+ return self.dict.keys()
+
+ def __str__(self):
+ return str(self.items())
+
diff --git a/backend/wsgi/xmlrpc.py b/backend/wsgi/xmlrpc.py
new file mode 100644
index 0000000..bf05256
--- /dev/null
+++ b/backend/wsgi/xmlrpc.py
@@ -0,0 +1,22 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response, "xmlrpc",
"server.xmlrpc")
diff --git a/backend/wsgi/xp.py b/backend/wsgi/xp.py
new file mode 100644
index 0000000..fe44ad2
--- /dev/null
+++ b/backend/wsgi/xp.py
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+#
+
+
+from wsgi import wsgiHandler
+
+def application(environ, start_response):
+ return wsgiHandler.handle(environ, start_response,
"xp","server.xp")