]>
Commit | Line | Data |
---|---|---|
93b35dff C |
1 | /* |
2 | ||
3 | SASL plugin for ChatZilla. | |
4 | ||
5 | ChatZilla is a clean, easy to use and highly extensible Internet Relay Chat (IRC) client. | |
6 | Get it here: https://addons.mozilla.org/addon/16 | |
7 | ||
8 | How do I install scripts? | |
9 | http://chatzilla.hacksrus.com/faq/#install-script | |
10 | ||
11 | ***************************************************************************************** | |
12 | ||
13 | Plugin usage. | |
14 | ||
15 | ||
16 | /plugin-pref cz_sasl | |
17 | /plugin-pref cz_sasl sasl.username YOUR_USERNAME | |
18 | /plugin-pref cz_sasl sasl.password YOUR_PASSWORD | |
19 | /plugin-pref cz_sasl sasl.proceed_on_fail (true|false) | |
20 | ||
21 | ***************************************************************************************** | |
22 | ||
23 | How to enable debug mode. | |
24 | ||
25 | - Set ``browser.dom.window.dump.enabled'' to true in ``about:config''. | |
26 | - Run ``/pref debugMode cdt'' in ChatZilla. | |
27 | - Start ChatZilla from console, like ``seamonkey -chat'' or ``firefox.exe -chat -console''. | |
28 | ||
29 | ***************************************************************************************** | |
30 | ||
31 | Raw SASL. | |
32 | ||
33 | ~$ telnet irc.freenode.net 6667 | |
34 | Trying 78.40.125.4... | |
35 | Connected to chat.freenode.net. | |
36 | Escape character is '^]'. | |
37 | :barjavel.freenode.net NOTICE * :*** Looking up your hostname... | |
38 | :barjavel.freenode.net NOTICE * :*** Checking Ident | |
39 | :barjavel.freenode.net NOTICE * :*** Found your hostname | |
40 | CAP LS | |
41 | NICK test | |
42 | USER test test irc.freenode.net :test | |
43 | :barjavel.freenode.net NOTICE * :*** No Ident response | |
44 | :barjavel.freenode.net CAP * LS :identify-msg multi-prefix sasl | |
45 | CAP REQ :multi-prefix sasl | |
46 | :barjavel.freenode.net CAP test ACK :multi-prefix sasl | |
47 | AUTHENTICATE PLAIN | |
48 | AUTHENTICATE + | |
49 | AUTHENTICATE R3...WYx <-- 'nick\0nick\0pass' encoded base64 | |
50 | :barjavel.freenode.net 900 test test!test@unaffiliated.test acnt :You are now logged in as Gryllida. | |
51 | :barjavel.freenode.net 903 test :SASL authentication successful | |
52 | CAP END | |
53 | ||
54 | ||
55 | ||
56 | ***************************************************************************************** | |
57 | ||
58 | (C) 2011 Gryllida A <Gryllida@gmail.com> | |
59 | ||
60 | */ | |
61 | ||
62 | ||
63 | plugin.id = "cz_sasl"; | |
64 | ||
65 | ||
66 | plugin.init = | |
67 | function initPlugin(glob){ | |
68 | plugin.major = 0; | |
69 | plugin.minor = 4; | |
70 | plugin.version = plugin.major + "." + plugin.minor; | |
71 | plugin.description = "Adds sasl authentication support. To setup, |/plugin-pref cz_sasl|"; | |
72 | plugin.prefary = plugin.prefary.concat([ | |
73 | ["sasl.servername", "chat.freenode.net"], | |
74 | ["sasl.username",""], | |
75 | ["sasl.password",""], | |
76 | ["sasl.proceed_on_fail",false] | |
77 | ]); | |
78 | display(plugin.id + " loaded from url " + plugin.url); | |
79 | return "OK"; | |
80 | } | |
81 | ||
82 | plugin.disable = | |
83 | function disablePlugin(status){ | |
84 | display("disabling " + plugin.id); | |
85 | client.eventPump.removeHookByName(plugin.id+"hook-cap"); | |
86 | client.eventPump.removeHookByName(plugin.id+"hook-connect"); | |
87 | return true; // Do NOT keep enabled without errors. | |
88 | } | |
89 | ||
90 | plugin.enable = | |
91 | function enablePlugin(status){ | |
92 | display("enabling " + plugin.id); | |
93 | client.eventPump.addHook([{ set: /^(server|channel|user)$/, type: "parseddata" }], hook_cap, plugin.id+"hook-cap"); | |
94 | client.eventPump.addHook([{ set: /^(server|channel|user)$/, type: "connect" }], hook_connect, plugin.id+"hook-connect"); | |
95 | ||
96 | return true; | |
97 | } | |
98 | ||
99 | function hook_connect(e){ | |
100 | if (e.server.hostname==plugin.prefs["sasl.servername"] && e.type=="connect"){ | |
101 | e.server.sendData("CAP LS\n"); | |
102 | } | |
103 | } | |
104 | ||
105 | function hook_cap(e){ | |
106 | if (e.server.hostname==plugin.prefs["sasl.servername"]){ | |
107 | if (e.params[0]=="CAP" && e.params[2]=="LS"){ | |
108 | e.server.sendData("CAP REQ :sasl\n"); | |
109 | display("CAP REQ :multi-prefix sasl"); | |
110 | } | |
111 | else if (e.params[3]=="sasl "){ | |
112 | e.server.sendData("AUTHENTICATE PLAIN\n"); | |
113 | display("AUTHENTICATE PLAIN"); | |
114 | } | |
115 | else if (e.data == "AUTHENTICATE +"){ | |
116 | stuff = window.btoa(plugin.prefs["sasl.username"]+'\0'+plugin.prefs["sasl.username"]+'\0'+plugin.prefs["sasl.password"]); | |
117 | e.server.sendData("AUTHENTICATE "+stuff+"\n"); | |
118 | display("AUTHENTICATE "+stuff); | |
119 | } | |
120 | else if (e.params[0]=="903"){ | |
121 | e.server.sendData("CAP END\n"); | |
122 | display("CAP END"); | |
123 | } | |
124 | else if (e.params[0]=="904" || e.params[0]=="905"){ | |
125 | e.server.sendData("CAP END\n"); | |
126 | display("SASL authentication failed - invalid login or password. Please use the accountname (not a nick) as username, and try again.","warning"); | |
127 | if(plugin.prefs["sasl.proceed_on_fail"]==false){ | |
128 | dispatch("cancel"); | |
129 | } | |
130 | } | |
131 | } | |
132 | } | |
133 |