Browse Source

add a verification code to CS UNREGISTER

tags/v0.12.0
Shivaram Lingamneni 6 years ago
parent
commit
c3b66b5236
1 changed files with 20 additions and 3 deletions
  1. 20
    3
      irc/chanserv.go

+ 20
- 3
irc/chanserv.go View File

4
 package irc
4
 package irc
5
 
5
 
6
 import (
6
 import (
7
+	"bytes"
7
 	"fmt"
8
 	"fmt"
9
+	"hash/crc32"
8
 	"sort"
10
 	"sort"
11
+	"strconv"
9
 	"strings"
12
 	"strings"
10
 
13
 
11
 	"github.com/goshuirc/irc-go/ircfmt"
14
 	"github.com/goshuirc/irc-go/ircfmt"
51
 		},
54
 		},
52
 		"unregister": {
55
 		"unregister": {
53
 			handler: csUnregisterHandler,
56
 			handler: csUnregisterHandler,
54
-			help: `Syntax: $bUNREGISTER #channel$b
57
+			help: `Syntax: $bUNREGISTER #channel [code]$b
55
 
58
 
56
-UNREGISTER deletes a channel registration, allowing someone else to claim it.`,
59
+UNREGISTER deletes a channel registration, allowing someone else to claim it.
60
+To prevent accidental unregistrations, a verification code is required;
61
+invoking the command without a code will display the necessary code.`,
57
 			helpShort: `$bUNREGISTER$b deletes a channel registration.`,
62
 			helpShort: `$bUNREGISTER$b deletes a channel registration.`,
58
 			enabled:   chanregEnabled,
63
 			enabled:   chanregEnabled,
59
 		},
64
 		},
258
 }
263
 }
259
 
264
 
260
 func csUnregisterHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
265
 func csUnregisterHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
261
-	channelName := strings.TrimSpace(params)
266
+	channelName, verificationCode := utils.ExtractParam(params)
262
 	channelKey, err := CasefoldChannel(channelName)
267
 	channelKey, err := CasefoldChannel(channelName)
263
 	if channelKey == "" || err != nil {
268
 	if channelKey == "" || err != nil {
264
 		csNotice(rb, client.t("Channel name is not valid"))
269
 		csNotice(rb, client.t("Channel name is not valid"))
282
 	}
287
 	}
283
 
288
 
284
 	info := channel.ExportRegistration(0)
289
 	info := channel.ExportRegistration(0)
290
+	// verification code is the crc32 of the name, plus the registration time
291
+	var codeInput bytes.Buffer
292
+	codeInput.WriteString(info.Name)
293
+	codeInput.WriteString(strconv.FormatInt(info.RegisteredAt.Unix(), 16))
294
+	expectedCode := int(crc32.ChecksumIEEE(codeInput.Bytes()))
295
+	receivedCode, err := strconv.Atoi(verificationCode)
296
+	if err != nil || expectedCode != receivedCode {
297
+		csNotice(rb, client.t("$bWarning:$b Unregistering this channel will remove all stored channel attributes."))
298
+		csNotice(rb, fmt.Sprintf(client.t("To confirm channel unregistration, type: /CS UNREGISTER %s %d"), channelKey, expectedCode))
299
+		return
300
+	}
301
+
285
 	channel.SetUnregistered()
302
 	channel.SetUnregistered()
286
 	go server.channelRegistry.Delete(channelKey, info)
303
 	go server.channelRegistry.Delete(channelKey, info)
287
 	csNotice(rb, fmt.Sprintf(client.t("Channel %s is now unregistered"), channelKey))
304
 	csNotice(rb, fmt.Sprintf(client.t("Channel %s is now unregistered"), channelKey))

Loading…
Cancel
Save