|
@@ -8,25 +8,22 @@ import (
|
8
|
8
|
"strings"
|
9
|
9
|
|
10
|
10
|
"github.com/goshuirc/irc-go/ircfmt"
|
11
|
|
- "github.com/oragono/oragono/irc/utils"
|
12
|
11
|
)
|
13
|
12
|
|
14
|
13
|
// "enabled" callbacks for specific nickserv commands
|
15
|
|
-func servCmdRequiresAccreg(server *Server) bool {
|
16
|
|
- return server.AccountConfig().Registration.Enabled
|
|
14
|
+func servCmdRequiresAccreg(config *Config) bool {
|
|
15
|
+ return config.Accounts.Registration.Enabled
|
17
|
16
|
}
|
18
|
17
|
|
19
|
|
-func servCmdRequiresAuthEnabled(server *Server) bool {
|
20
|
|
- return server.AccountConfig().AuthenticationEnabled
|
|
18
|
+func servCmdRequiresAuthEnabled(config *Config) bool {
|
|
19
|
+ return config.Accounts.AuthenticationEnabled
|
21
|
20
|
}
|
22
|
21
|
|
23
|
|
-func nsGroupEnabled(server *Server) bool {
|
24
|
|
- conf := server.Config()
|
25
|
|
- return conf.Accounts.AuthenticationEnabled && conf.Accounts.NickReservation.Enabled
|
|
22
|
+func nsGroupEnabled(config *Config) bool {
|
|
23
|
+ return config.Accounts.AuthenticationEnabled && config.Accounts.NickReservation.Enabled
|
26
|
24
|
}
|
27
|
25
|
|
28
|
|
-func nsEnforceEnabled(server *Server) bool {
|
29
|
|
- config := server.Config()
|
|
26
|
+func nsEnforceEnabled(config *Config) bool {
|
30
|
27
|
return config.Accounts.NickReservation.Enabled && config.Accounts.NickReservation.AllowCustomEnforcement
|
31
|
28
|
}
|
32
|
29
|
|
|
@@ -73,6 +70,7 @@ GHOST disconnects the given user from the network if they're logged in with the
|
73
|
70
|
same user account, letting you reclaim your nickname.`,
|
74
|
71
|
helpShort: `$bGHOST$b reclaims your nickname.`,
|
75
|
72
|
authRequired: true,
|
|
73
|
+ minParams: 1,
|
76
|
74
|
},
|
77
|
75
|
"group": {
|
78
|
76
|
handler: nsGroupHandler,
|
|
@@ -84,7 +82,6 @@ users from changing to it (or forcing them to rename).`,
|
84
|
82
|
enabled: nsGroupEnabled,
|
85
|
83
|
authRequired: true,
|
86
|
84
|
},
|
87
|
|
-
|
88
|
85
|
"identify": {
|
89
|
86
|
handler: nsIdentifyHandler,
|
90
|
87
|
help: `Syntax: $bIDENTIFY <username> [password]$b
|
|
@@ -92,6 +89,7 @@ users from changing to it (or forcing them to rename).`,
|
92
|
89
|
IDENTIFY lets you login to the given username using either password auth, or
|
93
|
90
|
certfp (your client certificate) if a password is not given.`,
|
94
|
91
|
helpShort: `$bIDENTIFY$b lets you login to your account.`,
|
|
92
|
+ minParams: 1,
|
95
|
93
|
},
|
96
|
94
|
"info": {
|
97
|
95
|
handler: nsInfoHandler,
|
|
@@ -113,6 +111,7 @@ If the password is left out, your account will be registered to your TLS client
|
113
|
111
|
certificate (and you will need to use that certificate to login in future).`,
|
114
|
112
|
helpShort: `$bREGISTER$b lets you register a user account.`,
|
115
|
113
|
enabled: servCmdRequiresAccreg,
|
|
114
|
+ minParams: 2,
|
116
|
115
|
},
|
117
|
116
|
"sadrop": {
|
118
|
117
|
handler: nsDropHandler,
|
|
@@ -122,6 +121,7 @@ SADROP forcibly de-links the given nickname from the attached user account.`,
|
122
|
121
|
helpShort: `$bSADROP$b forcibly de-links the given nickname from its user account.`,
|
123
|
122
|
capabs: []string{"accreg"},
|
124
|
123
|
enabled: servCmdRequiresAccreg,
|
|
124
|
+ minParams: 1,
|
125
|
125
|
},
|
126
|
126
|
"unregister": {
|
127
|
127
|
handler: nsUnregisterHandler,
|
|
@@ -132,6 +132,8 @@ IRC operator with the correct permissions). To prevent accidental
|
132
|
132
|
unregistrations, a verification code is required; invoking the command without
|
133
|
133
|
a code will display the necessary code.`,
|
134
|
134
|
helpShort: `$bUNREGISTER$b lets you delete your user account.`,
|
|
135
|
+ enabled: servCmdRequiresAccreg,
|
|
136
|
+ minParams: 1,
|
135
|
137
|
},
|
136
|
138
|
"verify": {
|
137
|
139
|
handler: nsVerifyHandler,
|
|
@@ -141,6 +143,7 @@ VERIFY lets you complete an account registration, if the server requires email
|
141
|
143
|
or other verification.`,
|
142
|
144
|
helpShort: `$bVERIFY$b lets you complete account registration.`,
|
143
|
145
|
enabled: servCmdRequiresAccreg,
|
|
146
|
+ minParams: 2,
|
144
|
147
|
},
|
145
|
148
|
"passwd": {
|
146
|
149
|
handler: nsPasswdHandler,
|
|
@@ -153,6 +156,7 @@ with the correct permissions, you can use PASSWD to reset someone else's
|
153
|
156
|
password by supplying their username and then the desired password.`,
|
154
|
157
|
helpShort: `$bPASSWD$b lets you change your password.`,
|
155
|
158
|
enabled: servCmdRequiresAuthEnabled,
|
|
159
|
+ minParams: 2,
|
156
|
160
|
},
|
157
|
161
|
}
|
158
|
162
|
)
|
|
@@ -162,9 +166,14 @@ func nsNotice(rb *ResponseBuffer, text string) {
|
162
|
166
|
rb.Add(nil, "NickServ", "NOTICE", rb.target.Nick(), text)
|
163
|
167
|
}
|
164
|
168
|
|
165
|
|
-func nsDropHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
|
169
|
+func nsDropHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
166
|
170
|
sadrop := command == "sadrop"
|
167
|
|
- nick, _ := utils.ExtractParam(params)
|
|
171
|
+ var nick string
|
|
172
|
+ if len(params) > 0 {
|
|
173
|
+ nick = params[0]
|
|
174
|
+ } else {
|
|
175
|
+ nick = client.NickCasefolded()
|
|
176
|
+ }
|
168
|
177
|
|
169
|
178
|
err := server.accounts.SetNickReserved(client, nick, sadrop, false)
|
170
|
179
|
if err == nil {
|
|
@@ -173,15 +182,13 @@ func nsDropHandler(server *Server, client *Client, command, params string, rb *R
|
173
|
182
|
nsNotice(rb, client.t("You're not logged into an account"))
|
174
|
183
|
} else if err == errAccountCantDropPrimaryNick {
|
175
|
184
|
nsNotice(rb, client.t("You can't ungroup your primary nickname (try unregistering your account instead)"))
|
176
|
|
- } else if err == errNicknameReserved {
|
177
|
|
- nsNotice(rb, client.t("That nickname is already reserved by someone else"))
|
178
|
185
|
} else {
|
179
|
186
|
nsNotice(rb, client.t("Could not ungroup nick"))
|
180
|
187
|
}
|
181
|
188
|
}
|
182
|
189
|
|
183
|
|
-func nsGhostHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
184
|
|
- nick, _ := utils.ExtractParam(params)
|
|
190
|
+func nsGhostHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
|
191
|
+ nick := params[0]
|
185
|
192
|
|
186
|
193
|
ghost := server.clients.Get(nick)
|
187
|
194
|
if ghost == nil {
|
|
@@ -207,7 +214,7 @@ func nsGhostHandler(server *Server, client *Client, command, params string, rb *
|
207
|
214
|
ghost.destroy(false)
|
208
|
215
|
}
|
209
|
216
|
|
210
|
|
-func nsGroupHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
|
217
|
+func nsGroupHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
211
|
218
|
nick := client.NickCasefolded()
|
212
|
219
|
err := server.accounts.SetNickReserved(client, nick, false, true)
|
213
|
220
|
if err == nil {
|
|
@@ -230,13 +237,17 @@ func nsLoginThrottleCheck(client *Client, rb *ResponseBuffer) (success bool) {
|
230
|
237
|
return true
|
231
|
238
|
}
|
232
|
239
|
|
233
|
|
-func nsIdentifyHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
|
240
|
+func nsIdentifyHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
234
|
241
|
loginSuccessful := false
|
235
|
242
|
|
236
|
|
- username, passphrase := utils.ExtractParam(params)
|
|
243
|
+ username := params[0]
|
|
244
|
+ var passphrase string
|
|
245
|
+ if len(params) > 1 {
|
|
246
|
+ passphrase = params[1]
|
|
247
|
+ }
|
237
|
248
|
|
238
|
249
|
// try passphrase
|
239
|
|
- if username != "" && passphrase != "" {
|
|
250
|
+ if passphrase != "" {
|
240
|
251
|
if !nsLoginThrottleCheck(client, rb) {
|
241
|
252
|
return
|
242
|
253
|
}
|
|
@@ -257,18 +268,23 @@ func nsIdentifyHandler(server *Server, client *Client, command, params string, r
|
257
|
268
|
}
|
258
|
269
|
}
|
259
|
270
|
|
260
|
|
-func nsInfoHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
261
|
|
- nick, _ := utils.ExtractParam(params)
|
262
|
|
-
|
263
|
|
- if nick == "" {
|
264
|
|
- nick = client.Nick()
|
265
|
|
- }
|
266
|
|
-
|
267
|
|
- accountName := nick
|
268
|
|
- if server.AccountConfig().NickReservation.Enabled {
|
269
|
|
- accountName = server.accounts.NickToAccount(nick)
|
|
271
|
+func nsInfoHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
|
272
|
+ var accountName string
|
|
273
|
+ if len(params) > 0 {
|
|
274
|
+ nick := params[0]
|
|
275
|
+ if server.AccountConfig().NickReservation.Enabled {
|
|
276
|
+ accountName = server.accounts.NickToAccount(nick)
|
|
277
|
+ if accountName == "" {
|
|
278
|
+ nsNotice(rb, client.t("That nickname is not registered"))
|
|
279
|
+ return
|
|
280
|
+ }
|
|
281
|
+ } else {
|
|
282
|
+ accountName = nick
|
|
283
|
+ }
|
|
284
|
+ } else {
|
|
285
|
+ accountName = client.Account()
|
270
|
286
|
if accountName == "" {
|
271
|
|
- nsNotice(rb, client.t("That nickname is not registered"))
|
|
287
|
+ nsNotice(rb, client.t("You're not logged into an account"))
|
272
|
288
|
return
|
273
|
289
|
}
|
274
|
290
|
}
|
|
@@ -276,6 +292,7 @@ func nsInfoHandler(server *Server, client *Client, command, params string, rb *R
|
276
|
292
|
account, err := server.accounts.LoadAccount(accountName)
|
277
|
293
|
if err != nil || !account.Verified {
|
278
|
294
|
nsNotice(rb, client.t("Account does not exist"))
|
|
295
|
+ return
|
279
|
296
|
}
|
280
|
297
|
|
281
|
298
|
nsNotice(rb, fmt.Sprintf(client.t("Account: %s"), account.Name))
|
|
@@ -287,10 +304,13 @@ func nsInfoHandler(server *Server, client *Client, command, params string, rb *R
|
287
|
304
|
}
|
288
|
305
|
}
|
289
|
306
|
|
290
|
|
-func nsRegisterHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
|
307
|
+func nsRegisterHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
291
|
308
|
// get params
|
292
|
|
- username, afterUsername := utils.ExtractParam(params)
|
293
|
|
- email, passphrase := utils.ExtractParam(afterUsername)
|
|
309
|
+ username, email := params[0], params[1]
|
|
310
|
+ var passphrase string
|
|
311
|
+ if len(params) > 0 {
|
|
312
|
+ passphrase = params[2]
|
|
313
|
+ }
|
294
|
314
|
|
295
|
315
|
if !server.AccountConfig().Registration.Enabled {
|
296
|
316
|
nsNotice(rb, client.t("Account registration has been disabled"))
|
|
@@ -366,12 +386,11 @@ func nsRegisterHandler(server *Server, client *Client, command, params string, r
|
366
|
386
|
}
|
367
|
387
|
}
|
368
|
388
|
|
369
|
|
-func nsUnregisterHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
370
|
|
- username, verificationCode := utils.ExtractParam(params)
|
371
|
|
-
|
372
|
|
- if !server.AccountConfig().Registration.Enabled {
|
373
|
|
- nsNotice(rb, client.t("Account registration has been disabled"))
|
374
|
|
- return
|
|
389
|
+func nsUnregisterHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
|
390
|
+ username := params[0]
|
|
391
|
+ var verificationCode string
|
|
392
|
+ if len(params) > 1 {
|
|
393
|
+ verificationCode = params[1]
|
375
|
394
|
}
|
376
|
395
|
|
377
|
396
|
if username == "" {
|
|
@@ -415,9 +434,8 @@ func nsUnregisterHandler(server *Server, client *Client, command, params string,
|
415
|
434
|
}
|
416
|
435
|
}
|
417
|
436
|
|
418
|
|
-func nsVerifyHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
419
|
|
- username, code := utils.ExtractParam(params)
|
420
|
|
-
|
|
437
|
+func nsVerifyHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
|
438
|
+ username, code := params[0], params[1]
|
421
|
439
|
err := server.accounts.Verify(client, username, code)
|
422
|
440
|
|
423
|
441
|
var errorMessage string
|
|
@@ -435,7 +453,7 @@ func nsVerifyHandler(server *Server, client *Client, command, params string, rb
|
435
|
453
|
sendSuccessfulRegResponse(client, rb, true)
|
436
|
454
|
}
|
437
|
455
|
|
438
|
|
-func nsPasswdHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
|
456
|
+func nsPasswdHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
439
|
457
|
var target string
|
440
|
458
|
var newPassword string
|
441
|
459
|
var errorMessage string
|
|
@@ -445,27 +463,26 @@ func nsPasswdHandler(server *Server, client *Client, command, params string, rb
|
445
|
463
|
return
|
446
|
464
|
}
|
447
|
465
|
|
448
|
|
- fields := strings.Fields(params)
|
449
|
|
- switch len(fields) {
|
|
466
|
+ switch len(params) {
|
450
|
467
|
case 2:
|
451
|
468
|
if !hasPrivs {
|
452
|
469
|
errorMessage = "Insufficient privileges"
|
453
|
470
|
} else {
|
454
|
|
- target, newPassword = fields[0], fields[1]
|
|
471
|
+ target, newPassword = params[0], params[1]
|
455
|
472
|
}
|
456
|
473
|
case 3:
|
457
|
474
|
target = client.Account()
|
458
|
475
|
if target == "" {
|
459
|
476
|
errorMessage = "You're not logged into an account"
|
460
|
|
- } else if fields[1] != fields[2] {
|
|
477
|
+ } else if params[1] != params[2] {
|
461
|
478
|
errorMessage = "Passwords do not match"
|
462
|
479
|
} else {
|
463
|
480
|
// check that they correctly supplied the preexisting password
|
464
|
|
- _, err := server.accounts.checkPassphrase(target, fields[0])
|
|
481
|
+ _, err := server.accounts.checkPassphrase(target, params[0])
|
465
|
482
|
if err != nil {
|
466
|
483
|
errorMessage = "Password incorrect"
|
467
|
484
|
} else {
|
468
|
|
- newPassword = fields[1]
|
|
485
|
+ newPassword = params[1]
|
469
|
486
|
}
|
470
|
487
|
}
|
471
|
488
|
default:
|
|
@@ -486,14 +503,12 @@ func nsPasswdHandler(server *Server, client *Client, command, params string, rb
|
486
|
503
|
}
|
487
|
504
|
}
|
488
|
505
|
|
489
|
|
-func nsEnforceHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
|
490
|
|
- arg := strings.TrimSpace(params)
|
491
|
|
-
|
492
|
|
- if arg == "" {
|
|
506
|
+func nsEnforceHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
|
507
|
+ if len(params) == 0 {
|
493
|
508
|
status := server.accounts.getStoredEnforcementStatus(client.Account())
|
494
|
509
|
nsNotice(rb, fmt.Sprintf(client.t("Your current nickname enforcement is: %s"), status))
|
495
|
510
|
} else {
|
496
|
|
- method, err := nickReservationFromString(arg)
|
|
511
|
+ method, err := nickReservationFromString(params[0])
|
497
|
512
|
if err != nil {
|
498
|
513
|
nsNotice(rb, client.t("Invalid parameters"))
|
499
|
514
|
return
|