|
/* This Source Code Form is subject to the terms of the Mozilla Public |
|
* License, v. 2.0. If a copy of the MPL was not distributed with this |
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
/* |
|
* SASL plugin for ChatZilla. |
|
* |
|
* ChatZilla is a clean, easy to use and highly extensible Internet Relay Chat (IRC) client. |
|
* Get it here: https://addons.mozilla.org/addon/16 |
|
* Standalone version here: http://chatzilla.rdmsoft.com/xulrunner/ |
|
* |
|
* How do I install scripts? |
|
* http://chatzilla.hacksrus.com/faq/#install-script |
|
* |
|
* ***************************************************************************************** |
|
* |
|
* Plugin usage: |
|
* |
|
* /plugin-pref cz_sasl |
|
* /plugin-pref cz_sasl sasl.servername SERVER_THAT_SUPPORTS_SASL |
|
* /plugin-pref cz_sasl sasl.username YOUR_USERNAME |
|
* /plugin-pref cz_sasl sasl.password YOUR_PASSWORD |
|
* /plugin-pref cz_sasl sasl.proceed_on_fail (true|false) |
|
* |
|
* ***************************************************************************************** |
|
* |
|
* (C) 2011 Gryllida A <Gryllida@gmail.com> |
|
* (C) 2013 auscompgeek <auscompgeek@myopera.com> |
|
*/ |
|
|
|
plugin.id = "cz_sasl"; |
|
|
|
plugin.init = |
|
function initPlugin(glob) { |
|
this.major = 0; |
|
this.minor = 6; |
|
this.version = this.major + "." + this.minor; |
|
this.description = "Adds SASL authentication support. To setup, |/plugin-pref cz_sasl|"; |
|
|
|
this.prefary = this.prefary.concat([ |
|
["sasl.servername", "chat.freenode.net", ""], |
|
["sasl.username", "", ""], |
|
["sasl.password", "", ""], |
|
["sasl.proceed_on_fail", false, ""] |
|
]); |
|
|
|
return "OK"; |
|
}; |
|
|
|
plugin.enable = |
|
function enablePlugin(status) { |
|
client.eventPump.addHook([{ set: "server", type: "parseddata" }], this.onData, this.id + "-hook-data"); |
|
client.eventPump.addHook([{ set: "server", type: "connect" }], this.onconnect, this.id + "-hook-connect"); |
|
|
|
return true; |
|
}; |
|
|
|
plugin.disable = |
|
function disablePlugin(status) { |
|
client.eventPump.removeHookByName(this.id + "-hook-data"); |
|
client.eventPump.removeHookByName(this.id + "-hook-connect"); |
|
|
|
return true; |
|
}; |
|
|
|
plugin.onConnect = |
|
function onConnect(e) { |
|
if (e.server.hostname === this.prefs["sasl.servername"]) { |
|
e.server.performSASLChecks = true; |
|
e.server.sendData("CAP LS\n"); |
|
} |
|
}; |
|
|
|
plugin.onData = |
|
function onData(e) { |
|
if (!e.server.performSASLChecks) { |
|
return; |
|
} |
|
|
|
if (e.data === "AUTHENTICATE +") { |
|
// Response to "AUTHENTICATE" command. Server has given us the OK to authenticate. |
|
var auth = btoa(this.prefs["sasl.username"] + '\0' + this.prefs["sasl.username"] + '\0' + this.prefs["sasl.password"]); |
|
e.server.sendData("AUTHENTICATE " + auth + "\n"); |
|
return; |
|
} |
|
|
|
switch (e.params[0]) { |
|
case "CAP": |
|
// Response to CAP command. |
|
if (e.params[2] === "LS") { |
|
// Response to CAP LS command: listing of extended capabilities. |
|
var capList = e.params[3]; |
|
e.server.parent.display("This server supports extended capabilities: " + capList); |
|
|
|
capList = capList.split(" "); |
|
if (capList.indexOf("sasl") !== -1) { |
|
e.server.sendData("CAP REQ :sasl\n"); |
|
} |
|
|
|
// We don't want to show the user the raw message now. |
|
return true; |
|
} |
|
|
|
if (e.params[2] === "ACK" && e.params[3] === "sasl ") { |
|
// Response to "CAP REQ :sasl". Start authentication process. |
|
e.server.sendData("AUTHENTICATE PLAIN\n"); |
|
} |
|
|
|
break; |
|
|
|
case "903": |
|
// Authentication succeeded, continue connecting. |
|
e.server.performSASLChecks = false; |
|
e.server.sendData("CAP END\n"); |
|
break; |
|
|
|
case "904": case "905": |
|
// Authentication failed. |
|
e.server.performSASLChecks = false; |
|
e.server.sendData("CAP END\n"); |
|
|
|
e.server.parent.display("SASL authentication failed - invalid username or password. " + |
|
"Please use the account name (not a nick) as the username, and try again.", "WARNING"); |
|
|
|
if (!plugin.prefs["sasl.proceed_on_fail"]) { |
|
// Disconnect if we're configured to stop if we fail. |
|
e.server.dispatch("cancel"); |
|
} |
|
|
|
break; |
|
} |
|
}; |
Can I use this script with multiple different servers?