aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libbugzilla.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libbugzilla.js')
-rw-r--r--lib/libbugzilla.js156
1 files changed, 90 insertions, 66 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 62df80b..d03cd3c 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -22,12 +22,11 @@ var copiedAttributes = [ "queryButton", "upstreamButton", "parseAbrtBacktraces",
"suspiciousComponents", "verboseInlineHistory" ];
-var passwords = {}; // hash of passwords indexed by a hostname
var config = exports.config = {};
-var debugOption = false;
+var debugOption = null;
function Message(cmd, data) {
- console.log("Message: cmd = " + cmd + ", data = " + data);
+ debug("Message: cmd = " + cmd + ", data = " + data);
this.cmd = cmd;
this.data = data;
}
@@ -84,53 +83,67 @@ function getRealBugNoSlow(bugNo, location, callback) {
function getPassword(login, domain, callback) {
var passPrompt = "Enter your Bugzilla password " +
"for accessing JSONRPC services";
- var switchPrompt = "Do you want to switch off features " +
- "requiring password completely";
- var prefName = BTSPrefNS+"withoutPassowrd";
+ var switchPrompt = "Do you want to switch off XML-RPC " +
+ "for domain ";
+ var prefName = BTSPrefNS+"withoutPassowrd", prefValue = [];
var retObject = {
password: null, // password string or null if no password provided
- withoutPass: false // whether user doesn't want to use password at all
+ withoutPass: [] // whether user doesn't want to use password at all
};
- passUtils.search({
- username: login,
- url: domain,
- realm: BTSPassRealm,
- onComplete: function onComplete([credential]) {
- if (credential) {
- // We found the password, just go ahead and use it
- retObject.password = credential.password;
- callback(retObject);
- }
- else {
- // We don't have a stored password, ask for one
- var passwordText = prompts.promptPassword(passPrompt);
- if (passwordText && passwordText.length > 0) {
- // Right, we've got it … store it and then use it.
- retObject.password = passwordText;
- passUtils.store({
- username: login,
- password: passwordText,
- url: domain,
- realm: BTSPassRealm,
- onComplete: function onComplete() {
- callback(retObject);
- }
- });
+ if (preferences.has(prefName)) {
+ prefValue = JSON.parse(preferences.get(prefName, null));
+ debug("getPassword: prefValue = " + prefValue);
+ if ((prefValue === true) || (prefValue === false)) {
+ console.log("Clearing previous scheme of " + prefName +
+ " preference " + prefValue + ".");
+ preferences.set(prefName, JSON.stringify([]));
+ prefValue = [];
+ }
+ }
+
+ if (prefValue.indexOf(domain) == -1) {
+ passUtils.search({
+ username: login,
+ url: domain,
+ realm: BTSPassRealm,
+ onComplete: function onComplete([credential]) {
+ if (credential) {
+ // We found the password, just go ahead and use it
+ retObject.password = credential.password;
+ callback(retObject);
}
else {
- // We don't have password, and user haven't entered one?
- // Does he want to live passwordless?
- var switchOff = prompts.promptYesNoCancel(switchPrompt);
- if (switchOff) {
- preferences.set(prefName,true);
+ // We don't have a stored password, ask for one
+ var passwordText = prompts.promptPassword(passPrompt);
+ if (passwordText && passwordText.length > 0) {
+ // Right, we've got it … store it and then use it.
+ retObject.password = passwordText;
+ passUtils.store({
+ username: login,
+ password: passwordText,
+ url: domain,
+ realm: BTSPassRealm,
+ onComplete: function onComplete() {
+ callback(retObject);
+ }
+ });
+ }
+ else {
+ // We don't have password, and user haven't entered one?
+ // Does he want to live passwordless for this domain?
+ var switchOff = prompts.promptYesNoCancel(switchPrompt + domain + "?");
+ if (switchOff) {
+ prefValue.push(domain);
+ preferences.set(prefName, JSON.stringify(prefValue));
+ }
+ retObject.withoutPass = prefValue;
+ callback(retObject);
}
- retObject.withoutPass = switchOff;
- callback(retObject);
}
}
- }
- });
+ });
+ }
}
// Change URL of the configuration JSON file
@@ -214,9 +227,8 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c
// In order to avoid sending whole password to the content script,
// we are sending just these two Booleans.
config.constantData.passwordState = {
- password: passwObj.password,
- passAvailable: (passwObj.password !== null),
- withoutPass: passwObj.withoutPass
+ passAvailable: (passwObj.password !== null),
+ withoutPass: passwObj.withoutPass.indexOf(passDomain) === -1
};
callback(new Message("CreateButtons", {
@@ -281,28 +293,40 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subjectStr, comme
});
};
-exports.makeJSONRPCCallWithLogin = function makeJSONRPCCallWithLogin(url, method,
- params, login, callback) {
- var urlObj = urlMod.URL(url);
- getPassword(login,
- urlObj.scheme + "://" + urlObj.host,
- function (passObj) {
- if (!passObj.password) {
- return;
+function loginToAllBugzillas(callback) {
+ var callbacksCounter = 0, bugzilla = "";
+ if ("enabledPackages" in config.gJSONData.configData) {
+ for (bugzillaHost in config.gJSONData.configData.enabledPackages) {
+ passUtils.search({
+ url: "https://" + bugzillaHost,
+ realm: BTSPassRealm,
+ onComplete: function onComplete(credentials) {
+ credentials.forEach(function(credential) {
+ debug("credential = " + credential.toSource());
+ // function makeJSONRPCCall(url, method, params, callback)
+ makeJSONRPCCall(credential.url + "/jsonrpc.cgi",
+ "User.login", {
+ login: credential.username,
+ password: credential.password,
+ remember: false
+ }, function(logResult) {
+ debug("Logging as " + credential.username + " to " + credential.url);
+ callbacksCounter--;
+ if (callbacksCounter <= 0) {
+ debug("All logins done!");
+ callback();
+ }
+ });
+ callbacksCounter++;
+ });
+ },
+ onError: function onError() {
+ console.error("No credentials were found for " + bugzillaHost + "!");
}
-
- debug("makeJSONRPCCallWithLogin: passObj = " +
- passObj.toSource());
- makeJSONRPCCall(url, "User.login", {
- login: login,
- password: passObj.password,
- remember: false
- }, function(logResult) {
- makeJSONRPCCall(url, method, params, callback);
- });
- }
- );
-};
+ });
+ }
+ }
+}
// Make a JSONL-RPC call ... most of the business logic should stay in the
// content script
@@ -406,7 +430,7 @@ exports.initialize = function initialize(config, callback) {
logger.initialize();
}
}
- callback();
+ loginToAllBugzillas(callback);
}
}).get();
}