[bugzilla-gnome-org-extensions] Make proxy do substitutions in config.js, add configNote
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bugzilla-gnome-org-extensions] Make proxy do substitutions in config.js, add configNote
- Date: Thu, 20 Nov 2014 22:18:22 +0000 (UTC)
commit f500933b8b4298a639927e98f53e690a37fbf845
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Sat Sep 12 19:48:35 2009 -0400
Make proxy do substitutions in config.js, add configNote
splinter_proxy.py now handles config.js directly and can substitute:
@@BUGZILLA_URL@@
@@NOTE@@
When running an anonymous proxy, the second is substituted to a warning
that the instance is read-only, and this his hooked up to be displayed
in a promiment banner across all pages.
js/splinter.js | 10 ++++++++
proxy/README | 2 +
proxy/splinter_proxy.py | 54 +++++++++++++++++++++++++++++++++++++++++-----
web/config.js.example | 10 +++++++-
web/index.html | 4 +-
web/splinter.css | 5 ++++
6 files changed, 76 insertions(+), 9 deletions(-)
---
diff --git a/js/splinter.js b/js/splinter.js
index 418f3ab..404b252 100644
--- a/js/splinter.js
+++ b/js/splinter.js
@@ -462,6 +462,7 @@ function gotBug(xml) {
theBug = Bug.Bug.fromDOM(xml);
$("#headers").show();
+ showNote();
$("#bugId").text(theBug.id);
$("#bugShortDesc").text(theBug.shortDesc);
@@ -505,7 +506,16 @@ function newPageUrl(newBugId, newAttachmentId) {
return newUrl;
}
+function showNote() {
+ if (configNote)
+ $("#note")
+ .text(configNote)
+ .show();
+}
+
function showEnterBug() {
+ showNote();
+
$("#enterBugGo").click(function() {
var newBugId = Utils.strip($("#enterBugInput").val());
document.location = newPageUrl(newBugId);
diff --git a/proxy/README b/proxy/README
index 3ca7503..251a6b8 100644
--- a/proxy/README
+++ b/proxy/README
@@ -29,6 +29,8 @@ login access to you should be OK.
Usage
=====
+* Copy config.js.example in the $(topdir)/web to config.js; you
+ probably won't need to edit it.
* Copy config.py.example to config.py
* Replace 'bugzilla.example.com' with your server, and edit
bugzilla_login, and bugzilla_password appropriately.
diff --git a/proxy/splinter_proxy.py b/proxy/splinter_proxy.py
index 09c0aa2..cd6f0a3 100755
--- a/proxy/splinter_proxy.py
+++ b/proxy/splinter_proxy.py
@@ -8,6 +8,7 @@ import os
from SimpleHTTPServer import SimpleHTTPRequestHandler
import socket
from SocketServer import ForkingMixIn
+import time
import urlparse
import re
import sys
@@ -34,6 +35,12 @@ def is_proxied(path):
# Cookie values we'll send to Bugzilla if logged in
login_cookie_header = None
+# Time we started the proxy server
+start_time = time.time()
+
+# Content for config.js
+config_js_content = None
+
# Convert an URL we received from a client to all the information we'll
# need to proxy to the Bugzilla server - host, port, new path, etc.
def get_proxy_info(path):
@@ -169,6 +176,18 @@ class ProxyHandler(SimpleHTTPRequestHandler):
connection.close()
+ def do_config_js(self):
+ self.send_response(200, "OK")
+ self.send_header("Content-type", "text/javascript")
+ self.send_header("Content-Length", str(len(config_js_content)))
+ self.send_header("Last-Modified", self.date_time_string(start_time))
+ self.end_headers()
+
+ if (self.command == 'GET'):
+ self.wfile.write(config_js_content)
+
+ self.wfile.close()
+
# Overrides
def version_string(self):
@@ -177,16 +196,18 @@ class ProxyHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if is_proxied(self.path):
self.do_proxied()
- return
-
- SimpleHTTPRequestHandler.do_GET(self)
+ elif self.path == "/config.js":
+ self.do_config_js()
+ else:
+ SimpleHTTPRequestHandler.do_GET(self)
def do_HEAD(self):
if is_proxied(self.path):
self.do_proxied()
- return
-
- SimpleHTTPRequestHandler.do_HEAD(self)
+ elif self.path == "/config.js":
+ self.do_config_js()
+ else:
+ SimpleHTTPRequestHandler.do_HEAD(self)
def do_POST(self):
if is_proxied(self.path):
@@ -284,6 +305,25 @@ def login():
print >>sys.stderr, "Can't log in to %s: %s" % (current_config['bugzilla_url'],
e.args[1])
+def read_config_js():
+ try:
+ f = open("../web/config.js")
+ except IOError:
+ print >>sys.stderr, "web/config.js doesn't exist; you need to create it from config.js.example"
+ sys.exit(1)
+
+ content = f.read()
+ f.close()
+
+ content = content.replace('@@BUGZILLA_URL@@', current_config['bugzilla_url'])
+ if 'bugzilla_login' in current_config and 'bugzilla_login' in current_config:
+ note = ''
+ else:
+ note = 'This is a read-only demo instance of Splinter; you will not be able to publish your reviews'
+ content = content.replace('@@NOTE@@', note)
+
+ return content
+
########################################
# SimpleHTTPRequestHandler serves files relative to the current working directory
@@ -306,6 +346,8 @@ if not config_name in config.configs:
current_config = config.configs[config_name]
+config_js_content = read_config_js()
+
if 'bugzilla_login' in current_config and 'bugzilla_login' in current_config:
if 'proxy_bind' in current_config and current_config['proxy_bind'] != '127.0.0.1':
# anybody connecting to the proxy can do ABSOLUTELY ANYTHING
diff --git a/web/config.js.example b/web/config.js.example
index a272ff0..ff69653 100644
--- a/web/config.js.example
+++ b/web/config.js.example
@@ -1,5 +1,13 @@
+# @@<name>@@ substituations are done by splinter_proxy.py; they should be be
+# replaced with the actual values for a production install.
+
# Base URL for links to Bugzilla
-configBugzillaUrl = 'http://bugzilla.gnome.org';
+#configBugzillaUrl = 'http://bugzilla.gnome.org';
+configBugzillaUrl = '@@BUGZILLA_URL@@';
+
+# Note displayed at the top of every page
+#configNote = ''
+configNote = '@@NOTE@@'
# These are the attachment statuses for bugzilla.gnome.org, which is
# the only Bugzilla instance I'm aware that supports attachment statuses
diff --git a/web/index.html b/web/index.html
index d475755..d7aa0c3 100644
--- a/web/index.html
+++ b/web/index.html
@@ -23,9 +23,9 @@
<span id="attachmentDate"></span>
</div>
</div>
+ <div id="note" style="display: none;></div>
+ <div id="error" style="display: none;"> </div>
<div id="loading">Loading....</div>
- <div id="error" style="display: none;">
- </div>
<div id="enterBug" style="display: none;">
Bug to review:
<input id="enterBugInput"></input>
diff --git a/web/splinter.css b/web/splinter.css
index 44d6261..acc9a50 100644
--- a/web/splinter.css
+++ b/web/splinter.css
@@ -17,6 +17,11 @@ body {
color: white;
}
+#note {
+ background: #ffee88;
+ padding: 0.5em;
+}
+
#error {
border: 1px solid black;
margin: 0.5em;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]