commit 0d205e8377c66442f8f960b582ca5b50257dc8ec
parent a3f5ead9876b5ae24b185d87a38e37edb78d32a1
Author: Adomas VenĨkauskas <adomas.ven@gmail.com>
Date: Fri, 21 Oct 2016 12:45:11 +0300
Connector server endpoint for reverse dns
Diffstat:
2 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/chrome/content/zotero/xpcom/proxy.js b/chrome/content/zotero/xpcom/proxy.js
@@ -35,12 +35,6 @@ Zotero.Proxies = new function() {
this.transparent = false;
this.hosts = {};
- var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var myHostName = null;
- var myCanonicalHostName = null;
/**
* Initializes http-on-examine-response observer to intercept page loads and gets preferences
@@ -218,9 +212,7 @@ Zotero.Proxies = new function() {
function _maybeRedirect(channel, browser, window, proxied) {
channel.QueryInterface(Components.interfaces.nsIHttpChannel);
- var proxiedURI = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService)
- .newURI(proxied, null, null);
+ var proxiedURI = Services.io.newURI(proxied, null, null);
if(channel.referrer) {
// If the referrer is a proxiable host, we already have access (e.g., we're
// on-campus) and shouldn't redirect
@@ -366,7 +358,7 @@ Zotero.Proxies = new function() {
* @type String
*/
this.properToProxy = function(url, onlyReturnIfProxied) {
- var uri = ioService.newURI(url, null, null);
+ var uri = Services.io.newURI(url, null, null);
if(Zotero.Proxies.hosts[uri.hostPort] && Zotero.Proxies.hosts[uri.hostPort].proxyID) {
var toProxy = Zotero.Proxies.hosts[uri.hostPort].toProxy(uri);
Zotero.debug("Proxies.properToProxy: "+url+" to "+toProxy);
@@ -964,16 +956,14 @@ Zotero.Proxies.Detectors.Juniper = function(channel) {
}
Zotero.Proxies.DNS = new function() {
- var _callbacks = [];
-
this.getHostnames = function() {
- if (!Zotero.isWin && !Zotero.isMac && !Zotero.isLinux) return Q([]);
- var deferred = Q.defer();
+ if (!Zotero.isWin && !Zotero.isMac && !Zotero.isLinux) return Zotero.Promise.resolve([]);
+ var deferred = Zotero.Promise.defer();
var worker = new ChromeWorker("chrome://zotero/content/xpcom/dns_worker.js");
Zotero.debug("Proxies.DNS: Performing reverse lookup");
worker.onmessage = function(e) {
Zotero.debug("Proxies.DNS: Got hostnames "+e.data);
- deferred.resolve(e.data);
+ deferred.resolve(e.data);
};
worker.onerror = function(e) {
Zotero.debug("Proxies.DNS: Reverse lookup failed");
diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js
@@ -679,6 +679,37 @@ Zotero.Server.Connector.GetSelectedCollection.prototype = {
}
}
+/**
+ * Get a list of client hostnames (reverse local IP DNS)
+ *
+ * Accepts:
+ * Nothing
+ * Returns:
+ * {Array} hostnames
+ */
+Zotero.Server.Connector.GetClientHostnames = {};
+Zotero.Server.Connector.GetClientHostnames = function() {};
+Zotero.Server.Endpoints["/connector/getClientHostnames"] = Zotero.Server.Connector.GetClientHostnames;
+Zotero.Server.Connector.GetClientHostnames.prototype = {
+ "supportedMethods":["POST"],
+ "supportedDataTypes":["application/json"],
+ "permitBookmarklet":false,
+
+ /**
+ * Returns a 200 response to say the server is alive
+ * @param {String} data POST data or GET query string
+ * @param {Function} sendResponseCallback function to send HTTP response
+ */
+ "init":Zotero.Promise.coroutine(function* (url, postData, sendResponseCallback) {
+ try {
+ var hostnames = yield Zotero.Proxies.DNS.getHostnames();
+ } catch(e) {
+ sendResponseCallback(500);
+ }
+ sendResponseCallback(200, "application/json", JSON.stringify(hostnames));
+ })
+};
+
/**
* Test connection