Skip to content
Snippets Groups Projects
Commit 6dc5fed6 authored by Aleksy Barcz's avatar Aleksy Barcz
Browse files

xslt fixes

parent 0fd8db94
No related branches found
Tags custom-nopy30
No related merge requests found
...@@ -45,19 +45,23 @@ class XsltHandler: ...@@ -45,19 +45,23 @@ class XsltHandler:
Request handler - checks for 'type' and serves document using Request handler - checks for 'type' and serves document using
proper stylesheet. proper stylesheet.
""" """
def __init__(self, uri, paramd_uri, query_string): def __init__(self, environ, uri, paramd_uri, query_string):
""" """
Initialization - save request object Initialization - save request object
""" """
self.environ = environ
self.uri = uri self.uri = uri
self.paramd_uri = paramd_uri self.paramd_uri = paramd_uri
self.query_string = query_string self.query_string = query_string
self.timeout = 2.0 self.timeout = 2.0
self.got_timeout = False self.got_timeout = False
def __log_error(self, error_string):
print(error_string, file=self.environ['wsgi.errors']))
def isl_vu(self, context, args): def isl_vu(self, context, args):
if self.got_timeout: if self.got_timeout:
#self.req.log_error('isl_vu: already got timeout - not doing request', apache.APLOG_WARNING) self.__log_error('isl_vu: already got timeout - not doing request')
return u'----' return u'----'
url = args[0] url = args[0]
...@@ -66,7 +70,7 @@ class XsltHandler: ...@@ -66,7 +70,7 @@ class XsltHandler:
r = requests.get(url, timeout=self.timeout) r = requests.get(url, timeout=self.timeout)
if (r.status_code != 200): if (r.status_code != 200):
#self.req.log_error('isl_vu status_code: %d' % r.status_code, apache.APLOG_WARNING) self.__log_error('isl_vu status_code: %d' % r.status_code)
return u'----' return u'----'
doc = etree.fromstring(r.content, parser) doc = etree.fromstring(r.content, parser)
...@@ -75,11 +79,10 @@ class XsltHandler: ...@@ -75,11 +79,10 @@ class XsltHandler:
return vu return vu
except requests.exceptions.Timeout as e: except requests.exceptions.Timeout as e:
#self.req.log_error('isl_vu http timeout for url: %s' % url, apache.APLOG_WARNING) self.__log_error('isl_vu http timeout for url: %s' % url)
self.got_timeout = True self.got_timeout = True
except Exception as e: except Exception as e:
#self.req.log_error('isl_vu url: %s get error: %s' % (url, str(e)), apache.APLOG_ERR) self.__log_error('isl_vu url: %s get error: %s' % (url, str(e)))
pass
return u'----' return u'----'
...@@ -115,7 +118,7 @@ class XsltHandler: ...@@ -115,7 +118,7 @@ class XsltHandler:
try: try:
r = stylesheet(doc, uri = "'" + self.paramd_uri + "'") r = stylesheet(doc, uri = "'" + self.paramd_uri + "'")
except Exception as e: except Exception as e:
#self.req.log_error('content: stylesheet failed %s' % str(e), apache.APLOG_ERR) self.__log_error('content: stylesheet failed %s' % str(e))
r = stylesheet.error_log r = stylesheet.error_log
return str(r) return str(r)
...@@ -141,7 +144,7 @@ def application(environ, start_response): ...@@ -141,7 +144,7 @@ def application(environ, start_response):
response_headers = [('Content-type', 'image/svg+xml')] response_headers = [('Content-type', 'image/svg+xml')]
start_response(status, response_headers) start_response(status, response_headers)
# paramd.uri should be set in Apache configuration file using SetEnv # paramd.uri should be set in Apache configuration file using SetEnv
h = XsltHandler(requested_path, environ['szarp.paramd.uri'], parse_qs(environ['QUERY_STRING'])) h = XsltHandler(environ, requested_path, environ['szarp.paramd.uri'], parse_qs(environ['QUERY_STRING']))
ret = h.content() ret = h.content()
return [ret.encode('utf-8')] return [ret.encode('utf-8')]
else: else:
......
...@@ -20,7 +20,7 @@ NameVirtualHost *:8084 ...@@ -20,7 +20,7 @@ NameVirtualHost *:8084
ExpiresDefault "access plus 9 seconds" ExpiresDefault "access plus 9 seconds"
#RewriteEngine On #RewriteEngine On
# Include user supplied configuration files # Include user supplied configuration files
IncludeOptional /etc/szarp/default/config/*.apache IncludeOptional /etc/szarp/default/config/*.apache
...@@ -31,7 +31,7 @@ NameVirtualHost *:8084 ...@@ -31,7 +31,7 @@ NameVirtualHost *:8084
# Everything else is forbidden # Everything else is forbidden
#RewriteRule .* / [F] #RewriteRule .* / [F]
# 'Deny all' rule if something slips through above rewrite rule # 'Deny all' rule if something slips through above rewrite rule
<Directory /> <Directory />
Require all denied Require all denied
...@@ -42,7 +42,7 @@ NameVirtualHost *:8084 ...@@ -42,7 +42,7 @@ NameVirtualHost *:8084
<Directory /etc/szarp/default/config/isl> <Directory /etc/szarp/default/config/isl>
Require all granted Require all granted
</Directory> </Directory>
# CGI directory # CGI directory
ScriptAlias /cgi-bin /opt/szarp/bin ScriptAlias /cgi-bin /opt/szarp/bin
<Directory /opt/szarp/bin> <Directory /opt/szarp/bin>
...@@ -51,7 +51,7 @@ NameVirtualHost *:8084 ...@@ -51,7 +51,7 @@ NameVirtualHost *:8084
Require all granted Require all granted
SetEnv szarp.paramd.uri "http://localhost:8081/" SetEnv szarp.paramd.uri "http://localhost:8081/"
</Directory> </Directory>
ErrorLog /var/log/szarp/apache-error.log ErrorLog /var/log/szarp/apache-error.log
CustomLog /var/log/szarp/apache-access.log combined CustomLog /var/log/szarp/apache-access.log combined
...@@ -62,7 +62,7 @@ NameVirtualHost *:8084 ...@@ -62,7 +62,7 @@ NameVirtualHost *:8084
LogLevel debug LogLevel debug
ScriptLog /var/log/szarp/apache-cgi.log ScriptLog /var/log/szarp/apache-cgi.log
</IfDefine> </IfDefine>
ServerSignature Off ServerSignature Off
</VirtualHost> </VirtualHost>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment